:root {
  --paper: #f6f1e7;
  --paper-2: #efe7d8;
  --card: #fffdf8;
  --ink: #221e19;
  --ink-2: #4a433a;
  --muted: #6f665a;
  --rule: #dcd2c1;
  --rubric: #9b2c1c;
  --rubric-soft: #9b2c1c1f;
  --hl: #f0d98a66;
  --amber: #8a5a00;
  --blue: #1f5a8a;
  --green: #2e6b3a;
  --shadow: 0 10px 30px #2a20141f, 0 2px 6px #2a201414;
  --la: "EB Garamond", "Garamond", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --en: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --bar-h: 3rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #191714; --paper-2: #221f1a; --card: #26221c; --ink: #ebe4d6; --ink-2: #cfc6b6; --muted: #a2988a;
    --rule: #3b352d; --rubric: #e38a72; --rubric-soft: #e38a7226; --hl: #8a6d1a66; --amber: #e0b35a;
    --blue: #8dbbe6; --green: #8fcf9b; --shadow: 0 10px 30px #0008; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #191714; --paper-2: #221f1a; --card: #26221c; --ink: #ebe4d6; --ink-2: #cfc6b6; --muted: #a2988a;
  --rule: #3b352d; --rubric: #e38a72; --rubric-soft: #e38a7226; --hl: #8a6d1a66; --amber: #e0b35a;
  --blue: #8dbbe6; --green: #8fcf9b; --shadow: 0 10px 30px #0008; 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(--en); }
a { color: var(--rubric); text-underline-offset: 0.15em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--rubric); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- masthead ---------- */
.masthead {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.4rem 1.5rem;
  padding: 1.1rem clamp(16px, 3vw, 40px) 0.9rem; border-bottom: 1px solid var(--rule);
}
.brand { text-decoration: none; color: var(--ink); display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.8rem; }
.brand-la { font: italic 500 1.45rem/1.1 var(--la); letter-spacing: 0.005em; }
.brand-sub { font: 500 0.78rem/1 var(--ui); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.topnav { display: flex; gap: 1.2rem; font: 0.88rem/1.3 var(--ui); }
.topnav a { color: var(--ink-2); text-decoration: none; }
.topnav a:hover { color: var(--rubric); }

/* ---------- toolbar ---------- */
.toolbar {
  position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.2rem;
  min-height: var(--bar-h); padding: 0.45rem clamp(16px, 3vw, 40px);
  background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule); font: 0.82rem/1 var(--ui);
}
.seg { display: inline-flex; align-items: center; border: 1px solid var(--rule); border-radius: 999px; padding: 2px; background: var(--card); }
.seg-label { padding: 0 0.55rem 0 0.7rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.7rem; }
.seg button, .toggle-img {
  border: 0; background: none; padding: 0.38rem 0.75rem; border-radius: 999px; cursor: pointer; color: var(--ink-2);
}
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.toggle-img { border: 1px solid var(--rule); background: var(--card); margin-left: auto; }
.toggle-img[aria-pressed="true"] { border-color: var(--ink); }
.toggle-img::before { content: "▣ "; }

/* ---------- chapter layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) clamp(300px, 31vw, 520px); gap: clamp(1.5rem, 3vw, 3rem);
  max-width: 1680px; margin: 0 auto; padding: 0 clamp(16px, 3vw, 40px) 4rem;
}
body.no-img .layout { grid-template-columns: minmax(0, 1fr); max-width: 1180px; }
body.no-img .page-panel { display: none; }

.chapter-head { padding: 2.2rem 0 1.4rem; max-width: 60rem; }
.kicker { font: 500 0.74rem/1.4 var(--ui); letter-spacing: 0.1em; text-transform: uppercase; color: var(--rubric); margin: 0 0 0.6rem; }
.chapter-head h1 { font: 500 clamp(2rem, 4vw, 2.9rem)/1.05 var(--la); margin: 0; letter-spacing: 0.005em; }
.chapter-en { font: italic 1.15rem/1.4 var(--en); color: var(--ink-2); margin: 0.5rem 0 1.4rem; }
.draft-note {
  border: 1px solid var(--rule); background: var(--card); padding: 0.8rem 1.1rem; border-radius: 6px;
  font: 0.92rem/1.55 var(--en); color: var(--ink-2); max-width: 52rem;
}
.draft-note p { margin: 0; }

.unit {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(1.2rem, 2.5vw, 2.6rem);
  padding: 1.3rem 0 1.4rem; border-top: 1px solid var(--rule); scroll-margin-top: calc(var(--bar-h) + 1rem);
}
.unit.cont { border-top: 1px dashed var(--rule); }
.unit:target, .unit.flash { background: linear-gradient(90deg, var(--rubric-soft), transparent 70%); }
body.cols-la .unit, body.cols-en .unit { grid-template-columns: minmax(0, 1fr); max-width: 46rem; }
body.cols-la .en, body.cols-en .la { display: none; }

/* EB Garamond's 'LAT ' language system draws u as V; tools/patch_fonts.py removes it from site/fonts */
.la { font: 1.2rem/1.55 var(--la); position: relative; hyphens: manual; }
.en { font: 1.02rem/1.62 var(--en); }
.en > p { margin: 0; }
.unit-label {
  display: block; font: 600 0.72rem/1 var(--ui); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--rubric); text-decoration: none; margin-bottom: 0.45rem;
}
.unit-label:hover { text-decoration: underline; }
.argument .reading, .argument .diplomatic, .argument .en > p { font-style: italic; }
.argument .la { font-size: 1.12rem; }

body.view-reading .diplomatic, body.view-diplomatic .reading { display: none; }
.la { container-type: inline-size; }
/* one printed line per screen line: never wrap, size the type to the column (a printed line is about 27em) */
.diplomatic { font-size: min(1.08rem, 3.5cqi); line-height: 1.55; white-space: nowrap; overflow-x: auto; font-feature-settings: "liga", "dlig"; }
.diplomatic abbr { text-decoration: underline dotted var(--rubric); text-underline-offset: 0.2em; cursor: help; }
.diplomatic .sic { text-decoration: underline wavy var(--rubric); }
.unclear { background: var(--hl); border-radius: 2px; }
.initial { font-weight: 600; color: var(--rubric); font-size: 1.5em; line-height: 0.8; }
.reading .initial { font-size: 1.3em; }
.margin-note {
  display: inline-block; font: italic 0.8rem/1.2 var(--ui); color: var(--muted); border: 1px solid var(--rule);
  border-radius: 3px; padding: 0 0.3rem; margin: 0 0.2rem;
}
.margin-note::before { content: "margin: "; font-style: normal; }

.folio {
  font: 600 0.68rem/1 var(--ui); letter-spacing: 0.04em; color: var(--rubric); text-decoration: none; white-space: nowrap;
  vertical-align: 0.2em; padding: 0.12rem 0.3rem; margin: 0 0.15rem; border: 1px solid var(--rubric-soft); border-radius: 3px;
  background: var(--card); scroll-margin-top: calc(var(--bar-h) + 3rem);
}
.folio:hover, .folio.current { background: var(--rubric); color: var(--paper); }

.w { cursor: pointer; border-radius: 2px; }
.w:hover { background: var(--hl); }
.w.active { background: var(--rubric-soft); box-shadow: 0 0 0 1px var(--rubric); }

.notes { margin: 0.8rem 0 0; padding-left: 1.3rem; font-size: 0.86rem; line-height: 1.5; color: var(--ink-2); }
.notes a { text-decoration: none; }
.nref { font: 600 0.7em/0 var(--ui); }
.nref a { text-decoration: none; padding: 0 0.1em; }

.queries { margin-top: 0.8rem; font: 0.84rem/1.5 var(--ui); color: var(--ink-2); }
.queries summary { cursor: pointer; color: var(--amber); font-weight: 500; list-style: none; display: inline-flex; align-items: center; gap: 0.4rem; }
.queries summary::-webkit-details-marker { display: none; }
.queries summary::before { content: "?"; display: inline-grid; place-items: center; width: 1.1rem; height: 1.1rem; border-radius: 50%; border: 1px solid currentColor; font-size: 0.7rem; font-weight: 600; }
.queries[open] summary { margin-bottom: 0.3rem; }
.qcount { font-size: 0.72rem; color: var(--muted); font-weight: 400; }
.queries ul { margin: 0; padding-left: 1.2rem; }
.queries li { margin-bottom: 0.3rem; }
.queries i { font-family: var(--la); font-size: 1.08em; }
.unit-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.9rem; margin-top: 0.8rem; font: 0.76rem/1.2 var(--ui); }
.badge { display: inline-block; padding: 0.18rem 0.5rem; border-radius: 999px; border: 1px solid currentColor; font: 500 0.7rem/1.2 var(--ui); letter-spacing: 0.02em; }
.status-ai-draft { color: var(--amber); }
.status-read { color: var(--blue); }
.status-checked, .status-final { color: var(--green); }
.cite, .suggest { border: 0; background: none; padding: 0; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 0.2em; font: inherit; }
.cite:hover, .suggest:hover { color: var(--rubric); }
.how-to-comment { margin-top: 0.5rem !important; font-size: 0.86rem; color: var(--muted); }

/* ---------- page image panel ---------- */
.page-panel { position: sticky; top: calc(var(--bar-h) + 1rem); align-self: start; margin-top: 2.2rem; }
.page-panel figure { margin: 0; }
.page-frame { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 4px; padding: 6px; }
.page-img { display: block; }
.page-img img {
  display: block; width: 100%; height: auto; max-height: calc(100vh - var(--bar-h) - 6.5rem); object-fit: contain;
  border-radius: 2px; background: var(--paper-2);
}
.page-panel figcaption { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0.2rem; font: 0.8rem/1 var(--ui); color: var(--muted); }
.page-label b { color: var(--rubric); font-weight: 600; }
.page-links { display: flex; align-items: center; gap: 0.35rem; }
.page-links button {
  width: 2rem; height: 2rem; border-radius: 50%; border: 1px solid var(--rule); background: var(--card); cursor: pointer; font-size: 1.1rem; line-height: 1;
}
.page-links button:hover { border-color: var(--rubric); color: var(--rubric); }
.page-full { margin-left: 0.4rem; }
.panel-close { display: none; }

/* ---------- word card ---------- */
.wordcard {
  position: absolute; z-index: 40; width: min(22rem, calc(100vw - 32px)); background: var(--card); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 8px; box-shadow: var(--shadow); padding: 0.9rem 1rem 0.8rem; font: 0.88rem/1.45 var(--ui);
}
.wc-close { position: absolute; top: 0.35rem; right: 0.45rem; border: 0; background: none; font-size: 1.3rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 0.2rem 0.4rem; }
.wc-form { font: 500 1.35rem/1.1 var(--la); margin-right: 1.5rem; }
.wc-parse { color: var(--ink-2); margin-top: 0.2rem; }
.wc-lemma { margin-top: 0.6rem; font: 1.02rem/1.3 var(--la); }
.wc-lemma b { font-weight: 600; }
.wc-gloss { margin: 0.3rem 0 0; font: 0.9rem/1.45 var(--en); color: var(--ink); }
.wc-links { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; margin-top: 0.7rem; padding-top: 0.55rem; border-top: 1px solid var(--rule); }
.wc-note { margin: 0.5rem 0 0; font-size: 0.74rem; color: var(--muted); }

/* ---------- prose pages ---------- */
.prose { max-width: 42rem; margin: 0 auto; padding: 2.6rem clamp(16px, 4vw, 24px) 4rem; }
.prose h1 { font: 500 clamp(2rem, 5vw, 2.8rem)/1.1 var(--la); margin: 0 0 0.8rem; }
.home .prose h1 { font-style: italic; }
.prose h2 { font: 600 0.8rem/1.3 var(--ui); letter-spacing: 0.1em; text-transform: uppercase; color: var(--rubric); margin: 2.4rem 0 0.6rem; }
.prose p, .prose li, .prose dd { color: var(--ink); }
.lede { font-size: 1.15rem; color: var(--ink-2); }
.muted { color: var(--muted); font-size: 0.95rem; }
.chapter-list { list-style: none; padding: 0; margin: 1.2rem 0; }
.chapter-list a {
  display: grid; grid-template-columns: 3rem 1fr; gap: 1rem; align-items: start; text-decoration: none; color: var(--ink);
  padding: 1rem 1.1rem; background: var(--card); border: 1px solid var(--rule); border-radius: 6px;
}
.chapter-list a:hover { border-color: var(--rubric); }
.ch-num { font: 500 2rem/1 var(--la); color: var(--rubric); }
.ch-folios { display: block; margin-top: 0.3rem; font: 0.78rem/1 var(--ui); color: var(--muted); }
.statuses { display: grid; grid-template-columns: max-content 1fr; gap: 0.5rem 1rem; align-items: center; }
.statuses dd { margin: 0; }
.refs li { margin-bottom: 0.6rem; }
code { font-size: 0.88em; background: var(--paper-2); padding: 0.05em 0.3em; border-radius: 3px; }

.colophon { border-top: 1px solid var(--rule); padding: 1.4rem clamp(16px, 3vw, 40px) 2.4rem; font: 0.78rem/1.55 var(--ui); color: var(--muted); }
.colophon p { max-width: 60rem; margin: 0 0 0.5rem; }
.colophon a { color: var(--muted); }

/* ---------- narrow screens ---------- */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .unit { grid-template-columns: minmax(0, 1fr); gap: 0.8rem; }
  .en { border-left: 2px solid var(--rule); padding-left: 0.9rem; }
  body.cols-en .en { border-left: 0; padding-left: 0; }
  .page-panel {
    position: fixed; inset: auto 0 0 0; top: auto; z-index: 30; margin: 0; max-height: 62vh; overflow: auto;
    background: var(--paper); border-top: 1px solid var(--rule); box-shadow: var(--shadow); padding: 0.6rem 16px calc(0.6rem + env(safe-area-inset-bottom, 0px));
  }
  .page-img img { max-height: 50vh; }
  .toggle-img { margin-left: 0; }
  .wordcard { position: fixed; left: 16px !important; right: 16px; top: auto !important; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); width: auto; }
}
@media (max-width: 560px) {
  body { font-size: 16px; }
  .la { font-size: 1.12rem; }
  .seg-label { display: none; }
  .brand-la { font-size: 1.25rem; }
}
@media print {
  .toolbar, .page-panel, .unit-meta, .wordcard, .topnav { display: none !important; }
  .layout { display: block; }
}
