/* Case studies: the index (index.html) and the template (_template.html) copied per write-up.
   Loads after ../paper.css (tokens, type, nav, footer, buttons, chips, .pp-todo, the rise-in). */

/* ───────────────────────── Shared ───────────────────────── */

.cs-crumb {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0;
  font: 400 12px/16px var(--mono); color: var(--ink-3);
}
.cs-crumb a { color: var(--ink-2); text-decoration: none; }
.cs-crumb a:hover { color: var(--accent-ink); text-decoration: underline; }
.cs-crumb .sep { color: var(--edge); }

/* Draft status: a hollow ring (the signal colour is kept for "running right now"). */
.cs-status { display: inline-flex; align-items: center; gap: 8px; margin: 0; font: 400 12px/16px var(--mono); color: var(--ink-2); }
.cs-status .ring { width: 8px; height: 8px; border: 1.5px solid var(--ink-3); border-radius: 50%; flex: none; }

/* A section head inside a write-up: mono eyebrow over a serif H2. */
.cs-shead .pp-eyebrow { margin-bottom: 12px; }
.cs-shead .pp-h2 { font-size: clamp(28px, 2.8vw, 40px); }
.cs-small { font-size: 14px; line-height: 20px; }

/* ───────────────────────── Index ───────────────────────── */

.cs-intro { padding-top: 48px; padding-bottom: 64px; row-gap: 32px; align-items: end; }
.cs-intro__head { grid-column: 1 / span 8; }
.cs-intro__head .pp-eyebrow { margin-bottom: 24px; }
.cs-intro__head .pp-display { max-width: 18ch; }
.cs-intro__side { grid-column: 9 / span 4; }
.cs-intro__side .pp-fine { margin: 16px 0 0; padding-top: 16px; border-top: 1px solid var(--line); }

.cs-index { padding-bottom: var(--sec); }
.cs-index__head { padding-bottom: 12px; font: 500 12px/16px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.cs-index__head .h-no { grid-column: 1 / span 1; }
.cs-index__head .h-cs { grid-column: 2 / span 5; }
.cs-index__head .h-stack { grid-column: 7 / span 3; }
.cs-index__head .h-state { grid-column: 10 / span 3; text-align: right; }

/* Ruled rows on a heavy top rule (like "What I've built" on the home page). */
.cs-rows { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--ink); }
.cs-row { position: relative; padding: 32px 0; border-bottom: 1px solid var(--edge); row-gap: 16px; align-items: start; }

.cs-no { grid-column: 1 / span 1; margin: 0; font: 500 32px/32px var(--serif); letter-spacing: -.02em; color: var(--accent); font-variant-numeric: tabular-nums; }
.cs-copy { grid-column: 2 / span 5; }
.cs-stack { grid-column: 7 / span 3; padding-top: 4px; }
.cs-state { grid-column: 10 / span 3; display: flex; flex-direction: column; align-items: flex-end; gap: 16px; padding-top: 6px; text-align: right; }

.cs-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 12px; margin: 0; font: 500 28px/34px var(--serif); letter-spacing: -.01em; }
.cs-title a { text-decoration: none; }
.cs-title a:hover { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 6px; }
.cs-tag {
  padding: 1px 8px; border: 1px dashed var(--edge); border-radius: var(--r-sm);
  font: 500 11px/16px var(--mono); letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2);
  position: relative; top: -4px;
}
.cs-what { margin: 8px 0 0; color: var(--ink-2); max-width: 48ch; }

.cs-run { font-size: 15px; }
.cs-run-wrap { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.cs-alt { margin: 0; font: 400 12px/16px var(--mono); color: var(--ink-3); }

@media (hover: hover) {
  .cs-row:hover .cs-run { color: var(--accent-ink); }
  .cs-row:hover .cs-run svg { transform: translateX(2px); }
}

.cs-end { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px 24px; margin: 24px 0 0; font: 400 12px/16px var(--mono); color: var(--ink-3); }
.cs-end a { color: var(--ink-2); }

/* ───────────────────────── Template: header ───────────────────────── */

.cs-hero { padding-top: 48px; padding-bottom: 64px; row-gap: 32px; align-items: end; }
.cs-hero__head { grid-column: 1 / span 7; }
.cs-hero__head .cs-crumb { margin-bottom: 48px; }
.cs-hero__head .pp-eyebrow { margin-bottom: 24px; }
.cs-hero__head .pp-lede { margin-top: 24px; max-width: 52ch; }

/* Slots in large type keep the type's size so the layout reads at its real scale. */
.cs-h1 { max-width: 20ch; }
.cs-h1 .pp-todo, .cs-hero .pp-lede .pp-todo {
  font: inherit; letter-spacing: inherit; color: var(--ink-2); padding: 0 .2em; border-radius: 10px;
}
.cs-h1 .pp-todo { font-size: .72em; line-height: 1.3; }

.cs-label {
  display: inline-flex; align-items: center; gap: 8px; margin: 24px 0 0; padding: 4px 12px;
  border: 1px solid var(--edge); border-radius: 999px; font: 400 12px/18px var(--mono); color: var(--ink-2);
}
.cs-label svg { width: 14px; height: 14px; color: var(--ink-3); }

/* The facts: a soft panel of spec rows. */
.cs-meta { grid-column: 9 / span 4; margin: 0; padding: 8px 24px; border-radius: var(--r-lg); background: var(--panel); }
.cs-meta > div { display: grid; grid-template-columns: 80px minmax(0, 1fr); gap: 12px; padding: 16px 0; border-top: 1px solid var(--edge); }
.cs-meta > div:first-child { border-top: 0; }
.cs-meta dt { font: 500 11px/20px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.cs-meta dd { margin: 0; font-size: 14px; line-height: 20px; color: var(--ink-2); min-width: 0; }

/* ───────────────────────── Template: body + table of contents ───────────────────────── */

.cs-body { padding-top: 32px; padding-bottom: var(--sec); align-items: start; }
.cs-toc { grid-column: 1 / span 3; position: sticky; top: calc(var(--nav-h) + 32px); }
.cs-main { grid-column: 4 / span 9; min-width: 0; }

.cs-toc__label { margin: 0 0 12px; font: 500 11px/16px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.cs-toc ol { margin: 0; padding: 0; list-style: none; border-left: 1px solid var(--edge); }
.cs-toc li a {
  display: grid; grid-template-columns: 28px 1fr; gap: 4px; margin-left: -1px; padding: 6px 0 6px 16px;
  border-left: 2px solid transparent; text-decoration: none; font-size: 14px; line-height: 20px; color: var(--ink-2);
  transition: color 120ms, border-color 200ms;
}
.cs-toc li a .n { font: 400 12px/20px var(--mono); color: var(--ink-3); }
.cs-toc li a:hover { color: var(--ink); }
.cs-toc li a[aria-current="location"] { color: var(--ink); border-left-color: var(--accent); }
.cs-toc li a[aria-current="location"] .n { color: var(--accent-ink); }

.cs-sec { padding-bottom: 96px; }
.cs-sec:last-child { padding-bottom: 0; }
.cs-sec .cs-shead { margin-bottom: 32px; }
.cs-prose p { margin: 0 0 16px; max-width: 64ch; }
.cs-prose p:last-child { margin-bottom: 0; }
.cs-sub { margin: 48px 0 16px; font: 500 12px/16px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }

/* ───────────────────────── Template: the step trace ───────────────────────── */

.cs-trace { margin-top: 32px; padding: 8px; border-radius: var(--r-lg); background: var(--panel); }
.cs-trace__bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px 12px 12px;
  font: 400 12px/18px var(--mono); color: var(--ink-2);
}
.cs-trace__bar .t { font-weight: 500; color: var(--ink); }
.cs-trace__state { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; color: var(--ink-3); }
.cs-trace__state .pp-live-dot { display: none; }
.cs-trace.is-playing .cs-trace__state { color: var(--ink); }
.cs-trace.is-playing .cs-trace__state .pp-live-dot { display: block; }
.cs-trace.is-done .cs-trace__state { color: var(--ok); }

.cs-steps { margin: 0; padding: 0; list-style: none; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--r-md) var(--r-md); background: var(--surface); overflow: hidden; }
.cs-steps__head, .cs-trace .step {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) minmax(0, 168px) 88px 20px; column-gap: 16px; align-items: start;
  padding: 0 16px;
}
.cs-steps__head {
  padding-top: 12px; padding-bottom: 12px; border: 1px solid var(--line); border-bottom: 0; border-radius: var(--r-md) var(--r-md) 0 0;
  background: var(--surface); font: 500 11px/16px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3);
}
.cs-steps__head .r { text-align: right; }
.cs-trace .step { padding-top: 16px; padding-bottom: 16px; border-top: 1px solid var(--line); transition: opacity 200ms var(--ease-out); }
.step__no { font: 500 12px/22px var(--mono); color: var(--ink-3); }
.step__name { margin: 0; font-weight: 500; font-size: 15px; line-height: 22px; }
.step__out { margin: 4px 0 0; font: 400 12px/18px var(--mono); color: var(--ink-2); }
.step__out .k { color: var(--ink-3); }
.step__tool { padding-top: 1px; }
.step__tool .pp-chip { display: inline-block; max-width: 100%; }
.step__ms { font: 400 12px/22px var(--mono); color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; }
.step__st { position: relative; width: 20px; height: 22px; }
.step__st > * { position: absolute; left: 2px; top: 3px; }

/* Status: idle ring → running spinner (signal) → done check (ok). Without JS every row shows done. */
.st-idle { width: 16px; height: 16px; border: 1.5px dashed var(--edge); border-radius: 50%; opacity: 0; }
.st-spin { width: 16px; height: 16px; border: 1.5px solid var(--signal-12); border-top-color: var(--signal); border-radius: 50%; opacity: 0; }
.st-done { display: grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--ok); color: var(--bg); }
.st-done svg { width: 11px; height: 11px; stroke-width: 2.5; }

.js .cs-trace .step { opacity: .42; }
.js .cs-trace .step .st-idle { opacity: 1; }
.js .cs-trace .step .st-done { opacity: 0; transform: scale(.6); transition: opacity 160ms, transform 240ms var(--ease-back); }
.js .cs-trace .step.is-run { opacity: 1; }
.js .cs-trace .step.is-run .st-idle { opacity: 0; }
.js .cs-trace .step.is-run .st-spin { opacity: 1; animation: cs-spin 800ms linear infinite; }
.js .cs-trace .step.is-run .step__name { color: var(--ink); }
.js .cs-trace .step.is-done { opacity: 1; }
.js .cs-trace .step.is-done .st-idle, .js .cs-trace .step.is-done .st-spin { opacity: 0; animation: none; }
.js .cs-trace .step.is-done .st-done { opacity: 1; transform: none; }
@keyframes cs-spin { to { transform: rotate(360deg); } }

/* Ghost rows: the shape of the next steps, replaced when a write-up is filled in. */
.step--ghost .bar { display: block; height: 10px; margin-top: 6px; border-radius: 3px; background: var(--panel); }
.step--ghost .bar.s { width: 56%; height: 8px; margin-top: 8px; }

.cs-trace__foot {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; padding: 12px 12px 8px;
  font: 400 12px/18px var(--mono); color: var(--ink-3);
}
.cs-trace__foot b { font-weight: 500; color: var(--ink-2); }

/* Still or diagram: a white frame on a soft panel. */
.cs-still { margin: 24px 0 0; padding: 8px; border-radius: var(--r-lg); background: var(--panel); }
.cs-still__frame {
  display: flex; flex-direction: column; justify-content: flex-end; gap: 12px; aspect-ratio: 16 / 9; padding: 24px;
  border: 1px dashed var(--edge); border-radius: var(--r-md); background: var(--surface);
}
.cs-still__frame svg { width: 20px; height: 20px; color: var(--ink-3); }
.cs-still figcaption { margin: 12px 12px 8px; font: 400 12px/18px var(--mono); color: var(--ink-3); }

/* ───────────────────────── Template: tools ───────────────────────── */

.cs-tools { margin: 0; border-bottom: 1px solid var(--edge); }
.cs-tools__row { display: grid; grid-template-columns: minmax(0, 160px) minmax(0, 1fr) minmax(0, 1fr); gap: 24px; padding: 16px 0; border-top: 1px solid var(--edge); }
.cs-tools__row:first-child { border-top-color: var(--ink); }
.cs-tools__row.h { padding: 0 0 12px; border-top: 0; font: 500 11px/16px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.cs-tools dt { font-weight: 600; }
.cs-tools dd { margin: 0; color: var(--ink-2); }
.cs-tools dd.m { font: 400 13px/24px var(--mono); }

/* ───────────────────────── Template: real vs sample ───────────────────────── */

.cs-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cs-col { padding: 24px; border-radius: var(--r-lg); background: var(--panel); }
.cs-col--sample { background: transparent; border: 1px dashed var(--edge); }
.cs-col__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; padding-bottom: 12px; border-bottom: 1px solid var(--edge); }
.cs-col__head .pp-h3 { font-size: 24px; line-height: 30px; }
.cs-list { margin: 0; padding: 0; list-style: none; }
.cs-list li { position: relative; padding: 6px 0 6px 20px; }
.cs-list li::before { content: ""; position: absolute; left: 2px; top: 16px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.cs-col--sample .cs-list li::before { background: transparent; border: 1px solid var(--ink-3); }

.cs-strip { margin: 24px 0 0; border-bottom: 1px solid var(--edge); }
.cs-strip > div { display: grid; grid-template-columns: minmax(0, 200px) 1fr; gap: 24px; padding: 16px 0; border-top: 1px solid var(--edge); }
.cs-strip dt { font: 500 12px/24px var(--mono); color: var(--ink-2); }
.cs-strip dd { margin: 0; }
.cs-strip dd.row { display: flex; flex-wrap: wrap; gap: 8px 16px; }

/* ───────────────────────── Template: limits + guards ───────────────────────── */

.cs-limits-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 320px); gap: 32px; align-items: start; }
.cs-limits { margin: 0; padding: 0; list-style: none; counter-reset: lim; border-top: 1px solid var(--ink); }
.cs-limits li { counter-increment: lim; display: grid; grid-template-columns: 48px 1fr; gap: 8px; padding: 16px 0; border-bottom: 1px solid var(--edge); }
.cs-limits li::before { content: "L" counter(lim, decimal-leading-zero); font: 500 12px/24px var(--mono); color: var(--accent-ink); }
.cs-guards { padding: 24px; border-radius: var(--r-lg); background: var(--panel); }
.cs-guards__head { display: flex; align-items: center; gap: 12px; margin: 0 0 12px; font: 500 22px/28px var(--serif); }
.cs-guards__head svg { width: 20px; height: 20px; color: var(--ink-2); }

/* ───────────────────────── Template: handover ───────────────────────── */

.cs-hand { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--ink); }
.cs-hand li { display: grid; grid-template-columns: 20px minmax(0, 180px) minmax(0, 1fr) minmax(0, 220px); gap: 16px; align-items: start; padding: 16px 0; border-bottom: 1px solid var(--edge); }
.cs-hand svg { width: 20px; height: 20px; margin-top: 2px; color: var(--ink-2); }
.cs-hand .nm { font-weight: 600; }
.cs-hand .wh { color: var(--ink-2); }
.cs-hand .at { font: 400 12px/24px var(--mono); color: var(--ink-3); text-align: right; }

/* ───────────────────────── Template: run the demo ───────────────────────── */

.cs-cta {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px 48px; align-items: end;
  padding: 48px; border-radius: var(--r-lg); background: var(--panel);
}
.cs-cta .pp-eyebrow { margin-bottom: 12px; }
.cs-cta .pp-lede { margin-top: 12px; max-width: 46ch; }
.cs-cta__go { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; }
.cs-back { margin: 24px 0 0; padding: 0 8px; font-size: 14px; }
.cs-back a { color: var(--ink-2); }

/* ───────────────────────── Reduced motion ───────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .js .cs-trace .step.is-run .st-spin { animation: none; }
  .cs-row:hover .cs-run svg { transform: none; }
}

/* ───────────────────────── Tablet ───────────────────────── */

@media (max-width: 1100px) {
  .cs-intro__head { grid-column: 1 / -1; }
  .cs-intro__side { grid-column: 1 / span 8; }

  .cs-index__head .h-stack, .cs-index__head .h-state { display: none; }
  .cs-index__head .h-cs { grid-column: 2 / -1; }
  .cs-copy { grid-column: 2 / span 7; }
  .cs-stack { grid-column: 2 / span 7; }
  .cs-state { grid-column: 9 / span 4; grid-row: 1; }

  .cs-hero__head, .cs-meta { grid-column: 1 / -1; }
  .cs-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; padding: 8px 24px; }
  .cs-meta > div:nth-child(2) { border-top: 0; }
  .cs-toc { grid-column: 1 / -1; position: static; margin-bottom: 48px; }
  .cs-main { grid-column: 1 / -1; }
  .cs-toc ol { columns: 2; column-gap: 24px; }
  .cs-toc li { break-inside: avoid; }
}
@media (max-width: 860px) {
  .cs-intro__side { grid-column: 1 / -1; max-width: 60ch; }
  .cs-limits-grid { grid-template-columns: minmax(0, 1fr); }
  .cs-hand li { grid-template-columns: 20px minmax(0, 160px) minmax(0, 1fr); }
  .cs-hand .at { grid-column: 3; text-align: left; }
}

/* ───────────────────────── Phone ───────────────────────── */

@media (max-width: 720px) {
  .pp-grid.cs-intro, .pp-grid.cs-row, .pp-grid.cs-hero, .pp-grid.cs-body { column-gap: 0; }
  .cs-intro { padding-top: 32px; padding-bottom: 40px; row-gap: 24px; }
  .cs-index__head { display: none; }
  .cs-row { padding: 24px 0; row-gap: 16px; }
  .cs-no { grid-column: 1 / -1; font-size: 28px; line-height: 28px; }
  .cs-copy, .cs-stack, .cs-state { grid-column: 1 / -1; }
  .cs-state { grid-row: auto; flex-direction: row; flex-wrap: wrap; justify-content: space-between; align-items: center; text-align: left; }
  .cs-run-wrap { align-items: flex-start; }
  .cs-title { font-size: 24px; line-height: 30px; }

  .cs-hero { padding-top: 32px; padding-bottom: 40px; }
  .cs-hero__head .cs-crumb { margin-bottom: 32px; }
  .cs-meta { grid-template-columns: minmax(0, 1fr); padding: 8px 16px; }
  .cs-meta > div:nth-child(2) { border-top: 1px solid var(--edge); }
  .cs-toc ol { columns: 1; }
  .cs-sec { padding-bottom: 64px; }

  .cs-steps__head { display: none; }
  .cs-steps { border-top: 1px solid var(--line); border-radius: var(--r-md); }
  .cs-trace .step { grid-template-columns: 28px minmax(0, 1fr) 20px; row-gap: 8px; padding-left: 12px; padding-right: 12px; }
  .cs-trace .step:first-child { border-top: 0; }
  .step__no { grid-row: 1 / span 3; }
  .step__body { grid-column: 2; }
  .step__st { grid-column: 3; grid-row: 1; }
  .step__tool { grid-column: 2; grid-row: 2; }
  .step__ms { grid-column: 2; grid-row: 3; text-align: left; }
  .cs-still__frame { aspect-ratio: 4 / 3; padding: 16px; }

  .cs-tools__row { grid-template-columns: 1fr; gap: 4px; }
  .cs-tools__row.h { display: none; }
  .cs-split { grid-template-columns: 1fr; }
  .cs-col { padding: 24px 16px; }
  .cs-strip > div { grid-template-columns: 1fr; gap: 4px; }
  .cs-hand li { grid-template-columns: 20px minmax(0, 1fr); row-gap: 4px; }
  .cs-hand .wh, .cs-hand .at { grid-column: 2; text-align: left; }
  .cs-cta { grid-template-columns: 1fr; padding: 24px 16px; }
}
