:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --ink: #1c2b4a;
  --muted: #5b6372;
  --rule: #d8dee8;
  --hi: #ffe45c;
  --ok: #1f7a4d;
  --bad: #c23b3b;
  --warn: #9a6408;
  --on-ink: #ffffff;
  --radius: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151f; --surface: #182030; --ink: #e6ebf3; --muted: #9aa4b5; --rule: #2a3446;
    --hi: #8a7413; --ok: #4cc08a; --bad: #f07a7a; --warn: #e0b04a; --on-ink: #10151f;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
input[type=radio], input[type=checkbox] { padding: 0; width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--ink); }
html { font-size: 16px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  line-height: 1.5; display: grid; grid-template-columns: 228px 1fr; min-height: 100vh;
}
a { color: inherit; text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--hi); outline-offset: 2px; box-shadow: 0 0 0 5px var(--ink); border-radius: 3px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 12px; top: 12px; z-index: 10; background: var(--surface); padding: 8px 12px; }

/* Sidebar */
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 20px; border-right: 1px solid var(--rule); background: var(--surface); display: flex; flex-direction: column; gap: 28px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 1.2rem; letter-spacing: -0.01em; }
.brand svg { width: 44px; height: 20px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: var(--radius); text-decoration: none; color: var(--muted); }
.nav a::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid currentColor; flex: none; transition: background .15s; }
.nav a:hover { color: var(--ink); }
.nav a[aria-current] { color: var(--ink); font-weight: 700; }
.nav a[aria-current]::before { background: var(--ink); border-color: var(--ink); }
.side-note { margin-top: auto; font-size: .8rem; color: var(--muted); }

/* Main */
main { padding: 40px clamp(16px, 4vw, 48px) 96px; max-width: 1180px; width: 100%; outline: none; }
.page-head { margin-bottom: 28px; }
.page-head.row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
h1 { font-size: 2.1rem; line-height: 1.15; margin: 0 0 8px; letter-spacing: -0.015em; display: inline;
  background: linear-gradient(transparent 60%, var(--hi) 60%, var(--hi) 92%, transparent 92%); padding: 0 2px; }
.lede { color: var(--muted); max-width: 68ch; margin: 10px 0 0; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 20px 0 10px; }
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 22px; margin-bottom: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.empty { color: var(--muted); padding: 18px 0; }
.bad { color: var(--bad); }
.warn-t { color: var(--warn); }
.ok-t { color: var(--ok); }
.note { background: color-mix(in srgb, var(--hi) 35%, transparent); padding: 10px 12px; border-radius: var(--radius); margin: 0; }
.steps { padding-left: 1.4em; margin: 0 0 18px; max-width: 70ch; }
.steps li { margin-bottom: 8px; }

/* Controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 700; font-size: .92rem;
  padding: 8px 14px; border-radius: var(--radius); border: 1.5px solid var(--ink); background: transparent; color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.btn.primary { background: var(--ink); color: var(--on-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--ink) 85%, var(--bg)); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.link { background: none; border: 0; font: inherit; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 0; }
.link.danger { color: var(--bad); }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 700; font-size: .9rem; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); background: var(--surface); border: 1.5px solid var(--rule); border-radius: var(--radius); padding: 8px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--ink); }
textarea { resize: vertical; font-variant-numeric: tabular-nums; }
fieldset { border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 14px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-weight: 700; font-size: .9rem; padding: 0 4px; }
label.radio, label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-grid .span2 { grid-column: 1 / -1; }
.form-row { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-end; margin-top: 16px; }
.quick { display: flex; gap: 8px; align-items: flex-end; margin: 12px 0 18px; flex-wrap: wrap; }
.quick label { flex: 1; min-width: 220px; }
.sticky-actions { position: sticky; bottom: 0; display: flex; gap: 8px; padding: 14px 0; background: linear-gradient(transparent, var(--bg) 35%); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1.5px solid var(--ink); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { white-space: nowrap; text-align: right; }
.actions > * + * { margin-left: 14px; }
.row-warn td:first-child { box-shadow: inset 4px 0 var(--warn); }
.row-bad td:first-child { box-shadow: inset 4px 0 var(--bad); }
.tag { display: inline-block; white-space: nowrap; font-size: .78rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; border: 1.5px solid currentColor; }
.tag.ok { color: var(--ok); } .tag.warn { color: var(--warn); } .tag.key { color: var(--ink); background: var(--hi); border-color: var(--hi); }
.mono-num { font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.namecrop { height: 30px; max-width: 260px; border: 1px solid var(--rule); border-radius: 3px; background: #fff; display: block; }
.namecrop.big { height: auto; width: 100%; max-width: 430px; margin-bottom: 14px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; margin-bottom: 20px; border-top: 1.5px solid var(--ink); }
.kpi { padding: 14px 16px 6px 0; display: flex; flex-direction: column; }
.kpi-n { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi-l { color: var(--muted); font-size: .85rem; }

/* Key editor */
.keygrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 4px 28px; }
.krow { display: grid; grid-template-columns: 34px auto 62px 1fr; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px dashed var(--rule); }
.qn { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.kchoices { display: flex; gap: 5px; }
.bubble { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--ink); background: var(--surface); color: var(--muted); font: inherit; font-size: .8rem; font-weight: 700; cursor: pointer; padding: 0; }
.bubble:hover { background: color-mix(in srgb, var(--ink) 12%, var(--surface)); }
.bubble.on { background: var(--ink); color: var(--on-ink); }
.krow input { padding: 5px 7px; font-size: .88rem; }

/* Print page */
.print-layout { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 24px; align-items: start; }
.preview-wrap { position: sticky; top: 24px; }
.sheet-preview svg { width: 100%; max-width: 560px; height: auto; display: block; box-shadow: 0 1px 2px rgba(28,43,74,.15), 0 10px 30px -12px rgba(28,43,74,.35); border-radius: 2px; }

/* Scan */
.drop { position: relative; border: 2px dashed var(--muted); border-radius: 10px; padding: 40px 20px; text-align: center; align-items: center; cursor: pointer; font-weight: 400; gap: 6px; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop.over, .drop:focus-within { border-color: var(--ink); background: color-mix(in srgb, var(--hi) 25%, transparent); }
.drop-title { font-weight: 700; font-size: 1.1rem; }
.progress { margin-top: 16px; display: flex; align-items: center; gap: 12px; }
.progress .bar { flex: 1; height: 8px; border-radius: 99px; background: var(--rule); overflow: hidden; }
.progress .bar span { display: block; height: 100%; width: 0; background: var(--ink); transition: width .2s; }
.ptext { font-size: .85rem; color: var(--muted); min-width: 200px; }

/* Analytics */
.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; }
.two-col .panel { margin-bottom: 20px; }
.hist { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; height: 200px; align-items: end; }
.hbar { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 4px; }
.hfill { width: 100%; background: var(--ink); border-radius: 3px 3px 0 0; min-height: 1px; }
.hcount { font-size: .8rem; font-weight: 700; }
.hlab { font-size: .75rem; color: var(--muted); }
.grades { display: flex; flex-direction: column; gap: 8px; }
.grade { display: grid; grid-template-columns: 40px 1fr 44px; gap: 10px; align-items: center; }
.grade.topic { grid-template-columns: minmax(80px, 140px) 1fr 44px; }
.gl { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gbar { height: 14px; background: var(--rule); border-radius: 99px; overflow: hidden; }
.gbar span { display: block; height: 100%; background: var(--ink); }
.gc { text-align: right; font-variant-numeric: tabular-nums; }
.pbar { display: inline-block; width: 60px; height: 6px; background: var(--rule); border-radius: 99px; overflow: hidden; margin-right: 8px; vertical-align: middle; }
.pbar span { display: block; height: 100%; background: var(--ink); }
.dist span { display: inline-block; margin-right: 10px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dist .keyc { font-weight: 700; background: var(--hi); padding: 0 5px; border-radius: 3px; }

/* Modal */
.modal-wrap { position: fixed; inset: 0; background: rgba(16,21,31,.55); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { background: var(--surface); border-radius: 10px; padding: 22px; width: min(900px, 100%); max-height: 92vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.modal-head h2 { margin: 0; }
.sheet-canvas { width: 100%; height: auto; border: 1px solid var(--rule); }
.edit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.eq { flex-direction: row; align-items: center; gap: 6px; font-weight: 700; }
.eq span { display: flex; flex-direction: column; min-width: 34px; text-align: right; line-height: 1.1; }
.eq small { font-weight: 400; color: var(--muted); font-size: .72rem; }
.eq select { flex: 1; padding: 4px 6px; }
.eq.wrong select { border-color: var(--bad); }
.grade-scale { display: flex; gap: 10px; flex-wrap: wrap; }
.gs { flex-direction: row; gap: 4px; }
.gs input:first-child { width: 52px; } .gs input:last-child { width: 72px; }

/* Toasts */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast { background: var(--ink); color: var(--on-ink); padding: 12px 16px; border-radius: var(--radius); max-width: 380px; font-size: .92rem; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.ok { border-left: 6px solid var(--ok); }
.toast.bad { border-left: 6px solid var(--bad); }

#print-area { display: none; }

@media (max-width: 860px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 14px 16px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--rule); }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a { padding: 6px 8px; font-size: .9rem; }
  .side-note { display: none; }
  .print-layout, .two-col { grid-template-columns: 1fr; }
  .preview-wrap { position: static; }
  h1 { font-size: 1.7rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

@media print {
  @page { size: letter; margin: 0; }
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing { display: block; background: #fff; }
  body.printing #print-area { display: block; }
  .print-page { width: 8.5in; height: 11in; overflow: hidden; break-after: page; page-break-after: always; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-page svg { width: 8.5in; height: 11in; display: block; }
  body:not(.printing) { display: block; background: #fff; color: #000; }
  body:not(.printing) .sidebar, body:not(.printing) .no-print, body:not(.printing) #toasts { display: none !important; }
  body:not(.printing) main { padding: .5in; max-width: none; }
  body:not(.printing) .panel { border: 0; padding: 0; break-inside: avoid-page; }
}
