/* ============================================================
   Lectiōnārium — print-like reader styling

   Light theme, a book-page reading surface with a slim toolbar and sidebar,
   the bundled ALPHABETUM Unicode font for Latin body text with a serif
   fallback. All five display toggles are CSS classes set on .folio by reader.js
   (hide-macrons, hide-persons, hide-places, plain-quotes, hide-citations).
   ============================================================ */

/* The bundled scholarly Unicode Latin font, served from /static (no CDN). */
@font-face {
  font-family: 'Alphabetum';
  src: url('ALPHABETUMUnicode.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink:        #221d16;
  --ink-soft:   #5a5044;
  --ink-faint:  #8c8170;
  --paper:      #f7f3ec;
  --paper-pure: #fffdf8;
  --rule:       #e3dccd;
  --rule-soft:  #ece5d7;
  --accent:     #7a3b2e;   /* muted Roman red, used sparingly */
  --persons:    #355e4f;   /* quiet green tint for person names */
  --persons-faint: #aac3b8; /* the same green, lightened, for the resting underline */
  --places:     #3a5168;   /* quiet blue tint for place names */
  --places-faint:  #a6b6c6; /* the same blue, lightened, for the resting underline */
  --highlight:  #efe7d6;

  --serif: 'Alphabetum', 'Iowan Old Style', 'Palatino Linotype', Palatino,
           'Book Antiqua', Georgia, 'Times New Roman', serif;
  --ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  --measure: 65ch;
  --toolbar-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ============ Toolbar ============ */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1rem;
  background: var(--paper-pure);
  border-bottom: 1px solid var(--rule);
}

.toolbar-left { display: flex; align-items: center; gap: 0.6rem; }
.toolbar-center { display: flex; align-items: center; gap: 0.45rem; flex: 1; justify-content: center; }
.toolbar-right { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }

.brand {
  font-family: var(--serif);
  font-size: 1.1rem;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.nav-link {
  font-family: var(--ui);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.nav-link:hover { border-color: var(--ink-faint); color: var(--ink); }
.nav-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.picker-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
}

.picker {
  font-family: var(--serif);
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  max-width: 22rem;
}
.picker:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.icon-button:hover { background: var(--rule-soft); color: var(--ink); }
.icon-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.chip {
  font-family: var(--ui);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}
.chip:hover { border-color: var(--ink-faint); }
.chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper-pure);
  border-color: var(--ink);
}
.chip.is-off { opacity: 0.85; }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ============ Layout ============ */

.layout {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 0;
  height: calc(100vh - var(--toolbar-h));
  transition: grid-template-columns 0.18s ease;
}
body.sidebar-collapsed .layout { grid-template-columns: 0 minmax(0, 1fr) 0; }
body.panel-open .layout { grid-template-columns: 270px minmax(0, 1fr) 340px; }
body.sidebar-collapsed.panel-open .layout { grid-template-columns: 0 minmax(0, 1fr) 340px; }

/* ============ Structure sidebar ============ */

.sidebar {
  border-right: 1px solid var(--rule);
  background: var(--paper-pure);
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
}
body.sidebar-collapsed .sidebar { border-right: none; }

.sidebar-head {
  position: sticky;
  top: 0;
  background: var(--paper-pure);
  padding: 0.85rem 1rem 0.55rem;
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--ink);
  border-bottom: 1px solid var(--rule-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree { padding: 0.4rem 0.4rem 2rem; }
.tree-empty { color: var(--ink-faint); font-size: 0.85rem; padding: 0.6rem 0.6rem; }

.tree-row {
  display: flex;
  align-items: baseline;
  gap: 0.15rem;
  padding-left: calc(var(--depth, 0) * 0.85rem);
}

.tree-twisty {
  flex: none;
  width: 18px; height: 18px;
  border: none;
  background: transparent;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 0;
  font-size: 0.7rem;
  line-height: 1;
}
.tree-twisty.is-leaf-twisty { cursor: default; visibility: hidden; }
.twisty-glyph { display: inline-block; transition: transform 0.12s ease; }
.tree-twisty.is-open .twisty-glyph { transform: rotate(90deg); }

.tree-label {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--ink-soft);
  padding: 0.2rem 0.35rem;
  border-radius: 5px;
  font-family: var(--serif);
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  transition: background 0.1s ease, color 0.1s ease;
}
.tree-label:hover { background: var(--rule-soft); color: var(--ink); }
.tree-label:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.tree-label-text { font-size: 0.9rem; white-space: nowrap; }
.tree-label-sub {
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-count {
  margin-left: auto;
  font-family: var(--ui);
  font-size: 0.68rem;
  color: var(--ink-faint);
  background: var(--rule-soft);
  border-radius: 999px;
  padding: 0.02rem 0.4rem;
}

.tree-children.is-collapsed { display: none; }

.tree-node.is-current > .tree-row > .tree-label {
  background: var(--highlight);
  color: var(--ink);
}
.tree-node.is-current > .tree-row > .tree-label .tree-label-text {
  font-weight: 600;
  color: var(--accent);
}

/* ============ Reading surface ============ */

.reader {
  position: relative;
  overflow-y: auto;
  padding: 0 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  outline: none;
}

.runninghead {
  position: sticky;
  top: 0;
  /* Above the folio so scrolled body text cannot show through. The background is
     fully opaque (the former gradient faded to transparent, which let text bleed
     under the strip). */
  z-index: 5;
  width: 100%;
  max-width: var(--measure);
  text-align: right;
  font-family: var(--ui);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  background: var(--paper);
  padding: 0.7rem 0 0.4rem;
  min-height: 1.2rem;
}

.folio {
  width: 100%;
  max-width: var(--measure);
  font-family: var(--serif);
  font-size: 1.32rem;
  line-height: 1.85;
  color: var(--ink);
  padding: 1rem 0 3rem;
  hyphens: none;
  -webkit-hyphens: none;
  /* Own stacking context below the running head so no positioned descendant can
     paint over the sticky strip. */
  position: relative;
  z-index: 0;
}

.folio-empty {
  margin-top: 18vh;
  text-align: center;
  color: var(--ink-soft);
}
.folio-empty-quote {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-style: italic;
  color: var(--ink-faint);
}
.folio-empty-hint {
  font-family: var(--ui);
  font-size: 0.92rem;
  line-height: 1.6;
  max-width: 40ch;
  margin: 1.4rem auto 0;
  color: var(--ink-soft);
}

/* Chapter heading: every page opens with the leaf-parent's label (e.g. 'Chapter 2',
   'Liber 1', 'Speech 2', 'Preface'). The primary structural heading of the page. */
.chapter-heading {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  letter-spacing: 0.01em;
  margin: 0.5rem 0 0.9rem;
  line-height: 1.3;
}
/* When a body title follows the chapter label, tighten the gap between the two. */
.chapter-heading + .chapter-subheading { margin-top: 0; }

/* Section headings (body <title>: florus chapters, aen book titles). Used as the
   secondary title line under a chapter heading, and standalone where applicable. */
.section-heading {
  font-family: var(--serif);
  font-size: 1.18rem;
  font-style: italic;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
  margin: 2.2rem 0 1.1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--rule);
  line-height: 1.4;
}
.section-heading:first-child { margin-top: 0.5rem; }
/* As a chapter subtitle the section heading sits directly beneath the chapter label,
   so its large top margin is dropped. */
.chapter-subheading { margin-top: 0; }

/* A leaf (a citation unit). The margin number sits in a hanging gutter. */
.leaf {
  position: relative;
  padding-left: 2.6rem;
}
.leaf-num {
  position: absolute;
  left: 0;
  top: 0.5rem;
  width: 2.1rem;
  text-align: right;
  font-family: var(--ui);
  font-size: 0.72rem;
  line-height: 1;
  color: var(--ink-faint);
  user-select: none;
  padding-top: 0.18rem;
}
.folio.hide-citations .leaf-num { display: none; }
.folio.hide-citations .leaf { padding-left: 0; }

.leaf-body { margin: 0; }
.para {
  margin: 0 0 0.2rem;
  text-align: justify;
  text-indent: 1.4em;
}
/* The first paragraph of a leaf is not indented (it follows the margin number). */
.leaf-body > .para:first-child { text-indent: 0; }
.para + .para { text-indent: 1.4em; }

/* ============ Inline word tokens ============ */

.word {
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.08s ease, box-shadow 0.08s ease;
}
.word:hover {
  background: var(--highlight);
  box-shadow: 0 1px 0 var(--ink-faint);
}
.word.is-active {
  background: var(--accent);
  color: var(--paper-pure);
}

/* persName / placeName: quiet underline + tint, never loud boxes. */
.persName, .placeName {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}
.persName {
  color: var(--persons);
  text-decoration-color: var(--persons-faint);
}
.placeName {
  color: var(--places);
  text-decoration-color: var(--places-faint);
}
.persName:hover { text-decoration-color: var(--persons); }
.placeName:hover { text-decoration-color: var(--places); }
/* The clickable word spans inside a name inherit its colour, not the hover box. */
.persName .word:hover, .placeName .word:hover { background: transparent; box-shadow: none; }

/* Toggle off: drop the tint and underline, leave plain readable text. */
.folio.hide-persons .persName {
  color: inherit;
  text-decoration: none;
}
.folio.hide-places .placeName {
  color: inherit;
  text-decoration: none;
}

/* Dates: a dotted underline cue, muted. */
.date {
  cursor: pointer;
  border-bottom: 1px dotted var(--ink-faint);
}
.date:hover { border-bottom-color: var(--accent); }
.date .word:hover { background: transparent; box-shadow: none; }

/* Quotations: rendered with marks + a soft slant when on; plain when off. */
.q { font-style: italic; color: var(--ink); }
.q::before { content: '\201C'; }
.q::after  { content: '\201D'; }
.folio.plain-quotes .q { font-style: normal; }
.folio.plain-quotes .q::before,
.folio.plain-quotes .q::after { content: ''; }

/* ============ Pager ============ */

.pager {
  position: sticky;
  bottom: 0;
  width: 100%;
  max-width: var(--measure);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0 1.1rem;
  background: linear-gradient(transparent, var(--paper) 40%);
}

.pager-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--ui);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  background: var(--paper-pure);
  border: 1px solid var(--rule);
  border-radius: 7px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.pager-button:hover:not(:disabled) { border-color: var(--ink-faint); color: var(--ink); }
.pager-button:disabled { opacity: 0.4; cursor: default; }
.pager-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.pager-loc {
  font-family: var(--serif);
  font-size: 0.95rem;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}

/* ============ Detail panel ============ */

.panel {
  border-left: 1px solid var(--rule);
  background: var(--paper-pure);
  overflow-y: auto;
  min-width: 0;
  opacity: 0;
  transition: opacity 0.16s ease;
}
.panel.is-open { opacity: 1; }
/* When closed the grid collapses the column to 0; keep content from spilling. */
body:not(.panel-open) .panel { display: none; }

.panel-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.9rem 0.6rem;
  background: var(--paper-pure);
  border-bottom: 1px solid var(--rule-soft);
}
.panel-kicker {
  font-family: var(--ui);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
}
.panel-body { padding: 0.9rem 0.95rem 2rem; }
.panel-message { color: var(--ink-faint); font-size: 0.88rem; }

/* Parse cards. */
.parse-card {
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.8rem 0.9rem;
  margin-bottom: 0.8rem;
  background: var(--paper);
}
.parse-card-head { display: flex; align-items: baseline; gap: 0.4rem; }
.parse-headword {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.4rem;
  color: var(--ink);
}
.parse-enclitic { font-family: var(--serif); font-size: 1rem; color: var(--ink-faint); }

.parse-meta {
  margin: 0.35rem 0 0.55rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
}
.parse-pos {
  font-variant: small-caps;
  letter-spacing: 0.04em;
  color: var(--accent);
  font-weight: 600;
}
.parse-class { color: var(--ink-soft); }
.parse-def { font-style: italic; color: var(--ink-soft); }
.parse-def::before { content: '· '; color: var(--ink-faint); font-style: normal; }

.parse-forms { list-style: none; margin: 0; padding: 0; }
.parse-forms li {
  padding: 0.22rem 0;
  border-top: 1px solid var(--rule-soft);
  font-size: 0.82rem;
}
.feat-tag {
  font-family: var(--ui);
  color: var(--ink);
}
.feat-sep { color: var(--ink-faint); margin: 0 0.25rem; }

.parse-empty { font-family: var(--serif); display: flex; align-items: baseline; gap: 0.5rem; }
.parse-empty em { color: var(--ink-faint); }
.parse-empty-word { font-size: 1.3rem; color: var(--ink); }

/* Authority (persName / placeName) cards. */
.auth-card {
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.8rem 0.9rem;
  margin-bottom: 0.8rem;
  background: var(--paper);
}
.auth-name { margin: 0; font-family: var(--serif); font-size: 1.25rem; color: var(--ink); }
.auth-full { font-family: var(--serif); font-size: 1.02rem; color: var(--ink-soft); margin-top: 0.15rem; }
.auth-notes { font-size: 0.86rem; color: var(--ink-soft); margin: 0.5rem 0 0.4rem; line-height: 1.5; }
.auth-link {
  display: inline-block;
  margin-top: 0.3rem;
  font-family: var(--ui);
  font-size: 0.82rem;
  color: var(--accent);
  text-decoration: none;
}
.auth-link:hover { text-decoration: underline; }
.auth-missing { color: var(--ink-faint); font-size: 0.85rem; }

/* Date card. */
.date-card {
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.9rem;
  background: var(--paper);
}
.date-modern { font-family: var(--serif); font-size: 1.4rem; color: var(--ink); }
.date-orig { font-family: var(--serif); font-size: 1rem; font-style: italic; color: var(--ink-soft); margin-top: 0.4rem; }
.date-raw { font-family: var(--ui); font-size: 0.72rem; color: var(--ink-faint); margin-top: 0.6rem; letter-spacing: 0.02em; }

/* ============ Narrow viewport ============ */

@media (max-width: 880px) {
  .layout { grid-template-columns: 0 minmax(0, 1fr) 0; }
  body.panel-open .layout { grid-template-columns: 0 minmax(0, 1fr) 1fr; }
  .toolbar-center { display: none; }
  .toolbar { flex-wrap: wrap; height: auto; padding: 0.5rem; }
  .folio { font-size: 1.18rem; }
}
