:root {
  --bg: #0f0e17;
  --surface: #1a1926;
  --surface-2: #242335;
  --border: #33324a;
  --text: #f4f3fa;
  --muted: #9d9bb5;
  --accent: #1ed760;
  --accent-ink: #062b13;
  --warn: #ffb547;
  --bad: #ff5d73;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.brand { color: var(--text); font-weight: 800; letter-spacing: -0.02em; text-decoration: none; }
.tag { font: 600 13px/1 ui-monospace, Menlo, monospace; background: var(--surface-2); padding: 6px 10px; border-radius: 999px; }

main { max-width: 880px; margin: 0 auto; padding: 28px 16px 64px; }
h1 { font-size: clamp(30px, 6vw, 48px); line-height: 1.1; letter-spacing: -0.03em; margin: 12px 0 14px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.accent { color: var(--accent); }
.lede { color: var(--muted); max-width: 560px; margin: 0 0 28px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.mono { font-family: ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }
.error { color: var(--bad); min-height: 1.5em; margin: 10px 0 0; font-size: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
.narrow { max-width: 440px; }
.view > .narrow { margin-left: auto; margin-right: auto; }
#view-home .narrow { margin-left: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + * { margin-top: 16px; }
@media (max-width: 680px) { .grid2 { grid-template-columns: 1fr; } }

.row { display: flex; gap: 8px; align-items: stretch; }
.row > input { flex: 1; min-width: 0; }
.field { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.field > input, .field > select, .field .row { margin-top: 6px; }
.settings .field { flex: 1; }

input, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 12px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
input:disabled { opacity: 0.5; }
.code-input { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 700; text-align: center; }

.btn {
  font: 600 15px/1 inherit; font-family: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 16px; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.wide { width: 100%; }

.hint { margin: -6px 0 14px; }

.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* Lobby */
.lobby-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.big-code { font: 800 44px/1 ui-monospace, Menlo, monospace; letter-spacing: 0.12em; }
.players { list-style: none; margin: 0; padding: 0; }
.players li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-top: 1px solid var(--border);
}
.players li:first-child { border-top: 0; }
.players .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .off { opacity: 0.45; }
.players .status { font-size: 13px; color: var(--muted); }
.players .status.ok { color: var(--accent); }
.players .status.bad { color: var(--bad); }
.players .score { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3ch; text-align: right; }
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--warn); }
.you { color: var(--muted); font-size: 13px; }

.playlist { display: flex; align-items: center; gap: 12px; margin: 0 0 14px; }
.playlist img { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.playlist b { display: block; }
.how ol { margin: 0; padding-left: 20px; color: var(--muted); }
.how li { margin: 4px 0; }
.how b { color: var(--text); }

/* Round */
.round-head { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; margin-bottom: 8px; }
.timebar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
#timeFill { height: 100%; width: 100%; background: var(--accent); transform-origin: left; }
#timeFill.low { background: var(--bad); }

.stages { list-style: none; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; padding: 0; margin: 0 0 18px; }
.stages li {
  text-align: center; font: 700 14px/1 ui-monospace, Menlo, monospace;
  padding: 10px 0; border-radius: 8px; background: var(--surface-2); color: var(--muted);
  border: 1px solid transparent;
}
.stages li.past { color: var(--bad); text-decoration: line-through; opacity: 0.7; }
.stages li.current { color: var(--text); border-color: var(--accent); }
.stages li.won { background: var(--accent); color: var(--accent-ink); }

.player { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.play {
  flex: none; width: 64px; height: 64px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.play:disabled { opacity: 0.4; cursor: not-allowed; }
.play:active:not(:disabled) { transform: scale(0.96); }
.clip { flex: 1; min-width: 0; }
.clipbar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
#clipFill { height: 100%; width: 0; background: var(--text); }

.guess-row { display: flex; gap: 8px; }
.ac { position: relative; flex: 1; min-width: 0; }
.suggestions {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px);
  list-style: none; margin: 0; padding: 4px; max-height: 320px; overflow-y: auto;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.suggestions li { padding: 9px 10px; border-radius: 7px; cursor: pointer; }
.suggestions li.active, .suggestions li:hover { background: var(--border); }
.suggestions .a { color: var(--muted); font-size: 13px; }
.suggestions .empty { color: var(--muted); cursor: default; }

.guesses { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 6px; }
.guesses li { font-size: 14px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); }
.guesses .wrong { color: var(--bad); }
.guesses .skip { color: var(--muted); }
.guesses .correct { color: var(--accent); }
.done-note { margin-top: 14px; padding: 12px; border-radius: 10px; background: var(--surface-2); text-align: center; font-weight: 600; }

/* Reveal & results */
.reveal { display: flex; gap: 18px; align-items: center; }
.reveal img { width: 120px; height: 120px; border-radius: 10px; object-fit: cover; background: var(--surface-2); flex: none; }
.reveal h2 { font-size: 24px; margin: 2px 0; }
.reveal a { color: var(--accent); display: inline-block; margin-top: 6px; }
.results { list-style: none; padding: 0; margin: 0; counter-reset: r; }
.results li {
  counter-increment: r; display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-top: 1px solid var(--border);
}
.results li:first-child { border-top: 0; }
.results li::before { content: counter(r); width: 1.6em; color: var(--muted); font-weight: 700; }
.results .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .detail { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.results .pts { font-weight: 700; min-width: 4ch; text-align: right; font-variant-numeric: tabular-nums; }
.results .pts.plus { color: var(--accent); }
.final li { padding: 12px 0; font-size: 18px; }
.final li:first-child .name { color: var(--accent); font-weight: 800; }
#nextBtn { display: block; margin: 0 auto; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

@media (max-width: 520px) {
  .guess-row { flex-direction: column; }
  .reveal img { width: 84px; height: 84px; }
  .big-code { font-size: 36px; }
}
