/* Gradient Maths Starters — shares the Gradient Maths look: navy grid paper, Archivo, IBM Plex Mono, square corners, one red. */
:root {
  --paper: #0b1631; --rule: #1a2a50; --rule-strong: #2b3f6e; --tint: #12214a;
  --ink: #eef3fb; --ink-2: #c9d8f0; --muted: #9fb1d6;
  --red: #ff6a4d; --red-solid: #c8321c; --red-hover: #a3260f;
  --band: #eef3fb; --on-band: #0b1631;
  --card: #f7f9fd; --card-ink: #0b1631; --card-soft: #51618a; --card-rule: #c3cde0; --ans: #c8321c; --shadow: #2b3f6e;
  --display: "Archivo", "Arial Narrow", system-ui, sans-serif;
  --body: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}
[data-theme="light"] {
  --paper: #eef3fb; --rule: #dbe3f1; --rule-strong: #b9c6de; --tint: #dfe7f4;
  --ink: #0b1631; --ink-2: #22345e; --muted: #55668c; --red: #c8321c;
  --band: #0b1631; --on-band: #eef3fb; --card: #ffffff; --shadow: #0b1631;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 400 16px/1.5 var(--body); color: var(--ink);
  background: linear-gradient(var(--rule) 1px, transparent 1px) 0 0 / 24px 24px, linear-gradient(90deg, var(--rule) 1px, transparent 1px) 0 0 / 24px 24px, var(--paper);
  display: grid; grid-template-rows: auto auto minmax(0, 1fr); height: 100vh; height: 100dvh; overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border-radius: 0; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }
.grow { flex: 1; }

/* ---------- header band ---------- */
.band { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 22px; background: var(--band); color: var(--on-band); padding: 8px 20px; }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-t b { display: block; font: 800 23px/1 var(--display); font-stretch: 88%; letter-spacing: -0.01em; }
.brand-t em { display: block; font: 400 12px/1.4 var(--mono); font-style: normal; }
.modes { display: flex; gap: 4px; margin-left: 12px; flex-wrap: wrap; }
.modes button { background: none; border: 2px solid transparent; padding: 8px 14px; font: 700 15px/1 var(--body); }
.modes button:hover { border-color: currentColor; }
.modes button.on { background: var(--on-band); color: var(--band); }
.band-r { margin-left: auto; display: flex; gap: 8px; }
.ghost { background: none; border: 2px solid currentColor; padding: 9px 14px; font: 700 14px/1 var(--body); }
.ghost:hover { background: var(--on-band); color: var(--band); border-color: var(--on-band); }
.solid { background: var(--red-solid); color: #fff; border: 2px solid var(--red-solid); padding: 8px 16px; font: 800 15px/1 var(--body); }
.solid:hover { background: var(--red-hover); border-color: var(--red-hover); }

/* ---------- setup rows ---------- */
.setup { padding: 10px 20px 4px; display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 38px; }
.lab { font: 600 11px/1 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.btn { background: var(--paper); border: 2px solid var(--ink); padding: 9px 14px; font: 700 14px/1 var(--body); color: var(--ink); }
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.quiet { border-color: var(--rule-strong); color: var(--ink-2); }
.btn.quiet:hover { border-color: var(--ink); background: var(--tint); color: var(--ink); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 8px; background: var(--tint); border: 1px solid var(--rule-strong); padding: 6px 6px 6px 12px; font: 600 13px/1.2 var(--body); color: var(--ink); }
.chip small, .chip .rlbtn { font: 600 10px/1 var(--mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--red); }
.chip .rlbtn { width: auto; height: auto; padding: 0 0 1px; border-bottom: 1px dashed currentColor; cursor: pointer; }
.chip .rlbtn:hover { color: var(--ink); }
.rl { flex: none; font: 600 10px/1 var(--mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ans); white-space: nowrap; }
.chip button { background: none; border: 0; width: 22px; height: 22px; line-height: 1; color: var(--muted); font-size: 16px; }
.chip button:hover { color: var(--red); }
.seg { display: inline-flex; border: 2px solid var(--ink); background: var(--paper); }
.seg button { background: none; border: 0; border-right: 1px solid var(--rule-strong); padding: 9px 14px; font: 700 14px/1 var(--body); color: var(--ink-2); display: inline-flex; align-items: center; gap: 7px; }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--tint); }
.seg button.on { background: var(--ink); color: var(--paper); }
.chk { display: inline-flex; align-items: center; gap: 6px; font: 600 14px/1 var(--body); color: var(--ink-2); cursor: pointer; }
.chk input { width: 17px; height: 17px; accent-color: var(--red-solid); margin: 0; }
select, input[type="text"], input[type="search"], input[type="number"] { background: var(--paper); border: 2px solid var(--ink); padding: 8px 12px; font: 600 14px/1.2 var(--body); color: var(--ink); border-radius: 0; }
.note { font: 400 12px/1.3 var(--mono); color: var(--muted); }

.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 0.95em; flex: none; }
.bars i { width: 0.3em; min-width: 3px; border: 1px solid currentColor; }
.bars i:nth-child(1) { height: 40%; } .bars i:nth-child(2) { height: 70%; } .bars i:nth-child(3) { height: 100%; }
.b1 i:nth-child(1), .b2 i:nth-child(-n + 2), .b3 i { background: currentColor; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

/* ---------- stage ---------- */
#stage { position: relative; min-height: 0; overflow: hidden; padding: 12px 20px 84px; }
#view { height: 100%; }
body[data-mode="ws"] #stage { overflow: auto; padding-bottom: 110px; }
body[data-mode="ws"] #view { height: auto; }
body[data-mode="ws"] #ink, body[data-mode="ws"] #tbar { display: none; }
body.present .band, body.present .setup { display: none; }
body.present { grid-template-rows: minmax(0, 1fr); }
body.present #stage { padding-top: 18px; }
#ink { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 30; pointer-events: none; }
body.pen #ink { pointer-events: auto; cursor: crosshair; touch-action: none; }
#tbar { position: absolute; left: 0; right: 0; top: 0; height: 5px; z-index: 35; }
#tbar i { display: block; height: 100%; width: 0; background: var(--red); }
#count { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; text-align: center; background: rgba(11, 22, 49, 0.94); color: #fff; font: 900 min(34vh, 22vw)/1 var(--display); font-stretch: 75%; text-transform: uppercase; }
#count.go { color: var(--red); font-size: min(22vh, 13vw); }

/* ---------- maths ---------- */
.m { white-space: nowrap; }
.m i { font-family: "Times New Roman", Times, serif; font-style: italic; font-size: 1.1em; font-weight: 500; padding: 0 0.02em; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: 0.8em; line-height: 1.15; margin: 0 0.12em; }
.frac > span:first-child { border-bottom: 0.08em solid currentColor; padding: 0 0.2em 0.06em; }
.frac > span:last-child { padding: 0.06em 0.2em 0; }
.rt > span { border-top: 0.08em solid currentColor; padding: 0 0.1em; }
sup { font-size: 0.62em; vertical-align: 0.6em; line-height: 0; }
.vec { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; line-height: 1.12; font-size: 0.85em; padding: 0.05em 0.4em; margin: 0 0.15em; border-left: 0.09em solid currentColor; border-right: 0.09em solid currentColor; border-radius: 0.55em / 50%; }
.vb { font-weight: 900; }
.ov { border-top: 0.08em solid currentColor; }
.tb { border-collapse: collapse; margin: 0.45em auto; font-size: 0.9em; }
.tb th, .tb td { border: 0.08em solid currentColor; padding: 0.12em 0.55em; text-align: center; }
.tb th { text-align: left; font-weight: 600; }
.dg { stroke: currentColor; fill: none; stroke-width: 2; display: block; margin: 0.3em auto 0; overflow: visible; }
.dg text { fill: currentColor; stroke: none; font-size: 19px; font-family: var(--body); font-weight: 600; }

.dg .gl { stroke-width: 0.6; opacity: 0.3; }
.dg text.xs { font-size: 11px; }
.dg text.sm { font-size: 14px; }

/* ---------- starter grid ---------- */
.grid { display: grid; height: 100%; gap: 14px; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); grid-template-rows: repeat(var(--rows), minmax(0, 1fr)); }
.cell { container-type: size; background: var(--card); color: var(--card-ink); border: 2px solid var(--card-ink); box-shadow: 5px 5px 0 var(--shadow); display: flex; flex-direction: column; cursor: pointer; min-height: 0; min-width: 0; user-select: none; }
.cell > header { display: flex; align-items: center; gap: 0.6em; padding: 0 0.5em 0 0; font: 600 clamp(11px, 5.6cqh, 15px)/1 var(--mono); text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 2px solid var(--card-ink); flex: none; }
.num { background: var(--card-ink); color: var(--card); padding: 0.5em 0.65em; font-weight: 600; }
.tname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--card-soft); }
.tname b { color: var(--ans); font-weight: 600; }
.tools { display: flex; gap: 2px; }
.tools button { background: none; border: 0; color: var(--card-soft); width: 2em; height: 2em; font: 600 1.1em/1 var(--mono); padding: 0; }
.tools button:hover { background: var(--card-ink); color: var(--card); }
.qa { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: safe center; padding: 0.2em 4cqw; text-align: center; overflow: hidden; }
.cell .q { font-size: calc(min(9cqw, 21cqh) * var(--k, 1) * var(--fit, 1)); font-weight: 600; line-height: 1.28; }
/* tables and diagrams under a question shrink with it (fitGrid in app.js) */
.qa > :not(.q) { zoom: var(--fit, 1); }
.cell .q { flex: none; max-width: 100%; }
.cell .dg { flex: 1 1 0; min-height: 0; height: auto; max-height: 72cqh; width: 100%; margin-top: 0.15em; }
.lvl { display: inline-flex; align-items: center; gap: 10px; flex-wrap: nowrap; }
.cell .ans { flex: none; font-size: min(6.4cqw, 14cqh); font-weight: 800; color: var(--ans); padding: 0.18em 0.5em 0.3em; text-align: center; border-top: 2px dashed var(--card-rule); min-height: 1.75em; }
.cell .ans > * , .cell .ans { visibility: hidden; }
.cell.shown .ans, .cell.shown .ans > * { visibility: visible; }
.cell.shown .ans { border-top-style: solid; border-top-color: var(--ans); }

.nodc { container-type: size; background: var(--red-solid); color: #fff; border: 2px solid var(--card-ink); box-shadow: 5px 5px 0 var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.4em; min-height: 0; min-width: 0; }
.nodc span { font: 600 clamp(11px, 6.5cqh, 17px)/1 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; }
.nodc b { font: 900 min(30cqw, 60cqh)/0.9 var(--display); font-stretch: 75%; }

/* ---------- zoomed question ---------- */
#zoom { position: absolute; inset: 0; z-index: 20; padding: 12px 20px 84px; background: linear-gradient(var(--rule) 1px, transparent 1px) 0 0 / 24px 24px, linear-gradient(90deg, var(--rule) 1px, transparent 1px) 0 0 / 24px 24px, var(--paper); }
.zcard { height: 100%; background: var(--card); color: var(--card-ink); border: 2px solid var(--card-ink); box-shadow: 6px 6px 0 var(--shadow); display: flex; flex-direction: column; }
.zcard > header { display: flex; align-items: center; gap: 12px; font: 600 13px/1 var(--mono); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 2px solid var(--card-ink); padding-right: 8px; }
.zcard > header .num { padding: 12px 14px; }
.zbody { flex: 1; min-height: 0; padding: 2.2vh 3vw; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 3vw; }
.zbody .q { font-size: calc(clamp(26px, 3.6vw, 62px) * var(--k, 1)); font-weight: 700; line-height: 1.25; }
.zbody .dg { height: 30vh; width: auto; margin: 0.6em 0 0; }
.zwork { border-left: 2px dashed var(--card-rule); padding-left: 3vw; font-size: clamp(20px, 2.5vw, 42px); }
.kbtn { background: var(--card); color: var(--card-ink); border: 2px solid var(--card-ink); padding: 9px 14px; font: 700 14px/1 var(--body); }
.kbtn:hover { background: var(--card-ink); color: var(--card); }
.kbtn.red { background: var(--red-solid); border-color: var(--red-solid); color: #fff; }

.steps { list-style: none; margin: 0.5em 0 0; padding: 0; counter-reset: s; }
.steps li { counter-increment: s; visibility: hidden; margin: 0.42em 0; padding-left: 1.7em; position: relative; line-height: 1.3; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0.2em; font: 600 0.5em/1 var(--mono); border: 1.5px solid currentColor; width: 1.9em; height: 1.9em; display: grid; place-items: center; }
.steps li.on { visibility: visible; }
.steps li.final { color: var(--ans); font-weight: 800; }
.steps li.final::before { content: "="; }

/* ---------- I do / We do / You do ---------- */
.iwy { display: grid; grid-template-columns: 1fr 1fr 1.05fr; gap: 14px; height: 100%; }
.iwy.f-i { grid-template-columns: 1fr 58px 58px; } .iwy.f-w { grid-template-columns: 58px 1fr 58px; } .iwy.f-y { grid-template-columns: 58px 58px 1fr; }
.col { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--card); color: var(--card-ink); border: 2px solid var(--card-ink); box-shadow: 5px 5px 0 var(--shadow); }
.col > h2 { display: flex; align-items: baseline; gap: 0.5em; margin: 0; padding: 0.3em 0.5em 0.26em; background: var(--card-ink); color: var(--card); font: 900 clamp(22px, 2.5vw, 38px)/1 var(--display); font-stretch: 75%; text-transform: uppercase; cursor: pointer; white-space: nowrap; overflow: hidden; }
.col.i > h2 { background: var(--red-solid); color: #fff; }
.col > h2 span { font: 600 11px/1 var(--mono); letter-spacing: 0.06em; opacity: 0.85; font-stretch: 100%; }
.col > h2 em { margin-left: auto; font: 600 11px/1 var(--mono); font-style: normal; opacity: 0.8; }
.col .body { flex: 1; min-height: 0; padding: 14px 18px; overflow: hidden; font-size: clamp(17px, 1.9vw, 32px); }
.col .q { font-weight: 700; line-height: 1.3; font-size: calc(1em * var(--k, 1)); }
.col .dg { height: 17vh; width: auto; margin: 0.4em 0 0; }
.col .steps { font-size: 0.86em; }
.col .body { overflow: auto; }
.col .body.n2 { font-size: clamp(15px, 1.6vw, 27px); }
.col .body.n3 { font-size: clamp(13px, 1.35vw, 23px); }
.exs { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.7em; }
.exs li { cursor: pointer; }
.exs li + li { border-top: 2px dashed var(--card-rule); padding-top: 0.65em; }
.n2 .dg, .n3 .dg { height: 12vh; }
.colbtns { display: flex; gap: 8px; padding: 10px; border-top: 2px solid var(--card-ink); flex: none; }
.iwy[class*="f-"] .col:not(.focus) .body, .iwy[class*="f-"] .col:not(.focus) .colbtns, .iwy[class*="f-"] .col:not(.focus) h2 span, .iwy[class*="f-"] .col:not(.focus) h2 em { display: none; }
.iwy[class*="f-"] .col:not(.focus) > h2 { writing-mode: vertical-rl; flex: 1; padding: 0.5em 0.25em; align-items: center; }
.iwy[class*="f-"] .col.focus .body { font-size: clamp(22px, 2.8vw, 46px); }
.ylist { list-style: none; margin: 0; padding: 0; counter-reset: y; display: grid; gap: 0.5em; font-size: 0.8em; }
.iwy.f-y .ylist { grid-template-columns: 1fr 1fr; gap: 0.7em 1.5em; }
.ylist li { counter-increment: y; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 0.6em; align-items: start; padding-bottom: 0.45em; border-bottom: 2px dashed var(--card-rule); }
.ylist li::before { content: counter(y); font: 600 0.55em/1 var(--mono); background: var(--card-ink); color: var(--card); width: 2em; height: 2em; display: grid; place-items: center; margin-top: 0.3em; }
.ylist .dg { height: 11vh; margin: 0.2em 0 0; }
.ylist .ans { color: var(--ans); font-weight: 800; visibility: hidden; text-align: right; }
.ylist.shown .ans { visibility: visible; }

/* ---------- mini-whiteboards ---------- */
.wb { height: 100%; display: flex; flex-direction: column; gap: 12px; }
.wb-top { display: flex; align-items: center; gap: 14px; font: 600 12px/1 var(--mono); text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); flex: none; }
.dots { display: flex; gap: 5px; }
.dots i { width: 22px; height: 6px; background: var(--rule-strong); }
.dots i.on { background: var(--red); }
.dots i.done { background: var(--ink-2); }
.wb-q { flex: 1; min-height: 0; background: var(--card); color: var(--card-ink); border: 2px solid var(--card-ink); box-shadow: 5px 5px 0 var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 2vh 4vw; overflow: hidden; }
.wb-q .q { font-size: calc(clamp(30px, 4.6vw, 84px) * var(--k, 1)); font-weight: 700; line-height: 1.25; }
.wb-q .q { flex: none; }
.wb-q .dg { flex: 1 1 0; min-height: 0; height: auto; max-height: 34vh; width: 100%; }
.iwy[class*="f-"] .col.focus .dg { height: 24vh; }
.iwy[class*="f-"] .col.focus .n2 .dg, .iwy[class*="f-"] .col.focus .n3 .dg { height: 18vh; }
.wb-q .ans { margin-top: 0.4em; font-size: clamp(30px, 4.6vw, 84px); font-weight: 900; color: var(--ans); visibility: hidden; }
.wb.revealed .wb-q .ans { visibility: visible; }
.claim { margin-top: 0.5em; font-size: clamp(26px, 3.6vw, 64px); font-weight: 800; border: 3px solid var(--card-ink); padding: 0.15em 0.6em; }
.claim small { display: block; font: 600 12px/1.6 var(--mono); text-transform: uppercase; letter-spacing: 0.07em; color: var(--card-soft); }
.verdict { margin-top: 0.5em; visibility: hidden; font: 900 clamp(26px, 3.4vw, 60px)/1.1 var(--display); font-stretch: 75%; text-transform: uppercase; color: var(--ans); }
.verdict small { display: block; font: 500 clamp(13px, 1.3vw, 20px)/1.4 var(--body); font-stretch: 100%; text-transform: none; color: var(--card-ink); margin-top: 0.3em; }
.wb.revealed .verdict { visibility: visible; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; flex: none; }
.opt { background: var(--card); color: var(--card-ink); border: 2px solid var(--card-ink); box-shadow: 5px 5px 0 var(--shadow); display: flex; align-items: center; gap: 0.6em; padding: 0.3em 0.6em 0.3em 0; font-size: clamp(22px, 3vw, 54px); font-weight: 700; min-height: 2.1em; }
.opt > b { flex: none; align-self: stretch; display: grid; place-items: center; width: 1.7em; background: var(--card-ink); color: var(--card); font: 900 0.85em/1 var(--display); }
.opt > span { flex: 1; min-width: 0; }
.opt em { display: none; font: 500 clamp(12px, 1.15vw, 18px)/1.35 var(--body); font-style: normal; color: var(--card-soft); margin-top: 0.15em; }
.wb.revealed .opt em { display: block; }
.wb.revealed .opt.ok { border-color: var(--ans); box-shadow: 0 0 0 5px var(--ans); }
.wb.revealed .opt.ok > b { background: var(--ans); color: #fff; }
.wb.revealed .opt.ok > b::after { content: "✓"; font-size: 0.6em; display: block; }
.wb.revealed .opt.no > span > .ot { opacity: 0.55; }

/* ---------- dock ---------- */
#dock { position: fixed; left: 10px; right: 10px; bottom: 14px; z-index: 60; display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; justify-content: center; pointer-events: none; }
.grp { display: flex; align-items: center; background: var(--paper); border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--shadow); pointer-events: auto; }
.grp button { background: none; border: 0; border-right: 1px solid var(--rule-strong); padding: 0 14px; height: 42px; font: 700 14px/1 var(--body); color: var(--ink); white-space: nowrap; }
.grp button:last-child { border-right: 0; }
.grp button:hover { background: var(--tint); }
.grp button.red { background: var(--red-solid); color: #fff; }
.grp button.red:hover { background: var(--red-hover); }
.grp button.on { background: var(--ink); color: var(--paper); }
.grp .time { font: 600 18px/42px var(--mono); padding: 0 12px; border-right: 1px solid var(--rule-strong); min-width: 76px; text-align: center; }
body.timeup .grp .time { background: var(--red-solid); color: #fff; }
.grp .sw { width: 34px; padding: 0; display: grid; place-items: center; }
.grp .sw i { width: 18px; height: 18px; border-radius: 50%; display: block; border: 2px solid transparent; }
.grp .sw.on { background: none; } .grp .sw.on i { outline: 2px solid var(--ink); outline-offset: 2px; }
body:not(.pen) .grp .penonly { display: none; }

/* ---------- dialogs ---------- */
dialog { border: 2px solid var(--ink); background: var(--paper); color: var(--ink); padding: 0; box-shadow: 8px 8px 0 var(--shadow); width: min(1100px, 94vw); max-height: 88vh; }
dialog::backdrop { background: rgba(5, 10, 26, 0.7); }
.dlg { display: flex; flex-direction: column; max-height: 88vh; }
.dlg.narrow { width: 100%; }
#savedDlg { width: min(560px, 94vw); }
.dlg header { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 2px solid var(--ink); }
.dlg h2 { margin: 0; font: 900 26px/1 var(--display); font-stretch: 75%; text-transform: uppercase; }
.dlg header input { flex: 1; min-width: 120px; }
.hint { font: 400 12px/1.5 var(--mono); color: var(--muted); margin: 10px 18px 0; }

/* ---------- write your own ---------- */
textarea { font: 600 14px/1.35 var(--body); color: var(--ink); background: var(--paper); border: 2px solid var(--ink); padding: 8px 12px; border-radius: 0; resize: vertical; width: 100%; min-height: 40px; }
#ownDlg header { flex-wrap: wrap; }
#ownDlg [hidden] { display: none; }
.own { overflow: auto; padding: 14px 18px 18px; display: grid; gap: 14px; align-items: start; }
.own.iwy { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.own.wb { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.own fieldset { border: 2px solid var(--ink); margin: 0; padding: 8px 12px 12px; display: grid; gap: 8px; min-width: 0; }
.own legend { font: 900 20px/1 var(--display); font-stretch: 75%; text-transform: uppercase; padding: 0 6px; }
.own fieldset > p { margin: 0; font: 400 12px/1.4 var(--mono); color: var(--muted); }
.own input[type="text"] { width: 100%; min-width: 0; }
.own > .btn { justify-self: start; }
.own-ex { display: grid; gap: 6px; }
.own-ex + .own-ex { border-top: 2px dashed var(--rule-strong); padding-top: 10px; }
.own-ex small { display: flex; justify-content: space-between; align-items: center; font: 600 11px/1 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.linkb { background: none; border: 0; padding: 4px 0; font: 600 12px/1 var(--body); color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; text-transform: none; letter-spacing: 0; justify-self: start; }
.linkb:hover { color: var(--ink); }
.own-row { display: grid; grid-template-columns: 18px minmax(0, 1.6fr) minmax(0, 1fr); gap: 6px; align-items: center; }
.own-row b, .own-opt b { font: 600 12px/1 var(--mono); }
.own-opt { display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(0, 1.5fr); gap: 6px; align-items: center; }
.own-opt label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; padding: 6px 2px; }
.own-opt input[type="radio"] { width: 17px; height: 17px; margin: 0; accent-color: var(--red-solid); }
.own-opt:has(input:checked) input[type="text"] { border-color: var(--ans); }
@media (max-width: 900px) { .own.iwy, .own.wb { grid-template-columns: minmax(0, 1fr); } }
.dot { display: inline-block; width: 7px; height: 7px; background: var(--red); border-radius: 50%; vertical-align: 1px; }
.pick-grid { overflow: auto; padding: 14px 18px 20px; columns: 3 260px; column-gap: 26px; }
.pick-grid section { break-inside: avoid; margin-bottom: 18px; }
.pick-grid h3 { font: 600 11px/1 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--red); margin: 0 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--rule-strong); }
.tp { display: flex; width: 100%; align-items: center; gap: 8px; text-align: left; background: none; border: 1px solid transparent; padding: 6px 8px; font: 500 15px/1.25 var(--body); color: var(--ink-2); }
.tp:hover { border-color: var(--rule-strong); background: var(--tint); }
.tp[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 700; }
.tp .dot { margin-left: auto; flex: none; }
.tp[hidden] { display: none; }
.save-row { display: flex; gap: 10px; align-items: center; padding: 14px 18px 0; }
.save-row input { flex: 1; }
.save-row .hint { margin: 0; }
.saved { list-style: none; margin: 14px 0 0; padding: 0 18px 18px; overflow: auto; }
.saved li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--rule-strong); }
.saved li b { flex: 1; font-weight: 700; }
.saved li small { font: 400 11px var(--mono); color: var(--muted); }
.saved .empty { color: var(--muted); font: 400 13px var(--mono); }
#toast { position: fixed; left: 50%; top: 18px; transform: translate(-50%, -150%); background: var(--ink); color: var(--paper); padding: 10px 16px; font: 700 14px/1.2 var(--body); z-index: 100; transition: transform 0.2s; border: 2px solid var(--paper); }
#toast.on { transform: translate(-50%, 0); }

/* ---------- worksheet ---------- */
.ws-wrap { display: flex; flex-direction: column; align-items: center; gap: 26px; padding-top: 6px; }
.sheet { background: #fff; color: #000; width: 210mm; height: 297mm; padding: 11mm 11mm 8mm; display: flex; flex-direction: column; box-shadow: 8px 8px 0 var(--shadow); font-family: var(--body); flex: none; overflow: hidden; }
.sheet.a5 { width: 148.5mm; height: 210mm; padding: 8mm 8mm 6mm; }
.spread { display: flex; width: 297mm; height: 210mm; background: #fff; box-shadow: 8px 8px 0 var(--shadow); flex: none; }
.spread .sheet { box-shadow: none; }
.spread .sheet + .sheet { border-left: 1px dashed #000; }
.sh-head { display: flex; align-items: flex-end; gap: 4mm; border-bottom: 2pt solid #000; padding-bottom: 3mm; flex: none; }
.sh-head svg { width: 11mm; height: 11mm; flex: none; }
.a5 .sh-head svg { width: 8.5mm; height: 8.5mm; }
.sh-title { min-width: 0; }
.sh-title b { display: block; font: 900 19pt/1 var(--display); font-stretch: 75%; text-transform: uppercase; }
.a5 .sh-title b { font-size: 14pt; }
.sh-title em { display: block; margin-top: 1.2mm; font: 600 7.5pt/1 var(--mono); font-style: normal; letter-spacing: 0.06em; text-transform: uppercase; }
.a5 .sh-title em { font-size: 6pt; }
.sh-name { margin-left: auto; font: 600 8pt/2.2 var(--mono); text-align: right; white-space: nowrap; flex: none; }
.a5 .sh-name { font-size: 6.5pt; }
.sh-name u { display: inline-block; border-bottom: 1pt solid #000; text-decoration: none; height: 1em; vertical-align: baseline; }
.sh-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: repeat(var(--rows), minmax(0, 1fr)); margin-top: 4mm; border-top: 1pt solid #000; border-left: 1pt solid #000; }
.wq { border-right: 1pt solid #000; border-bottom: 1pt solid #000; padding: 2.2mm 2.5mm; display: flex; gap: 2.5mm; align-items: flex-start; min-height: 0; overflow: hidden; position: relative; font-size: var(--fs); }
.wn { flex: none; min-width: 1.9em; height: 1.9em; border: 1.3pt solid #000; display: grid; place-items: center; font: 700 0.78em/1 var(--mono); }
.wq .wbody { flex: 1; min-width: 0; padding-right: 5mm; }
.wq .q { font-weight: 500; line-height: 1.3; padding-top: 0.12em; }
.wq .q.long { font-size: 0.86em; }
.wq .dg { height: 25mm; width: auto; margin: 1.5mm 0 0; stroke-width: 1.6; }
.a5 .wq .dg { height: 17mm; }
.wq .bars { position: absolute; right: 2mm; top: 2.4mm; font-size: 8pt; }
.sh-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.wq.nc { flex-direction: column; align-items: center; justify-content: center; gap: 2mm; }
.wq.nc small { font: 600 0.6em/1 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; }
.wq.nc b { font: 900 4.4em/1 var(--display); font-stretch: 75%; }
.sh-foot { display: flex; justify-content: space-between; font: 600 6.5pt/1 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; margin-top: 2.5mm; flex: none; }
.wans { columns: 3; column-gap: 8mm; font-size: 11pt; margin: 5mm 0 0; padding: 0; list-style: none; flex: 1; }
.a5 .wans { columns: 2; font-size: 8.5pt; }
.wans li { break-inside: avoid; padding: 1.3mm 0; border-bottom: 0.5pt solid #777; display: flex; gap: 3mm; align-items: baseline; }
.wans li b { font: 700 0.8em var(--mono); min-width: 1.8em; }

@media (max-width: 900px) {
  .iwy { grid-template-columns: 1fr; height: auto; }
  .opts { grid-template-columns: 1fr; }
  .zbody { grid-template-columns: 1fr; }
}

@media print {
  html, body { background: #fff !important; }
  body { display: block; height: auto; overflow: visible; }
  .band, .setup, #dock, #ink, #tbar, #toast, #zoom, #count, dialog { display: none !important; }
  #stage { overflow: visible !important; padding: 0 !important; position: static; }
  .ws-wrap { display: block; padding: 0; }
  .sheet, .spread { box-shadow: none; margin: 0; break-after: page; page-break-after: always; }
  .sheet { height: 296mm; } .sheet.a5 { height: 209mm; } .spread { height: 209mm; } .spread .sheet { break-after: auto; page-break-after: auto; height: 100%; }
  .ws-wrap > :last-child { break-after: auto; page-break-after: auto; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* ---------- short screens (classroom boards at 125-150% zoom) ----------
   Slimmer header and controls so the questions keep their room. The header comes from the site (site-header.css). */
@media (max-height: 820px) {
  body .sitehead__bar { min-height: 46px; }
  body .sitehead__brand { font-size: 20px; }
  body .sitehead__brand svg { width: 28px; height: 28px; }
  body .sitehead__how { font-size: 14px; padding: 4px 8px; }
  body .sitehead__tabs > a, body .sitehead__tabs > button { padding: 6px 14px; font-size: 15px; }
  .setup { padding: 6px 20px 2px; gap: 4px; }
  .row { min-height: 32px; gap: 8px; }
  .setup .note { display: none; }
  #stage { padding: 8px 20px 62px; }
  .grid { gap: 10px; }
  #dock { bottom: 8px; }
}
@media (max-height: 640px) {
  body .sitehead__tabs { display: none; }
}
