/* Case study template (cst-*). One layout: full-width hero, sticky section rail, content column.
   Colours, type and space alias the site tokens in styles.css (DESIGN_SYSTEM.md).
   No uppercase, no small caps, no dot-separated eyebrows. See CASE_STUDY_TEMPLATE.md. */

.cst{
  /* Aliases onto the site tokens in styles.css (DESIGN_SYSTEM.md) */
  --cst-bg:var(--bg);
  --cst-surface:var(--surface);
  --cst-surface-2:var(--surface-2);
  --cst-line:var(--line);
  --cst-line-soft:var(--line-soft);
  --cst-text:var(--text);
  --cst-text-2:var(--text-2);
  --cst-muted:var(--muted);
  --cst-accent:var(--lavender);
  --cst-accent-hover:var(--lavender-hover);
  --cst-quote-mark:var(--pink-large);
  --accent:var(--cst-accent);

  --cst-sans:var(--font-sans);
  --cst-mono:var(--font-mono);

  /* Type scale */
  --cst-fs-h1:var(--fs-display);
  --cst-fs-pitch:clamp(18px,1.6vw,20px);
  --cst-fs-lead:clamp(21px,2.2vw,26px); /* no token fits: between --fs-lead and --fs-h3 */
  --cst-fs-h2:var(--fs-title);
  --cst-fs-h3:var(--fs-h4);             /* decision card titles */
  --cst-fs-body:var(--fs-body-lg);
  --cst-fs-caption:var(--fs-small);
  --cst-fs-label:var(--fs-label);

  /* Space and widths */
  --cst-gutter:var(--gutter);
  --cst-measure:36rem;      /* text: measured 64 characters a line on average at 17px */
  --cst-figure:41.5rem;     /* wide figures: measure + 15% */
  --cst-figure-small:30rem; /* content figures: portraits, small artefacts */
  --cst-column:55rem;       /* full: galleries, decisions, stats */
  --cst-rail:12rem;
  --cst-rail-gap:4.5rem;
  --cst-space-flow:1.25rem;
  --cst-space-block:var(--space-8);
  --cst-space-section:var(--space-section);
}

.cst main{color:var(--cst-text-2);font-size:var(--cst-fs-body);line-height:var(--lh-body);}
.cst nav.primary-nav{margin-bottom:56px;}
.cst main .wrap,.cst footer > .wrap{padding-inline:var(--cst-gutter);}

.cst a:focus-visible,.cst button:focus-visible{outline:var(--focus-width) solid var(--cst-accent);outline-offset:var(--focus-offset);border-radius:var(--r-xs);}

/* Intro and hero */
/* The intro starts where the content column starts, past the rail */
.cst main .cst-intro{padding-left:calc(var(--cst-gutter) + var(--cst-rail) + var(--cst-rail-gap));}
.cst-intro > *{max-width:var(--cst-column);}
.cst-back{margin-bottom:17px;} /* 28px of space, less the 11px tap-area overhang */
.cst-title{margin:0;font-size:var(--cst-fs-h1);font-weight:var(--fw-black);line-height:var(--lh-tight);letter-spacing:var(--ls-display);color:var(--cst-text);text-wrap:balance;}
.cst-pitch{margin:20px 0 0;font-size:var(--cst-fs-pitch);line-height:var(--lh-body);max-width:var(--cst-measure);text-wrap:pretty;}

/* The reel has a transparent background, so it sits in the content column, lined up with the
   intro, rather than bleeding to the browser edges. */
.cst-hero{max-width:1240px;margin:var(--cst-space-block) auto 0;padding:0 var(--cst-gutter) 0 calc(var(--cst-gutter) + var(--cst-rail) + var(--cst-rail-gap));}
/* The frame is the app window's box. The video, with its transparent margin and shadow,
   overflows it by the `inset` set in the frontmatter, so the window edges line up with the copy. */
.cst-hero-frame{max-width:var(--cst-column);}
.cst-hero .cst-media{width:var(--hero-w,100%);margin:var(--hero-mt,0) 0 var(--hero-mb,0) var(--hero-ml,0);pointer-events:none;}
.cst-hero video{display:block;width:100%;height:auto;}
.cst main{overflow-x:clip;}  /* the reel's shadow may spill past the screen edge on phones */
.cst .cst-hero-caption{display:flex;align-items:center;justify-content:space-between;gap:16px;max-width:var(--cst-column);min-height:44px;margin-top:10px;}
.cst-hero-toggle,.cst-embed-toggle{
  flex:none;margin-left:auto;min-height:44px;padding:6px 14px;cursor:pointer;
  font-family:var(--cst-mono);font-size:var(--cst-fs-label);color:var(--cst-muted);
  background:transparent;border:1px solid var(--cst-line);border-radius:var(--r-pill);
}
.cst-hero-toggle:hover,.cst-embed-toggle:hover{color:var(--cst-text);border-color:var(--cst-accent);}
.cst-embed-toggle[hidden]{display:none;}
/* Embed captions share their line with the play/pause button */
.cst .cst-embed-caption{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;max-width:none;}
.cst-embed-caption > span{max-width:var(--cst-measure);}

/* Rail + content grid */
.cst-grid{display:grid;grid-template-columns:var(--cst-rail) minmax(0,1fr);gap:var(--cst-rail-gap);align-items:start;}
.cst-rail{position:sticky;top:24px;padding-top:var(--cst-space-section);}
.cst-rail-title{margin:0 0 12px;font-family:var(--cst-mono);font-size:var(--cst-fs-label);color:var(--cst-muted);}
.cst-rail ol{list-style:none;margin:0;padding:0;border-left:1px solid var(--cst-line);}
.cst-rail-link{display:block;margin-left:-1px;padding:7px 0 7px 16px;border-left:2px solid transparent;font-size:var(--fs-small);line-height:var(--lh-ui);color:var(--cst-muted);transition:color var(--dur) ease,border-color var(--dur) ease;}
.cst-rail-link:hover{color:var(--cst-text);}
.cst-rail-link[aria-current="true"]{color:var(--cst-text);border-left-color:var(--cst-accent);font-weight:var(--fw-semibold);}
.cst-content{max-width:var(--cst-column);min-width:0;}

/* Sections and flow */
.cst-section{display:flex;flex-direction:column;padding-top:var(--cst-space-section);scroll-margin-top:1rem;}
.cst-section > *{width:100%;}
.cst-w-text{max-width:var(--cst-measure);}
.cst-w-content{max-width:var(--cst-figure-small);}
.cst-w-wide{max-width:var(--cst-figure);}
.cst-w-full{max-width:100%;}
.cst-section > * + *{margin-top:var(--cst-space-flow);}
.cst-section > .cst-block,.cst-section > .cst-block + *{margin-top:var(--cst-space-block);}
.cst-section > .cst-section-head + *{margin-top:2rem;}
/* A heading sits close to the paragraph it introduces */
.cst-section > .cst-section-head:has(.cst-lead-heading) + .cst-w-text,
.cst-section > .cst-w-text:has(> .cst-h3) + .cst-w-text{margin-top:.6rem;}
.cst-section > .cst-w-text:has(> .cst-h3) + .cst-block--figure{margin-top:1rem;}

.cst-h2{margin:0;font-size:var(--cst-fs-h2);font-weight:var(--fw-bold);line-height:var(--lh-snug);color:var(--cst-accent);}
.cst-lead{margin:14px 0 0;font-size:var(--cst-fs-lead);font-weight:var(--fw-semibold);line-height:var(--lh-ui);color:var(--cst-text);text-wrap:pretty;}
.cst-lead strong{font-weight:var(--fw-bold);}
.cst-lead-heading{margin:14px 0 0;font-size:var(--fs-title);font-weight:var(--fw-bold);line-height:var(--lh-snug);color:var(--cst-text);text-wrap:balance;}
.cst-h3{margin:.75rem 0 0;font-size:var(--fs-title);font-weight:var(--fw-bold);line-height:var(--lh-snug);color:var(--cst-text);}
.cst-p{margin:0;}
.cst-p strong,.cst-list strong{color:var(--cst-text);font-weight:var(--fw-semibold);}
.cst main a:not([class]){color:var(--cst-accent);text-decoration:underline;text-decoration-thickness:1px;text-underline-offset:3px;}
.cst main a:not([class]):hover{color:var(--cst-accent-hover);}
.cst-list{margin:0;padding-left:1.2em;}
.cst-list li + li{margin-top:.7em;}
.cst-list li::marker{color:var(--cst-accent);}

/* Media */
/* Media sits straight on the page: graphics bring their own transparent corners and shadows.
   Only plain photos get rounded corners. */
.cst-media{position:relative;}
.cst-media--photo img{border-radius:var(--r-md);}
.cst-media img{display:block;width:100%;height:auto;}
.cst-figure{margin:0;}
/* Interactive graphic: the box takes its size from `ratio`, the still shows until the iframe loads */
.cst-media--embed{overflow:hidden;}
.cst-media--embed img{height:100%;object-fit:cover;}
.cst-media--embed iframe{position:absolute;inset:0;display:block;width:100%;height:100%;border:0;opacity:0;transition:opacity var(--dur-wipe) ease;}
.cst-media--embed.is-live iframe{opacity:1;}
.cst-media--embed.is-live img{visibility:hidden;}  /* the iframe's title and its graphic's label take over */
.cst-media picture{display:contents;}
.cst-hero-phone{display:none;}
/* Phones: a cropped still stands in for the hero reel and for any graphic that has one
   (made by build/make_mobile_crops.py), since full desktop screens are unreadable at this size */
@media (max-width: 640px){
  .cst-hero--phone .cst-hero-frame,.cst-hero--phone .cst-hero-toggle{display:none;}
  .cst-hero-phone{display:block;width:100%;height:auto;max-width:var(--cst-column);border-radius:var(--r-md);}
  .cst-media--embed[data-cst-phone]{aspect-ratio:var(--phone-ratio) !important;}
  .cst-hero .cst-media--embed[data-cst-phone]{width:100%;margin:0;}
  .cst-media--embed[data-cst-phone] iframe{display:none;}
  .cst-media--embed[data-cst-phone] img{visibility:visible;}
  .cst-figure--phone .cst-embed-toggle{display:none;}
}
.cst-caption{margin-top:12px;max-width:var(--cst-measure);font-size:var(--cst-fs-caption);line-height:var(--lh-body);color:var(--cst-muted);text-wrap:pretty;}

/* Honesty label: always visible, inside the frame. It sits on media glass, so it keeps --on-media
   and a pastel border in both themes. */
.cst-label{
  position:absolute;top:12px;left:12px;z-index:1;
  font-family:var(--cst-mono);font-size:var(--cst-fs-label);line-height:var(--lh-snug);color:var(--on-media);
  background:var(--scrim-heavy);border:1px solid var(--lavender-fill);border-radius:var(--r-pill);padding:5px 12px;
}

/* View larger: the whole media box opens the site lightbox (script.js) */
.cst-zoom{position:absolute;inset:0;z-index:2;display:block;width:100%;padding:0;border:0;background:transparent;cursor:zoom-in;}
.cst-zoom-hint{
  position:absolute;right:12px;top:12px;
  font-family:var(--cst-mono);font-size:var(--cst-fs-label);line-height:var(--lh-snug);color:var(--on-media);
  background:var(--scrim-heavy);border:1px solid var(--cst-line);border-radius:var(--r-pill);padding:5px 12px;
}
.cst-zoom:hover .cst-zoom-hint{border-color:var(--lavender-fill);}
.cst .cst-zoom:focus-visible{outline-offset:var(--focus-offset);}
/* Case study screenshots can be taller than the screen: show them at full lightbox width and
   let the overlay scroll, rather than shrinking them to fit the height. */
.cst .lightbox-overlay{align-items:flex-start;overflow-y:auto;overscroll-behavior:contain;}
.cst .lightbox{max-height:none;margin:auto;transform:none;}
.cst .lightbox-img{max-height:none;}
.cst .lightbox-close{position:fixed;top:20px;right:20px;}

/* Gallery: items share a row height whatever their ratio */
.cst-gallery{display:flex;gap:16px;align-items:flex-start;}
.cst-gallery-item{margin:0;flex:var(--r) 1 0;min-width:0;}

/* Snapshot facts */
.cst-facts{margin:0;}
.cst-fact{display:grid;grid-template-columns:8rem minmax(0,1fr);gap:16px;padding:14px 0;border-top:1px solid var(--cst-line);}
.cst-fact dt{margin-top:3px;font-family:var(--cst-mono);font-size:var(--cst-fs-label);color:var(--cst-muted);}
.cst-fact dd{margin:0;font-size:var(--fs-body);line-height:var(--lh-body);color:var(--cst-text);}
.cst-fact-detail{display:block;margin-top:4px;font-size:var(--cst-fs-caption);color:var(--cst-muted);}

/* Decision */
.cst-decision{padding:26px 28px;border:1px solid var(--cst-line);border-radius:var(--r-md);background:var(--cst-surface);}
.cst-decision-head{margin-bottom:20px;}
.cst-decision-number{margin:0 0 6px;font-family:var(--cst-mono);font-size:var(--cst-fs-label);color:var(--cst-accent);}
.cst-decision h3{margin:0;font-size:var(--cst-fs-h3);font-weight:var(--fw-bold);line-height:var(--lh-snug);color:var(--cst-text);text-wrap:balance;}
.cst-decision-rows{margin:0;}
.cst-decision-row{display:grid;grid-template-columns:9.5rem minmax(0,1fr);gap:20px;padding:14px 0;border-top:1px solid var(--cst-line);}
.cst-decision-row dt{padding-top:3px;font-family:var(--cst-mono);font-size:var(--cst-fs-label);line-height:var(--lh-ui);color:var(--cst-muted);}
.cst-decision-row dd{margin:0;font-size:var(--fs-body);line-height:var(--lh-body);max-width:var(--cst-measure);color:var(--cst-text);}
.cst-decision-media{margin-top:24px;}

/* Quote */
.cst-quote{margin:0;padding:8px 0 0 28px;border-left:3px solid var(--cst-quote-mark);}
.cst-quote blockquote{margin:0;}
.cst-quote blockquote p{margin:0;font-size:var(--fs-h3);font-weight:var(--fw-semibold);line-height:var(--lh-ui);color:var(--cst-text);text-wrap:balance;}
.cst-quote figcaption{display:flex;align-items:center;gap:14px;margin-top:20px;}
.cst-quote-photo{width:56px;height:56px;border-radius:50%;object-fit:cover;object-position:50% 20%;flex:none;}
.cst-quote-who{display:flex;flex-direction:column;}
.cst-quote-name{font-size:var(--fs-body);font-weight:var(--fw-semibold);color:var(--cst-text);}
.cst-quote-role{font-size:var(--cst-fs-caption);color:var(--cst-muted);}

/* Stats: four across, two by two below 900px; never three plus one */
.cst-stats{margin:0;padding:0;list-style:none;display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:16px;}
.cst-stats[data-count="1"]{grid-template-columns:minmax(0,1fr);}
.cst-stats[data-count="2"]{grid-template-columns:repeat(2,minmax(0,1fr));}
.cst-stats[data-count="3"]{grid-template-columns:repeat(3,minmax(0,1fr));}
.cst-stat{display:flex;flex-direction:column;gap:10px;padding:22px 20px 24px;border-radius:var(--r-md);background:var(--cst-surface);border:1px solid var(--cst-line-soft);}
.cst-stat-value{font-size:var(--fs-h3);font-weight:var(--fw-bold);line-height:var(--lh-tight);color:var(--cst-accent);letter-spacing:var(--ls-tight);text-wrap:balance;}
.cst-stat-label{font-size:var(--fs-small);line-height:var(--lh-ui);}
.cst-tag{align-self:flex-start;font-family:var(--cst-mono);font-size:var(--cst-fs-label);color:var(--cst-text);border:1px solid var(--cst-line);border-radius:var(--r-pill);padding:4px 12px;}

/* Callout: quiet, not an alert */
.cst-callout{padding:24px 26px;border-radius:var(--r-md);background:var(--cst-surface);border:1px solid var(--cst-line);}
.cst-callout-title{margin:0 0 8px;font-size:var(--fs-body-lg);font-weight:var(--fw-bold);color:var(--cst-text);}
.cst-callout p{margin:0;font-size:var(--fs-body);line-height:var(--lh-body);}
/* Markdown `>` quote: the callout's type, set off by a rule instead of a box */
.cst-section > :has(> .cst-blockquote),.cst-section > :has(> .cst-blockquote) + *{margin-top:var(--cst-space-block);}
.cst-blockquote{margin:0;padding:2px 0 2px 22px;border-left:2px solid var(--cst-accent);}
.cst-blockquote p{margin:0;font-size:var(--fs-body);line-height:var(--lh-body);color:var(--cst-text);}

/* End of article */
.cst-disclaimer{margin:var(--cst-space-section) 0 0;max-width:var(--cst-measure);font-size:var(--cst-fs-caption);line-height:var(--lh-body);color:var(--cst-muted);}
.cst-disclaimer + .cst-end{margin-top:2rem;}
/* The phone ending (.cst-end-m) replaces .cst-end at 640px and under */
.cst-end-m{display:none;}
.cst-end{display:flex;justify-content:space-between;gap:16px;flex-wrap:wrap;margin:var(--cst-space-section) 0 96px;padding-top:28px;border-top:1px solid var(--cst-line);}

/* Below 900px: one column, the rail becomes a sticky horizontal strip at the top */
@media (max-width: 900px){
  .cst{--cst-space-section:4.5rem;}
  .cst .cs-page-header{padding:24px var(--cst-gutter) 0;}
  .cst nav.primary-nav{margin-bottom:36px;}
  .cst-hero{margin-top:2rem;padding-left:var(--cst-gutter);}

  .cst main .cst-intro{padding-left:var(--cst-gutter);}
  .cst-grid{grid-template-columns:minmax(0,1fr);gap:0;}
  .cst-rail{
    /* --pinned-nav: the height of the site nav while it's slid in (script.js), so the strip sits under it */
    position:sticky;top:var(--pinned-nav,0px);z-index:5;padding:0;margin:0 calc(-1 * var(--cst-gutter));
    transition:top var(--dur-wipe) var(--ease-wipe);
    /* the page colour at 90%: equals --scrim-heavy in dark, a frosted paper bar in light */
    background:color-mix(in oklch, var(--bg) 90%, transparent);border-bottom:1px solid var(--cst-line);
    -webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);
  }
  .cst-rail-title{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;}
  .cst-rail ol{display:flex;gap:4px;overflow-x:auto;border:0;padding:8px var(--cst-gutter);scrollbar-width:none;}
  .cst-rail ol::-webkit-scrollbar{display:none;}
  .cst-rail-link{white-space:nowrap;margin:0;padding:10px 14px;border:0;border-radius:var(--r-pill);font-size:var(--fs-label);}
  .cst-rail-link[aria-current="true"]{background:var(--cst-surface-2);border:0;}
  .cst-section{scroll-margin-top:64px;}

  .cst-stats,.cst-stats[data-count="3"]{grid-template-columns:repeat(2,minmax(0,1fr));}
  .cst-stats[data-count="3"] .cst-stat:last-child{grid-column:1 / -1;} /* no half-width orphan */
}

@media (max-width: 640px){
  .cst-fact,.cst-decision-row{grid-template-columns:1fr;gap:4px;}
  .cst-fact dt,.cst-decision-row dt{margin-top:0;padding-top:0;}
  .cst-decision{padding:20px 18px;}
  .cst-stats{gap:10px;}
  .cst-stat{padding:16px 14px 18px;}
  .cst-gallery{flex-wrap:wrap;gap:20px 12px;}
  .cst-gallery-item--landscape{flex:1 1 100%;}
  .cst-gallery-item--portrait{flex:0 1 calc(50% - 6px);}
  .cst-quote{padding-left:18px;}
  /* Phones: the next study's card, then Previous and Back to all case studies as tall rows (_end_mobile) */
  .cst-end{display:none;}
  .cst-end-m{
    display:flex;flex-direction:column;gap:var(--space-4);
    margin:var(--cst-space-section) 0 var(--space-9);padding-top:var(--space-4);border-top:1px solid var(--cst-line);
  }
  .cst-disclaimer + .cst-end + .cst-end-m{margin-top:var(--space-4);}
  .cst-end-next{margin:0;font-family:var(--font-mono);font-size:var(--fs-label);font-weight:var(--fw-regular);color:var(--cst-muted);}
  .cst-end-rows{display:flex;flex-direction:column;border-top:1px solid var(--cst-line);}
  .cst-end-row{
    display:flex;align-items:center;gap:14px;min-height:60px;padding:var(--space-2) 0;
    border-bottom:1px solid var(--cst-line);color:var(--text);
  }
  .cst-end-row:hover{color:var(--text);}
  .cst-end-row:focus-visible{outline:var(--focus-width) solid var(--accent);outline-offset:var(--focus-offset);border-radius:var(--r-xs);}
  .cst-end-icon{display:flex;color:var(--accent);transition:transform var(--dur-fast) ease;}
  .cst-end-row:hover .cst-end-icon{transform:translateX(calc(-1 * var(--nudge)));}
  .cst-end-row:last-child:hover .cst-end-icon{transform:none;}
  .cst-end-text{display:flex;flex-direction:column;}
  .cst-end-label{font-family:var(--font-mono);font-size:var(--fs-label);color:var(--cst-muted);}
  .cst-end-name{font-size:var(--fs-body-lg);font-weight:var(--fw-semibold);}
}

@media (prefers-reduced-motion: reduce){
  .cst-rail-link,.cst-media--embed iframe,.cst-rail,.cst-end-icon{transition:none;}
}

/* colour-fallback:start (generated by build/casestudy/colours.py, don't edit) */
@supports not (color: oklch(0 0 0)) {
@media (max-width: 900px){.cst-rail{background:rgba(21,18,28,0.9);}}
}
/* colour-fallback:end */
