/* Exam trainer — phone-first layout, light + dark themes via tokens.
   Pictures always sit on white: the PDF artwork (lights, flags, buoys) is drawn for white paper. */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #14202e;
  --muted: #5b6878;
  --border: #d5dbe4;
  --accent: #0b5cad;
  --accent-text: #ffffff;
  --accent-soft: #dbe8f7;
  --ok: #17803d;
  --ok-soft: #dcf3e3;
  --bad: #b42318;
  --bad-soft: #fde3e0;
  --warn: #9a5b00;
  --warn-soft: #fdf0d5;
  --radius: 14px;
  --tap: 52px;
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141b;
    --surface: #17202a;
    --surface-2: #1f2a36;
    --text: #e8eef5;
    --muted: #9aa8b8;
    --border: #2c3a49;
    --accent: #4c9be8;
    --accent-text: #08121c;
    --accent-soft: #1b3550;
    --ok: #4cc27a;
    --ok-soft: #173826;
    --bad: #ff7b6e;
    --bad-soft: #43201d;
    --warn: #f0b44c;
    --warn-soft: #3d2f12;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 8px; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
p { margin: 0 0 8px; }
img { max-width: 100%; }
.muted { color: var(--muted); }
.small, small { font-size: 14px; }

.screen {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) calc(env(safe-area-inset-right) + var(--gutter)) calc(env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + var(--gutter));
  min-height: 100dvh;
}

button {
  font: inherit;
  min-height: var(--tap);
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  color: inherit;
  background: none;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.secondary { background: var(--surface); border-color: var(--border); }
.danger { background: var(--bad); color: #fff; font-weight: 600; }
.ghost { min-width: var(--tap); font-size: 22px; padding: 6px 10px; }
.link { min-height: 40px; padding: 6px 8px; color: var(--accent); text-decoration: underline; }
.link.danger { background: none; color: var(--bad); font-weight: 400; }
.huge { width: 100%; min-height: 72px; font-size: 21px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; margin: 16px 0; }
.huge small { font-weight: 400; opacity: .9; }
.wide { width: 100%; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.hero { padding: 8px 0 4px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 10px 0; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; }
.tile .big { font-size: 30px; font-weight: 700; }
.sync { margin-top: 16px; font-size: 14px; }
.sync.ok { color: var(--ok); }
.sync.warn { color: var(--warn); }
.sync.bad { color: var(--bad); }

.banner { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-radius: var(--radius); padding: 10px 14px; margin: 8px 0; font-size: 15px; }
.banner.info { background: var(--accent-soft); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }

/* exam */
.exambar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px;
  background: var(--bg); padding: 4px 0 8px; margin: 0 0 4px;
  border-bottom: 1px solid var(--border);
}
.counter { font-weight: 600; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 19px; padding: 4px 10px; border-radius: 10px; background: var(--surface-2); }
.timer.low { background: var(--bad-soft); color: var(--bad); }
.question { padding: 8px 0 4px; }
.qtext { font-size: 20px; font-weight: 600; margin: 4px 0 10px; overflow-wrap: anywhere; }
.pic { display: flex; justify-content: center; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin: 8px 0; }
.pic img { max-height: min(220px, 26dvh); object-fit: contain; }
.apic { display: block; background: #fff; border-radius: 8px; padding: 6px; margin-top: 6px; }
.apic img { max-height: 90px; display: block; }

.answers { display: flex; flex-direction: column; gap: 10px; margin: 8px 0; }
.answer {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 10px; text-align: left;
  background: var(--surface); border: 2px solid var(--border); padding: 12px; min-height: 64px;
}
.answer .letter, .review-answers .letter {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-weight: 700;
}
.answer .atext { overflow-wrap: anywhere; }
.answer.selected { border-color: var(--accent); background: var(--accent-soft); }
.answer.selected .letter { background: var(--accent); color: var(--accent-text); }
.answer.removed { opacity: .35; }
.answer.removed .atext { text-decoration: line-through; }
.answer.shown-correct { border-color: var(--ok); box-shadow: inset 0 0 0 1px var(--ok); }
.tag { font-size: 13px; font-weight: 600; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.tag.ok, .tag.right { background: var(--ok-soft); color: var(--ok); }
.tag.wrong { background: var(--bad-soft); color: var(--bad); }
.tag.unanswered { background: var(--surface-2); color: var(--muted); }
.tag.revealed { background: var(--warn-soft); color: var(--warn); }
.note { font-size: 15px; color: var(--muted); }
.note.warn { color: var(--warn); }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 84px; }
.examnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  padding: 10px max(var(--gutter), env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  background: var(--bg); border-top: 1px solid var(--border);
}
@media (min-width: 752px) {
  .examnav { left: 50%; right: auto; width: 720px; transform: translateX(-50%); padding-left: var(--gutter); padding-right: var(--gutter); }
}

.overlay { position: fixed; inset: 0; z-index: 10; background: rgb(0 0 0 / .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--surface); width: 100%; max-width: 720px; max-height: 88dvh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 16px var(--gutter) calc(16px + env(safe-area-inset-bottom));
}
.small-sheet { max-width: 480px; }
.overlay.center { align-items: center; padding: 16px; }
.overlay.center .sheet { border-radius: 20px; }
@media (min-width: 752px) { .overlay { align-items: center; } .sheet { border-radius: 20px; } }
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 12px 0; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(10, 1fr); } }
.cell { min-height: 46px; padding: 0; border: 1px solid var(--border); background: var(--surface-2); font-weight: 600; }
.cell.answered { background: var(--accent); color: var(--accent-text); }
.cell.revealed { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.cell.current { outline: 3px solid var(--text); outline-offset: 1px; }
.sheet-actions { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); background: var(--surface); padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 4px; }
.legend { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--border); }
.dot.answered { background: var(--accent); }
.dot.revealed { background: var(--warn-soft); border-color: var(--warn); }

/* results */
.verdict { border-radius: var(--radius); padding: 20px; text-align: center; margin: 8px 0 12px; }
.verdict .big { font-size: 34px; font-weight: 800; letter-spacing: .04em; margin: 0; }
.verdict.pass { background: var(--ok-soft); color: var(--ok); }
.verdict.fail { background: var(--bad-soft); color: var(--bad); }
.chips { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.chips li { background: var(--surface); border: 1px solid var(--border); border-radius: 99px; padding: 4px 12px; font-size: 14px; }
.review { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.review .qtext { font-size: 17px; }
.review-answers .atext { overflow-wrap: anywhere; min-width: 0; }
.review-answers { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.review-answers li { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 6px; border-radius: 10px; }
.review-answers .is-correct { background: var(--ok-soft); }
.review-answers .is-correct .letter { background: var(--ok); color: #fff; }
.review-answers .is-wrong { background: var(--bad-soft); }
.review-answers .is-wrong .letter { background: var(--bad); color: #fff; }
.review-answers .removed { opacity: .5; }
.review-answers .mark { font-size: 13px; font-weight: 700; white-space: nowrap; }
.sticky-bottom { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); }

/* history + settings */
.subbar { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.subbar h1 { margin: 0; }
.history { list-style: none; padding: 0; margin: 0; }
.history-row { width: 100%; display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; text-align: left; background: var(--surface); border-color: var(--border); margin: 6px 0; }
.switch { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; margin-bottom: 14px; }
.switch input { width: 24px; height: 24px; accent-color: var(--accent); }
.switch small { grid-column: 2; }
.segmented { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 6px; }
.segmented button { flex: 1; border-radius: 0; border-right: 1px solid var(--border); background: var(--surface); }
.segmented button:last-child { border-right: none; }
.segmented button.on { background: var(--accent); color: var(--accent-text); font-weight: 700; }
input[type="password"], input[type="text"] {
  width: 100%; min-height: var(--tap); font: inherit; padding: 10px 12px; margin: 8px 0;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--text);
}
.diag dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 14px; }
.diag dt { color: var(--muted); }
.diag dd { margin: 0; overflow-wrap: anywhere; }
