/* Colours, type, spacing and radii come from the Teacher Cris design system (tokens.json). */
:root {
  --cream: #fbf5ea;
  --parchment: #ead9bc;
  --ink: #1b2a52;
  --muted: #5a5f70;
  --blue: #2b4c9b;
  --gold: #d4a017;
  --gold-ink: #7a570c;
  --orange: #e07b1a;
  --line: #c9b48e;
  /* Not in the design system: right and wrong answers need their own pair. */
  --good: #2e6b3a;
  --bad: #a3341f;

  --display: "Libre Baskerville", Georgia, "Times New Roman", serif;
  --sans: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --space-2: 8px;
  --space-4: 16px;
  --space-6: 24px;
  --space-12: 48px;
  --radius-sm: 4px;
  --radius-md: 12px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--cream); color: var(--ink); font: 400 16px/26px var(--sans); }
h1, h2, h3 { margin: 0 0 .5em; }
h1 { font: 700 40px/46px var(--display); }
h2 { font: 700 28px/34px var(--display); }
h3 { font: 700 20px/28px var(--sans); }
p { margin: 0 0 .8em; }
a { color: var(--blue); }
code { background: var(--cream); border: 1px solid var(--line); padding: 0 .35em; border-radius: var(--radius-sm); }
svg.icon { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- controls ---------- */
input, textarea, select {
  font: inherit; color: var(--ink); width: 100%; padding: .55em .75em; margin: 0 0 var(--space-4);
  border: 1.5px solid var(--muted); border-radius: var(--radius-sm); background: #fff;
}
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
input[type=checkbox] { width: 1.2em; height: 1.2em; margin: 0; flex: none; accent-color: var(--blue); }
input[type=number] { width: 5.5em; }
input[type=file] { padding: .4em; }
label { display: block; font: 700 14px/20px var(--sans); color: var(--muted); }
label > input, label > textarea, label > select { margin-top: .3em; font: 400 16px/26px var(--sans); }
label.check { display: flex; align-items: center; gap: var(--space-2); color: var(--ink); font: 400 16px/26px var(--sans); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); font: 700 16px/24px var(--sans); cursor: pointer;
  padding: .5em 1em; border-radius: var(--radius-md); border: 1.5px solid var(--muted); background: var(--cream); color: var(--ink); text-decoration: none;
}
.btn:hover { border-color: var(--blue); color: var(--blue); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: var(--cream); }
.btn.primary:hover { background: var(--ink); border-color: var(--ink); color: var(--cream); }
.btn.accent { background: var(--orange); border-color: var(--orange); color: var(--ink); }
.btn.accent:hover { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.on { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn.big { padding: .75em 1.3em; font-size: 18px; }
.btn.tiny { padding: .1em .6em; font-size: 14px; }

.row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.row > input, .row > select, .row > label { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.stack > .row > input { margin: 0; }
.grow { flex: 1; min-width: 0; }
.note { color: var(--muted); font: 400 14px/20px var(--sans); }
.error { color: var(--bad); font-weight: 700; }
.empty { color: var(--muted); text-align: center; padding: var(--space-4); }
.good { color: var(--good); }
.code { font-family: ui-monospace, Consolas, monospace; letter-spacing: .12em; }
.tag { font: 700 12px/16px var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--blue); margin-bottom: .25em; }
.tag.live { color: var(--bad); }
.stars { color: var(--gold-ink); font-weight: 700; white-space: nowrap; }
.brand { font-family: var(--display); font-weight: 700; color: var(--ink); }
.brand b { color: var(--blue); }
.logo { display: block; width: 168px; height: auto; margin: 0 auto var(--space-4); }

.card { background: var(--parchment); border-radius: var(--radius-md); padding: var(--space-6); margin: 0 0 var(--space-6); }
.card.center { text-align: center; }
.narrow { max-width: 34rem; }
.card.center.narrow { margin: 8vh auto; }
.card .card, .card .resp-card { background: var(--cream); }

.spinner { width: 34px; height: 34px; margin: 2em auto; border: 4px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { display: inline-block; font: 700 12px/16px var(--sans); letter-spacing: .04em; padding: .2em .7em; border-radius: var(--radius-pill); background: var(--cream); color: var(--ink); border: 1px solid var(--line); white-space: nowrap; }
.badge.lv5, .badge.lv6, .badge.lv7, .badge.lv8 { background: var(--gold); border-color: var(--gold); }
.badge.lv9, .badge.lv10 { background: var(--blue); border-color: var(--blue); color: var(--cream); }

#toasts { position: fixed; left: 50%; bottom: 1.2em; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: var(--space-2); align-items: center; }
.toast { background: var(--ink); color: var(--cream); padding: .5em 1em; border-radius: var(--radius-md); max-width: 90vw; }
.toast.error { background: var(--bad); }

.modal-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(27, 42, 82, .6); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 1em; overflow: auto; }
.modal { background: var(--cream); color: var(--ink); border-radius: var(--radius-md); border: 1px solid var(--line); width: 100%; max-width: 30rem; }
.modal.wide { max-width: 52rem; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: var(--space-4) var(--space-6) 0; }
.modal-head h2 { margin: 0; }
.modal-body { padding: var(--space-4) var(--space-6) var(--space-6); }
.lightbox { max-width: 100%; max-height: 75vh; display: block; margin: auto; }

.offline { position: fixed; top: 0; left: 0; right: 0; z-index: 60; background: var(--orange); color: var(--ink); text-align: center; padding: .3em; font-weight: 700; }

/* ---------- drawing ---------- */
.sketch-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: var(--space-2); }
.tool { display: inline-flex; align-items: center; justify-content: center; font: inherit; min-width: 2.5em; height: 2.5em; border-radius: var(--radius-md); border: 1.5px solid transparent; background: transparent; cursor: pointer; color: inherit; }
.tool:hover { border-color: currentColor; }
.tool.on { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.swatch { width: 1.7em; height: 1.7em; border-radius: 50%; border: 2px solid var(--cream); box-shadow: 0 0 0 1.5px var(--muted); cursor: pointer; padding: 0; flex: none; }
.swatch.on { box-shadow: 0 0 0 3px var(--ink); }
.draw-wrap { background: #fff center / contain no-repeat; border: 1.5px solid var(--muted); border-radius: var(--radius-md); aspect-ratio: 4 / 3; margin-bottom: var(--space-4); overflow: hidden; }
.draw-canvas { width: 100%; height: 100%; display: block; cursor: crosshair; }

/* ---------- student ---------- */
body.student { display: flex; flex-direction: column; min-height: 100%; }
.student main { width: 100%; max-width: 34rem; margin: 0 auto; padding: var(--space-4); flex: 1; }
.student .brand { font-size: 40px; line-height: 46px; }
.student form { display: flex; flex-direction: column; }
.student .btn.big { width: 100%; margin-top: .3em; }
.teacher-link { display: block; text-align: center; padding: var(--space-4); font-size: 14px; color: var(--muted); }
.code-input { text-align: center; font: 700 2rem ui-monospace, Consolas, monospace; letter-spacing: .25em; text-transform: uppercase; }
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: var(--space-2); margin-bottom: var(--space-4); }
.roster-name { justify-content: flex-start; text-align: left; }
.roster-name.taken { opacity: .6; }
header.me { display: flex; align-items: center; gap: var(--space-2); padding: .2em .3em var(--space-4); }
header.me strong { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prompt { font: 700 24px/32px var(--display); white-space: pre-wrap; }
.options { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.option { display: flex; align-items: center; gap: .7em; text-align: left; font: 400 18px/26px var(--sans); padding: .7em; border-radius: var(--radius-md); border: 2px solid var(--line); background: var(--cream); color: var(--ink); cursor: pointer; }
.option.on { border-color: var(--blue); background: var(--blue); color: var(--cream); }
.option.on .letter { background: var(--gold); color: var(--ink); }
.option.static { cursor: default; }
.option.good { border-color: var(--good); color: var(--ink); }
.letter { flex: none; width: 1.9em; height: 1.9em; border-radius: var(--radius-pill); background: var(--blue); color: var(--cream); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .9em; }
.blanks { font-size: 20px; line-height: 2.6; white-space: pre-wrap; }
.blank { display: inline-block; width: 8em; margin: 0 .3em; padding: .2em .5em; }
.filled { font-size: 18px; white-space: pre-wrap; }
.filled b { color: var(--good); text-decoration: underline; text-decoration-color: var(--gold); text-decoration-thickness: 3px; }
div.check { width: 4.5rem; height: 4.5rem; margin: 0 auto var(--space-4); border-radius: 50%; background: var(--cream); border: 3px solid var(--blue); color: var(--blue); font-size: 2.2rem; display: flex; align-items: center; justify-content: center; }
div.check.good { border-color: var(--gold); background: var(--gold); color: var(--ink); }
div.check.bad { border-color: var(--muted); color: var(--muted); }
.pulse { width: 1.2rem; height: 1.2rem; margin: 1em auto 1.6em; border-radius: 50%; background: var(--gold); animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(212, 160, 23, .6); } 100% { box-shadow: 0 0 0 1.6rem rgba(212, 160, 23, 0); } }
.preview { display: block; max-width: 100%; max-height: 50vh; margin: 0 auto var(--space-4); border-radius: var(--radius-md); }
audio { width: 100%; margin: .6em 0; }
.btn.recording { background: var(--bad); border-color: var(--bad); color: var(--cream); }

/* ---------- teacher pages ---------- */
.topnav { display: flex; align-items: center; gap: .3em; padding: .5em var(--space-6); background: var(--cream); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topnav .brand { font-size: 24px; margin-right: var(--space-6); }
.topnav a { padding: .3em .9em; border-radius: var(--radius-pill); text-decoration: none; color: var(--ink); font-weight: 700; }
.topnav a:hover { color: var(--blue); }
.topnav a.on { background: var(--blue); color: var(--cream); }
.page { max-width: 76rem; margin: 0 auto; padding: var(--space-6) var(--space-6) var(--space-12); }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-6); }
.page-head h1 { margin: 0; }
.banner { display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); flex-wrap: wrap; background: var(--cream); border: 2px solid var(--gold); border-radius: var(--radius-md); padding: var(--space-4); margin-bottom: var(--space-6); font-weight: 700; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: var(--space-6); }
.tile { display: block; background: var(--parchment); border-radius: var(--radius-md); padding: var(--space-4); text-decoration: none; color: inherit; border: 2px solid transparent; }
.tile:hover { border-color: var(--blue); }
.tile h3 { font: 700 20px/28px var(--display); }
.tile p { color: var(--muted); margin: 0; }
.tile-kind { font: 700 12px/16px var(--sans); color: var(--gold-ink); text-transform: uppercase; letter-spacing: .08em; margin-bottom: .4em; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: var(--space-6); align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.preview-box { margin-top: var(--space-4); }
.preview-box iframe { width: 100%; aspect-ratio: 16 / 10; border: 1.5px solid var(--line); border-radius: var(--radius-md); background: var(--ink); }
.activity-row, .launch-row { display: flex; align-items: center; gap: 6px; padding: .6em; background: var(--cream); border: 1px solid var(--line); border-radius: var(--radius-md); margin-bottom: var(--space-2); }
.activity-prompt { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.thumb { height: 4.5rem; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.draft { display: flex; gap: .7em; align-items: flex-start; padding: .7em; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-md); margin-bottom: var(--space-2); color: var(--ink); font: 400 16px/26px var(--sans); }
.draft ol { margin: .3em 0 0; padding-left: 1.6em; }
.draft li.good { font-weight: 700; }
.table { width: 100%; border-collapse: collapse; }
.table.card { padding: 0; overflow: hidden; display: table; }
.table th, .table td { text-align: left; padding: .5em .9em; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font: 700 12px/16px var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.table td.good { color: var(--good); font-weight: 700; }
.table td.bad { color: var(--bad); text-decoration: line-through; }

/* ---------- results ---------- */
.bar-row { margin-bottom: var(--space-4); }
.bar-label { display: flex; align-items: center; gap: .6em; font-weight: 700; margin-bottom: .3em; }
.bar-count { margin-left: auto; white-space: nowrap; }
.bar-track { height: 1.6em; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-pill); overflow: hidden; }
.bar-fill { height: 100%; background: var(--blue); border-radius: var(--radius-pill); transition: width .5s; min-width: 3px; }
.bar-row.good { color: var(--ink); }
.bar-row.good .bar-fill { background: var(--gold); }
.bar-row.good .bar-track { border: 2px solid var(--gold-ink); }
.bar-names { font-size: 14px; color: var(--muted); margin-top: .25em; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: var(--space-4); }
.cards.small { margin-top: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); }
.resp-card { background: var(--parchment); color: var(--ink); border-radius: var(--radius-md); padding: var(--space-4); }
.resp-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.resp-name { font: 700 14px/20px var(--sans); color: var(--muted); margin-top: .4em; }
.resp-actions { display: flex; gap: 6px; margin-top: .5em; }
.hidden-resp { opacity: .4; }
.cloud { display: flex; flex-wrap: wrap; gap: .3em 1.1em; align-items: center; justify-content: center; padding: var(--space-4); font-family: var(--display); font-weight: 700; line-height: 1.15; }
.summary { font: 700 20px/28px var(--sans); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: var(--space-4); }
.gallery figure { margin: 0; background: var(--parchment); color: var(--ink); border-radius: var(--radius-md); overflow: hidden; }
.gallery img, .gallery video { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: #fff; display: block; cursor: zoom-in; }
.gallery video { background: var(--ink); cursor: default; }
.gallery figcaption { padding: .4em .6em; font: 700 14px/20px var(--sans); display: flex; justify-content: space-between; align-items: center; gap: .4em; }
.gallery .resp-actions { margin: 0; }

/* ---------- present view ---------- */
body.presenting { overflow: hidden; background: var(--ink); }
.present { display: flex; height: 100vh; color: var(--cream); }
.stage-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.stage { position: relative; flex: 1; min-height: 0; background: var(--ink); overflow: hidden; }
.fill { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.no-slides { display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--parchment); text-align: center; padding: 2em; }
.annot { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; cursor: crosshair; }
.layer { position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; }
.layer.browser { background: #fff; }
.layer.browser iframe { position: static; flex: 1; }
.layer.whiteboard { z-index: 4; background: #fff; color: var(--ink); }
.layer.whiteboard[data-bg=grid] { background-image: linear-gradient(var(--parchment) 1px, transparent 1px), linear-gradient(90deg, var(--parchment) 1px, transparent 1px); background-size: 40px 40px; }
.layer.whiteboard[data-bg=lined] { background-image: linear-gradient(transparent 47px, var(--line) 48px); background-size: 100% 48px; }
.layer.whiteboard[data-bg=dark] { background: var(--ink); }
.wb-canvas { flex: 1; width: 100%; min-height: 0; cursor: crosshair; }
.layer-bar { display: flex; align-items: center; gap: var(--space-2); padding: .4em .6em; background: var(--cream); color: var(--ink); border-top: 1px solid var(--line); }
.layer-bar.top { border-top: 0; border-bottom: 1px solid var(--line); }
.layer-bar input, .layer-bar select { margin: 0; }
.layer-bar select { width: auto; }
.layer.activity { z-index: 5; background: var(--cream); color: var(--ink); overflow: auto; padding: var(--space-12) var(--space-12) 0; }
.act-head h1 { font-size: clamp(28px, 3.4vw, 56px); line-height: 1.15; white-space: pre-wrap; }
.act-wait { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-4); text-align: center; padding: var(--space-4) 0; }
.options.preview { width: 100%; max-width: 46rem; display: grid; grid-template-columns: 1fr 1fr; }
.options.preview .option { font-size: 20px; background: var(--parchment); border-color: var(--parchment); }
.bg-preview { max-height: 30vh; border-radius: var(--radius-md); border: 1px solid var(--line); }
.count-box { font-size: 20px; color: var(--muted); }
.count { font: 700 clamp(3rem, 9vw, 6rem)/1 var(--display); color: var(--blue); text-decoration: underline; text-decoration-color: var(--gold); text-decoration-thickness: 6px; text-underline-offset: 10px; margin-bottom: 18px; }
.join-line { font-size: 20px; }
.join-line .code { font-size: 1.5em; color: var(--blue); }
.act-results { flex: 1; padding: var(--space-4) 0 var(--space-6); font-size: 18px; }
.act-bar { position: sticky; bottom: 0; display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; padding: var(--space-4) 0; background: var(--cream); border-top: 1px solid var(--line); }
.chip { position: absolute; z-index: 6; top: .8em; left: 50%; transform: translateX(-50%); font: 700 16px/24px var(--sans); padding: .4em 1.1em; border-radius: var(--radius-pill); border: 0; background: var(--orange); color: var(--ink); cursor: pointer; }
.present .offline { position: absolute; }
.timer-box { position: absolute; z-index: 7; top: .8em; right: .8em; background: var(--cream); color: var(--ink); border: 2px solid var(--gold); border-radius: var(--radius-md); padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); align-items: center; }
.timer-box input { margin: 0; width: 4.2em; padding: .15em .4em; }
.timer-face { font: 700 3.4rem/1 var(--display); }
.timer-box.done { background: var(--orange); border-color: var(--orange); animation: flash 1s steps(2) 5; }
@keyframes flash { 50% { background: var(--cream); } }
.toolbar { display: flex; align-items: center; gap: 4px; padding: 6px 10px; background: var(--ink); color: var(--cream); overflow-x: auto; }
.toolbar .tool.wide { flex-direction: column; height: auto; padding: 4px 9px; line-height: 1.15; }
.toolbar .tool small { font: 700 11px/14px var(--sans); white-space: nowrap; }
.toolbar .swatch { border-color: var(--ink); box-shadow: 0 0 0 1.5px var(--line); }
.toolbar .swatch.on { box-shadow: 0 0 0 3px var(--cream); }
.sep { width: 1px; align-self: stretch; background: var(--muted); margin: 3px 6px; }
.panel { width: 21rem; flex: none; background: var(--parchment); color: var(--ink); overflow: auto; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); }
.panel > * { flex: none; }
.panel h3 { margin: var(--space-2) 0 0; }
.panel-closed .panel { display: none; }
.join-box { text-align: center; background: var(--blue); color: var(--cream); border-radius: var(--radius-md); padding: var(--space-4); }
.join-box small { font: 700 12px/16px var(--sans); letter-spacing: .08em; text-transform: uppercase; }
.join-url { font-weight: 700; overflow-wrap: anywhere; }
.join-code { font: 700 2.6rem/1.25 ui-monospace, Consolas, monospace; letter-spacing: .15em; border-bottom: 4px solid var(--gold); display: inline-block; margin-bottom: 6px; }
.people { max-height: 34vh; overflow: auto; }
.person { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.person .dot { width: .6em; height: .6em; border-radius: 50%; background: var(--good); flex: none; }
.person.away { color: var(--muted); }
.person.away .dot { background: transparent; border: 1.5px solid var(--muted); }
.launch-row { margin: 0; }
.launch-row.current { border: 2px solid var(--gold-ink); }
.picker-face { font: 700 40px/46px var(--display); text-align: center; padding: var(--space-12) .3em; color: var(--muted); overflow-wrap: anywhere; }
.picker-face.landed { color: var(--blue); animation: pop .4s; }
@keyframes pop { 50% { transform: scale(1.15); } }
.leaderboard { list-style: none; margin: var(--space-4) 0 0; padding: 0; }
.leaderboard li { display: flex; align-items: center; gap: .7em; padding: .5em .8em; border-bottom: 1px solid var(--line); font-size: 18px; }
.leaderboard .rank { width: 2em; height: 2em; border-radius: var(--radius-pill); background: var(--parchment); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.leaderboard .top1 .rank, .leaderboard .top2 .rank, .leaderboard .top3 .rank { background: var(--gold); }
.leaderboard .top1 { font: 700 24px/32px var(--display); }
