/* ==========================================================================
   Reignance Studios — reading pages (Field Notes, case files, buyer's guide)
   Loaded after minimal.css on the nine reading pages only. Tokens come from minimal.css.
   Scoped exceptions to DESIGN.md: light/dark theme, reading-progress line, one-shot block reveal.
   ========================================================================== */

:root {
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --read-measure: 68ch;
  --read-toc: 220px;
}

/* ---------- Dark theme (reader choice, else system preference; set before paint by reading-theme.js) ---------- */
html[data-theme="dark"] {
  --paper: var(--ink-850);
  --soft: var(--ink-750);
  --ink: var(--ink-50);
  --ink-2: var(--ink-100);
  --muted: var(--ink-150);
  --line: var(--ink-600);
  --line-2: var(--ink-500);
  --black: var(--ink-700);
  --on-black: #FFFFFF;
  --on-black-2: var(--ink-150);
  --grid-rule: rgba(255, 255, 255, 0.05);
  color-scheme: dark;
}
html[data-theme="dark"] .logo img { filter: invert(1); }
html[data-theme="dark"] .display em,
html[data-theme="dark"] .read-body h2 em { color: var(--hl); }
html[data-theme="dark"] .pill:hover { background: var(--hl); border-color: var(--hl); }
html[data-theme="dark"] .dark { border-block: 1px solid var(--line); }
html[data-theme="dark"] .dark .pill { color: var(--ink-900); }
html[data-theme="dark"] .dark .pill--ghost { color: var(--on-black); }
html[data-theme="dark"] .dark .pill--ghost:hover { color: var(--ink-900); }

/* ---------- Header additions: theme toggle + progress line ---------- */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 44px; height: 44px; border-radius: 999px; border: 1px solid var(--line-2);
  background: var(--paper); color: var(--ink); cursor: pointer;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease);
}
.theme-toggle:hover { border-color: var(--ink); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .i-sun { display: none; }
html[data-theme="dark"] .theme-toggle .i-sun { display: block; }
html[data-theme="dark"] .theme-toggle .i-moon { display: none; }

.read-progress {
  position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: var(--ink); transform-origin: left center; transform: scaleX(0); pointer-events: none;
}

/* ---------- Breadcrumb: long case/article titles wrap beside their separator ---------- */
.crumbs li { display: flex; align-items: center; min-width: 0; }
.crumbs li + li::before { flex: none; }
.crumbs [aria-current="page"] { display: block; min-height: 44px; padding-block: 0.7rem; line-height: 1.45; }

/* ---------- Layout ---------- */
.read-main { padding-block: clamp(2.5rem, 5vw, 4rem) clamp(4rem, 8vw, 6rem); }
.read-layout { display: grid; grid-template-columns: var(--read-toc) minmax(0, 1fr); gap: 2rem clamp(2rem, 5vw, 4.5rem); align-items: start; }

/* ---------- Contents list ---------- */
.read-toc { position: sticky; top: calc(73px + 1.5rem); max-height: calc(100vh - 73px - 3rem); overflow: auto; }
.read-toc details > summary {
  display: flex; align-items: center; justify-content: space-between; min-height: 44px;
  font-size: var(--fs-label); font-weight: 600; color: var(--ink); list-style: none; cursor: pointer;
}
.read-toc details > summary::-webkit-details-marker { display: none; }
.read-toc details > summary::after {
  content: ""; width: 8px; height: 8px; margin-right: 4px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px); transition: transform 220ms var(--ease);
}
.read-toc details[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
.read-toc ol { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--ink); }
.read-toc li { border-bottom: 1px solid var(--line); }
.read-toc li a {
  display: grid; grid-template-columns: 2.4ch minmax(0, 1fr); gap: 0.6rem; align-items: baseline;
  min-height: 44px; padding: 0.7rem 0 0.7rem 0.75rem; border-left: 2px solid transparent;
  font-size: var(--fs-small); line-height: 1.35; color: var(--muted);
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}
.read-toc li a:hover { color: var(--ink); }
.read-toc li a[aria-current="true"] { color: var(--ink); font-weight: 600; border-left-color: var(--ink); }
.read-toc-no { font-size: var(--fs-label); font-variant-numeric: tabular-nums; }
.read-toc-cta { margin-top: 1.25rem; font-size: var(--fs-small); color: var(--muted); }
.read-toc-cta p { max-width: 30ch; }
.read-toc-cta .text-link { color: var(--ink); }

/* ---------- Body type ---------- */
.read-body { min-width: 0; font-size: var(--fs-body); line-height: 1.7; color: var(--ink-2); }
.read-body > * + * { margin-top: 1.15rem; }
.read-body > p, .read-body > ul, .read-body > h3, .read-body > .read-note, .read-body > .read-quote, .read-body > .read-fig { max-width: var(--read-measure); }
.read-body h2 {
  margin-top: clamp(3rem, 6vw, 4.5rem); padding-top: 1.25rem; border-top: 1px solid var(--ink);
  font-weight: 700; font-size: var(--fs-figure); line-height: 1.1; letter-spacing: -0.03em;
  color: var(--ink); text-wrap: balance; scroll-margin-top: 96px;
}
.read-body > h2:first-child { margin-top: 0; }
.read-body h2 + * { margin-top: 1.25rem; }
.read-body h3 { margin-top: 2rem; font-weight: 600; font-size: var(--fs-title-sm); line-height: 1.3; letter-spacing: -0.015em; color: var(--ink); }
.read-body h3 + p { margin-top: 0.5rem; }
.read-body p strong, .read-body li strong { color: var(--ink); font-weight: 600; }
.read-body a { color: var(--ink); text-decoration: underline; text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
.read-body a:hover { text-decoration-thickness: 2px; }
.read-body ul { margin-bottom: 0; padding: 0; list-style: none; }
.read-body ul li { position: relative; padding-left: 1.4rem; }
.read-body ul li + li { margin-top: 0.65rem; }
.read-body ul li::before { content: ""; position: absolute; left: 0.1rem; top: 0.68em; width: 6px; height: 6px; background: var(--ink); }
.read-body :not(pre) > code {
  padding: 0.05em 0.35em; border: 1px solid var(--line); background: var(--soft);
  font-family: var(--mono); font-size: var(--fs-small); color: var(--ink); overflow-wrap: anywhere;
}

/* ---------- Metrics ---------- */
.read-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 0; padding: 0; list-style: none; border-block: 1px solid var(--ink); }
.read-metrics:has(> li:nth-child(4)) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.read-metrics > li { padding: 1.2rem 1rem 1.35rem; border-left: 1px solid var(--line); }
.read-metrics > li:first-child { padding-left: 0; border-left: 0; }
.read-metrics > li::before { content: none; }
.read-metric-val { display: block; font-weight: 700; font-size: var(--fs-figure); line-height: 1.1; letter-spacing: -0.03em; color: var(--ink); font-variant-numeric: tabular-nums; }
.read-metric-label { display: block; margin-top: 0.35rem; font-size: var(--fs-small); font-weight: 600; line-height: 1.35; color: var(--ink); }
.read-metric-sub { display: block; margin-top: 0.2rem; font-size: var(--fs-label); line-height: 1.4; color: var(--muted); }

/* ---------- Notes ---------- */
.read-note { padding: 1.2rem 1.4rem 1.3rem; background: var(--soft); border: 1px solid var(--line); }
.read-note--warn { border-color: var(--ink); }
.read-note-label { margin-bottom: 0.35rem; font-size: var(--fs-label); font-weight: 600; color: var(--ink); }
.read-note p { font-size: var(--fs-body-sm); line-height: 1.65; color: var(--ink-2); }
.read-note p + p { margin-top: 0.6rem; }

/* ---------- Quote ---------- */
.read-quote { margin-block: 2.25rem; padding-top: 1.25rem; border-top: 1px solid var(--ink); }
.read-body > .read-quote { margin-top: 2.25rem; }
.read-quote p { max-width: 40ch; font-family: var(--serif); font-style: italic; font-weight: 500; font-size: var(--fs-title-md); line-height: 1.35; letter-spacing: -0.01em; color: var(--ink); }

/* ---------- Tables ---------- */
.read-table-wrap { overflow-x: auto; border-top: 1px solid var(--ink); }
.read-table { width: 100%; min-width: 34rem; border-collapse: collapse; font-size: var(--fs-body-sm); line-height: 1.5; }
.read-table th { padding: 0.8rem 1rem 0.8rem 0; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: bottom; font-size: var(--fs-label); font-weight: 600; color: var(--ink); }
.read-table td { padding: 0.85rem 1rem 0.85rem 0; border-bottom: 1px solid var(--line); vertical-align: top; color: var(--ink-2); }
.read-table td:first-child { font-weight: 600; color: var(--ink); }
.read-table .is-good, .read-table .is-bad { font-variant-numeric: tabular-nums; }
/* Glyphs are decorative (empty alt text): the Before/After column headers carry the meaning. */
.read-table .is-good::before { content: "✓\00a0" / ""; color: var(--ink); font-weight: 700; }
.read-table .is-bad::before { content: "✕\00a0" / ""; color: var(--muted); font-weight: 700; }

/* ---------- Quote attribution, metric units ---------- */
.read-quote cite { display: block; margin-top: 0.75rem; font-family: var(--sans); font-style: normal; font-size: var(--fs-small); color: var(--muted); }
.read-metric-unit { font-size: var(--fs-lede); font-weight: 600; letter-spacing: -0.01em; }

/* ---------- Field Notes list (blog index) ---------- */
.read-list { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--ink); }
.read-list > li::before { content: none; }
.read-list a {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) 44px; gap: 0.45rem 1.5rem; align-items: start;
  padding: 1.8rem 1rem; border-bottom: 1px solid var(--line); color: var(--ink);
  transition: background-color 220ms var(--ease), color 220ms var(--ease);
}
.read-list-no { grid-column: 1; grid-row: 1 / span 3; padding-top: 0.2rem; font-size: var(--fs-label); color: var(--muted); font-variant-numeric: tabular-nums; }
.read-list-meta { grid-column: 2; font-size: var(--fs-label); color: var(--muted); font-variant-numeric: tabular-nums; }
.read-list h2 { grid-column: 2; font-weight: 600; font-size: var(--fs-title-md); line-height: 1.2; letter-spacing: -0.025em; text-wrap: balance; }
.read-list p { grid-column: 2; max-width: 64ch; font-size: var(--fs-body-sm); line-height: 1.6; color: var(--muted); }
.read-list .arrow { grid-column: 3; grid-row: 1 / span 3; align-self: center; }
.read-list :not(pre) > code { padding: 0.05em 0.35em; border: 1px solid var(--line); background: var(--soft); font-family: var(--mono); font-size: var(--fs-small); color: var(--ink); overflow-wrap: anywhere; }
.read-list a:hover, .read-list a:focus-visible { background: var(--black); color: var(--on-black); }
.read-list a:hover .read-list-no, .read-list a:hover .read-list-meta, .read-list a:hover p,
.read-list a:focus-visible .read-list-no, .read-list a:focus-visible .read-list-meta, .read-list a:focus-visible p { color: var(--on-black-2); }
.read-list a:hover .arrow, .read-list a:focus-visible .arrow { border-color: var(--on-black); }
.read-list a:focus-visible { outline-offset: -4px; outline-color: var(--hl); }
@media (max-width: 600px) {
  .read-list a { grid-template-columns: minmax(0, 1fr) 44px; padding-inline: 0; }
  .read-list-no { display: none; }
  .read-list-meta, .read-list h2, .read-list p { grid-column: 1; }
  .read-list .arrow { grid-column: 2; }
}

/* ---------- Code ---------- */
.read-code { border: 1px solid var(--line); background: var(--soft); }
.read-code-head { display: flex; flex-wrap: wrap; gap: 0.2rem 0.6rem; align-items: baseline; padding: 0.6rem 1rem; border-bottom: 1px solid var(--line); font-size: var(--fs-label); color: var(--muted); }
.read-code-head b { font-weight: 600; color: var(--ink); }
.read-code pre { margin: 0; padding: 1rem; overflow-x: auto; font: 400 var(--fs-small)/1.65 var(--mono); color: var(--ink); tab-size: 4; }
.read-code pre code { font: inherit; }
.read-code .kw { font-weight: 600; color: var(--ink); }
.read-code .ty { color: var(--ink); }
.read-code .fn, .read-code .st { color: var(--ink-2); }
.read-code .cm { font-style: italic; color: var(--muted); }
.read-code .nu { font-variant-numeric: tabular-nums; }

/* ---------- Figure captions (no image placeholders) ---------- */
.read-fig { padding-top: 0.85rem; border-top: 1px solid var(--line); }
.read-fig figcaption { font-size: var(--fs-body-sm); line-height: 1.6; color: var(--muted); }
.read-fig figcaption b { font-weight: 600; color: var(--ink); }

/* ---------- Next / previous ---------- */
.read-next { margin-top: clamp(3rem, 6vw, 4.5rem); border-top: 1px solid var(--ink); }
.read-next a {
  display: grid; grid-template-columns: minmax(0, 1fr) 44px; gap: 1rem 1.5rem; align-items: center;
  padding: 1.3rem 1rem; border-bottom: 1px solid var(--line); color: var(--ink);
  transition: background-color 220ms var(--ease), color 220ms var(--ease);
}
.read-next-dir { display: block; font-size: var(--fs-label); color: var(--muted); }
.read-next-title { display: block; margin-top: 0.2rem; font-size: var(--fs-title-sm); font-weight: 500; line-height: 1.3; letter-spacing: -0.02em; }
.read-next a:hover, .read-next a:focus-visible { background: var(--black); color: var(--on-black); }
.read-next a:hover .read-next-dir, .read-next a:focus-visible .read-next-dir { color: var(--on-black-2); }
.read-next a:hover .arrow, .read-next a:focus-visible .arrow { border-color: var(--on-black); }
.read-next a:focus-visible { outline-offset: -4px; outline-color: var(--hl); }

/* ---------- Scroll reveal: armed by script only, below the fold, once ---------- */
[data-reveal].is-armed { opacity: 0; transform: translateY(10px); }
[data-reveal].is-armed.is-in { opacity: 1; transform: none; transition: opacity 500ms var(--ease), transform 600ms var(--ease); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .read-layout { grid-template-columns: minmax(0, 1fr); }
  .read-toc { position: static; max-height: none; overflow: visible; border-block: 1px solid var(--line); }
  .read-toc ol { border-top-color: var(--line); }
  .read-metrics:has(> li:nth-child(4)) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .read-metrics:has(> li:nth-child(4)) > li:nth-child(odd) { padding-left: 0; border-left: 0; }
  .read-metrics:has(> li:nth-child(4)) > li:nth-child(n+3) { border-top: 1px solid var(--line); }
}
@media (min-width: 901px) {
  .read-toc details > summary { pointer-events: none; }
  .read-toc details > summary::after { content: none; }
}
@media (max-width: 600px) {
  .theme-toggle { margin-left: auto; }
  .theme-toggle + .menu-btn { margin-left: 0; }
  .read-metrics { grid-template-columns: minmax(0, 1fr); }
  .read-metrics:has(> li:nth-child(4)) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .read-metrics:not(:has(> li:nth-child(4))) > li { padding-left: 0; border-left: 0; }
  .read-metrics:not(:has(> li:nth-child(4))) > li + li { border-top: 1px solid var(--line); }
  .read-next a { padding-inline: 0; }
}

@media print {
  .read-toc, .read-progress, .theme-toggle, .cta-band { display: none; }
  .read-layout { grid-template-columns: minmax(0, 1fr); }
  [data-reveal].is-armed { opacity: 1 !important; transform: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  [data-reveal].is-armed { opacity: 1; transform: none; transition: none; }
  .read-toc details > summary::after, .theme-toggle { transition: none; }
}
