:root {
  --paper: #f6f3ec; --card: #ffffff; --ink: #1f2a2e; --muted: #5d686c; --line: #ddd6c9;
  --accent: #a8431f; --accent-ink: #fff; --soft: #efe9de; --ok: #2f6b4f; --warn: #a35a00; --danger: #b3261e;
  --info: #1f4e79; --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 10px rgba(0,0,0,.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14191b; --card: #1c2326; --ink: #e8e4dc; --muted: #9aa5a8; --line: #2e383b; --soft: #232b2e;
    --accent: #e0774f; --accent-ink: #14191b; --ok: #6fbf95; --warn: #e3a34a; --danger: #ef7a72; --info: #7fb2e5;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #14191b; --card: #1c2326; --ink: #e8e4dc; --muted: #9aa5a8; --line: #2e383b; --soft: #232b2e;
  --accent: #e0774f; --accent-ink: #14191b; --ok: #6fbf95; --warn: #e3a34a; --danger: #ef7a72; --info: #7fb2e5;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 17px/1.6 var(--font); }
p { margin: 0 0 .9em; }
a { color: var(--accent); }
img { max-width: 100%; }
h1, h2, h3, h4, h5 { line-height: 1.22; letter-spacing: -.01em; margin: 1.4em 0 .45em; color: var(--ink); text-wrap: balance; }
h1 { font-size: 1.85rem; letter-spacing: -.02em; } h2 { font-size: 1.4rem; } h3 { font-size: 1.14rem; } h4 { font-size: 1rem; }
button, .btn { font: inherit; cursor: pointer; border: 0; border-radius: 999px; padding: .62em 1.15em;
  background: var(--accent); color: var(--accent-ink); font-weight: 650; text-decoration: none; display: inline-flex;
  align-items: center; gap: .45em; min-height: 44px; }
.btn.ghost, button.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.small, button.small { padding: .35em .85em; min-height: 36px; font-size: .92rem; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1.5px solid var(--line);
  border-radius: 10px; padding: .55em .7em; width: 100%; }
textarea { min-height: 5em; }
label { font-weight: 600; font-size: .93rem; display: block; margin: .8em 0 .25em; }
.muted { color: var(--muted); }
.small:not(.btn):not(button) { font-size: .88rem; color: var(--muted); }

/* ---------- app shell ---------- */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top-in { max-width: 860px; margin: 0 auto; padding: .55rem 16px; display: flex; align-items: center; gap: .6rem; min-height: 56px; }
.top .back { background: none; color: var(--ink); padding: .3em .5em; min-height: 40px; font-size: 1.3rem; }
.top .title { font-weight: 750; font-size: 1.05rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .sos { background: var(--danger); color: #fff; padding: .35em .9em; min-height: 38px; font-size: .95rem; }
main { max-width: 860px; margin: 0 auto; padding: 8px 16px 110px; overflow-wrap: break-word; }
main a[href^="http"], main code { overflow-wrap: anywhere; }
.grid > *, .cards > *, .side > *, .imgrow > *, .kit-row > *, .row .t, .callrow .t { min-width: 0; }
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--card);
  border-top: 1px solid var(--line); display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); }
nav.tabs a { flex: 1; max-width: 140px; text-align: center; padding: .45em 0 .5em; color: var(--muted); text-decoration: none;
  font-size: .74rem; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 2px; }
nav.tabs a svg { width: 24px; height: 24px; }
nav.tabs a.on { color: var(--accent); }
.ico { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- tiles & lists ---------- */
.hello { margin: 1.2rem 0 1rem; }
.hello h1 { margin: 0 0 .2em; font-size: 1.6rem; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; color: var(--ink);
  text-decoration: none; display: flex; flex-direction: column; gap: 6px; min-height: 112px; box-shadow: var(--shadow); }
.tile .ico { width: 28px; height: 28px; color: var(--accent); }
.tile b { font-size: 1rem; } .tile span { font-size: .84rem; color: var(--muted); line-height: 1.35; }
.tile.urgent { background: var(--danger); border-color: var(--danger); color: #fff; }
.tile.urgent .ico, .tile.urgent span { color: #fff; }
.list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.row { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex;
  gap: 12px; align-items: center; text-decoration: none; color: var(--ink); }
.row .num { width: 40px; height: 40px; border-radius: 10px; color: #fff; font-weight: 750; display: grid; place-items: center; flex: none; }
.row .t { flex: 1; min-width: 0; } .row .t b { display: block; } .row .t span { font-size: .86rem; color: var(--muted); }
.row .go { color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: .5rem 0 1rem; }
.chip { border: 1.5px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: .3em .8em;
  font-size: .88rem; text-decoration: none; min-height: 36px; display: inline-flex; align-items: center; font-weight: 600; }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.panel h3:first-child, .panel h2:first-child { margin-top: 0; }
.item { padding: 12px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item .meta { display: flex; gap: 6px; flex-wrap: wrap; margin: .35em 0; }
.tag { font-size: .74rem; font-weight: 650; background: var(--soft); color: var(--muted); border-radius: 6px; padding: .15em .5em; }
.search { position: relative; margin: .4rem 0 1rem; }
.search input { padding-left: 2.4em; border-radius: 999px; }
.search .ico { position: absolute; left: .8em; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; }

/* ---------- reader ---------- */
.volhead { border-radius: var(--radius); color: #fff; padding: 20px 18px; margin: 12px 0 8px; }
.volhead small { opacity: .85; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; font-size: .75rem; }
.volhead h1 { margin: .15em 0 .2em; color: #fff; }
.volhead p { margin: 0; opacity: .92; }
.volhead .acts { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.volhead .btn { background: rgba(255,255,255,.18); color: #fff; }
details.toc { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px; margin: 10px 0 18px; }
details.toc summary { cursor: pointer; font-weight: 650; padding: .55em 0; min-height: 40px; }
details.toc ol { margin: 0 0 .7em; padding-left: 1.2em; } details.toc li { margin: .3em 0; }
/* Reading column: editorial rhythm, ~70ch prose, volume colour as an accent only. */
.doc { --vca: var(--vc, var(--accent)); }
.doc > :where(p, ul, ol, h2, h3, h4, h5, aside, .side) { max-width: 70ch; }
.doc h2 { color: var(--ink); font-size: 1.42rem; margin: 2.4em 0 .6em; padding-top: .9em; border-top: 1px solid var(--line); position: relative; scroll-margin-top: 70px; }
.doc h2::before { content: ""; position: absolute; top: -2px; left: 0; width: 56px; height: 4px; border-radius: 2px; background: var(--vca); }
.doc > h2:first-child { margin-top: 1.2em; }
.doc h3 { margin: 1.8em 0 .45em; } .doc h4 { margin: 1.4em 0 .35em; font-size: .98rem; }
.doc h2 + h3, .doc h3 + h4 { margin-top: .6em; }
.doc ul, .doc ol { padding-left: 1.3em; margin: .3em 0 1.1em; } .doc li { margin: .3em 0; }
.doc li::marker { color: var(--muted); }
ol.steps { list-style: none; counter-reset: s; padding: 0; margin-left: 0; }
ol.steps > li { counter-increment: s; position: relative; padding-left: 2.4em; margin: .6em 0; }
ol.steps > li::before { content: counter(s); position: absolute; left: 0; top: .1em; width: 1.7em; height: 1.7em; border-radius: 50%;
  background: var(--vca, var(--accent)); color: #fff; font-weight: 700; font-size: .82em; display: grid; place-items: center; }
ul.check { list-style: none; padding: 0; margin-left: 0; } ul.check > li { padding-left: 1.8em; position: relative; }
ul.check > li::before { content: ""; position: absolute; left: 0; top: .3em; width: 1em; height: 1em; border: 2px solid var(--muted); border-radius: 4px; }
.doc ul.kv { list-style: none; padding: 0; columns: 2; column-gap: 2em; } .doc ul.kv li { break-inside: avoid; border-bottom: 1px dotted var(--line); padding: .3em 0; }
@media (max-width: 480px) { .doc ul.kv { columns: 1; } .tbl th, .tbl td { min-width: 5.5em; } }
.tbl { overflow-x: auto; margin: 1.3em 0; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.tbl table { border-collapse: collapse; width: 100%; font-size: .92rem; line-height: 1.45; }
.tbl th { background: var(--soft); color: var(--ink); text-align: left; font-weight: 700; font-size: .86rem; letter-spacing: .01em; }
.tbl th, .tbl td { padding: .6em .75em; border-top: 1px solid var(--line); vertical-align: top; min-width: 7em; }
.tbl tr:first-child th, .tbl tr:first-child td { border-top: 0; }
aside.callout { --cc: var(--info); border-left: 4px solid var(--cc); background: color-mix(in srgb, var(--cc) 7%, var(--card));
  border-radius: 0 12px 12px 0; padding: .85em 1.1em; margin: 1.5em 0; }
aside.callout strong:first-child { display: block; margin-bottom: .3em; }
aside.callout p { margin: 0 0 .5em; } aside.callout > :last-child { margin-bottom: 0; }
aside.callout ul, aside.callout ol { margin: .2em 0 0; padding-left: 1.2em; }
aside.callout.warn { --cc: var(--warn); } aside.callout.danger { --cc: var(--danger); } aside.callout.ok, aside.callout.tip { --cc: var(--ok); }
figure { margin: 1.6em auto; text-align: center; }
figure img { border-radius: 10px; background: #fff; }
figure.one img { max-height: 340px; width: auto; }
figcaption, .caption { font-size: .86rem; color: var(--muted); margin-top: .55em; text-align: center; line-height: 1.4; }
/* Diagrams are drawn on white: keep a light card, centred, caption outside it. */
figure.vec { max-width: 720px; }
figure.vec svg { display: block; width: 100%; height: auto; box-sizing: border-box; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; }
.imgrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.imgrow figure { margin: .4em 0; } .imgrow img { aspect-ratio: 1; object-fit: contain; width: 100%; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 10px; margin: 1em 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.card img { width: 100%; aspect-ratio: 4/3; object-fit: contain; background: #fff; border-radius: 8px; }
.card h5 { margin: .5em 0 .2em; font-size: .98rem; } .card p { margin: 0; font-size: .88rem; }
.side { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; margin: 1.4em 0; }
.side > img { max-height: 260px; width: auto; margin: 0 auto; border-radius: 10px; background: #fff; }
@media (min-width: 640px) { .side { grid-template-columns: 34% 1fr; } .side > img { max-height: none; width: 100%; } }
.side > div > :first-child { margin-top: 0; }
.pager { display: flex; justify-content: space-between; gap: 10px; margin: 2.5em 0 1em; }
.pager a { flex: 1; } .pager a:last-child { text-align: right; justify-content: flex-end; }
mark { background: #ffe58a; color: #222; border-radius: 3px; }

/* ---------- pdf viewer ---------- */
.pdfbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0; }
.pdfpages { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.pdfpages canvas { width: 100%; max-width: 820px; height: auto; background: #fff; box-shadow: var(--shadow); border-radius: 4px; }
.pdfpages .ph { width: 100%; max-width: 820px; aspect-ratio: 210/297; background: var(--soft); border-radius: 4px; }

/* ---------- tools ---------- */
.big-num { font-size: 2.4rem; font-weight: 800; letter-spacing: -.02em; margin: .1em 0; }
.callrow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.callrow:first-child { border-top: 0; }
.callrow .t { flex: 1; } .callrow .t span { display: block; font-size: .86rem; color: var(--muted); }
.flash { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 40px; }
.flash.on { background: #fff; }
.flash button { background: #444; color: #fff; }
.compass { width: 240px; height: 240px; margin: 1rem auto; position: relative; }
.compass .dial { width: 100%; height: 100%; transition: transform .15s linear; }
.breath { width: 220px; height: 220px; margin: 1.2rem auto; border-radius: 50%; background: color-mix(in srgb, var(--ok) 25%, transparent);
  border: 3px solid var(--ok); display: grid; place-items: center; font-weight: 700; font-size: 1.2rem; transform: scale(.6);
  transition: transform 4s ease-in-out; text-align: center; }
.timer { text-align: center; }
.timer img { max-height: 220px; background: #fff; border-radius: 12px; }
.timer .count { font-size: 3.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--soft); border-radius: 99px; overflow: hidden; } .bar i { display: block; height: 100%; background: var(--accent); width: 0; }
.kit-row { display: grid; grid-template-columns: 1fr 9.5em 40px; gap: 6px; align-items: center; margin: 6px 0; }
.kit-row.due input[type=date] { border-color: var(--warn); } .kit-row.over input[type=date] { border-color: var(--danger); }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--paper);
  padding: .6em 1.1em; border-radius: 999px; z-index: 200; font-weight: 600; font-size: .92rem; }
.offline-pill { font-size: .72rem; font-weight: 700; background: var(--warn); color: #fff; border-radius: 99px; padding: .2em .6em; }
@media print { nav.tabs, .top, .noprint { display: none !important; } main { padding: 0; } body { background: #fff; } }

/* ---------- library cards, packages, modal ---------- */
.libcard .desc { font-size: .92rem; margin: .2em 0 .3em; }
.libcard .req { margin-bottom: .2em; }
.libcard .acts { margin: .5em 0 0; }
.thanks { border-color: var(--ok); } .thanks .ico { color: var(--ok); width: 28px; height: 28px; }
.pkg-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; justify-content: space-between; }
.pkg-head h3 { margin: 0; }
.tag.big { font-size: .85rem; background: var(--ink); color: var(--paper); padding: .25em .7em; }
ul.check .tag { margin-left: .2em; }
.devcards .card h5 { margin-top: 0; }
.devcards .card p { margin: .3em 0 0; }
dialog.modal { width: min(640px, calc(100% - 24px)); max-height: min(88vh, 900px); max-height: min(88dvh, 900px); padding: 0; border: 1px solid var(--line);
  border-radius: 18px; background: var(--paper); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); overflow-y: auto; overscroll-behavior: contain; overflow-wrap: break-word; }
dialog.modal::backdrop { background: rgba(15, 20, 22, .55); }
.modal-in { padding: 4px 18px 18px; }
.modal-head { position: sticky; top: 0; z-index: 1; display: flex; gap: 10px; align-items: center; justify-content: space-between;
  background: var(--paper); padding: 14px 0 8px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 1.25rem; }
.modal-head button { flex: none; min-width: 40px; justify-content: center; }
.modal h3 { font-size: 1.05rem; margin: 1.2em 0 .4em; }
.modal .tbl th { width: 38%; }
html.modal-open { overflow: hidden; }

/* ---------- dark-mode refinements ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .doc { --vca: color-mix(in srgb, var(--vc, var(--accent)) 55%, #fff); }
  :root:not([data-theme="light"]) figure img, :root:not([data-theme="light"]) figure.vec svg, :root:not([data-theme="light"]) .card img { filter: brightness(.93); border-color: transparent; }
}
:root[data-theme="dark"] .doc { --vca: color-mix(in srgb, var(--vc, var(--accent)) 55%, #fff); }
:root[data-theme="dark"] figure img, :root[data-theme="dark"] figure.vec svg, :root[data-theme="dark"] .card img { filter: brightness(.93); border-color: transparent; }

/* ---------- volume thumbnails ---------- */
.vthumb { position: relative; flex: none; width: 56px; height: 56px; }
.vthumb img { width: 56px; height: 56px; object-fit: contain; background: #fff; border-radius: 12px; border: 1px solid var(--line); padding: 4px; box-sizing: border-box; display: block; }
.vthumb .num { position: absolute; right: -6px; bottom: -6px; width: 26px; height: 26px; border-radius: 8px; font-size: .74rem; border: 2px solid var(--card); }
.volhead.has-thumb { display: grid; grid-template-columns: 1fr auto; column-gap: 14px; }
.volhead.has-thumb > :not(.vh-thumb) { grid-column: 1; }
.vh-thumb { grid-column: 2; grid-row: 1 / span 3; align-self: start; width: 84px; height: 84px; object-fit: contain; background: #fff; border-radius: 14px; padding: 6px; box-sizing: border-box; }
@media (min-width: 640px) { .vh-thumb { width: 120px; height: 120px; } }
.volhead .acts { grid-column: 1 / -1 !important; }
.tag { white-space: nowrap; }
.row .acts { display: flex; gap: 6px; flex: none; }
@media (max-width: 520px) {
  .row.pdfrow { flex-wrap: wrap; row-gap: 8px; }
  .row.pdfrow .t { flex: 1 1 calc(100% - 70px); }
  .row.pdfrow .acts { margin-left: 68px; }
}
.panel > :last-child { margin-bottom: 0; }
