/* ==========================================================================
   NEON MATRIX - TETRIS GAME STYLESHEET
   Aesthetic: Cyberpunk Neon Synthwave / Dark Glassmorphism
   Mobile-First Ergonomic Layouts & Touch Controls
   ========================================================================== */

:root {
  /* Color Palette */
  --bg-color: #070913;
  --bg-card: rgba(18, 22, 41, 0.7);
  --border-color: rgba(0, 240, 255, 0.25);
  --border-glow: rgba(0, 240, 255, 0.5);

  --text-main: #f0f4f8;
  --text-muted: #8899ac;
  
  --neon-cyan: #00f0ff;
  --neon-pink: #ff007f;
  --neon-purple: #9d00ff;
  --neon-yellow: #ffe600;
  --neon-green: #00ff66;
  --neon-orange: #ff6600;
  --neon-blue: #0066ff;

  --shadow-glow: 0 0 25px rgba(0, 240, 255, 0.35);
  --font-heading: 'Orbitron', -apple-system, sans-serif;
  --font-body: 'Rajdhani', -apple-system, sans-serif;
}

/* Reset & Box Sizing */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed; /* Prevents scroll bounces on iOS/Android */
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-body);
  display: flex;
  justify-content: center;
  align-items: center;
  overscroll-behavior: none;
}

/* Dynamic Background Glows & Grid */
.bg-glow {
  position: fixed;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  filter: blur(140px);
  z-index: -2;
  opacity: 0.35;
  animation: pulse-glow 10s infinite alternate ease-in-out;
  pointer-events: none;
}

.bg-glow-1 {
  top: -100px;
  left: -100px;
  background: radial-gradient(circle, var(--neon-cyan), var(--neon-purple));
}

.bg-glow-2 {
  bottom: -100px;
  right: -100px;
  background: radial-gradient(circle, var(--neon-pink), var(--neon-blue));
  animation-delay: 5s;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  z-index: -1;
  pointer-events: none;
}

@keyframes pulse-glow {
  0% { transform: scale(1) translate(0, 0); opacity: 0.3; }
  50% { transform: scale(1.2) translate(30px, -20px); opacity: 0.45; }
  100% { transform: scale(0.9) translate(-20px, 30px); opacity: 0.25; }
}

/* Main Outer Wrapper */
.game-wrapper {
  width: 100%;
  height: 100%;
  max-width: 1050px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

/* Header */
.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.37);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  font-size: 1.5rem;
  color: var(--neon-cyan);
  text-shadow: 0 0 10px var(--neon-cyan);
  animation: logo-spin 12s infinite linear;
}

@keyframes logo-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.logo h1 {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.logo .highlight {
  color: var(--neon-cyan);
  text-shadow: 0 0 12px var(--neon-cyan);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: 8px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: rgba(0, 240, 255, 0.15);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.4);
}

/* Glass Card Common */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Main Arcade Container */
.arcade-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 15px;
  width: 100%;
  flex: 1;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 170px;
}

.sidebar h2 {
  font-family: var(--font-heading);
  font-size: 0.8rem;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.preview-box {
  background: rgba(5, 7, 15, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.8);
}

.hold-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 6px;
}

/* Stats Section */
.panel-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(0, 0, 0, 0.3);
  padding: 6px;
  border-radius: 8px;
  border-left: 3px solid var(--neon-cyan);
}

.stat-label {
  font-size: 0.7rem;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-family: var(--font-heading);
}

.stat-value {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
}

.highlight-val {
  color: var(--neon-cyan);
  text-shadow: 0 0 10px var(--neon-cyan);
}

/* Board Section */
.board-section {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
}

/* Mobile Top HUD (Hidden on desktop) */
.mobile-hud {
  display: none;
}

.board-card {
  padding: 6px;
  border-color: rgba(0, 240, 255, 0.35);
  box-shadow: var(--shadow-glow), 0 12px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
}

.canvas-frame {
  position: relative;
  background: #04060f;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid rgba(0, 240, 255, 0.35);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.9);
}

#tetris-canvas {
  display: block;
  touch-action: none;
  max-height: 65vh;
  width: auto;
}

/* Overlay Window */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 9, 20, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.overlay-content {
  text-align: center;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  animation: scale-up 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes scale-up {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.overlay h2 {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  letter-spacing: 2px;
  color: var(--neon-cyan);
  text-shadow: 0 0 15px var(--neon-cyan);
}

.btn-primary {
  background: linear-gradient(135deg, var(--neon-cyan), var(--neon-blue));
  border: none;
  color: #04060f;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1rem;
  padding: 12px 26px;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 1px;
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.5);
  transition: all 0.25s ease;
}

.btn-primary:active {
  transform: scale(0.96);
}

/* Floating Banner Notification */
.alert-banner {
  position: absolute;
  top: 25%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--neon-yellow);
  text-shadow: 0 0 15px var(--neon-yellow), 0 0 30px var(--neon-orange);
  pointer-events: none;
  z-index: 5;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  opacity: 1;
}

.alert-banner.hidden {
  opacity: 0;
  transform: translate(-50%, -70%) scale(0.5);
}

/* Controls Guide Box */
.panel-controls-guide h2 {
  margin-bottom: 6px;
}

.control-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.control-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

kbd {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 2px 5px;
  font-family: var(--font-heading);
  font-size: 0.7rem;
  color: var(--neon-cyan);
}

/* Mobile Arcade Touch Controls */
.touch-controls {
  display: none;
  width: 100%;
  max-width: 440px;
  flex-direction: column;
  gap: 6px;
  padding: 2px 4px;
  padding-bottom: max(6px, env(safe-area-inset-bottom)); /* Safe Area for Pixel/iPhone bottom nav */
  flex-shrink: 0;
  touch-action: none;
}

.touch-row {
  display: flex;
  gap: 6px;
  width: 100%;
  justify-content: center;
}

.touch-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: #fff;
  border-radius: 10px;
  padding: 10px 4px;
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: none;
  transition: background 0.1s, transform 0.1s;
  flex: 1;
  text-align: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.touch-btn:active, .touch-btn.active {
  background: rgba(0, 240, 255, 0.35);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 15px var(--neon-cyan);
  transform: scale(0.95);
}

.touch-btn-dir {
  font-size: 1.2rem;
  background: rgba(0, 240, 255, 0.1);
}

.touch-btn-action {
  background: rgba(255, 0, 127, 0.25);
  border-color: var(--neon-pink);
  color: #fff;
  font-weight: 900;
  flex: 1.4;
}

.touch-btn-action:active, .touch-btn-action.active {
  background: rgba(255, 0, 127, 0.6);
  box-shadow: 0 0 15px var(--neon-pink);
}

.touch-btn-sec {
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 8px 4px;
}

/* Modal Popup */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  max-width: 450px;
  width: 92%;
  position: relative;
}

.modal-card h2 {
  font-family: var(--font-heading);
  color: var(--neon-cyan);
  margin-bottom: 12px;
}

.close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  line-height: 1.4;
  font-size: 0.9rem;
}

/* Footer */
.game-footer {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  flex-shrink: 0;
}

/* ==========================================================================
   SMARTPHONE ULTRA-COMPACT LAYOUT (< 900px - Google Pixel 10 & Mobile)
   ========================================================================== */
@media (max-width: 900px) {
  .game-wrapper {
    padding: 4px;
    gap: 4px;
  }

  .game-header {
    padding: 4px 10px;
    border-radius: 8px;
  }

  .logo h1 {
    font-size: 1rem;
  }

  .logo-icon {
    font-size: 1.1rem;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.95rem;
  }

  .arcade-container {
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  /* Hide bulky sidebars completely on smartphones */
  .sidebar {
    display: none !important;
  }

  /* Show sleek, compact Mobile HUD bar right above the board */
  .mobile-hud {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 320px;
    padding: 4px 8px;
    margin-bottom: 4px;
    border-radius: 10px;
    background: rgba(18, 22, 41, 0.9);
    border: 1px solid var(--border-color);
  }

  .hud-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
  }

  .hud-label {
    font-family: var(--font-heading);
    font-size: 0.6rem;
    color: var(--text-muted);
    letter-spacing: 1px;
  }

  #hold-canvas-mobile, #next-canvas-mobile {
    width: 42px;
    height: 42px;
    background: rgba(5, 7, 15, 0.9);
    border: 1px solid rgba(0, 240, 255, 0.3);
    border-radius: 6px;
  }

  .hud-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2px 8px;
    align-items: center;
  }

  .hud-stat-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 3px;
  }

  .hud-stat-item .stat-label {
    font-size: 0.55rem;
    color: var(--text-muted);
    font-family: var(--font-heading);
    letter-spacing: 0.5px;
  }

  .hud-stat-item .stat-value {
    font-size: 0.9rem;
    font-family: var(--font-heading);
    font-weight: 800;
    color: #ffffff;
    text-shadow: 0 0 8px var(--neon-cyan);
  }

  .board-card {
    padding: 3px;
  }

  #tetris-canvas {
    max-height: 48vh;
    width: auto;
  }

  .touch-controls {
    display: flex;
  }

  .game-footer {
    display: none;
  }
}
