:root {
  --bg: #14121f;
  --panel: #232037;
  --text: #f4f2ff;
  --muted: #a39fc0;
  --accent: #ffd23f;
  --team: #6e56cf;
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
h1, h2, h3 { margin: 0; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.2rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 16px; }

button {
  font: inherit; color: inherit; border: 0; border-radius: 12px;
  padding: .6em 1em; background: var(--panel); cursor: pointer;
}
button:disabled { opacity: .4; cursor: default; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: #1b1600; font-weight: 800; }
button.on { box-shadow: inset 0 0 0 3px var(--accent); }
button.ghost { background: transparent; box-shadow: inset 0 0 0 1px var(--muted); }

#banner { position: fixed; inset: 0 0 auto 0; background: #c62a2f; color: #fff; text-align: center; padding: .5em; z-index: 10; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #000d; padding: .7em 1.2em; border-radius: 10px; z-index: 10; }
.notice { font-size: 1.3rem; max-width: 40em; margin: 20vh auto; text-align: center; }

.countdown {
  position: fixed; inset: 0; z-index: 5; padding: 16px; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #14121fe8;
}
.countdown .count { font-size: min(40vw, 40vh); font-weight: 900; line-height: 1; color: var(--accent); }
.countdown p { font-size: 1.3rem; max-width: 30em; }

/* ---------- player (phone) ---------- */
body.play { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
body.play #app { min-height: 100dvh; display: flex; flex-direction: column; gap: 14px; padding: 16px; max-width: 520px; margin: 0 auto; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field input {
  font: inherit; font-size: 1.2rem; padding: .6em; border-radius: 10px; width: 100%;
  border: 1px solid var(--muted); background: var(--panel); color: var(--text);
  -webkit-user-select: text; user-select: text;
}
.team-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.team-pick button {
  background: var(--team); color: #fff; font-size: 1.4rem; font-weight: 800; padding: 1em .5em;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.team-pick small { font-size: .9rem; font-weight: 400; opacity: .85; }
.card { background: var(--team); color: #fff; border-radius: 20px; padding: 24px; text-align: center; }
.card .big { font-size: 2.6rem; font-weight: 900; }
.names { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.names li { background: var(--panel); padding: .3em .8em; border-radius: 999px; }
.names li.off, .team li.off { opacity: .4; }
.team-switch { display: flex; flex-wrap: wrap; gap: 8px; }
.team-switch button { background: var(--team); color: #fff; font-weight: 700; }

.stage { flex: 1; display: flex; flex-direction: column; gap: 12px; }
.bar { height: 18px; background: var(--panel); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--team); transition: width 150ms linear; }
.tap-count { font-size: 3rem; font-weight: 900; text-align: center; }
.tap-status { text-align: center; margin: 0; min-height: 1.4em; font-size: 1.2rem; }
.tap-btn {
  flex: 1; min-height: 45vh; border-radius: 28px; background: var(--team); color: #fff;
  font-size: 3.5rem; font-weight: 900; touch-action: manipulation;
}
.tap-btn:active:not(:disabled) { transform: scale(.97); filter: brightness(1.15); }

/* ---------- host (big screen) ---------- */
body.host #app { min-height: 100vh; display: flex; flex-direction: column; gap: 20px; padding: 24px; }
.lobby { display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; gap: 24px; flex: 1; }
.join { background: #fff; color: #111; border-radius: 20px; padding: 20px; text-align: center; align-self: start; display: flex; flex-direction: column; gap: 10px; }
.join .qr svg { width: 100%; max-width: 440px; height: auto; display: block; margin: 0 auto; }
.join .url { font-size: 1.3rem; font-weight: 700; word-break: break-all; }
.teams { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; align-content: start; }
.team { background: var(--panel); border-radius: 16px; overflow: hidden; border-top: 10px solid var(--team); }
.team h3 { padding: 12px 16px; display: flex; justify-content: space-between; font-size: 1.6rem; }
.team h3 span { color: var(--accent); }
.team ul { list-style: none; margin: 0; padding: 0 16px 16px; font-size: 1.25rem; display: flex; flex-direction: column; gap: 4px; }
.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.controls.end { justify-content: flex-end; }
.controls .group { display: flex; gap: 6px; align-items: center; }
.controls .spacer { flex: 1; }
.controls .primary { font-size: 1.2rem; padding: .7em 1.4em; }

.round-head { display: flex; justify-content: space-between; align-items: center; }
.round-head h2 { font-size: 2rem; }
.race-timer { font-size: 4rem; font-weight: 900; text-align: center; color: var(--accent); min-height: 1.2em; }
.race { display: flex; flex-direction: column; gap: 16px; flex: 1; justify-content: center; }
.lane { display: grid; grid-template-columns: 9rem 1fr; gap: 16px; align-items: center; }
.lane-label { font-size: 1.5rem; font-weight: 800; display: flex; flex-direction: column; }
.lane-label small { font-size: 1rem; font-weight: 400; color: var(--muted); }
.track { position: relative; height: 76px; background: var(--panel); border-radius: 16px; }
.finish {
  position: absolute; right: 0; top: 0; bottom: 0; width: 14px; border-radius: 0 16px 16px 0;
  background: repeating-linear-gradient(0deg, #fff 0 9px, #222 9px 18px);
}
.runner {
  position: absolute; top: 6px; width: 64px; height: 64px; border-radius: 50%;
  left: calc((100% - 64px - 14px) * var(--p, 0)); transition: left 120ms linear;
  background: var(--team); color: #fff; font-size: 1.6rem; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  box-shadow: -18px 0 0 -6px color-mix(in srgb, var(--team) 45%, transparent);
}

/* ---------- shake ---------- */
.shake-pad {
  flex: 1; min-height: 38vh; border-radius: 28px; background: var(--team); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 2.6rem; font-weight: 900; transition: rotate 80ms ease-out;
}
.shake-pad .icon { font-size: 5rem; }

/* ---------- reaction ---------- */
.react-pad {
  flex: 1; min-height: 70vh; border-radius: 28px; background: var(--panel); padding: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  text-align: center; font-size: 1.2rem; touch-action: manipulation;
}
.react-pad .big { font-size: 3rem; font-weight: 900; }
.react-pad p { margin: 0; }
.react-pad.wait { background: #b4232a; color: #fff; }
.react-pad.go { background: #1f9d55; color: #fff; }
.react-host { font-size: 3rem; font-weight: 900; text-align: center; padding: 24px 0 0; }

/* ---------- quiz (host + phone) ---------- */
.quiz-top { color: var(--muted); font-weight: 700; font-size: 1.1rem; }
.quiz-q { font-size: 1.4rem; font-weight: 800; margin: 0; }
.quiz-question { font-size: 2.6rem; line-height: 1.3; text-align: center; margin: 8px 0; }
.quiz-timer { height: 14px; }
.quiz-timer .bar-fill { background: var(--accent); transition: width 120ms linear; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--panel); border-radius: 16px; padding: 16px; font-size: 1.25rem; font-weight: 700;
}
.choice .num {
  flex: none; width: 2em; height: 2em; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #1b1600; font-weight: 900;
}
.choice .text { flex: 1; }
.choice .votes { color: var(--muted); }
.choice.correct { box-shadow: inset 0 0 0 4px var(--accent); background: color-mix(in srgb, var(--accent) 22%, var(--panel)); }
.choice.wrong { opacity: .4; }
body.play .choices { grid-template-columns: 1fr; }
body.play .choice { min-height: 64px; }
body.host .choice { font-size: 1.9rem; padding: 22px 26px; }
.quiz-teams { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.quiz-team {
  display: flex; gap: 12px; align-items: baseline; font-size: 1.3rem;
  background: var(--panel); border-left: 8px solid var(--team); border-radius: 12px; padding: 10px 16px;
}
.quiz-team .gain { color: var(--accent); font-weight: 800; }

.standings { list-style: none; padding: 0; margin: 0 auto; width: min(960px, 100%); display: flex; flex-direction: column; gap: 12px; }
.standings li {
  display: grid; grid-template-columns: 5rem 1fr auto auto; gap: 20px; align-items: center;
  background: var(--panel); border-left: 12px solid var(--team); border-radius: 14px;
  padding: 16px 24px; font-size: 1.7rem; font-weight: 700;
}
.standings .rank { font-weight: 900; color: var(--accent); }
.standings .pts { font-weight: 900; }
.standings li.hidden-row { color: var(--muted); border-left-color: var(--muted); }
.standings li.reveal { animation: pop .45s ease-out; }
.standings li.winner { font-size: 2.2rem; animation: pop .45s ease-out, glow 1.2s ease-in-out .45s infinite alternate; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
@keyframes glow { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: 0 0 36px 8px var(--accent); } }
@media (prefers-reduced-motion: reduce) {
  .standings li.reveal, .standings li.winner { animation: none; }
  .runner, .bar-fill { transition: none; }
}

/* Host page opened on a phone = remote control */
@media (max-width: 800px) {
  body.host #app { padding: 16px; }
  .lobby { grid-template-columns: 1fr; }
  .standings li { font-size: 1.1rem; grid-template-columns: 3rem 1fr auto; padding: 12px 16px; }
  .standings li > :nth-child(3) { display: none; }
  .lane { grid-template-columns: 5rem 1fr; }
  .quiz-question { font-size: 1.5rem; }
  body.host .choices { grid-template-columns: 1fr; }
  body.host .choice { font-size: 1.1rem; padding: 12px 16px; }
}
