/* ══════════════════════════════════════════════════════════════════
   CASE-STUDY COMPONENTS  (csx-*)
   Visual building blocks that turn prose into things you can scan:
   roadmap, message thread, meters, tiles, findings with mock crops,
   merge diagram, tap counter, before/after.

   Usage: link this file in the head and load components.js (defer).
   Theming: each page sets --csx-accent (falls back to --ed-accent).
   Type follows the page: display = --font-display, mono = DM Mono.
   Mock content (.csx-snip, .csx-thread) uses the system UI stack,
   since it represents phone UI.
   Docs + examples: docs/case-study-components.md
   ══════════════════════════════════════════════════════════════════ */

:root {
    --csx-accent: var(--ed-accent, #A8864A);
    --csx-ink: var(--ed-ink, #2D3130);
    --csx-ink-2: var(--ed-ink-2, #5C6360);
    --csx-ink-3: var(--ed-ink-3, #8A908D);
    --csx-rule: var(--ed-rule, #D3D8DF);
    --csx-surface: #FFFFFF;
    --csx-tint: color-mix(in srgb, var(--csx-accent) 9%, transparent);
    --csx-display: var(--font-display, 'Montserrat', sans-serif);
    --csx-mono: 'DM Mono', ui-monospace, monospace;
    --csx-ui: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
    --csx-ease: cubic-bezier(0.16, 1, 0.3, 1);
    --csx-shadow: 0 1px 2px rgba(20, 24, 31, .05), 0 8px 24px -12px rgba(20, 24, 31, .18);
}

/* Visual blocks use the full content column; page rules cap ul/ol at text measure */
:is(.csx-tiles, .csx-fixes, .csx-roadmap__track, .csx-heard, .csx-findings, .csx-merge, .csx-ba, .csx-meters) { max-width: none !important; }

/* Shared small label */
.csx-label {
    display: block; margin: 0 0 14px;
    font-family: var(--csx-mono); font-size: 11px; font-weight: 400; letter-spacing: .1em;
    text-transform: uppercase; color: var(--csx-ink-3);
}

/* Reveal: only armed once JS runs, so no-JS readers see everything */
.csx-js [data-csx]:not(.is-in) { opacity: 0; transform: translateY(14px); }
.csx-js [data-csx] { transition: opacity .7s var(--csx-ease), transform .7s var(--csx-ease); }

/* ── 1. ROADMAP — the project timeline as a map ──────────────────── */
/* Phases run left→right on a rail; each phase's milestones stack beneath. */
.csx-roadmap { margin: 8px 0 72px; }
.csx-roadmap__track {
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
    gap: 0; list-style: none; margin: 0; padding: 0;
}
.csx-roadmap__group { position: relative; min-width: 0; padding: 30px 14px 0 0; }
/* rail */
.csx-roadmap__group::before {
    content: ''; position: absolute; top: 6px; left: 0; right: 0; height: 2px; background: var(--csx-rule); transform-origin: left;
}
.csx-roadmap__group:last-child::before { right: auto; width: 14px; }
/* phase dot */
.csx-roadmap__group::after {
    content: ''; position: absolute; top: 0; left: 0; width: 14px; height: 14px; box-sizing: border-box; border-radius: 50%;
    background: var(--bg-primary, #EFF1F4); border: 2px solid var(--csx-accent); box-shadow: 0 0 0 5px var(--bg-primary, #EFF1F4);
}
.csx-roadmap__group-name {
    display: block; margin-bottom: 14px;
    font-family: var(--csx-mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--csx-accent);
}
.csx-roadmap__stops { display: flex; flex-direction: column; gap: 8px; list-style: none; margin: 0; padding: 0; }
.csx-roadmap__stop > :is(a, div) {
    display: block; padding: 10px 12px 11px; border-radius: 10px; background: var(--csx-surface);
    box-shadow: 0 1px 2px rgba(20, 24, 31, .05); color: inherit; text-decoration: none;
    transition: box-shadow .2s ease, transform .2s ease;
}
.csx-roadmap__stop a:hover, .csx-roadmap__stop a:focus-visible { transform: translateY(-1px); box-shadow: var(--csx-shadow); }
.csx-roadmap__stop.is-key > :is(a, div) { box-shadow: inset 3px 0 0 var(--csx-accent), 0 1px 2px rgba(20, 24, 31, .05); }
.csx-roadmap__when { display: block; margin-bottom: 3px; font-family: var(--csx-mono); font-size: 10.5px; color: var(--csx-ink-3); }
.csx-roadmap__what { display: block; font-family: var(--csx-display); font-size: 13.5px; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; color: var(--csx-ink); }
/* draw-in: rail grows, then milestones land */
.csx-js .csx-roadmap[data-csx]:not(.is-in) { opacity: 1; transform: none; }
.csx-js .csx-roadmap .csx-roadmap__group::before { transform: scaleX(0); transition: transform .7s var(--csx-ease); transition-delay: calc(var(--g, 0) * 140ms); }
.csx-js .csx-roadmap .csx-roadmap__stop { opacity: 0; transform: translateY(8px); transition: opacity .5s ease, transform .6s var(--csx-ease); transition-delay: calc(var(--i, 0) * 80ms + 200ms); }
.csx-js .csx-roadmap.is-in .csx-roadmap__group::before { transform: none; }
.csx-js .csx-roadmap.is-in .csx-roadmap__stop { opacity: 1; transform: none; }

@media (max-width: 900px) {
    .csx-roadmap__track { grid-auto-flow: row; grid-auto-columns: auto; }
    .csx-roadmap__group { padding: 0 0 22px 30px; }
    .csx-roadmap__group::before { top: 7px; bottom: -7px; left: 6px; right: auto; width: 2px; height: auto; transform-origin: top; }
    .csx-roadmap__group:last-child::before { display: none; }
    .csx-roadmap__group-name { margin-bottom: 10px; }
    .csx-js .csx-roadmap .csx-roadmap__group::before { transform: scaleY(0); }
}

/* ── 2. MESSAGE THREAD — a quote as an iMessage conversation ──────── */
.csx-thread {
    margin: 0; max-width: 360px; padding: 18px 16px 16px; border-radius: 28px;
    background: var(--csx-surface); box-shadow: var(--csx-shadow); font-family: var(--csx-ui);
}
.csx-thread__head { display: flex; flex-direction: column; align-items: center; gap: 4px; padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid #EDEEF0; }
.csx-thread__avatar {
    width: 40px; height: 40px; border-radius: 50%; overflow: hidden;
    background: linear-gradient(180deg, #A5ABB6, #868C98);
}
.csx-thread__avatar svg { display: block; width: 100%; height: 100%; }
.csx-thread__name { font-size: 12px; font-weight: 500; color: #1C1C1E; }
.csx-thread__stamp { align-self: center; margin: 0 0 8px; font-size: 10.5px; color: #8E8E93; }
.csx-thread blockquote { margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }
.csx-bubble {
    position: relative; max-width: 86%; margin: 0; padding: 8px 13px 9px; border-radius: 18px;
    background: #E9E9EB; color: #1C1C1E; font-size: 15px; line-height: 1.32; letter-spacing: -.01em;
}
.csx-bubble { isolation: isolate; }
.csx-bubble:last-child::before,   /* tail on the last bubble of a run */
.csx-bubble:last-child::after { content: ''; position: absolute; bottom: 0; height: 20px; z-index: -1; }
.csx-bubble:last-child::before { left: -7px; width: 20px; background: #E9E9EB; border-bottom-right-radius: 16px 14px; }
.csx-bubble:last-child::after { left: -10px; width: 10px; background: var(--csx-surface); border-bottom-right-radius: 10px; }
.csx-thread__src { margin-top: 14px; font-family: var(--csx-mono); font-size: 11px; letter-spacing: .02em; color: var(--csx-ink-3); text-align: center; }
/* typing → bubbles, in order */
.csx-typing { display: none; gap: 4px; overflow: hidden; padding: 11px 13px; border-radius: 18px; background: #E9E9EB; width: max-content; }
.csx-typing i { width: 7px; height: 7px; border-radius: 50%; background: #9A9AA0; animation: csx-blink 1s infinite; }
.csx-typing i:nth-child(2) { animation-delay: .15s; } .csx-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes csx-blink { 0%, 80%, 100% { opacity: .35; } 40% { opacity: 1; } }
.csx-js .csx-thread[data-csx]:not(.is-in) { opacity: 1; transform: none; }
.csx-js .csx-thread .csx-bubble { opacity: 0; transform: translateY(8px) scale(.96); transform-origin: left bottom; }
.csx-js .csx-thread.is-in .csx-bubble { animation: csx-pop .45s var(--csx-ease) forwards; animation-delay: calc(1.1s + var(--i, 0) * .8s); }
.csx-js .csx-thread.is-in .csx-typing { display: flex; animation: csx-type 1.1s ease forwards; }
@keyframes csx-pop { to { opacity: 1; transform: none; } }
@keyframes csx-type {
    0% { opacity: 0; max-height: 40px; }
    15%, 85% { opacity: 1; max-height: 40px; }
    100% { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; margin-bottom: -3px; }
}

/* Quote beside the findings it backs up */
.csx-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); gap: 48px; align-items: center; margin: 24px 0 8px; }
.csx-heard { list-style: none; margin: 0; padding: 0; counter-reset: csx-heard; }
.csx-heard li {
    display: grid; grid-template-columns: 32px 1fr; padding: 14px 0; border-top: 1px solid var(--csx-rule);
    font-family: var(--csx-display); font-size: 17px; font-weight: 500; line-height: 1.4; letter-spacing: -.01em; color: var(--csx-ink);
}
.csx-heard li:last-child { border-bottom: 1px solid var(--csx-rule); }
.csx-heard li::before { counter-increment: csx-heard; content: counter(csx-heard, decimal-leading-zero); padding-top: 4px; font-family: var(--csx-mono); font-size: 11px; font-weight: 400; color: var(--csx-accent); }
@media (max-width: 760px) { .csx-pair { grid-template-columns: 1fr; gap: 28px; } .csx-thread { max-width: none; } }

/* ── 3. METERS — a percentage you can see ─────────────────────────── */
.csx-meters { display: grid; gap: 22px; margin: 0; }
.csx-meter { display: grid; grid-template-columns: var(--csx-num-w, 92px) minmax(0, 1fr); column-gap: 18px; row-gap: 8px; align-items: center; }
.csx-meter__num { grid-row: span 2; font-family: var(--csx-display); font-size: 36px; font-weight: 600; letter-spacing: -.04em; line-height: 1; color: var(--csx-accent); }
.csx-meter__bar { position: relative; height: 8px; border-radius: 99px; background: var(--csx-rule); overflow: hidden; }
.csx-meter__bar span { position: absolute; inset: 0 auto 0 0; width: calc(var(--v) * 1%); border-radius: inherit; background: var(--csx-accent); }
.csx-meter__label { font-size: 14px; line-height: 1.5; color: var(--csx-ink-2); }
.csx-js .csx-meters[data-csx]:not(.is-in) { opacity: 1; transform: none; }
.csx-js .csx-meters .csx-meter__bar span { transform: scaleX(0); transform-origin: left; transition: transform 1.1s var(--csx-ease); }
.csx-js .csx-meters.is-in .csx-meter__bar span { transform: none; }
.csx-js .csx-meters.is-in .csx-meter + .csx-meter .csx-meter__bar span { transition-delay: .15s; }

/* ── 4. TILES — a list of areas or principles as a grid ───────────── */
.csx-tiles { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 12px; max-width: none; margin: 28px 0 8px; padding: 0; list-style: none; }
.csx-tile { padding: 20px 20px 22px; border-radius: 14px; background: var(--csx-surface); box-shadow: var(--csx-shadow); }
.csx-tile__icon {
    display: grid; place-items: center; width: 36px; height: 36px; margin-bottom: 16px; border-radius: 10px;
    background: var(--csx-tint); color: var(--csx-accent);
}
.csx-tile__icon svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.csx-tile__num { display: block; margin-bottom: 18px; font-family: var(--csx-display); font-size: 34px; font-weight: 600; letter-spacing: -.04em; line-height: 1; color: var(--csx-accent); }
.csx-tile__title { margin: 0 0 6px; font-family: var(--csx-display); font-size: 16px; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; color: var(--csx-ink); }
.csx-tile__desc { margin: 0; font-size: 14px; line-height: 1.55; color: var(--csx-ink-2); }
.csx-tiles--prose .csx-tile__desc { font-size: 14px; line-height: 1.65; }
.csx-tiles--prose strong { color: var(--csx-ink); font-weight: 600; }
@media (max-width: 900px) { .csx-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .csx-tiles { grid-template-columns: 1fr; } }

/* ── 5. FINDINGS — each finding sits on the UI it's about ─────────── */
.csx-findings { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 16px; margin: 28px 0 8px; }
.csx-finding { display: flex; flex-direction: column; border-radius: 16px; background: var(--csx-surface); box-shadow: var(--csx-shadow); overflow: hidden; }
.csx-finding__body { padding: 18px 20px 22px; }
.csx-finding__title { margin: 0 0 8px; font-family: var(--csx-display); font-size: 16.5px; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; color: var(--csx-ink); }
.csx-finding__desc { margin: 0; font-size: 14px; line-height: 1.6; color: var(--csx-ink-2); }
.csx-finding .csx-bubble { margin-top: 14px; font-family: var(--csx-ui); font-size: 14px; }
.csx-finding .csx-bubble-note { margin: 6px 0 0 4px; font-family: var(--csx-mono); font-size: 11px; color: var(--csx-ink-3); }
@media (max-width: 900px) { .csx-findings { grid-template-columns: 1fr; } }

/* Mock crop: a slice of a real screen, sitting on a soft tint */
.csx-snip {
    position: relative; display: flex; flex-direction: column; justify-content: center; gap: 0;
    min-height: 150px; padding: 22px 18px; background: var(--csx-tint); font-family: var(--csx-ui);
}
.csx-snip__screen { width: 100%; max-width: 300px; margin: 0 auto; padding: 12px 0 4px; border-radius: 14px; background: #fff; box-shadow: 0 6px 18px -10px rgba(20, 24, 31, .35); zoom: 1.15; }
.csx-snip__screen [class*="-name"] { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.csx-snip__screen [class*="-status"] { white-space: nowrap; flex: none; }
.csx-snip__screen [class*="-info"] { min-width: 0; }
.csx-snip__mark + *, * + .csx-snip__mark { margin-top: 8px !important; }
.csx-snip__screen > * { margin-left: 12px !important; margin-right: 12px !important; }
.csx-snip__mark { outline: 2px solid var(--csx-accent); outline-offset: 3px; border-radius: 8px; }

/* ── 6. MERGE — A + B (+ C) = direction ───────────────────────────── */
.csx-merge { display: flex; align-items: stretch; gap: 10px; margin: 28px 0 8px; }
.csx-merge__in, .csx-merge__out { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; padding: 16px 16px 18px; border-radius: 14px; }
.csx-merge__in { background: var(--csx-surface); box-shadow: var(--csx-shadow); }
.csx-merge__out { flex-grow: 1.15; background: var(--csx-ink); color: #fff; }
.csx-merge__tag { margin-bottom: 14px; font-family: var(--csx-mono); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--csx-accent); }
.csx-merge__out .csx-merge__tag { color: color-mix(in srgb, var(--csx-accent) 60%, #fff); }
.csx-merge__glyph { height: 44px; margin-bottom: 14px; color: var(--csx-ink-3); }
.csx-merge__glyph svg { height: 100%; width: auto; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.csx-merge__name { font-family: var(--csx-display); font-size: 15.5px; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; }
.csx-merge__why { margin-top: 4px; font-size: 13px; line-height: 1.45; color: var(--csx-ink-2); }
.csx-merge__out .csx-merge__name { font-size: 17px; }
.csx-merge__op { align-self: center; flex: none; font-family: var(--csx-display); font-size: 22px; font-weight: 500; color: var(--csx-ink-3); }
@media (max-width: 760px) {
    .csx-merge { flex-direction: column; gap: 6px; }
    .csx-merge__in, .csx-merge__out { display: grid; grid-template-columns: 56px 1fr; column-gap: 14px; align-items: center; padding: 14px 16px; }
    .csx-merge__in > *, .csx-merge__out > * { grid-column: 2; }
    .csx-merge__glyph { grid-column: 1; grid-row: 1 / span 3; height: 34px; margin: 0; }
    .csx-merge__tag { margin-bottom: 4px; }
    .csx-merge__op { align-self: flex-start; padding-left: 34px; line-height: 1; }
}

/* ── 7. TAPS — count of steps as dots ─────────────────────────────── */
.csx-taps { display: flex; gap: 4px; margin-top: 8px; }
.csx-taps i { width: 9px; height: 9px; border-radius: 50%; background: currentColor; opacity: .85; }

/* ── 8. BEFORE / AFTER — two states side by side ──────────────────── */
.csx-ba { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 28px 0 8px; }
.csx-ba__side { border-radius: 16px; background: var(--csx-surface); box-shadow: var(--csx-shadow); overflow: hidden; }
.csx-ba__side > .csx-label { margin: 16px 20px 0; }
.csx-ba__side--after > .csx-label { color: var(--csx-accent); }
.csx-ba__body { padding: 8px 20px 20px; font-size: 14px; line-height: 1.6; color: var(--csx-ink-2); }
.csx-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 0; padding: 0; list-style: none; }
.csx-chips li { padding: 5px 10px; border-radius: 99px; background: var(--csx-tint); color: var(--csx-ink); font-size: 13px; line-height: 1.3; }
.csx-ba__side--after .csx-chips li { background: var(--csx-accent); color: #fff; }
@media (max-width: 760px) { .csx-ba { grid-template-columns: 1fr; } }


/* ── 9. FIXES — each pain point paired with the rule that answers it ─ */
.csx-fixes { list-style: none; margin: 24px 0 8px; padding: 0; display: grid; gap: 8px; }
.csx-fixes__head, .csx-fix { display: grid; grid-template-columns: minmax(0, .9fr) 28px minmax(0, 1.4fr); align-items: center; column-gap: 12px; }
.csx-fixes__head { padding: 0 18px 2px; margin-top: 28px; }
.csx-fixes__head .csx-label { margin: 0; }
.csx-fixes__head .csx-label:last-child { grid-column: 3; color: var(--csx-accent); }
.csx-fix { padding: 14px 18px; border-radius: 14px; background: var(--csx-surface); box-shadow: var(--csx-shadow); }
.csx-fix__from { font-size: 13.5px; line-height: 1.45; color: var(--csx-ink-3); }
.csx-fix__arrow { justify-self: center; color: var(--csx-accent); font-size: 16px; }
.csx-fix__to { font-size: 14px; line-height: 1.55; color: var(--csx-ink-2); }
.csx-fix__to strong { display: block; margin-bottom: 2px; font-family: var(--csx-display); font-size: 15px; font-weight: 600; letter-spacing: -.01em; color: var(--csx-ink); }
.csx-js .csx-fixes .csx-fix { opacity: 0; transform: translateY(10px); transition: opacity .5s ease, transform .6s var(--csx-ease); transition-delay: calc(var(--i, 0) * 90ms); }
.csx-js .csx-fixes[data-csx]:not(.is-in) { opacity: 1; transform: none; }
.csx-js .csx-fixes.is-in .csx-fix { opacity: 1; transform: none; }
@media (max-width: 760px) {
    .csx-fixes__head { display: none; }
    .csx-fix { grid-template-columns: 1fr; row-gap: 6px; }
    .csx-fix__arrow { justify-self: start; transform: rotate(90deg); }
}

/* Tile with a screen crop on top (tiles that map to real screens) */
.csx-tile--shot { padding: 0; overflow: hidden; }
.csx-tile__shot { display: block; height: 150px; overflow: hidden; background: var(--csx-tint); }
.csx-tile__shot img { display: block; width: 100%; height: auto; }
.csx-tile--shot .csx-tile__title, .csx-tile--shot .csx-tile__desc { padding: 0 16px; }
.csx-tile--shot .csx-tile__title { margin-top: 14px; }
.csx-tile--shot .csx-tile__desc { padding-bottom: 18px; }

/* ── Reduced motion: final frame, no choreography ─────────────────── */
@media (prefers-reduced-motion: reduce) {
    .csx-js [data-csx], .csx-js [data-csx] * { transition: none !important; animation: none !important; }
    .csx-js [data-csx]:not(.is-in) { opacity: 1; transform: none; }
    .csx-js .csx-thread .csx-bubble, .csx-js .csx-roadmap .csx-roadmap__stop, .csx-js .csx-fixes .csx-fix { opacity: 1; transform: none; }
    .csx-js .csx-roadmap .csx-roadmap__group::before, .csx-js .csx-meters .csx-meter__bar span { transform: none; }
    .csx-js .csx-thread .csx-typing { display: none !important; }
}

/* Roadmap links land below the fixed nav */
:target { scroll-margin-top: 96px; }
