/* CCAR-F Field Guide — one page: the study plan, with pop-ups for each task statement.
   GitHub-style reading UI: plain canvas, bordered boxes and tables. Colours follow GitHub's light and dark themes. */

:root {
  --bg: #ffffff;
  --bg-subtle: #f6f8fa;
  --bg-hover: #818b9814;
  --border: #d1d9e0;
  --border-muted: #d1d9e0b3;
  --fg: #1f2328;
  --fg-muted: #59636e;
  --accent: #0969da;
  --success: #1a7f37;
  --danger: #d1242f;
  --attention: #9a6700;
  --header-bg: #f6f8fa;
  --btn-bg: #f6f8fa;
  --btn-hover: #eff2f5;
  --primary: #1f883d;
  --primary-hover: #1c8139;
  --code-inline: #818b981f;
  --d1: #0969da;
  --d2: #1a7f37;
  --d3: #9a6700;
  --d4: #bf3989;
  --d5: #8250df;
  --shadow: 0 1px 0 #1f23280a;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-ar: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Arabic", "Noto Naskh Arabic", Tahoma, "Geeza Pro", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --header-h: 56px;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --bg-subtle: #151b23;
    --bg-hover: #656c761a;
    --border: #3d444d;
    --border-muted: #3d444db3;
    --fg: #f0f6fc;
    --fg-muted: #9198a1;
    --accent: #4493f8;
    --success: #3fb950;
    --danger: #f85149;
    --attention: #d29922;
    --header-bg: #010409;
    --btn-bg: #212830;
    --btn-hover: #262c36;
    --primary: #238636;
    --primary-hover: #29903b;
    --code-inline: #656c7633;
    --d1: #4493f8;
    --d2: #3fb950;
    --d3: #d29922;
    --d4: #db61a2;
    --d5: #ab7df8;
    --shadow: 0 0 transparent;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-subtle: #151b23;
  --bg-hover: #656c761a;
  --border: #3d444d;
  --border-muted: #3d444db3;
  --fg: #f0f6fc;
  --fg-muted: #9198a1;
  --accent: #4493f8;
  --success: #3fb950;
  --danger: #f85149;
  --attention: #d29922;
  --header-bg: #010409;
  --btn-bg: #212830;
  --btn-hover: #262c36;
  --primary: #238636;
  --primary-hover: #29903b;
  --code-inline: #656c7633;
  --d1: #4493f8;
  --d2: #3fb950;
  --d3: #d29922;
  --d4: #db61a2;
  --d5: #ab7df8;
  --shadow: 0 0 transparent;
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 15px; line-height: 1.55; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 60; background: var(--header-bg); }
[hidden] { display: none !important; }
svg { max-width: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 4px; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; text-wrap: balance; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
code { unicode-bidi: isolate; direction: ltr; font-family: var(--mono); font-size: 85%; background: var(--code-inline); padding: .15em .4em; border-radius: 6px; overflow-wrap: anywhere; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; inset-inline-start: -9999px; top: 8px; z-index: 100; background: var(--bg); color: var(--accent); padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.skip:focus { inset-inline-start: 16px; }
.container { max-width: 1280px; margin-inline: auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
@media (min-width: 768px) { .container { padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); } }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- Header ---------- */
.site-header { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 50; background: var(--header-bg); border-bottom: 1px solid var(--border); }
.site-header .container { display: flex; align-items: center; gap: 12px; min-height: var(--header-h); }
.brand { flex: 1; display: flex; align-items: center; gap: 10px; color: var(--fg); font-weight: 600; font-size: 15px; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg); color: var(--fg); }
.brand-mark svg { width: 18px; height: 18px; }
.brand small { font-weight: 400; color: var(--fg-muted); margin-inline-start: 2px; font-size: inherit; }
.head-link { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: var(--radius); color: var(--fg); font-size: 14px; }
.head-link:hover { background: var(--bg-hover); text-decoration: none; }
.head-link svg { width: 16px; height: 16px; color: var(--fg-muted); }
.theme-btn { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--btn-bg); color: var(--fg-muted); cursor: pointer; }
.theme-btn:hover { background: var(--btn-hover); color: var(--fg); }
.theme-btn svg { width: 16px; height: 16px; }
.theme-btn .i-sun { display: none; }
:root[data-theme="dark"] .theme-btn .i-sun { display: block; }
:root[data-theme="dark"] .theme-btn .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .i-sun { display: block; }
  :root:not([data-theme="light"]) .theme-btn .i-moon { display: none; }
}
@media (max-width: 860px) { .site-header { position: static; } }

/* ---------- Page head ---------- */
.pagehead { padding-block: 28px 20px; }
.pagehead h1 { font-size: 30px; }
.pagehead-t { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; }
.pagehead .byline { font-size: 14px; color: var(--fg-muted); }
.byline a { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; color: var(--fg); }
.byline a:hover { color: var(--accent); }
.byline svg { width: 15px; height: 15px; align-self: center; }
.pagehead p { margin-top: 8px; color: var(--fg-muted); font-size: 16px; max-width: 75ch; }
.pagehead p.exam-note { font-size: 13px; }

/* ---------- Primitives ---------- */
.Box { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.Label {
  display: inline-flex; align-items: center; gap: 4px; padding: 0 7px; border-radius: 2em; font-size: 12px; font-weight: 500; line-height: 20px; white-space: nowrap;
  border: 1px solid color-mix(in srgb, var(--c, var(--fg-muted)) 45%, transparent);
  color: var(--c, var(--fg-muted));
  background: color-mix(in srgb, var(--c, var(--fg-muted)) 8%, transparent);
}
.Counter { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 2em; font-size: 12px; font-weight: 500; line-height: 18px; text-align: center; background: var(--code-inline); color: var(--fg); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 5px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--btn-bg); color: var(--fg); font: 500 14px/20px var(--font); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--btn-hover); text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn-sm { padding: 3px 10px; font-size: 13px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-primary { border-color: transparent; background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.flash { padding: 12px 16px; border-radius: var(--radius); border: 1px solid color-mix(in srgb, var(--c, var(--accent)) 40%, transparent); background: color-mix(in srgb, var(--c, var(--accent)) 8%, var(--bg)); }
.flash-title { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; color: var(--c, var(--accent)); margin-bottom: 6px; }
.flash-title svg { width: 16px; height: 16px; flex: none; }
.flash ul { padding-inline-start: 18px; display: grid; gap: 4px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 2em; border: 1px solid var(--border); background: var(--bg); color: var(--fg-muted); font: 500 13px/20px var(--font); cursor: pointer; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

/* ---------- Tables ---------- */
.tscroll { overflow-x: auto; }
table.gh { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.gh th, table.gh td { text-align: start; vertical-align: top; padding: 9px 14px; border-top: 1px solid var(--border-muted); }
table.gh thead th { border-top: 0; background: var(--bg-subtle); font-size: 13px; font-weight: 600; color: var(--fg-muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
table.gh tbody tr:first-child td { border-top: 0; }
table.gh tbody tr:hover td { background: var(--bg-hover); }

/* Decisions (symptom → usual answer) and facts & terms (question → answer) */
table.gh.decide td.q { font-weight: 600; width: 46%; }
table.decide td.a .ans { display: inline; } /* stays on the line of the phone layout's "→" */
/* Exam traps */
table.traps td { width: 33.3%; }
table.traps td.trapcol { font-weight: 600; }
table.traps td.whycol { color: var(--fg-muted); }

/* Phones: each row becomes a small card */
@media (max-width: 700px) {
  table.stack thead { display: none; }
  table.stack, table.stack tbody { display: block; }
  table.stack tr { display: grid; gap: 4px; padding: 12px 14px; border-top: 1px solid var(--border-muted); }
  table.stack tr:first-child { border-top: 0; }
  table.stack td { display: block; padding: 0; border: 0; width: auto !important; }
  table.stack tbody tr:hover td { background: none; }
  table.stack td.trx { justify-self: end; margin-top: 4px; }
  table.gh.decide td.a { color: var(--fg-muted); }
  table.gh.decide td.a::before { content: "→ "; color: var(--c); font-weight: 600; }
  table.traps td.whycol::before, table.traps td.fixcol::before { display: block; font-size: 12px; font-weight: 600; margin-top: 6px; }
  table.traps td.whycol::before { content: "Why it's wrong"; color: var(--danger); }
  table.traps td.fixcol::before { content: "What's actually true"; color: var(--success); }
}

/* Quiz mode: each answer hidden until tapped */
.quiz tbody tr[tabindex] { cursor: pointer; }
.quiz tbody tr[tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.quiz table.decide td.a, .quiz table.traps td.whycol, .quiz table.traps td.fixcol { position: relative; }
.quiz table.decide td.a:not(.revealed) > .ans,
.quiz table.traps td.whycol:not(.revealed) > *, .quiz table.traps td.fixcol:not(.revealed) > * { visibility: hidden; }
.quiz table.decide td.a:not(.revealed)::after,
.quiz table.traps td.whycol:not(.revealed)::after, .quiz table.traps td.fixcol:not(.revealed)::after {
  content: "Click to reveal"; position: absolute; inset: 6px; display: grid; place-items: center; border-radius: var(--radius);
  border: 1px dashed var(--border); color: var(--fg-muted); font-size: 12px; font-weight: 400; background: var(--bg-subtle);
}
@media (max-width: 700px) {
  .quiz table.decide td.a:not(.revealed) { min-height: 44px; }
  .quiz table.decide td.a:not(.revealed)::after { inset: 0; content: "Tap to reveal"; }
  .quiz table.traps td.whycol:not(.revealed), .quiz table.traps td.fixcol:not(.revealed) { min-height: 64px; }
  .quiz table.traps td.whycol:not(.revealed)::after, .quiz table.traps td.fixcol:not(.revealed)::after { inset: 24px 0 0; content: "Tap to reveal"; }
}

/* ---------- Translate: each row (and the summary and tips) carries its Arabic, one tap away ---------- */
table.gh th.trx, table.gh td.trx { width: 1%; padding-inline: 4px 10px; }
.trx-btn { display: grid; place-items: center; min-width: 32px; height: 26px; padding: 0 6px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--btn-bg); color: var(--fg-muted); font: 600 12px/1 var(--font); cursor: pointer; white-space: nowrap; }
.trx-btn:hover { color: var(--fg); background: var(--btn-hover); }
.trx-btn[aria-pressed="true"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.tx { text-align: start; }
.tx[lang="ar"] { font-family: var(--font-ar); line-height: 1.75; }
tr.translated td:not(.trx) { background: color-mix(in srgb, var(--accent) 4%, var(--bg)); }

/* ---------- Study plan: a progress table, one checkbox per task statement and step ---------- */
.plan-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-bottom: 16px; }
.plan-prog { flex: 1 1 320px; display: grid; gap: 6px; }
.plan-bar { height: 8px; border-radius: 99px; background: var(--border-muted); overflow: hidden; }
.plan-bar span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--success); transition: width .2s; }
.plan-prog p { font-size: 14px; color: var(--fg-muted); }
.plan-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.plan-next-at { font-weight: 400; }
.plan-next-at b { font-family: var(--mono); font-weight: 600; }
/* Every step ticked: congratulations, where Continue was */
.plan-congrats { --c: var(--success); display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.plan-congrats > svg { flex: none; width: 30px; height: 30px; color: var(--success); }
.plan-congrats-t { font-size: 16px; font-weight: 600; color: var(--fg); }
.plan-congrats p + p { font-size: 14px; color: var(--fg-muted); }
/* The options above the plan: quiet until switched on */
.plan-opts { display: flex; flex-wrap: wrap; gap: 4px 24px; margin: -6px 0 12px; }
.plan-opts .toggle { min-height: 32px; font-size: 13px; color: var(--fg-muted); }
.plan-opts .toggle:has(input:checked) { color: var(--fg); }
table.plan-table td { vertical-align: middle; }
table.plan-table thead th { vertical-align: bottom; }
table.plan-table thead th.plan-step { min-width: 104px; white-space: normal; text-align: center; line-height: 1.35; }
/* The Practice questions heading links to the practice test */
.th-link { color: inherit; }
.th-link:hover { color: var(--accent); }
.th-link svg.ext { width: 11px; height: 11px; margin-inline-start: 4px; vertical-align: -1px; }
table.plan-table td.plan-step { width: 1%; padding: 0; text-align: center; }
table.gh.plan-table tr.plan-dh th { padding: 0; background: var(--bg-subtle); border-top: 1px solid var(--border); }
/* The heading row: a button that folds the domain's task rows away, then "Mark all" */
.plan-dh-in { display: flex; align-items: center; gap: 4px; padding-inline-end: 12px; }
.plan-dh-fold { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; align-self: stretch; padding: 9px 14px; border: 0; background: none; color: inherit; font: inherit; text-align: start; cursor: pointer; }
.plan-dh-fold:hover { background: var(--bg-hover); }
.plan-dh-fold:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* "Mark all" stays quiet until it's wanted: it opens the domain's chips in a row under the heading */
.plan-bulk-btn { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius); background: none; color: var(--fg-muted); font: 500 12px/1 var(--font); white-space: nowrap; cursor: pointer; }
.plan-bulk-btn:hover, .plan-bulk-btn[aria-expanded="true"] { color: var(--fg); background: var(--btn-hover); }
.plan-bulk-btn svg { width: 14px; height: 14px; }
table.gh.plan-table tr.plan-bulk td { padding: 10px 14px 12px; background: var(--bg-subtle); border-top: 1px dashed var(--border-muted); }
.plan-bulk-in p { margin-bottom: 8px; font-size: 13px; color: var(--fg-muted); }
.plan-chips { display: flex; flex-wrap: wrap; gap: 8px; }
/* A chip: its step and count; once all are ticked, a quiet green edge and a check (tap again to clear) */
.plan-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 3px 6px 3px 12px; border: 1px solid var(--border); border-radius: 2em; background: var(--bg); color: var(--fg-muted); font: 500 13px/20px var(--font); cursor: pointer; }
.plan-chip:hover { color: var(--fg); background: var(--btn-hover); }
.plan-chip-ok { display: none; width: 14px; height: 14px; color: var(--success); }
.plan-chip[aria-pressed="true"] { padding-inline-start: 8px; color: var(--fg); border-color: color-mix(in srgb, var(--success) 45%, transparent); }
.plan-chip[aria-pressed="true"] .plan-chip-ok { display: block; }
.plan-chev { flex: none; width: 16px; height: 16px; color: var(--fg-muted); transition: transform .15s; }
tbody.folded .plan-chev { transform: rotate(-90deg); }
table.plan-table tbody.folded tr[data-plan-row] { display: none !important; }
/* "Hide completed tasks": the finished rows and domains go (with everything finished, the whole table). One that's
   just been finished fades for a moment first (site.js). */
.hide-done table.plan-table tbody.done:not(.leaving), .hide-done table.plan-table tr.done[data-plan-row]:not(.leaving),
.plan.hide-done.all-done > .Box:not(:has(.leaving)) { display: none !important; }
.hide-done table.plan-table tr.leaving, .hide-done table.plan-table tbody.leaving > tr { opacity: .4; transition: opacity 1.4s; }
.plan-dt { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; color: var(--fg); }
.plan-w { font-weight: 400; color: var(--fg-muted); font-size: 13px; white-space: nowrap; }
/* The task opens its summary in the pop-up */
.plan-task a { display: grid; grid-template-columns: 34px minmax(0, 1fr); color: var(--fg); }
.plan-task a:hover { text-decoration: none; color: var(--c); }
.plan-task a:hover span { text-decoration: underline; text-underline-offset: 3px; }
.plan-task b { font-family: var(--mono); font-weight: 600; color: var(--c); }
/* Each step: its checkbox (a generous tap target) and, beside it, the button that opens that step in the pop-up */
.plan-cell { display: flex; align-items: center; justify-content: center; gap: 2px; }
.plan-cb { display: flex; align-items: center; justify-content: center; min-width: 40px; min-height: 44px; padding: 6px; cursor: pointer; }
.plan-cb input { width: 18px; height: 18px; margin: 0; accent-color: var(--success); cursor: pointer; }
.plan-open { display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 50%; background: var(--btn-bg); color: var(--c); }
.plan-open:hover { background: color-mix(in srgb, var(--c) 12%, var(--btn-bg)); border-color: color-mix(in srgb, var(--c) 55%, transparent); }
.plan-open svg { width: 15px; height: 15px; }
/* A finished row isn't tinted (a domain of green rows strains the eyes): its ticks and dimmed title say enough */
table.plan-table tr.done .plan-task a { color: var(--fg-muted); }
tbody.done .plan-dh .Counter { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
/* Phones: the task on its own line, the four steps in a row under it, each with its name */
@media (max-width: 640px) {
  table.plan-table thead { display: none; }
  table.plan-table, table.plan-table tbody, table.plan-table tr.plan-dh, table.plan-table tr.plan-dh th,
  table.plan-table tr.plan-bulk, table.plan-table tr.plan-bulk td { display: block; }
  .plan-dh-fold { padding-inline-end: 8px; }
  /* "Mark all" shows just its icon (the name stays for screen readers), leaving the title room */
  .plan-bulk-btn { position: relative; justify-content: center; width: 36px; height: 36px; padding: 0; }
  .plan-bulk-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .plan-bulk-btn svg { width: 16px; height: 16px; }
  .plan-chip { min-height: 38px; }
  table.plan-table tr[data-plan-row] { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px 4px; padding: 10px 10px 6px; border-top: 1px solid var(--border-muted); }
  table.plan-table tr[data-plan-row] td { display: block; width: auto; padding: 0; border: 0; }
  table.plan-table td.plan-task { grid-column: 1 / -1; padding-inline: 4px; }
  /* The step names sit above their checkboxes; a name on two lines ("Decisions & terms") keeps the boxes in line */
  table.plan-table tr[data-plan-row] td.plan-step { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px; }
  table.plan-table td.plan-step::before { content: attr(data-label); font-size: 12px; line-height: 1.25; color: var(--fg-muted); text-align: center; }
  .plan-cb { min-width: 36px; padding: 4px; }
  table.plan-table tbody tr:hover td { background: none; }
}

/* ---------- Pop-ups (the study pop-up and About) ---------- */
/* Only the body scrolls, never the pop-up itself; svh (the viewport with the browser bars showing) keeps the head
   and close button clear of the address bar. */
.dialog { width: min(720px, calc(100% - 32px)); max-width: none; max-height: min(86vh, 900px); max-height: min(86svh, 900px); overflow: hidden; padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); color: var(--fg); box-shadow: 0 16px 48px rgba(1, 4, 9, .35); }
.dialog::backdrop { background: rgba(1, 4, 9, .55); }
.dialog[open] { display: flex; flex-direction: column; }
.dialog-in { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.dialog-head { flex: none; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 16px; background: var(--bg-subtle); border-bottom: 1px solid var(--border); }
.dialog-titles { min-width: 0; }
.dialog-titles .Label { color: var(--c); border-color: color-mix(in srgb, var(--c) 45%, transparent); background: color-mix(in srgb, var(--c) 8%, transparent); }
.dialog-titles h2 { font-size: 18px; }
.dialog-titles .Label + h2 { margin-top: 6px; }
.dialog-close { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--btn-bg); color: var(--fg-muted); cursor: pointer; }
.dialog-close:hover { color: var(--fg); background: var(--btn-hover); }
.dialog-close svg { width: 16px; height: 16px; }
.dialog-body { flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; padding: 16px 18px 22px; overflow: auto; display: grid; grid-auto-rows: max-content; gap: 14px; }
/* While a pop-up is open the page behind it stays put (site.js sets the class; :has() covers the rest). */
html.modal-open, html:has(dialog[open]) { overflow: hidden; }

/* The study pop-up: always the same height, so switching tabs doesn't make it jump */
.pop { width: min(1040px, calc(100% - 32px)); height: min(86vh, 900px); height: min(86svh, 900px); }
.pop-code { font-family: var(--mono); font-weight: 600; color: var(--c); margin-inline-end: 4px; }
.pop-bar, .pop-foot { flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 10px 16px; }
.pop-bar { border-bottom: 1px solid var(--border-muted); }
.pop-foot { border-top: 1px solid var(--border-muted); }
[dir="rtl"] .pop-foot svg { transform: scaleX(-1); }
.pop-tabs button svg { width: 14px; height: 14px; color: var(--c); }
.pop-tabs button[aria-pressed="true"] { color: var(--fg); border-color: color-mix(in srgb, var(--c) 60%, transparent); background: color-mix(in srgb, var(--c) 12%, transparent); }
/* "Mark this step done" sits between the arrows, as a toggle that turns green once ticked */
.pop-done { padding: 4px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; font-weight: 500; line-height: 20px; }
.pop-done:hover { background: var(--btn-hover); }
.pop-done:has(input:checked) { border-color: color-mix(in srgb, var(--success) 60%, transparent); background: color-mix(in srgb, var(--success) 12%, transparent); }
.pop-done input { accent-color: var(--success); }
.pop-body { font-size: 14.5px; line-height: 1.6; }
.pop-note { color: var(--fg-muted); }
.pop-sum { display: grid; gap: 10px; font-size: 16px; line-height: 1.7; }
.pop-sum > .trx-btn { justify-self: end; }
.pop-sum .tx p + p { margin-top: 10px; }
.pop-sum strong { font-weight: 600; }
/* Decisions & terms: each part under its own heading, a rule running from the heading to the edge */
.pop-sec { display: grid; gap: 10px; min-width: 0; }
.pop-sec + .pop-sec { margin-top: 14px; }
.pop-sec-h { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.pop-sec-h svg { flex: none; width: 17px; height: 17px; color: var(--c); }
.pop-sec-h::after { content: ""; flex: 1; height: 2px; border-radius: 2px; background: color-mix(in srgb, var(--c) 35%, var(--border)); }
.tips { --c: var(--attention); }
.tips .flash-title .trx-btn { margin-inline-start: auto; }
.tips li { font-size: 14px; }

/* About */
.about .dialog-body { font-size: 15px; gap: 0; }
.prose > * + * { margin-top: 10px; }
.prose h3 { font-size: 16px; margin-top: 22px; }
.prose h3:first-child { margin-top: 0; }
.prose ul { padding-inline-start: 1.4em; }
.prose li + li { margin-top: 6px; }

/* Phones, upright or sideways: pop-ups fill the screen (dvh: the area actually visible, whatever the browser bars
   do), with the notch and home bar kept clear of their head and foot, and touch-sized buttons. */
@media (max-width: 560px), (max-height: 500px) {
  .dialog { width: 100%; height: 100%; height: 100dvh; max-height: none; margin: 0; border: 0; border-radius: 0; padding: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px); }
  .dialog-head { padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
  .dialog-body { padding: 14px 16px calc(22px + env(safe-area-inset-bottom, 0px)); }
  .pop .dialog-body { padding-bottom: 18px; }
  .pop-foot { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  /* A close button that stands out from the head: full-contrast X, a visible edge */
  .dialog-close { width: 40px; height: 40px; color: var(--fg); border-color: color-mix(in srgb, var(--fg) 30%, transparent); }
  .dialog-close svg { width: 20px; height: 20px; stroke-width: 2.5; }
}
@media (max-width: 560px) {
  /* Head: the domain label and the close button share the top row; the title gets the full width under them */
  .dialog-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px 12px; padding-inline: 16px 12px; padding-bottom: 12px; }
  .dialog-titles { display: contents; }
  .dialog-titles .Label { grid-area: 1 / 1; justify-self: start; }
  .dialog-close { grid-area: 1 / 2; }
  .dialog-titles .Label + h2 { grid-area: 2 / 1 / 3 / -1; margin: 0; }
  .dialog-titles h2 { font-size: 16.5px; line-height: 1.4; }
  .pop-body { font-size: 15px; }
  .pop-sum { font-size: 15px; }
  /* Tabs: always one row sharing the width, each a full-height tap target; on the narrowest phones a tab's name
     wraps inside it rather than pushing a tab onto a second row */
  .pop-bar { padding: 8px 12px; }
  .pop-tabs { flex: 1 1 100%; flex-wrap: nowrap; gap: 6px; }
  .pop-tabs button { flex: 1 1 auto; justify-content: center; min-height: 40px; padding: 4px 8px; gap: 5px; border-radius: 20px; font-size: 13.5px; line-height: 1.25; text-align: center; }
  .pop-tabs button svg { display: none; } /* room for "Decisions & terms" and the counts */
  /* Foot: previous · done · next, the toggle taking the room left between the arrows */
  .pop-foot { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; padding-inline: 12px; }
  .pop-foot .btn { min-height: 42px; padding: 6px 12px; }
  .pop-done { justify-content: center; min-height: 42px; padding: 4px 10px; font-size: 13.5px; line-height: 1.3; text-align: center; }
  .pop-done input { flex: none; width: 18px; height: 18px; }
}

/* ---------- Practice test: the header's main action (and each task's Practice Qs step) ---------- */
.head-test { margin-inline-start: 4px; border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent); background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent); font-weight: 500; }
.head-test:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.head-test svg { color: var(--accent); }
.head-link svg.ext { width: 12px; height: 12px; opacity: .8; }
@media (max-width: 640px) {
  /* Phones: the test keeps its name, Bookmarks and About show their icons only (their titles name them) */
  .brand small { display: none; }
  .site-header .container { gap: 6px; }
  .head-link { padding: 0 8px; }
  .head-link:not(.head-test) > span, .head-link svg.ext { display: none; }
  .head-link { white-space: nowrap; }
}
/* The smallest phones: the logo stands in for the site's name, so "Practice test" stays on one line */
@media (max-width: 400px) { .brand > span:last-child { display: none; } }

/* ---------- Bookmarks: the button on each row, the count in the header, and the Bookmarks pop-up ---------- */
.row-acts { display: flex; align-items: center; gap: 6px; }
.bm-btn { display: grid; place-items: center; width: 32px; height: 26px; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--btn-bg); color: var(--fg-muted); cursor: pointer; }
.bm-btn:hover { color: var(--fg); background: var(--btn-hover); }
.bm-btn svg { width: 14px; height: 14px; }
.bm-btn[aria-pressed="true"] { color: var(--attention); border-color: color-mix(in srgb, var(--attention) 60%, transparent); }
.bm-btn[aria-pressed="true"] svg { fill: currentColor; }
.head-link { position: relative; }
.bm-count { min-width: 18px; padding: 0 5px; border-radius: 2em; background: var(--attention); color: #fff; font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; }
.bm-count[hidden] { display: none; }
@media (max-width: 640px) { .head-link .bm-count { position: absolute; top: -4px; inset-inline-end: -4px; min-width: 16px; padding: 0 4px; font-size: 10px; line-height: 16px; } }
@media (min-width: 561px) and (min-height: 501px) { .bms { width: min(860px, calc(100% - 32px)); } } /* phones: full screen, like the other pop-ups */
.bms h2 { display: flex; align-items: center; gap: 8px; }
.bm-ic { width: 18px; height: 18px; color: var(--attention); }
.bm-bar { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 16px; border-bottom: 1px solid var(--border-muted); }
/* Search: an input with its icon inside one bordered box */
.bm-search { flex: 1 1 220px; max-width: 340px; display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--fg-muted); cursor: text; }
.bm-search:focus-within { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.bm-search svg { flex: none; width: 16px; height: 16px; }
.bm-search input { flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; background: none; color: var(--fg); font: 14px var(--font); outline: none; }
.bm-foot { display: flex; justify-content: center; padding-top: 4px; }
.bm-filter button[hidden] { display: none; }
.bm-filter button[aria-pressed="true"] { color: var(--fg); border-color: color-mix(in srgb, var(--accent) 60%, transparent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.bm-list { display: grid; gap: 12px; }
.bm-h { display: flex; align-items: center; gap: 8px 10px; padding: 8px 12px; background: var(--bg-subtle); border-bottom: 1px solid var(--border-muted); }
.bm-where { flex: 1; min-width: 0; color: var(--fg-muted); font-size: 13px; }
a.bm-where:hover { color: var(--fg); text-decoration: none; }
.bm-where b { font-family: var(--mono); color: var(--c, var(--fg)); margin-inline-end: 4px; }
.bm-kind { --c: var(--accent); }
.bm-kind.k-trap { --c: var(--danger); }
.bm-kind.k-note { --c: var(--fg-muted); }
.bm-cells { display: grid; gap: 8px; padding: 12px 14px; font-size: 15px; }
.bm-c0 { font-weight: 600; }
.bm-lbl { font-size: 12px; font-weight: 600; color: var(--fg-muted); }
.bm-item:has(.k-trap) .bm-c1 .bm-lbl { color: var(--danger); }
.bm-item:has(.k-trap) .bm-c2 .bm-lbl { color: var(--success); }
.bm-item:has(.k-trap) .bm-c1 { color: var(--fg-muted); }
.bm-empty { padding: 24px; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--fg-muted); text-align: center; }
.bm-empty[hidden] { display: none; }
@media (max-width: 560px) {
  .bm-bar { padding: 8px 12px; }
  .bm-search { flex-basis: 100%; max-width: none; height: 40px; }
  .bm-search input { font-size: 16px; } /* 16px keeps iPhones from zooming in on it */
  .bm-h { flex-wrap: wrap; } .bm-where { flex-basis: 100%; order: 3; } .bm-h .row-acts { margin-inline-start: auto; }
}

/* ---------- Footer and back to top ---------- */
main { display: block; padding-bottom: 40px; }
.site-footer { border-top: 1px solid var(--border); padding-block: 20px calc(24px + env(safe-area-inset-bottom, 0px)); font-size: 13px; color: var(--fg-muted); }
.totop { position: fixed; z-index: 54; inset-inline-end: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--btn-bg); color: var(--fg); box-shadow: 0 4px 14px rgba(1, 4, 9, .18); cursor: pointer; }
.totop:hover { background: var(--btn-hover); }
.totop svg { width: 18px; height: 18px; }

@media print {
  .site-header, .site-footer, .totop, .skip, .plan-top .btn, .plan-opts, .plan-open { display: none !important; }
}
