/* Page styles. Header, hero, section heads, cards, buttons, badges, pills and the
   theme control come from tokens.css; reading typography comes from site.css. */

#progress { position: fixed; inset: 0 0 auto 0; height: 3px; background: var(--accent); transform: scaleX(0); transform-origin: 0 50%; z-index: calc(var(--z-toast) + 1); pointer-events: none; }

/* ───────── header ───────── */
.top .brand span { color: var(--fg-subtle); font-weight: 400; }
.top .tools { display: flex; align-items: center; gap: var(--space-2); }
.top .tools .btn { height: 2.5rem; padding-inline: var(--space-5); }
@media (max-width: 52rem) { .top .tools .btn-ghost { display: none; } }
@media (max-width: 34rem) { .top .brand span { display: none; } .top .tools .btn-secondary { padding-inline: var(--space-4); } }
.container > main { display: block; }

/* ───────── home ───────── */
.hero-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: var(--space-16); align-items: end; }
.hero-copy .row { display: flex; flex-wrap: wrap; gap: var(--space-4); margin-top: var(--space-10); }
.jump { padding: var(--space-8); display: grid; gap: var(--space-5); align-content: start; }
.jump dl { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5) var(--space-6); }
.jump dt { font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--fg-muted); }
.jump dd { margin: var(--space-1) 0 0; font-size: var(--text-3xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); line-height: var(--leading-tight); }
.jump .note { font-size: var(--text-sm); color: var(--fg-subtle); padding-top: var(--space-4); border-top: 1px solid var(--border); }
@media (max-width: 62rem) { .hero-grid { grid-template-columns: minmax(0, 1fr); gap: var(--space-10); } }
.section { padding-block: 0 var(--space-16); }
.section[id] { scroll-margin-top: 6rem; }

.vol-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 26rem), 1fr)); gap: var(--space-6); }
.volc { padding: var(--space-8); display: grid; gap: var(--space-5); align-content: start; scroll-margin-top: 7rem; }
.volc header { display: grid; gap: var(--space-2); }
.volc h3 { font-size: var(--text-2xl); letter-spacing: var(--tracking-snug); line-height: var(--leading-snug); }
.volc header p { color: var(--fg-muted); font-size: var(--text-sm); }
.roman { font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--accent-text); }
.chapters { list-style: none; margin: 0; padding: 0; display: grid; }
.chapters li + li { border-top: 1px solid var(--border); }
.chapters a { display: grid; grid-template-columns: 2.2rem minmax(0, 1fr) auto; align-items: baseline; gap: var(--space-3); padding: var(--space-3) var(--space-2); border-radius: var(--radius-md); color: var(--fg); text-decoration: none; transition: background var(--dur-fast) var(--ease-out); }
.chapters a:hover { background: var(--accent-subtle); }
.chapters .num { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-subtle); }
.chapters .ct { line-height: var(--leading-snug); }
.m { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-subtle); white-space: nowrap; }
.vcount { padding-top: var(--space-2); }
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr)); gap: var(--space-5); }
.refc { padding: var(--space-6); display: grid; gap: var(--space-2); align-content: start; color: var(--fg); text-decoration: none; }
.refc h3 { font-size: var(--text-lg); letter-spacing: var(--tracking-snug); line-height: var(--leading-snug); }
.refc p { color: var(--fg-muted); font-size: var(--text-sm); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ───────── chapter / reference pages ───────── */
.ch-head { padding-block: clamp(2rem, 1rem + 3vw, 3.5rem) var(--space-8); display: grid; gap: var(--space-3); max-width: 60rem; }
.ch-head h1 { font-size: var(--text-3xl); max-width: 26ch; letter-spacing: var(--tracking-tight); }
.ch-head .chnum { font-family: var(--font-mono); font-size: var(--text-lg); font-weight: var(--weight-medium); color: var(--accent-text); letter-spacing: 0; }
.lede { color: var(--fg-muted); font-size: var(--text-base); }
.lede a.inline { color: var(--accent-text); }
.crumbs { display: flex; gap: var(--space-2); flex-wrap: wrap; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-subtle); }
.crumbs a { color: var(--fg-muted); text-decoration: none; }
.crumbs a:hover { color: var(--fg); }
.jump-chips { display: none; flex-wrap: wrap; gap: var(--space-2); }
.covers { color: var(--fg-muted); font-size: var(--text-sm); margin-top: var(--space-8); padding-top: var(--space-6); border-top: 1px solid var(--border); scroll-margin-top: 6rem; }
.covers summary { cursor: pointer; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-subtle); width: fit-content; }
.covers ul { list-style: none; margin: var(--space-4) 0 0; padding: 0; columns: 2 18rem; column-gap: var(--space-8); }
.covers li { break-inside: avoid; padding: 3px 0; }
.covers li span { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-subtle); margin-right: var(--space-2); }

.ch-layout { display: grid; grid-template-columns: 16rem minmax(0, 1fr); gap: var(--space-12); align-items: start; padding-bottom: var(--space-16); border-top: 1px solid var(--border); padding-top: var(--space-8); }
.ch-body { min-width: 0; max-width: 50rem; }
.ch-body.wide { max-width: 60rem; }
@media (max-width: 62rem) { .ch-layout { grid-template-columns: minmax(0, 1fr); gap: 0; } .side { display: none; } .jump-chips { display: flex; } }

/* in-chapter navigation */
.side { position: sticky; top: 7rem; max-height: calc(100vh - 9rem); overflow: auto; display: grid; gap: var(--space-3); font-size: var(--text-sm); align-content: start; scrollbar-width: thin; }
.side ol { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); }
.side li > a { display: block; padding: var(--space-2) var(--space-3); border-left: 2px solid var(--border); color: var(--fg-muted); text-decoration: none; line-height: var(--leading-snug); }
.side > ol > li > a { font-weight: var(--weight-medium); color: var(--fg); }
.side li > a:hover { color: var(--accent-text); }
.side ul { list-style: none; margin: 0 0 var(--space-3); padding: 0; display: none; }
.side li.cur > ul { display: block; }
.side ul a { font-size: var(--text-xs); padding: var(--space-1) var(--space-3) var(--space-1) var(--space-5); }
.side a.on { color: var(--accent-text); border-left-color: var(--accent); }
.side ol.flat li > a { font-weight: var(--weight-regular); color: var(--fg-muted); }

/* articles inside a chapter: one continuous read */
.ch-art { padding-bottom: var(--space-16); margin-bottom: var(--space-16); border-bottom: 1px solid var(--border-strong); scroll-margin-top: 6rem; }
.ch-art:last-of-type { border-bottom: 0; margin-bottom: var(--space-8); }
.art-top { display: grid; gap: var(--space-3); padding-bottom: var(--space-4); }
.art-top h2 { font-size: var(--text-2xl); letter-spacing: var(--tracking-snug); line-height: var(--leading-snug); position: relative; }
.art-top .aka { color: var(--fg-muted); font-size: var(--text-sm); }
.sec { padding-block: var(--space-6); scroll-margin-top: 6rem; }
.sec > h3 { font-size: var(--text-xl); letter-spacing: var(--tracking-snug); line-height: var(--leading-snug); margin-bottom: var(--space-4); position: relative; }
.sec > h3 .anchor, .art-top h2 .anchor, .term h3 .anchor { position: absolute; left: -1.6rem; color: var(--fg-subtle); text-decoration: none; opacity: 0; font-weight: var(--weight-regular); }
.sec > h3:hover .anchor, .art-top h2:hover .anchor, .term h3:hover .anchor { opacity: 1; }
.sec .prose h4 { font-size: var(--text-lg); margin-top: var(--space-6); scroll-margin-top: 6rem; }
.sec .prose h5, .sec .prose h6 { font-size: var(--text-base); margin-top: var(--space-5); }

/* apparatus: references, evidence, revision history tucked away */
.apparatus { margin-top: var(--space-8); border: 1px solid var(--glass-border); border-radius: var(--radius-lg); background: var(--glass-bg); }
.apparatus > summary { cursor: pointer; padding: var(--space-5) var(--space-6); display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); align-items: baseline; font-weight: var(--weight-medium); list-style: none; }
.apparatus > summary::-webkit-details-marker { display: none; }
.apparatus > summary::after { content: "Show"; margin-left: auto; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--accent-text); }
.apparatus[open] > summary::after { content: "Hide"; }
.apparatus > summary .m { font-weight: var(--weight-regular); }
.apparatus > .sec { padding: var(--space-4) var(--space-6) var(--space-6); border-top: 1px solid var(--border); }
.apparatus .prose { font-size: var(--text-sm); }

.planned-box { margin-top: var(--space-8); padding: var(--space-6); border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); display: grid; gap: var(--space-3); }
.planned-box ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); font-size: var(--text-sm); color: var(--fg-muted); }
.planned-box li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.empty { color: var(--fg-muted); padding: var(--space-6) 0; }
.pn .card.l { text-align: left; }

/* glossary + index */
.letters { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.letters a { width: 2.4rem; height: 2.4rem; display: grid; place-items: center; border-radius: var(--radius-full); border: 1px solid var(--border-strong); font-family: var(--font-mono); font-size: var(--text-sm); color: var(--fg); text-decoration: none; }
.letters a:hover { background: var(--accent-subtle); border-color: var(--accent); }
.gl-group { padding-top: var(--space-10); scroll-margin-top: 6rem; }
.gl-letter { font-size: var(--text-3xl); color: var(--accent-text); padding-bottom: var(--space-3); border-bottom: 1px solid var(--border-strong); margin-bottom: var(--space-4); }
.term { padding-block: var(--space-5); border-bottom: 1px solid var(--border); scroll-margin-top: 6rem; }
.term h3 { font-size: var(--text-lg); position: relative; margin-bottom: var(--space-2); }
.term .prose { font-size: var(--text-base); }
.ix { list-style: none; margin: 0; padding: 0; columns: 2 20rem; column-gap: var(--space-10); }
.ix li { break-inside: avoid; display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: baseline; padding: 5px 0; font-size: var(--text-sm); }
.ix .how, .ix .how a { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-subtle); }
.soon { color: var(--fg-subtle); }

/* ───────── contents drawer ───────── */
.toc-panel { position: fixed; inset: var(--space-4) auto var(--space-4) var(--space-4); width: min(26rem, calc(100vw - 2 * var(--space-4))); z-index: var(--z-modal); display: grid; grid-template-rows: auto 1fr; gap: var(--space-4); padding: var(--space-6); background: var(--glass-bg-strong); border: 1px solid var(--glass-border); border-radius: var(--radius-xl); box-shadow: var(--shadow-glass); -webkit-backdrop-filter: blur(var(--glass-blur-lg)) saturate(var(--glass-saturate)); backdrop-filter: blur(var(--glass-blur-lg)) saturate(var(--glass-saturate)); transform: translateX(calc(-100% - 2rem)); transition: transform var(--dur-slow) var(--ease-out); visibility: hidden; }
body.toc-open .toc-panel { transform: none; visibility: visible; }
body.toc-open::after { content: ""; position: fixed; inset: 0; background: var(--overlay); z-index: calc(var(--z-modal) - 1); }
.toc-head { display: flex; align-items: center; justify-content: space-between; }
.toc-head .btn { height: 2.5rem; }
.tree { overflow: auto; font-size: var(--text-sm); overscroll-behavior: contain; scrollbar-width: thin; display: grid; gap: var(--space-1); align-content: start; }
.tree a { display: block; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); color: var(--fg-muted); text-decoration: none; line-height: var(--leading-snug); }
.tree a:hover { color: var(--fg); background: var(--glass-bg); }
.tree a.cur { color: var(--accent-text); background: var(--accent-subtle); }
.tree b { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--accent-text); font-weight: var(--weight-medium); margin-right: var(--space-2); }
.tree details { border-top: 1px solid var(--border); }
.tree summary { cursor: pointer; padding: var(--space-3) var(--space-3); font-weight: var(--weight-medium); line-height: var(--leading-snug); list-style: none; }
.tree summary::-webkit-details-marker { display: none; }
.tree summary::after { content: ""; float: right; width: 0.45rem; height: 0.45rem; margin-top: 0.4rem; border-right: 1.5px solid var(--fg-subtle); border-bottom: 1.5px solid var(--fg-subtle); transform: rotate(-45deg); transition: transform var(--dur-fast) var(--ease-out); }
.tree details[open] > summary::after { transform: rotate(45deg); }
.tree details > div { padding: 0 0 var(--space-3) var(--space-3); display: grid; }
.tree .t-sep { margin: var(--space-4) 0 var(--space-1); padding-left: var(--space-3); font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--fg-subtle); }
.tree .k { color: var(--fg-subtle); font-family: var(--font-mono); font-size: var(--text-xs); margin-left: var(--space-2); }

/* ───────── search palette ───────── */
.pal { position: fixed; inset: 0; z-index: var(--z-modal); background: var(--overlay); display: grid; justify-items: center; align-content: start; padding: 12vh var(--gutter) var(--space-8); }
.pal[hidden] { display: none; }
.pal-box { width: min(42rem, 100%); background: var(--glass-bg-strong); border: 1px solid var(--glass-border); border-radius: var(--radius-xl); box-shadow: var(--shadow-glass); -webkit-backdrop-filter: blur(var(--glass-blur-lg)) saturate(var(--glass-saturate)); backdrop-filter: blur(var(--glass-blur-lg)) saturate(var(--glass-saturate)); padding: var(--space-5); display: grid; gap: var(--space-4); }
#palr { list-style: none; margin: 0; padding: 0; max-height: min(50vh, 26rem); overflow: auto; display: grid; gap: 2px; }
#palr li { display: grid; grid-template-columns: 5rem minmax(0, 1fr); gap: 2px var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); cursor: pointer; align-items: baseline; }
#palr li[aria-selected="true"], #palr li:hover { background: var(--accent-subtle); }
#palr .k { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--accent-text); grid-row: span 2; }
#palr .tt { font-weight: var(--weight-medium); line-height: var(--leading-snug); }
#palr .ss { font-size: var(--text-xs); color: var(--fg-subtle); font-family: var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#palr .none { display: block; color: var(--fg-muted); font-size: var(--text-sm); cursor: default; }
.pal-hint { margin: 0; font-size: var(--text-xs); color: var(--fg-subtle); font-family: var(--font-mono); }
.pal-hint kbd { border: 1px solid var(--border-strong); border-radius: var(--radius-xs); padding: 0 0.3rem; margin-right: 2px; }

/* ───────── reading rhythm: one spacing scale for every article page ─────────
   title block -> 2.5rem -> sections; sections 2.5rem apart; heading -> text 0.75rem;
   paragraphs 1rem apart; articles 5rem apart.                                       */
.ch-head { padding-block: var(--space-10) var(--space-6); gap: var(--space-2); }
.ch-head h1 { font-size: var(--text-3xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); line-height: 1.15; margin-top: var(--space-2); }
.ch-head .lede { margin-top: var(--space-1); font-size: var(--text-sm); }
.crumbs { line-height: 1.5; }
.ch-layout { gap: var(--space-16); padding-top: var(--space-10); }

.side { top: 6.5rem; font-size: var(--text-sm); gap: var(--space-4); }
.side > .eyebrow { margin: 0; }
.side ol { gap: 2px; }
.side li > a { padding: var(--space-2) var(--space-4); line-height: 1.4; }
.side > ol > li > a { font-weight: var(--weight-medium); }
.side ul { margin: 2px 0 var(--space-3); }
.side ul a { padding: 5px var(--space-4) 5px var(--space-6); color: var(--fg-muted); }

.ch-art { padding-bottom: var(--space-20); margin-bottom: var(--space-20); }
.art-top { gap: var(--space-3); padding-bottom: var(--space-4); margin-bottom: var(--space-2); }
.art-top h2 { font-size: var(--text-2xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); line-height: 1.2; }
.art-top .aka { font-size: var(--text-sm); line-height: 1.6; max-width: var(--measure); }

.sec { padding-block: 0; margin-top: var(--space-10); }
.art-top + .sec { margin-top: var(--space-6); }
.sec > h3 { font-size: var(--text-xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); line-height: 1.3; margin: 0 0 var(--space-3); }
.sec .prose { line-height: 1.75; }
.sec .prose > * + * { margin-top: var(--space-4); }
.sec .prose ul, .sec .prose ol { margin-top: var(--space-3); padding-left: var(--space-6); }
.sec .prose li + li { margin-top: var(--space-2); }
.sec .prose h4 { font-size: var(--text-lg); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); line-height: 1.35; margin: var(--space-8) 0 var(--space-2); }
.sec .prose h5, .sec .prose h6 { font-size: var(--text-base); font-weight: var(--weight-semibold); letter-spacing: 0; line-height: 1.4; margin: var(--space-6) 0 var(--space-1); }
.sec .prose .table-wrap { margin-block: var(--space-6); }
.sec .prose .math-block { margin-block: var(--space-4); }

.rel { margin-top: var(--space-10); padding-top: var(--space-5); }
.apparatus { margin-top: var(--space-10); }
.apparatus > .sec { margin-top: 0; padding: var(--space-5) var(--space-6) var(--space-6); }
.apparatus > .sec > h3 { font-size: var(--text-base); }

/* ───────── wide reading column: fill the space to the right ───────── */
.ch-body, .ch-body.wide { max-width: none; }
.sec .prose p, .sec .prose ul, .sec .prose ol, .sec .prose blockquote, .term .prose p { max-width: 92ch; }
.art-top .aka { max-width: 92ch; }
.sec .prose table { min-width: 0; width: 100%; }
.ch-layout { grid-template-columns: 15rem minmax(0, 1fr); gap: var(--space-12); }
.ch-head { max-width: none; }

/* ═════════ three-column reading layout: chapter rail | text | article info rail ═════════ */
body.reading .container { width: min(100% - 2 * var(--gutter), 96rem); }

/* chapter header: title left, facts right, one band */
.ch-head--band { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-4) var(--space-8); max-width: none; padding-block: var(--space-8) var(--space-6); }
.ch-head--band .ch-title { display: grid; gap: var(--space-3); min-width: 0; }
.ch-head--band h1 { font-size: var(--text-4xl); letter-spacing: var(--tracking-tight); line-height: 1.05; max-width: 24ch; margin: 0; }
.ch-facts { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; padding-bottom: var(--space-2); }
.ch-facts .badge { font-size: var(--text-sm); padding: 0.4rem 0.9rem; text-decoration: none; }
.ch-facts a.badge:hover { background: var(--accent); color: var(--fg-on-accent); }
.ch-head--band .jump-chips { flex-basis: 100%; }

.ch-layout { grid-template-columns: 14rem minmax(0, 1fr); gap: var(--space-10); padding-top: var(--space-8); }
.ch-body { max-width: none; }

/* left rail: the chapter's articles */
.side li > a { display: grid; grid-template-columns: 1.4rem minmax(0, 1fr); gap: var(--space-2); }
.side .n { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-subtle); padding-top: 2px; }
.side li.cur > a { color: var(--accent-text); border-left-color: var(--accent); background: var(--accent-subtle); }
.side ol.flat li > a { display: block; }

/* each article: title + text in the middle, info and outline in a sticky right rail */
.ch-art { display: grid; grid-template-columns: minmax(0, 1fr) 19rem; grid-template-areas: "top info" "text info"; column-gap: var(--space-12); align-items: start; }
.art-top { grid-area: top; padding-bottom: var(--space-6); margin: 0; }
.art-top h2 { font-size: var(--text-3xl); letter-spacing: var(--tracking-tight); line-height: 1.1; }
.art-text { grid-area: text; min-width: 0; max-width: 52rem; }
.art-text .sec:first-child { margin-top: 0; }
.art-text .sec .prose p, .art-text .sec .prose ul, .art-text .sec .prose ol, .art-text .sec .prose blockquote { max-width: none; }

.art-info { grid-area: info; position: sticky; top: 6.5rem; align-self: start; max-height: calc(100vh - 8rem); overflow: auto; display: grid; gap: var(--space-5); padding: var(--space-5); background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: var(--radius-lg); font-size: var(--text-sm); scrollbar-width: thin; }
.art-info .facts { gap: var(--space-2); }
.art-info .meta { margin: 0; display: grid; gap: var(--space-3); }
.art-info dt { font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--fg-subtle); }
.art-info dd { margin: 2px 0 0; color: var(--fg-muted); line-height: 1.45; }
.art-info .outline { display: grid; gap: var(--space-2); }
.art-info .outline ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.art-info .outline a { display: block; padding: 5px var(--space-3); border-left: 2px solid var(--border); color: var(--fg-muted); text-decoration: none; line-height: 1.35; }
.art-info .outline a:hover { color: var(--fg); }
.art-info .outline a.on { color: var(--accent-text); border-left-color: var(--accent); background: var(--accent-subtle); }
.art-info .outline li.src a { margin-top: var(--space-2); font-family: var(--font-mono); font-size: var(--text-xs); }
.art-info .rail-group { display: grid; gap: var(--space-2); }
.art-info .chips { display: grid; gap: var(--space-2); }
.art-info .chip { display: grid; gap: 2px; border-radius: var(--radius-md); padding: var(--space-2) var(--space-3); }

/* narrower screens: the article rail moves above the text, the chapter rail goes away */
@media (max-width: 85rem) {
  .ch-art { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "info" "text"; }
  .art-info { position: static; max-height: none; margin-bottom: var(--space-8); }
  .art-info .outline ol { grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); }
}
@media (max-width: 62rem) { .ch-head--band h1 { font-size: var(--text-3xl); } }

/* ═════════ responsive: authoritative, must stay last ═════════ */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: clip; }
.prose, .art-top h2, .ch-head h1, .sec > h3, .lede, .aka, .term h3 { overflow-wrap: anywhere; }
.prose a { overflow-wrap: anywhere; }
.toc-panel .seg { display: none; }
.toc-head { gap: var(--space-3); }
.pal-box input { font-size: 1rem; }

/* tablet and below: single column, sidebars out */
@media (max-width: 62rem) {
  .ch-layout { grid-template-columns: minmax(0, 1fr); gap: 0; padding-top: var(--space-6); }
  .side { display: none; }
  .top .tools .btn-ghost { display: inline-flex; }
  .toc-panel .seg { display: inline-flex; }
  .jump-chips { display: flex; flex-wrap: nowrap; overflow-x: auto; margin: 0 calc(-1 * var(--gutter)); padding: var(--space-1) var(--gutter) var(--space-3); scroll-snap-type: x proximity; scroll-padding-inline: var(--gutter); scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .jump-chips::-webkit-scrollbar { display: none; }
  .jump-chips .chip { flex: none; scroll-snap-align: start; white-space: nowrap; min-height: 2.5rem; align-items: center; }
  .ch-head .jump-chips { margin-top: var(--space-2); }
}

/* phones */
@media (max-width: 40rem) {
  /* header: brand + Contents + Search; theme control lives in the Contents drawer */
  .top { gap: var(--space-2); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4); margin-top: var(--space-2); top: calc(var(--space-2) + env(safe-area-inset-top, 0px)); }
  .top .seg { display: none; }
  .top .brand { font-size: var(--text-sm); white-space: nowrap; min-width: 0; }
  .top .tools { gap: 0; flex: none; }
  .top .tools .btn { height: 2.75rem; padding-inline: var(--space-4); font-size: var(--text-sm); }
  .toc-panel { inset: var(--space-2); width: auto; padding: var(--space-4); border-radius: var(--radius-lg); padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px)); }
  .toc-head .btn { height: 2.75rem; }
  .tree a { padding: var(--space-3); }
  .tree summary { padding: var(--space-4) var(--space-3); }
  .pal { padding: var(--space-3) var(--space-3) var(--space-4); }
  .pal-box { padding: var(--space-3); border-radius: var(--radius-lg); }
  #palr { max-height: calc(100dvh - 11rem); }
  #palr li { grid-template-columns: 4.2rem minmax(0, 1fr); padding: var(--space-3); }
  .pal-hint { display: none; }

  /* home */
  .hero { padding-block: var(--space-12) var(--space-8); }
  .hero p { margin-top: var(--space-5); font-size: var(--text-base); }
  .hero-copy .row { margin-top: var(--space-6); gap: var(--space-3); }
  .hero-copy .row .btn { flex: 1 1 8rem; }
  .jump { padding: var(--space-5); }
  .jump dd { font-size: var(--text-2xl); }
  .section { padding-bottom: var(--space-10); }
  .vol-grid { gap: var(--space-4); }
  .volc { padding: var(--space-5); gap: var(--space-4); }
  .volc h3 { font-size: var(--text-xl); }
  .chapters a { grid-template-columns: 2rem minmax(0, 1fr) auto; min-height: 2.75rem; align-items: center; padding: var(--space-2); }
  .refc { padding: var(--space-5); }

  /* chapter + article reading */
  .ch-head { padding-block: var(--space-6) var(--space-4); }
  .ch-head h1 { font-size: var(--text-2xl); }
  .crumbs { font-size: 0.6875rem; gap: var(--space-1) var(--space-2); }
  .ch-art { padding-bottom: var(--space-10); margin-bottom: var(--space-10); }
  .art-top h2 { font-size: var(--text-xl); }
  .facts { gap: var(--space-2); }
  .fact { white-space: normal; }
  .sec { margin-top: var(--space-8); }
  .sec > h3 { font-size: var(--text-lg); }
  .sec .prose { font-size: 1.0625rem; line-height: 1.7; }
  .sec .prose h4 { font-size: var(--text-base); margin-top: var(--space-6); }
  .sec .prose ul, .sec .prose ol { padding-left: var(--space-5); }
  .sec .prose blockquote { padding: var(--space-1) var(--space-4); }
  .sec .prose pre { padding: var(--space-4); font-size: var(--text-xs); }
  .sec .prose table { width: auto; min-width: 30rem; }
  .prose th, .prose td { padding: var(--space-3) var(--space-4); }
  .table-wrap { margin-inline: calc(-1 * var(--gutter)); border-radius: 0; border-inline: 0; -webkit-overflow-scrolling: touch; }
  .math-block { max-width: 100%; }
  .rel { margin-top: var(--space-8); }
  .chips .lab { min-width: 100%; }
  .chip { min-height: 2.25rem; align-items: center; }
  .apparatus { margin-top: var(--space-8); }
  .apparatus > summary { padding: var(--space-4); min-height: 2.75rem; }
  .apparatus > summary .m { flex-basis: 100%; order: 3; }
  .apparatus > .sec { padding: var(--space-4); }
  .covers ul { columns: 1; }
  .ix { columns: 1; }
  .pn { gap: var(--space-4); margin-top: var(--space-8); }
  .pn .card { padding: var(--space-5); }
  .planned-box { padding: var(--space-4); }
  .letters a { width: 2.75rem; height: 2.75rem; }
  .gl-letter { font-size: var(--text-2xl); }
  footer { padding-block: var(--space-10); }
}

/* touch: no hover, so no hover-only anchors; no sticky-hover states */
@media (hover: none) {
  .prose .anchor, .sec > h3 .anchor, .art-top h2 .anchor, .term h3 .anchor { display: none; }
}
@media (max-width: 22rem) { .top .brand { font-size: var(--text-xs); } .top .tools .btn { padding-inline: var(--space-3); } }
.apparatus > summary .m { white-space: normal; }
.prose .katex { max-width: 100%; }
.prose p:has(> .katex), .prose li:has(> .katex) { overflow-x: auto; overflow-y: hidden; }
.toc-panel { grid-template-columns: minmax(0, 1fr); }
.tree, .tree details, .tree details > div { min-width: 0; }
@media (max-width: 40rem) {
  .toc-head { flex-wrap: wrap; }
  .toc-head .eyebrow { flex: 1 0 auto; }
  .toc-panel, .pal-box { background: var(--bg-elevated); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (max-width: 40rem) {
  .toc-head .btn { order: 2; }
  .toc-head .seg { order: 3; flex: 1 1 100%; }
  .toc-head .seg button { flex: 1; min-height: 2.75rem; }
}
/* chapter jump chips: wrap, never clip */
@media (max-width: 62rem) {
  .jump-chips { flex-wrap: wrap; overflow: visible; margin: var(--space-2) 0 0; padding: 0; scroll-snap-type: none; gap: var(--space-2); }
  .jump-chips .chip { flex: 0 1 auto; max-width: 100%; white-space: normal; min-height: 2.5rem; padding: 0.5rem 0.9rem; font-family: var(--font-sans); font-size: var(--text-sm); line-height: 1.3; }
}

/* ═════════ mobile refinement pass ═════════ */
/* tables: never break words mid-word; keep columns readable, scroll the rest */
.prose th, .prose td { overflow-wrap: normal; word-break: normal; hyphens: manual; }
@media (max-width: 40rem) {
  .sec .prose table { min-width: 36rem; }
  .prose td:first-child, .prose th:first-child { min-width: 9rem; }
  .prose th, .prose td { padding: var(--space-3) var(--space-4); font-size: var(--text-sm); }
  .table-wrap { position: relative; scrollbar-width: thin; }

  /* sources / evidence disclosure: title + Show on one row, meta underneath */
  .apparatus > summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-1) var(--space-3); align-items: center; }
  .apparatus > summary::after { margin-left: 0; grid-column: 2; grid-row: 1; }
  .apparatus > summary .m { grid-column: 1 / -1; grid-row: 2; font-size: 0.6875rem; line-height: 1.5; }

  /* tighter vertical rhythm at the end of a chapter */
  .ch-art:last-of-type { margin-bottom: var(--space-4); padding-bottom: var(--space-6); }
  .ch-layout { padding-bottom: var(--space-8); }
  .covers { margin-top: var(--space-4); padding-top: var(--space-4); }
  .covers summary { min-height: 2.75rem; display: flex; align-items: center; }
  .pn { margin-top: var(--space-6); }
  .pn .card { padding: var(--space-4) var(--space-5); border-radius: var(--radius-xl); }
  .rel { margin-top: var(--space-6); }
  .sec .prose .table-wrap { margin-block: var(--space-5); }
  .art-top .aka { font-size: var(--text-sm); }
}

/* floating header slides away while reading down, returns on scroll up */
@media (max-width: 62rem) {
  .top { transition: transform var(--dur-base) var(--ease-out); will-change: transform; }
  .top.away { transform: translateY(calc(-100% - 1.5rem)); }
}
@media (max-width: 40rem) {
  .ch-art:last-of-type { padding-bottom: 0; margin-bottom: 0; }
  .ch-layout { padding-bottom: var(--space-4); }
  .covers summary::before { content: ""; width: 0.45rem; height: 0.45rem; margin-right: var(--space-3); border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform var(--dur-fast) var(--ease-out); }
  .covers[open] summary::before { transform: rotate(45deg); }

  /* narrow tables (2-3 columns) become stacked rows instead of sideways scrolling */
  .table-wrap.stack { margin-inline: 0; border-radius: var(--radius-lg); border-inline: 1px solid var(--glass-border); overflow: visible; }
  .table-wrap.stack table { min-width: 0 !important; width: 100%; display: block; }
  .table-wrap.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-wrap.stack tbody, .table-wrap.stack tr, .table-wrap.stack td { display: block; }
  .table-wrap.stack tr { padding: var(--space-4); border-top: 1px solid var(--border); }
  .table-wrap.stack tr:first-child { border-top: 0; }
  .table-wrap.stack td { padding: 0; border: 0; min-width: 0 !important; }
  .table-wrap.stack td + td { margin-top: var(--space-3); }
  .table-wrap.stack td:first-child { font-size: var(--text-base); }
  .table-wrap.stack td[data-label]:not(:first-child)::before { content: attr(data-label); display: block; font-family: var(--font-mono); font-size: 0.6875rem; letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--fg-subtle); margin-bottom: 2px; }
}

/* ═════════ phones: centered titles, home hero, section spacing ═════════ */
@media (max-width: 40rem) {
  /* centered titles */
  .hero-copy, .sec-head, .ch-head, .art-top, footer { text-align: center; }
  .hero h1, .ch-head h1, .art-top h2, .hero p, .sec-head p, .ch-head .lede, .art-top .aka { margin-inline: auto; }
  .hero h1 { max-width: 11ch; font-size: clamp(2.5rem, 12vw, 3.25rem); line-height: 1.02; }
  .hero p, .sec-head p { max-width: 32ch; }
  .crumbs, .facts, .jump-chips, .ch-head .eyebrow { justify-content: center; }
  .hero-copy .row { justify-content: center; }
  .ch-head, .art-top { justify-items: center; }
  .art-top .aka { text-align: center; }
  .sec-head h2 { font-size: var(--text-3xl); line-height: 1.1; }

  /* home hero */
  .hero { padding-block: var(--space-10) var(--space-8); }
  .hero-grid { gap: var(--space-8); }
  .hero p { margin-top: var(--space-4); }
  .hero-copy .row { margin-top: var(--space-6); }
  .hero-copy .row .btn { flex: 1 1 9rem; max-width: 14rem; }
  .jump dl { gap: var(--space-4); text-align: left; }
  .jump { text-align: left; }

  /* section spacing: one rhythm */
  .section, .section[id] { padding-top: var(--space-10) !important; padding-bottom: var(--space-6); }
  .sec-head { margin-bottom: var(--space-6); display: grid; gap: var(--space-3); }
  .sec-head h2, .sec-head p { margin: 0 auto; }
}
@media (max-width: 40rem) {
  .jump, .jump > * { text-align: left; justify-self: stretch; margin-inline: 0; }
  .jump .note { padding-inline: 0; max-width: none; }
  .hero { padding-top: var(--space-12); }
}
@media (max-width: 40rem) { .hero .jump p { margin: 0; max-width: none; font-size: inherit; text-align: left; } .hero .jump .eyebrow { font-size: var(--text-xs); } .hero .jump .note { margin-top: 0; font-size: var(--text-sm); } }


/* ═════════ review fixes ═════════ */
/* buttons that are links must not be underlined */
a.btn, a.btn:hover { text-decoration: none; }
.lid { font-family: var(--font-mono); font-size: 0.85em; color: var(--accent-text); margin-right: 0.35em; }

/* article rail: compact top line, no stretched gaps, foldable on small screens */
.art-info { align-content: start; gap: var(--space-4); }
.art-info .rail-top { display: grid; gap: var(--space-2); }
.art-info .rail-line { margin: 0; font-size: var(--text-sm); color: var(--fg-muted); line-height: 1.4; }
.rail-more > summary { display: none; }
.rail-body { display: grid; gap: var(--space-5); }
@media (max-width: 85rem) {
  .art-info { gap: var(--space-3); padding: var(--space-4) var(--space-5); margin-bottom: var(--space-6); }
  .rail-more > summary { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); cursor: pointer; list-style: none; min-height: 2.75rem; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--accent-text); }
  .rail-more > summary::-webkit-details-marker { display: none; }
  .rail-more > summary::after { content: ""; width: 0.5rem; height: 0.5rem; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform var(--dur-fast) var(--ease-out); flex: none; }
  .rail-more[open] > summary::after { transform: rotate(45deg); }
  .rail-more[open] > summary { padding-bottom: var(--space-2); }
}

/* chapters without an article of their own */
.ch-layout.no-side { grid-template-columns: minmax(0, 1fr); }
.ch-layout.no-side .ch-body { max-width: 56rem; }
.empty { padding: 0 0 var(--space-4); color: var(--fg-muted); max-width: 60ch; }
.also { margin-top: var(--space-6); display: grid; gap: var(--space-4); }
.also-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr)); gap: var(--space-4); }
.also-grid .card { display: grid; gap: var(--space-2); padding: var(--space-5); text-decoration: none; color: var(--fg); align-content: start; }
.also-grid .card strong { font-weight: var(--weight-medium); line-height: 1.3; }
.ch-layout.no-side .covers { margin-top: var(--space-6); border-top: 0; padding-top: 0; }

/* glossary: definition first, labels quieter */
.term .prose > * + * { margin-top: var(--space-2); }
.term .prose p { max-width: 80ch; }
.term .prose .tm { font-size: var(--text-sm); color: var(--fg-muted); line-height: 1.55; }
.term .prose .tm > span { font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--fg-subtle); margin-right: var(--space-2); }
.term .prose .tm:first-of-type { margin-top: var(--space-3); }

/* reference and method pages: let the text and tables use the width */
.ch-body > .prose { max-width: none; }
.ch-body > .prose > p, .ch-body > .prose > ul, .ch-body > .prose > ol, .ch-body > .prose > blockquote { max-width: 88ch; }
.ch-body > .prose h2 { margin-top: var(--space-12); }
.ch-body > .prose table { width: 100%; min-width: 0; }
input[type="checkbox"][disabled] { width: 1rem; height: 1rem; margin: 0 var(--space-2) 0 0; vertical-align: -2px; accent-color: var(--accent); }

/* tap targets and breadcrumbs on touch screens */
@media (max-width: 40rem) {
  .top .brand { padding-block: 0.75rem; }
  .crumbs a, .crumbs span { padding-block: 0.4rem; }
  .crumbs { row-gap: 0; }
  .ch-facts { justify-content: center; }
  .ch-facts .badge { font-size: var(--text-xs); padding: 0.35rem 0.75rem; }
  .ch-head--band { gap: var(--space-3); padding-top: var(--space-4); }
  .ch-head--band .ch-title { justify-items: center; }
}
/* tables inside the sources fold stay inside their card, on every screen */
.apparatus .sec .prose .table-wrap { margin-inline: 0; border-radius: var(--radius-lg); border-inline: 1px solid var(--glass-border); }

/* small touch-target and card polish */
.also-grid .card .badge { justify-self: start; }
@media (max-width: 40rem) { .crumbs a, .crumbs span { padding-block: 0.55rem; } }

/* heading anchors appear for keyboard users too */
.prose .anchor:focus-visible, .sec > h3 .anchor:focus-visible, .art-top h2 .anchor:focus-visible, .term h3 .anchor:focus-visible { opacity: 1; }
@media (max-width: 40rem) { .ch-facts a.badge { display: inline-flex; align-items: center; min-height: 2.5rem; } }

/* content first: on narrow screens drop everything between the top bar and the text */
@media (max-width: 85rem) {
  .ch-head .crumbs, .ch-head .ch-facts, .ch-head .jump-chips { display: none; }
  .ch-head--band { padding-block: var(--space-4) var(--space-2); }
  .ch-head--band .ch-title { width: 100%; justify-items: center; }
  .ch-head--band h1 { margin-inline: auto; text-align: center; font-size: var(--text-xl); line-height: 1.2; color: var(--fg-muted); font-weight: var(--weight-medium); }
  .ch-layout > .ch-body > .ch-art > .art-top { padding-bottom: var(--space-2); }
  .art-info { padding: 0; background: none; border: 0; box-shadow: none; backdrop-filter: none; margin-bottom: var(--space-4); }
  .rail-more > summary { justify-content: center; gap: var(--space-2); min-height: 2.25rem; }
  .rail-more > summary::after { margin-left: var(--space-1); }
}

/* download row inside the article info panel */
.art-info .dl-links { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.art-info .dl-links .chip { cursor: pointer; font: inherit; font-size: var(--text-sm); text-decoration: none; display: inline-flex; align-items: center; min-height: 2.5rem; border-radius: var(--radius-full); padding: 0.4rem 0.9rem; }
.art-info .dl-links button.chip { appearance: none; -webkit-appearance: none; background: transparent; color: var(--fg); border: 1px solid var(--border-strong); }
.art-info .dl-links button.chip[data-saved="1"] { background: var(--accent-subtle); color: var(--accent-text); }

/* print: plain reading copy */
@media print {
  @page { margin: 18mm 16mm; }
  :root, :root[data-theme] { --ambient: none; }
  html, body, body::before, body::after { background: #fff !important; background-image: none !important; color: #000 !important; }
  .ch-head--band .ch-title { width: auto !important; justify-items: start !important; }
  .ch-head--band { border: 0 !important; }
  body { font: 11pt/1.5 Georgia, "Times New Roman", serif; }
  .top, .side, .art-info, .crumbs, .ch-facts, .jump-chips, .pn, footer, .covers, .anchor, #toc, .theme, [data-theme-set], .reading-progress, .toc-drawer, .search-overlay { display: none !important; }
  .container-inner, .ch-layout, .ch-body, .ch-art, .art-text { display: block !important; max-width: none !important; width: auto !important; padding: 0 !important; margin: 0 !important; box-shadow: none !important; background: none !important; }
  .ch-head--band { display: block !important; padding: 0 0 8mm !important; text-align: left; }
  .ch-head--band h1 { font-size: 22pt !important; color: #000 !important; text-align: left !important; margin: 0 !important; }
  .ch-art { break-before: page; }
  .ch-art:first-of-type { break-before: auto; }
  .art-top h2 { font-size: 18pt !important; text-align: left !important; color: #000 !important; }
  .sec > h3, .prose h4 { break-after: avoid; color: #000 !important; }
  .prose p, .prose li { orphans: 3; widows: 3; }
  .prose table, .prose pre, .prose figure, .katex-display { break-inside: avoid; }
  .prose a { color: #000 !important; text-decoration: underline; }
  .prose a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 9pt; word-break: break-all; }
  details.apparatus > summary { font-weight: 600; }
  * { animation: none !important; transition: none !important; backdrop-filter: none !important; }
}

.linkbtn { all: unset; cursor: pointer; color: var(--accent-text); text-decoration: underline; text-underline-offset: 0.2em; }
.linkbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.art-info .dl-links .chip[data-saved="1"] { background: var(--accent-subtle); color: var(--accent-text); }

/* ═════════ phone home hero: one centred column, short copy, two equal buttons, compact stats (authoritative, keep last) ═════════ */
.show-m { display: none !important; }
@media (max-width: 40rem) {
  .hide-m { display: none !important; }
  .show-m { display: inline-flex !important; }
  .hero { padding-block: var(--space-8) var(--space-4); }
  .hero-grid { gap: var(--space-6); justify-items: center; }
  .hero-copy { display: grid; justify-items: center; text-align: center; width: 100%; }
  .hero h1 { max-width: 12ch; font-size: clamp(2.25rem, 10.5vw, 2.75rem); line-height: 1.05; text-wrap: balance; margin: 0 auto; }
  .hero-copy > p { max-width: 28ch; margin: var(--space-4) auto 0; font-size: 1.125rem; line-height: 1.55; text-wrap: balance; }
  .hero-copy .row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); width: 100%; max-width: 22rem; margin: var(--space-6) auto 0; }
  .hero-copy .row .btn { flex: none; max-width: none; width: 100%; justify-content: center; min-height: 3rem; padding-inline: var(--space-3); }
  .hero .jump { width: 100%; max-width: 22rem; padding: var(--space-4) var(--space-4) var(--space-5); gap: var(--space-3); text-align: center; justify-items: center; }
  .hero .jump > * { text-align: center; justify-self: center; }
  .hero .jump .eyebrow { text-align: center; }
  .hero .jump dl { width: 100%; grid-template-columns: 1fr 1fr; gap: var(--space-4) var(--space-3); text-align: center; }
  .hero .jump dd { font-size: var(--text-2xl); margin-top: 2px; }
  .hero .jump dt { font-size: 0.6875rem; letter-spacing: 0.08em; }
  .hero .jump .note { text-align: center; font-size: var(--text-xs); line-height: 1.5; padding-top: var(--space-3); max-width: 30ch; }
}

/* skip link: first tab stop, visible only on focus */
.skip { position: fixed; left: var(--space-3); top: -4rem; z-index: 1000; padding: var(--space-2) var(--space-4); background: var(--bg-inverse); color: var(--fg-inverse, var(--bg)); border-radius: var(--radius-md, 8px); font-weight: 600; text-decoration: none; }
.skip:focus { top: var(--space-3); outline: 2px solid var(--accent); outline-offset: 2px; }

.nf-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, max-content)); gap: var(--space-3); margin-top: var(--space-5); }
@media (max-width: 40rem) { .nf-actions { grid-template-columns: 1fr 1fr; } .nf-actions .btn { justify-content: center; } }

/* phone: footer links and the offline button get a 44px touch target */
@media (max-width: 40rem) {
  footer a, footer .linkbtn { display: inline-block; padding-block: 11px; }
}

/* phone: the hero "How claims are graded" link gets a 44px hit area without shifting the text */
@media (max-width: 40rem) {
  .hero .jump .note a { display: inline-block; padding-block: 15px; margin-block: -15px; }
}
