:root {
  --bg: #faf7f0;
  --bg-panel: #f2ede2;
  --ink: #2b2620;
  --ink-soft: #6b6157;
  --accent: #8b2c2c;
  --rule: #d8cfbf;
  --it-col: #4a4238;
  --note-linguistic: #2b5f8a;
  --note-musical: #2e6e46;
  --note-historical: #9a6511;
  --note-esoteric: #6d3f8e;
  --note-editorial: #6b6157;
  --serif: "Iowan Old Style", "Palatino", "Palatino Linotype", Georgia, serif;
  --sans: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191613;
    --bg-panel: #221e19;
    --ink: #e8e1d5;
    --ink-soft: #a3988a;
    --accent: #d98f6d;
    --rule: #3a342c;
    --it-col: #c4b8a5;
    --note-linguistic: #7fb3dd;
    --note-musical: #83c79b;
    --note-historical: #ddb265;
    --note-esoteric: #bb95d8;
    --note-editorial: #a3988a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--serif);
  min-height: 100dvh; display: flex; flex-direction: column; }

.nav-open { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

#topbar {
  flex: none; display: flex; align-items: center; gap: .75rem;
  padding: .4rem 1rem; background: var(--bg-panel);
  border-bottom: 1px solid var(--rule); font-family: var(--sans); z-index: 12;
}
#toggle-contents {
  font: inherit; font-size: 1.05rem; line-height: 1; padding: .25rem .5rem;
  border: 1px solid var(--rule); background: var(--bg); color: var(--ink);
  border-radius: 6px; cursor: pointer; user-select: none;
}
#nav-open:checked ~ #topbar #toggle-contents,
#toggle-contents[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.top-brand { color: var(--ink); font-style: italic; font-family: var(--serif); font-size: 1rem; white-space: nowrap; }
.top-brand:hover { text-decoration: none; color: var(--accent); }
#topnav { display: flex; flex-wrap: wrap; gap: .15rem .1rem; margin-left: auto; }
#topnav a {
  color: var(--ink-soft); padding: .28rem .7rem; border-radius: 999px; font-size: .82rem;
}
#topnav a:hover { text-decoration: none; background: var(--rule); color: var(--ink); }
#topnav a.on { background: var(--accent); color: var(--bg); }

#app {
  display: grid; grid-template-columns: 270px minmax(0, 1fr) auto;
  flex: 1 1 auto; min-height: 0;
  height: calc(100dvh - 48px);
}
#nav-open:not(:checked) ~ #app,
#app.contents-off { grid-template-columns: 0 minmax(0, 1fr) auto; }
#nav-open:not(:checked) ~ #app #sidebar,
#app.contents-off #sidebar { overflow: hidden; padding: 0; border: 0; }
#boot-error { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

#sidebar {
  background: var(--bg-panel); border-right: 1px solid var(--rule);
  overflow-y: auto; padding: 1.2rem 1rem; display: flex; flex-direction: column;
}
.brand h1 { font-size: 1.15rem; margin: 0 0 .3rem; line-height: 1.25; font-style: italic; }
.brand h1 a { color: var(--ink); }
.brand .byline { font-size: .78rem; color: var(--ink-soft); margin: 0 0 1rem; line-height: 1.4; }
#nav { flex: 1; }
#nav .group { font-family: var(--sans); font-size: .68rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-soft); margin: .9rem 0 .3rem; }
#nav a.doc {
  display: flex; align-items: baseline; gap: .45rem;
  padding: .22rem .4rem; border-radius: 5px; font-size: .86rem; color: var(--ink);
  line-height: 1.25;
}
#nav a.doc:hover { background: var(--rule); text-decoration: none; }
#nav a.doc.active { background: var(--accent); color: var(--bg); }
#nav .num {
  flex: none; width: 1.55em; font-family: var(--sans); font-size: .68rem;
  font-variant-numeric: tabular-nums; letter-spacing: .02em;
  color: var(--ink-soft); text-align: right; line-height: 1.25;
}
#nav a.doc.active .num { color: inherit; opacity: .8; }
.side-foot { font-family: var(--sans); font-size: .75rem; margin-top: 1rem; color: var(--ink-soft); }

#main { overflow-y: auto; padding: 0; min-width: 0; min-height: 0; }
.toolbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  border-bottom: 1px solid var(--rule); padding: .55rem 1.4rem;
  display: flex; gap: 1rem; align-items: center; flex-wrap: wrap;
  font-family: var(--sans); font-size: .8rem;
}
.toolbar .modes button, .toolbar .filters button {
  background: none; border: 1px solid var(--rule); color: var(--ink-soft);
  padding: .22rem .6rem; cursor: pointer; font: inherit; border-radius: 999px;
}
.toolbar .modes button.on, .toolbar .filters button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.toolbar .filters button.on.t-linguistic { background: var(--note-linguistic); border-color: var(--note-linguistic); }
.toolbar .filters button.on.t-musical { background: var(--note-musical); border-color: var(--note-musical); }
.toolbar .filters button.on.t-historical { background: var(--note-historical); border-color: var(--note-historical); }
.toolbar .filters button.on.t-esoteric { background: var(--note-esoteric); border-color: var(--note-esoteric); }
.toolbar .filters button.on.t-editorial { background: var(--note-editorial); border-color: var(--note-editorial); }

.reader { max-width: 1160px; margin: 0 auto; padding: 1.6rem 1.6rem 6rem; }
.doc-title { text-align: center; margin: 1rem 0 2rem; }
.doc-title .muse { font-size: 1rem; letter-spacing: .35em; color: var(--accent);
  text-transform: uppercase; font-family: var(--sans); }
.doc-title h2 { font-size: 1.7rem; margin: .2rem 0; font-weight: 500; }

.unit { display: grid; grid-template-columns: 1fr 1fr; gap: 2.2rem; padding: .45rem 0; }
.unit:target, .unit.flash { animation: flash 2.2s ease-out; }
@keyframes flash { 0% { background: color-mix(in srgb, var(--accent) 22%, transparent); } 100% { background: none; } }
.mode-en .unit { grid-template-columns: 1fr; }
.mode-en .unit .it { display: none; }
.mode-it .unit { grid-template-columns: 1fr; }
.mode-it .unit .en { display: none; }
.unit .it { color: var(--it-col); font-size: .95rem; line-height: 1.62; }
.unit .en { font-size: 1rem; line-height: 1.62; }
.unit .en.pending { color: var(--ink-soft); font-style: italic; font-size: .9rem; }

.unit.u-heading { grid-template-columns: 1fr; text-align: center; padding: 1.4rem 0 .2rem; }
.unit.u-heading .it { font-size: 1.25rem; color: var(--ink); font-variant: small-caps;
  letter-spacing: .08em; }
.unit.u-heading .en { display: none; }
.unit.u-subtitle { grid-template-columns: 1fr 1fr; text-align: center; padding-bottom: 1rem; }
.unit.u-subtitle .it, .unit.u-subtitle .en { font-style: italic; }
.unit.u-centered { text-align: center; }
.unit.u-item { padding: .12rem 0; }
.unit.u-item .it, .unit.u-item .en { line-height: 1.45; font-size: .92rem; }
.ed-page-marker {
  grid-column: 1 / -1; text-align: right; font-family: var(--sans);
  font-size: .68rem; color: var(--ink-soft); border-top: 1px dashed var(--rule);
  padding-top: .2rem; margin-top: .6rem;
}
.ed-page-marker a { color: inherit; }

sup.fnref { color: var(--note-editorial); cursor: pointer; font-size: .68em; }
sup.noteref { cursor: pointer; font-weight: 700; font-size: .72em; margin-left: .15em; }
sup.noteref.t-linguistic { color: var(--note-linguistic); }
sup.noteref.t-musical { color: var(--note-musical); }
sup.noteref.t-historical { color: var(--note-historical); }
sup.noteref.t-esoteric { color: var(--note-esoteric); }
.hide-linguistic sup.noteref.t-linguistic, .hide-musical sup.noteref.t-musical,
.hide-historical sup.noteref.t-historical, .hide-esoteric sup.noteref.t-esoteric { display: none; }

#notepanel {
  width: 340px; border-left: 1px solid var(--rule); background: var(--bg-panel);
  overflow-y: auto; padding: 1rem 1.1rem;
}
#notepanel h3 { font-family: var(--sans); font-size: .75rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-soft); margin: 0 0 .6rem;
  display: flex; justify-content: space-between; }
#notepanel h3 button { background: none; border: none; cursor: pointer; color: var(--ink-soft); font-size: 1rem; }
.note { margin-bottom: .9rem; padding-left: .7rem; border-left: 3px solid var(--rule);
  font-size: .86rem; line-height: 1.5; }
.note .tag { font-family: var(--sans); font-size: .64rem; letter-spacing: .1em;
  text-transform: uppercase; display: block; margin-bottom: .15rem; }
.note.t-linguistic { border-color: var(--note-linguistic); } .note.t-linguistic .tag { color: var(--note-linguistic); }
.note.t-musical { border-color: var(--note-musical); } .note.t-musical .tag { color: var(--note-musical); }
.note.t-historical { border-color: var(--note-historical); } .note.t-historical .tag { color: var(--note-historical); }
.note.t-esoteric { border-color: var(--note-esoteric); } .note.t-esoteric .tag { color: var(--note-esoteric); }
.note.t-editorial { border-color: var(--note-editorial); } .note.t-editorial .tag { color: var(--note-editorial); }
.note .src { color: var(--ink-soft); font-size: .78rem; display: block; margin-top: .2rem; }

.fnsection { margin-top: 3rem; border-top: 1px solid var(--rule); padding-top: 1rem; }
.fnsection h4 { font-family: var(--sans); font-size: .72rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-soft); }
.fnsection .fn { font-size: .82rem; color: var(--ink-soft); line-height: 1.5; margin: .35rem 0; }
.fnsection .fn b { color: var(--ink); }
.fnsection .fn .fn-en { display: block; color: var(--ink); margin-left: 1.2rem; }

.facsimile { text-align: center; padding: 1rem; }
.facsimile img { max-width: 100%; max-height: 86vh; box-shadow: 0 4px 24px rgba(0,0,0,.25);
  border-radius: 4px; }
.facsimile .fac-nav { font-family: var(--sans); font-size: .85rem; margin: .6rem; }
.facsimile .fac-nav button { font: inherit; padding: .3rem .8rem; margin: 0 .4rem;
  border: 1px solid var(--rule); background: var(--bg-panel); color: var(--ink);
  cursor: pointer; border-radius: 6px; }

.page { max-width: 780px; margin: 0 auto; padding: 2rem 1.6rem 6rem; }
.page h2 { font-weight: 500; }
.page .lead { font-size: 1.05rem; line-height: 1.7; }
.searchbox { width: 100%; font: inherit; font-size: 1.05rem; padding: .6rem .8rem;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--bg-panel);
  color: var(--ink); margin-bottom: 1.2rem; }
.result { margin-bottom: 1.1rem; }
.result .where { font-family: var(--sans); font-size: .7rem; color: var(--ink-soft);
  letter-spacing: .06em; text-transform: uppercase; }
.result .snip { font-size: .92rem; line-height: 1.5; }
.result mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit;
  border-radius: 2px; padding: 0 2px; }

.gloss-entry { margin-bottom: 1rem; }
.gloss-entry dt { font-weight: 700; font-style: italic; }
.gloss-entry dd { margin: .15rem 0 0 1.2rem; font-size: .92rem; line-height: 1.5; }
.gloss-entry .ren { color: var(--accent); font-style: normal; font-weight: 400; }

.progress-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.progress-table th, .progress-table td { text-align: left; padding: .45rem .5rem;
  border-bottom: 1px solid var(--rule); }
.progress-table th { font-family: var(--sans); font-size: .7rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-soft); }
.bar { background: var(--rule); border-radius: 999px; height: 8px; width: 130px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--note-musical); }

.page.wide { max-width: 920px; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .4rem 0 1rem; }
.chips.sort, .chips.facet { margin-top: -.4rem; }
.chip {
  font-family: var(--sans); font-size: .78rem; padding: .22rem .7rem;
  border: 1px solid var(--rule); border-radius: 999px; color: var(--ink-soft);
}
.chip:hover { text-decoration: none; background: var(--rule); color: var(--ink); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.with-help { display: flex; align-items: baseline; gap: .5rem; }
.help-wrap { position: relative; display: inline-flex; }
.help {
  font-family: var(--sans); font-size: .72rem; font-weight: 600;
  width: 1.2rem; height: 1.2rem; padding: 0; border-radius: 50%;
  border: 1px solid var(--rule); background: var(--bg-panel); color: var(--ink-soft);
  cursor: pointer; line-height: 1.15; flex: none;
}
.help:hover, .help-wrap.open .help { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.help-pop {
  display: none; position: absolute; left: 0; top: calc(100% + .4rem); z-index: 8;
  width: min(28rem, 70vw); padding: .7rem .85rem; border-radius: 8px;
  background: var(--bg-panel); border: 1px solid var(--rule); color: var(--ink-soft);
  font-family: var(--sans); font-size: .8rem; line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.help-wrap:hover .help-pop, .help-wrap.open .help-pop { display: block; }
.idx-blurb { color: var(--ink-soft); font-size: .9rem; }
.letter-nav { font-family: var(--sans); font-size: .78rem; word-spacing: .45rem; margin: .4rem 0 1rem; }
.letter-nav a { color: var(--ink-soft); }
.let { font-family: var(--sans); font-size: .75rem; letter-spacing: .14em; color: var(--accent);
  margin: 1.1rem 0 .35rem; border-bottom: 1px solid var(--rule); }
.idx-row { display: grid; grid-template-columns: minmax(10rem, 1fr) minmax(8rem, 1.2fr);
  gap: .6rem; padding: .28rem 0; font-size: .92rem; line-height: 1.4; }
.idx-name .sub { color: var(--ink-soft); font-size: .82rem; }
.idx-refs { color: var(--ink-soft); font-family: var(--sans); font-size: .8rem; }
.iref { margin-right: .15rem; }
.iref.intro { color: var(--ink-soft); cursor: help; }

.qlist { display: flex; flex-direction: column; gap: 1.2rem; }
.qcard { background: var(--bg-panel); border: 1px solid var(--rule); border-radius: 10px; padding: 1rem 1.15rem; }
.qcard blockquote { margin: 0 0 .8rem; font-size: 1.02rem; line-height: 1.55; }
.qcard footer { font-family: var(--sans); font-size: .8rem; color: var(--ink-soft); }
.qwho { color: var(--ink); margin-bottom: .2rem; }
.qhill { font-style: italic; margin-top: .15rem; }
.qtags { margin-top: .4rem; display: flex; gap: .3rem; flex-wrap: wrap; }
.qtags .tag { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase;
  border: 1px solid var(--rule); padding: .1rem .45rem; border-radius: 999px; }

.timeline-page { max-width: 820px; }
.tl-spine { display: flex; flex-direction: column; gap: 1.1rem; position: relative;
  padding-left: 1.4rem; border-left: 2px solid var(--rule); margin-top: 1.4rem; }
.tl-card {
  position: relative; overflow: hidden; border-radius: 12px; min-height: 11rem;
  color: #f4efe6; padding: 1.1rem 1.2rem 1.3rem;
  background: #1a1612;
  box-shadow: 0 6px 22px rgba(0,0,0,.18);
  transition: transform .25s ease, box-shadow .25s ease;
}
.tl-photo {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: center;
  filter: saturate(.85) contrast(1.05);
}
.tl-card::before {
  content: ""; position: absolute; left: -1.55rem; top: 1.35rem;
  width: .7rem; height: .7rem; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-panel);
  z-index: 2;
}
.tl-shade {
  position: absolute; inset: 0; z-index: 1;
  background: linear-gradient(90deg, rgba(18,14,10,.82) 0%, rgba(18,14,10,.55) 55%, rgba(18,14,10,.28) 100%);
  transition: background .25s ease;
}
.tl-card:hover, .tl-card.focus {
  transform: translateY(-2px);
  box-shadow: 0 10px 32px rgba(0,0,0,.28);
}
.tl-card:hover .tl-shade, .tl-card.focus .tl-shade {
  background: linear-gradient(90deg, rgba(18,14,10,.7) 0%, rgba(18,14,10,.38) 60%, rgba(18,14,10,.18) 100%);
}
.tl-card h3, .tl-card p, .tl-card .tl-meta { position: relative; z-index: 2; }
.tl-card h3 { margin: .25rem 0 .45rem; font-weight: 500; font-size: 1.25rem; }
.tl-meta { display: flex; gap: .6rem; flex-wrap: wrap; font-family: var(--sans);
  font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; opacity: .9; }
.tl-note { margin: 0; line-height: 1.5; font-size: .95rem; max-width: 46rem; }
.tl-src, .tl-credit { margin: .45rem 0 0; font-family: var(--sans); font-size: .72rem; opacity: .8; }
.tl-credit { opacity: .6; }

@media (max-width: 1100px) {
  #app { grid-template-columns: minmax(0, 1fr); height: calc(100dvh - 48px); }
  #nav-open:not(:checked) ~ #app,
  #app.contents-off { grid-template-columns: minmax(0, 1fr); }
  #sidebar { display: none; }
  #nav-open:checked ~ #app #sidebar,
  #app:not(.contents-off) #sidebar { display: block; position: absolute; z-index: 11;
    height: calc(100dvh - 48px); width: min(270px, 90vw); }
  #notepanel { position: fixed; right: 0; top: 0; height: 100vh; z-index: 20; }
  .top-brand { display: none; }
  .idx-row { grid-template-columns: 1fr; }
}
@media print {
  #sidebar, .toolbar, #notepanel { display: none !important; }
  #app { display: block; }
  .unit { break-inside: avoid; }
}
