:root {
  --bg: #0e0d12;
  --panel: #18161f;
  --panel-2: #221f2b;
  --line: #2f2b3a;
  --text: #f1eee8;
  --muted: #8d8899;
  --accent: #ff5a36;
  --accent-2: #ffb547;
  --good: #3ddc84;
  --close: #ffc83d;
  --bad: #4a4556;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(255, 90, 54, 0.12), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }
.hidden { display: none !important; }

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}
h1 { font-size: 26px; margin: 0; letter-spacing: -0.03em; flex: 1; }
h1 .dot { color: var(--accent); }
.modes { display: flex; background: var(--panel); border-radius: 999px; padding: 3px; }
.mode { background: none; border: 0; padding: 6px 14px; border-radius: 999px; color: var(--muted); font-size: 14px; }
.mode.active { background: var(--panel-2); color: var(--text); }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 10px; width: 36px; height: 36px; font-size: 18px; }

main { max-width: 640px; width: 100%; margin: 0 auto; padding: 20px 16px 40px; flex: 1; }
.subtitle { color: var(--muted); text-align: center; margin: 4px 0 20px; font-size: 15px; }

/* ---------- player ---------- */
.player { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.timeline { position: relative; height: 14px; background: var(--panel-2); border-radius: 7px; overflow: hidden; }
.unlocked { position: absolute; inset: 0 auto 0 0; width: 0; background: rgba(255, 90, 54, 0.22); transition: width 0.35s ease; }
.playhead { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.ticks { position: absolute; inset: 0; }
.ticks span { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--bg); }
.controls { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; }
.time { color: var(--muted); font-size: 14px; min-width: 64px; }
.time:last-child { text-align: right; }
.play {
  width: 64px; height: 64px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 8px 30px rgba(255, 90, 54, 0.35);
  transition: transform 0.1s;
}
.play:active:not(:disabled) { transform: scale(0.94); }

/* ---------- guesses ---------- */
.guesses { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 8px; }
.guesses li {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); font-size: 15px;
}
.guesses li .badge { width: 10px; height: 10px; border-radius: 3px; flex: none; background: var(--line); }
.guesses li .len { margin-left: auto; color: var(--muted); font-size: 12px; }
.guesses li.wrong .badge { background: var(--bad); }
.guesses li.close .badge { background: var(--close); }
.guesses li.right .badge { background: var(--good); }
.guesses li.skip { color: var(--muted); font-style: italic; }
.guesses li.empty { border-style: dashed; background: none; }
.guesses li.new { animation: pop 0.35s ease-out; }
@keyframes pop {
  0% { transform: scale(0.96); background: var(--panel-2); border-color: var(--accent); }
  100% { transform: scale(1); }
}
#guessInput.shake { animation: shake 0.3s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
@media (prefers-reduced-motion: reduce) {
  .guesses li.new, #guessInput.shake { animation: none; }
}

/* ---------- input ---------- */
.combo { position: relative; }
#guessInput {
  width: 100%; padding: 14px 16px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; outline: none;
}
#guessInput:focus { border-color: var(--accent); }
.suggestions {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px);
  list-style: none; margin: 0; padding: 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  max-height: 320px; overflow-y: auto; z-index: 10;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
}
.suggestions:empty { display: none; }
.suggestions li { padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.suggestions li small { color: var(--muted); }
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--line); }
.buttons { display: flex; gap: 10px; margin-top: 10px; }
.buttons button { flex: 1; }
.primary, .secondary { padding: 12px 18px; border-radius: 12px; font-weight: 500; border: 1px solid var(--line); }
.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.secondary { background: var(--panel); }
.skip-plus { color: #ff4d4d; font-weight: 700; margin-left: 4px; }
.len-right { color: var(--good); font-weight: 700; }

/* ---------- result ---------- */
.result {
  display: flex; gap: 18px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-top: 16px;
}
.result img { width: 120px; height: 120px; border-radius: 10px; flex: none; object-fit: cover; background: var(--panel-2); }
.result .meta { min-width: 0; flex: 1; }
.verdict { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.verdict.win { color: var(--good); }
.result h2 { margin: 4px 0 2px; font-size: 22px; line-height: 1.2; overflow-wrap: anywhere; }
.result p { margin: 0; }
#songArtist { color: var(--muted); }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.result-actions button { padding: 8px 12px; font-size: 14px; }
.countdown { color: var(--muted); font-size: 13px; margin-top: 10px !important; }

/* ---------- stats ---------- */
dialog {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  width: min(420px, calc(100vw - 32px)); padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin-top: 0; }
dialog h3 { font-size: 14px; color: var(--muted); font-weight: 500; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 8px; }
.stat-grid b { display: block; font-size: 26px; }
.stat-grid span { font-size: 12px; color: var(--muted); }
.bar { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 13px; }
.bar .lbl { width: 40px; color: var(--muted); }
.bar .fill { background: var(--panel-2); padding: 2px 6px; border-radius: 4px; min-width: 22px; text-align: right; }
.bar .fill.hi { background: var(--accent); }
dialog form { margin-top: 16px; }
dialog form button { width: 100%; }

.toast {
  position: fixed; left: 50%; top: 20px; transform: translate(-50%, -20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: 0.2s; font-weight: 500;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }

@media (max-width: 480px) {
  header { padding: 12px 16px; gap: 10px; flex-wrap: wrap; }
  header .modes { order: 3; width: 100%; justify-content: space-between; }
  h1 { font-size: 22px; }
  .mode { padding: 6px 10px; font-size: 13px; }
  .buttons { gap: 8px; }
  .buttons button { padding: 12px 8px; font-size: 15px; }
  .result { flex-direction: column; text-align: center; }
  .result-actions { justify-content: center; }
}

/* ---------- reveal popup (after each round) ---------- */
dialog.reveal { text-align: center; width: min(380px, calc(100vw - 32px)); }
dialog.reveal[open] { animation: reveal-in 0.25s ease-out; }
@keyframes reveal-in { from { opacity: 0; transform: translateY(12px) scale(0.97); } }
.reveal .verdict { margin: 0 0 14px; }
.reveal-art { position: relative; width: 220px; max-width: 70vw; aspect-ratio: 1; margin: 0 auto; }
.reveal-art img { width: 100%; height: 100%; border-radius: 12px; object-fit: cover; background: var(--panel-2); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5); }
.reveal-play {
  position: absolute; right: 10px; bottom: 10px; width: 52px; height: 52px; border-radius: 50%;
  border: 0; background: var(--accent); color: #fff; display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(255, 90, 54, 0.45);
}
.reveal h2 { margin: 16px 0 2px; font-size: 22px; line-height: 1.2; overflow-wrap: anywhere; }
.reveal-artist { margin: 0; color: var(--muted); }
.reveal-progress { height: 4px; background: var(--panel-2); border-radius: 2px; margin: 16px 0; overflow: hidden; }
.reveal-progress div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.reveal-actions { display: flex; gap: 10px; }
.reveal-actions button { flex: 1; }
@media (prefers-reduced-motion: reduce) { dialog.reveal[open] { animation: none; } }

/* ---------- celebration ---------- */
/* Shown as a popover so it sits in the top layer, above the modal popup. */
#confetti {
  position: fixed; inset: 0; width: 100vw; height: 100vh; margin: 0; padding: 0;
  border: 0; background: transparent; pointer-events: none; z-index: 1000;
}
#confetti:not(:popover-open) { display: none; }
.reveal .cheer {
  margin: 0 0 4px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15;
  background: linear-gradient(90deg, var(--good), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: cheer-in 0.5s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes cheer-in { from { transform: scale(0.4); opacity: 0; } }
.reveal .streak { margin: -8px 0 14px; font-size: 14px; color: var(--accent-2); font-weight: 500; }
dialog.reveal.won { border-color: var(--good); box-shadow: 0 0 0 1px var(--good), 0 0 60px rgba(61, 220, 132, 0.25); }
dialog.reveal.won .reveal-art img { animation: cover-bounce 0.7s cubic-bezier(0.2, 1.8, 0.4, 1); box-shadow: 0 0 0 3px var(--good), 0 16px 50px rgba(61, 220, 132, 0.35); }
@keyframes cover-bounce { 0% { transform: scale(0.6) rotate(-6deg); } 100% { transform: scale(1) rotate(0); } }
.guesses li.right.new { animation: right-flash 0.8s ease-out; }
@keyframes right-flash { 0% { background: rgba(61, 220, 132, 0.45); transform: scale(1.03); } 100% { background: var(--panel); transform: scale(1); } }
@media (prefers-reduced-motion: reduce) {
  .reveal .cheer, dialog.reveal.won .reveal-art img, .guesses li.right.new { animation: none; }
}

/* ---------- duel ---------- */
main.duel-screen .player, main.duel-screen #guesses, main.duel-screen #inputRow, main.duel-screen #result { display: none !important; }
.duel-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.duel-panel h2 { margin: 0 0 6px; font-size: 24px; letter-spacing: -0.02em; }
.duel-panel p { color: var(--muted); margin: 0 0 16px; line-height: 1.45; }
.duel-panel label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.duel-panel input[type="text"] {
  width: 100%; padding: 12px 14px; font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; outline: none;
}
.duel-panel input[type="text"]:focus { border-color: var(--accent); }
.pool-pick { display: flex; gap: 8px; }
.pool-pick button { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--muted); }
.pool-pick button.active { border-color: var(--accent); color: var(--text); background: var(--panel-2); }
.duel-panel .primary { width: 100%; margin-top: 18px; }
.duel-actions { display: flex; gap: 10px; margin-top: 18px; }
.duel-actions button { flex: 1; margin-top: 0 !important; }
.players-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 6px; }
.players-list span { background: var(--panel-2); border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.duel-banner { font-size: 26px; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.02em; }
.duel-banner.win { background: linear-gradient(90deg, var(--good), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.scoreboard { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
.scoreboard th { color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 4px; text-align: center; }
.scoreboard th:first-child, .scoreboard td:first-child { text-align: left; }
.scoreboard td { padding: 9px 4px; border-top: 1px solid var(--line); text-align: center; }
.scoreboard td.total { font-weight: 700; font-size: 16px; }
.scoreboard tr.me td:first-child { color: var(--accent-2); font-weight: 700; }
.scoreboard tr.leader td.total { color: var(--good); }
.scoreboard .p0 { color: var(--bad); }
.duel-songs { margin: 14px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.duel-songs li { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.duel-songs img { width: 36px; height: 36px; border-radius: 6px; }
.duel-songs small { color: var(--muted); }
@media (max-width: 480px) { .scoreboard { font-size: 13px; } .scoreboard td, .scoreboard th { padding: 7px 2px; } }

/* ---------- stats in header + popup ---------- */
.stats-btn { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; font-size: 14px; font-weight: 500; }
.reveal-stats { margin: 4px 0 16px; text-align: left; }
.reveal-stats .stat-grid b { font-size: 20px; }
.reveal-dist { margin-top: 10px; }
.reveal-dist .bar { margin: 2px 0; font-size: 12px; }
.reveal-dist .bar .lbl { width: 34px; }
@media (max-width: 480px), (max-height: 760px) {
  .reveal-art { width: 150px; }
  .reveal h2 { margin-top: 10px; font-size: 19px; }
  .reveal-progress { margin: 10px 0; }
}
