/* ── Self-hosted fonts (variable woff2, Latin subset) ────── */
@font-face {
  font-family: 'Cormorant Garamond';
  font-style: italic;
  font-weight: 400 600;
  src: url('fonts/cormorant-garamond-italic.woff2') format('woff2');
  font-display: fallback;
}
@font-face {
  font-family: 'Cormorant Garamond';
  font-style: normal;
  font-weight: 500;
  src: url('fonts/cormorant-garamond.woff2') format('woff2');
  font-display: fallback;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 700;
  src: url('fonts/inter.woff2') format('woff2');
  font-display: fallback;
}
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 400 600;
  src: url('fonts/space-grotesk.woff2') format('woff2');
  font-display: fallback;
}

/* ── Palette ────────────────────────────────────────────── */
:root {
  /* Warm paper + ink */
  --paper:        #fbfaf6;
  --paper-soft:   #f4f1e8;
  --ink:          #14110a;
  --ink-soft:     #4a4534;
  --rule:         rgba(20, 17, 10, 0.14);
  --rule-soft:    rgba(20, 17, 10, 0.07);

  /* Links — pulled into the site's teal accent. */
  --link:         #3f7a8a;
  --link-visited: #6c8088;
  --link-hover:   #1c5b6b;

  /* Selection + highlight */
  --selection:    #ffe066;
  --mark:         #fff3a8;

  /* The single accent — dusty teal, reads as "second plate" */
  --seam-tint:        #6da4b8;
  --seam-tint-strong: #3f7a8a;

  /* Type stacks */
  --serif:  "Charter", "Iowan Old Style", "Sitka Text",
            "Source Serif Pro", Georgia, "Times New Roman", Times, serif;
  --sans:   "Inter", "Söhne", "GT America", -apple-system,
            BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial,
            sans-serif;
  --mono:   ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas,
            "Liberation Mono", monospace;
  --serif-display: "Cormorant Garamond", "Cormorant", "EB Garamond",
                   "Hoefler Text", Charter, Georgia, serif;
  --seam-face: "Space Grotesk", "Inter", -apple-system, sans-serif;

  /* Layout */
  --topbar-h:        44px;
  --measure:         38rem;
  --measure-prelude: 46rem;
  --rail-w:          220px;
  --rail-gap:        32px;
}

[data-theme="dark"] {
  --paper:        #15140f;
  --paper-soft:   #1d1c16;
  --ink:          #ece7d6;
  --ink-soft:     #a39d8a;
  --rule:         rgba(236, 231, 214, 0.16);
  --rule-soft:    rgba(236, 231, 214, 0.08);

  --link:         #a4d0dc;
  --link-visited: #88a8b2;
  --link-hover:   #c4e0e8;

  --selection:    #44391a;
  --mark:         rgba(255, 243, 168, 0.22);

  /* Lift the accent for dark paper. */
  --seam-tint:        #7fb6c8;
  --seam-tint-strong: #a4d0dc;
}

/* On wide viewports, let the rails breathe — wider gutters mean
   shorter wraps inside the notes. Capped so the rails never
   compete with the center column for the eye. The 220px floor
   matches the inline breakpoint below: above 1100px the rails
   are always 220px+. */
@media (min-width: 1100px) {
  :root {
    --rail-w:   clamp(220px, 16vw, 300px);
    --rail-gap: clamp(32px, 2.6vw, 44px);
  }
}

/* Follow the OS preference when the user has not made an explicit choice. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:        #15140f;
    --paper-soft:   #1d1c16;
    --ink:          #ece7d6;
    --ink-soft:     #a39d8a;
    --rule:         rgba(236, 231, 214, 0.16);
    --rule-soft:    rgba(236, 231, 214, 0.08);

    --link:         #a4d0dc;
    --link-visited: #88a8b2;
    --link-hover:   #c4e0e8;

    --selection:    #44391a;
    --mark:         rgba(255, 243, 168, 0.22);

    --seam-tint:        #7fb6c8;
    --seam-tint-strong: #a4d0dc;
  }
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.6;
  font-feature-settings: "kern", "liga", "onum";
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overflow-wrap: break-word;
}
::selection { background: var(--selection); color: var(--ink); }

/* ── Keyboard focus ─────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--seam-tint-strong);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Skip-to-content — visually offscreen until focused. */
.skip-link {
  position: absolute;
  left: 12px;
  top: -100px;
  z-index: 100;
  padding: 8px 12px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  text-decoration: none;
}
.skip-link:focus-visible {
  top: 8px;
}

/* ── Topbar ─────────────────────────────────────────────── */
body > header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  background: color-mix(in srgb, var(--paper) 85%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 0.5px solid var(--rule);
}
site-title {
  display: inline-block;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: 18px;
  margin: 0 6px 0 4px;
  white-space: nowrap;
  letter-spacing: 0.005em;
}
site-title a { color: inherit; text-decoration: none; }
site-title a:hover { text-decoration: underline; text-underline-offset: 3px; }
header > span { flex: 1; }
header nav {
  display: flex;
  font-family: var(--sans);
  font-size: 13px;
}
header nav a {
  color: var(--ink-soft);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 4px;
}
header nav a:hover { color: var(--ink); background: var(--rule-soft); }

/* Theme toggle — mirrors the header nav link sizing. The icon swaps via
   data-theme so we don't need a script to update aria/text. */
header button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--seam-tint-strong);
  width: 32px;
  height: 32px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
header button:hover { background: var(--rule-soft); }
header button svg { width: 16px; height: 16px; display: block; }
/* Show the moon in light mode ("switch to dark"); sun in dark mode. */
/* Default (light): show moon ("switch to dark"). */
header button .icon-sun { display: none; }
/* Dark via OS preference (no explicit override) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) header button .icon-sun  { display: block; }
  :root:not([data-theme="light"]) header button .icon-moon { display: none; }
}
/* Explicit dark override */
[data-theme="dark"] header button .icon-sun  { display: block; }
[data-theme="dark"] header button .icon-moon { display: none; }

/* ── Page shell for the entry ───────────────────────────── */
article {
  min-height: 100%;
}

/* ── Article header — eyebrow + title, siblings of dann-text */
article > header {
  max-width: var(--measure-prelude);
  margin: 0 auto;
  padding: 64px 32px 0;
}

/* ── dann-text (human-written prelude) ────────────────────
   Custom element, so default display is inline; force block. */
dann-text {
  display: block;
  max-width: var(--measure-prelude);
  margin: 0 auto;
  padding: 0 32px 24px;
}

/* Eyebrow — Space Grotesk caps with a tinted printer's bar.
   Used in article headers and on the cabinet page. */
eye-brow {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.6em;
  margin: 0 0 18px;
  white-space: nowrap;
  font-family: var(--seam-face);
  font-weight: 500;
  font-size: 11px;
  line-height: 1.4;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.78;
}
eye-brow > span { white-space: nowrap; }
.eyebrow-bar {
  display: inline-block;
  width: 3px;
  height: 14px;
  background: var(--seam-tint-strong);
  flex: 0 0 auto;
}
.eyebrow-sep { opacity: 0.5; font-weight: 400; }

article h1 {
  font-family: var(--serif-display);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(2.4rem, 1.6rem + 2.8vw, 3.6rem);
  line-height: 1.05;
  letter-spacing: -0.012em;
  color: var(--ink);
  margin: 0 0 0.65em;
  text-wrap: balance;
}

dann-text p {
  font-size: 17.5px;
  line-height: 1.62;
  margin: 0 0 1em;
  text-wrap: pretty;
}
dann-text a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 0.5px;
  text-underline-offset: 2px;
}
dann-text a:visited { color: var(--link-visited); }
dann-text a:hover   { color: var(--link-hover); }

/* ── Seam (AUTOTEXT divider, FIN closer) ────────────────── */
.seam {
  --seam-fade: 0.5;
  margin: 56px auto 44px;
  max-width: var(--measure-prelude);
  padding: 0 32px;
  pointer-events: none;
  user-select: none;
  opacity: var(--seam-fade);
}
.seam-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.seam-rule {
  flex: 1;
  height: 0;
  border-top: 0.5px solid var(--ink);
  opacity: 0.55;
}
.seam-word {
  font-family: var(--seam-face);
  font-weight: 500;
  font-size: 10.5px;
  letter-spacing: 0.5em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--paper);
  /* Uneven padding compensates for trailing letter-spacing. */
  padding: 0 12px 0 calc(12px + 0.5em);
  white-space: nowrap;
}

/* ── auto-text (autotext-generated walkthrough) ───────────
   Custom element, so default display is inline; force block. */
auto-text {
  display: block;
  font-family: var(--sans);
  font-size: 16.5px;
  line-height: 1.6;
  letter-spacing: -0.005em;
  color: var(--ink);
  margin: 0 auto;
  max-width: var(--measure);
  padding: 0 32px 80px;
}
auto-text h2 {
  font-weight: 600;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  margin: 2em 0 0.5em;
}
auto-text p {
  margin: 0 0 1em;
  text-wrap: pretty;
  text-align: justify;
  hyphens: auto;
}
auto-text a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 0.5px;
  text-underline-offset: 2px;
}
auto-text a:visited { color: var(--link-visited); }
auto-text a:hover   { color: var(--link-hover); }
auto-text code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--paper-soft);
  padding: 0.05em 0.32em;
  border-radius: 3px;
  border: 0.5px solid var(--rule);
}

/* ── The block: paragraph + optional notes ──────────────── */
auto-text section {
  position: relative;
  margin: 0 0 1.1em;
}
auto-text section > p,
auto-text section > h2 { margin: 0 0 0.4em; }

/* Inline ref paired with a numbered sidenote. */
auto-text sup {
  font-family: var(--seam-face);
  font-size: 0.62em;
  font-weight: 600;
  font-feature-settings: "tnum";
  vertical-align: super;
  line-height: 0;
  color: var(--seam-tint-strong);
  margin: 0 0.05em 0 0.1em;
  letter-spacing: 0.04em;
}

/* ── Notes — wide viewports: pull into gutters ─────────────
   Each note is positioned by JS (_partials/notes.html); the
   stylesheet just establishes the absolute frame. The rails
   may clip into the page margins at narrower widths — the
   inline fallback below kicks in at <1100px. */
@media (min-width: 1100px) {
  auto-text section > dann-note,
  auto-text section > aside {
    position: absolute;
    top: 0;
    width: var(--rail-w);
  }
  auto-text section > dann-note { right: 100%; margin-right: var(--rail-gap); }
  auto-text section > aside    { left:  100%; margin-left:  var(--rail-gap); }
}

/* ── Notes — narrow: inline below the paragraph ────────── */
@media (max-width: 1099px) {
  auto-text section > dann-note,
  auto-text section > aside {
    margin: 0.7em 0 0.4em 1.5em;
    max-width: calc(var(--measure) - 1.5em);
  }
}

/* Left rail — Dann's marginalia. Italic serif, accent border. */
dann-note {
  display: block;
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  border-left: 2px solid var(--seam-tint);
  padding: 4px 0 4px 14px;
  background: linear-gradient(to right,
    color-mix(in srgb, var(--seam-tint) 8%, transparent),
    transparent 80%);
}
/* Editor's red revision: strikethrough on body-color text + plain ins. */
dann-note del {
  color: var(--ink);
  text-decoration: line-through;
  text-decoration-color: oklch(0.55 0.18 25);
  text-decoration-thickness: 1.5px;
}
dann-note ins {
  text-decoration: none;
  color: var(--ink);
  font-style: italic;
}

/* Right rail — autotext sidenotes. Sans, numbered. */
aside {
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
  border-left: 2px solid var(--rule);
  padding: 4px 0 4px 12px;
  display: flex;
  gap: 10px;
  text-align: justify;
  hyphens: auto;
}
aside .num {
  font-family: var(--seam-face);
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  font-feature-settings: "tnum";
  color: var(--seam-tint-strong);
  flex: 0 0 auto;
  padding-top: 1px;
}

/* ── Figures ──────────────────────────────────────────────
   Every figure has a 4:3 framed image (default object-fit:
   contain — letterboxed so nothing crops). Add class="cover"
   on the img to stretch and crop. */
figure {
  margin: 1.6em 0;
  max-width: var(--measure-prelude);
}
figure > div {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--paper-soft);
  border: 0.5px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
figure > div img,
figure > div video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
figure > div img.cover,
figure > div video.cover { object-fit: cover; }
figure > figcaption {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 10px;
  line-height: 1.5;
  max-width: 36em;
}

/* ── Article footer — prev/next navigation ──────────────── */
article > footer {
  max-width: var(--measure-prelude);
  margin: 56px auto 80px;
  padding: 0 32px;
  display: flex;
  justify-content: space-between;
  gap: 32px;
}
article > footer a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 45%;
  text-decoration: none;
  color: var(--ink);
}
article > footer a[rel="next"] {
  margin-left: auto;
  text-align: right;
}
article > footer a > span:first-child {
  font-family: var(--seam-face);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.6;
}
article > footer a > span:last-child {
  font-family: var(--serif-display);
  font-style: italic;
  font-size: 1.2rem;
  line-height: 1.15;
  text-wrap: balance;
}
article > footer a:hover > span:last-child {
  text-decoration: underline;
  text-decoration-thickness: 0.5px;
  text-underline-offset: 3px;
}
@media (max-width: 720px) {
  article > footer { flex-direction: column; gap: 24px; }
  article > footer a { max-width: none; }
  article > footer a[rel="next"] { margin-left: 0; text-align: left; }
}

/* ── Signoff mark ──────────────────────────────────────── */
dann-text > img {
  display: block;
  width: 20%;
  max-width: 140px;
  height: auto;
  margin-top: 2.4em;
}

/* ── Demo code block ────────────────────────────────────── */
.codeblock {
  background: var(--paper-soft);
  border: 0.5px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
  margin: 1.2em 0;
  font-family: var(--mono);
}
.codeblock-hd {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border-bottom: 0.5px solid var(--rule);
}
.codeblock-hd .lang { opacity: 0.6; }
.codeblock pre {
  margin: 0;
  padding: 14px 16px;
  font-size: 12px;
  line-height: 1.55;
  overflow-x: auto;
}

/* ── Cabinet (browse/list page) ─────────────────────────── */
/* Scope to the cabinet's main; the article-wrapping main on
   article pages is a bare landmark with no layout of its own. */
main:has(> h1) {
  max-width: var(--measure-prelude);
  margin: 0 auto;
  padding: 64px 32px 80px;
}
main > h1 {
  font-family: var(--serif-display);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(2rem, 1.2rem + 2vw, 2.6rem);
  line-height: 1.05;
  letter-spacing: -0.012em;
  color: var(--ink);
  margin: 0 0 32px;
  text-wrap: balance;
}
main > h2 {
  font-family: var(--serif-display);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(1.5rem, 1rem + 1vw, 1.9rem);
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 56px 0 12px;
}
main > h2:first-of-type { margin-top: 0; }
.cab-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.cab-item {
  padding: 24px 0;
  border-top: 0.5px solid var(--rule);
}
.cab-meta {
  font-family: var(--seam-face);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.6;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 0.6em;
}
.cab-title {
  font-family: var(--serif-display);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(1.5rem, 1rem + 1.5vw, 2.1rem);
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  display: block;
  margin: 0 0 10px;
  text-wrap: balance;
}
.cab-title:hover {
  text-decoration: underline;
  text-decoration-thickness: 0.5px;
  text-underline-offset: 3px;
}
.cab-desc {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink-soft);
  margin: 0;
  text-wrap: pretty;
  max-width: var(--measure);
}
header nav a[aria-current="page"] { color: var(--ink); }
