/* Layout: a single reading column (~66ch) under floating, self-hiding controls; lists are stacked rows, not cards. */
@font-face { font-family: "Literata"; src: url("fonts/literata.woff2") format("woff2"); font-weight: 200 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Literata"; src: url("fonts/literata-italic.woff2") format("woff2"); font-weight: 200 900; font-style: italic; font-display: swap; }
@font-face { font-family: "Schibsted Grotesk"; src: url("fonts/schibsted.woff2") format("woff2"); font-weight: 400 900; font-style: normal; font-display: swap; }

:root {
  --paper: #f4f6f3;
  --sheet: #ffffff;
  --ink: #1b2826;
  --ink-soft: #4d5d59;
  --rule: #d9e0dc;
  --spruce: #17322e;
  --brass: #9a6b16;
  --brass-soft: #f3e6c8;
  --part-handbook: #1f5a50;
  --part-lite: #5b7a3c;
  --part-training: #9a6b16;
  --part-icf: #3b5a85;
  --bar: rgba(255,255,255,0.92);
  --shadow: 0 6px 24px rgba(23,50,46,0.16);
  --f-read: "Literata", Georgia, "Times New Roman", serif;
  --f-ui: "Schibsted Grotesk", -apple-system, "Segoe UI", Roboto, sans-serif;
  --text-scale: 1;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #101716; --sheet: #172120; --ink: #e4ebe8; --ink-soft: #a3b3ae; --rule: #2b3836;
    --spruce: #cfe3dc; --brass: #e0b45e; --brass-soft: #3a2f17;
    --part-handbook: #6fc0ae; --part-lite: #a9c97f; --part-training: #e0b45e; --part-icf: #93b4e4;
    --bar: rgba(23,33,32,0.92); --shadow: 0 6px 24px rgba(0,0,0,0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #101716; --sheet: #172120; --ink: #e4ebe8; --ink-soft: #a3b3ae; --rule: #2b3836;
  --spruce: #cfe3dc; --brass: #e0b45e; --brass-soft: #3a2f17;
  --part-handbook: #6fc0ae; --part-lite: #a9c97f; --part-training: #e0b45e; --part-icf: #93b4e4;
  --bar: rgba(23,33,32,0.92); --shadow: 0 6px 24px rgba(0,0,0,0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--f-ui); font-size: 16px; line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; border-radius: 6px; }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.wrap {
  max-width: 44rem; margin: 0 auto;
  padding-left: max(18px, env(safe-area-inset-left, 0px));
  padding-right: max(18px, env(safe-area-inset-right, 0px));
}

/* ---------- Floating controls ---------- */
.bar {
  position: fixed; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  padding-left: max(10px, env(safe-area-inset-left, 0px));
  padding-right: max(10px, env(safe-area-inset-right, 0px));
  transition: opacity .35s ease, transform .35s ease;
  pointer-events: none;
}
.bar > * { pointer-events: auto; }
.bar.top { top: 0; padding-top: calc(env(safe-area-inset-top, 0px) + 8px); }
.bar.bottom { bottom: 0; padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 10px); justify-content: space-between; }
.bar .spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px;
  background: var(--bar); color: var(--ink); border-radius: 999px; box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  font-size: 15px; font-weight: 550; white-space: nowrap; max-width: 46vw; overflow: hidden; text-overflow: ellipsis;
}
.chip.round { width: 44px; padding: 0; justify-content: center; }
.chip.on { color: var(--brass); }
.chip.on svg.i { fill: currentColor; }
.chip span { overflow: hidden; text-overflow: ellipsis; }
body.controls-hidden .bar.top { opacity: 0; transform: translateY(-12px); }
body.controls-hidden .bar.bottom { opacity: 0; transform: translateY(12px); }
body.controls-hidden .bar > * { pointer-events: none; }
.progress { position: fixed; top: 0; left: 0; height: 3px; background: var(--brass); z-index: 21; width: 0; }

/* ---------- Home ---------- */
.home-head { padding-block: calc(env(safe-area-inset-top, 0px) + 28px) 8px; display: flex; align-items: center; gap: 14px; }
.home-head img { width: 54px; height: 54px; border-radius: 13px; }
.home-head h1 { font-family: var(--f-read); font-weight: 600; font-size: 1.65rem; line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
.home-head p { margin: 2px 0 0; color: var(--ink-soft); font-size: .9rem; }
.eyebrow { font-size: .74rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-soft); margin: 28px 0 10px; }

.parts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.part-tile {
  text-align: left; background: var(--sheet); border-radius: 16px; padding: 16px 14px 14px;
  border: 1px solid var(--rule); display: flex; flex-direction: column; gap: 10px; min-height: 148px;
  position: relative; overflow: hidden;
}
.part-tile::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--pc); }
.part-tile .num { font-family: var(--f-read); font-style: italic; font-size: .9rem; color: var(--pc); }
.part-tile .name { font-family: var(--f-read); font-weight: 600; font-size: 1.15rem; line-height: 1.2; }
.part-tile .meta { margin-top: auto; font-size: .8rem; color: var(--ink-soft); display: flex; gap: 10px; flex-wrap: wrap; }
.part-tile .meta b { color: var(--brass); font-weight: 600; }

.resume { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--spruce); color: var(--paper); border-radius: 16px; padding: 14px 16px; margin-top: 18px; }
.resume small { display: block; opacity: .75; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; font-weight: 700; }
.resume strong { font-family: var(--f-read); font-weight: 600; font-size: 1.02rem; }
.resume div { min-width: 0; flex: 1; }

/* ---------- Lists (part contents, bookmarks, menu) ---------- */
.page-head { padding-block: calc(env(safe-area-inset-top, 0px) + 72px) 6px; }
.page-head .kicker { font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--pc, var(--brass)); }
.page-head h1 { font-family: var(--f-read); font-weight: 600; font-size: 1.85rem; line-height: 1.15; margin: 4px 0 6px; text-wrap: balance; }
.page-head p { color: var(--ink-soft); margin: 0; font-size: .95rem; }

.rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.rows li { border-bottom: 1px solid var(--rule); }
.row { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 14px 2px; min-height: 56px; }
.row .lab { flex: none; width: 3.1rem; font-family: var(--f-read); font-size: 1.25rem; font-weight: 600; color: var(--pc, var(--ink-soft)); font-variant-numeric: tabular-nums; text-align: center; }
.row .lab.sm { font-size: .78rem; font-family: var(--f-ui); font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.row .txt { flex: 1; min-width: 0; }
.row .t { display: block; font-weight: 550; line-height: 1.3; }
.row .s { display: block; font-size: .82rem; color: var(--ink-soft); margin-top: 2px; }
.row .bm { flex: none; display: inline-flex; align-items: center; gap: 3px; font-size: .78rem; color: var(--brass); font-weight: 650; }
.row .bm svg.i { width: 15px; height: 15px; fill: currentColor; }
.group-label { font-size: .74rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-soft); padding: 22px 2px 8px; border-bottom: 1px solid var(--rule); }

.bm-part { margin-top: 22px; }
.bm-part h2 { display: flex; align-items: center; gap: 8px; font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--pc); margin: 0 0 6px; }
.bm-part h2::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--pc); }
.bm-item { font-family: var(--f-read); font-weight: 600; font-size: 1.02rem; padding: 12px 2px 4px; }
.bm-row { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--rule); }
.bm-row .go { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 11px 2px; min-height: 48px; text-align: left; }
.bm-row .go svg.i { width: 17px; height: 17px; color: var(--brass); fill: currentColor; }
.bm-row .go span { min-width: 0; }
.bm-row .del { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-soft); }
.empty { color: var(--ink-soft); padding: 18px 2px; font-size: .95rem; }
.empty svg.i { width: 16px; height: 16px; vertical-align: -3px; }

/* ---------- Reader ---------- */
.reader { padding-block: calc(env(safe-area-inset-top, 0px) + 68px) calc(env(safe-area-inset-bottom, 0px) + 96px); }
.reader-head .kicker { font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--pc); }
.reader-head h1 { font-family: var(--f-read); font-weight: 650; font-size: calc(1.9rem * var(--text-scale)); line-height: 1.15; margin: 6px 0 4px; text-wrap: balance; letter-spacing: -0.01em; }
.reader-head .sub { color: var(--ink-soft); font-size: .92rem; }

.prose { font-family: var(--f-read); font-size: calc(1.06rem * var(--text-scale)); line-height: 1.68; }
.prose h2 { font-family: var(--f-read); font-weight: 650; font-size: 1.42em; line-height: 1.22; margin: 2.1em 0 .55em; padding-top: .7em; border-top: 1px solid var(--rule); text-wrap: balance; }
.prose h3 { font-family: var(--f-ui); font-weight: 700; font-size: 1.02em; line-height: 1.3; margin: 1.7em 0 .4em; color: var(--pc); }
.prose h4 { font-family: var(--f-ui); font-weight: 700; font-size: .95em; margin: 1.4em 0 .3em; }
.prose > h2:first-child { border-top: 0; margin-top: 1.2em; }
.prose p, .prose ul, .prose ol { margin: 0 0 .9em; }
.prose ul, .prose ol { padding-left: 1.25em; }
.prose li { margin: .28em 0; }
.prose li > p { margin: 0 0 .3em; }
.prose strong { font-weight: 650; }
.prose a { color: var(--pc); text-underline-offset: 3px; }
.prose blockquote { margin: 1.2em 0; padding: .2em 0 .2em 1em; border-left: 3px solid var(--brass); color: var(--ink-soft); font-style: italic; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2em 0; }
.prose code { font-size: .9em; background: var(--brass-soft); padding: .05em .3em; border-radius: 4px; }
.prose img { display: block; width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--rule); background: var(--sheet); margin: 1em 0 .3em; cursor: zoom-in; }
.prose .tbl { overflow-x: auto; margin: 1.1em 0 1.3em; border: 1px solid var(--rule); border-radius: 10px; background: var(--sheet); }
.prose table { border-collapse: collapse; font-family: var(--f-ui); font-size: .82em; line-height: 1.45; min-width: 100%; }
.prose th, .prose td { text-align: left; vertical-align: top; padding: .6em .75em; border-bottom: 1px solid var(--rule); min-width: 7.5em; }
.prose th { font-weight: 700; background: var(--paper); }
.prose tr:last-child td { border-bottom: 0; }
.prose .bm-flag { display: inline-flex; vertical-align: .1em; margin-left: .35em; color: var(--brass); }
.prose .bm-flag svg.i { width: .8em; height: .8em; fill: currentColor; }
.prose .xref { font-family: var(--f-ui); font-weight: 600; }
.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { background: var(--brass-soft); } 100% { background: transparent; } }

/* ICF official document styling */
.icf-doc .domain { font-family: var(--f-ui); font-size: .78rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--part-icf); margin: 0 0 4px; }
.icf-doc .def { background: var(--sheet); border: 1px solid var(--rule); border-radius: 12px; padding: .9em 1em; margin: 1em 0 1.4em; }
.icf-doc .def b { display: block; font-family: var(--f-ui); font-size: .74rem; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: .2em; }
.icf-doc ol.subs { list-style: none; padding: 0; margin: 0; }
.icf-doc ol.subs li { display: flex; gap: .9em; padding: .7em 0; border-bottom: 1px solid var(--rule); margin: 0; scroll-margin-top: 80px; }
.icf-doc ol.subs .code { flex: none; width: 2.6em; font-family: var(--f-ui); font-weight: 700; font-size: .88em; color: var(--part-icf); padding-top: .15em; font-variant-numeric: tabular-nums; }
.icf-doc dl { margin: 0; }
.icf-doc dt { font-family: var(--f-ui); font-weight: 700; margin-top: 1.1em; scroll-margin-top: 80px; }
.icf-doc dd { margin: .2em 0 0; }
.icf-doc .letters { display: flex; flex-wrap: wrap; gap: 6px; margin: .4em 0 1em; }
.icf-doc .letters button { width: 36px; height: 36px; border-radius: 8px; background: var(--sheet); border: 1px solid var(--rule); font-family: var(--f-ui); font-weight: 650; }
.icf-doc .credit { font-family: var(--f-ui); font-size: .8rem; color: var(--ink-soft); margin-top: 2.4em; }

.next { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; margin-top: 2.6em; padding: 16px; border-radius: 14px; background: var(--sheet); border: 1px solid var(--rule); }
.next small { font-size: .74rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.next strong { font-family: var(--f-read); font-weight: 600; font-size: 1.05rem; color: var(--pc); }

.hint { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 18px); transform: translateX(-50%); z-index: 25; background: var(--spruce); color: var(--paper); padding: 10px 16px; border-radius: 999px; font-size: .88rem; box-shadow: var(--shadow); max-width: calc(100vw - 32px); text-align: center; transition: opacity .3s; }

/* ---------- Sheets (menu, contents) ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10,20,18,.42); z-index: 40; animation: fade .2s; }
.sheet {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 41; width: min(88vw, 380px);
  background: var(--paper); box-shadow: var(--shadow); overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px calc(env(safe-area-inset-bottom, 0px) + 24px) max(16px, env(safe-area-inset-left, 0px));
  animation: slide .22s ease-out;
}
.sheet.right { left: auto; right: 0; padding-left: 16px; padding-right: max(16px, env(safe-area-inset-right, 0px)); animation-name: slideR; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.sheet-head h2 { font-family: var(--f-read); font-size: 1.3rem; margin: 0; }
.sheet .x { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.menu-top { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.menu-top button { display: flex; align-items: center; gap: 8px; padding: 12px; border-radius: 12px; background: var(--sheet); border: 1px solid var(--rule); font-weight: 600; min-height: 48px; }
.menu-part > button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 13px 4px; border-bottom: 1px solid var(--rule); font-weight: 650; }
.menu-part > button .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--pc); flex: none; }
.menu-part > button .chev { margin-left: auto; transition: transform .2s; width: 18px; height: 18px; }
.menu-part.open > button .chev { transform: rotate(90deg); }
.menu-part ul { list-style: none; margin: 0; padding: 4px 0 8px 20px; }
.menu-part li button { display: flex; gap: 10px; width: 100%; text-align: left; padding: 9px 4px; font-size: .93rem; min-height: 42px; align-items: center; }
.menu-part li button .l { flex: none; width: 2.2rem; color: var(--pc); font-weight: 700; font-size: .82rem; font-variant-numeric: tabular-nums; }
.menu-part li button.cur { color: var(--pc); font-weight: 700; }
.menu-part li button .bmc { margin-left: auto; color: var(--brass); font-size: .78rem; font-weight: 700; }
.text-size { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; padding: 10px 4px; border-top: 1px solid var(--rule); color: var(--ink-soft); font-size: .9rem; }
.text-size div { display: flex; gap: 6px; }
.text-size button { width: 44px; height: 40px; border-radius: 10px; background: var(--sheet); border: 1px solid var(--rule); font-family: var(--f-read); font-weight: 600; color: var(--ink); }

.toc a, .toc button { display: block; width: 100%; text-align: left; padding: 10px 4px; border-bottom: 1px solid var(--rule); font-size: .95rem; line-height: 1.3; }
.toc .h3 { padding-left: 22px; font-size: .88rem; color: var(--ink-soft); }
.toc .has-bm::after { content: " \2022"; color: var(--brass); font-weight: 800; }

.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 66px); transform: translateX(-50%); z-index: 50; background: var(--spruce); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-size: .9rem; box-shadow: var(--shadow); max-width: calc(100vw - 32px); animation: fade .2s; }

.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(5,10,9,.94); overflow: auto; display: flex; align-items: center; justify-content: center; padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px); }
.viewer img { max-width: none; width: 100%; height: auto; touch-action: pinch-zoom; }
.viewer .x { position: fixed; top: calc(env(safe-area-inset-top, 0px) + 10px); right: max(10px, env(safe-area-inset-right, 0px)); width: 44px; height: 44px; border-radius: 999px; background: rgba(255,255,255,.15); color: #fff; display: inline-flex; align-items: center; justify-content: center; }

@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(-100%); } }
@keyframes slideR { from { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (min-width: 640px) { .parts { gap: 14px; } .part-tile { min-height: 170px; padding: 20px 18px; } }

.twin { display: inline-flex; align-items: center; gap: 6px; margin-top: 12px; padding: 8px 14px 8px 10px; min-height: 40px; border-radius: 999px; border: 1px solid var(--rule); background: var(--sheet); color: var(--tc); font-weight: 600; font-size: .88rem; }
.twin svg.i { width: 18px; height: 18px; }
