/* =========================================================
   TETRIS — Arcade neon theme
   ========================================================= */

:root{
  --bg-0: #08070f;
  --bg-1: #0f0d1e;
  --bg-2: #16132b;
  --panel: rgba(24, 20, 46, 0.72);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-0: #f2f0ff;
  --text-1: #a9a3c9;
  --text-dim: #6a638f;

  --neon-magenta: #ff3ec8;
  --neon-cyan: #22e6ff;
  --neon-violet: #8b5cf6;
  --accent: var(--neon-cyan);

  --piece-i: #22e6ff;
  --piece-o: #ffd23f;
  --piece-t: #b660ff;
  --piece-s: #39ff88;
  --piece-z: #ff3b5c;
  --piece-j: #3b7bff;
  --piece-l: #ff8f2e;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;

  --font-display: "Orbitron", "Segoe UI", system-ui, sans-serif;
  --font-body: "Rajdhani", "Segoe UI", system-ui, sans-serif;
}

body.light-mode{
  --bg-0: #eef0fb;
  --bg-1: #e4e7fb;
  --bg-2: #d9defa;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-border: rgba(20, 10, 60, 0.10);
  --text-0: #171532;
  --text-1: #423d66;
  --text-dim: #8a84b0;
}

*{ box-sizing: border-box; }

html, body{
  height: 100%;
  margin: 0;
  padding: 0;
  overscroll-behavior: none;
  touch-action: none;
}

body{
  font-family: var(--font-body);
  background:
    radial-gradient(1200px 800px at 15% 0%, rgba(139,92,246,0.16), transparent 60%),
    radial-gradient(1200px 900px at 100% 100%, rgba(34,230,255,0.10), transparent 55%),
    linear-gradient(180deg, var(--bg-0), var(--bg-1) 45%, var(--bg-2));
  color: var(--text-0);
  min-height: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

@font-face{
  font-family: "Orbitron";
  src: local("Orbitron");
}

/* subtle scanline overlay for arcade feel */
.crt-overlay{
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.02) 0px,
    rgba(255,255,255,0.02) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
  opacity: 0.35;
}

#app{
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

/* ================= Screens ================= */
.screen{
  display: none;
  width: 100%;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 24px 16px;
  animation: fadeIn 0.35s ease;
}
.screen.active{ display: flex; }

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

/* ================= Menu ================= */
.menu-wrap{
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  text-align: center;
}

.title{
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(2.6rem, 10vw, 4.2rem);
  letter-spacing: 0.08em;
  margin: 0;
  display: flex;
  gap: 4px;
}
.title-block{
  display: inline-block;
  text-shadow: 0 0 12px currentColor, 0 0 28px currentColor;
  animation: pulseGlow 3.2s ease-in-out infinite;
}
.t-i{ color: var(--piece-i); animation-delay: 0s; }
.t-o{ color: var(--piece-o); animation-delay: 0.1s; }
.t-t{ color: var(--piece-t); animation-delay: 0.2s; }
.t-s{ color: var(--piece-z); animation-delay: 0.3s; }
.t-z{ color: var(--piece-j); animation-delay: 0.4s; }
.t-l{ color: var(--piece-l); animation-delay: 0.5s; }

@keyframes pulseGlow{
  0%, 100%{ filter: brightness(1); transform: translateY(0); }
  50%{ filter: brightness(1.35); transform: translateY(-3px); }
}

.subtitle{
  margin: -18px 0 0;
  color: var(--text-dim);
  letter-spacing: 0.35em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.menu-buttons{
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 280px;
}

.menu-highscore{
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 26px;
  border-radius: var(--radius-md);
  background: var(--panel);
  border: 1px solid var(--panel-border);
}
.menu-highscore .label{
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.menu-highscore .value{
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--piece-o);
  text-shadow: 0 0 14px rgba(255, 210, 63, 0.6);
}

/* ================= Buttons ================= */
.btn{
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--text-0);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  backdrop-filter: blur(6px);
}
.btn:hover{
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.25);
}
.btn:active{
  transform: translateY(0px) scale(0.98);
}
.btn-primary{
  background: linear-gradient(135deg, var(--neon-violet), var(--neon-cyan));
  border: none;
  color: #0a0715;
  font-weight: 700;
  box-shadow: 0 0 18px rgba(139, 92, 246, 0.45), 0 0 32px rgba(34, 230, 255, 0.25);
}
.btn-primary:hover{
  box-shadow: 0 0 24px rgba(139, 92, 246, 0.65), 0 0 44px rgba(34, 230, 255, 0.4);
}

.icon-btn{
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text-0);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover{ transform: translateY(-1px); border-color: var(--accent); color: var(--accent); }
.icon-btn:active{ transform: scale(0.95); }

/* ================= Game Screen ================= */
.game-wrap{
  width: 100%;
  max-width: 920px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px;
}
.brand{
  font-family: var(--font-display);
  letter-spacing: 0.25em;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.topbar-actions{ display: flex; gap: 8px; }

.game-layout{
  display: grid;
  grid-template-columns: 116px 1fr 116px;
  gap: 16px;
  align-items: start;
  justify-content: center;
}

.side-panel{
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-box{
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 10px;
  backdrop-filter: blur(8px);
}
.panel-title{
  font-family: var(--font-display);
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-align: center;
}
#hold-canvas, #next-canvas{
  width: 100%;
  height: auto;
  aspect-ratio: 1/1;
  display: block;
}

.stat-box{
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stat-row{ display: flex; flex-direction: column; gap: 2px; }
.stat-label{
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.stat-value{
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--accent);
  text-shadow: 0 0 10px rgba(34, 230, 255, 0.5);
}

.board-area{
  display: flex;
  justify-content: center;
}
.board-frame{
  position: relative;
  border-radius: var(--radius-lg);
  padding: 8px;
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.015));
  border: 1px solid var(--panel-border);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.02), 0 20px 60px rgba(0,0,0,0.45), inset 0 0 40px rgba(139,92,246,0.06);
}
#board-canvas{
  display: block;
  border-radius: 10px;
  background: radial-gradient(120% 100% at 50% 0%, rgba(139,92,246,0.10), rgba(0,0,0,0.35) 70%);
}

/* ================= Overlays (pause / game over) ================= */
.overlay{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 5, 14, 0.72);
  backdrop-filter: blur(4px);
  border-radius: 10px;
  animation: fadeIn 0.2s ease;
}
.overlay.hidden{ display: none; }

.overlay-panel{
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 26px 30px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
  min-width: 220px;
  box-shadow: 0 0 40px rgba(139,92,246,0.25);
}
.overlay-panel h2{
  font-family: var(--font-display);
  text-align: center;
  margin: 0 0 6px;
  letter-spacing: 0.1em;
  color: var(--text-0);
  text-shadow: 0 0 16px var(--accent);
}
.gameover-title{ color: var(--piece-z) !important; text-shadow: 0 0 18px var(--piece-z) !important; }

.go-stats{
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 4px;
}
.go-row{
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-1);
  border-bottom: 1px dashed var(--panel-border);
  padding-bottom: 4px;
}
.go-row span:last-child{
  font-family: var(--font-display);
  color: var(--text-0);
}
.new-best{
  text-align: center;
  color: var(--piece-o);
  text-shadow: 0 0 12px rgba(255,210,63,0.7);
  font-family: var(--font-display);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}
.new-best.hidden{ display: none; }

/* ================= Touch Controls ================= */
.touch-controls{
  display: none;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}
.touch-row{ display: flex; gap: 10px; justify-content: center; }
.touch-btn{
  flex: 1;
  max-width: 90px;
  height: 56px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text-0);
  font-family: var(--font-display);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.touch-btn:active{
  background: rgba(139, 92, 246, 0.25);
  border-color: var(--accent);
  transform: scale(0.96);
}
.touch-wide{ max-width: 140px; flex: 1.4; }

@media (max-width: 720px){
  .touch-controls{ display: flex; }
  .game-layout{
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .side-panel{
    flex-direction: row;
    width: 100%;
    max-width: 340px;
    justify-content: space-between;
  }
  .side-panel .panel-box{ flex: 1; }
  .side-left{ order: 2; }
  .side-right{ order: 3; }
  .board-area{ order: 1; }
}

/* ================= How To / Settings ================= */
.panel-heading{
  font-family: var(--font-display);
  letter-spacing: 0.1em;
  margin-bottom: 6px;
  text-shadow: 0 0 14px var(--accent);
}
.howto-wrap, .settings-wrap{
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 30px;
  max-width: 520px;
}
.howto-grid{
  display: flex;
  gap: 30px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 10px;
}
.howto-col h3{
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 10px;
}
.howto-list{
  list-style: none;
  margin: 0; padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  color: var(--text-1);
  font-size: 0.88rem;
}
kbd{
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--font-display);
  font-size: 0.72rem;
  margin-right: 4px;
  color: var(--text-0);
}

.setting-row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px;
  border-bottom: 1px solid var(--panel-border);
  font-size: 0.92rem;
  color: var(--text-1);
}
.setting-row:last-of-type{ border-bottom: none; }

.switch{
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}
.switch input{ opacity: 0; width: 0; height: 0; }
.slider{
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
  transition: 0.2s;
}
.slider::before{
  content: "";
  position: absolute;
  height: 20px; width: 20px;
  left: 3px; top: 3px;
  background: var(--text-0);
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider{
  background: linear-gradient(135deg, var(--neon-violet), var(--neon-cyan));
}
.switch input:checked + .slider::before{
  transform: translateX(20px);
}

/* ================= Utility ================= */
.hidden{ display: none !important; }

@media (max-width: 380px){
  .title{ letter-spacing: 0.03em; }
  .game-layout{ gap: 10px; }
}
