:root {
  --bg: #15121e;
  --surface: #1e1a2b;
  --surface-raised: #251f38;
  --border: #362f4a;
  --accent: #e8a33d;
  --accent-dim: #a67a34;
  --text: #f3efe6;
  --text-muted: #a49dbd;
  --success: #7fbf8f;
  --danger: #e2685c;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}

.scanline {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.015) 0px,
    rgba(255,255,255,0.015) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 1;
}

.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 100;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  row-gap: 8px;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 1.5rem 0.5rem;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.logo {
  height: 52px;
  width: auto;
  max-width: 60vw;
  display: block;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 16, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 50;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}
.modal-head h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 1.1rem;
  margin: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 1.5rem;
}
.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface-raised);
  border-radius: 10px;
  padding: 10px 4px;
}
.stat-num {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
}
.stat-label {
  font-size: 0.64rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 2px;
}

.howto-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.howto-steps li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  font-size: 0.86rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.howto-steps li strong { color: var(--text); }
.howto-num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #23180a;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.dist-title {
  font-size: 0.85rem;
  font-weight: 500;
  margin: 0 0 10px;
  color: var(--text-muted);
}
.dist-chart {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dist-row .dist-label {
  width: 16px;
  font-size: 0.78rem;
  color: var(--text-muted);
  flex-shrink: 0;
  text-align: right;
}
.dist-row .dist-bar-track {
  flex: 1;
  background: var(--surface-raised);
  border-radius: 6px;
  overflow: hidden;
  height: 20px;
}
.dist-row .dist-bar {
  height: 100%;
  background: var(--accent-dim);
  min-width: 22px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  border-radius: 6px;
}
.dist-row.fail .dist-bar { background: var(--danger); }
.dist-row .dist-count {
  font-size: 0.72rem;
  font-weight: 600;
  color: #23180a;
}

.date-pill {
  font-size: 0.75rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  text-transform: capitalize;
  width: 132px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-sizing: border-box;
  flex-shrink: 0;
}

.stage {
  flex: 1;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  z-index: 2;
}

.mode-tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}
.mode-tab {
  flex: 1;
  background: none;
  border: none;
  border-radius: 9px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 9px 0;
  cursor: pointer;
}
.mode-tab.active {
  background: var(--accent);
  color: #23180a;
}

.new-song-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0 auto;
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.new-song-btn:hover { border-color: var(--accent); color: var(--accent); }
.new-song-btn[hidden] { display: none; }

.dial-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.dial {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--surface-raised), var(--surface) 75%);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.35);
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}
.dial:has(.eq.playing) {
  border-color: rgba(232, 163, 61, 0.45);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.35), 0 0 24px rgba(232, 163, 61, 0.28);
}

.play-btn {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(155deg, #f2b458 0%, var(--accent) 55%, var(--accent-dim) 100%);
  color: #23180a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(232, 163, 61, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
#icon-play { position: relative; left: 1px; }
.play-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 20px rgba(232, 163, 61, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.play-btn:active {
  transform: scale(0.94);
  box-shadow: 0 2px 8px rgba(232, 163, 61, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.play-btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
  box-shadow: none;
}

.eq {
  position: absolute;
  bottom: -10px;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 16px;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.eq.playing { opacity: 1; }
.eq span {
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  animation: eq-bounce 0.9s ease-in-out infinite;
}
.eq span:nth-child(1) { animation-delay: 0s; height: 6px; }
.eq span:nth-child(2) { animation-delay: 0.15s; height: 14px; }
.eq span:nth-child(3) { animation-delay: 0.3s; height: 9px; }
.eq span:nth-child(4) { animation-delay: 0.1s; height: 16px; }
.eq span:nth-child(5) { animation-delay: 0.25s; height: 7px; }
@keyframes eq-bounce {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}

.progress-track {
  position: relative;
  width: 100%;
  height: 8px;
  background: var(--surface-raised);
  border-radius: 999px;
  overflow: visible;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 999px;
  box-shadow: 0 0 8px rgba(232, 163, 61, 0.45);
}
.progress-marks {
  position: absolute;
  inset: 0;
  display: flex;
}
.progress-marks span {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 14px;
  border-radius: 2px;
  background: rgba(243, 239, 230, 0.35);
  transform: translateX(-1px);
}

.progress-labels {
  position: relative;
  width: 100%;
  height: 14px;
  margin-top: -8px;
}
.progress-labels span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 0.62rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.progress-labels span:first-child { transform: translateX(0); }
.progress-labels span:last-child { transform: translateX(-100%); }

.stage-caption {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.stage-caption.result-message {
  color: var(--text);
  font-weight: 700;
  font-size: 0.95rem;
}

.time-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: -0.5rem;
}

.volume-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  width: 100%;
}
.mute-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  padding: 2px;
}
.mute-btn:hover { color: var(--accent); }

.volume-slider {
  flex: none;
  width: 96px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: var(--surface-raised);
  outline: none;
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 0 3px rgba(232, 163, 61, 0.18);
}
.volume-slider::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 0 3px rgba(232, 163, 61, 0.18);
}
.volume-slider::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--surface-raised);
}

.guess-panel { display: flex; flex-direction: column; gap: 0.75rem; }

#guess-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.input-wrap {
  position: relative;
  flex: 1 1 100%;
}

.guess-actions {
  display: flex;
  gap: 8px;
  flex: 1 1 100%;
}
.guess-actions button { flex: 1; }

#guess-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px 14px;
  font-size: 0.95rem;
  font-family: inherit;
}
#guess-input:focus {
  outline: none;
  border-color: var(--accent);
}
#guess-input:disabled { opacity: 0.5; }

.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  list-style: none;
  margin: 0;
  padding: 6px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 10;
}
.suggestions[hidden] { display: none; }
.suggestions li {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.suggestions li .s-artist { color: var(--text-muted); font-size: 0.82rem; }
.suggestions li:hover,
.suggestions li.active { background: var(--surface); }

#guess-btn {
  background: var(--accent);
  color: #23180a;
  border: none;
  border-radius: var(--radius);
  padding: 13px 18px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
}
#guess-btn:hover { transform: scale(1.02); }
#guess-btn:disabled { opacity: 0.5; cursor: default; transform: none; }

.skip-btn {
  background: var(--accent);
  color: #23180a;
  border: none;
  border-radius: var(--radius);
  padding: 13px 16px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.skip-btn:hover { transform: scale(1.02); }
.skip-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

.history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.history li.correct {
  border-color: var(--success);
  color: var(--text);
  font-weight: 700;
  font-size: 0.92rem;
}
.history li.wrong .mark { color: var(--danger); }
.history li .mark { font-weight: 600; width: 14px; text-align: center; }
.history li.correct .mark { color: var(--success); }

.result-card {
  display: none;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.result-card.show {
  display: flex;
}
.result-main {
  display: flex;
  align-items: center;
  gap: 14px;
}
.share-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: var(--accent);
  color: #23180a;
  border: none;
  border-radius: 10px;
  padding: 11px 0;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.share-btn:hover { transform: scale(1.01); }
.share-btn[hidden] { display: none; }

.countdown-row {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0;
}
.countdown-row span {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  color: var(--text);
}
.countdown-row[hidden] { display: none; }
.result-play {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #23180a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.result-play:hover { transform: scale(1.05); }
.result-play:disabled { opacity: 0.4; cursor: default; }

.result-art {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: var(--surface-raised);
  object-fit: cover;
  flex-shrink: 0;
}
.result-eyebrow {
  margin: 0 0 2px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}
.result-title { margin: 0; font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 1.05rem; }
.result-artist { margin: 2px 0 6px; color: var(--text-muted); font-size: 0.88rem; }
.result-link { color: var(--accent); font-size: 0.82rem; text-decoration: none; }
.result-link:hover { text-decoration: underline; }

.status-line {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  min-height: 1.2em;
  margin: 0;
}

.retry-btn {
  display: block;
  margin: 10px auto 0;
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.retry-btn:hover { border-color: var(--accent); color: var(--accent); }
.retry-btn[hidden] { display: none; }

.foot {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  z-index: 2;
}
.foot .copyright {
  margin-top: 6px;
  opacity: 0.7;
}

@media (max-width: 420px) {
  .stage { padding: 1rem; }
}
