/* Rarebit site: Paperback Chic.
   Colors and font stacks come from brand.mjs through brand-data.js (site.js sets
   --brand-*). The fallbacks below repeat those values only for no-script visits. */
@font-face { font-family: "EB Garamond"; src: url("fonts/EBGaramond-Variable.ttf") format("truetype"); font-weight: 400 800; font-style: normal; font-display: swap; }
@font-face { font-family: "EB Garamond"; src: url("fonts/EBGaramond-Italic-Variable.ttf") format("truetype"); font-weight: 400 800; font-style: italic; font-display: swap; }
@font-face { font-family: "Jost"; src: url("fonts/Jost-Variable.ttf") format("truetype"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Courier Prime"; src: url("fonts/CourierPrime-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Courier Prime"; src: url("fonts/CourierPrime-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --paper: var(--brand-paper, #efe6d3);
  --page: var(--brand-paper-bright, #faf5ea);
  --ink: var(--brand-ink, #211c16);
  --muted: var(--brand-muted, #6b6255);
  --faint: var(--brand-faint, #e3d8c2);
  --rule: var(--brand-rule, #cdbfa3);
  --cover: var(--brand-cover, #d9912b);
  --highlight: var(--brand-highlight, #f2c96f);
  --dark: var(--brand-dark, #231e18);
  --dark-text: var(--brand-dark-text, #f4ecdc);
  --serif: var(--brand-font-body, "EB Garamond", Garamond, Georgia, serif);
  --sans: var(--brand-font-label, "Jost", Futura, "Century Gothic", sans-serif);
  --mono: var(--brand-font-mono, "Courier Prime", "Courier New", monospace);
  --gutter: clamp(20px, 5vw, 72px);
  --measure: 34em;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 clamp(19px, 1.05vw + 12px, 22px) / 1.55 var(--serif);
  font-feature-settings: "kern", "liga", "onum";
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; }
a { color: inherit; text-decoration-color: var(--cover); text-decoration-thickness: 2px; text-underline-offset: 0.18em; }
a:hover { text-decoration-color: var(--ink); }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
code { font-family: var(--mono); font-size: 0.86em; }
em { font-style: italic; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; line-height: 1.08; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
sup { font-family: var(--sans); font-size: 0.6em; margin-left: 0.1em; }
sup a { text-decoration: none; color: var(--muted); display: inline-block; padding: 4px 5px; margin: -4px -2px; }

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--ink); color: var(--page); padding: 8px 14px; z-index: 10; }
.skip-link:focus { left: 8px; }

.eyebrow, .label, nav a, .numeral, .button, .site-footer {
  font-family: var(--sans);
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.78rem;
}
.eyebrow { color: var(--muted); margin-bottom: 18px; }

/* Running head: a book's page header. */
.running-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin: 0 var(--gutter); padding: 18px 0 12px;
  border-bottom: 1px solid var(--rule);
}
.wordmark img { height: 44px; width: auto; display: block; }
nav { display: flex; gap: clamp(14px, 2.4vw, 32px); flex-wrap: wrap; }
nav a { text-decoration: none; color: var(--muted); }
nav a:hover { color: var(--ink); }

main { overflow-x: clip; }
main > section { padding: clamp(64px, 9vw, 128px) max(var(--gutter), calc((100% - 1320px) / 2)); }
.section + .section { border-top: 1px solid var(--rule); }

/* Hero */
.hero {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: clamp(32px, 6vw, 96px); align-items: center;
}
h1 { font-size: clamp(2.7rem, 5.2vw, 4.6rem); text-wrap: balance; }
h1 em, h2 em { color: var(--ink); font-weight: 400; }
.lede { margin-top: 28px; max-width: var(--measure); font-size: 1.12em; color: var(--ink); }
.actions { margin-top: 36px; display: flex; gap: 28px; align-items: center; flex-wrap: wrap; }
.button {
  display: inline-block; padding: 16px 26px; background: var(--ink); color: var(--page);
  text-decoration: none; font-size: 0.78rem;
}
.button:hover { background: #000; }
.text-link { font-style: italic; }

.hero-art { margin: 0; position: relative; }
.hero-art .band { position: absolute; left: -8%; right: -40%; top: 28%; height: 40%; background: var(--cover); }

/* The extraction: a Pi session card, an ink sieve, a sand pile, and the rare bits.
   site.js drives the motion and measures the settled column; .done is the
   settled state (also the reduced-motion and no-script-motion state). */
.extract {
  --row: 22px; --top: 64px; --gutter: 34px;
  position: relative; height: 560px; overflow: hidden;
  background: var(--page); box-shadow: 0 1px 0 var(--rule), 8px 12px 0 rgba(60, 40, 20, 0.08);
  transition: height 0.9s cubic-bezier(.6, 0, .2, 1);
}
.extract.done { height: max(560px, var(--settled-height, 560px)); }
.extract-head {
  position: absolute; left: 24px; right: 24px; top: 18px; padding-bottom: 10px; border-bottom: 1px solid var(--rule);
  font: 500 0.75rem/1.2 var(--sans); letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted);
}
.extract-head span { transition: opacity 0.3s; }
.extract.done .head-bits { transition-delay: 0.3s; }
.head-bits { position: absolute; left: 0; opacity: 0; color: var(--ink); }
.extract.done .head-session { opacity: 0; }
.extract.done .head-bits { opacity: 1; }
.rows { list-style: none; margin: 0; padding: 0; }
.row {
  position: absolute; left: 24px; right: 24px; top: calc(var(--top) + var(--i) * var(--row));
  height: var(--row); display: flex; align-items: center; padding-left: var(--gutter);
  font: 400 12.5px/1 var(--mono); color: var(--muted); white-space: pre; overflow: hidden;
  transition: top 0.9s cubic-bezier(.6, 0, .2, 1), height 0.9s cubic-bezier(.6, 0, .2, 1);
}
.row .mono { overflow: hidden; text-overflow: ellipsis; transition: opacity 0.35s; }
.row.user { background: linear-gradient(to right, transparent var(--gutter), var(--faint) var(--gutter)); }
.row.user, .row.prose { color: var(--ink); }
.row.meta { color: var(--muted); }
/* A fallen row leaves a ghost rule: the entry still exists in the source. */
.row.fallen .mono { opacity: 0; }
.row.fallen::after { content: ""; position: absolute; left: var(--gutter); right: 35%; top: 50%; height: 1px; background: var(--rule); }
.row.fallen.user { background: none; }
.row .mark { position: absolute; left: 0; width: 22px; height: 22px; opacity: 0; transition: opacity 0.3s; }
.row.caught .mark { opacity: 1; }
.row.caught .mono { background: linear-gradient(var(--faint), var(--faint)) no-repeat left bottom / 100% 2px; }
.row .serif {
  position: absolute; left: var(--gutter); right: 0; top: 0;
  opacity: 0; white-space: normal; font: 400 clamp(16px, 1.4vw, 20px)/1.25 var(--serif); color: var(--ink);
  transition: opacity 0.5s 0.35s;
}
.row .serif small { display: block; font: 500 0.7rem/1.5 var(--sans); letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.extract.done .row:not(.rare) { visibility: hidden; }
.extract.done .row.rare { top: var(--final-top); height: var(--final-height); align-items: flex-start; background: none; }
.extract.done .row.rare .mark { top: 1.35rem; }
.extract.done .row.rare .mono { opacity: 0; }
.extract.done .row.rare .serif, .extract.done .row.rare .mark { opacity: 1; }
.next {
  position: absolute; left: calc(24px + var(--gutter)); right: 24px; margin: 0; opacity: 0;
  font: italic 500 clamp(16px, 1.4vw, 20px)/1.3 var(--serif);
  background: linear-gradient(transparent 55%, var(--highlight) 55%) no-repeat left / 0 100%;
  transition: opacity 0.4s 0.5s, background-size 0.6s 0.8s;
}
.extract.done .next { opacity: 1; background-size: 100% 100%; width: fit-content; }
.sieve {
  position: absolute; left: 0; right: 0; top: 40px; height: 26px; opacity: 0; z-index: 1;
  border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink);
  background: repeating-linear-gradient(45deg, transparent 0 6px, rgba(107, 98, 85, 0.45) 6px 7px),
              repeating-linear-gradient(-45deg, rgba(250, 245, 234, 0.6) 0 6px, rgba(107, 98, 85, 0.45) 6px 7px);
}
.sieve span {
  position: absolute; right: 0; top: -9px; padding: 5px 12px; background: var(--ink); color: var(--page);
  font: 600 0.72rem/1.2 var(--sans); letter-spacing: 0.18em; text-transform: uppercase;
}
.grain { position: absolute; width: 3px; height: 3px; margin: -1.5px 0 0 -1.5px; border-radius: 1px; background: var(--muted); opacity: 0.75; }
.grain.dark { background: var(--ink); opacity: 0.5; }
.pile-label {
  position: absolute; z-index: 2; left: 24px; bottom: calc(9% + 10px); padding: 2px 8px 2px 0; background: var(--page);
  font: italic 400 0.95rem/1 var(--serif); color: var(--muted); opacity: 0; transition: opacity 0.6s;
}
.extract.running .pile-label, .extract.done .pile-label { opacity: 1; }
figcaption { margin: 12px 0 0; color: var(--muted); font: italic 400 0.95rem/1.4 var(--serif); display: flex; gap: 14px; align-items: baseline; }
.replay { font: 500 0.75rem/1 var(--sans); letter-spacing: 0.14em; text-transform: uppercase; background: none; border: 0; border-bottom: 2px solid var(--cover); padding: 8px 0 4px; min-height: 24px; color: var(--ink); cursor: pointer; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Chapter heads */
.chapter-head { max-width: 1320px; margin: 0 auto clamp(40px, 5vw, 64px); position: relative; }
.numeral { font-family: var(--serif); font-style: italic; text-transform: none; letter-spacing: 0.02em; color: var(--muted); }
.chapter-head .numeral { font-size: 1.1rem; margin-bottom: 6px; }
h2 { font-size: clamp(2.3rem, 4.4vw, 3.8rem); }

/* Rare bits ledger */
.ledger { max-width: 1320px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 2px solid var(--ink); }
.ledger article { padding: 28px 28px 8px 0; }
.ledger article + article { padding-left: 28px; border-left: 1px solid var(--rule); }
.ledger img { width: 40px; height: 40px; display: block; margin: 0 0 14px -6px; }
.ledger h3 { font-size: 1.6rem; margin-bottom: 8px; }
.ledger p { color: var(--muted); max-width: 22em; }
.hygiene {
  max-width: 1320px; margin: clamp(40px, 5vw, 64px) auto 0; padding: 22px 0 0;
  border-top: 1px solid var(--rule); display: flex; gap: 12px 40px; flex-wrap: wrap; font-size: 0.95em;
}
.hygiene b { font-family: var(--sans); font-weight: 500; font-size: 0.75rem; letter-spacing: 0.14em; text-transform: uppercase; margin-right: 6px; }

/* Uses as chapters */
.chapters { max-width: 1320px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(20px, 3vw, 40px); }
.chapter { background: var(--page); padding: 34px 30px 30px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 1px 0 var(--rule), 6px 8px 0 rgba(60, 40, 20, 0.06); }
.chapter .numeral { font-size: 1.15rem; border-bottom: 2px solid var(--cover); align-self: flex-start; padding-bottom: 2px; }
.chapter .label { color: var(--muted); font-size: 0.75rem; }
.chapter h3 { font-size: 2.1rem; font-style: italic; font-weight: 400; }
.chapter p:not(.label) { flex: 1; }
.chapter code { align-self: flex-start; color: var(--muted); border-top: 1px solid var(--rule); padding-top: 12px; width: 100%; }

/* Video */
.video-frame { max-width: 1120px; margin: 0 auto; }
video { width: 100%; display: block; background: var(--dark); aspect-ratio: 16 / 9; }
details { margin-top: 18px; }
summary { cursor: pointer; font-style: italic; }
details ol { padding-left: 1.2em; color: var(--muted); }

/* Install */
.install-body { max-width: 1320px; margin: 0 auto; display: grid; gap: 22px; }
.install-body > p { max-width: var(--measure); }
.slip { margin: 0; background: var(--dark); color: var(--dark-text); padding: 24px 28px; overflow-x: auto; font-size: clamp(0.9rem, 1.6vw, 1.25rem); }
.slip code { font-size: 1em; font-weight: 700; }
.for-scripts pre { background: var(--page); padding: 16px 18px; overflow-x: auto; border-left: 3px solid var(--rule); }
.for-scripts p { color: var(--muted); font-size: 0.92em; }

/* Notes: every claim points to its source */
.notes h2 { margin-bottom: 18px; }
.notes ol { margin: 0; padding-left: 1.4em; columns: 2 22em; column-gap: 48px; color: var(--muted); font-size: 0.9em; }
.notes li { break-inside: avoid; margin-bottom: 10px; }
.notes a code { font-size: 0.8em; }

/* Closing cover band */
.closing { background: var(--cover); text-align: center; }
.closing h2 { margin-bottom: 36px; }
.button-ink { background: var(--ink); }

.site-footer {
  margin: 0 var(--gutter); padding: 22px 0 36px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  color: var(--muted); font-size: 0.75rem; border-top: 1px solid var(--rule);
}
.site-footer a { text-decoration: none; }

.reveal { opacity: 0; transform: translateY(18px); transition: opacity 0.7s ease, transform 0.7s ease; }
.reveal.is-visible { opacity: 1; transform: none; }

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
  .hero-art { max-width: 560px; width: 100%; margin: 0 auto 36px; }
  .extract { --row: 20px; height: 520px; }
  .row { font-size: 11px; }
  .ledger, .chapters { grid-template-columns: 1fr; }
  .ledger article + article { padding-left: 0; border-left: 0; border-top: 1px solid var(--rule); }
}
@media (max-width: 600px) {
  .slip { white-space: pre-wrap; overflow-wrap: anywhere; }
  .site-footer { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .extract, .row, .row .mono, .row .serif, .row .mark, .extract-head span, .pile-label, .next { transition: none; }
  .reveal { opacity: 1; transform: none; transition: none; }
}
