:root {
  --bg: #16130f;
  --panel: #221d17;
  --panel-2: #2c251d;
  --line: #3a3127;
  --text: #f6efe4;
  --muted: #a89a86;
  --amber: #f4a51c;
  --amber-deep: #c97d05;
  --go: #2fbf71;
  --go-deep: #1d8a4f;
  --bad: #e5484d;
  --bad-deep: #a8282d;
  --idle: #4a4036;
  --radius: 18px;
  --display: "Archivo Black", "Arial Black", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .35; cursor: default; }
input {
  font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; width: 100%;
}
input:focus { outline: 2px solid var(--amber); outline-offset: 1px; }
h1, h3 { font-family: var(--display); font-weight: 400; letter-spacing: .01em; }
h1 { font-size: 1.6rem; margin: 0 0 18px; }
h3 { font-size: 1rem; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--bad); margin: 0; }

/* top bar */
.bar {
  display: flex; align-items: center; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--display); color: var(--amber); font-size: 1.25rem; }
.who { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; font-size: .85rem; font-weight: 600;
}

.notice {
  margin: 16px; padding: 14px 16px; border-radius: 12px;
  background: #3b2a10; border: 1px solid var(--amber-deep); color: #ffd99a;
}

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
}
.join { max-width: 420px; margin: 32px auto; margin-inline: 16px; }
@media (min-width: 460px) { .join { margin-inline: auto; } }
.join form { display: grid; gap: 14px; }
.join label { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
.code-input { font-family: var(--display); font-size: 1.8rem; letter-spacing: .3em; text-transform: uppercase; text-align: center; }

.btn {
  border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 12px; padding: 12px 16px; font-weight: 700;
}
.btn.big { padding: 16px 20px; font-size: 1.1rem; }
.btn.primary { background: var(--amber); color: #1a1206; border-color: var(--amber-deep); }
.btn.go { background: var(--go); color: #06150c; border-color: var(--go-deep); }
.btn.bad { background: transparent; color: var(--bad); border-color: var(--bad-deep); }

/* ---------------- player buzzer ---------------- */
body.player { display: flex; flex-direction: column; min-height: 100dvh; overflow: hidden; }
#buzzView { flex: 1; display: flex; flex-direction: column; }
.buzz-wrap { flex: 1; display: grid; place-items: center; padding: 16px; }
.buzzer {
  width: min(78vw, 50vh, 380px); aspect-ratio: 1; border-radius: 50%;
  border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  background: var(--idle); color: #d7cbb9;
  box-shadow: 0 14px 0 #2a241e, 0 24px 40px rgba(0,0,0,.45);
  transition: transform .06s, box-shadow .06s, background .15s;
}
.buzzer:active { transform: translateY(8px); box-shadow: 0 6px 0 #2a241e, 0 12px 24px rgba(0,0,0,.4); }
.buzz-label { font-family: var(--display); font-size: clamp(1.8rem, 9vw, 3.2rem); line-height: 1; text-align: center; padding: 0 12px; }
.buzz-sub { font-weight: 600; font-size: 1rem; min-height: 1.2em; text-align: center; padding: 0 20px; }

.buzzer.is-open { background: var(--go); color: #06150c; box-shadow: 0 14px 0 var(--go-deep), 0 24px 50px rgba(47,191,113,.35); animation: pulse 1.2s ease-in-out infinite; }
.buzzer.is-buzzed { background: var(--amber-deep); color: #1a1206; box-shadow: 0 14px 0 #7a4b02; }
.buzzer.is-won { background: var(--amber); color: #1a1206; box-shadow: 0 14px 0 var(--amber-deep), 0 0 80px rgba(244,165,28,.6); }
.buzzer.is-excluded, .buzzer.is-penalty { background: var(--bad); color: #fff; box-shadow: 0 14px 0 var(--bad-deep); }
@keyframes pulse { 50% { filter: brightness(1.12); } }

.player-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.player-foot b { font-family: var(--display); color: var(--amber); font-size: 1.2rem; }

/* ---------------- host ---------------- */
.host-grid {
  display: grid; gap: 16px; padding: 16px;
  grid-template-columns: 1fr;
}
@media (min-width: 1000px) { .host-grid { grid-template-columns: 280px 1fr 320px; align-items: start; } }

.joinbox { text-align: center; }
.join-url { font-weight: 800; font-size: 1.1rem; margin: 4px 0 12px; word-break: break-all; }
.room-code { font-family: var(--display); font-size: 3.6rem; letter-spacing: .12em; color: var(--amber); line-height: 1; margin-bottom: 16px; }
.qr { display: inline-block; background: #fff; padding: 10px; border-radius: 12px; }
.qr img, .qr canvas { display: block; max-width: 100%; height: auto; }

.stage-top { display: flex; align-items: center; gap: 12px; }
.stage-top .muted { flex: 1; font-weight: 600; }
.pill { border-radius: 999px; padding: 6px 14px; font-weight: 800; font-size: .85rem; text-transform: uppercase; background: var(--idle); }
.pill.is-open { background: var(--go); color: #06150c; }
.pill.is-locked { background: var(--amber); color: #1a1206; }
.timer { font-family: var(--display); font-size: 1.4rem; min-width: 3ch; text-align: right; }

.winner {
  margin: 18px 0; min-height: 150px; border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--panel-2); border: 2px dashed var(--line); text-align: center; padding: 16px;
}
.winner.has { background: var(--amber); border: 0; color: #1a1206; }
.w-name { font-family: var(--display); font-size: clamp(2rem, 6vw, 4.2rem); line-height: 1.05; }
.w-team { font-weight: 800; font-size: 1.2rem; margin-top: 6px; }

.controls { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); }
.controls #btnOpen { grid-column: 1 / -1; }

.order { margin: 0; padding-left: 1.4em; display: grid; gap: 6px; }
.order li { font-weight: 600; }
.delta { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; margin-left: 6px; }
.struck { text-decoration: line-through; opacity: .55; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--panel-2); }
.list .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list b { font-family: var(--display); color: var(--amber); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--go); flex: none; }
.list li.off .dot { background: var(--idle); }
.x { background: none; border: 0; color: var(--muted); font-size: 1.2rem; line-height: 1; padding: 0 4px; }
.x:hover { color: var(--bad); }

.settings { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.settings summary { font-weight: 800; cursor: pointer; }
.settings label { display: grid; gap: 4px; margin: 12px 0; font-size: .9rem; }
.settings label.check { display: flex; gap: 10px; align-items: flex-start; }
.settings label.check input { width: auto; margin-top: 2px; }
.settings .btn { width: 100%; margin-top: 8px; }

/* brand logo in the top bar */
.logo { height: 40px; width: auto; display: block; flex: none; }
body.host .logo { height: 48px; }

/* reaction times — host list */
.order li { display: flex; align-items: baseline; gap: 10px; }
.order .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order .rt { font-family: var(--display); color: var(--amber); font-variant-numeric: tabular-nums; }
.order .delta { min-width: 7ch; text-align: right; margin-left: 0; }

/* reaction times — player panel */
.stats {
  margin: 0 16px 12px; padding: 12px 14px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line);
  display: grid; gap: 4px; text-align: center;
}
.stats .st-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stats .st-time { font-family: var(--display); font-size: 1.8rem; color: var(--amber); line-height: 1.1; }
.stats .st-line { font-weight: 600; }
.stats .st-faster { color: var(--muted); font-size: .9rem; }
.stats .st-faster b { color: var(--text); font-weight: 600; }
.order { list-style: none; padding-left: 0; }
.order .rank { color: var(--muted); min-width: 2ch; font-variant-numeric: tabular-nums; }

/* late window: someone already won, press to record your time */
.buzzer.is-late { background: var(--go-deep); color: #fff; box-shadow: 0 14px 0 #125b33, 0 24px 40px rgba(0,0,0,.45); }

/* ================= answer countdown ================= */
.winner { position: relative; overflow: hidden; transition: background .2s; }
.ans-num {
  font-family: var(--display); line-height: 1; margin-top: 12px;
  font-size: clamp(4rem, 12vw, 9rem); font-variant-numeric: tabular-nums;
  text-shadow: 0 4px 0 rgba(0,0,0,.18);
}
.ans-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 12px; background: rgba(0,0,0,.18); }
.ans-bar i { display: block; height: 100%; width: 100%; background: #1a1206; transition: width .1s linear; }

/* 5 s left: hot orange, heartbeat */
.winner.has.warn { background: #ff7a00; }
.winner.has.warn .ans-num { animation: beat .5s ease-in-out infinite; }

/* 3 s left: red/white strobe, shake, glow */
.winner.has.crit { animation: strobe .25s steps(1) infinite, shake .3s linear infinite; box-shadow: 0 0 60px 10px rgba(229,72,77,.6); }
.winner.has.crit .ans-num { animation: beat .25s ease-in-out infinite; }
.winner.has.crit .ans-bar i { background: #fff; }

/* time's up */
.winner.has.timeup { background: var(--bad); color: #fff; animation: strobe-up .5s steps(1) infinite; }
.winner.has.timeup .ans-num { font-size: clamp(2.6rem, 7vw, 5.5rem); }

@keyframes beat { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }
@keyframes strobe { 0% { background: #e5484d; color: #fff; } 50% { background: #fff; color: #e5484d; } }
@keyframes strobe-up { 0% { background: #e5484d; } 50% { background: #7a1418; } }
@keyframes shake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  25% { transform: translate(-4px, 1px) rotate(-.4deg); }
  75% { transform: translate(4px, -1px) rotate(.4deg); }
}

/* winner's phone */
.ans-big { display: block; font-family: var(--display); font-size: clamp(3rem, 18vw, 5.5rem); line-height: 1; }
.buzzer.is-won.ans-warn { background: #ff7a00; box-shadow: 0 14px 0 #b35500, 0 0 80px rgba(255,122,0,.6); }
.buzzer.is-won.ans-warn .ans-big { animation: beat .5s ease-in-out infinite; }
.buzzer.is-won.ans-crit { animation: strobe .25s steps(1) infinite, shake .3s linear infinite; box-shadow: 0 14px 0 var(--bad-deep), 0 0 90px rgba(229,72,77,.7); }
.buzzer.is-won.ans-crit .ans-big { animation: beat .25s ease-in-out infinite; }
.buzzer.is-won.ans-timeup { background: var(--bad); color: #fff; box-shadow: 0 14px 0 var(--bad-deep); animation: strobe-up .5s steps(1) infinite; }
.buzzer.is-won.ans-timeup .ans-big { font-size: clamp(1.6rem, 9vw, 2.6rem); }

@media (prefers-reduced-motion: reduce) {
  .winner.has.warn .ans-num, .winner.has.crit, .winner.has.crit .ans-num,
  .buzzer.is-won.ans-warn .ans-big, .buzzer.is-won.ans-crit, .buzzer.is-won.ans-crit .ans-big { animation-duration: 1s; }
}
.small-btn { width: 100%; margin-top: 8px; padding: 8px 12px; font-size: .85rem; }
