/* Case studies: every product, AI system and role reads as Overview / How it
   works / Key decisions. The region hue (data-tone on .case, from base.css)
   carries the accents; runtime-map stages keep their own four kind colours. */

.modal[data-modal-variant='case'] {
    max-width: min(1040px, 94vw);
    max-height: min(90vh, 1000px);
    /* One height for all three tabs, so switching never makes the window jump. */
    height: min(90vh, 860px);
}

/* The tab rail sticks to the scrollport, so the body gives up its top padding. */
.modal-body[data-modal-variant='case'] {
    padding: 0 28px 28px;
    gap: 0;
}

.case {
    --case-panel: var(--surface-solid);
    --case-sticky: rgba(251, 249, 246, 0.94);
    --kind-input: #A86A25;
    --kind-input-wash: rgba(253, 235, 208, 0.55);
    --kind-core: #2F6F9F;
    --kind-core-wash: rgba(214, 234, 248, 0.55);
    --kind-branch: #6D5589;
    --kind-branch-wash: rgba(232, 224, 240, 0.62);
    --kind-edge: #2B7D58;
    --kind-edge-wash: rgba(212, 245, 224, 0.55);
    --case-wire: rgba(37, 40, 55, 0.24);
    display: flex;
    flex-direction: column;
}

body[data-theme='dark'] .case {
    --case-sticky: color-mix(in srgb, #33231F 94%, transparent);
    --kind-input: #F0BD7F;
    --kind-input-wash: rgba(62, 45, 27, 0.6);
    --kind-core: #99CCF3;
    --kind-core-wash: rgba(29, 48, 67, 0.6);
    --kind-branch: #C8BCF1;
    --kind-branch-wash: rgba(43, 35, 61, 0.66);
    --kind-edge: #91DFB8;
    --kind-edge-wash: rgba(29, 58, 46, 0.6);
    --case-wire: rgba(247, 242, 232, 0.24);
}

/* --- Tabs ------------------------------------------------------------------ */

.case-tabs {
    position: sticky;
    top: 0;
    z-index: 4;
    display: flex;
    gap: 4px;
    margin: 0 -28px;
    padding: 14px 28px 12px;
    overflow-x: auto;
    scrollbar-width: none;
    background: var(--case-sticky);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--hairline-soft);
}

.case-tabs::-webkit-scrollbar { display: none; }

.case-tab {
    flex: 0 0 auto;
    padding: 8px 15px;
    border-radius: 999px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.case-tab:hover { color: var(--text); background: var(--surface-hover); }

.case-tab[aria-selected='true'] {
    color: var(--hue-ink);
    background: var(--case-panel);
    border-color: var(--hairline);
    box-shadow: var(--elev-1);
}

.case-panel { padding-top: 22px; }
.case-panel[hidden] { display: none; }

.case-tab:focus-visible,
.casenode:focus-visible,
.case-link:focus-visible,
.case-panel:focus-visible,
.casedetail:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
}

/* --- Overview -------------------------------------------------------------- */

.case-summary {
    max-width: 62ch;
    margin: 0;
    font-size: 18px;
    font-weight: 500;
    line-height: 1.6;
    letter-spacing: -0.005em;
    color: var(--text);
}

/* Open figures, like the entrance stats: hairline columns instead of boxes,
   so the numbers carry the weight. */
.case-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-top: 24px;
    border-block: 1px solid var(--hairline);
}

.case-stat {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 16px 20px 18px;
}

.case-stat:first-child {
    padding-left: 0;
}

.case-stat + .case-stat {
    border-left: 1px solid var(--hairline-soft);
}

.case-stat strong {
    font-family: var(--font-serif);
    font-size: 36px;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: -0.02em;
    color: var(--hue-ink);
}

.case-stat span {
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--text-muted);
}

.case-overview {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
    margin-top: 22px;
}

.case-heading,
.case-kicker {
    display: block;
    margin: 0 0 10px;
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.case-built ul {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.case-built li {
    position: relative;
    padding-left: 18px;
    font-size: 14.5px;
    line-height: 1.65;
    color: var(--text-secondary);
}

.case-built li::before {
    content: '';
    position: absolute;
    left: 2px;
    top: 0.62em;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--hue);
}

.case-hardest {
    padding: 16px 18px 17px;
    border-radius: var(--r-xl);
    border: 1px solid color-mix(in srgb, var(--hue) 26%, transparent);
    background: var(--hue-wash);
}

.case-hardest .case-kicker { color: var(--hue-ink); }

.case-hardest h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.4;
    color: var(--text);
}

.case-hardest p {
    margin: 8px 0 0;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
}

.case-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 22px;
}

.modal-body .case-link {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 9px 13px 10px;
    border-radius: var(--r-md);
    border: 1px solid var(--hairline);
    background: var(--case-panel);
    color: var(--text);
    font-weight: 400;
    text-decoration: none;
    transition: border-color 0.18s ease, transform 0.18s ease;
}

.modal-body .case-link:hover {
    text-decoration: none;
    border-color: var(--hue);
    transform: translateY(-1px);
}

.case-link-label {
    font-family: var(--font-mono);
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.case-link-text {
    font-size: 13px;
    font-weight: 600;
    color: var(--hue-ink);
    overflow-wrap: anywhere;
}

.case-note {
    max-width: 78ch;
    margin: 18px 0 0;
    padding-left: 12px;
    border-left: 2px solid var(--hairline);
    font-size: 12.5px;
    line-height: 1.65;
    color: var(--text-muted);
}

/* --- How it works ---------------------------------------------------------- */

.case-intro {
    max-width: 72ch;
    margin: 0 0 18px;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
}

.case-steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.case-step {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 15px 16px 16px;
    border-radius: var(--r-lg);
    border: 1px solid var(--hairline-soft);
    border-top: 3px solid var(--hue);
    background: var(--case-panel);
}

.case-step-index {
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 700;
    color: var(--hue-ink);
}

.case-step strong { font-size: 15px; color: var(--text); }

.case-step small {
    font-family: var(--font-mono);
    font-size: 10.5px;
    line-height: 1.5;
    color: var(--text-muted);
}

.case-step p {
    margin: 2px 0 0;
    font-size: 13.5px;
    line-height: 1.65;
    color: var(--text-secondary);
}

/* The runtime map: select a stage on the left, read it on the right. */
.casemap-split {
    display: grid;
    grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
    gap: 20px;
    align-items: start;
}

.casemap { display: flex; flex-direction: column; }

.casemap-entry {
    align-self: center;
    padding: 7px 14px;
    border-radius: 999px;
    border: 1px dashed var(--case-wire);
    background: var(--surface-sunken);
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-muted);
}

.casemap-stage {
    display: grid;
    grid-template-columns: repeat(var(--fan), minmax(0, 1fr));
    gap: 12px;
}

/* Wires are derived shapes drawn with hairline boxes, so nothing scales oddly. */
.casemap-link { position: relative; height: 26px; }

.casemap-stem,
.casemap-leg {
    position: absolute;
    width: 1.5px;
    background: var(--case-wire);
    border-radius: 999px;
}

.casemap-stem { left: 50%; transform: translateX(-50%); }
.casemap-leg { transform: translateX(-50%); }
.casemap-stem[data-pos='full'] { top: 0; bottom: 0; }
.casemap-stem[data-pos='top'],
.casemap-leg[data-pos='top'] { top: 0; height: 13px; }
.casemap-stem[data-pos='bottom'],
.casemap-leg[data-pos='bottom'] { top: 13px; bottom: 0; }

.casemap-bar {
    position: absolute;
    top: 12.25px;
    height: 1.5px;
    background: var(--case-wire);
    border-radius: 999px;
}

.casemap-tip {
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 6px;
    height: 6px;
    border-right: 1.5px solid var(--case-wire);
    border-bottom: 1.5px solid var(--case-wire);
    transform: translateX(-50%) rotate(45deg);
}

.casenode,
.casedetail-inner { --kind: var(--kind-core); --kind-wash: var(--kind-core-wash); }
:is(.casenode, .casedetail-inner)[data-kind='input'] { --kind: var(--kind-input); --kind-wash: var(--kind-input-wash); }
:is(.casenode, .casedetail-inner)[data-kind='branch'] { --kind: var(--kind-branch); --kind-wash: var(--kind-branch-wash); }
:is(.casenode, .casedetail-inner)[data-kind='edge'] { --kind: var(--kind-edge); --kind-wash: var(--kind-edge-wash); }

.casenode {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    padding: 10px 12px 11px 15px;
    border-radius: 12px;
    border: 1px solid var(--hairline-soft);
    background: var(--case-panel);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.casenode::before {
    content: '';
    position: absolute;
    left: 0;
    top: 10px;
    bottom: 10px;
    width: 3px;
    border-radius: 999px;
    background: var(--kind);
    opacity: 0.55;
}

.casenode-step {
    flex: 0 0 auto;
    padding-top: 2px;
    font-family: var(--font-mono);
    font-size: 9.5px;
    font-weight: 700;
    color: var(--kind);
}

.casenode-body { min-width: 0; }

.casenode-title {
    display: block;
    font-size: 12.5px;
    font-weight: 700;
    line-height: 1.35;
    color: var(--text);
}

.casenode-meta {
    display: block;
    margin-top: 3px;
    font-family: var(--font-mono);
    font-size: 10px;
    line-height: 1.5;
    color: var(--text-muted);
}

.casenode:hover { transform: translateY(-1px); box-shadow: var(--elev-1); }

.casenode[aria-selected='true'] {
    border-color: var(--kind);
    background: linear-gradient(135deg, var(--kind-wash), var(--case-panel) 72%);
    box-shadow: var(--elev-2);
}

.casenode[aria-selected='true']::before { opacity: 1; }

.casedetail {
    position: sticky;
    top: 70px;
    padding: 18px 20px 20px;
    border-radius: var(--r-xl);
    border: 1px solid var(--hairline-soft);
    background: var(--case-panel);
    box-shadow: var(--elev-1);
}

.casedetail-step {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--kind-wash);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 700;
    color: var(--kind);
}

.casedetail h4 {
    margin: 10px 0 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
}

.casedetail-role {
    margin: 6px 0 0;
    font-size: 14px;
    line-height: 1.65;
    color: var(--text-secondary);
}

.casedetail dl {
    display: flex;
    flex-direction: column;
    gap: 13px;
    margin: 16px 0 0;
    padding-top: 14px;
    border-top: 1px dashed var(--hairline);
}

.casedetail dt {
    margin-bottom: 4px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--kind);
}

.casedetail dd {
    margin: 0;
    font-size: 13.5px;
    line-height: 1.7;
    color: var(--text-secondary);
}

/* --- Key decisions --------------------------------------------------------- */

.case-decisions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.case-decision {
    display: flex;
    flex-direction: column;
    padding: 17px 19px 18px;
    border-radius: var(--r-xl);
    border: 1px solid var(--hairline-soft);
    background: var(--case-panel);
}

.case-decision-index {
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 700;
    color: var(--hue-ink);
}

.case-decision h4 {
    margin: 6px 0 0;
    font-size: 15.5px;
    font-weight: 700;
    line-height: 1.4;
    color: var(--text);
}

.case-decision p {
    margin: 8px 0 0;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
}

.case-decision .case-tradeoff {
    margin-top: auto;
    padding-top: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

.case-tradeoff span {
    display: block;
    margin-bottom: 3px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent);
}

/* Before/after bars under a stat: each row names itself and its value; the
   faint bar is the starting point, the hue bar the result, both to one scale.
   They grow once when the tab opens. */
.case-compare {
    display: grid;
    gap: 5px;
    margin-top: 10px;
}

.case-compare-row {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    font-size: 11.5px;
    line-height: 1.2;
    color: var(--text-muted);
}

.case-compare-row em {
    font-style: normal;
    letter-spacing: 0.02em;
}

.case-compare-row b {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.case-compare-row[data-kind='to'] { color: var(--hue-ink); }

.case-compare-row i {
    display: block;
    width: var(--bar);
    height: 6px;
    border-radius: 999px;
    background: var(--hairline);
    transform-origin: left center;
    animation: caseBarGrow 0.9s cubic-bezier(0.22, 0.61, 0.36, 1) 0.15s backwards;
}

.case-compare-row[data-kind='to'] i {
    background: var(--hue-ink);
    animation-delay: 0.35s;
}

/* Product media sits between the figures and the write-up. Compact media is
   capped on laptops; full product artwork keeps its complete composition. */
.case-media {
    margin: 22px 0 0;
    border-radius: 14px;
    overflow: hidden;
    background: var(--surface-sunken);
    box-shadow: inset 0 0 0 1px var(--hairline);
}

.case-media :is(img, video) {
    display: block;
    width: 100%;
    height: auto;
    max-height: 360px;
    object-fit: cover;
}

/* Product posters and the Orbit preview need their complete composition. */
.case-media[data-fit='full'] {
    max-width: 800px;
    margin-inline: auto;
}

.case-media[data-fit='full'] img {
    max-height: none;
    object-fit: contain;
}

/* A terminal recording sits on its own dark ground, not a light letterbox. */
.case-media:has(video) { background: #13171C; }

.case-media[data-fit='contain'] :is(img, video) {
    object-fit: contain;
    padding: 14px;
}

@keyframes caseBarGrow {
    from { transform: scaleX(0); }
}

/* --- Responsive and motion ------------------------------------------------- */

@media (max-width: 899px) {
    .case-overview,
    .casemap-split { grid-template-columns: 1fr; }
    .casedetail { position: static; }
    .case-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .case-stat:nth-child(odd) { padding-left: 0; border-left: 0; }
    .case-stat:nth-child(n + 3) { border-top: 1px solid var(--hairline-soft); }
}

@media (max-width: 767px) {
    .modal[data-modal-variant='case'] { height: 92vh; max-height: 92vh; }
    .modal-body[data-modal-variant='case'] { padding: 0 18px 20px; }
    .case-tabs { margin: 0 -18px; padding: 12px 18px 10px; }
    .case-summary { font-size: 16px; }
    .case-stat strong { font-size: 28px; }
    .case-decisions { grid-template-columns: 1fr; }
    .casemap-stage { gap: 8px; }
    .casenode { padding: 9px 10px 10px 13px; }
    .casenode-title { font-size: 12px; }
}

body[data-motion='reduced'] :is(.casenode, .case-link):hover { transform: none; }
body[data-motion='reduced'] .case-compare-row i { animation: none; }

@media (prefers-reduced-motion: reduce) {
    .case-compare-row i { animation: none; }
}

@media (prefers-reduced-motion: reduce) {
    :is(.casenode, .case-link):hover { transform: none; }
}
