/* Literary Lineage
   One family, EB Garamond, set like a scholarly book. Cool archival paper,
   iron-gall ink, and one accent, lapis, for the thing being pointed at. The
   stemma (the tree drawing) is the only bold element; everything else is
   typography. */

/* EB Garamond (OFL), vendored in app/assets/fonts; the same files are
   installed in the production image so the share cards match the page. */
@font-face {
  font-family: "EB Garamond";
  src: url("/assets/ebgaramond-var-3ef4083c.ttf") format("truetype");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("/assets/ebgaramond-italic-var-b0dae46b.ttf") format("truetype");
  font-weight: 400 800;
  font-style: italic;
  font-display: swap;
}

:root {
  --paper: #f3f2ee;
  --paper-2: #e9e7e1;
  --ink: #23201c;
  --ink-2: #5c5751;
  --rule: #cfcbc2;
  --lapis: #1f3a93;
  --lapis-2: #4b63b8;
  --lapis-soft: rgba(31, 58, 147, 0.1);
  --serif: "EB Garamond", Garamond, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --measure: 62ch;
  --gutter: clamp(1rem, 4vw, 2.5rem);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15181f;
    --paper-2: #1d2129;
    --ink: #e8e5de;
    --ink-2: #9c988f;
    --rule: #333843;
    --lapis: #8ca6ff;
    --lapis-2: #6f89e8;
    --lapis-soft: rgba(140, 166, 255, 0.14);
  }
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--serif);
  font-size: 1.1875rem; /* 19px: Garamond runs small */
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  font-feature-settings: "kern", "liga", "onum";
  -webkit-font-smoothing: antialiased;
}

/* The body is a column flexbox (for the sticky footer); a main with auto
   margins would otherwise size to its max-width rather than the viewport. */
body > main { width: 100%; }

a { color: var(--lapis); text-decoration-thickness: 1px; text-underline-offset: 0.12em; }
a:hover { color: var(--lapis-2); }
:focus-visible { outline: 2px solid var(--lapis); outline-offset: 3px; border-radius: 2px; }

h1, h2, h3 { font-weight: 400; margin: 0; line-height: 1.15; text-wrap: balance; }
p { margin: 0 0 1em; }
i.title { font-style: italic; }
.num { font-variant-numeric: lining-nums tabular-nums; font-feature-settings: "kern", "liga", "lnum", "tnum"; }

button, .button, input[type="text"], input[type="search"] {
  font: inherit;
  color: inherit;
}

/* ---- Chrome ------------------------------------------------------------ */

.site-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 1.1rem var(--gutter) 0.9rem;
  border-bottom: 1px solid var(--rule);
}
.site-name {
  font-style: italic;
  font-size: 1.35rem;
  color: var(--ink);
  text-decoration: none;
}
.site-nav a { color: var(--ink-2); text-decoration: none; }
.site-nav a:hover { color: var(--ink); }

.flash {
  margin: 0;
  padding: 0.75rem var(--gutter);
  background: var(--lapis-soft);
  color: var(--ink);
}

.site-foot {
  margin-top: auto;
  padding: 2.5rem var(--gutter) 3rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-2);
  font-size: 0.95rem;
  max-width: calc(var(--measure) + 2 * var(--gutter));
}
.site-foot p:last-child { margin-bottom: 0; }

/* ---- Home -------------------------------------------------------------- */

.home {
  padding: clamp(3rem, 12vh, 8rem) var(--gutter) 4rem;
  max-width: 44rem;
  margin: 0 auto;
}
.home-lede {
  font-size: clamp(2rem, 6vw, 3.25rem);
  font-style: italic;
  line-height: 1.1;
  margin-bottom: 0.5em;
}
.home-sub {
  font-size: 1.25rem;
  color: var(--ink-2);
  max-width: 34rem;
  margin-bottom: 2.25rem;
}

.search {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 1rem;
}
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0.5rem 0;
  font-size: 1.6rem;
  font-style: italic;
}
.search input::placeholder { color: var(--ink-2); opacity: 0.8; }
.search input:focus { outline: none; }
.search button {
  border: 0;
  background: transparent;
  padding: 0.5rem 0 0.5rem 1rem;
  font-size: 1.2rem;
  color: var(--lapis);
  cursor: pointer;
}
.search button:hover { color: var(--lapis-2); }

.examples {
  color: var(--ink-2);
  font-size: 1rem;
  margin-bottom: 3.5rem;
}
.examples form { display: inline; }
.examples button {
  border: 0;
  background: none;
  padding: 0;
  color: var(--lapis);
  font-style: italic;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.12em;
}

.shelf { margin-bottom: 2.75rem; }
.shelf h2 { font-size: 1.1rem; color: var(--ink-2); margin-bottom: 0.6rem; }
.shelf ol { list-style: none; margin: 0; padding: 0; }
.shelf li { padding: 0.45rem 0; border-top: 1px solid var(--rule); }
.shelf li a { text-decoration: none; color: var(--ink); display: block; }
.shelf li a:hover i { text-decoration: underline; text-decoration-thickness: 1px; }
.shelf .meta { color: var(--ink-2); font-size: 0.95rem; }

/* ---- Candidates -------------------------------------------------------- */

.candidates {
  padding: 3rem var(--gutter) 4rem;
  max-width: 44rem;
  margin: 0 auto;
}
.candidates h1 { font-size: 2rem; font-style: italic; margin-bottom: 0.25em; }
.candidates .lede { color: var(--ink-2); margin-bottom: 1.5rem; }
.candidates ol { list-style: none; margin: 0; padding: 0; }
.candidates li { border-top: 1px solid var(--rule); }
.candidates li:last-child { border-bottom: 1px solid var(--rule); }
.candidates button {
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 0.9rem 0;
  cursor: pointer;
}
.candidates button:hover .cand-title { color: var(--lapis); }
.cand-title { font-size: 1.35rem; font-style: italic; }
.cand-by { color: var(--ink-2); }
.cand-desc { margin: 0.15rem 0 0; color: var(--ink-2); font-size: 1rem; }
.candidates .again { margin-top: 1.5rem; color: var(--ink-2); }

/* ---- Waiting / failed / busy ------------------------------------------- */

.waiting {
  padding: 3rem var(--gutter) 4rem;
  max-width: 44rem;
  margin: 0 auto;
}
.waiting h1 { font-size: clamp(2rem, 6vw, 2.75rem); font-style: italic; margin-bottom: 0.2em; }
.waiting .by { color: var(--ink-2); font-size: 1.2rem; margin-bottom: 2rem; }
.waiting-line {
  display: grid;
  grid-template-columns: 2.5rem 1fr;
  gap: 1.25rem;
  align-items: start;
}
.waiting-line svg { width: 2.5rem; height: 16rem; overflow: visible; }
.waiting-line .grow {
  stroke: var(--lapis);
  stroke-width: 1.5;
  stroke-dasharray: 240;
  stroke-dashoffset: 240;
  animation: grow 150s linear forwards;
}
.waiting-line .tick { stroke: var(--rule); stroke-width: 1; }
.waiting-line .root { fill: var(--ink); }
@keyframes grow { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) {
  .waiting-line .grow { animation: none; stroke-dashoffset: 0; }
}
.waiting-text p { max-width: 34rem; }
.waiting-text .status { font-style: italic; color: var(--lapis); min-height: 1.6em; }
.waiting-text .small { color: var(--ink-2); font-size: 1rem; }

.button {
  display: inline-block;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: transparent;
  padding: 0.45rem 1rem;
  text-decoration: none;
  color: var(--ink);
  cursor: pointer;
}
.button:hover { background: var(--paper-2); color: var(--ink); }

/* ---- Viewer ------------------------------------------------------------ */

.viewer { padding: 2.25rem var(--gutter) 5rem; }

/* Running head: small, quiet, one or two lines. The card below carries the
   large type. */
.running-head {
  max-width: calc(300px + 2rem + var(--measure));
  margin: 0 auto 1.75rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--rule);
}
.running-head h1 { font-size: 1.2rem; color: var(--ink-2); margin-bottom: 0.15rem; }
.running-head h1 i { color: var(--ink); }
.running-head .stats { font-size: 1rem; color: var(--ink-2); margin: 0; max-width: var(--measure); }

.viewer-body {
  max-width: calc(300px + 2rem + var(--measure));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem 2rem;
}
@media (min-width: 60rem) {
  .viewer-body { grid-template-columns: 300px minmax(0, var(--measure)); align-items: start; }
}

/* The stemma. Sticky beside the reading column on wide screens; on narrow
   ones it hides behind the "tree" control in the step bar. */
.stemma {
  position: sticky;
  top: 1rem;
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  scrollbar-width: thin;
  padding-right: 0.25rem;
}
.stemma svg { width: 100%; height: auto; display: block; }
.stemma .edge { fill: none; stroke: var(--ink-2); stroke-opacity: 0.6; stroke-linecap: round; }
.stemma .edge.disputed { stroke-dasharray: 3 3; }
.stemma .edge.on-thread { stroke: var(--lapis); stroke-opacity: 1; }
.stemma .node { cursor: pointer; }
.stemma .node:focus { outline: none; }
/* The whole row is the target; it shows only when pointed at or current. */
.stemma .node .hit { fill: transparent; }
.stemma .node:is(:hover, :focus-visible) .hit { fill: var(--paper-2); }
.stemma .node[aria-current="step"] .hit { fill: var(--lapis-soft); }
.stemma .node .dot { fill: var(--paper); stroke: var(--ink); stroke-width: 1.4; }
.stemma .node.terminal .dot,
.stemma .node.root .dot { fill: var(--ink); }
.stemma .node[aria-current="step"] .dot { fill: var(--lapis); stroke: var(--lapis); }
.stemma .node text { font-family: var(--serif); font-size: 12.5px; fill: var(--ink); }
.stemma .node .t { font-style: italic; }
.stemma .node .yr { fill: var(--ink-2); font-size: 11px; font-variant-numeric: lining-nums; }
.stemma .node[aria-current="step"] .t { fill: var(--lapis); }
.stemma .node.off-thread text { fill: var(--ink-2); }
.stemma a { text-decoration: none; }
.stemma-note { color: var(--ink-2); font-size: 0.9rem; margin: 0.5rem 0 0; }
.reading { scroll-margin-top: 1rem; }
@media (max-width: 59.98rem) {
  /* On a phone the tree waits behind "Show the tree" and opens above the
     card, full width. */
  .stemma { position: static; max-height: none; display: none; padding: 0.5rem 0 1rem; border-bottom: 1px solid var(--rule); }
  .stemma.is-open { display: block; }
}

/* Steps: every work rendered; one shown at a time. */
.steps { list-style: none; margin: 0; padding: 0; }
.step[hidden] { display: none; }
.step-article { max-width: var(--measure); }

.step-year {
  font-size: 1rem;
  color: var(--ink-2);
  margin-bottom: 0.2rem;
}
.step-title { font-size: clamp(1.9rem, 5.5vw, 2.6rem); font-style: italic; margin-bottom: 0.2em; }
.step-by { font-size: 1.25rem; margin-bottom: 0.15rem; }
.step-where { color: var(--ink-2); margin-bottom: 1.25rem; }
.step-blurb { margin-bottom: 1.5rem; }

.handed h2, .drew h2 {
  font-size: 1.05rem;
  color: var(--ink-2);
  font-style: italic;
  border-top: 1px solid var(--rule);
  padding-top: 0.9rem;
  margin: 1.75rem 0 0.75rem;
}
.handed h3 { font-size: 1.2rem; margin-bottom: 0.1rem; }
.handed .kind { color: var(--ink-2); font-size: 1rem; margin-bottom: 0.4rem; }
.handed .kind.low { font-style: italic; }
.handed article { margin-bottom: 1.4rem; }
.handed p { max-width: var(--measure); }

.drew ul { list-style: none; margin: 0; padding: 0; }
.drew li { padding: 0.4rem 0; display: flex; flex-wrap: wrap; gap: 0.25rem 0.9rem; align-items: baseline; }
.drew li a.go { color: var(--ink); text-decoration: none; font-size: 1.15rem; }
.drew li a.go:hover i { text-decoration: underline; text-decoration-thickness: 1px; }
.drew li .yr { color: var(--ink-2); }
.drew li .thread { font-size: 0.95rem; }
.drew .stops { color: var(--ink-2); }

.step-actions { margin-top: 1.75rem; display: flex; gap: 1rem 1.5rem; flex-wrap: wrap; align-items: baseline; }
.step-actions .amazon { font-size: 1rem; }

/* Step bar: inline on wide screens, pinned to the bottom on phones. */
.stepbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}
.stepbar .counter { color: var(--ink-2); text-align: center; }
.stepbar .counter .thread-name { display: block; font-size: 0.9rem; }
.stepbar a, .stepbar button {
  color: var(--ink);
  text-decoration: none;
  border: 0;
  background: none;
  padding: 0.25rem 0;
  cursor: pointer;
  font-size: 1.1rem;
}
.stepbar a:hover, .stepbar button:hover { color: var(--lapis); }
.stepbar .older { text-align: right; }
.stepbar .is-disabled { color: var(--rule); pointer-events: none; }
.stepbar .tree-toggle { display: none; font-size: 0.95rem; color: var(--ink-2); }
.stepbar kbd { display: none; }
@media (max-width: 59.98rem) {
  .viewer { padding-bottom: 7rem; }
  .stepbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    margin: 0;
    padding: 0.6rem var(--gutter) calc(0.6rem + env(safe-area-inset-bottom, 0px));
    background: var(--paper);
    border-top: 1px solid var(--rule);
    z-index: 2;
  }
  .stepbar .tree-toggle { display: inline; }
}

.thread-crumb {
  color: var(--ink-2);
  font-size: 1rem;
  margin-bottom: 1.25rem;
}
.thread-crumb a { margin-left: 0.5rem; }

/* Share */
.share {
  max-width: calc(300px + 2rem + var(--measure));
  margin: 3rem auto 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}
@media (min-width: 60rem) { .share { padding-left: calc(300px + 2rem); } }
.share h2 { font-size: 1.05rem; color: var(--ink-2); font-style: italic; margin-bottom: 0.5rem; }
.share ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem 1.4rem; }
.share a, .share button {
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--lapis); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.12em;
}
.share .card-preview { margin-top: 1rem; max-width: 30rem; }
.share .card-preview img { width: 100%; height: auto; display: block; border: 1px solid var(--rule); }

/* ---- About ------------------------------------------------------------- */
.prose { padding: 3rem var(--gutter) 4rem; max-width: calc(var(--measure) + 2 * var(--gutter)); margin: 0 auto; }
.prose h1 { font-size: 2.25rem; font-style: italic; margin-bottom: 0.5em; }
.prose h2 { font-size: 1.4rem; margin: 1.75rem 0 0.5rem; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0.001s !important; }
}
