/* ==========================================================================
   NEON TETRIS — stylesheet
   Theme: dark neon cyber arcade. Kept intentionally restrained so gameplay
   stays legible: one glow language, one accent per piece, no busy chrome.
   ========================================================================== */

:root {
  --bg-void:      #060814;
  --bg-panel:     #0b0f22;
  --bg-panel-2:   #0e1329;
  --line:         rgba(120, 170, 255, 0.16);
  --line-strong:  rgba(120, 170, 255, 0.32);
  --text-main:    #dce6ff;
  --text-dim:     #6d7aa8;

  --neon-cyan:    #33f7ff;
  --neon-pink:    #ff3df0;
  --neon-violet:  #9b5cff;
  --neon-amber:   #ffb63d;

  --piece-I: #33f7ff;
  --piece-O: #ffe93d;
  --piece-T: #c86bff;
  --piece-S: #3dff8b;
  --piece-Z: #ff3d5e;
  --piece-J: #3d7bff;
  --piece-L: #ff9a3d;

  --font-display: 'Orbitron', 'Segoe UI', sans-serif;
  --font-body: 'Rajdhani', 'Segoe UI', sans-serif;

  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-void);
  color: var(--text-main);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button {
  font-family: var(--font-display);
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* ---------------------------------------------------------------- background */

.bg-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 20% -10%, rgba(155, 92, 255, 0.18), transparent 55%),
    radial-gradient(ellipse at 85% 110%, rgba(51, 247, 255, 0.12), transparent 55%),
    var(--bg-void);
}

.bg-grid {
  position: absolute;
  inset: -10% -10%;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 46px 46px;
  transform: perspective(600px) rotateX(58deg);
  transform-origin: center 20%;
  opacity: 0.35;
  animation: gridDrift 14s linear infinite;
}

@keyframes gridDrift {
  from { background-position: 0 0, 0 0; }
  to   { background-position: 0 46px, 46px 0; }
}

#bg-particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ---------------------------------------------------------------- screens */

.screen {
  position: relative;
  z-index: 1;
  overflow-y: auto;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
}

.screen.active { display: flex; }

.overlay-screen {
  background: rgba(6, 8, 20, 0.72);
  backdrop-filter: blur(6px);
}

/* ---------------------------------------------------------------- menu */

.menu-wrap {
  text-align: center;
  padding: 24px;
  animation: menuIn 0.6s ease both;
}

@keyframes menuIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.logo {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(2.6rem, 8vw, 4.6rem);
  margin: 0;
  letter-spacing: 0.04em;
  line-height: 1;
}

.logo-neon {
  color: var(--neon-cyan);
  text-shadow:
    0 0 8px rgba(51, 247, 255, 0.9),
    0 0 24px rgba(51, 247, 255, 0.55),
    0 0 52px rgba(51, 247, 255, 0.35);
  animation: flicker 4.5s ease-in-out infinite;
}

.logo-solid {
  color: var(--text-main);
  margin-left: 0.15em;
}

@keyframes flicker {
  0%, 92%, 100% { opacity: 1; }
  93% { opacity: 0.75; }
  94% { opacity: 1; }
  95% { opacity: 0.6; }
  96% { opacity: 1; }
}

.tagline {
  color: var(--text-dim);
  font-size: 0.95rem;
  letter-spacing: 0.22em;
  text-transform: lowercase;
  margin: 6px 0 30px;
}

.menu-highscore {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 28px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(14, 19, 41, 0.6);
  margin-bottom: 30px;
}

.hs-label {
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.hs-value {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--neon-amber);
  text-shadow: 0 0 12px rgba(255, 182, 61, 0.6);
  font-variant-numeric: tabular-nums;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(280px, 78vw);
  margin: 0 auto;
}

.btn {
  padding: 14px 20px;
  font-size: 1rem;
  letter-spacing: 0.14em;
  border-radius: var(--radius);
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, rgba(51, 247, 255, 0.18), rgba(155, 92, 255, 0.18));
  border: 1px solid var(--neon-cyan);
  color: var(--neon-cyan);
  box-shadow: 0 0 14px rgba(51, 247, 255, 0.25), inset 0 0 14px rgba(51, 247, 255, 0.08);
}

.btn-primary:hover {
  box-shadow: 0 0 22px rgba(51, 247, 255, 0.5), inset 0 0 18px rgba(51, 247, 255, 0.15);
}

.btn-ghost {
  border: 1px solid var(--line-strong);
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.02);
}

.btn-ghost:hover {
  color: var(--text-main);
  border-color: var(--neon-violet);
  box-shadow: 0 0 14px rgba(155, 92, 255, 0.25);
}

.wide { width: 100%; }

.icon-toggle {
  margin-top: 26px;
  font-family: var(--font-body);
  font-weight: 600;
  letter-spacing: 0.12em;
  font-size: 0.8rem;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-toggle:hover { color: var(--text-main); }

/* ---------------------------------------------------------------- panel cards (howto/settings/scores) */

.panel-card {
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 28px 26px;
  width: min(420px, 90vw);
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 0 40px rgba(51, 247, 255, 0.08);
}

.panel-title {
  font-family: var(--font-display);
  color: var(--neon-cyan);
  text-shadow: 0 0 10px rgba(51, 247, 255, 0.5);
  letter-spacing: 0.12em;
  font-size: 1.2rem;
  margin: 0 0 20px;
  text-align: center;
}

.howto-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.howto-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  color: var(--text-main);
}

.key {
  font-family: var(--font-display);
  font-size: 0.72rem;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 4px 8px;
  color: var(--neon-cyan);
  min-width: 20px;
  text-align: center;
  background: rgba(51, 247, 255, 0.06);
}

.howto-note {
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 22px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}

.setting-row input[type="range"] {
  width: 130px;
  accent-color: var(--neon-cyan);
}

.toggle-pill {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid var(--neon-cyan);
  color: var(--neon-cyan);
  background: rgba(51, 247, 255, 0.08);
  transition: all 0.2s ease;
}

.toggle-pill[data-on="false"] {
  border-color: var(--text-dim);
  color: var(--text-dim);
  background: transparent;
}

.top-scores-list {
  list-style: none;
  counter-reset: rank;
  padding: 0;
  margin: 0 0 20px;
}

.top-scores-list li {
  counter-increment: rank;
  display: flex;
  justify-content: space-between;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-display);
  font-size: 0.95rem;
}

.top-scores-list li::before {
  content: counter(rank) ".";
  color: var(--text-dim);
  margin-right: 10px;
}

.top-scores-list li span { color: var(--neon-amber); }
.top-scores-list .empty { color: var(--text-dim); font-family: var(--font-body); text-align: center; }

/* ---------------------------------------------------------------- game layout */

#screen-game.active { display: flex; }

.game-layout {
  display: grid;
  grid-template-columns: 168px auto 168px;
  gap: 22px;
  align-items: start;
  justify-content: center;
  padding: 18px;
  width: 100%;
  height: 100%;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 4px;
}

.panel-right { align-items: stretch; }

.stat-box {
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.stat-label {
  font-family: var(--font-display);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  color: var(--text-dim);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--neon-cyan);
  text-shadow: 0 0 10px rgba(51, 247, 255, 0.45);
  font-variant-numeric: tabular-nums;
}

.stat-value-sm {
  font-size: 1.1rem;
  color: var(--neon-amber);
  text-shadow: 0 0 10px rgba(255, 182, 61, 0.4);
}

#hold-canvas, #next-canvas {
  width: 76px;
  height: 76px;
  image-rendering: pixelated;
}

.controls-box { align-items: stretch; }

.controls-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.controls-list li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.controls-list .key {
  font-size: 0.62rem;
  padding: 2px 6px;
  min-width: 16px;
}

/* ---------------------------------------------------------------- board */

.board-wrap {
  position: relative;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(14, 19, 41, 0.9), rgba(8, 11, 24, 0.95));
  box-shadow: 0 0 46px rgba(51, 247, 255, 0.1), inset 0 0 30px rgba(0, 0, 0, 0.5);
  line-height: 0;
  overflow: hidden;
}

#board-canvas, #fx-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#fx-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.line-clear-text {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(1.6rem, 5vw, 2.6rem);
  color: var(--neon-cyan);
  text-shadow: 0 0 14px currentColor, 0 0 36px currentColor;
  opacity: 0;
  pointer-events: none;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.line-clear-text.show {
  animation: lineClearPop 0.9s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

@keyframes lineClearPop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  18%  { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  30%  { transform: translate(-50%, -50%) scale(1); }
  78%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.15); }
}

/* ---------------------------------------------------------------- in-game overlays */

.ingame-overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 14, 0.82);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.ingame-overlay.show { display: flex; }

.overlay-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
  width: 82%;
  max-width: 260px;
  text-align: center;
  animation: menuIn 0.35s ease both;
}

.overlay-title {
  font-family: var(--font-display);
  font-size: 1.7rem;
  letter-spacing: 0.12em;
  color: var(--neon-cyan);
  text-shadow: 0 0 16px rgba(51, 247, 255, 0.6);
  margin: 0 0 6px;
}

.overlay-title-danger {
  color: var(--neon-pink);
  text-shadow: 0 0 16px rgba(255, 61, 240, 0.6);
  animation: dangerPulse 1.4s ease-in-out infinite;
}

@keyframes dangerPulse {
  0%, 100% { text-shadow: 0 0 16px rgba(255, 61, 240, 0.6); }
  50% { text-shadow: 0 0 30px rgba(255, 61, 240, 0.95); }
}

.overlay-newhigh {
  display: none;
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  color: var(--neon-amber);
  text-shadow: 0 0 12px rgba(255, 182, 61, 0.7);
  margin: -4px 0 4px;
  animation: menuIn 0.4s ease both;
}

.overlay-newhigh.show { display: block; }

.overlay-score-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

.overlay-score-row span:last-child {
  color: var(--neon-cyan);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- mobile controls */

.mobile-controls {
  display: none;
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 4;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, rgba(6, 8, 20, 0.85) 30%);
}

.mc-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.mc-top { margin-bottom: 8px; }

.mc-btn {
  font-family: var(--font-display);
  border: 1px solid var(--line-strong);
  background: rgba(14, 19, 41, 0.75);
  color: var(--neon-cyan);
  border-radius: 12px;
  box-shadow: 0 0 10px rgba(51, 247, 255, 0.15);
}

.mc-btn:active {
  background: rgba(51, 247, 255, 0.18);
  box-shadow: 0 0 16px rgba(51, 247, 255, 0.4);
}

.mc-dir {
  flex: 1;
  max-width: 78px;
  height: 54px;
  font-size: 1.3rem;
}

.mc-drop {
  flex: 1.3;
  height: 54px;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  color: var(--neon-pink);
  border-color: var(--neon-pink);
}

.mc-small {
  flex: 1;
  max-width: 90px;
  height: 40px;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--text-main);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 880px) {
  html, body { overflow-y: auto; overflow-x: hidden; }

  .game-layout {
    grid-template-columns: 1fr;
    grid-template-areas: "left" "board" "right";
    padding: 10px 10px 190px;
    gap: 10px;
    height: auto;
    min-height: 100%;
  }

  .panel-left {
    grid-area: left;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .panel-left .stat-box { flex: 1 1 68px; min-width: 68px; padding: 6px 8px; }
  .panel-left .stat-value { font-size: 1.05rem; }
  #hold-canvas { width: 46px; height: 46px; }

  .board-wrap { grid-area: board; justify-self: center; }

  .panel-right {
    grid-area: right;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .panel-right .controls-box,
  .panel-right .toggle-pill,
  .panel-right .btn { display: none; }

  #next-canvas { width: 46px; height: 46px; }

  .mobile-controls { display: block; }
}

@media (min-width: 881px) {
  .mobile-controls { display: none !important; }
}

@media (max-width: 420px) {
  .logo { font-size: 2.2rem; }
  .menu-buttons { width: 86vw; }
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .bg-grid, .logo-neon, .overlay-title-danger { animation: none !important; }
  .line-clear-text.show { animation-duration: 0.4s; }
}
