/* fable — editorial reading layer
   serif body, ~65ch measure, paper/ink/one-accent, dark via media query */

:root {
  --paper: #f6f1e8;
  --paper-deep: #efe8db;
  --ink: #211d17;
  --muted: #6f6557;
  --accent: #8a3324;
  --faint: rgba(33, 29, 23, 0.14);
  --serif: "Charter", "Iowan Old Style", "Georgia", "Times New Roman", serif;
  --sans: -apple-system, "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161410;
    --paper-deep: #1d1a15;
    --ink: #e6dfd1;
    --muted: #998f7e;
    --accent: #c96f53;
    --faint: rgba(230, 223, 209, 0.16);
  }
}

* { box-sizing: border-box; }

html {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(17px, 1.05vw + 13px, 20px);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration-color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }

::selection { background: var(--accent); color: var(--paper); }

/* ---- small-caps labels ---- */
.label {
  font-family: var(--sans);
  font-variant-caps: all-small-caps;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: lowercase;
}

/* ---- masthead ---- */
.masthead { max-width: 72rem; margin: 0 auto; padding: 1.4rem clamp(1rem, 4vw, 2.5rem); }
.masthead-nav { display: flex; align-items: baseline; gap: 1.5rem; font-size: 0.95rem; }
.masthead-nav a { text-decoration: none; }
.masthead-nav a[aria-current] { color: var(--accent); }
.masthead-spacer { flex: 1; }

/* ---- reading progress ---- */
.progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 10;
  background: transparent; pointer-events: none;
}
.progress-bar {
  display: block; height: 100%; width: 100%;
  background: var(--accent);
  transform: scaleX(0); transform-origin: 0 50%;
}

/* ---- hero / index ---- */
.page-home main { max-width: 72rem; margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2.5rem); }
.hero { padding: clamp(2rem, 7vh, 5rem) 0 2rem; max-width: 42rem; }
.hero-title { font-size: clamp(3rem, 8vw, 5.5rem); line-height: 1; margin: 0; font-weight: 400; letter-spacing: -0.015em; }
.hero-sub { margin: 0.6rem 0 0; }
.hero-intro { margin-top: 1.8rem; font-size: 1.05rem; }
.hero-intro p { margin: 0; }

.section-label {
  border-top: 1px solid var(--faint);
  padding-top: 0.9rem; margin: 3.5rem 0 0.8rem;
  font-size: 0.85rem;
}
.section-note { color: var(--muted); font-style: italic; margin: 0 0 1.2rem; max-width: 42rem; }

.index-list { list-style: none; margin: 0; padding: 0; }
.index-item { border-bottom: 1px solid var(--faint); }
.index-link {
  display: flex; gap: 1.6rem; align-items: center;
  padding: 1.3rem 0; text-decoration: none;
}
.index-art { flex: 0 0 9rem; max-width: 9rem; opacity: 0.9; }
.index-art .art { display: block; width: 100%; height: auto; }
.index-text { display: block; }
.index-title { display: block; font-size: 1.35rem; line-height: 1.25; }
.index-link:hover .index-title { color: var(--accent); }
.index-summary { display: block; color: var(--muted); margin-top: 0.3rem; font-size: 0.95rem; }
.index-meta { display: block; margin-top: 0.45rem; }
@media (max-width: 600px) { .index-art { display: none; } }

/* ---- the recursion (nested boxes) ---- */
.descent-section { max-width: 56rem; }
.descent-hint { color: var(--muted); font-style: italic; max-width: 42rem; margin: 0 0 1.4rem; }
.descent { container-type: inline-size; }

.layer {
  border: 1px solid var(--faint);
  background: color-mix(in srgb, var(--ink) 2.5%, transparent);
  padding: clamp(0.9rem, 2.5cqw, 1.8rem);
  margin-top: 1rem;
}
.layer-path { margin: 0; word-break: break-all; }
.layer-title { margin: 0.2rem 0 0.4rem; font-size: 1.25rem; font-weight: 600; }
.layer-line { margin: 0; color: var(--muted); font-style: italic; }

.layer-descend {
  font-family: var(--sans); font-size: 0.8rem; letter-spacing: 0.1em;
  background: none; border: 1px solid var(--faint); color: var(--accent);
  padding: 0.45rem 0.9rem; margin-top: 1rem; cursor: pointer;
}
.layer-descend:hover { border-color: var(--accent); }
.layer-child { margin-top: 0.4rem; }
.layer-child.open { animation: layer-in 0.5s ease both; }
@keyframes layer-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.layer-last { border-color: var(--accent); }
.residue {
  margin: 0.8rem 0 0.4rem; padding: 0 0 0 1.1rem;
  border-left: 3px solid var(--accent);
  font-style: italic; font-size: 1.05rem;
}
.residue h1 { font-size: 1rem; font-weight: 600; font-style: normal; margin: 0 0 0.4rem; letter-spacing: 0.05em; }
.residue-caption { margin: 0.8rem 0 0; }

/* no-JS: everything is simply visible */
.js .layer-child[hidden] { display: none; }

/* ---- essay page ---- */
.page-essay main { padding: 0 clamp(1rem, 4vw, 2.5rem); }
.essay { max-width: 42rem; margin: 0 auto; padding-bottom: 4rem; }

.essay-header { padding-top: clamp(1.5rem, 5vh, 3.5rem); }
.essay-kicker { margin: 0 0 0.8rem; }
.essay h1 { font-size: clamp(2rem, 5vw, 3rem); line-height: 1.12; font-weight: 500; margin: 0 0 0.8rem; letter-spacing: -0.01em; }
.standfirst { font-size: 1.18rem; line-height: 1.5; color: var(--muted); font-style: italic; margin: 0 0 1.6rem; }
.essay-art { margin: 0 0 1rem; }
.essay-art .art { display: block; width: 100%; height: auto; }
.essay-date { margin: 0 0 2.2rem; border-bottom: 1px solid var(--faint); padding-bottom: 1.6rem; }

.essay-body { font-size: 1.02rem; }
.essay-body p { margin: 0 0 1.35rem; }
.essay-body > p:first-of-type::first-letter {
  float: left;
  font-size: 3.55em; line-height: 0.82;
  padding: 0.07em 0.12em 0 0;
  color: var(--accent);
  font-weight: 500;
}
.essay-body strong { font-weight: 600; }
.essay-body ul { padding-left: 1.2rem; margin: 0 0 1.35rem; }
.essay-body li { margin-bottom: 0.6rem; }

/* ---- pull quotes ---- */
.pull-quote {
  margin: 2.2rem 0;
  padding: 0.4rem 0;
  border-top: 1px solid var(--faint);
  border-bottom: 1px solid var(--faint);
}
.pull-quote p {
  margin: 0.9rem 0;
  font-size: 1.35rem; line-height: 1.4;
  font-style: italic; text-align: center;
  color: var(--accent);
  quotes: "\201C" "\201D";
}
.pull-quote p::before { content: open-quote; }
.pull-quote p::after { content: close-quote; }

/* ---- scroll reveals ---- */
@media (prefers-reduced-motion: no-preference) {
  .js .reveal { opacity: 0; transform: translateY(14px); transition: opacity 0.7s ease, transform 0.7s ease; }
  .js .reveal.is-visible { opacity: 1; transform: none; }
}

/* ---- margin notes ---- */
.sn { counter-increment: sidenote; }
.sn-num { cursor: pointer; }
.sn-num::after {
  content: counter(sidenote);
  vertical-align: super; font-size: 0.68em;
  font-family: var(--sans);
  color: var(--accent);
  padding: 0 0.15em;
}
.sn-toggle { display: none; }
.sn-note {
  display: none;
  font-size: 0.84rem; line-height: 1.5;
  color: var(--muted);
  font-family: var(--sans);
}
.sn-note::before {
  content: counter(sidenote) " ";
  color: var(--accent);
  font-size: 0.75em; vertical-align: super;
}
.essay-body { counter-reset: sidenote; }

/* narrow screens: tap the number to expand inline */
.sn-toggle:checked ~ .sn-note {
  display: block;
  margin: 0.7rem 0;
  padding: 0.6rem 0.8rem;
  border-left: 2px solid var(--accent);
  background: color-mix(in srgb, var(--ink) 4%, transparent);
}

/* wide screens: notes live in the right margin */
@media (min-width: 1160px) {
  .page-essay .essay { margin-left: max(calc((100% - 42rem) / 2 - 7rem), 1rem); }
  .sn-num { cursor: text; }
  .sn-note, .sn-toggle:checked ~ .sn-note {
    display: block;
    float: right; clear: right;
    width: 15rem;
    margin: 0 -17.5rem 0.9rem 0;
    padding: 0; border: 0; background: none;
  }
}

/* ---- essay footer nav ---- */
.essay-end { border-top: 1px solid var(--faint); margin-top: 3rem; padding-top: 1.2rem; }
.essay-end p { margin: 0.25rem 0; }
.essay-end-min { color: var(--muted); font-size: 0.85rem; }
.back { font-family: var(--sans); font-size: 0.85rem; text-decoration: none; color: var(--muted); }
.back:hover { color: var(--accent); }

/* ---- footer ---- */
.site-footer {
  max-width: 72rem; margin: 3rem auto 0;
  padding: 1.6rem clamp(1rem, 4vw, 2.5rem) 2.4rem;
  border-top: 1px solid var(--faint);
}
.site-footer p { margin: 0.2rem 0; }
.footer-note { color: var(--muted); font-size: 0.82rem; font-style: italic; }

/* ---- generated art ---- */
.art { color: var(--ink); }
