/* Obi Sleeve. Each page is a record sleeve: a grey face with the title, wrapped in a
   chartreuse obi band of credits. The reading column under it stays calm (direction contract in
   .impeccable/surfaces/garden-theme-layout-html.md). */

@font-face { font-family: "Jost"; src: url("/fonts/jost.woff2") format("woff2"); font-weight: 300 500; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url("/fonts/barlow-condensed-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url("/fonts/barlow-condensed-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url("/fonts/barlow-condensed-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url("/fonts/barlow-condensed-800.woff2") format("woff2"); font-weight: 800; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url("/fonts/source-serif-4.woff2") format("woff2"); font-weight: 400 600; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url("/fonts/source-serif-4-italic.woff2") format("woff2"); font-style: italic; font-weight: 400; font-display: swap; }

:root {
  /* Light only, by choice: browser chrome stays light even when the OS is dark. */
  color-scheme: light;
  --ground: #f2f2ef;
  --face: #e4e4df;
  --ink: #111112;
  --mute: #55555a;
  --rule: #cdcdc6;
  /* Chartreuse is too light to read on grey paper, so links and marks on the page take
     its olive shade; the band itself prints in black ink. */
  --link: #4d6600;
  --band: #c6f000;
  --band-ink: #111111;
  --band-soft: #1d2600;
  --band-label: #3a4a00;
  --band-rule: rgb(0 0 0 / .3);
  --code: #e4e4df;
  /* Drawn marks (bullets, current page, rules) on the ground, not on the band. */
  --mark: #4d6600;
  --scroll-shade: rgb(0 0 0 / .18);

  --title: "Jost", "Futura", system-ui, sans-serif;
  --credit: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --read: "Source Serif 4", Georgia, serif;

  --gutter: clamp(1rem, 5vw, 5rem);
  --page: 78rem;
  --ease: cubic-bezier(.16, 1, .3, 1);
  /* Bands run edge to edge; their content lines up with the shelf below. */
  --inline: max(var(--gutter), calc((100% - var(--page)) / 2));
}

* { box-sizing: border-box; }

html { background: var(--ground); scrollbar-color: var(--mute) var(--ground); }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 1.0625rem/1.65 var(--read);
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  caret-color: var(--link);
}

::selection { background: var(--band); color: var(--band-ink); }

a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: .2em; transition: text-decoration-thickness .3s var(--ease); }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; border-radius: 1px; }

.skip { position: absolute; left: -999rem; z-index: 1; padding: .5rem .9rem; background: var(--band); color: var(--band-ink); font: 700 .875rem/1 var(--credit); letter-spacing: .12em; text-transform: uppercase; }
.skip:focus { left: var(--gutter); top: .75rem; }

/* ---- Sleeve face ---- */

.face {
  /* Positioned and clipped so the link graph paints only inside the face (graph plan R7). */
  position: relative;
  overflow: hidden;
  background: var(--face);
  padding: 1.75rem var(--inline) clamp(2rem, 4vw, 3rem);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "run run" "title stage";
  align-items: end;
  column-gap: 2rem;
  row-gap: clamp(3.5rem, 10vw, 8rem);
}

/* Running head: the sleeve's printed edge. */
.runhead {
  grid-area: run;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: .25rem 2rem;
  font: 500 .8125rem/1.3 var(--credit);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--mute);
}
.runhead span:first-child { color: var(--ink); font-weight: 700; }
.runhead .home { margin-left: auto; color: var(--ink); text-decoration: none; font-weight: 700; }
.runhead .home:hover { text-decoration: underline; text-decoration-thickness: 2px; }

.face h1 {
  grid-area: title;
  margin: 0;
  max-width: 18ch;
  font: 300 clamp(2.5rem, 1.2rem + 4.6vw, 5.5rem)/1.04 var(--title);
  letter-spacing: -.015em;
  text-wrap: balance;
}

/* Growth stage: a circle that fills as the note grows. */
.stage { grid-area: stage; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: .7em;
  font: 700 .8125rem/1 var(--credit);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink);
}
.badge::before,
.key li::before {
  content: "";
  flex: none;
  width: 1em;
  height: 1em;
  border: .12em solid currentColor;
  border-radius: 50%;
}
.stage .badge::before { width: 2.6rem; height: 2.6rem; border-width: 2px; }
.badge-budding::before, .key-budding::before { background: linear-gradient(90deg, currentColor 50%, transparent 50%); }
.badge-evergreen::before, .key-evergreen::before { background: currentColor; }
/* An AI page gets a square, not a stage circle: it is not a note that grows. */
.badge-ai::before { border-radius: 0; background: linear-gradient(135deg, transparent calc(50% - 1px), currentColor calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)); }

/* Link graph: a permanent note's neighbors, drawn by script.js as a faint field behind the
   face text (note link graph plan). The row exists from first paint only when scripts run and
   the note has R18's minimum of 1 neighbor, so readers without JS get no gap (KTD4). The
   script draws only when this row exists. */
@media (scripting: enabled) {
  .face:has(> .graph > li:nth-child(1)) {
    grid-template-areas: "run run" "field field" "title stage";
    grid-template-rows: auto clamp(8rem, 18vw, 14rem) auto;
    row-gap: clamp(1rem, 3vw, 2rem);
  }
}
@media (scripting: enabled) and (max-width: 36rem) {
  .face:has(> .graph > li:nth-child(1)) {
    grid-template-areas: "run" "field" "title" "stage";
    grid-template-rows: auto clamp(8rem, 18vw, 14rem) auto auto;
  }
}
/* Text paints above the graph: positioned, and after it in tree order (KTD6). */
.face > .runhead, .face > h1, .face > .stage { position: relative; }
.graph-field { position: absolute; inset: 0; pointer-events: none; }
.graph-edge { fill: none; stroke: var(--rule); stroke-width: 1; }
/* The face fill hides the edge under a mark, so faintness dims the stroke only. */
.graph-mark { fill: var(--face); stroke: var(--mute); stroke-width: 1.5; stroke-opacity: .55; }
.graph-slash { stroke-width: 1; }
.graph-current { fill: var(--mark); }
/* A 12px radius makes a 24px target (KTD6). */
.graph-hit { fill: transparent; pointer-events: auto; cursor: pointer; }
.graph-edge, .graph-mark { transition: stroke .3s var(--ease), stroke-width .3s var(--ease), stroke-opacity .3s var(--ease); }
.graph-edge.lit { stroke: var(--link); stroke-width: 1.5; }
.lit > .graph-mark { stroke: var(--link); stroke-opacity: 1; }
/* A missing target (graph plan R20) is a bare slash, a dead end that lights in Pencil Grey,
   the unpublished link colour, never link olive. */
.missing > .graph-slash { stroke-width: 1.5; }
.missing > .graph-hit { cursor: default; }
.graph-edge.missing.lit, .missing.lit > .graph-mark { stroke: var(--mute); }
.graph-label { font: 500 .875rem/1 var(--credit); fill: var(--ink); stroke: var(--face); stroke-width: 4px; stroke-linejoin: round; paint-order: stroke; }

/* ---- Obi band ---- */

.obi {
  background: var(--band);
  color: var(--band-soft);
  padding: 1.25rem var(--inline) 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
  gap: 1.25rem 1.75rem;
  font: 500 .875rem/1.3 var(--credit);
  letter-spacing: .06em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}
.obi p, .obi ul { margin: 0; }
.obi a { color: var(--band-ink); text-decoration-color: var(--band-rule); }
.obi a:hover { text-decoration-color: currentColor; }
.obi :focus-visible { outline-color: var(--band-ink); }
.obi ::selection { background: var(--band-ink); color: var(--band); }

.credit { border-left: 1px solid var(--band-rule); padding-left: .85rem; display: flex; flex-direction: column; gap: .4rem; }
.credit .k { font-weight: 600; font-size: .75rem; letter-spacing: .22em; color: var(--band-label); }
.credit .fine { font-size: .75rem; letter-spacing: .14em; line-height: 1.4; color: var(--band-label); }
.credit .fine b { color: var(--band-ink); font-weight: 700; }

.credit-no { display: grid; grid-template-columns: auto auto; grid-template-areas: "k k" "big side"; justify-content: start; column-gap: .75rem; row-gap: .25rem; }
.credit-no .k { grid-area: k; }
.big { grid-area: big; font: 800 clamp(4.5rem, 3rem + 4vw, 7rem)/.84 var(--credit); letter-spacing: -.02em; color: var(--band-ink); }
/* The obi's spine credit: set vertically beside the number, as on a printed band. */
.credit-no .fine { grid-area: side; writing-mode: vertical-rl; transform: rotate(180deg); align-self: end; line-height: 1.2; }

.by { color: var(--band-ink); font-weight: 700; font-size: 1.125rem; line-height: 1.1; }
.key { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .3rem 1rem; color: var(--band-label); font-size: .8125rem; letter-spacing: .12em; }
.key li { display: inline-flex; align-items: center; gap: .5em; }

.cites, .maps { list-style: none; padding: 0; display: grid; gap: .45rem; }
.cites li { color: var(--band-soft); font-size: .8125rem; line-height: 1.3; text-wrap: balance; }
.cites .citation { font-style: normal; }
.cites .citation > a:first-child { font-size: 1rem; font-weight: 700; letter-spacing: .03em; }
.maps a { font-size: 1.125rem; font-weight: 700; letter-spacing: .06em; }

/* The generator emits every band slot on every page, empty when a page has no value.
   Lines that make a claim (who wrote it, AI sources, stage) stay hidden unless :has() proves
   they apply, so a browser without :has() shows no false credit. */
.credit-no:has(.big:empty),
.credit-maps:not(:has(.maps)) .k-maps,
.counts .out:has(b:empty),
.tended:not(:has(time)) { display: none; }
.credit-cites, .by, .key, .k-links, .credit-ai { display: none; }
.credit-cites:has(.cites) { display: flex; }
/* Sources carry no number, so the AI mark takes the number's place at band scale. */
.sleeve:has(.badge-ai) .credit-ai { display: grid; }
.sleeve:has(.badge-ai) .by-ai,
.sleeve:not(:has(.badge-ai)) .by-human,
.credit-maps:not(:has(.maps)) .k-links { display: block; }
.sleeve:has(.badge-seedling, .badge-budding, .badge-evergreen) .key { display: flex; }
.sleeve:has(.badge-seedling) .key-seedling,
.sleeve:has(.badge-budding) .key-budding,
.sleeve:has(.badge-evergreen) .key-evergreen { color: var(--band-ink); font-weight: 700; }

/* ---- Shelf: reading column and page tree ---- */

.shelf {
  max-width: calc(var(--page) + 2 * var(--gutter));
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 3.5rem) var(--gutter) 5rem;
  display: grid;
  gap: 3.5rem;
}

main { min-width: 0; max-width: 42rem; }
main > :first-child { margin-top: 0; }
main p, main li { max-width: 66ch; text-wrap: pretty; }
main p { margin: 0 0 1em; }

main h1, main h2, main h3 { text-wrap: balance; }
/* Source pages carry their own `#` heading inside the content. */
main h1 { font: 300 2.125rem/1.15 var(--title); letter-spacing: -.01em; margin: 3rem 0 1rem; }
main h2 {
  font: 700 1.25rem/1.2 var(--credit);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--link);
  margin: 2.75rem 0 .75rem;
  padding-top: .75rem;
  border-top: 1px solid var(--rule);
}
main h3 { font: 700 1rem/1.3 var(--credit); letter-spacing: .14em; text-transform: uppercase; margin: 2rem 0 .5rem; }

main ul, main ol { padding: 0; margin: 0 0 1.25em; }
main ul { list-style: none; }
main ol { padding-left: 1.5em; }
main li { margin-bottom: .6em; }
main ul > li { position: relative; padding-left: 1.5em; }
main ul > li::before { content: ""; position: absolute; left: .1em; top: .62em; width: .5em; height: .5em; border: 1.5px solid var(--mark); }

.citation { font-style: normal; }
/* The affiliate disclosure inherits the citation's size and contrast, and never wraps apart. */
.paid-link { white-space: nowrap; }
/* The second link in a source citation is the original, set as a small credit. */
main .citation > a + a { font: 600 .8125rem/1 var(--credit); letter-spacing: .14em; text-transform: uppercase; }
/* After the original, the disclosure matches that credit, in full ink. */
main .citation > a + a + .paid-link { font: 600 .8125rem/1 var(--credit); letter-spacing: .14em; text-transform: uppercase; color: var(--ink); }

.ai-notice { background: var(--face); border: 1px solid var(--rule); padding: .9rem 1.1rem; font-size: .9375rem; }
.unpublished { color: var(--mute); border-bottom: 1px dotted currentColor; }

code { font: .875em/1 ui-monospace, "SF Mono", Menlo, monospace; background: var(--code); padding: .1em .3em; border-radius: 2px; }
pre { overflow-x: auto; background: var(--code); padding: 1rem; }
pre code { padding: 0; background: none; }
blockquote { margin: 1.5em 0; padding-left: 1.25em; border-left: 1px solid var(--mark); font-style: italic; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

/* Tables take a strip of the band as their head row. */
table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 1.25rem 0 1.75rem; font-size: .9375rem; line-height: 1.45; }
/* A shade on the edge that has more columns, so a clipped table reads as scrollable. The
   ground-coloured covers scroll with the content and hide the shade at either end. */
table {
  background:
    linear-gradient(to right, var(--ground) 30%, transparent) left / 2rem 100% no-repeat local,
    linear-gradient(to left, var(--ground) 30%, transparent) right / 2rem 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, var(--scroll-shade), transparent) left / .75rem 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, var(--scroll-shade), transparent) right / .75rem 100% no-repeat scroll;
}
th { background: var(--band); color: var(--band-ink); font: 700 .8125rem/1.2 var(--credit); letter-spacing: .14em; text-transform: uppercase; text-align: left; padding: .55rem .8rem; }
td { padding: .6rem .8rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th:first-child, td:first-child { padding-left: 0; }
th:first-child { padding-left: .8rem; }

.linked { margin-top: 3.5rem; }
.linked:not(:has(.backlinks)) { display: none; }
.linked .linked-head { color: var(--mute); font-size: .875rem; letter-spacing: .2em; }
.backlinks ul { margin: 0; }
.backlinks li::before { display: none; }
.backlinks li { padding-left: 0; }
.backlinks a { font: 700 1.125rem/1.3 var(--credit); letter-spacing: .06em; text-transform: uppercase; text-decoration: none; }
.backlinks a:hover { text-decoration: underline; }

/* Page tree. Maps read as credits; notes keep sentence case so long titles stay legible. */
.sidebar { font: 500 1rem/1.3 var(--credit); letter-spacing: .02em; border-top: 2px solid var(--mark); padding-top: 1rem; }
.sidebar::before { content: "Index"; display: block; margin-bottom: .75rem; font-weight: 600; font-size: .75rem; letter-spacing: .22em; text-transform: uppercase; color: var(--mute); }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar ul ul { padding: .35rem 0 .5rem .95rem; border-left: 1px solid var(--rule); margin-left: .3rem; }
.sidebar li { margin: .3rem 0; text-wrap: balance; }
.sidebar a { color: var(--ink); text-decoration: none; }
.sidebar a:hover { color: var(--link); text-decoration: underline; }
.sidebar > ul > li > a, .sidebar summary { font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.sidebar summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: .5rem; }
.sidebar summary::-webkit-details-marker { display: none; }
.sidebar summary::before { content: ""; width: .4rem; height: .4rem; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: rotate(-45deg); transition: transform .35s var(--ease); }
.sidebar details[open] > summary::before { transform: rotate(45deg) translate(-.1rem, -.1rem); }
.sidebar summary:hover { color: var(--link); }
.sidebar [aria-current="page"] { color: var(--link); font-weight: 700; }
.sidebar [aria-current="page"]::before { content: ""; display: inline-block; width: .45em; height: .45em; margin-right: .45em; background: var(--mark); vertical-align: .12em; }

/* Colophon: the analytics note and its opt-out, quiet under the shelf. */
.colophon { padding: 0 var(--inline) 3rem; color: var(--mute); font-size: .875rem; line-height: 1.5; }
.colophon p { max-width: 66ch; margin: 0 0 .75rem; }
.colophon button { font: 700 .8125rem/1 var(--credit); letter-spacing: .14em; text-transform: uppercase; color: var(--ink); background: none; border: 1.5px solid var(--mark); padding: .55rem .8rem; cursor: pointer; }
.colophon button:hover { background: var(--face); }
.colophon button[aria-pressed="true"] { background: var(--band); border-color: var(--band); color: var(--band-ink); }

/* Phone: the stage drops under the title so the title keeps the full width. */
@media (max-width: 36rem) {
  .face { grid-template-columns: minmax(0, 1fr); grid-template-areas: "run" "title" "stage"; row-gap: 2.5rem; }
  .face h1 { margin-bottom: -1rem; }
  .stage .badge::before { width: 1.75rem; height: 1.75rem; }
  .runhead { font-size: .75rem; letter-spacing: .14em; column-gap: 1rem; }
}

@media (min-width: 60rem) {
  .shelf { grid-template-columns: minmax(0, 42rem) minmax(13rem, 17rem); justify-content: space-between; column-gap: 4rem; }
  .sidebar { position: sticky; top: 1.5rem; align-self: start; max-height: calc(100vh - 3rem); overflow-y: auto; }
  /* The AI block leads the band only on sources; elsewhere the number column does. */
  .credit:first-child { border-left: 0; padding-left: 0; }
  /* Its own rule: a browser without :has() would drop the whole list. */
  .sleeve:not(:has(.badge-ai)) .credit-ai + .credit { border-left: 0; padding-left: 0; }
}

@media print {
  .graph-field { display: none; }
}

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