:root {
  --bg: #07070f;
  --bg-2: #0d0d1a;
  --panel: rgba(20, 20, 38, 0.72);
  --line: rgba(120, 140, 255, 0.16);
  --text: #e8ecff;
  --muted: #8b93c7;
  --accent: #22d3ee;
  --accent-2: #a855f7;
  --good: #22c55e;
  --bad: #ef4444;
  --cell: 30px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(1100px 600px at 15% -10%, rgba(34, 211, 238, 0.13), transparent 60%),
    radial-gradient(900px 700px at 100% 0%, rgba(168, 85, 247, 0.14), transparent 55%),
    radial-gradient(700px 500px at 50% 120%, rgba(34, 197, 94, 0.1), transparent 60%),
    var(--bg);
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  max-width: 1180px;
  margin: 0 auto;
}

.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.brand {
  font-family: "Press Start 2P", monospace;
  font-size: 18px;
  letter-spacing: 1px;
  color: var(--text);
  text-shadow: 0 0 18px rgba(34, 211, 238, 0.55);
  user-select: none;
}

.brand span {
  color: var(--accent);
  margin-left: 6px;
}

.music-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 7px 10px;
  backdrop-filter: blur(8px);
}

.track-info {
  display: flex;
  flex-direction: column;
  min-width: 130px;
  line-height: 1.1;
}

.track-label {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--muted);
}

.track-info b {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover { background: rgba(34, 211, 238, 0.14); border-color: rgba(34, 211, 238, 0.5); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.off { opacity: 0.4; color: var(--muted); }

.vol { width: 84px; accent-color: var(--accent); cursor: pointer; }

.layout {
  display: grid;
  grid-template-columns: auto auto auto auto;
  gap: 16px;
  align-items: start;
  justify-content: center;
  width: 100%;
}

.stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 128px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  backdrop-filter: blur(8px);
}

.stat span {
  display: block;
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat b {
  font-family: "Press Start 2P", monospace;
  font-size: 15px;
  color: var(--text);
  display: block;
  transition: color 0.2s ease, transform 0.12s ease;
}

.stat b.pop { color: var(--accent); transform: scale(1.09); }

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

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px 12px;
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.panel h2 {
  margin: 0;
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--muted);
  font-weight: 500;
}

.panel canvas { display: block; }

.board-area { display: flex; justify-content: center; }

.board-wrap {
  position: relative;
  border-radius: 18px;
  padding: 10px;
  background: linear-gradient(180deg, rgba(30, 32, 64, 0.85), rgba(10, 10, 22, 0.92));
  border: 1px solid rgba(120, 140, 255, 0.35);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.5),
    0 18px 50px rgba(0, 0, 0, 0.6),
    0 0 46px rgba(34, 211, 238, 0.12);
}

#board { display: block; border-radius: 8px; }

.overlay {
  position: absolute;
  inset: 10px;
  border-radius: 8px;
  display: none;
  place-items: center;
  background: rgba(6, 6, 15, 0.86);
  backdrop-filter: blur(6px);
  text-align: center;
  padding: 16px;
  z-index: 5;
}

.overlay.show { display: grid; }
.screen { display: none; flex-direction: column; align-items: center; gap: 16px; width: 100%; }
.screen.active { display: flex; }

.mega-title {
  font-family: "Press Start 2P", monospace;
  font-size: clamp(24px, 7vw, 40px);
  line-height: 1.35;
  margin: 0;
  color: var(--text);
  text-shadow: 0 0 24px rgba(34, 211, 238, 0.7), 0 0 60px rgba(168, 85, 247, 0.5);
}

.mega-sub {
  font-family: "Press Start 2P", monospace;
  font-size: clamp(20px, 6vw, 32px);
  margin: 0;
  color: var(--accent);
  text-shadow: 0 0 22px rgba(34, 211, 238, 0.7);
  line-height: 1.4;
}

.mega-sub.over {
  color: var(--bad);
  text-shadow: 0 0 22px rgba(239, 68, 68, 0.7);
}

.tagline { margin: 0; color: var(--muted); font-size: 13px; }

.btn {
  font-family: "Press Start 2P", monospace;
  font-size: 13px;
  padding: 14px 24px;
  border-radius: 14px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  color: #04121a;
  box-shadow: 0 8px 26px rgba(34, 211, 238, 0.35);
}

.btn.primary:hover { box-shadow: 0 10px 32px rgba(34, 211, 238, 0.55); }
.btn.primary:active { transform: translateY(2px) scale(0.98); }

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}
.btn.ghost:hover { background: rgba(255, 255, 255, 0.06); }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.mini-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  justify-content: center;
  max-width: 320px;
  color: var(--muted);
  font-size: 11px;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  max-width: 260px;
}

.result-grid div {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
}

.result-grid span { display: block; font-size: 9px; letter-spacing: 2px; color: var(--muted); }
.result-grid b { font-family: "Press Start 2P", monospace; font-size: 14px; color: var(--accent); }

.new-best {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  font-size: 12px;
  color: #facc15;
  text-shadow: 0 0 16px rgba(250, 204, 21, 0.8);
  animation: blink 0.7s steps(2, start) infinite;
}

.hidden { display: none !important; }

@keyframes blink { 50% { opacity: 0.35; } }

.legend {
  color: var(--muted);
  font-size: 11.5px;
  text-align: center;
  line-height: 2;
}

kbd {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 10.5px;
  color: var(--text);
}

.touch { display: none; width: 100%; max-width: 460px; gap: 8px; }
.touch button {
  flex: 1;
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 19px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition: transform 0.06s ease, background 0.12s ease;
}
.touch button:active { transform: scale(0.93); background: rgba(34, 211, 238, 0.22); }

@media (pointer: coarse), (max-width: 760px) {
  .touch { display: flex; flex-wrap: wrap; }
}

@media (max-width: 760px) {
  #app { gap: 9px; padding: 9px 9px calc(9px + env(safe-area-inset-bottom)); }
  .brand { font-size: 13px; }
  .music-bar { width: 100%; justify-content: space-between; padding: 6px 8px; gap: 5px; }
  .track-info { min-width: 0; flex: 1; }
  .vol { width: 58px; }

  .layout {
    display: grid;
    grid-template-columns: repeat(2, min-content);
    justify-content: center;
    gap: 9px;
    width: 100%;
  }

  .stats {
    grid-column: 1 / -1;
    flex-direction: row;
    width: 100%;
    gap: 6px;
  }

  .stat { flex: 1; padding: 6px 8px; border-radius: 11px; }
  .stat b { font-size: 12px; }

  .side { flex-direction: row; gap: 8px; }
  .hold-side { order: 1; }
  .next-side { order: 1; }
  .panel { padding: 7px 8px 8px; border-radius: 12px; }
  .panel h2 { font-size: 8px; }

  .board-area { order: 2; grid-column: 1 / -1; }
  .legend { display: none; }
}
