/* QuickBee — Take Quiz (player / presenter). Uses theme tokens with fallbacks. */

[hidden] { display: none !important; }

body.take {
  --tk-bg: var(--bg, #fbf7ef);
  --tk-surface: var(--surface, #ffffff);
  --tk-surface-2: var(--surface-2, #f4eee2);
  --tk-border: var(--border, #e6dcc8);
  --tk-text: var(--text, #1b1712);
  --tk-muted: var(--text-muted, #6b6253);
  --tk-primary: var(--primary, #f5a524);
  --tk-primary-ink: var(--primary-ink, #1b1300);
  --tk-primary-soft: var(--primary-soft, #fdf0d5);
  --tk-danger: var(--danger, #e5484d);
  --tk-success: var(--success, #3fb950);
  --tk-warning: var(--warning, #ffb224);
  --tk-radius: var(--radius, 12px);
  --tk-radius-lg: var(--radius-lg, 20px);
  --tk-shadow: var(--shadow, 0 2px 10px rgba(0,0,0,.08));
  --tk-shadow-lg: var(--shadow-lg, 0 20px 50px rgba(0,0,0,.25));
  --tk-display: var(--font-display, "Inter", system-ui, -apple-system, "Segoe UI", sans-serif);
  --tk-body: var(--font-body, system-ui, -apple-system, "Segoe UI", sans-serif);
  --tk-mono: var(--font-mono, ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace);
  --sg-bg: var(--stage-bg, #0e0d0b);
  --sg-text: var(--stage-text, #fdf8ec);
  --sg-accent: var(--stage-accent, #ffc23d);
  --sg-muted: color-mix(in srgb, var(--sg-text) 62%, transparent);
  --sg-line: color-mix(in srgb, var(--sg-text) 14%, transparent);
  margin: 0;
  min-height: 100vh;
  background: var(--tk-bg);
  color: var(--tk-text);
  font-family: var(--tk-body);
}
body.take[data-screen="stage"] { background: var(--sg-bg); overflow: hidden; }

.take-topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px clamp(16px, 3vw, 32px); }
.take-brand { display: inline-flex; align-items: center; color: inherit; text-decoration: none; }
.take-brand img { height: 34px; width: auto; display: block; }
.take-brand .logo-text { font: 800 1.3rem/1 var(--tk-display); letter-spacing: -.03em; }

.screen { box-sizing: border-box; }
.screen-center { min-height: calc(100vh - 70px); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px 48px; text-align: center; }

.take-spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--tk-primary-soft); border-top-color: var(--tk-primary); animation: tk-spin .8s linear infinite; margin-bottom: 12px; }
@keyframes tk-spin { to { transform: rotate(360deg); } }

/* ---------- Mode ribbon ---------- */
.mode-ribbon {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%); z-index: 90;
  padding: 4px 16px 5px; border-radius: 0 0 10px 10px;
  font: 800 .72rem/1.2 var(--tk-display); letter-spacing: .14em; text-transform: uppercase;
  background: var(--tk-primary); color: var(--tk-primary-ink); box-shadow: 0 4px 14px rgba(0,0,0,.18);
  pointer-events: none; white-space: nowrap;
}
.mode-ribbon.ribbon-preview { background: #7c5cff; color: #fff; }

/* ---------- 1. Code entry ---------- */
.entry-card { width: min(560px, 100%); box-sizing: border-box; padding: clamp(24px, 5vw, 44px); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.entry-eyebrow { margin: 0; font: 800 .78rem/1 var(--tk-display); letter-spacing: .16em; text-transform: uppercase; color: var(--tk-primary); }
.entry-title { margin: 6px 0 0; font: 800 clamp(1.6rem, 4vw, 2.3rem)/1.1 var(--tk-display); letter-spacing: -.02em; }
.entry-sub { margin: 4px 0 18px; }
.code-boxes { display: flex; align-items: center; justify-content: center; gap: clamp(5px, 1.4vw, 10px); flex-wrap: nowrap; }
.code-box {
  width: clamp(40px, 11vw, 62px); height: clamp(52px, 14vw, 76px); box-sizing: border-box;
  border: 2px solid var(--tk-border); border-radius: var(--tk-radius); background: var(--tk-surface);
  color: var(--tk-text); text-align: center; text-transform: uppercase; padding: 0;
  font: 800 clamp(1.5rem, 6vw, 2.3rem)/1 var(--tk-mono); caret-color: var(--tk-primary);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.code-box:focus { outline: none; border-color: var(--tk-primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--tk-primary) 28%, transparent); transform: translateY(-2px); }
.code-sep { color: var(--tk-muted); font: 700 1.5rem var(--tk-mono); }
.code-boxes.has-error .code-box { border-color: var(--tk-danger); }
.code-boxes.shake { animation: tk-shake .4s; }
@keyframes tk-shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
.entry-error { min-height: 1.4em; margin: 12px 0 4px; color: var(--tk-danger); font-weight: 600; font-size: .95rem; }
.entry-open { min-width: 200px; margin-top: 4px; }
.entry-alt { margin-top: 18px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
.entry-alt a { color: var(--tk-text); font-weight: 600; }
.entry-sample { color: var(--tk-primary) !important; }

/* ---------- 2. Waiting ---------- */
.waiting-wrap, .finish-wrap { width: min(760px, 100%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.take-illus { width: min(260px, 60vw); height: auto; margin-bottom: 8px; }
.waiting-title { margin: 6px 0 0; font: 800 clamp(1.7rem, 5vw, 3rem)/1.1 var(--tk-display); letter-spacing: -.02em; }
.waiting-desc { max-width: 60ch; }
.waiting-count {
  margin: 18px 0 6px; font: 800 clamp(2.8rem, 13vw, 8rem)/1 var(--tk-mono); letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; color: var(--tk-text);
}
.waiting-count.is-soon { color: var(--tk-primary); }
.waiting-at { margin: 0; font-size: 1.1rem; }
.waiting-meta { margin: 0; }
.waiting-code { margin-top: 14px; font-size: clamp(1.4rem, 4vw, 2.2rem); }
.waiting-note { margin-top: 18px; font-size: .9rem; display: inline-flex; align-items: center; gap: 8px; }
.pulse-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--tk-success); box-shadow: 0 0 0 0 color-mix(in srgb, var(--tk-success) 60%, transparent); animation: tk-pulse 1.8s infinite; }
@keyframes tk-pulse { 70% { box-shadow: 0 0 0 10px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ---------- 3. Lobby ---------- */
.lobby { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; padding: 16px clamp(16px, 3vw, 32px) 48px; max-width: 1180px; margin: 0 auto; box-sizing: border-box; align-items: start; }
.lobby-main, .lobby-side { box-sizing: border-box; padding: clamp(20px, 3vw, 32px); }
.lobby-title { margin: 8px 0 6px; font: 800 clamp(1.8rem, 4.5vw, 2.8rem)/1.08 var(--tk-display); letter-spacing: -.02em; overflow-wrap: anywhere; }
.lobby-desc { max-width: 70ch; }
.lobby h2 { font: 800 1rem/1.2 var(--tk-display); margin: 0 0 10px; }
.lobby-stats { display: flex; flex-wrap: wrap; gap: 12px; margin: 20px 0; }
.stat { flex: 1 1 120px; padding: 14px 16px; border-radius: var(--tk-radius); background: var(--tk-surface-2); border: 1px solid var(--tk-border); }
.stat-v { font: 800 clamp(1.6rem, 3vw, 2.2rem)/1 var(--tk-display); }
.stat-l { color: var(--tk-muted); font-size: .85rem; margin-top: 4px; }
.lobby-topics { margin-bottom: 22px; }
.topic-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.topic-chip b { opacity: .6; font-weight: 700; margin-left: 4px; }
.lobby-teams { border-top: 1px solid var(--tk-border); padding-top: 20px; }
.lobby-teams-head p { margin: -4px 0 12px; font-size: .9rem; }
.lobby-optional { font: 600 .75rem var(--tk-body); text-transform: uppercase; letter-spacing: .08em; margin-left: 6px; }
.lobby-team-form { display: flex; gap: 8px; flex-wrap: wrap; }
.lobby-team-form .input { flex: 1 1 200px; min-width: 0; }
.team-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.team-item { display: inline-flex; align-items: center; gap: 8px; padding: 4px 4px 4px 8px; border: 1px solid var(--tk-border); border-radius: 999px; background: var(--tk-surface); }
.team-name { font-weight: 600; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lobby-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--tk-border); }
.lobby-start { font-size: 1.2rem; padding-inline: 28px; }
.lobby-fs-opt { display: inline-flex; align-items: center; gap: 8px; color: var(--tk-muted); font-size: .9rem; cursor: pointer; }
.lobby-side { position: sticky; top: 16px; }

.shortcut-list { display: grid; gap: 8px; }
.shortcut { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: baseline; font-size: .9rem; }
.shortcut-keys { display: flex; flex-wrap: wrap; gap: 4px; }
.shortcut-desc { color: var(--tk-muted); }
.take .kbd:not(:where(.stage *)) { min-width: 1.4em; text-align: center; }

@media (max-width: 860px) {
  .lobby { grid-template-columns: 1fr; }
  .lobby-side { position: static; }
}

/* ---------- 4. Stage ---------- */
.stage {
  position: fixed; inset: 0; z-index: 10;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) minmax(0, 0fr);
  background:
    radial-gradient(1200px 600px at 85% -10%, color-mix(in srgb, var(--sg-accent) 10%, transparent), transparent 60%),
    var(--sg-bg);
  color: var(--sg-text);
  padding: clamp(10px, 1.6vw, 24px) clamp(16px, 3vw, 48px) calc(clamp(10px, 1.6vw, 24px) + 64px);
  box-sizing: border-box;
  font-family: var(--tk-body);
  transition: grid-template-rows .45s cubic-bezier(.2,.8,.2,1);
  user-select: none;
  cursor: default;
}
body.has-ribbon .stage { padding-top: 34px; }
.stage.revealed { grid-template-rows: auto minmax(0, 1fr) minmax(0, .62fr); }
body.idle .stage { cursor: none; }

.st-progress-bar { position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--sg-line); }
.st-progress-bar span { display: block; height: 100%; width: 0; background: var(--sg-accent); transition: width .4s ease; }

.st-top { display: flex; align-items: center; gap: 16px; min-height: 44px; }
.st-progress { font: 700 clamp(1rem, 1.8vw, 1.6rem)/1 var(--tk-display); color: var(--sg-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.st-progress b { color: var(--sg-text); font-weight: 800; }
.st-tags { flex: 1; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.st-chip {
  --chip: #888;
  display: inline-flex; align-items: center; padding: .3em .85em; border-radius: 999px;
  font: 700 clamp(.75rem, 1.15vw, 1.05rem)/1.1 var(--tk-display); letter-spacing: .03em;
  color: var(--chip); background: color-mix(in srgb, var(--chip) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--chip) 55%, transparent);
}
.st-points {
  margin-left: auto; white-space: nowrap; padding: .35em .9em; border-radius: 999px;
  font: 700 clamp(.95rem, 1.6vw, 1.5rem)/1 var(--tk-display);
  background: var(--sg-accent); color: #1b1300;
}
.st-points b { font-weight: 900; }

.st-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: clamp(16px, 3vw, 48px); min-height: 0; padding: clamp(8px, 2vh, 28px) 0; }
.stage.has-timer .st-body { grid-template-columns: minmax(0, 1fr) clamp(150px, 22vw, 380px); }
.st-qcol { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.st-qcol.enter { animation: st-enter .45s cubic-bezier(.2,.8,.2,1); }
@keyframes st-enter { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.st-topic {
  font: 900 clamp(1rem, 2.4vw, 2.2rem)/1.1 var(--tk-display); letter-spacing: .16em; text-transform: uppercase;
  color: var(--sg-accent); margin-bottom: clamp(8px, 1.6vh, 20px);
  display: flex; align-items: center; gap: .6em;
}
.st-topic::before { content: ""; width: 1.4em; height: .22em; border-radius: 99px; background: var(--sg-accent); flex: none; }
.st-qbox { flex: 1; min-height: 0; overflow: hidden; display: flex; align-items: center; }
.st-text {
  width: 100%; max-height: 100%;
  font-family: var(--tk-display); font-weight: 650; line-height: 1.22; letter-spacing: -.01em;
  overflow-wrap: anywhere; text-wrap: pretty;
  font-size: clamp(22px, 5vw, 88px);
}
.st-text .katex { font-size: 1.05em; }
.st-text .katex-display { margin: .4em 0; }
.st-img-wrap { margin-top: .5em; }
.st-img { max-width: 100%; max-height: 42vh; border-radius: 12px; display: block; }

/* Timer */
.st-timer { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: 0; }
.ring-wrap { position: relative; width: 100%; max-width: 100%; aspect-ratio: 1; max-height: 52vh; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.ring circle { fill: none; stroke-width: 9; }
.ring-track { stroke: var(--sg-line); }
.ring-bar { stroke: var(--sg-accent); stroke-linecap: round; transition: stroke .3s; filter: drop-shadow(0 0 10px color-mix(in srgb, var(--sg-accent) 45%, transparent)); }
.ring-time {
  position: absolute; inset: 0; display: grid; place-items: center;
  font: 800 clamp(2rem, 6.4vw, 7rem)/1 var(--tk-mono); font-variant-numeric: tabular-nums; letter-spacing: -.04em;
}
.st-timer-state { min-height: 1.3em; font: 800 clamp(.85rem, 1.4vw, 1.3rem)/1.2 var(--tk-display); letter-spacing: .14em; text-transform: uppercase; color: var(--sg-muted); }
.st-start { font-size: clamp(.95rem, 1.5vw, 1.4rem); padding: .6em 1.2em; border-radius: 999px; display: inline-flex; gap: .5em; align-items: center;
  background: var(--sg-accent); color: #1b1300; border: 0; font-weight: 800; cursor: pointer; }
.st-reveal.locked { background: color-mix(in srgb, var(--sg-text) 10%, transparent); color: var(--sg-muted); box-shadow: none; border-color: var(--sg-line); cursor: not-allowed; }
.st-reveal.locked .kbd { opacity: .4; }
.st-reveal.armed { box-shadow: 0 0 0 3px #fff, 0 0 24px var(--sg-accent); animation: ctl-armed .8s ease-in-out infinite alternate; }
.st-start .kbd { background: rgba(0,0,0,.15); color: inherit; border-color: transparent; }

.stage.warn .ring-bar { stroke: var(--tk-danger); filter: drop-shadow(0 0 14px color-mix(in srgb, var(--tk-danger) 60%, transparent)); }
.stage.warn .ring-time { color: #ff8a8d; animation: st-beat 1s ease-in-out infinite; }
@keyframes st-beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.08); } }
.stage.timeup .ring-time { color: var(--tk-danger); }
.stage.timeup .st-timer-state { color: var(--tk-danger); }

.st-timesup {
  position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%) scale(.6);
  font: 900 clamp(2.5rem, 11vw, 11rem)/1 var(--tk-display); letter-spacing: .04em; color: #fff;
  padding: .12em .5em; border-radius: .2em; background: var(--tk-danger);
  box-shadow: 0 20px 80px color-mix(in srgb, var(--tk-danger) 60%, transparent);
  opacity: 0; pointer-events: none; white-space: nowrap; z-index: 5;
}
.stage.flash .st-timesup { animation: st-timesup 1.7s cubic-bezier(.2,.8,.2,1) forwards; }
@keyframes st-timesup {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.6) rotate(-4deg); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(1.06) rotate(-2deg); }
  24% { transform: translate(-50%, -50%) scale(1) rotate(-2deg); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-2deg); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(.96) rotate(-2deg); }
}
.stage.flash::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 10px var(--tk-danger); animation: st-edge 1.2s ease-out forwards; }
@keyframes st-edge { from { opacity: 1; } to { opacity: 0; } }

.st-reveal-pill {
  position: absolute; right: clamp(16px, 3vw, 48px); bottom: calc(clamp(10px, 1.6vw, 24px) + 76px);
  padding: .5em 1em; border-radius: 999px; font: 700 clamp(.9rem, 1.4vw, 1.3rem)/1 var(--tk-display);
  background: color-mix(in srgb, var(--sg-accent) 18%, transparent); color: var(--sg-accent);
  border: 1px solid color-mix(in srgb, var(--sg-accent) 50%, transparent);
}

/* Answer */
.st-answer { min-height: 0; overflow: hidden; }
.st-answer-inner {
  height: 100%; box-sizing: border-box; display: flex; flex-direction: column; justify-content: center; gap: .5em;
  padding: clamp(12px, 2vh, 24px) clamp(16px, 2.4vw, 36px);
  border-radius: var(--tk-radius-lg);
  background: linear-gradient(135deg, color-mix(in srgb, var(--sg-accent) 20%, transparent), color-mix(in srgb, var(--sg-accent) 6%, transparent));
  border: 2px solid color-mix(in srgb, var(--sg-accent) 60%, transparent);
  opacity: 0; transform: translateY(40%) scale(.97); visibility: hidden;
  transition: opacity .35s ease, transform .5s cubic-bezier(.2,1.2,.3,1), visibility 0s .5s;
}
.stage.revealed .st-answer-inner { opacity: 1; transform: none; visibility: visible; transition: opacity .35s ease .08s, transform .55s cubic-bezier(.2,1.25,.3,1) .05s, visibility 0s; }
.st-answer-label { font: 900 clamp(.8rem, 1.3vw, 1.2rem)/1 var(--tk-display); letter-spacing: .22em; text-transform: uppercase; color: var(--sg-accent); }
.st-answer-text {
  font: 800 clamp(22px, 4.2vw, 76px)/1.15 var(--tk-display); letter-spacing: -.01em; color: #fff;
  overflow: hidden; overflow-wrap: anywhere; min-height: 0; flex: 0 1 auto;
  padding: .12em 0 .18em; /* room for KaTeX fractions/descenders so they aren't clipped */
}
.stage.revealed .st-answer-text { animation: st-pop .6s cubic-bezier(.2,1.4,.4,1) .12s both; }
@keyframes st-pop { from { opacity: 0; filter: blur(8px); transform: scale(.92); } to { opacity: 1; filter: none; transform: none; } }
.st-award { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: .2em; }
.st-award-label { color: var(--sg-muted); font-weight: 700; font-size: clamp(.8rem, 1.1vw, 1rem); margin-right: 4px; }
.award-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px 6px 6px; border-radius: 999px; cursor: pointer;
  font: 700 clamp(.8rem, 1.1vw, 1rem)/1 var(--tk-display); color: var(--sg-text);
  background: color-mix(in srgb, var(--sg-text) 8%, transparent); border: 1px solid var(--sg-line);
  transition: background .15s, transform .1s;
}
.award-btn:hover { background: color-mix(in srgb, var(--sg-text) 16%, transparent); }
.award-btn:active { transform: scale(.96); }
.award-btn.is-on { background: var(--tk-success); border-color: var(--tk-success); color: #04120a; }
.award-btn .kbd, .stage .kbd {
  display: inline-grid; place-items: center; min-width: 1.6em; height: 1.6em; padding: 0 .3em; box-sizing: border-box;
  border-radius: 6px; font: 700 .8em/1 var(--tk-mono);
  background: color-mix(in srgb, var(--sg-text) 14%, transparent); color: inherit; border: 0;
}

.st-hint {
  position: absolute; left: clamp(16px, 3vw, 48px); bottom: calc(clamp(10px, 1.6vw, 24px) + 20px);
  font: 600 .85rem/1 var(--tk-display); color: var(--sg-muted); letter-spacing: .04em;
  transition: opacity .3s;
}

/* Control bar */
.stage-controls {
  position: absolute; left: 50%; bottom: clamp(8px, 1.2vw, 16px); transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 2px; padding: 5px;
  background: color-mix(in srgb, #000 55%, var(--sg-bg)); border: 1px solid var(--sg-line); border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,.45); backdrop-filter: blur(10px);
  transition: opacity .3s, transform .3s; max-width: calc(100vw - 24px); overflow-x: auto; scrollbar-width: none;
}
.stage-controls::-webkit-scrollbar { display: none; }
body.idle .stage-controls, body.idle .st-hint { opacity: 0; pointer-events: none; }
body.idle .stage-controls { transform: translate(-50%, 12px); }
.ctl {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 54px; height: 50px; padding: 0 8px; border: 0; border-radius: 11px; cursor: pointer;
  background: transparent; color: var(--sg-text); font-family: var(--tk-display);
  transition: background .15s, color .15s;
}
.ctl:hover:not(:disabled) { background: color-mix(in srgb, var(--sg-text) 12%, transparent); }
.ctl:focus-visible { outline: 2px solid var(--sg-accent); outline-offset: 1px; }
.ctl:disabled { opacity: .32; cursor: default; }
.ctl-i { font-size: 1.05rem; font-weight: 800; line-height: 1; }
.ctl-l { font-size: .66rem; font-weight: 600; letter-spacing: .04em; color: var(--sg-muted); line-height: 1; }
.ctl-accent { color: var(--sg-accent); }
.ctl.armed { background: color-mix(in srgb, var(--sg-accent) 30%, transparent); color: #fff; box-shadow: 0 0 0 2px var(--sg-accent); animation: ctl-armed .8s ease-in-out infinite alternate; }
.ctl.armed .ctl-l { color: #fff; }
@keyframes ctl-armed { from { transform: scale(1); } to { transform: scale(1.06); } }
@media (prefers-reduced-motion: reduce) { .ctl.armed, .st-reveal.armed { animation: none; } }
.ctl.is-on { background: color-mix(in srgb, var(--sg-accent) 18%, transparent); color: var(--sg-accent); }
.ctl-sep { width: 1px; align-self: stretch; margin: 6px 4px; background: var(--sg-line); flex: none; }

@media (max-width: 760px) {
  .stage.has-timer .st-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .stage.has-timer .st-timer { order: -1; flex-direction: row; justify-content: flex-start; }
  .ring-wrap { width: 92px; max-height: none; }
  .ring-time { font-size: 1.5rem; }
  .st-start { font-size: .9rem; }
  .st-hint { display: none; }
  .ctl { min-width: 44px; }
  .ctl-l { display: none; }
}

/* ---------- Modals (self-contained layout; theme adds polish) ---------- */
.take-modal-backdrop {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px;
  background: rgba(8, 7, 5, .62); backdrop-filter: blur(3px);
  animation: tk-fade .18s ease;
}
.take-modal {
  position: relative; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-sizing: border-box;
  padding: clamp(18px, 3vw, 28px); border-radius: var(--tk-radius-lg);
  background: var(--tk-surface); color: var(--tk-text); box-shadow: var(--tk-shadow-lg);
  animation: tk-rise .25s cubic-bezier(.2,1,.3,1); text-align: left; outline: none;
}
.take-modal-wide { width: min(880px, 100%); }
@keyframes tk-fade { from { opacity: 0; } }
@keyframes tk-rise { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.take-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.take-modal-head h2 { margin: 0; font: 800 1.35rem/1.2 var(--tk-display); }
.menu-actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.menu-sub { margin: 22px 0 10px; font: 800 .8rem/1 var(--tk-display); letter-spacing: .12em; text-transform: uppercase; color: var(--tk-muted); }

.jump-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.jump-item {
  display: flex; align-items: center; gap: 10px; padding: 10px; text-align: left; cursor: pointer;
  border: 1px solid var(--tk-border); border-radius: var(--tk-radius); background: var(--tk-surface-2); color: var(--tk-text);
  font: inherit; transition: border-color .15s, transform .1s;
}
.jump-item:hover, .jump-item:focus-visible { border-color: var(--tk-primary); outline: none; }
.jump-item.is-current { border-color: var(--tk-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tk-primary) 25%, transparent); }
.jump-n { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; font: 800 1rem var(--tk-display); background: var(--tk-surface); border: 1px solid var(--tk-border); }
.jump-item.is-done .jump-n { background: var(--tk-success); color: #04120a; border-color: transparent; }
.jump-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.jump-topic { font: 700 .72rem/1.2 var(--tk-display); letter-spacing: .08em; text-transform: uppercase; color: var(--tk-primary); }
.jump-text { font-size: .85rem; color: var(--tk-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.jump-done { color: var(--tk-success); font-weight: 800; }

/* Scoreboard (dark, projector-friendly) */
.score-modal { width: min(760px, 100%); background: color-mix(in srgb, #000 40%, var(--sg-bg)); color: var(--sg-text); border: 1px solid var(--sg-line); }
.score-modal .take-modal-head h2 { font-size: clamp(1.4rem, 3vw, 2.4rem); color: var(--sg-accent); }
.score-modal .btn-ghost { color: var(--sg-text); }
.score-board { display: grid; gap: 10px; }
.score-row {
  display: grid; grid-template-columns: 2.2em minmax(0, 1.3fr) minmax(60px, 2fr) auto auto; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 14px; background: color-mix(in srgb, var(--sg-text) 6%, transparent);
  font-size: clamp(1rem, 2vw, 1.6rem);
}
.score-row.is-lead { background: color-mix(in srgb, var(--sg-accent) 16%, transparent); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--sg-accent) 50%, transparent); }
.score-rank { font: 900 1.1em var(--tk-display); color: var(--sg-muted); text-align: center; }
.score-row.is-lead .score-rank { color: var(--sg-accent); }
.score-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: .5em; }
.score-name .kbd { font-size: .6em; display: inline-grid; place-items: center; min-width: 1.6em; height: 1.6em; border-radius: 6px; background: color-mix(in srgb, var(--sg-text) 14%, transparent); }
.score-bar { height: .55em; border-radius: 99px; background: var(--sg-line); overflow: hidden; }
.score-bar span { display: block; height: 100%; border-radius: inherit; background: var(--sg-accent); transition: width .5s cubic-bezier(.2,.8,.2,1); }
.score-val { font: 900 1.3em/1 var(--tk-mono); font-variant-numeric: tabular-nums; min-width: 2.2ch; text-align: right; }
.score-adj { display: flex; gap: 2px; }
.score-adj .btn { color: var(--sg-muted); }
.score-empty { color: var(--sg-muted); }
.score-add { margin-top: 14px; }
.score-add .input { background: color-mix(in srgb, var(--sg-text) 8%, transparent); color: var(--sg-text); border-color: var(--sg-line); }
@media (max-width: 600px) { .score-row { grid-template-columns: 2em minmax(0, 1fr) auto auto; } .score-bar { display: none; } }

/* ---------- Coach marks ---------- */
.coach { position: fixed; inset: 0; z-index: 150; }
.coach-spot {
  position: fixed; border-radius: 16px; pointer-events: none;
  box-shadow: 0 0 0 4px var(--sg-accent), 0 0 0 9999px rgba(5, 4, 2, .66);
  transition: left .35s cubic-bezier(.2,.8,.2,1), top .35s cubic-bezier(.2,.8,.2,1), width .35s, height .35s;
}
.coach-spot.is-center { left: 50%; top: 50%; width: 0; height: 0; box-shadow: 0 0 0 9999px rgba(5, 4, 2, .66); }
.coach-card {
  position: fixed; box-sizing: border-box; padding: 18px 20px; text-align: left;
  background: var(--tk-surface); color: var(--tk-text); border-radius: var(--tk-radius-lg); box-shadow: var(--tk-shadow-lg);
  transition: left .35s cubic-bezier(.2,.8,.2,1), top .35s cubic-bezier(.2,.8,.2,1);
  animation: tk-rise .3s cubic-bezier(.2,1,.3,1);
}
.coach-step { font: 800 .72rem/1 var(--tk-display); letter-spacing: .14em; color: var(--tk-primary); text-transform: uppercase; }
.coach-title { margin: 6px 0 4px; font: 800 1.2rem/1.2 var(--tk-display); }
.coach-text { margin: 0 0 14px; color: var(--tk-muted); line-height: 1.45; }
.coach-actions { display: flex; align-items: center; gap: 6px; }
.coach-spacer { flex: 1; }
body.coach-active .stage-controls, body.coach-active .st-hint { opacity: 1 !important; pointer-events: auto; }
body.coach-active .stage-controls { transform: translateX(-50%) !important; }

/* ---------- 5. Finish ---------- */
.finish-title { margin: 4px 0 0; font: 900 clamp(2.2rem, 7vw, 4.5rem)/1 var(--tk-display); letter-spacing: -.03em; }
.finish-sub { margin: 6px 0 20px; }
.finish-board { width: min(560px, 100%); display: grid; gap: 8px; text-align: left; margin-bottom: 24px; }
.finish-board h2 { margin: 0 0 4px; font: 800 .8rem/1 var(--tk-display); letter-spacing: .14em; text-transform: uppercase; color: var(--tk-muted); text-align: center; }
.final-row {
  display: grid; grid-template-columns: 2.6em 1fr auto; align-items: center; gap: 12px; padding: 12px 16px;
  border-radius: var(--tk-radius); background: var(--tk-surface); border: 1px solid var(--tk-border); box-shadow: var(--tk-shadow);
  font-size: 1.15rem; animation: tk-rise .45s cubic-bezier(.2,1,.3,1) both; animation-delay: calc(var(--i, 0) * 90ms + 150ms);
}
.final-row.is-winner { border-color: var(--tk-primary); background: var(--tk-primary-soft); font-size: 1.35rem; }
.final-place { font: 900 1.2em var(--tk-display); text-align: center; }
.final-name { font-weight: 700; overflow-wrap: anywhere; }
.final-score { font: 900 1.2em var(--tk-mono); font-variant-numeric: tabular-nums; }
.final-score small { font: 600 .6em var(--tk-body); color: var(--tk-muted); }
.finish-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* ---------- Toasts (positioning fallback) ---------- */
#toast-root { position: fixed; left: 50%; transform: translateX(-50%); z-index: 1000; pointer-events: none; }
body.take[data-screen="stage"] #toast-root { bottom: 92px; }
#toast-root .toast { pointer-events: auto; transition: opacity .3s, transform .3s; }
#toast-root .toast-out { opacity: 0; transform: translateY(8px); }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; transition-delay: 0s !important; }
  .stage.flash .st-timesup, .stage.flash::after { animation: none; opacity: 0; }
  .stage.warn .ring-time { animation: none; }
}

.ctl.locked { opacity: .45; cursor: not-allowed; }

.st-answer-alt { font: 700 clamp(14px, 1.9vw, 34px)/1.3 var(--tk-display); color: color-mix(in srgb, #fff 75%, transparent); overflow-wrap: anywhere; flex: none; }
.st-answer-alt-l { font: 900 clamp(.65rem, 1vw, .95rem)/1 var(--tk-display); letter-spacing: .18em; text-transform: uppercase; color: var(--sg-accent); margin-right: .6em; vertical-align: .15em; }
.st-answer-alt-sep { color: var(--sg-accent); }
.stage.revealed .st-answer-alt { animation: st-pop .6s cubic-bezier(.2,1.4,.4,1) .22s both; }

/* Round title cards ("Easy" → "Moderate" → …) */
.st-card {
  --card: var(--sg-accent);
  position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; cursor: pointer;
  background:
    radial-gradient(900px 520px at 50% 45%, color-mix(in srgb, var(--card) 22%, transparent), transparent 70%),
    var(--sg-bg);
}
.st-card[hidden] { display: none; }
.st-card-inner { text-align: center; padding: 24px; display: grid; justify-items: center; gap: clamp(10px, 2vh, 22px); }
.st-card-eyebrow { font: 900 clamp(.9rem, 1.6vw, 1.5rem)/1 var(--tk-display); letter-spacing: .3em; text-transform: uppercase; color: var(--sg-muted); }
.st-card-title {
  font: 900 clamp(64px, 15vw, 260px)/.9 var(--tk-display); letter-spacing: -.03em; text-transform: uppercase;
  color: var(--card); text-shadow: 0 0 60px color-mix(in srgb, var(--card) 45%, transparent);
}
.st-card-sub { font: 700 clamp(1rem, 2vw, 1.8rem)/1.2 var(--tk-display); color: var(--sg-text); }
.st-card-groups { display: grid; gap: 8px; margin-top: 4px; }
.st-card-group {
  display: grid; grid-template-columns: auto auto auto; gap: 1.2em; align-items: baseline; justify-content: center;
  font: 700 clamp(.9rem, 1.5vw, 1.4rem)/1.2 var(--tk-display);
  padding: .5em 1.1em; border-radius: 999px; border: 1px solid var(--sg-line);
  background: color-mix(in srgb, var(--sg-text) 5%, transparent);
}
.st-card-g-l { color: var(--sg-text); }
.st-card-g-v { color: var(--card); }
.st-card-g-n { color: var(--sg-muted); font-size: .85em; }
.st-card-hint { margin-top: clamp(8px, 3vh, 32px); font: 600 clamp(.8rem, 1.2vw, 1.05rem)/1 var(--tk-body); color: var(--sg-muted); }
.st-card.in .st-card-eyebrow { animation: st-card-up .5s cubic-bezier(.2,.9,.3,1) both; }
.st-card.in .st-card-title { animation: st-card-zoom .8s cubic-bezier(.2,1.3,.3,1) .1s both; }
.st-card.in .st-card-sub, .st-card.in .st-card-groups { animation: st-card-up .5s cubic-bezier(.2,.9,.3,1) .35s both; }
.st-card.in .st-card-hint { animation: st-card-up .5s ease .7s both; }
.st-card.in { animation: st-card-bg .35s ease both; }
@keyframes st-card-bg { from { opacity: 0; } to { opacity: 1; } }
@keyframes st-card-zoom { from { opacity: 0; transform: scale(.6); filter: blur(12px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes st-card-up { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .st-card.in, .st-card.in * { animation: none !important; } }

/* Solution slide (after the answer, before the next question) */
.st-sol {
  position: absolute; inset: 0; bottom: 76px; z-index: 15; overflow: hidden;
  padding: clamp(10px, 2vh, 24px) clamp(14px, 2vw, 32px) 0;
  background: var(--sg-bg); cursor: pointer;
}
.st-sol[hidden] { display: none; }
.st-sol-inner { min-width: 0; width: 100%; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: .5em; line-height: 1.4; color: var(--sg-text); font-family: var(--tk-body); }
.st-sol-head { display: flex; align-items: center; gap: .4em 1em; flex-wrap: wrap; font-size: .6em; }
.st-sol-eyebrow { font: 900 1em/1 var(--tk-display); letter-spacing: .24em; text-transform: uppercase; color: var(--sg-accent); }
.st-sol-q { font: 700 .8em/1 var(--tk-display); letter-spacing: .1em; text-transform: uppercase; color: var(--sg-muted); }
.st-sol-body { font-weight: 500; min-width: 0; }
.st-sol-body .katex-display { margin: .3em 0; overflow: visible; text-align: left; }
.st-sol-body .katex-display > .katex { text-align: left; }
.st-sol-ans {
  margin-left: auto; padding: .3em .9em; border-radius: 10px; font: 800 1.3em/1.2 var(--tk-display);
  background: color-mix(in srgb, var(--sg-accent) 16%, transparent); border: 2px solid color-mix(in srgb, var(--sg-accent) 55%, transparent);
}
.st-sol-ans-l { font: 900 .55em/1 var(--tk-display); letter-spacing: .2em; text-transform: uppercase; color: var(--sg-accent); margin-right: .6em; vertical-align: .2em; }
.st-sol.in .st-sol-inner { animation: st-card-up .45s cubic-bezier(.2,.9,.3,1) both; }
@media (prefers-reduced-motion: reduce) { .st-sol.in .st-sol-inner { animation: none; } }
