/* Shared styles for the quiz and the results board */
:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --ink: #18212f;
  --muted: #5b6676;
  --line: #d6dde8;
  --accent: #2d5be3;
  --accent-soft: #e3eafc;
  --warn: #d9480f;
  --blue: #1c64d9;
  --blue-soft: #e2ecfc;
  --red: #d42f3a;
  --red-soft: #fce4e5;
  --orange: #e8590c;
  --orange-soft: #fff0e6;
  --ok: #2b8a3e;
  --peer-1: #e8590c; --peer-2: #2b8a3e; --peer-3: #7048e8; --peer-4: #c2255c; --peer-5: #1971c2; --peer-6: #e67700; --peer-7: #0c8599;
  --font-display: "Bricolage Grotesque", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "Nunito Sans", "Segoe UI", system-ui, sans-serif;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121722; --surface: #1b2230; --ink: #e8edf5; --muted: #9aa5b6; --line: #2e3849;
    --accent: #7b9cff; --accent-soft: #24304d; --warn: #ff8a4c; --ok: #5fd07a;
    --blue: #6aa1ff; --blue-soft: #1d2b47; --red: #ff6b73; --red-soft: #3f2128; --orange: #ff9a52; --orange-soft: #3d2618; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 17px; line-height: 1.5;
  padding: 0 16px;
}
[hidden] { display: none !important; }
.wrap { max-width: 640px; margin: 0 auto; padding-block: 28px 40px; display: flex; flex-direction: column; gap: 20px; }
.wrap.wide { max-width: 980px; }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; line-height: 1.15; }
h1 { font-size: clamp(30px, 6vw, 42px); font-weight: 800; }
h2 { font-size: clamp(22px, 4.5vw, 28px); font-weight: 600; }
h3 { font-size: 20px; font-weight: 800; }
p { margin: 0; }
a { color: var(--accent); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.label { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.between { justify-content: space-between; }
.btn {
  font: 700 18px var(--font-body); color: #fff; background: var(--accent);
  border: 0; border-radius: 999px; padding: 14px 28px; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--muted); border: 2px solid var(--line); padding: 10px 20px; font-size: 16px; }
.btn.ghost:hover { color: var(--ink); border-color: var(--muted); filter: none; }
.btn.sm { padding: 8px 16px; font-size: 15px; }
.btn:focus-visible, .opt:focus-visible, a:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* Quiz */
.topline { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-weight: 700; }
.secs { font-family: var(--font-display); font-size: 26px; font-variant-numeric: tabular-nums; }
.secs.low { color: var(--warn); }
.bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 100%; background: var(--accent); transform-origin: left; }
.bar > i.low { background: var(--warn); }
.opts { display: grid; gap: 12px; }
.opt {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--surface); color: var(--ink); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; font: 600 17px var(--font-body); cursor: pointer; min-height: 64px;
}
.opt:hover { border-color: var(--accent); }
.opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.letter {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-family: var(--font-display); font-weight: 800;
}
.opt.sel .letter { background: var(--accent); color: #fff; }
.otext { flex: 1; min-width: 0; }
.peers { display: flex; flex-wrap: wrap; justify-content: flex-end; max-width: 46%; }
.peer {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--surface); margin-left: -6px; animation: pop .35s ease-out both;
}
.peer svg { width: 18px; height: 18px; fill: #fff; }
@keyframes pop { from { transform: scale(.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .peer { animation: none; } }
.quizfoot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.hint { font-size: 14px; color: var(--muted); }
.status { font-weight: 700; }
.status.ok { color: var(--ok); }
.status.bad { color: var(--red); }
.code { font-family: var(--font-display); font-size: 36px; font-weight: 800; letter-spacing: .05em; font-variant-numeric: tabular-nums; }

/* Results */
.teams { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.team { border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 8px; border: 2px solid; }
.team.b { background: var(--blue-soft); border-color: var(--blue); }
.team.r { background: var(--red-soft); border-color: var(--red); }
.team.b h3, .team.b .big { color: var(--blue); }
.team.r h3, .team.r .big { color: var(--red); }
.big { font-family: var(--font-display); font-size: 56px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.stats { display: flex; gap: 20px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.chartbox { overflow-x: auto; }
.chartbox svg { display: block; width: 100%; min-width: 560px; height: auto; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
select { font: 600 16px var(--font-body); padding: 8px 12px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface); color: var(--ink); }
.notice { background: var(--accent-soft); border-radius: 10px; padding: 14px 16px; }

/* Results: verdict, flow, per-question ranking */
.verdict { font-family: var(--font-display); font-size: 20px; font-weight: 600; }
.verdict:empty { display: none; }
.big.blue { color: var(--blue); }
.big.red { color: var(--red); }
.big.sm { font-size: 36px; }
.flow { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 24px; align-items: center; }
@media (max-width: 640px) { .flow { grid-template-columns: 1fr; } }
.flowmain { display: flex; flex-direction: column; gap: 6px; }
.flowside { display: flex; flex-direction: column; gap: 6px; border-left: 3px solid var(--red); padding-left: 16px; }
.qrank { display: flex; flex-direction: column; gap: 14px; }
.qrow { display: flex; flex-direction: column; gap: 4px; }
.qhead { display: flex; gap: 10px; align-items: baseline; min-width: 0; }
.qno { font-family: var(--font-display); font-weight: 800; color: var(--muted); flex: none; min-width: 34px; }
.qtitle { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.qbar { display: flex; align-items: center; gap: 12px; }
.track { position: relative; flex: 1; height: 18px; background: var(--line); border-radius: 999px; }
.track .fill { position: absolute; inset: 0 auto 0 0; background: var(--blue); border-radius: 999px; transition: width .4s ease; }
.track .base { position: absolute; top: -4px; bottom: -4px; width: 4px; margin-left: -2px; background: var(--red); border-radius: 2px; }
.qpct { font-family: var(--font-display); font-weight: 800; font-size: 20px; color: var(--blue); min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; }
.qmeta { padding-left: 44px; }
@media (prefers-reduced-motion: reduce) { .track .fill { transition: none; } }

/* Results: entries table */
details summary { cursor: pointer; list-style-position: outside; }
.tablebox { overflow-x: auto; margin-top: 12px; }
.etable { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.etable th, .etable td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.etable th { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.etable td.tb { color: var(--blue); font-weight: 700; }
.etable td.tr { color: var(--red); font-weight: 700; }

/* Results v3: orange team + per-question option rows */
.team.o { background: var(--orange-soft); border-color: var(--orange); }
.team.o h3, .team.o .big { color: var(--orange); }
.etable td.to { color: var(--orange); font-weight: 700; }
.qlist { display: flex; flex-direction: column; gap: 22px; }
.qitem { display: flex; flex-direction: column; gap: 8px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.qitem:last-child { border-bottom: 0; padding-bottom: 0; }
.orow { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 8px 20px; align-items: center; }
@media (max-width: 640px) { .orow { grid-template-columns: 1fr; } }
.olabel { display: flex; align-items: center; gap: 8px; min-width: 0; }
.otag { flex: none; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; }
.orow.correct .otag { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.orow.crowd .otag { background: var(--line); color: var(--muted); }
.oletter { flex: none; font-family: var(--font-display); font-weight: 800; color: var(--muted); }
.otext { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.obars { display: flex; flex-direction: column; gap: 5px; }
.obar { display: flex; align-items: center; gap: 10px; }
.otrack { position: relative; flex: 1; height: 14px; background: var(--line); border-radius: 999px; overflow: hidden; }
.otrack i { position: absolute; inset: 0 auto 0 0; border-radius: 999px; transition: width .4s ease; }
.obar.b .otrack i { background: var(--blue); }
.obar.o .otrack i { background: var(--orange); }
.obar span { min-width: 44px; text-align: right; font-family: var(--font-display); font-weight: 800; font-variant-numeric: tabular-nums; }
.obar.b span { color: var(--blue); }
.obar.o span { color: var(--orange); }
@media (prefers-reduced-motion: reduce) { .otrack i { transition: none; } }

/* Cap avatars: fake classmates, the student's own cap, and the picker */
.peer { background: #eef1f6; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.peer svg { width: 24px; height: 24px; fill: currentColor; }
.peer.me { box-shadow: 0 0 0 2px var(--accent); z-index: 1; }
.hatpick { display: flex; flex-direction: column; gap: 10px; }
.hats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; max-width: 360px; }
.hat { aspect-ratio: 1; max-width: 100%; border-radius: 50%; border: 2px solid var(--line); background: #eef1f6; cursor: pointer; display: grid; place-items: center; padding: 0; }
.hat svg { width: 76%; height: 76%; }
.hat:hover { border-color: var(--muted); }
.hat.sel { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hat:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
