:root {
  --bg: #f6f3ec;
  --paper: #fffdf8;
  --ink: #23201b;
  --ink-soft: #5c564c;
  --ink-faint: #8a8275;
  --rule: #e4ddcf;
  --accent: #7a6a4f;
  --hl: #ffe9a8;
  --hl-edge: #f2cf6b;
  --nav-w: 248px;
  --gutter-w: 300px;
  --measure: 33rem;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr) var(--gutter-w);
  align-items: start;
  gap: 0;
  max-width: 1400px;
  margin: 0 auto;
}

/* ---------- Left nav ---------- */
.nav {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 2rem 1.4rem 2rem 1.8rem;
  border-right: 1px solid var(--rule);
  font-family: var(--sans);
  background: var(--bg);
}
.nav__brand {
  font-family: var(--serif);
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 0.2rem;
}
.nav__title {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0 0 1.6rem;
  line-height: 1.1;
}
.nav__title a { color: var(--ink); text-decoration: none; }
.nav__sec {
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 1.4rem 0 0.5rem;
}
.nav ol { list-style: none; margin: 0; padding: 0; counter-reset: ch; }
.nav li { margin: 0; }
.nav__link {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.34rem 0.5rem;
  border-radius: 6px;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.25;
}
.nav__link:hover { background: #efe9dc; color: var(--ink); }
.nav__link.is-active { background: #ece3cf; color: var(--ink); font-weight: 600; }
.nav__num { color: var(--ink-faint); font-size: 0.78rem; min-width: 1.1rem; font-variant-numeric: tabular-nums; }
.nav__sub {
  display: block;
  padding: 0.28rem 0.5rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
  text-decoration: none;
  border-radius: 6px;
}
.nav__sub:hover { background: #efe9dc; color: var(--ink); }
.nav__sub.is-active { background: #ece3cf; color: var(--ink); font-weight: 600; }
.nav__actions { margin-top: 1.6rem; padding-top: 1.2rem; border-top: 1px solid var(--rule); }
.nav__hint { font-family: var(--sans); font-size: 0.72rem; line-height: 1.55; color: var(--ink-faint); margin: 0; }
.nav__hint code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95em; background: #efe9dc; padding: 0.05em 0.3em; border-radius: 4px; }
.btn {
  font-family: var(--sans);
  font-size: 0.82rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink-soft);
  padding: 0.45rem 0.7rem;
  border-radius: 7px;
  cursor: pointer;
  width: 100%;
  text-align: left;
}
.btn:hover { background: #efe9dc; color: var(--ink); }
.btn + .btn { margin-top: 0.5rem; }

/* ---------- Main reading column ---------- */
.main { padding: 4.5rem 3rem 8rem; min-width: 0; }
.reader { max-width: var(--measure); margin: 0 auto; }

.chapter-eyebrow {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 0.6rem;
}
.chapter-title {
  font-size: 2.6rem;
  font-weight: 600;
  line-height: 1.05;
  margin: 0 0 2.4rem;
  letter-spacing: -0.01em;
}
.audio-player {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin: 0 0 2.6rem;
  padding: 0.6rem 0.9rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
}
.audio-player__label {
  font-family: var(--sans);
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
}
.audio-player audio {
  flex: 1;
  min-width: 0;
  height: 36px;
  accent-color: var(--accent);
}

.prose { font-size: 1.18rem; line-height: 1.72; color: var(--ink); }
.prose .para { margin: 0 0 1.35rem; }
.prose:not(.board) .para:first-of-type::first-letter {
  font-size: 3.1rem;
  line-height: 0.8;
  float: left;
  padding: 0.1rem 0.6rem 0 0;
  font-weight: 600;
  color: var(--accent);
}
.scene-break {
  text-align: center;
  color: var(--ink-faint);
  letter-spacing: 0.5em;
  margin: 2.2rem 0;
  font-size: 0.9rem;
}
.prose em { font-style: italic; }

/* highlights */
mark.hl {
  background: var(--hl);
  box-shadow: inset 0 -0.45em 0 rgba(242,207,107,0.35);
  border-radius: 2px;
  padding: 0 0.04em;
  cursor: pointer;
  transition: background 0.15s;
}
mark.hl.has-note { background: linear-gradient(var(--hl), var(--hl)); border-bottom: 2px solid var(--hl-edge); }
mark.hl.is-focused { background: #ffd66b; }

/* chapter footer nav */
.chapter-foot {
  max-width: var(--measure);
  margin: 4rem auto 0;
  display: flex;
  justify-content: space-between;
  font-family: var(--sans);
  font-size: 0.9rem;
  border-top: 1px solid var(--rule);
  padding-top: 1.4rem;
}
.chapter-foot a { color: var(--ink-soft); text-decoration: none; }
.chapter-foot a:hover { color: var(--ink); }
.chapter-foot .spacer { color: var(--ink-faint); }

/* ---------- Right gutter ---------- */
.gutter {
  position: relative;
  padding: 4.5rem 1.2rem 8rem 0.4rem;
  border-left: 1px solid var(--rule);
  min-height: 100vh;
  font-family: var(--sans);
}
.gutter__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0.6rem 0.4rem 0.6rem;
}
.gutter__clear {
  font-family: var(--sans);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.15rem 0.45rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.gutter__clear[hidden] { display: none; }
.gutter__clear:hover { color: #a23b2d; border-color: #a23b2d; }
.gutter__empty {
  margin: 0.4rem 0.6rem;
  font-size: 0.84rem;
  color: var(--ink-faint);
  line-height: 1.5;
}
.note-layer { position: relative; }
.note-card {
  position: absolute;
  left: 0.4rem;
  right: 0.4rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--hl-edge);
  border-radius: 8px;
  padding: 0.55rem 0.7rem 0.6rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.note-card.is-focused { border-color: var(--accent); box-shadow: 0 3px 10px rgba(0,0,0,0.09); }
.note-card__quote {
  font-family: var(--serif);
  font-size: 0.82rem;
  color: var(--ink-soft);
  border-left: 2px solid var(--hl-edge);
  padding-left: 0.5rem;
  margin: 0 0 0.45rem;
  line-height: 1.4;
  max-height: 4.2em;
  overflow: hidden;
}
.note-card textarea {
  width: 100%;
  border: none;
  resize: vertical;
  min-height: 2.2rem;
  font-family: var(--sans);
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--ink);
  background: transparent;
  outline: none;
  padding: 0;
}
.note-card textarea::placeholder { color: var(--ink-faint); }
.note-card__foot { display: flex; justify-content: space-between; align-items: center; margin-top: 0.35rem; }
.note-card__del {
  border: none; background: none; cursor: pointer;
  color: var(--ink-faint); font-size: 0.74rem; padding: 0;
}
.note-card__del:hover { color: #a23b2d; }

/* ---------- Selection toolbar ---------- */
.sel-toolbar {
  position: absolute;
  z-index: 50;
  display: none;
  gap: 0.25rem;
  background: #2c281f;
  border-radius: 8px;
  padding: 0.3rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  transform: translate(-50%, -100%);
}
.sel-toolbar.is-visible { display: flex; }
.sel-toolbar button {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: #f3ead4;
  background: none;
  border: none;
  padding: 0.3rem 0.6rem;
  border-radius: 5px;
  cursor: pointer;
}
.sel-toolbar button:hover { background: #423b2d; }

/* ---------- Index / title page ---------- */
.title-wrap { max-width: 40rem; margin: 0 auto; padding: 5rem 0 4rem; }
.title-wrap .series { font-family: var(--sans); letter-spacing: 0.24em; text-transform: uppercase; font-size: 0.78rem; color: var(--ink-faint); }
.title-wrap h1 { font-size: 4rem; margin: 0.6rem 0 0.2rem; letter-spacing: 0.01em; }
.title-wrap .dedication { font-style: italic; color: var(--ink-soft); font-size: 1.25rem; margin: 0.4rem 0 2.6rem; }
.title-wrap .lede { font-size: 1.16rem; line-height: 1.7; color: var(--ink-soft); }
.title-wrap .read-total { font-family: var(--sans); font-size: 0.82rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-faint); margin: 2.4rem 0 0; }
.toc-list { list-style: none; padding: 0; margin: 0.8rem 0 0; }
.toc-list li { border-top: 1px solid var(--rule); }
.toc-list li:last-child { border-bottom: 1px solid var(--rule); }
.toc-list a { display: flex; gap: 1rem; align-items: baseline; padding: 0.9rem 0.4rem; text-decoration: none; color: var(--ink); }
.toc-list a:hover { background: #efe9dc; }
.toc-list .n { font-family: var(--sans); font-size: 0.8rem; color: var(--ink-faint); min-width: 2rem; }
.toc-list .t { font-size: 1.25rem; }
.toc-list .d { margin-left: auto; font-family: var(--sans); font-size: 0.8rem; color: var(--ink-faint); }
.howto { background: var(--paper); border: 1px solid var(--rule); border-radius: 12px; padding: 1.4rem 1.6rem; margin-top: 3rem; font-family: var(--sans); font-size: 0.92rem; line-height: 1.6; color: var(--ink-soft); }
.howto h2 { font-family: var(--serif); font-size: 1.1rem; color: var(--ink); margin: 0 0 0.6rem; }
.howto kbd { font-family: var(--sans); background: #ece3cf; border-radius: 4px; padding: 0.05rem 0.35rem; font-size: 0.82rem; }

/* ---------- Planning board ---------- */
.app--wide { max-width: 1680px; }
.main--board { padding: 4.5rem 2.4rem 8rem; }
.board-title { margin-bottom: 1.2rem; }

.board-intro {
  max-width: 46rem;
  font-family: var(--sans);
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--ink-soft);
  margin-bottom: 2.2rem;
}
.board-intro p { margin: 0 0 0.8rem; }
.board-intro code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
  background: #efe9dc;
  padding: 0.05em 0.3em;
  border-radius: 4px;
}
.board-intro__flag {
  border-left: 3px solid var(--hl-edge);
  padding-left: 0.8rem;
  color: var(--ink);
}

.status-legend {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 1rem 1.2rem 1.1rem;
  margin-top: 1.4rem;
}
.status-legend__head,
.status-legend__note { margin: 0; }
.status-legend__head {
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 0.7rem;
}
.status-legend ul {
  list-style: none;
  margin: 0 0 0.8rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.status-legend li { display: flex; align-items: baseline; gap: 0.6rem; }
.status-legend__desc { font-size: 0.86rem; color: var(--ink-soft); }
.status-legend__note { font-size: 0.84rem; color: var(--ink-soft); line-height: 1.55; }

/* status badges */
.status-badge {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.status--draft-v1 { background: #ece3cf; color: #5c5440; border-color: #ddd0b4; }
.status--v2-ideas { background: #fbe9c4; color: #7a5a16; border-color: #f0d191; }
.status--v2-needed { background: #f6d7cf; color: #9a3b27; border-color: #e9b6a8; }
.status--v2-wip { background: #d6e4ef; color: #2f5a7a; border-color: #b3cde0; }
.status--v2-landed { background: #d7e9d2; color: #356b3a; border-color: #b4d6ac; }

/* the grid */
.board-scroll {
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper);
}
.prose.board { font-size: 0.9rem; line-height: 1.5; color: var(--ink); }
.board .para { margin: 0; }
/* belt-and-suspenders: never a drop cap inside the grid */
.prose.board .para::first-letter {
  font-size: inherit;
  line-height: inherit;
  float: none;
  padding: 0;
  font-weight: inherit;
  color: inherit;
}
.board-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 1180px;
}
.board-th {
  text-align: left;
  vertical-align: bottom;
  font-family: var(--sans);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 0.85rem 0.85rem 0.7rem;
  border-bottom: 2px solid #cdc1a5;
  border-left: 1px solid #d6cbb4;
  background: #f1ece0;
  min-width: 160px;
}
.board-cell {
  vertical-align: top;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid #d6cbb4;
  border-left: 1px solid #d6cbb4;
  min-width: 160px;
}
.board-table tbody tr:last-child .board-cell { border-bottom: none; }
.board-cell--empty { color: var(--ink-faint); text-align: center; min-width: 0; }
.board-th--status, .board-cell--status { min-width: 132px; }
.board-th--pov, .board-cell--pov { min-width: 96px; }
.board-cell--pov .para { color: var(--ink-soft); font-family: var(--sans); font-size: 0.84rem; }

/* sticky chapter column */
.board-th--chapter, .board-cell--chapter {
  position: sticky;
  left: 0;
  min-width: 138px;
  border-left: none;
}
.board-cell--chapter {
  background: #f1ece0;
  font-family: var(--sans);
  font-weight: 600;
  z-index: 1;
}
.board-cell--chapter .para { font-weight: 600; }
.board-th--chapter { background: #e9e0cd; z-index: 3; }
.board-th { z-index: 2; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .app { grid-template-columns: var(--nav-w) minmax(0,1fr); }
  .gutter { display: none; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--rule); }
  .main { padding: 2.2rem 1.4rem 5rem; }
  .chapter-title { font-size: 2rem; }
}

.toast {
  position: fixed; bottom: 1.4rem; left: 50%; transform: translateX(-50%);
  background: #2c281f; color: #f3ead4; font-family: var(--sans); font-size: 0.86rem;
  padding: 0.6rem 1rem; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 100;
}
.toast.is-visible { opacity: 1; }

/* ---------- Nav: back-to-landing + brand link ---------- */
.nav__brand a { color: inherit; text-decoration: none; }
.nav__brand a:hover { color: var(--ink-soft); }
.nav__back {
  display: block;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-decoration: none;
  margin-bottom: 0.9rem;
}
.nav__back:hover { color: var(--ink); }
.toc-sec {
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 2.4rem 0 0.2rem;
}
.title-cover {
  display: block;
  width: 190px;
  max-width: 48%;
  height: auto;
  float: right;
  margin: 0.4rem 0 1.4rem 1.8rem;
  border-radius: 6px;
  box-shadow: 0 8px 26px rgba(0,0,0,0.18);
}

/* ---------- Static host (deployed / file://): hide local-only notes UI ----- */
/* The annotation gutter + selection toolbar only work under serve.py on
   localhost. Everywhere else there is no server to capture notes, so hide them
   and let the reading column take the full width. */
.static-host .app { grid-template-columns: var(--nav-w) minmax(0, 1fr); }
.static-host .gutter,
.static-host .sel-toolbar,
.static-host .nav__hint,
.static-host .howto { display: none; }
.static-host .nav__actions { margin-top: 1.6rem; padding-top: 1.2rem; border-top: 1px solid var(--rule); }
.static-host .reader,
.static-host .main--board .board-scroll { /* unchanged measure, just more room around it */ }

/* ---------- Landing page (root index.html) ---------- */
.landing {
  max-width: 1040px;
  margin: 0 auto;
  padding: 7vh 1.5rem 5rem;
}
.landing__head { text-align: center; margin-bottom: 3.2rem; }
.landing__eyebrow {
  font-family: var(--sans);
  font-size: 0.74rem;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 0.9rem;
}
.landing__title {
  font-size: clamp(2.6rem, 6vw, 4.2rem);
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
  line-height: 1.04;
}
.landing__sub {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 1.18rem;
  margin: 0.8rem 0 0;
}
.landing__books {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2rem;
  align-items: stretch;
}
.bookcard {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 14px;
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.bookcard:hover {
  transform: translateY(-4px);
  box-shadow: 0 18px 40px rgba(0,0,0,0.14);
  border-color: #d8cdb2;
}
.bookcard__cover {
  position: relative;
  aspect-ratio: 5 / 8;
  background: #1c2230;
  overflow: hidden;
}
.bookcard__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.bookcard__cover--placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  text-align: center;
  padding: 2rem;
  background: linear-gradient(160deg, #2b3447, #161b27 70%);
  color: #f3ead4;
}
.bookcard__ph-series {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: #b9c2d6;
}
.bookcard__ph-title {
  font-family: var(--serif);
  font-size: 1.9rem;
  line-height: 1.1;
  color: #f6edd6;
}
.bookcard__body { padding: 1.4rem 1.5rem 1.6rem; display: flex; flex-direction: column; flex: 1; }
.bookcard__series {
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 0.4rem;
}
.bookcard__title { font-size: 1.9rem; font-weight: 600; margin: 0 0 0.5rem; line-height: 1.08; }
.bookcard__tagline { font-size: 1rem; line-height: 1.55; color: var(--ink-soft); margin: 0 0 1.2rem; }
.bookcard__cta {
  margin-top: auto;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
}
.bookcard:hover .bookcard__cta { color: var(--ink); }
.landing__foot {
  margin-top: 3.4rem;
  text-align: center;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--ink-faint);
}
.landing__foot code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #efe9dc; padding: 0.05em 0.3em; border-radius: 4px; }
@media (max-width: 680px) {
  .landing__books { grid-template-columns: 1fr; max-width: 360px; margin: 0 auto; }
}
