/* BrainWeave — the parts every screen is built from. One definition of each part, here and only here.
   Screens compose these; they do not restyle them. See docs/DESIGN.md for when to use which. */

/* ───────── Icon ───────── */
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 16px; height: 16px; }
.icon.lg { width: 28px; height: 28px; stroke-width: 1.4; }

/* ───────── Button ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--hit); padding: 0 var(--s4); border-radius: var(--r);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-size: var(--fs-md); font-weight: 600; line-height: 1; white-space: nowrap; text-decoration: none; cursor: pointer;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.btn:hover { background: var(--paper-sunk); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
/* A quiet destructive button (btn(…, {kind:'danger', class:'quiet'})): where it repeats down a list (Needs you's "Delete the
   hub" on every question), it rests as plain words and its bin, and only turns red, in the look's own danger style, when
   pointed at or focused. Its words say what it does, and it always asks first (confirmDialog). Written to outrank a look's
   own danger rules at rest; a look that wants its own quiet version writes the same selector with its own name,
   :root[data-theme="NAME"] .btn.danger.quiet:not(:hover):not(:focus-visible) (its file loads later, so it wins). */
:root[data-theme] .btn.danger.quiet:not(:hover):not(:focus-visible) { background: transparent; border-color: transparent; color: var(--ink-2); box-shadow: none; }
.btn.sm { min-height: 32px; padding: 0 var(--s3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn.lg { min-height: 48px; padding: 0 var(--s6); font-size: var(--fs-lg); }
.btn.block { display: flex; width: 100%; }
.btn.icon-only { width: var(--hit); padding: 0; }
.btn.icon-only.sm { width: 32px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn[aria-busy="true"] { cursor: progress; }
@media (pointer: coarse) { .btn.sm { min-height: 40px; } .btn.icon-only.sm { width: 40px; } }

/* ───────── Form field ───────── */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
.field .hint { font-size: var(--fs-sm); color: var(--ink-3); }
.field .error { font-size: var(--fs-sm); color: var(--danger); font-weight: 600; display: flex; gap: 6px; align-items: flex-start; }
.input, .textarea, .select {
  width: 100%; min-height: var(--hit); padding: 9px var(--s3); border-radius: var(--r);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.textarea { min-height: 112px; resize: vertical; line-height: var(--lh-body); }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); opacity: 1; }
.input:hover, .textarea:hover, .select:hover { border-color: var(--ink-2); }
.input:focus-visible, .textarea:focus-visible, .select:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; box-shadow: none; border-color: var(--accent); border-radius: var(--r); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.select { appearance: none; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.search { position: relative; display: flex; align-items: center; }
.search > .icon { position: absolute; left: var(--s3); color: var(--ink-3); pointer-events: none; }
.search > .input { padding-left: 40px; }
.check { display: inline-flex; align-items: center; gap: var(--s3); min-height: var(--hit); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.switch { display: inline-flex; align-items: center; gap: var(--s3); min-height: var(--hit); cursor: pointer; }
.switch input { appearance: none; width: 40px; height: 24px; flex: none; border-radius: var(--r-full); background: var(--line-strong); position: relative; cursor: pointer; transition: background var(--fast) var(--ease); }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface-raised); transition: transform var(--fast) var(--ease); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); background: var(--on-accent); }

/* Choice cards: a radio group where each choice explains itself. */
.choices { display: grid; gap: var(--s3); }
.choice { position: relative; display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s4); border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); cursor: pointer; }
.choice:hover { border-color: var(--ink-2); }
.choice input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.choice:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.choice .choice-title { font-weight: 650; display: block; }
.choice .choice-text { color: var(--ink-2); font-size: var(--fs-sm); display: block; margin-top: 2px; }

/* ───────── Page frame ───────── */
.page { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--s10) var(--s8) var(--s20); display: flex; flex-direction: column; gap: var(--s8); }
.page.narrow { max-width: calc(var(--read-max) + var(--s16)); }
.page.form { max-width: calc(var(--form-max) + var(--s16)); }
.page-head { display: flex; flex-direction: column; gap: var(--s3); }
/* The title and its action share one line and never wrap apart, so the action cannot drop between the title and the bar under it. */
.page-head .top { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); }
.page-head .top > h1 { flex: 1 1 auto; min-width: 0; }
.page-head h1:focus-visible { outline-offset: 6px; }
.page-head .lede { font-size: var(--fs-lg); color: var(--ink-2); max-width: 62ch; }
.page-head .actions { display: flex; gap: var(--s2); flex-wrap: wrap; justify-content: flex-end; flex: none; max-width: 60%; }
.thread { height: 3px; border: 0; margin: 0; border-radius: 2px; background:
  repeating-linear-gradient(90deg, var(--accent) 0 14px, transparent 14px 20px),
  linear-gradient(var(--madder), var(--madder)); background-size: auto, 100% 1px; background-position: 0 0, 0 2px; background-repeat: repeat-x, no-repeat; opacity: .9; width: 64px; }
.section { display: flex; flex-direction: column; gap: var(--s4); min-width: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s4); }
.section-head .more { font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--ink-3); }
.crumbs a { color: var(--ink-2); text-decoration: none; font-weight: 600; padding: 11px 0; margin: -7px 0; }
.crumbs a:hover { color: var(--accent); text-decoration: underline; }
.crumbs .sep { color: var(--ink-3); }
/* In a page head the trail is the way back. Its last step is this very page, and the title right under it already says so,
   so that step (and the slash before it) is left out at every width. */
.page-head .crumbs > .to-here { display: none; }
.toolbar { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.toolbar .search { flex: 1 1 240px; max-width: 420px; }
/* A line of small facts with a dot between each two (seps() in ui.js). Each dot sits in the room before its fact; the line
   is moved left by that room and cut back to its own edge, so the dot of a fact that starts a line falls outside and is
   not drawn. No line of facts starts or ends with a dot. */
.seps { display: flex; flex-wrap: wrap; align-items: baseline; margin-left: -1.1em; clip-path: inset(0 0 0 1.1em); }
.seps > * { position: relative; padding-left: 1.1em; min-width: 0; overflow-wrap: anywhere; }
.seps > *::before { content: "·"; position: absolute; left: .42em; color: var(--ink-3); }

/* ───────── Card and panel ───────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s5); display: flex; flex-direction: column; gap: var(--s3); min-width: 0; }
a.card, button.card { text-decoration: none; color: inherit; text-align: left; cursor: pointer; transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease), transform var(--fast) var(--ease); }
a.card:hover, button.card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-1); color: inherit; }
a.card:focus-visible, button.card:focus-visible { border-radius: var(--r-lg); }
.card.sunk { background: var(--paper-sunk); border-color: transparent; }
.card.accent { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); background: var(--accent-soft); }
.grid { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.split { display: grid; gap: var(--s8); grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
@media (max-width: 1023px) { .split { grid-template-columns: minmax(0, 1fr); } }

/* ───────── List ───────── */
.list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.list.plain { border: 0; border-radius: 0; background: transparent; }
.list-row { display: flex; align-items: center; gap: var(--s4); padding: var(--s3) var(--s4); min-height: 56px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; text-align: left; width: 100%; min-width: 0; }
.list-row:first-child { border-top: 0; }
a.list-row:hover, button.list-row:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); color: inherit; }
a.list-row:focus-visible, button.list-row:focus-visible { outline-offset: -2px; box-shadow: none; border-radius: var(--r); }
.list-row .lead { flex: none; color: var(--ink-3); display: grid; place-items: center; }
.list-row .body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.list-row .title { font-weight: 600; color: var(--ink); }
.list-row .sub { font-size: var(--fs-sm); color: var(--ink-3); }
.list-row .meta { flex: none; display: flex; align-items: center; gap: var(--s3); font-size: var(--fs-sm); color: var(--ink-3); }
.list-row .chev { color: var(--ink-3); flex: none; }
/* On a phone a row's pill or small facts sit under its words, so the words get the whole width. */
@media (max-width: 719px) {
  .list-row .meta .hide-sm { display: none; }
  .list-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 0; }
  .list-row > .lead { grid-column: 1; grid-row: 1 / span 2; margin-right: var(--s3); }
  .list-row > .body { grid-column: 2; grid-row: 1; }
  .list-row > .meta { grid-column: 2; grid-row: 2; justify-self: start; flex-wrap: wrap; margin-top: var(--s1); max-width: 100%; }
  .list-row > .chev { grid-column: 3; grid-row: 1 / span 2; margin-left: var(--s3); }
}

/* ───────── Book cover (cloth-bound, drawn when a book has no picture) ───────── */
.cover { position: relative; aspect-ratio: 2 / 3; width: 100%; border-radius: 3px 6px 6px 3px; overflow: hidden; background: var(--cloth, var(--cloth-1)); color: #FFF8EA; box-shadow: var(--shadow-1), inset 5px 0 0 rgba(0, 0, 0, .18), inset 6px 0 0 rgba(255, 255, 255, .08); display: flex; flex-direction: column; justify-content: space-between; padding: 14% 10% 10% 16%; }
.cover::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(0deg, rgba(255, 255, 255, .035) 0 1px, transparent 1px 3px), repeating-linear-gradient(90deg, rgba(0, 0, 0, .05) 0 1px, transparent 1px 3px); pointer-events: none; }
.cover .cover-title { font-family: var(--font-read); font-weight: 500; line-height: 1.12; font-size: clamp(.8rem, 9cqw, 1.25rem); font-variation-settings: "opsz" 24; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; }
.cover .cover-author { font-size: clamp(.6rem, 5.5cqw, .8rem); letter-spacing: .06em; text-transform: uppercase; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.cover-wrap { container-type: inline-size; width: 100%; }
.cover.c1 { --cloth: var(--cloth-1); } .cover.c2 { --cloth: var(--cloth-2); } .cover.c3 { --cloth: var(--cloth-3); }
.cover.c4 { --cloth: var(--cloth-4); } .cover.c5 { --cloth: var(--cloth-5); } .cover.c6 { --cloth: var(--cloth-6); }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: var(--s8) var(--s6); }
.shelf-item { display: flex; flex-direction: column; gap: var(--s3); text-decoration: none; color: inherit; min-width: 0; }
.shelf-item:hover .cover { transform: translateY(-3px); box-shadow: var(--shadow-2), inset 5px 0 0 rgba(0, 0, 0, .18); }
.shelf-item .cover { transition: transform var(--slow) var(--ease), box-shadow var(--slow) var(--ease); }
.shelf-item .title { font-family: var(--font-read); font-size: var(--fs-lg); font-weight: 550; line-height: var(--lh-snug); }
.shelf-item .sub { font-size: var(--fs-sm); color: var(--ink-3); }
@media (max-width: 719px) { .shelf { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: var(--s6) var(--s4); } }

/* ───────── Chip, badge, level ───────── */
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 10px; border-radius: var(--r-full); border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-size: var(--fs-sm); font-weight: 550; text-decoration: none; white-space: nowrap; max-width: 100%; }
a.chip:hover, button.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"], .chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.badge { display: inline-flex; align-items: center; gap: 5px; min-height: 22px; padding: 0 8px; border-radius: var(--r-full); font-size: var(--fs-xs); font-weight: 650; background: var(--paper-sunk); color: var(--ink-2); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent-strong); }
.badge.madder { background: var(--madder-soft); color: var(--madder); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
/* Link level: how much a note says about a topic, drawn as five stitches. Always paired with its name in words. */
.level { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.level .stitches { display: inline-flex; gap: 2px; }
.level .stitches i { width: 4px; height: 14px; border-radius: 2px; background: var(--line-strong); opacity: .45; }
.level[data-level="5"] .stitches i, .level[data-level="4"] .stitches i:nth-child(-n+4), .level[data-level="3"] .stitches i:nth-child(-n+3), .level[data-level="2"] .stitches i:nth-child(-n+2), .level[data-level="1"] .stitches i:nth-child(-n+1) { background: var(--madder); opacity: 1; }

/* ───────── Tabs and segmented control ───────── */
.tabs { display: flex; gap: var(--s5); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; min-height: var(--hit); padding: 0 2px; font-weight: 600; color: var(--ink-3); white-space: nowrap; display: inline-flex; align-items: center; gap: var(--s2); text-decoration: none; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"], .tab[aria-current="page"] { color: var(--ink); }
.tab[aria-selected="true"]::after, .tab[aria-current="page"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px 2px 0 0; }
.tab:focus-visible { outline-offset: -2px; box-shadow: none; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r); background: var(--paper-sunk); border: 1px solid var(--line); }
.segmented button { min-height: 32px; padding: 0 var(--s3); border-radius: 7px; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.segmented button[aria-pressed="true"] { background: var(--surface-raised); color: var(--ink); box-shadow: var(--shadow-1); }
@media (pointer: coarse) { .segmented button { min-height: 40px; } }

/* ───────── States: empty, error, loading ───────── */
.state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s3); padding: var(--s12) var(--s6); border: 1px dashed var(--line-strong); border-radius: var(--r-lg); background: color-mix(in srgb, var(--surface) 60%, transparent); }
.state .state-art { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-strong); margin-bottom: var(--s2); }
.state.error .state-art { background: var(--danger-soft); color: var(--danger); }
.state h2 { font-size: var(--fs-xl); }
.state p { color: var(--ink-2); max-width: 46ch; }
.state .actions { display: flex; gap: var(--s2); flex-wrap: wrap; justify-content: center; margin-top: var(--s2); }
.state.compact { padding: var(--s6) var(--s5); }
/* Loading bars take two tokens a look may set, on :root or per place: --skel (the bar) and --skel-shine (the light that
   runs across it). Left unset they come from the page's own sunk and surface colours. */
.skel { display: block; border-radius: var(--r-sm); background: linear-gradient(90deg, var(--skel, var(--paper-sunk)) 25%, var(--skel-shine, color-mix(in srgb, var(--paper-sunk) 55%, var(--surface))) 45%, var(--skel, var(--paper-sunk)) 65%); background-size: 300% 100%; animation: skel 1.4s linear infinite; min-height: 14px; }
.skel.line { height: 14px; } .skel.title { height: 34px; width: min(60%, 420px); } .skel.block { height: 120px; border-radius: var(--r-lg); } .skel.row { height: 56px; border-radius: var(--r); } .skel.cover { aspect-ratio: 2 / 3; height: auto; }
/* A loading page head (skeletonHead() in ui.js) has the real head's parts: a bar for the label, the title, the action. */
.skel.action { flex: none; width: 148px; height: var(--hit); border-radius: var(--r); }
.skel.eyebrow-bar { height: 12px; min-height: 12px; }
.skel-head .top > .skel.title { flex: 0 1 auto; }
@keyframes skel { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor; animation: spin .7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 6px; border-radius: var(--r-full); background: var(--paper-sunk); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width var(--slow) var(--ease); }

/* ───────── Banner ───────── */
.banner { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r); background: var(--accent-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }
.banner .icon { color: var(--accent-strong); margin-top: 1px; }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); } .banner.warn .icon { color: var(--warn); }
.banner.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); } .banner.danger .icon { color: var(--danger); }
.banner.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); } .banner.ok .icon { color: var(--ok); }
.banner .grow { min-width: 0; }

/* ───────── Dialog and side sheet ───────── */
dialog.dialog { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface-raised); color: var(--ink); padding: 0; width: min(560px, calc(100vw - 32px)); max-height: min(86dvh, 760px); box-shadow: var(--shadow-2); overflow: hidden; }
dialog.dialog.wide { width: min(760px, calc(100vw - 32px)); }
dialog.dialog[open] { display: flex; flex-direction: column; animation: pop var(--slow) var(--ease); }
dialog.dialog::backdrop { background: var(--scrim); }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); padding: var(--s5) var(--s6) var(--s3); }
.dialog-head h2 { font-size: var(--fs-xl); }
.dialog-body { padding: var(--s2) var(--s6) var(--s5); overflow: auto; display: flex; flex-direction: column; gap: var(--s4); }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s4) var(--s6); border-top: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
dialog.sheet { border: 0; border-left: 1px solid var(--line); margin: 0 0 0 auto; height: 100dvh; max-height: none; width: min(440px, 100vw); background: var(--surface-raised); color: var(--ink); padding: 0; box-shadow: var(--shadow-2); }
dialog.sheet[open] { display: flex; flex-direction: column; animation: slide var(--slow) var(--ease); }
dialog.sheet::backdrop { background: var(--scrim); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
@media (max-width: 719px) {
  dialog.dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92dvh; }
  .dialog-head { padding: var(--s5) var(--s4) var(--s3); } .dialog-body { padding: var(--s2) var(--s4) var(--s5); } .dialog-foot { padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom)); }
  .dialog-foot .btn { flex: 1 1 auto; }
}

/* ───────── Menu ───────── */
.menu { position: absolute; z-index: var(--z-pop); min-width: 220px; max-width: min(320px, calc(100vw - 16px)); padding: 6px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-raised); box-shadow: var(--shadow-2); animation: pop var(--fast) var(--ease); }
.menu-item { display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 38px; padding: 0 var(--s3); border-radius: var(--r-sm); font-weight: 550; color: var(--ink); text-decoration: none; text-align: left; }
.menu-item:hover, .menu-item:focus-visible { background: var(--accent-soft); color: var(--accent-strong); outline: none; box-shadow: none; }
.menu-item.danger { color: var(--danger); }
.menu-item .hint { margin-left: auto; color: var(--ink-3); font-size: var(--fs-xs); font-weight: 500; }
.menu-sep { height: 1px; background: var(--line); margin: 6px; }
.menu-label { padding: 6px var(--s3) 2px; font-size: var(--fs-xs); color: var(--ink-3); font-weight: 600; }
@media (pointer: coarse) { .menu-item { min-height: 44px; } }

/* ───────── Toast ───────── */
/* The host is a popover (toast() in ui.js), so it sits in the browser's top layer, above an open dialog, sheet or menu and
   their dimmed backdrop. The popover's own browser styles are undone here: no box, no inset, no centring. */
.toasts { position: fixed; z-index: var(--z-toast); inset: auto auto calc(var(--s6) + env(safe-area-inset-bottom)) 50%; margin: 0; padding: 0; border: 0; background: transparent; color: inherit; overflow: visible; height: auto; transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--s2); align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toasts[popover]:not(:popover-open) { display: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r); background: var(--ink); color: var(--paper); box-shadow: var(--shadow-2); font-weight: 550; animation: pop var(--slow) var(--ease); max-width: 100%; }
.toast .btn { min-height: 30px; border-color: color-mix(in srgb, var(--paper) 40%, transparent); background: transparent; color: var(--paper); }
.toast.danger { background: var(--danger); color: #fff; }
:root[data-theme="midnight"] .toast.danger { color: #1a0c0a; }
@media (max-width: 1023px) { .toasts { bottom: calc(var(--tabbar-h) + var(--s4) + env(safe-area-inset-bottom)); } }
/* While a dialog is open on a phone it rises from the foot of the screen, so a toast moves to the top, over the dimmed
   page, and never covers the dialog's buttons. (placeToasts() in ui.js places them exactly while any dialog or side sheet
   is open, at every width, and says where on data-spot: below, above, beside or under-head; this is the fallback.) */
@media (max-width: 719px) { .toasts[data-over="dialog"] { top: calc(var(--s3) + env(safe-area-inset-top)); bottom: auto; } }

/* ───────── Avatar, stat, steps, checklist ───────── */
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--madder); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: var(--fs-sm); flex: none; letter-spacing: .02em; }
:root[data-theme="midnight"] .avatar { color: #23100b; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .n { font-family: var(--font-read); font-size: var(--fs-2xl); font-weight: 500; line-height: 1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: var(--fs-sm); color: var(--ink-3); }
.stats { display: flex; gap: var(--s8); flex-wrap: wrap; }
.steps { display: flex; gap: 6px; align-items: center; }
.steps i { height: 4px; flex: 1 1 0; border-radius: 2px; background: var(--line); }
.steps i.done { background: var(--accent); }
.steps i.now { background: var(--madder); }
.checklist { display: flex; flex-direction: column; }
.checklist .item { display: flex; align-items: center; gap: var(--s4); padding: var(--s4) 0; border-top: 1px solid var(--line); }
.checklist .item:first-child { border-top: 0; }
.checklist .tick { width: 28px; height: 28px; flex: none; border-radius: 50%; border: 1.5px solid var(--line-strong); display: grid; place-items: center; color: transparent; font-weight: 700; font-size: var(--fs-sm); }
.checklist .item.todo .tick { color: var(--ink-2); }
.checklist .item.done .tick { background: var(--ok); border-color: var(--ok); color: var(--paper); }
.checklist .item.done .title { color: var(--ink-3); text-decoration: line-through; }
.checklist .title { font-weight: 650; }
.checklist .sub { font-size: var(--fs-sm); color: var(--ink-3); }

/* ───────── Prose: the author's text and anything written at length ───────── */
.prose { font-family: var(--font-read); font-size: var(--fs-read); line-height: var(--lh-read); font-variation-settings: "opsz" 18; max-width: var(--read-max); overflow-wrap: break-word; }
.prose > * + * { margin-top: 1em; }
.prose h1, .prose h2, .prose h3 { margin-top: 1.6em; }
.prose h2 { font-size: 1.4em; } .prose h3 { font-size: 1.15em; }
.prose ul, .prose ol { padding-left: 1.3em; } .prose ul { list-style: disc; } .prose ol { list-style: decimal; }
.prose li + li { margin-top: .35em; }
.prose blockquote { border-left: 3px solid var(--madder); padding: .1em 0 .1em 1em; color: var(--ink-2); font-style: italic; }
.prose img { border-radius: var(--r); margin-inline: auto; height: auto; }
.prose table { font-family: var(--font-ui); font-size: var(--fs-sm); display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.prose a { color: var(--accent); }
.synopsis { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: var(--s4) var(--s5); border-radius: 0 var(--r) var(--r) 0; font-family: var(--font-ui); font-size: var(--fs-md); line-height: var(--lh-body); color: var(--ink); }
.synopsis .eyebrow { color: var(--accent-strong); display: block; margin-bottom: 4px; }

/* ───────── Table (for dense lists that really are tables) ───────── */
.table th { text-align: left; font-size: var(--fs-xs); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); font-weight: 650; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); }
.table td { padding: var(--s3); border-bottom: 1px solid var(--line); vertical-align: top; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }

@media (max-width: 719px) {
  /* A phone's first screen belongs to the page's first real item, so the page head is compact: small gaps inside it, a
     lede of two lines at most, and the blocks of the page closer together. A look keeps its own head padding small here. */
  .page { padding: var(--s3) var(--s4) var(--s16); gap: var(--s3); }
  .page-head { gap: var(--s2); }
  .page-head .lede { font-size: var(--fs-md); line-height: var(--lh-snug); display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
  .page-head .lede:has(> .seps) { display: block; }
  .page-head .lede .lede-more { display: none; }   /* the rest of a lede, for wider screens (ledeMore() in ui.js) */
  .card { padding: var(--s4); }
  /* Summary numbers: one tight row, each number with its word beside it. */
  .stats { gap: var(--s2) var(--s5); }
  .stats > .stat { flex-direction: row; align-items: baseline; gap: 6px; }
  /* A narrow page head reads top to bottom: the way back, the title, the bar under it, the line about it, then the action. */
  .page-head .top { display: contents; }
  .page-head .actions { order: 9; width: 100%; max-width: none; justify-content: flex-start; } .page-head .actions .btn { flex: 1 1 auto; }
}
/* A tablet's page head is about 630px wide beside the icon rail, and a small window's is about 720px beside the full side bar.
   Either is too narrow for a long title and its action side by side, so the head reads top to bottom as a phone's does: the
   title has the whole line to itself and the action comes last, at its own width. */
@media (min-width: 720px) and (max-width: 1199px) {
  .page-head .top { display: contents; }
  .page-head .actions { order: 9; max-width: none; justify-content: flex-start; align-self: flex-start; }
}
