/* Layout: one 46rem column under a sticky olive command band; each view swaps in place below it. */
:root {
  --ground: #eceee4;
  --sheet: #fafbf6;
  --ink: #1d2216;
  --ink-2: #485040;
  --ink-3: #646c5a;
  --rule: #d3d8c6;
  --band: #3c4a1f;
  --band-ink: #f1f3e6;
  --action: #4a5a26;
  --action-ink: #f7f8f0;
  --action-soft: #dfe5cc;
  --meter: #5b6f2e;
  --brass: #9a7223;
  --brass-soft: #efe3c2;
  --good: #22704a;
  --good-soft: #dcefe2;
  --bad: #ad3529;
  --bad-soft: #f7e0dc;
  --focus: #9a7223;
  --water: #c3d6dc;
  --water-ink: #6f95a1;

  --font-display: "Karantina", "Secular One", "Arial Narrow", sans-serif;
  --font-body: "IBM Plex Sans Hebrew", "Assistant", "Segoe UI", Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --radius: 8px;
  --col: 46rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #14170f;
    --sheet: #1c2017;
    --ink: #e7eadf;
    --ink-2: #bcc2af;
    --ink-3: #959c87;
    --rule: #343b2b;
    --band: #222a15;
    --band-ink: #e7eadf;
    --action: #a9ba72;
    --action-ink: #141a0b;
    --action-soft: #2d3820;
    --meter: #a9ba72;
    --brass: #d4a84e;
    --brass-soft: #3a3019;
    --good: #66c493;
    --good-soft: #173325;
    --bad: #ef8072;
    --bad-soft: #3d1c18;
    --focus: #d4a84e;
    --water: #263f47;
    --water-ink: #5f8c99;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --ground: #14170f;
  --sheet: #1c2017;
  --ink: #e7eadf;
  --ink-2: #bcc2af;
  --ink-3: #959c87;
  --rule: #343b2b;
  --band: #222a15;
  --band-ink: #e7eadf;
  --action: #a9ba72;
  --action-ink: #141a0b;
  --action-soft: #2d3820;
  --meter: #a9ba72;
  --brass: #d4a84e;
  --brass-soft: #3a3019;
  --good: #66c493;
  --good-soft: #173325;
  --bad: #ef8072;
  --bad-soft: #3d1c18;
  --focus: #d4a84e;
  --water: #263f47;
  --water-ink: #5f8c99;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 10;
  background: var(--band);
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

h1, h2, h3 { text-wrap: balance; margin: 0; }
p { margin: 0; }

.num, [data-timer] { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- top band ---------- */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
  background: var(--band);
  color: var(--band-ink);
}

.topbar-inner {
  max-width: calc(var(--col) + 32px);
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-btn {
  display: inline-grid;
  place-content: center;
  gap: 4px;
  width: 42px;
  height: 42px;
  margin-inline-start: -10px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.menu-btn span { display: block; width: 20px; height: 2px; border-radius: 1px; background: var(--band-ink); }
.menu-btn:hover { background: rgb(255 255 255 / 0.08); }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  margin-inline-end: auto;
}

/* One brass bar: the insignia a course graduate pins on. */
.brand-bar {
  width: 22px;
  height: 7px;
  border-radius: 2px;
  background: var(--brass);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.15) inset;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.9rem;
  line-height: 1;
  letter-spacing: 0.01em;
}

.clock {
  font: 600 0.95rem var(--font-mono);
  color: var(--band-ink);
  background: rgb(255 255 255 / 0.08);
  border: 1px solid rgb(255 255 255 / 0.25);
  border-radius: 999px;
  padding: 2px 12px;
  cursor: pointer;
}
.clock.is-low, .clock:has(.is-low) { border-color: var(--brass); color: var(--brass); }

/* ---------- page column ---------- */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
}
.view {
  flex: 1 0 auto;
  width: 100%;
  max-width: calc(var(--col) + 32px);
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 28px 72px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.view > * { min-width: 0; }

.view-head { display: flex; flex-direction: column; gap: 6px; }
.view-head h1 {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 7vw, 3.2rem);
  line-height: 0.95;
  font-weight: 700;
}
.view-head h1:focus { outline: none; }
.lede { color: var(--ink-2); max-width: 62ch; font-size: 1.05rem; }

.eyebrow {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--brass);
}

.block { display: flex; flex-direction: column; gap: 12px; }
.block > h2, .section-head h2 { font-size: 1.2rem; font-weight: 600; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.count { color: var(--ink-3); font-weight: 500; font-size: 0.9em; }
.muted { color: var(--ink-3); }

/* ---------- buttons ---------- */
.btn {
  font: 600 1rem var(--font-body);
  color: var(--action-ink);
  background: var(--action);
  border: 1px solid var(--action);
  border-radius: var(--radius);
  padding: 10px 18px;
  cursor: pointer;
  min-height: 44px;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn-quiet:hover:not(:disabled) { border-color: var(--ink-3); filter: none; }
.btn-good { background: var(--good); border-color: var(--good); color: var(--sheet); }
.btn-bad { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: var(--sheet); }
.btn-danger-text { color: var(--bad); }

.btn-text {
  font: 500 0.9rem var(--font-body);
  color: var(--ink-2);
  background: none;
  border: 0;
  padding: 6px 2px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn-text[aria-pressed="true"] { color: var(--brass); font-weight: 600; }
.btn-text.is-hidden { visibility: hidden; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.actions-split { justify-content: space-between; }

/* ---------- notices ---------- */
.notice {
  background: var(--brass-soft);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}
.notice p { max-width: 60ch; }

/* ---------- home ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: 16px 20px;
  padding-block: 16px;
  border-block: 1px solid var(--rule);
}
.kpi { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi-label { font-size: 0.85rem; color: var(--ink-2); }
.kpi-value { font-size: 1.75rem; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-of { font-size: 1rem; font-weight: 500; color: var(--ink-3); }
.kpi-sub { font-size: 0.8rem; color: var(--ink-3); }

.mode-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.mode {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 16px;
  padding-block: 14px;
  border-bottom: 1px solid var(--rule);
}
.mode:first-child { border-top: 1px solid var(--rule); }
.mode-name { font-weight: 600; font-size: 1.05rem; }
.mode-desc { color: var(--ink-2); font-size: 0.95rem; }
.mode .btn { white-space: nowrap; }

/* ---------- setup forms ---------- */
.setup { display: flex; flex-direction: column; gap: 20px; }
.chips-field { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.chips-field legend { font-weight: 600; padding: 0; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: 500 0.92rem var(--font-body);
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
}
.chip:hover { border-color: var(--ink-3); }
.chip[aria-pressed="true"] { background: var(--action); border-color: var(--action); color: var(--action-ink); }
.chip-count { font: 500 0.78rem var(--font-mono); opacity: 0.75; }

.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; }
.field select, .field input {
  font: 500 1rem var(--font-body);
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 9px 10px;
  min-height: 44px;
  width: 100%;
}
.checks { display: flex; flex-direction: column; gap: 10px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--action); flex: none; }

/* ---------- question sheet ---------- */
.session-bar { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: baseline; }
.session-count { font-size: 0.95rem; color: var(--ink-2); display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.session-count b { color: var(--ink); font-family: var(--font-mono); }
.session-score { font-size: 0.9rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.track {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 2px;
  background: var(--brass-soft);
  overflow: hidden;
}
.track span { display: block; height: 100%; background: var(--brass); border-radius: 2px; }

.sheet {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
@media (max-width: 480px) { .sheet { padding: 16px; } }

.sheet-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--ink-3);
}
.tag {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--action-soft);
  border-radius: 4px;
  padding: 1px 8px;
}
.source { font-size: 0.8rem; }

.question { font-size: 1.2rem; font-weight: 500; line-height: 1.55; }
.question:focus { outline: none; }
.hint { font-size: 0.9rem; color: var(--ink-2); }

.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: grid;
  grid-template-columns: auto 1fr 1.25rem;
  gap: 4px 12px;
  align-items: start;
  width: 100%;
  text-align: start;
  font: 400 1rem/1.5 var(--font-body);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 11px 12px;
  cursor: pointer;
}
.option:hover:not(:disabled) { border-color: var(--action); }
.option:disabled { cursor: default; }
.option-letter {
  display: inline-grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  border: 1px solid var(--ink-3);
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1;
}
.option-text { min-width: 0; overflow-wrap: anywhere; padding-top: 1px; }
.option-mark { font-size: 1.1rem; font-weight: 700; line-height: 1.6rem; text-align: center; }

.option.is-selected { border: 2px solid var(--action); background: var(--action-soft); padding: 10px 11px; }
.option.is-selected .option-letter { background: var(--action); border-color: var(--action); color: var(--action-ink); }
.option.is-correct { border: 2px solid var(--good); background: var(--good-soft); padding: 10px 11px; }
.option.is-correct .option-letter { background: var(--good); border-color: var(--good); color: var(--sheet); }
.option.is-correct .option-mark { color: var(--good); }
.option.is-wrong { border: 2px solid var(--bad); background: var(--bad-soft); padding: 10px 11px; }
.option.is-wrong .option-letter { background: var(--bad); border-color: var(--bad); color: var(--sheet); }
.option.is-wrong .option-mark { color: var(--bad); }
.option.is-muted { color: var(--ink-3); }
.option.is-missed { border-style: dashed; }

.feedback {
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--ground);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.feedback.is-good { background: var(--good-soft); }
.feedback.is-bad { background: var(--bad-soft); }
.feedback-title { font-weight: 600; }
.feedback.is-good .feedback-title { color: var(--good); }
.feedback.is-bad .feedback-title { color: var(--bad); }
.feedback-text { color: var(--ink-2); font-size: 0.95rem; }

.answer-card {
  border: 1px dashed var(--ink-3);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.answer-label { font-size: 0.8rem; font-weight: 600; color: var(--brass); letter-spacing: 0.04em; }
.answer-text { font-size: 1.05rem; }
.answer-text ol, .answer-text ul { margin: 0; padding-inline-start: 1.3rem; display: flex; flex-direction: column; gap: 4px; }
.self-grade { justify-content: flex-start; }
.self-grade-q { font-weight: 600; margin-inline-end: 4px; }

.sheet-tools { display: flex; flex-wrap: wrap; gap: 4px 18px; }

/* ---------- exam ---------- */
.exam-bar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}
.exam-progress { color: var(--ink-2); }
.exam-progress b { color: var(--ink); font-family: var(--font-mono); }
.exam-clock { display: flex; flex-direction: column; align-items: flex-end; gap: 0; }
.exam-clock-label { font-size: 0.8rem; color: var(--ink-3); }
.exam-clock [data-timer] { font-size: 1.9rem; font-weight: 600; line-height: 1.1; }
.exam-clock .is-low { color: var(--bad); }

.answer-sheet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.75rem, 1fr));
  gap: 6px;
}
.cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 4px 0;
  font: 500 0.8rem var(--font-mono);
  color: var(--ink-2);
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: 6px;
  cursor: pointer;
  overflow: hidden;
}
.cell-a { font: 600 0.85rem var(--font-body); color: var(--ink-3); min-height: 1.2em; }
.cell.is-answered { background: var(--action-soft); color: var(--ink); }
.cell.is-answered .cell-a { color: var(--ink); }
.cell.is-current { border: 2px solid var(--action); padding: 3px 0; }
.cell.is-flagged::after {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  border-style: solid;
  border-width: 10px 10px 0 0;
  border-color: var(--brass) transparent transparent transparent;
}
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.85rem; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--rule); background: var(--sheet); display: inline-block; position: relative; overflow: hidden; }
.swatch-answered { background: var(--action-soft); }
.swatch-current { border: 2px solid var(--action); }
.swatch-flag::after { content: ""; position: absolute; inset: 0 auto auto 0; border-style: solid; border-width: 8px 8px 0 0; border-color: var(--brass) transparent transparent transparent; }

.confirm {
  background: var(--sheet);
  border: 2px solid var(--brass);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.confirm p { font-weight: 500; }

/* ---------- results ---------- */
.result-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 28px;
  padding-block: 8px 16px;
  border-bottom: 1px solid var(--rule);
}
.score { font-size: 3.6rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.score-detail { color: var(--ink-2); }
.result-facts { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 0; }
.result-facts div { display: flex; flex-direction: column; }
.result-facts dt { font-size: 0.8rem; color: var(--ink-3); }
.result-facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.segmented { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.segmented button {
  font: 500 0.88rem var(--font-body);
  color: var(--ink-2);
  background: transparent;
  border: 0;
  padding: 7px 12px;
  cursor: pointer;
}
.segmented button + button { border-inline-start: 1px solid var(--rule); }
.segmented button[aria-pressed="true"] { background: var(--action-soft); color: var(--ink); box-shadow: inset 0 -2px 0 var(--action); }

.review-list { margin: 0; padding-inline-start: 1.6rem; display: flex; flex-direction: column; gap: 14px; }
.review-list li::marker { color: var(--ink-3); font-family: var(--font-mono); font-size: 0.85rem; }
.review-item { display: flex; flex-direction: column; gap: 4px; padding-bottom: 14px; border-bottom: 1px solid var(--rule); }
.review-q { font-weight: 500; }
.review-line { font-size: 0.95rem; }
.review-label { font-weight: 600; margin-inline-end: 6px; }
.review-line.is-good .review-label { color: var(--good); }
.review-line.is-bad .review-label { color: var(--bad); }
.review-line.is-muted { color: var(--ink-3); }
.review-expl { font-size: 0.88rem; color: var(--ink-2); background: var(--brass-soft); border-radius: 6px; padding: 6px 10px; }

.mistake-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.mistake-list li { border-bottom: 1px solid var(--rule); }
.mistake-list details { padding-block: 10px; }
.mistake-list summary { cursor: pointer; font-weight: 500; }
.mistake-list details[open] summary { margin-bottom: 6px; }
.mistake-list details > p { margin-top: 4px; }

.empty {
  background: var(--sheet);
  border: 1px dashed var(--rule);
  border-radius: 12px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}
.empty-title { font-weight: 600; font-size: 1.1rem; }

/* ---------- progress ---------- */
.topic-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.topic-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-block: 12px;
  border-bottom: 1px solid var(--rule);
}
.topic-row:first-child { border-top: 1px solid var(--rule); }
.topic-row-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.topic-name { font-weight: 600; }
.topic-rate { margin-inline-start: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.topic-row-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 0.85rem; color: var(--ink-3); flex-wrap: wrap; }
.chip-weak {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--bad);
  border: 1px solid var(--bad);
  border-radius: 999px;
  padding: 0 8px;
}
.meter { height: 8px; border-radius: 4px; background: var(--action-soft); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--meter); border-radius: 4px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: start; padding: 9px 8px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
th { font-size: 0.8rem; font-weight: 600; color: var(--ink-2); }
td.num { font-family: var(--font-body); font-variant-numeric: tabular-nums; }

.danger-zone { padding-top: 8px; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .chip, .option, .menu-item { transition: background-color 120ms ease, border-color 120ms ease, opacity 120ms ease; }
  .track span, .meter span { transition: width 240ms ease; }
}

/* ---------- bottom bar ---------- */
/* Fixed to the screen, so the main buttons sit in one place whatever the content above them. */
.dock {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 6;
  background: var(--sheet);
  border-top: 1px solid var(--rule);
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.dock-inner {
  max-width: var(--col);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.dock-start, .dock-end { display: flex; gap: 8px; align-items: center; }
.dock .btn { padding-inline: 14px; white-space: nowrap; }
.has-dock .view { padding-top: 14px; gap: 14px; padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
/* On a phone the source file name is the first thing to go, so the tag and tools share one line. */
@media (max-width: 560px) { .sheet-meta .source { display: none; } }
/* Short screens: tighter question cards, so four answers usually fit above the bottom bar. */
@media (max-height: 760px) {
  .sheet { gap: 12px; padding: 14px; }
  .option, .pick-row { padding-block: 8px; }
  .question { font-size: 1.12rem; }
}
/* Keyboard focus and scrollIntoView stop short of the bar instead of hiding things under it. */
html:has(body.has-dock) { scroll-padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }

/* ---------- dialog & toast ---------- */
.dialog {
  border: 0;
  border-radius: 12px;
  padding: 0;
  width: min(32rem, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.28);
}
.dialog::backdrop { background: rgb(20 23 15 / 0.55); }
.dialog-body { display: flex; flex-direction: column; gap: 14px; padding: 18px; }
.dialog-title { font-weight: 600; font-size: 1.1rem; }
.dialog-text { font-weight: 500; }
.dialog-q { color: var(--ink-2); font-size: 0.95rem; border-inline-start: 3px solid var(--brass); padding-inline-start: 10px; }
.dialog textarea, .copy-box {
  font: 400 1rem var(--font-body);
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 9px 10px;
  width: 100%;
  resize: vertical;
}

.toast {
  position: fixed;
  inset-inline: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 8;
  max-width: 30rem;
  margin: 0 auto;
  background: var(--ink);
  color: var(--sheet);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.95rem;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
}
.has-dock .toast { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
.toast .btn-text { color: var(--sheet); font-weight: 600; margin-inline-start: 8px; }

/* ---------- question tools ---------- */
.sheet-icons { display: inline-flex; gap: 2px; margin-inline-start: auto; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--ink-3);
  cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.icon-btn:hover { color: var(--ink); background: var(--ground); }
.icon-btn.is-on { color: var(--brass); }
.icon-btn.is-on svg { fill: currentColor; }

/* ---------- practice modes ---------- */
.mode-picks { display: flex; flex-direction: column; gap: 8px; }
.mode-pick {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
  cursor: pointer;
}
.mode-pick:has(input:checked) { border-color: var(--action); box-shadow: inset 0 0 0 1px var(--action); }
.mode-pick input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--action); flex: none; }
.mode-pick.is-off { opacity: 0.55; cursor: not-allowed; }
.mode-pick-text { display: flex; flex-direction: column; gap: 2px; }
.mode-pick-name { font-weight: 600; }
.mode-pick-desc { font-size: 0.88rem; color: var(--ink-2); }

/* ---------- ordering & matching ---------- */
.pick-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.pick-row {
  display: grid;
  grid-template-columns: 1.9rem 1fr 1.25rem;
  gap: 4px 10px;
  align-items: start;
  width: 100%;
  text-align: start;
  font: 400 1rem/1.5 var(--font-body);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
}
.pick-row:hover:not(:disabled) { border-color: var(--action); }
.pick-row:disabled { cursor: default; }
.pick-key {
  display: inline-grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 6px;
  border: 1px dashed var(--ink-3);
  font: 600 0.9rem var(--font-mono);
  line-height: 1;
}
.pick-text { min-width: 0; overflow-wrap: anywhere; padding-top: 1px; display: flex; flex-direction: column; gap: 2px; }
.pick-when { font-size: 0.85rem; font-weight: 600; color: var(--ink-2); }
.pick-row.is-placed { background: var(--action-soft); border-color: var(--action); }
.pick-row.is-placed .pick-key { border: 1px solid var(--action); background: var(--action); color: var(--action-ink); }
.pick-row.is-correct { background: var(--good-soft); border-color: var(--good); }
.pick-row.is-correct .pick-key { border: 1px solid var(--good); background: var(--good); color: var(--sheet); }
.pick-row.is-correct .option-mark { color: var(--good); }
.pick-row.is-wrong { background: var(--bad-soft); border-color: var(--bad); }
.pick-row.is-wrong .pick-key { border: 1px solid var(--bad); background: var(--bad); color: var(--sheet); }
.pick-row.is-wrong .option-mark { color: var(--bad); font: 700 1rem/1.6rem var(--font-mono); }
.pick-when.is-hidden { visibility: hidden; }
.match-terms .chip { align-items: center; }
.match-term .pick-key { width: 1.4rem; height: 1.4rem; font-size: 0.8rem; border-style: solid; }
.match-term.is-done { background: var(--action-soft); }
.match-term.is-active, .match-term[aria-pressed="true"] { background: var(--action); border-color: var(--action); color: var(--action-ink); }

/* ---------- learning tab ---------- */
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.history-row {
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  gap: 2px 12px;
  align-items: baseline;
  padding-block: 10px;
  border-bottom: 1px solid var(--rule);
}
.history-row:first-child { border-top: 1px solid var(--rule); }
.history-n { font: 600 0.9rem var(--font-mono); color: var(--brass); }
.history-name { font-weight: 600; }
.history-years { font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.history-note { grid-column: 2 / -1; font-size: 0.85rem; color: var(--ink-3); }

.event-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.event-card { background: var(--sheet); border: 1px solid var(--rule); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.event-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.event-when { font-size: 0.9rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.event-name { font-weight: 600; font-size: 1.08rem; }
.event-alias { font-weight: 400; color: var(--ink-2); }
.event-note { font-size: 0.92rem; color: var(--ink-2); }
.holders { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 4px 16px; margin: 4px 0 0; padding-top: 8px; border-top: 1px dashed var(--rule); }
.holders div { display: flex; flex-direction: column; }
.holders dt { font-size: 0.78rem; color: var(--ink-3); }
.holders dd { margin: 0; font-weight: 500; }
.holders-none { font-size: 0.88rem; }

.flashcard { min-height: 14rem; }
.card-ask { color: var(--ink-2); font-size: 1rem; }
.card-big { font-family: var(--font-display); font-size: clamp(2.2rem, 9vw, 3rem); line-height: 1.05; font-weight: 700; }
.card-big:focus { outline: none; }
.card-answer { font-weight: 600; font-size: 1.2rem; }

.map-sheet { gap: 12px; flex: 1; }
.map-wrap { flex: 1; min-height: 200px; position: relative; }
.map-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.map-land { fill: var(--action-soft); stroke: var(--ink-3); stroke-width: 0.8; stroke-linejoin: round; }
.map-water { fill: var(--water); stroke: var(--water-ink); stroke-width: 0.6; }
.map-river { fill: none; stroke: var(--water-ink); stroke-width: 1.1; stroke-linecap: round; }
.map-mark { fill: var(--bad); stroke: var(--sheet); stroke-width: 2; }
.map-pin { cursor: pointer; }
.map-hit { fill: transparent; }
.map-pin-dot { fill: var(--brass); stroke: var(--sheet); stroke-width: 1.5; }
.map-pin-label { fill: var(--sheet); font: 700 8.5px var(--font-body); pointer-events: none; }
.map-pin.is-correct .map-pin-dot { fill: var(--good); }
.map-pin.is-wrong .map-pin-dot { fill: var(--bad); }
.map-pin.is-muted { opacity: 0.45; }
.map-pin:focus-visible { outline: none; }
.map-pin:focus-visible .map-pin-dot { stroke: var(--focus); stroke-width: 2.5; }
.options-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.feedback-line { min-height: 1.6em; font-weight: 600; }
.feedback-line.is-good { color: var(--good); }
.feedback-line.is-bad { color: var(--bad); }

.search-item { display: flex; flex-direction: column; gap: 4px; padding-block: 10px; }
.search-item .sheet-meta { min-height: 36px; }
mark { background: var(--brass-soft); color: inherit; border-radius: 3px; padding: 0 2px; }
.report-item { display: flex; flex-direction: column; gap: 4px; padding-block: 10px; }

/* ---------- score trend ---------- */
.trend { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.trend-caption { font-size: 0.92rem; color: var(--ink-2); min-height: 1.5em; }
.trend svg { width: 100%; height: auto; display: block; overflow: visible; }
.trend-grid { stroke: var(--rule); stroke-width: 1; }
.trend-axis { fill: var(--ink-3); font: 500 12px var(--font-body); }
.trend-line { fill: none; stroke: var(--meter); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend-dot { fill: var(--meter); stroke: var(--sheet); stroke-width: 2; }
.trend-hit { fill: transparent; }
.trend-pt { cursor: pointer; }
.trend-pt.is-on .trend-dot { fill: var(--brass); }
.trend-pt:focus-visible { outline: none; }
.trend-pt:focus-visible .trend-dot { stroke: var(--focus); stroke-width: 3; }

/* ---------- flashcards ---------- */
/* The stage grows to fill the screen; the card turns in 3D on tap and follows the finger on a swipe. */
.fc-stage {
  flex: 1;
  min-height: 15rem;
  display: flex;
  perspective: 1400px;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
}
.fc-drag { flex: 1; display: flex; will-change: transform; }
.fc-drag.is-entering { animation: fc-in 260ms cubic-bezier(.2, .8, .2, 1); }
@keyframes fc-in {
  from { opacity: 0; transform: translateX(-28px) scale(.96); }
}
.fc-card {
  flex: 1;
  display: grid;
  grid-template-rows: 1fr;
  transform-style: preserve-3d;
  transition: transform 520ms cubic-bezier(.22, 1, .36, 1);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.fc-card.is-flipped { transform: rotateY(180deg); }
.fc-card:focus { outline: none; }
.fc-card:focus-visible .fc-face { outline: 3px solid var(--focus); outline-offset: 2px; }
.fc-face {
  grid-area: 1 / 1;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 10px;
  box-shadow: 0 6px 22px rgb(0 0 0 / 0.07);
  overflow: hidden;
}
.fc-back { transform: rotateY(180deg); border-color: var(--action); }
.fc-face .tag { align-self: flex-start; }
/* Two auto margins centre the question between the tag at the top and the hint at the bottom. */
.fc-front .card-ask { margin-top: auto; }
.fc-hint { margin-top: auto; font-size: 0.82rem; color: var(--ink-3); align-self: center; }
.fc-face .card-answer { font-size: 1.35rem; font-weight: 600; line-height: 1.35; }
.fc-face .card-big.is-long { font-family: var(--font-body); font-size: 1.3rem; font-weight: 600; line-height: 1.45; }
.fc-face .holders { width: 100%; }
/* While dragging, the card edge tints toward the choice it would make. */
.fc-drag.is-going-right .fc-face { border-color: var(--good); }
.fc-drag.is-going-left .fc-face { border-color: var(--bad); }
.fc-help { text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .fc-card { transition: none; }
  .fc-drag.is-entering { animation: none; }
}

/* ---------- menu ---------- */
/* A drawer from the right (the start side in Hebrew) holding every page, the learning sections and text size. */
.menu {
  margin: 0;
  padding: 0;
  border: 0;
  inset-block: 0;
  inset-inline-start: 0;
  inset-inline-end: auto;
  width: min(20rem, 86vw);
  max-width: none;
  height: 100dvh;
  max-height: none;
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 0 40px rgb(0 0 0 / 0.3);
}
.menu::backdrop { background: rgb(20 23 15 / 0.5); }
.menu[open] { animation: menu-in 220ms cubic-bezier(.2, .8, .2, 1); }
.menu[open]::backdrop { animation: fade-in 220ms ease-out; }
.menu.is-closing { animation: menu-out 160ms ease-in forwards; }
.menu.is-closing::backdrop { animation: fade-out 160ms ease-in forwards; }
@keyframes menu-in { from { transform: translateX(100%); } }
@keyframes menu-out { to { transform: translateX(100%); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .menu[open], .menu[open]::backdrop, .menu.is-closing, .menu.is-closing::backdrop { animation: none; }
}
.menu-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px calc(16px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
}
.menu-head { display: flex; align-items: center; gap: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--rule); }
.menu-title { font-family: var(--font-display); font-size: 1.6rem; line-height: 1; margin-inline-end: auto; }
.menu-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 10px 12px;
  font: 500 1.05rem var(--font-body);
  color: var(--ink);
  text-align: start;
  background: none;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}
.menu-item:hover { background: var(--ground); }
.menu-item[aria-current="page"] { background: var(--action-soft); box-shadow: inset -3px 0 0 var(--action); }
.menu-sub-item { padding-inline-start: 26px; font-size: 1rem; }
.menu-extra { font-size: 0.8rem; font-weight: 500; color: var(--ink-3); white-space: nowrap; }
.menu-group { margin-top: 6px; }
.menu-group-title { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.04em; color: var(--brass); padding: 4px 12px 2px; }
.menu-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--rule); display: flex; flex-direction: column; gap: 8px; }
.menu-foot .segmented { display: flex; }
.menu-foot .segmented button { flex: 1; }

/* ---------- question card: one column on phones, two side by side on wide landscape screens ---------- */
/* On phones the two wrappers vanish from layout, so their children sit in the card exactly as before. */
.sheet-q, .sheet-a { display: contents; }
@media (min-width: 900px) and (orientation: landscape) {
  .view:has(> .sheet.split) { max-width: calc(68rem + 32px); }
  body:has(.sheet.split) .dock-inner { max-width: 68rem; }
  .sheet.split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    gap: 16px 32px;
    align-items: start;
  }
  .sheet.split > .sheet-q, .sheet.split > .sheet-a { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
  .sheet.split > .sheet-q { grid-column: 1; }
  .sheet.split > .sheet-a { grid-column: 2; grid-row: 1 / span 2; }
  .sheet.split > .feedback { grid-column: 1; }
  .map-sheet.split { grid-template-rows: minmax(0, 1fr); align-items: stretch; }
  .map-sheet.split > .sheet-a { grid-row: 1; align-self: center; }
}

/* ---------- page animations ---------- */
/* The new page's content slides in; the fixed bottom bar only fades, since moving it would make it jump. */
.view.is-entering-forward > :not(.dock) { animation: page-in-forward 260ms cubic-bezier(.22, 1, .36, 1); }
.view.is-entering-back > :not(.dock) { animation: page-in-back 260ms cubic-bezier(.22, 1, .36, 1); }
.view.is-entering-forward > .dock, .view.is-entering-back > .dock { animation: fade-in 200ms ease-out; }
@keyframes page-in-forward { from { opacity: 0; transform: translateX(-24px); } }
@keyframes page-in-back { from { opacity: 0; transform: translateX(24px); } }
@media (prefers-reduced-motion: reduce) {
  .view.is-entering-forward > *, .view.is-entering-back > * { animation: none; }
}

/* ---------- home: resume ---------- */
.resume { display: flex; flex-direction: column; gap: 8px; }
.resume h2 { font-size: 1rem; font-weight: 600; color: var(--brass); }
.resume-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.resume-item {
  width: 100%;
  min-height: 52px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 4px 12px;
  padding: 12px 14px;
  font: inherit;
  color: var(--ink);
  text-align: start;
  background: var(--sheet);
  border: 1px solid var(--action);
  border-radius: var(--radius);
  box-shadow: inset -4px 0 0 var(--action);
  cursor: pointer;
}
.resume-item:hover { background: var(--action-soft); }
.resume-name { font-weight: 600; }
.resume-detail { color: var(--ink-2); font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.resume-go { font-weight: 700; color: var(--action); }

/* ---------- exam pause ---------- */
.exam-pause { padding: 2px 0; font-size: 0.85rem; }
.paused-sheet { min-height: 12rem; justify-content: center; align-items: center; text-align: center; }
.clock.is-paused { opacity: 0.75; }
.clock.is-paused [data-timer]::before { content: "⏸ "; }

/* ---------- learning lists: aliyot and documents ---------- */
.facts { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 0; padding-top: 8px; border-top: 1px dashed var(--rule); }
.facts div { display: grid; grid-template-columns: 5.5rem 1fr; gap: 8px; }
.facts dt { font-size: 0.8rem; color: var(--ink-3); padding-top: 2px; }
.facts dd { margin: 0; font-size: 0.95rem; }
.doc-row { grid-template-columns: 8.5rem 1fr; }
.doc-row .history-note { grid-column: 2; }

/* ---------- step ordering ---------- */
.order-answer { margin: 6px 0 0; padding-inline-start: 1.4rem; display: flex; flex-direction: column; gap: 4px; }
.order-answer li::marker { font-weight: 700; }

/* ---------- keyboard shortcuts ---------- */
.keys { display: flex; flex-direction: column; gap: 8px; margin: 0; }
.keys div { display: grid; grid-template-columns: 4.5rem 1fr; gap: 10px; align-items: baseline; }
.keys dd { margin: 0; }
kbd {
  font: 600 0.85rem var(--font-mono);
  background: var(--ground);
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 7px;
}
.menu-shortcuts { align-self: flex-start; }
