:root {
  color-scheme: dark;
  --bg: #090d16;
  --surface: rgba(22, 29, 45, 0.82);
  --surface-2: #1d2638;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f7f8fb;
  --muted: #aeb7c8;
  --accent: #ffcf4a;
  --accent-2: #ff7a55;
  --good: #61dfa8;
  --danger: #ff6b77;
  --radius: 22px;
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 122, 85, .2), transparent 32rem),
    radial-gradient(circle at 85% 80%, rgba(92, 110, 255, .18), transparent 34rem),
    var(--bg);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 18px max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.host-shell { width: min(100%, 1050px); }

.brand { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.brand-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.logo { font-weight: 950; letter-spacing: -.06em; font-size: 2rem; }
.logo span { color: var(--accent); }
.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  background: rgba(255,255,255,.04);
  font-size: .86rem;
}
button.pill { color: var(--muted); }

.dialog-open { overflow: hidden; }
.rules-dialog {
  width: min(calc(100% - 28px), 760px);
  max-height: min(88vh, 860px);
  padding: 0;
  color: var(--text);
  background: #111827;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 30px 100px rgba(0,0,0,.65);
  overflow: auto;
}
.rules-dialog::backdrop { background: rgba(3,6,12,.78); backdrop-filter: blur(7px); }
.rules-dialog.open { display: block; position: fixed; inset: 6vh auto auto 50%; transform: translateX(-50%); z-index: 1000; }
.rules-content { position: relative; padding: clamp(22px, 5vw, 38px); text-align: left; }
.rules-content h2 { margin: 6px 48px 24px 0; }
.rules-content h3 { margin-bottom: 10px; color: var(--accent); }
.rules-content ol, .rules-content ul { margin: 0; padding-left: 1.25rem; color: var(--muted); line-height: 1.55; }
.rules-content li + li { margin-top: 6px; }
.rules-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; margin-bottom: 28px; }
.rules-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  background: var(--surface-2);
  font-size: 1.6rem;
  line-height: 1;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(20px, 5vw, 34px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .28);
  backdrop-filter: blur(18px);
}

.center { text-align: center; }
.grow { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.eyebrow { color: var(--accent); font-weight: 850; text-transform: uppercase; letter-spacing: .12em; font-size: .78rem; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 8vw, 4.8rem); line-height: .98; letter-spacing: -.055em; }
h2 { font-size: clamp(1.55rem, 5vw, 2.4rem); letter-spacing: -.035em; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.field { display: grid; gap: 8px; margin: 18px 0; }
.field small { line-height: 1.4; }
.field label { color: var(--muted); font-weight: 700; font-size: .92rem; }
input, select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(5, 8, 14, .62);
  color: var(--text);
  border-radius: 16px;
  padding: 16px 17px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,207,74,.14); }
input.answer { font-size: 1.25rem; text-align: center; }
.answer-auto-hint { display: block; margin-top: 9px; text-align: center; line-height: 1.35; }

.primary, .secondary, .danger {
  border: 0;
  border-radius: 16px;
  padding: 15px 20px;
  font-weight: 850;
}
.primary { color: #17130a; background: linear-gradient(135deg, var(--accent), #ffad45); }
.secondary { color: var(--text); background: var(--surface-2); border: 1px solid var(--line); }
.danger { color: white; background: rgba(255,107,119,.18); border: 1px solid rgba(255,107,119,.3); }
.wide { width: 100%; }
.action-link { display: inline-block; text-align: center; text-decoration: none; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.landing-shell { width: min(100%, 980px); }
.landing-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 28px; text-align: left; }
.landing-option { display: flex; flex-direction: column; padding: 24px; border: 1px solid var(--line); border-radius: 20px; background: rgba(255,255,255,.035); }
.landing-option h2 { margin: 12px 0 8px; }
.landing-option p { flex: 1; line-height: 1.45; }
.landing-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 15px; color: #17130a; background: var(--accent); font-size: 1.35rem; font-weight: 950; }
.landing-option form { display: grid; gap: 10px; }
.session-code-input { text-align: center; text-transform: uppercase; letter-spacing: .2em; font-size: 1.35rem; font-weight: 900; }

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(190px, 1fr));
  gap: 14px;
  width: min(100%, 680px);
  margin: 24px auto 14px;
  text-align: left;
}
.setup-grid .field { margin: 0; }
.playlist-field { grid-column: 1 / -1; }
.spotify-setup {
  display: grid;
  grid-template-columns: minmax(250px, 1fr) auto;
  align-items: end;
  gap: 12px;
  width: min(100%, 680px);
  margin: 0 auto 18px;
  text-align: left;
}
.spotify-test {
  width: min(100%, 680px);
  margin: 0 auto 18px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.035);
  text-align: left;
}
.spotify-test p { margin-bottom: 12px; font-weight: 800; }
.spotify-test .button-row { margin-bottom: 10px; }
.spotify-test a { color: var(--accent); }
.spotify-status {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(100%, 680px);
  margin: 0 auto 18px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.035);
  text-align: left;
}
.spotify-status span { display: grid; gap: 3px; }
.spotify-status small { color: var(--muted); line-height: 1.35; }
.spotify-status-dot { width: 12px; height: 12px; flex: 0 0 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 5px rgba(255,207,74,.11); }
.spotify-status.ready { border-color: rgba(97,223,168,.35); background: rgba(97,223,168,.07); }
.spotify-status.ready .spotify-status-dot { background: var(--good); box-shadow: 0 0 0 5px rgba(97,223,168,.11); }
.spotify-status.failed { border-color: rgba(255,107,119,.35); background: rgba(255,107,119,.07); }
.spotify-status.failed .spotify-status-dot { background: var(--danger); box-shadow: 0 0 0 5px rgba(255,107,119,.11); }

.error { color: #ffd2d6; background: rgba(255,107,119,.14); border: 1px solid rgba(255,107,119,.28); border-radius: 14px; padding: 12px 14px; }
.success { color: var(--good); }

.timer {
  --progress: 100%;
  width: min(54vw, 220px);
  aspect-ratio: 1;
  margin: 20px auto 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--accent) var(--progress), rgba(255,255,255,.08) 0);
  position: relative;
}
.timer::after { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: #111827; }
.timer span { position: relative; z-index: 1; font-size: clamp(2.8rem, 13vw, 5rem); font-weight: 950; letter-spacing: -.06em; }
.timer.urgent { background: conic-gradient(var(--danger) var(--progress), rgba(255,255,255,.08) 0); }

.question { text-align: center; font-size: clamp(1.8rem, 7vw, 3.6rem); letter-spacing: -.04em; }
.question small { display: block; margin-bottom: 8px; color: var(--muted); font-size: .9rem; letter-spacing: .1em; text-transform: uppercase; }

.score-list, .player-list, .answer-list { display: grid; gap: 9px; padding: 0; list-style: none; }
.score-row, .player-row, .answer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.035);
}
.score-row.me { border-color: rgba(255,207,74,.55); background: rgba(255,207,74,.08); }
.score { color: var(--accent); font-weight: 950; font-size: 1.1rem; }
.live-score-panel { width: min(100%, 520px); margin: 24px auto 0; text-align: left; }
.live-score-panel h3 { margin-bottom: 10px; text-align: center; }
.compact-score-list { max-height: 230px; overflow-y: auto; overscroll-behavior: contain; }
.compact-score-list .score-row { padding: 9px 12px; }
.final-results { width: min(100%, 620px); margin: 30px auto 0; text-align: left; }
.final-results h2 { text-align: center; }
.final-scoreboard { width: min(100%, 620px); margin: 26px auto; text-align: left; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); display: inline-block; margin-right: 8px; }
.dot.offline { background: #657085; }

.reveal-title { font-size: clamp(2rem, 8vw, 3.8rem); margin-bottom: 8px; }
.reveal-artist { color: var(--accent); font-size: 1.35rem; font-weight: 800; }
.reveal-year { color: var(--muted); font-size: 1.1rem; }
.points-burst { font-size: 2rem; font-weight: 950; color: var(--good); }

.host-progress { width: min(100%, 620px); margin: 28px auto 0; text-align: left; }
.host-progress h3 { text-align: center; }
.own-bingo-panel { width: min(100%, 430px); margin: 26px auto 0; }
.bingo-card {
  display: grid;
  grid-template-columns: repeat(var(--bingo-size, 3), minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}
.bingo-cell {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 7px 4px;
  overflow: hidden;
  color: var(--text);
  border: 2px solid rgba(255,255,255,.13);
  border-radius: 14px;
  background: rgba(255,255,255,.045);
}
.bingo-cell span { font-size: clamp(.68rem, 2.8vw, .9rem); font-weight: 850; }
.bingo-cell strong { position: absolute; font-size: clamp(3rem, 15vw, 5rem); line-height: 1; color: var(--text); opacity: .88; }
.bingo-cell:disabled { cursor: default; opacity: 1; }
.bingo-artist { border-color: rgba(97,223,168,.4); background: rgba(97,223,168,.08); }
.bingo-title { border-color: rgba(255,207,74,.4); background: rgba(255,207,74,.08); }
.bingo-year { border-color: rgba(255,122,85,.45); background: rgba(255,122,85,.09); }
.bingo-cell.marked span { opacity: .42; }
.bingo-cell.selectable { cursor: pointer; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,207,74,.14); animation: bingo-pulse 1.4s ease-in-out infinite; }
.bingo-cell.removable { cursor: pointer; border-color: var(--danger); box-shadow: 0 0 0 3px rgba(255,107,119,.12); }
.bingo-card.small { width: min(100%, 300px); gap: 5px; }
.bingo-card.small .bingo-cell { border-radius: 10px; padding: 3px; }
.bingo-card.small .bingo-cell span { font-size: .65rem; }
.bingo-card.small .bingo-cell strong { font-size: 2.8rem; }
.opponent-bingo { width: min(100%, 320px); padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.025); }
.opponent-bingo > strong { display: block; margin-bottom: 9px; }
@keyframes bingo-pulse { 50% { transform: scale(.97); } }

.lobby-grid { display: grid; grid-template-columns: minmax(260px, .8fr) 1.2fr; gap: 18px; }
.qr { width: min(100%, 360px); border-radius: 18px; background: white; padding: 10px; }
.code { font-size: clamp(2.5rem, 8vw, 5rem); letter-spacing: .12em; font-weight: 950; color: var(--accent); }
.host-status { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat { text-align: center; padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.03); }
.stat strong { display: block; font-size: 1.8rem; }
.space-hint { font-size: 1rem; font-weight: 800; color: var(--muted); }
kbd { color: var(--text); border: 1px solid rgba(255,255,255,.25); border-bottom-width: 3px; border-radius: 8px; padding: 4px 9px; background: rgba(255,255,255,.08); }

@media (max-width: 720px) {
  .lobby-grid { grid-template-columns: 1fr; }
  .host-status { grid-template-columns: 1fr; }
  .card { padding: 20px; }
  .setup-grid, .spotify-setup { grid-template-columns: 1fr; }
  .rules-grid { grid-template-columns: 1fr; gap: 20px; }
  .brand-actions { gap: 6px; }
  .brand-actions .pill { padding: 7px 9px; font-size: .78rem; }
  .landing-options { grid-template-columns: 1fr; }
}
