:root {
  --bg: #f1f5f9; --surface: #fff; --text: #0f172a; --muted: #64748b; --border: #e2e8f0;
  --brand: #0b1f3a; --brand-2: #1d4ed8; --danger: #b91c1c;
  --ok-bg: #dcfce7; --ok-text: #166534; --err-bg: #fee2e2; --err-text: #991b1b;
  --radius: 12px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1220; --surface: #111a2e; --text: #e2e8f0; --muted: #94a3b8; --border: #1e293b; --brand-2: #60a5fa; --ok-bg: #052e16; --ok-text: #86efac; --err-bg: #450a0a; --err-text: #fca5a5; color-scheme: dark; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--brand-2); }
.container { max-width: 1000px; margin: 0 auto; padding: 16px; }
.topbar { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; background: var(--brand); color: #fff; padding: 10px 16px; }
.topbar a, .topbar summary { color: #fff; text-decoration: none; }
.brand { font-weight: 700; font-size: 1.1rem; }
nav { display: flex; gap: 14px; flex: 1; flex-wrap: wrap; }
.menu { position: relative; }
.menu summary { cursor: pointer; padding: 4px 8px; border-radius: 6px; list-style: none; }
.menu summary:hover, .menu[open] summary { background: rgba(255,255,255,.15); }
.menu-items { position: absolute; z-index: 10; top: 100%; left: 0; min-width: 190px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.2); padding: 6px; display: flex; flex-direction: column; }
.menu-items a { color: var(--text); padding: 8px 10px; border-radius: 6px; }
.menu-items a:hover { background: var(--bg); }
.who { display: flex; gap: 10px; align-items: center; }
.who form { margin: 0; }
button, .btn { font: inherit; background: var(--brand-2); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer; text-decoration: none; display: inline-block; }
button.secondary, .btn.secondary { background: transparent; color: var(--brand-2); border: 1px solid var(--brand-2); }
button.link { background: none; color: #fff; padding: 0; text-decoration: underline; }
button.small { padding: 4px 10px; font-size: .85rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin: 12px 0; }
.card.narrow { max-width: 460px; margin: 32px auto; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
ul.plain { list-style: none; padding: 0; margin: 0; } ul.plain li { padding: 4px 0; }
label { display: block; margin: 12px 0; font-weight: 600; }
label.check { font-weight: 400; display: flex; gap: 8px; align-items: center; }
input:not([type=checkbox]), select, textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
:focus-visible { outline: 3px solid var(--brand-2); outline-offset: 2px; }
.muted { color: var(--muted); } .small-text { font-size: .9rem; }
.alert { padding: 10px 14px; border-radius: 8px; margin: 12px 0; } .alert.ok { background: var(--ok-bg); color: var(--ok-text); } .alert.err { background: var(--err-bg); color: var(--err-text); }
.alert ul { margin: 0; padding-left: 18px; }
.tabs a { margin-right: 12px; } .tabs a.on { font-weight: 700; }
.table-wrap { overflow-x: auto; } table { border-collapse: collapse; width: 100%; background: var(--surface); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.actions form { display: inline-block; margin: 0 4px 4px 0; }
.badge { padding: 2px 8px; border-radius: 999px; font-size: .8rem; background: var(--border); } .badge.pending { background: #fef3c7; color: #92400e; } .badge.approved { background: var(--ok-bg); color: var(--ok-text); }
code { background: var(--bg); padding: 2px 6px; border-radius: 4px; }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 8px 0 16px; }

/* ----- worksheets (always black on white, also on screen in dark mode) ----- */
.sheet { background: #fff; color: #000; border: 1px solid var(--border); border-radius: 6px; padding: 28px 32px; margin: 0 0 20px; min-height: 9in; }
.sheet h1 { margin: 0; font-size: 1.5rem; } .sheet-sub { margin: 2px 0 8px; color: #333; }
.namedate { display: flex; justify-content: space-between; gap: 24px; margin: 8px 0 18px; }
.blank { display: inline-block; border-bottom: 1.5px solid #000; width: 200px; height: 1em; vertical-align: baseline; } .blank.short { width: 90px; }
.legend { font-style: italic; margin: 0 0 12px; }
ol.problems { list-style: none; margin: 0; padding: 0; display: grid; gap: 22px 12px; counter-reset: p; grid-template-columns: repeat(4, 1fr); }
ol.problems.d5, ol.problems.d6, ol.problems.d7 { grid-template-columns: repeat(3, 1fr); }
ol.problems.horizontal { grid-template-columns: repeat(2, 1fr); }
ol.problems li { counter-increment: p; position: relative; padding-left: 26px; min-height: 90px; }
ol.problems li::before { content: counter(p) "."; position: absolute; left: 0; top: 0; font-size: .85rem; }
.vp { display: inline-block; font-variant-numeric: tabular-nums; font-size: 1.25rem; }
.vp .row { display: flex; justify-content: flex-end; gap: 10px; } .vp .opsym { min-width: 1ch; }
.vp .rule { border-top: 2px solid #000; margin-top: 2px; height: 34px; }
.hp { font-size: 1.25rem; padding-top: 6px; }
.div-bracket { display: inline-flex; align-items: flex-start; font-size: 1.25rem; font-variant-numeric: tabular-nums; margin-top: 8px; }
.div-bracket .divisor { padding: 6px 8px 0 0; } .div-bracket .dividend { border-left: 2px solid #000; border-top: 2px solid #000; padding: 6px 12px 28px 8px; border-top-left-radius: 8px; }
.words-problems { padding-left: 22px; } .words-problems li { margin-bottom: 8px; break-inside: avoid; font-size: 1.1rem; }
.workspace { height: 100px; border: 1px dashed #aaa; border-radius: 6px; margin: 6px 0; } .answerline { margin: 4px 0 16px; }
.keylist { columns: 2; font-size: 1.05rem; }
.wordgrid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; counter-reset: w; }
.wordgrid li { counter-increment: w; font-size: 1.6rem; padding: 6px 0; } .wordgrid li::before { content: counter(w) "."; font-size: .75rem; margin-right: 6px; color: #444; }
.wordgrid.write { grid-template-columns: repeat(2, 1fr); } .wordgrid.write .blank { width: 55%; margin-left: 12px; }
.mark { font-size: 1rem; }
.cards { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); } .cards li { border: 1px dashed #666; height: 1.6in; display: flex; align-items: center; justify-content: center; font-size: 2.4rem; break-inside: avoid; }
.tracelist { list-style: none; padding: 0; margin: 0; } .tracelist li { display: grid; grid-template-columns: 1.5fr 1.5fr 2fr; gap: 12px; align-items: end; font-size: 1.7rem; padding: 6px 0; } .trace { color: #aaa; } .tracelist .blank { width: 100%; }
.prompt { margin-bottom: 20px; break-inside: avoid; } .lines .line { height: 34px; border-bottom: 1.5px solid #555; } .lines.primary .line { height: 46px; border-bottom: 1.5px solid #555; background: linear-gradient(transparent 49%, #bbb 49%, #bbb 51%, transparent 51%); }

@media (max-width: 640px) {
  ol.problems, ol.problems.d5, ol.problems.d6, ol.problems.d7 { grid-template-columns: repeat(2, 1fr); }
  .wordgrid, .cards { grid-template-columns: repeat(2, 1fr); } .sheet { padding: 16px; }
}
@media print {
  @page { margin: .5in; }
  body { background: #fff; }
  .no-print, .topbar { display: none !important; }
  .container { max-width: none; padding: 0; }
  .sheet { border: 0; padding: 0; margin: 0; min-height: 0; border-radius: 0; }
  .sheet.key { break-before: page; }
  .menu-items { display: none; }
}
.pill { background: #f59e0b; color: #000; border-radius: 999px; padding: 0 7px; font-size: .8rem; font-weight: 700; }
