/* ============ Worksheet Checker ============ */
:root {
  --bg: #f3f5fa;
  --bg-glow: rgba(51, 97, 232, .09);
  --panel: #ffffff;
  --panel-2: #f6f8fc;
  --panel-glass: rgba(255, 255, 255, .86);
  --track: #e8ecf4;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e4e8f1;
  --line-2: #d3dae6;
  --brand: #3361e8;
  --brand-2: #5a7cfa;
  --brand-ink: #ffffff;
  --brand-soft: #eaf0ff;
  --brand-glow: rgba(51, 97, 232, .32);

  /* the navigation bar stays dark in both themes */
  --side-bg: #0f1a3a;
  --side-bg-2: #172452;
  --side-ink: #b9c4e0;
  --side-muted: #7d8bb0;
  --side-hover: rgba(255, 255, 255, .07);
  --side-active: rgba(255, 255, 255, .13);

  --ok: #15803d;      --ok-bg: #e7f6ec;    --ok-line: #b5e3c4;
  --bad: #c53030;     --bad-bg: #fdeded;   --bad-line: #f4c3c3;
  --warn: #975a00;    --warn-bg: #fff5de;  --warn-line: #f3d996;
  --man: #5b4cc4;     --man-bg: #f0edfd;   --man-line: #d4cdf8;
  --part: #a35a00;    --part-bg: #fdf0e0;  --part-line: #f2cfa4;

  /* question-type chips */
  --chip-mc: #2457c5;      --chip-mc-bg: #eef3fe;      --chip-mc-line: #c6d6f6;
  --chip-number: #0d7466;  --chip-number-bg: #e8f7f3;  --chip-number-line: #b4e1d9;
  --chip-algebra: #8236b1; --chip-algebra-bg: #f7eefc; --chip-algebra-line: #e2c9f1;
  --chip-text: #8a5a12;    --chip-text-bg: #fcf4e6;    --chip-text-line: #ecd6b0;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 18px -8px rgba(15, 23, 42, .10);
  --shadow-lg: 0 18px 40px -12px rgba(15, 23, 42, .22);
  --font: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, Roboto, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  color-scheme: light;
}

/* dark theme: follows the computer ("Auto"), or is chosen in the app (data-theme on <html>) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0f1d; --bg-glow: rgba(107, 140, 255, .10); --panel: #111a2c; --panel-2: #17213a; --panel-glass: rgba(17, 26, 44, .86);
    --track: #0d1426; --ink: #e7ecf6; --ink-2: #c3ccdd; --muted: #8b97ae; --line: #212c45; --line-2: #2d3a58;
    --brand: #6b8cff; --brand-2: #8da6ff; --brand-ink: #0a0f1d; --brand-soft: #1a2650; --brand-glow: rgba(107, 140, 255, .30);
    --side-bg: #070c19; --side-bg-2: #0e1631; --side-hover: rgba(255, 255, 255, .06); --side-active: rgba(107, 140, 255, .18);
    --ok: #5fd08a; --ok-bg: #12291b; --ok-line: #24553a;
    --bad: #f28b8b; --bad-bg: #331a1d; --bad-line: #5f2f33;
    --warn: #f0c062; --warn-bg: #30260f; --warn-line: #5f4a1c;
    --man: #ab9ff5; --man-bg: #221d40; --man-line: #3f3770;
    --part: #f0a860; --part-bg: #33240f; --part-line: #634322;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 20px -10px rgba(0, 0, 0, .5);
    --shadow-lg: 0 20px 44px -12px rgba(0, 0, 0, .65);
    --chip-mc: #8fb4f5;      --chip-mc-bg: #1b2840;      --chip-mc-line: #2e4570;
    --chip-number: #6fd4c4;  --chip-number-bg: #142d29;  --chip-number-line: #22524a;
    --chip-algebra: #d1a3ef; --chip-algebra-bg: #2a1e35; --chip-algebra-line: #4f3366;
    --chip-text: #e6bd78;    --chip-text-bg: #2f2615;    --chip-text-line: #5a4524;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0f1d; --bg-glow: rgba(107, 140, 255, .10); --panel: #111a2c; --panel-2: #17213a; --panel-glass: rgba(17, 26, 44, .86);
  --track: #0d1426; --ink: #e7ecf6; --ink-2: #c3ccdd; --muted: #8b97ae; --line: #212c45; --line-2: #2d3a58;
  --brand: #6b8cff; --brand-2: #8da6ff; --brand-ink: #0a0f1d; --brand-soft: #1a2650; --brand-glow: rgba(107, 140, 255, .30);
  --side-bg: #070c19; --side-bg-2: #0e1631; --side-hover: rgba(255, 255, 255, .06); --side-active: rgba(107, 140, 255, .18);
  --ok: #5fd08a; --ok-bg: #12291b; --ok-line: #24553a;
  --bad: #f28b8b; --bad-bg: #331a1d; --bad-line: #5f2f33;
  --warn: #f0c062; --warn-bg: #30260f; --warn-line: #5f4a1c;
  --man: #ab9ff5; --man-bg: #221d40; --man-line: #3f3770;
  --part: #f0a860; --part-bg: #33240f; --part-line: #634322;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 20px -10px rgba(0, 0, 0, .5);
  --shadow-lg: 0 20px 44px -12px rgba(0, 0, 0, .65);
  --chip-mc: #8fb4f5;      --chip-mc-bg: #1b2840;      --chip-mc-line: #2e4570;
  --chip-number: #6fd4c4;  --chip-number-bg: #142d29;  --chip-number-line: #22524a;
  --chip-algebra: #d1a3ef; --chip-algebra-bg: #2a1e35; --chip-algebra-line: #4f3366;
  --chip-text: #e6bd78;    --chip-text-bg: #2f2615;    --chip-text-line: #5a4524;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1100px 520px at 100% -8%, var(--bg-glow), transparent 62%) fixed, var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
::selection { background: var(--brand-soft); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-family: var(--font-display); }
h1 { font-size: 27px; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 15.5px; font-weight: 650; }
p { margin: 0; }
a { color: var(--brand); text-underline-offset: 3px; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* thin, quiet scrollbars (mainly for Windows) */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 99px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--side-bg-2), var(--side-bg) 55%);
  color: #fff;
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px; }
.brand strong { display: block; font-size: 15.5px; font-family: var(--font-display); letter-spacing: -.01em; }
.brand small { color: var(--side-muted); font-size: 12px; }
.logo svg { width: 36px; height: 36px; display: block; filter: drop-shadow(0 6px 14px rgba(90, 124, 250, .45)); }
.logo rect { fill: var(--brand-2); }
.logo path { stroke: #fff; stroke-width: 3.2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav button {
  display: flex; align-items: center; gap: 11px;
  text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 10px;
  cursor: pointer; color: var(--side-ink); font-weight: 550; position: relative;
  transition: background .15s, color .15s;
}
.nav button .ico { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav button:hover { background: var(--side-hover); color: #fff; }
.nav button.active { background: var(--side-active); color: #fff; }
.nav button.active .ico { opacity: 1; color: var(--brand-2); }
.nav button.active::before {
  content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand-2);
}
.save-status {
  margin-top: auto; font-size: 12px; color: var(--side-muted); padding: 8px 10px;
  border-radius: 10px; background: rgba(255, 255, 255, .04); display: flex; align-items: center; gap: 8px;
}
.save-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #4ade80; flex: none; box-shadow: 0 0 0 3px rgba(74, 222, 128, .18); }
.save-status.failed { color: #fca5a5; font-weight: 600; }
.theme-toggle {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; flex: none;
  color: var(--side-ink); font-size: 13px; font-weight: 600; cursor: pointer; user-select: none; transition: background .15s;
}
.theme-toggle:hover { background: var(--side-hover); }
.theme-toggle .ico { width: 17px; height: 17px; flex: none; }
.theme-toggle .toggle-label { flex: 1; }
.theme-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.toggle-track {
  position: relative; width: 38px; height: 22px; border-radius: 99px; flex: none;
  background: rgba(255, 255, 255, .16); transition: background .2s;
}
.toggle-thumb {
  position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35); transition: transform .2s;
}
.theme-toggle input:checked + .toggle-track { background: var(--brand-2); }
.theme-toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.theme-toggle input:focus-visible + .toggle-track { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.save-status.failed::before { background: #f87171; box-shadow: 0 0 0 3px rgba(248, 113, 113, .2); }

.main { padding: 30px 36px 64px; min-width: 0; max-width: 1480px; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 5px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.spacer { flex: 1; }

/* ---------- cards & panels ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px;
}
.panel + .panel { margin-top: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.ws-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: 12px;
  transition: border-color .18s, transform .18s, box-shadow .18s; position: relative; overflow: hidden;
}
.ws-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2)); opacity: 0; transition: opacity .18s;
}
.ws-card:hover, .ws-card:focus-visible { border-color: var(--line-2); transform: translateY(-2px); box-shadow: var(--shadow-lg); outline: none; }
.ws-card:hover::before, .ws-card:focus-visible::before { opacity: 1; }
.ws-card .meta { color: var(--muted); font-size: 13px; margin-top: 3px; }
.progress { height: 8px; background: var(--track); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: 99px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: linear-gradient(180deg, var(--brand), var(--brand-2)); }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat .value { font-family: var(--font-display); font-size: 29px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 4px; }
.stat .value small { font-size: 14px; color: var(--muted); font-weight: 500; letter-spacing: 0; }

.empty-state { text-align: center; padding: 52px 24px; color: var(--muted); }
.empty-state::before {
  content: ""; display: block; width: 60px; height: 60px; margin: 0 auto 18px; border-radius: 18px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9 16.5l4.5 4.5L23 11' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 34px no-repeat,
    linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 12px 26px -10px var(--brand-glow);
}
.empty-state h2 { color: var(--ink); margin-bottom: 8px; font-size: 21px; }
.empty-state .row { justify-content: center; margin-top: 20px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid var(--line-2); background: var(--panel);
  cursor: pointer; font-weight: 600; white-space: nowrap; line-height: 1.2;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
  transition: border-color .15s, color .15s, background .15s, box-shadow .15s, transform .1s;
}
.btn:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible, .nav button:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); border-color: transparent; color: var(--brand-ink);
  box-shadow: 0 6px 16px -6px var(--brand-glow), inset 0 1px 0 rgba(255, 255, 255, .18);
}
.btn.primary:hover { filter: brightness(1.06); color: var(--brand-ink); box-shadow: 0 10px 22px -8px var(--brand-glow), inset 0 1px 0 rgba(255, 255, 255, .18); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); background: var(--bad-bg); }
.btn.ok { color: var(--ok); border-color: var(--ok-line); background: var(--ok-bg); }
.btn.ok:hover { border-color: var(--ok); color: var(--ok); }
.btn.bad { color: var(--bad); border-color: var(--bad-line); background: var(--bad-bg); }
.btn.bad:hover { border-color: var(--bad); color: var(--bad); }
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn kbd { font-family: var(--mono); font-size: 11px; border: 1px solid currentColor; border-radius: 5px; padding: 0 4px; opacity: .65; }

.input, select.input, textarea.input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--panel);
  transition: border-color .15s, box-shadow .15s;
}
.input:hover:not(:focus):not(:disabled) { border-color: var(--muted); }
.input:focus, textarea.input:focus, select.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.input:disabled { background: var(--panel-2); opacity: .7; }
textarea.input { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 14px; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
label.field .input { color: var(--ink); font-weight: 400; font-size: 15px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }

/* ---------- worksheet tabs (segmented control) ---------- */
.tabs {
  display: flex; gap: 4px; margin-bottom: 20px; padding: 4px; width: fit-content; max-width: 100%;
  background: var(--track); border: 1px solid var(--line); border-radius: 13px;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: none; padding: 8px 16px; cursor: pointer; color: var(--muted); font-weight: 600;
  border-radius: 10px; white-space: nowrap; transition: background .15s, color .15s, box-shadow .15s;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--brand); background: var(--panel); box-shadow: 0 1px 2px rgba(15, 23, 42, .08), 0 4px 10px -6px rgba(15, 23, 42, .2); }
.badge {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; font-size: 11.5px; line-height: 19px; font-weight: 700;
  text-align: center; background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-line); margin-left: 6px;
}
.badge.zero { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }

/* ---------- general tables ---------- */
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; background: var(--panel-2); }
.table td.num, .table th.num { text-align: right; }
.table tr:last-child td { border-bottom: 0; }
.table:not(.q-table) tbody tr:not(.sec-band):not(.unclear):hover > td { background: var(--panel-2); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }

/* ---------- question editor ---------- */
.q-table td { padding: 7px 6px; }
.q-table .input { padding: 7px 9px; }
.q-table td.no { width: 44px; text-align: center; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.q-table .type-col { width: 160px; min-width: 160px; }
.q-table .points-col { width: 80px; }
.q-table .points-col .input { min-width: 56px; }
.q-table .actions-col { width: 120px; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* sections and questions with sub-questions in the answer-key table */
.q-table tr.sec-row td { background: linear-gradient(90deg, var(--brand-soft), var(--panel) 85%); border-top: 2px solid var(--brand); padding: 10px 12px; }
.q-table tr.sec-row:first-child td { border-top: 0; }
.sec-head, .grp-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.q-table .sec-title { flex: 0 1 380px; min-width: 200px; font-weight: 700; font-size: 15px; font-family: var(--font-display); }
.q-table tr.grp-row td { background: var(--panel-2); border-bottom-style: dashed; }
.q-table tr.grp-row td.no { color: var(--ink); }
.grp-head .prompt-input { flex: 0 1 560px; min-width: 200px; }
.q-table tr.sub-row td.no { text-align: right; padding-right: 10px; font-weight: 600; box-shadow: inset 3px 0 0 var(--brand-soft); }
.q-table input.key { font-family: var(--mono); }
.key-preview { font-size: 12px; margin-top: 4px; min-height: 16px; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 6px 8px; border-radius: 8px; color: var(--muted); font-size: 15px; line-height: 1; transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--brand-soft); color: var(--brand); }
.icon-btn.del:hover { color: var(--bad); background: var(--bad-bg); }

.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 650; padding: 2px 9px; border-radius: 99px;
  border: 1px solid var(--line-2); color: var(--ink-2); background: var(--panel-2); white-space: nowrap;
}
.chip.mc { color: var(--chip-mc); border-color: var(--chip-mc-line); background: var(--chip-mc-bg); }
.chip.number { color: var(--chip-number); border-color: var(--chip-number-line); background: var(--chip-number-bg); }
.chip.algebra { color: var(--chip-algebra); border-color: var(--chip-algebra-line); background: var(--chip-algebra-bg); }
.chip.essay { color: var(--man); border-color: var(--man-line); background: var(--man-bg); }
.chip.text { color: var(--chip-text); border-color: var(--chip-text-line); background: var(--chip-text-bg); }

/* ---------- answer entry grid ---------- */
.info-bar {
  position: sticky; top: 8px; z-index: 7; background: var(--panel-glass); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(12px) saturate(1.4); backdrop-filter: blur(12px) saturate(1.4);
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 14px; box-shadow: var(--shadow-lg);
  display: grid; grid-template-columns: minmax(160px, 1.1fr) minmax(160px, 1.3fr) minmax(200px, 1.6fr) auto; gap: 16px; align-items: center;
}
.info-bar .label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.info-bar .value { font-weight: 650; word-break: break-word; }
.info-bar .value.mono { font-family: var(--mono); font-weight: 500; }
.info-bar .verdict { font-weight: 650; }
.info-bar .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.grid-wrap { overflow: auto; max-height: calc(100vh - 260px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.grid { border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
.grid th, .grid td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 0; }
.grid thead th {
  position: sticky; top: 0; z-index: 4; background: var(--panel-2); font-size: 12px; font-weight: 700;
  padding: 8px 6px; text-align: center; min-width: 118px; color: var(--ink-2);
}
.grid thead th .key-small { display: block; font-family: var(--mono); font-weight: 400; color: var(--muted); font-size: 11px; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 2px auto 0; }
.grid .name-col {
  position: sticky; left: 0; z-index: 3; background: var(--panel); min-width: 190px; max-width: 220px;
  padding: 0 12px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px;
}
.grid thead .name-col { z-index: 6; background: var(--panel-2); }
.grid .name-col .no { display: inline-block; width: 24px; color: var(--muted); font-size: 12px; }
.grid .total-col { position: sticky; right: 0; z-index: 3; background: var(--panel-2); min-width: 74px; text-align: center; font-weight: 700; padding: 0 8px; }
.grid thead .total-col { z-index: 6; }
.grid tr.active-row .name-col { background: var(--brand-soft); color: var(--brand); font-weight: 650; box-shadow: inset 3px 0 0 var(--brand); }
.grid td.cell { position: relative; }
.grid td.cell input {
  width: 100%; min-width: 118px; height: 40px; border: 0; padding: 0 8px; background: transparent;
  font-family: var(--mono); font-size: 14px; text-align: center; outline: none;
}
.grid td.cell input:focus { box-shadow: inset 0 0 0 2px var(--brand); background: var(--panel); position: relative; z-index: 1; border-radius: 4px; }
.grid td.cell input::placeholder { color: var(--line-2); font-family: var(--font); font-size: 12px; }

td.s-correct { background: var(--ok-bg); }
td.s-wrong { background: var(--bad-bg); }
td.s-review { background: var(--warn-bg); }
td.s-manual { background: var(--man-bg); }
td.s-partial { background: var(--part-bg); }
td.cell::after {
  content: ""; position: absolute; top: 3px; right: 4px; font-size: 11px; font-weight: 700; pointer-events: none; z-index: 1; line-height: 1;
}
td.s-correct::after { content: "\2713"; color: var(--ok); }
td.s-wrong::after { content: "\2717"; color: var(--bad); }
td.s-review::after { content: "?"; color: var(--warn); }
td.s-partial::after { content: "\00BD"; color: var(--part); }
td.cell.overridden input { text-decoration: underline dotted; text-underline-offset: 3px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 14px; border-radius: 5px; display: inline-block; border: 1px solid var(--line-2); }

.verdict.correct, .txt-correct { color: var(--ok); }
.verdict.wrong, .txt-wrong { color: var(--bad); }
.verdict.review, .txt-review { color: var(--warn); }
.verdict.manual { color: var(--man); }
.verdict.partial { color: var(--part); }
.verdict.blank { color: var(--muted); }

/* ---------- review queue ---------- */
.review-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow); display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: start;
  transition: border-color .15s, box-shadow .15s;
}
.review-card.active { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft), var(--shadow-lg); }
.review-card + .review-card { margin-top: 12px; }
.review-card .compare { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin-top: 12px; }
.review-card .compare dt { color: var(--muted); font-size: 13px; font-weight: 600; }
.review-card .compare dd { margin: 0; font-family: var(--mono); font-size: 15px; word-break: break-word; }
.review-card .compare dd.answer { font-size: 17px; font-weight: 650; background: var(--panel-2); border-radius: 8px; padding: 2px 8px; justify-self: start; }
.review-card .grade-buttons { display: flex; flex-direction: column; gap: 7px; min-width: 220px; }
.review-card .rubric { display: flex; flex-direction: column; gap: 5px; margin-top: 6px; }
.review-card .partial { display: flex; gap: 6px; }
.review-card .partial .input { width: 80px; }

/* ---------- results ---------- */
.bar { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.bar .track { flex: 1; height: 8px; background: var(--track); border-radius: 99px; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 99px; }
.bar .fill.easy { background: linear-gradient(90deg, #16a34a, #4ade80); }
.bar .fill.medium { background: linear-gradient(90deg, #d97706, #fbbf24); }
.bar .fill.hard { background: linear-gradient(90deg, #dc2626, #f87171); }
.bar b { width: 42px; text-align: right; font-variant-numeric: tabular-nums; }
.tag { font-size: 11.5px; padding: 2px 9px; border-radius: 99px; font-weight: 700; display: inline-block; }
.tag.easy, .tag.passed { background: var(--ok-bg); color: var(--ok); }
.tag.medium { background: var(--warn-bg); color: var(--warn); }
.tag.hard, .tag.remedial { background: var(--bad-bg); color: var(--bad); }
.tag.pending { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.misconceptions { font-family: var(--mono); font-size: 13px; }
.misconceptions span { display: inline-block; background: var(--bad-bg); color: var(--bad); border-radius: 6px; padding: 0 6px; margin: 1px 4px 1px 0; }
.histogram { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 8px; }
.histogram .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.histogram .pillar { width: 100%; max-width: 56px; background: linear-gradient(180deg, var(--brand-2), var(--brand)); border-radius: 8px 8px 3px 3px; min-height: 3px; }
.histogram .pillar.low { background: linear-gradient(180deg, #f87171, #dc2626); opacity: .9; }
.histogram .n { font-size: 13px; font-weight: 700; }
.histogram .r { font-size: 12px; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.two-col > .panel + .panel { margin-top: 0; }
.suggestions li { margin-bottom: 8px; }

/* ---------- toast & dialog ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 11px 20px; border-radius: 12px; font-weight: 600;
  box-shadow: var(--shadow-lg); transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--panel); color: var(--ink);
  width: min(640px, 92vw); box-shadow: var(--shadow-lg), 0 0 0 1px rgba(15, 23, 42, .03);
}
dialog[open] { animation: dialog-in .18s ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
dialog::backdrop { background: rgba(10, 15, 30, .45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
dialog .dialog-body { padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; }
dialog .dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--line); background: var(--panel-2); border-radius: 0 0 18px 18px; }
dialog .dialog-foot .cancel { order: -1; }

.note { background: var(--brand-soft); border-radius: var(--radius-sm); padding: 11px 15px; font-size: 14px; color: var(--ink-2); border-left: 3px solid var(--brand); }
.note.warning { background: var(--warn-bg); color: var(--warn); border-left-color: var(--warn); }
.format-sample { font-family: var(--mono); font-size: 13px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; white-space: pre; overflow-x: auto; color: var(--ink-2); }
.guide h2 { margin: 24px 0 8px; }
.guide ol, .guide ul { padding-left: 22px; margin: 6px 0; }
.guide li { margin-bottom: 6px; }
.test-result { font-weight: 650; padding: 11px 15px; border-radius: var(--radius-sm); }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 12px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav button.active::before { display: none; }
  .save-status { margin-top: 0; flex: 1; min-width: 200px; }
  .main { padding: 20px 16px 50px; }
  .info-bar { grid-template-columns: 1fr 1fr; position: static; }
  .two-col { grid-template-columns: 1fr; }
  .review-card { grid-template-columns: 1fr; }
}

/* ---------- print ---------- */
.print-area { display: none; }
@media print {
  @page { size: A4; margin: 0; }                  /* no margin = the browser prints no URL, date or title */
  body { background: #fff; color: #000; font-size: 12px; }
  .app, .toast, dialog { display: none !important; }
  .print-area { display: block; padding: 0 14mm; }
  .print-area table.print-frame { margin: 0; border: 0; }
  .print-area .print-frame > thead > tr > td, .print-area .print-frame > tbody > tr > td,
  .print-area .print-frame > tfoot > tr > td { border: 0; padding: 0; background: none; }
  .print-area .pf-top { height: 13mm; }
  .print-area .pf-foot { height: 15mm; padding-top: 5mm; font-size: 11px; color: #333; }
  .print-area .pf-sign { display: inline-block; min-width: 60mm; border-bottom: 1px solid #999; padding: 0 4px; font-weight: 600; }
  .print-area h1 { font-size: 18px; margin-bottom: 2px; }
  .print-area .print-info { color: #444; margin-bottom: 10px; }
  .print-area table { width: 100%; border-collapse: collapse; margin: 8px 0 14px; }
  .print-area th, .print-area td { border: 1px solid #999; padding: 4px 6px; text-align: left; }
  .print-area th { background: #eee; }
  .print-area td.num, .print-area th.num { text-align: right; }
  .print-area .slip { padding: 0 0 6px; }
  .print-area .slip + .slip { break-before: page; }          /* every student starts on a new page */
  .print-area .c { color: #0a6b2f; font-weight: 700; }
  .print-area .w { color: #a51d1d; font-weight: 700; }
  .print-area .signature { margin-top: 30px; display: flex; justify-content: flex-end; }
  .print-area .signature div { text-align: center; width: 220px; }
}

/* ---------- photo scanning ---------- */
dialog.wide { width: min(1000px, 96vw); }
td.cell.scanned::before {
  content: ""; position: absolute; left: 4px; bottom: 4px; width: 6px; height: 6px; border-radius: 50%;
  background: var(--brand); opacity: .7; pointer-events: none; z-index: 1;
}
#tabBody.dragging .scan-layout { outline: 2px dashed var(--brand); outline-offset: 4px; border-radius: var(--radius); }
.scan-layout { display: grid; grid-template-columns: 260px 1fr; gap: 16px; margin-top: 16px; align-items: start; }
.scan-list { display: flex; flex-direction: column; gap: 8px; position: sticky; top: 12px; max-height: calc(100vh - 40px); overflow: auto; }
.scan-empty { border: 2px dashed var(--line-2); border-radius: var(--radius); padding: 30px 14px; text-align: center; background: var(--panel); }
.scan-item {
  display: flex; gap: 11px; align-items: center; text-align: left; width: 100%; padding: 8px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.scan-item:hover { border-color: var(--brand); }
.scan-item.active { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.scan-item img, .scan-item .scan-noimg { width: 46px; height: 60px; object-fit: cover; border-radius: 7px; background: var(--panel-2); flex: none; }
.scan-item .scan-noimg { display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); }
.scan-item-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; align-items: flex-start; }
.scan-item-text b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.scan-detail { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-height: 200px; }
.scan-detail:empty { display: none; }
.scan-detail-grid { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.1fr); gap: 20px; align-items: start; }
.scan-photo { max-height: 78vh; overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); cursor: zoom-in; }
.scan-photo img { display: block; width: 100%; height: auto; }
.scan-photo.zoomed { cursor: zoom-out; }
.scan-photo.zoomed img { width: 220%; max-width: none; }
.scan-photo.scan-noimg { padding: 30px 16px; text-align: center; color: var(--muted); cursor: default; }
.scan-q-table td { padding: 6px 8px; }
.scan-q-table .input { padding: 6px 9px; }
.scan-q-table tr.unclear td { background: var(--warn-bg); }
.scan-waiting { text-align: center; padding: 44px 10px; }
.spinner {
  width: 32px; height: 32px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid var(--line-2); border-top-color: var(--brand); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 1100px) { .scan-detail-grid { grid-template-columns: 1fr; } }
@media (max-width: 860px) { .scan-layout { grid-template-columns: 1fr; } .scan-list { position: static; max-height: none; } }

/* question text in the answer-key table: wraps and grows, never cut off */
.q-table td.prompt-col { min-width: 260px; width: 30%; }
.q-table textarea.prompt-input {
  font-family: var(--font); font-size: 15px; line-height: 1.4; min-height: 38px;
  resize: none; overflow: hidden; display: block;
}

/* a scanned sheet can have several pages (one student) */
.scan-page-label { position: sticky; top: 0; z-index: 1; padding: 5px 10px; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel-glass); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.scan-photo img + .scan-page-label, .scan-photo .scan-noimg + .scan-page-label { border-top: 1px solid var(--line); }
.scan-photo .scan-noimg { padding: 30px 16px; text-align: center; color: var(--muted); }

/* section subtotals on the results page */
.table th.sec-col { max-width: 140px; white-space: normal; text-transform: none; letter-spacing: 0; line-height: 1.25; }
.table td.sec-score { white-space: nowrap; }
.table tr.sec-band td { background: linear-gradient(90deg, var(--brand-soft), var(--panel) 85%); font-weight: 700; font-size: 13px; color: var(--brand); }

/* essays graded by AI */
td.cell.ai-graded::after {
  content: "AI"; position: absolute; right: 3px; top: 2px; font-size: 9px; font-weight: 800; letter-spacing: .02em;
  color: var(--man); opacity: .85; pointer-events: none; z-index: 1;
}
.scan-q-table textarea.essay-text { font-family: var(--font); font-size: 14px; line-height: 1.4; resize: vertical; min-height: 56px; }
.scan-q-table .model-answer { max-width: 180px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; }

.partial-max { align-self: center; font-size: 13px; font-weight: 700; color: var(--ink-2); white-space: nowrap; }

/* ---------- phones ---------- */
/* notches and the home bar on phones (viewport-fit=cover in index.html) */
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

@media (max-width: 600px) {
  /* 16px stops iPhones from zooming in on every field that gets focus */
  .input, select.input, textarea.input, label.field .input, .grid input { font-size: 16px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { min-width: 0; flex-wrap: nowrap; gap: 8px; padding: 8px 10px; position: sticky; top: 0; z-index: 20; box-shadow: 0 6px 18px -10px rgba(0, 0, 0, .5); }
  .brand { padding: 0; }
  .brand > div, .save-status { display: none; }
  .theme-toggle { padding: 6px 4px 6px 8px; gap: 7px; }
  .theme-toggle .toggle-label { display: none; }
  .logo svg { width: 30px; height: 30px; }
  .nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 2px; }
  .nav::-webkit-scrollbar { display: none; }
  .nav button { white-space: nowrap; padding: 7px 10px; font-size: 14px; gap: 7px; }
  .nav button .ico { width: 16px; height: 16px; }
  .main { padding: 16px 12px 40px; }
  h1 { font-size: 21px; }
  .page-head { margin-bottom: 14px; gap: 10px; }
  .panel { padding: 15px; }
  .panel-head > .row, .panel-head > div:last-child.row { width: 100%; }
  .tabs { width: 100%; }
  .tabs button { padding: 7px 12px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat .value { font-size: 22px; }
  .info-bar { grid-template-columns: 1fr; gap: 8px; }
  .grid-wrap { max-height: 70vh; }
  .review-card .grade-buttons { min-width: 0; }
  .review-card .grade-buttons .btn { white-space: normal; }
  dialog { width: calc(100vw - 16px); max-height: calc(100vh - 32px); }
  dialog .dialog-body { padding: 16px; }
  dialog .dialog-foot { padding: 12px 16px; }
  .format-sample { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  dialog[open] { animation: none; }
}

/* Home Screen app on an iPhone runs under the status bar (black-translucent): the dark menu bar
   fills the space behind the clock, and nothing sits under it. env() is 0 everywhere else. */
body { padding-top: 0; }
.sidebar { padding-top: calc(20px + env(safe-area-inset-top)); }
.main { padding-top: calc(30px + env(safe-area-inset-top)); }
@media (max-width: 860px) {
  .sidebar { padding-top: calc(12px + env(safe-area-inset-top)); }
  .main { padding-top: 20px; }
}
@media (max-width: 600px) {
  .sidebar { padding-top: calc(8px + env(safe-area-inset-top)); }
  .main { padding-top: 16px; }
}

/* ---------- phones: the four menu items as a tab bar at the bottom ---------- */
.nav-short { display: none; }
@media (max-width: 600px) {
  /* top bar: logo and name on the left, the Dark mode switch on the right */
  .brand > div { display: block; }
  .brand small { display: none; }
  .brand strong { font-size: 15px; white-space: nowrap; }
  .theme-toggle { margin-left: auto; }

  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; overflow: visible;
    padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
    background: var(--side-bg); border-top: 1px solid rgba(255, 255, 255, .08); box-shadow: 0 -8px 24px -12px rgba(0, 0, 0, .45);
  }
  .nav button {
    flex-direction: column; justify-content: center; gap: 3px; padding: 7px 2px 6px; border-radius: 12px;
    font-size: 11px; font-weight: 600; text-align: center; white-space: nowrap; min-width: 0;
  }
  .nav button .ico { width: 22px; height: 22px; }
  .nav button.active { background: var(--side-active); }
  .nav button.active::before { display: none; }
  .nav-text { display: none; }
  .nav-short { display: block; }

  /* keep content and messages clear of the tab bar */
  .main { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

/* sync between devices (Settings) */
.sync-code { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; margin-top: 10px; border-radius: var(--radius-sm); background: var(--panel-2); border: 1px solid var(--line); }
.sync-code code { font-size: 16px; font-weight: 700; letter-spacing: .06em; color: var(--ink); }

/* ---------- phones: the worksheet screens (web layout above is untouched) ---------- */
.tab-short { display: none; }
@media (max-width: 600px) {
  /* header: smaller title, the four tabs always visible */
  .page-head h1 { font-size: 19px; }
  .page-head .sub { font-size: 13px; }
  .page-head > .btn { padding: 6px 11px; font-size: 13px; }
  .tabs { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; gap: 2px; margin-bottom: 14px; }
  .tabs button { padding: 8px 2px; font-size: 13px; text-align: center; }
  .tabs .tab-long { display: none; }
  .tabs .tab-short { display: inline; }
  .tabs .badge { margin-left: 3px; min-width: 18px; padding: 0 4px; line-height: 17px; }

  /* answer key: worksheet details two by two, every question a card */
  .ws-meta { grid-template-columns: 1fr 1fr; gap: 10px; }
  .ws-meta label:first-child { grid-column: 1 / -1; }
  .q-table, .q-table tbody { display: block; }
  .q-table thead { display: none; }
  .q-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); }
  .q-table tr:last-child { border-bottom: 0; }
  .q-table td { display: block; padding: 0; border: 0; width: auto !important; min-width: 0 !important; }
  .q-table td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 4px;
    font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
  }
  .q-table td.no { grid-column: 1; grid-row: 1; text-align: left; align-self: center; font-size: 16px; color: var(--ink); }
  .q-table td.no::before { content: "Question "; }
  .q-table td.actions-col { grid-column: 2; grid-row: 1; justify-self: end; }
  .q-table td.prompt-col, .q-table td.key-col, .q-table td.alt-col, .q-table td.rule-col { grid-column: 1 / -1; }
  /* type and points side by side, under the question */
  .q-table td.no, .q-table td.actions-col { order: -1; }
  .q-table td.type-col { order: 1; }
  .q-table td.points-col { order: 2; }
  .q-table td.key-col { order: 3; }
  .q-table td.alt-col { order: 4; }
  .q-table td.rule-col { order: 5; }
  .q-table td.rule-col:has(> .muted:only-child) { display: none; }
  .q-table tr.sub-row { margin-left: 14px; border-left: 3px solid var(--brand-soft); }
  .q-table tr.sub-row td.no { text-align: left; padding: 0; box-shadow: none; }
  .q-table tr.sec-row, .q-table tr.grp-row { display: block; }
  .q-table tr.grp-row { display: grid; }
  .q-table tr.grp-row td.no::before { content: "Question "; }
  .q-table tr.grp-row td[colspan] { grid-column: 1 / -1; }
  .q-table .sec-title { flex: 1 1 100%; min-width: 0; }
  .grp-head .prompt-input { flex: 1 1 100%; min-width: 0; }

  /* results and scan check: rows become cards */
  .cards-sm, .cards-sm tbody { display: block; }
  .cards-sm thead { display: none; }
  .cards-sm tr { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 13px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .cards-sm tr:last-child { border-bottom: 0; }
  .cards-sm td { display: block; padding: 0; border: 0; text-align: left !important; }
  .cards-sm td[data-label]::before {
    content: attr(data-label); display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
  }
  .cards-sm td.card-no { order: -2; font-weight: 700; color: var(--muted); }
  .cards-sm td.card-title { order: -1; flex: 1 1 auto; min-width: 40%; font-weight: 650; font-size: 15px; }
  .cards-sm td.card-status { order: -1; margin-left: auto; }
  .cards-sm td.card-grade { order: -1; margin-left: auto; text-align: right !important; }
  .cards-sm td.card-grade::before { display: none !important; }
  .cards-sm td.card-grade b { font-size: 18px; }
  .cards-sm td.card-grade + td.card-status { margin-left: 0; }
  .cards-sm td.card-wide { flex: 1 1 100%; }
  .cards-sm tr.sec-band { display: block; }
  .cards-sm td[colspan] { flex: 1 1 100%; }
  .table.cards-sm tbody tr:hover > td { background: none; }

  .scan-q-table.cards-sm td:nth-child(1) { order: -2; font-weight: 700; color: var(--ink); }
  .scan-q-table.cards-sm td:nth-child(1)::before { content: "Question "; font-weight: 700; }
  .scan-q-table.cards-sm td:nth-child(2) { order: -1; flex: 1 1 auto; }
  .scan-q-table.cards-sm tr.unclear { background: var(--warn-bg); }
  .scan-q-table.cards-sm tr.unclear td { background: none; }
  .scan-q-table.cards-sm td:nth-child(2)::before { content: "Key "; font-weight: 700; }
  .scan-q-table.cards-sm td:nth-child(3) { flex: 1 1 100%; }
  .scan-q-table.cards-sm td:nth-child(4) { order: -1; margin-left: auto; }
  .scan-q-table.cards-sm .model-answer { max-width: none; }

  .review-card .compare { grid-template-columns: 96px 1fr; }
}

/* answer entry on a phone: one student, every question below each other (only rendered on phones) */
.pe-student { display: grid; grid-template-columns: 46px 1fr 46px; gap: 8px; position: sticky; top: calc(54px + env(safe-area-inset-top)); z-index: 6;
  padding: 8px; margin: 0 -4px 10px; border-radius: var(--radius); background: var(--panel-glass);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); box-shadow: var(--shadow); border: 1px solid var(--line); }
.pe-student .btn { font-size: 20px; padding: 0; }
.pe-student select { font-weight: 650; }
.pe-summary { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.pe-summary b { font-size: 20px; font-family: var(--font-display); }
.pe-summary .btn { margin-left: auto; }
.pe-section { margin: 18px 2px 8px; font-size: 14px; color: var(--brand); text-transform: uppercase; letter-spacing: .05em; }
.pe-group { margin: 12px 2px 6px; font-weight: 650; font-size: 14px; }
.pe-q { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--line-2); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.pe-q.s-correct { border-left-color: var(--ok); }
.pe-q.s-wrong { border-left-color: var(--bad); }
.pe-q.s-review { border-left-color: var(--warn); }
.pe-q.s-manual { border-left-color: var(--man); }
.pe-q.s-partial { border-left-color: var(--part); }
.pe-q-top { display: flex; align-items: center; gap: 8px; }
.pe-q-top b { font-size: 16px; }
.pe-prompt { font-size: 14px; color: var(--ink-2); }
.pe-essay { font-size: 14px; background: var(--panel-2); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; }
.pe-input { font-size: 16px; }
.pe-choices { display: flex; gap: 8px; flex-wrap: wrap; }
.pe-choice { width: 46px; height: 42px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel); font-weight: 700; font-size: 16px; cursor: pointer; }
.pe-choice.on { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: var(--brand-ink); border-color: transparent; }
.pe-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.pe-next { display: flex; gap: 10px; justify-content: space-between; margin-top: 6px; }
.pe-next .btn { flex: 1; }

/* phones: written answers are shown in full */
textarea.pe-long { min-height: 44px; resize: none; overflow: hidden; display: block; font-family: var(--font); font-size: 16px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
@media (max-width: 600px) {
  .scan-q-table textarea.essay-text { resize: none; overflow: hidden; }
  .scan-q-table .model-answer { display: block; -webkit-line-clamp: unset; overflow: visible; }
}
.pe-tools .btn { white-space: normal; text-align: left; }

/* Classes & Students: class name and teacher name above each other */
.class-fields { display: flex; flex-direction: column; gap: 10px; flex: 1 1 280px; max-width: 420px; }
.class-fields .class-name-input { font-weight: 650; }
