/* Layout: workbook-first tool; ledger-green accent on near-neutral sage greys. */
:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --sunken: #eef2ef;
  --ink: #18211d;
  --muted: #5b6862;
  --line: #dbe2dd;
  --line-strong: #c3ccc6;
  --accent: #146c45;
  --accent-ink: #ffffff;
  --accent-soft: #e1f0e7;
  --select: #146c45;
  --select-fill: rgba(20, 108, 69, 0.10);
  --ok: #1d7a4c;
  --ok-soft: #e0f2e8;
  --warn: #9a5f00;
  --warn-soft: #fbeed5;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --info: #2a5ea8;
  --info-soft: #e3ecf8;
  --shadow: 0 1px 2px rgba(16, 32, 24, 0.06), 0 4px 16px rgba(16, 32, 24, 0.06);
  --font-display: "IBM Plex Sans Condensed", "Arial Narrow", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --radius: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111513; --surface: #181d1a; --sunken: #1f2522; --ink: #e4eae6; --muted: #98a59e;
    --line: #2a322e; --line-strong: #3a4540; --accent: #4fc28b; --accent-ink: #06130c; --accent-soft: #1b3226;
    --select: #4fc28b; --select-fill: rgba(79, 194, 139, 0.14);
    --ok: #5ccf96; --ok-soft: #173126; --warn: #e6b04f; --warn-soft: #3a2c12; --bad: #f08a80; --bad-soft: #3c1c19;
    --info: #8fb4ec; --info-soft: #1a2638; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111513; --surface: #181d1a; --sunken: #1f2522; --ink: #e4eae6; --muted: #98a59e;
  --line: #2a322e; --line-strong: #3a4540; --accent: #4fc28b; --accent-ink: #06130c; --accent-soft: #1b3226;
  --select: #4fc28b; --select-fill: rgba(79, 194, 139, 0.14);
  --ok: #5ccf96; --ok-soft: #173126; --warn: #e6b04f; --warn-soft: #3a2c12; --bad: #f08a80; --bad-soft: #3c1c19;
  --info: #8fb4ec; --info-soft: #1a2638; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; margin: 0; text-wrap: balance; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); }
.num { font-variant-numeric: tabular-nums; }
.label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; color: var(--muted);
}

/* ---- controls ---- */
button, .btn {
  font: inherit; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  text-decoration: none; white-space: nowrap;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--bad); }
button.danger.solid { background: var(--bad); border-color: var(--bad); color: var(--surface); }
button.ghost { border-color: transparent; background: transparent; }
button.small { padding: 4px 10px; font-size: 0.85rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--select-fill); }
textarea { resize: vertical; min-height: 70px; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 0.85rem; font-weight: 500; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600; white-space: nowrap;
  background: var(--sunken); color: var(--muted);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.assigned { background: var(--info-soft); color: var(--info); }
.pill.in_progress { background: var(--warn-soft); color: var(--warn); }
.pill.submitted, .pill.correct { background: var(--ok-soft); color: var(--ok); }
.pill.expired, .pill.wrong, .pill.error { background: var(--bad-soft); color: var(--bad); }
.pill.hardcoded { background: var(--warn-soft); color: var(--warn); }
.pill.blank { background: var(--sunken); color: var(--muted); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 6px; font-size: 0.9rem;
  box-shadow: var(--shadow); z-index: 100;
}
.error-text { color: var(--bad); font-size: 0.88rem; }

/* ---- spreadsheet ---- */
.sheet-tabs { display: flex; gap: 2px; padding: 0 8px; border-top: 1px solid var(--line); background: var(--sunken); }
.sheet-tabs button {
  border: 0; border-radius: 0 0 6px 6px; background: transparent; color: var(--muted);
  padding: 6px 14px; font-size: 0.85rem;
}
.sheet-tabs button[aria-selected=true] { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: inset 0 2px 0 var(--accent); }
.fbar { display: flex; border-bottom: 1px solid var(--line); background: var(--surface); min-width: 0; }
.fbar .namebox { width: 84px; flex: none; padding: 6px 8px; border-right: 1px solid var(--line); font: 0.85rem var(--font-mono); color: var(--muted); }
.fbar .fx { padding: 6px 8px; font: italic 600 0.85rem var(--font-body); color: var(--muted); border-right: 1px solid var(--line); }
.fbar .content { padding: 6px 10px; font: 0.85rem var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.grid-wrap { overflow: auto; background: var(--surface); }
table.grid { border-collapse: separate; border-spacing: 0; font-size: 0.84rem; user-select: none; min-width: 100%; }
table.grid th, table.grid td {
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: 3px 8px; height: 26px; white-space: nowrap;
}
table.grid thead th {
  position: sticky; top: 0; z-index: 2; background: var(--sunken); color: var(--muted);
  font-weight: 500; font-size: 0.78rem; text-align: center; cursor: pointer; min-width: 64px;
}
table.grid tbody th {
  position: sticky; left: 0; z-index: 1; background: var(--sunken); color: var(--muted);
  font-weight: 500; font-size: 0.78rem; text-align: center; min-width: 40px; cursor: default;
}
table.grid thead th.corner { left: 0; z-index: 3; cursor: default; }
table.grid td { cursor: cell; font-variant-numeric: tabular-nums; }
table.grid td.n { text-align: right; }
table.grid tr.hdr td { font-weight: 600; background: var(--accent-soft); }
table.grid td.sel { outline: 2px solid var(--select); outline-offset: -2px; }
table.grid td.inrange { background: var(--select-fill); }
table.grid thead th.hl, table.grid tbody th.hl { background: var(--accent-soft); color: var(--accent); }

/* ---- multi-section tests ---- */
.section-nav {
  display: flex; gap: 4px; padding: 8px 16px 0; overflow-x: auto;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: calc(env(safe-area-inset-top, 0px) + 58px); z-index: 19;
}
.section-nav button {
  border: 0; border-radius: 6px 6px 0 0; background: transparent; color: var(--muted);
  padding: 8px 14px; display: inline-flex; gap: 8px; align-items: center;
}
.section-nav button[aria-current=true] { color: var(--accent); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
.section-nav .count { font-size: 0.75rem; font-variant-numeric: tabular-nums; background: var(--sunken); color: var(--muted); padding: 1px 7px; border-radius: 999px; }
.section-nav .count.done { background: var(--ok-soft); color: var(--ok); }
.quiz { max-width: 860px; margin: 0 auto; padding: 16px; display: grid; gap: 12px; }
.quiz .task { padding: 16px 18px; }
.quiz .qtext { font-weight: 500; }
.quiz .type-hint { font-size: 0.8rem; color: var(--muted); }
pre.code {
  margin: 0; padding: 12px 14px; border-radius: 6px; overflow-x: auto;
  background: var(--sunken); border: 1px solid var(--line);
  font: 0.84rem/1.55 var(--font-mono); tab-size: 4; white-space: pre;
}
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 8px 11px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 4px; accent-color: var(--accent); flex: none; }
.choice span { min-width: 0; overflow-wrap: anywhere; }
.choices { display: grid; gap: 6px; }
textarea.output { font-family: var(--font-mono); font-size: 0.88rem; min-height: 64px; }
.next-row { display: flex; justify-content: flex-end; }
.finish-wrap { max-width: 860px; margin: 0 auto; padding: 0 16px 32px; }
