/* ==========================================================================
   MAIN.CSS — layout + components for rickysunay.com
   All values reference semantic tokens in tokens.css. If you find yourself
   typing a hex code in this file, it probably belongs in tokens.css instead.
   ==========================================================================
   CONTENTS
   01 · Base / reset
   02 · Layout primitives (.container, .prose, .section)
   03 · Header + nav
   04 · Type roles (eyebrow, display, lede)
   05 · Buttons + links
   06 · Home: hero, case grid
   07 · Case study: meta grid, metrics, spec figures, principle cards
   08 · About / Contact
   09 · Token footer
   10 · Grid overlay (press G)
   11 · Accessibility + motion
   ========================================================================== */


/* 01 · BASE ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg-canvas);
  color: var(--fg-secondary);
  font-family: var(--text-body);
  font-size: var(--scale-300);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  /* faint blueprint grid on the canvas itself */
  background-image:
    linear-gradient(var(--border-hairline) 1px, transparent 1px),
    linear-gradient(90deg, var(--border-hairline) 1px, transparent 1px);
  background-size: 72px 72px;
  /* first horizontal grid line sits exactly on the header's bottom edge */
  background-position: 0 var(--header-h);
  background-attachment: fixed;
}

/* Generalist mode swaps the blueprint grid for a whisper of paper grain —
   inline SVG fractal noise, no image assets. TUNING: the strength knob is
   opacity='0.16' inside the data URI below (0.08 = barely there, 0.3 = visible texture); tile size is background-size. */
:root[data-mode="gen"] body {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.16'/%3E%3C/svg%3E");
  background-size: 240px 240px;
  background-position: 0 0;
  background-attachment: fixed;
}

img { max-width: 100%; height: auto; display: block; }

h1, h2, h3, h4 { color: var(--fg-primary); line-height: 1.15; margin: 0 0 var(--space-4); }

p { margin: 0 0 var(--space-4); max-width: var(--measure); }

ul { padding-left: 1.2em; max-width: var(--measure); }
li { margin-bottom: var(--space-2); }

/* Component lists are layout, not prose — they escape the prose ul constraints.
   (This is the fix for the case grid rendering single-column on desktop.) */
.case-grid, .metrics, .principles, .how-i-work, .contact-list {
  max-width: none;
  padding-left: 0;
}

::selection { background: var(--bg-accent); color: var(--fg-on-accent); }

:focus-visible { outline: var(--focus-ring); outline-offset: var(--focus-offset); border-radius: var(--radius-1); }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--bg-accent); color: var(--fg-on-accent);
  padding: var(--space-2) var(--space-4); z-index: 100;
  font-family: var(--text-technical); font-size: var(--scale-200);
}
.skip-link:focus { left: var(--space-4); }


/* 02 · LAYOUT -------------------------------------------------------------- */

.container {
  max-width: var(--content-max);
  margin: 0 auto;
  /* longhand on purpose: co-classed rules (.section, .hero, .case-hero,
     .case-nav) set vertical padding with padding-block and must never be
     able to zero this out */
  padding-inline: var(--gutter);
}

.section { padding-block: var(--space-24); }
.section--flush { border-top: none; }

.prose h2 { font-family: var(--text-display); font-size: var(--scale-600); font-weight: 500; margin-top: var(--space-12); }
.prose h3 { font-size: var(--scale-400); font-weight: 600; margin-top: var(--space-8); }
.prose strong { color: var(--fg-primary); font-weight: 600; }


/* 03 · HEADER + NAV -------------------------------------------------------- */

.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg-canvas) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: var(--line-1) solid var(--border-hairline);
}

.site-header__inner {
  display: flex; align-items: stretch; justify-content: space-between;
  height: var(--header-h);
}

.logo {
  align-self: center;
  font-family: var(--text-technical);
  font-size: var(--scale-200);
  color: var(--fg-primary);
  text-decoration: none;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
}
.logo__glyph {
  width: 22px; height: 22px; flex-shrink: 0;
  /* Matches the wordmark text color (light in dark mode, dark in light mode).
     Prefer the red glyph? Change this line to: color: var(--fg-accent); */
  color: var(--fg-primary);
  transition: transform var(--duration-2) var(--ease-out);
}
/* LOGO HOVER EFFECT — tweak the rotation here; speed/easing live on .logo__glyph's transition */
.logo:hover .logo__glyph { transform: rotate(90deg); }

.nav { display: flex; gap: var(--space-6); align-items: stretch; }

.nav a {
  font-family: var(--text-technical);
  font-size: var(--scale-200);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-secondary);
  text-decoration: none;
  display: inline-flex; align-items: center;
  /* full-height link; -1px overlap puts the active border ON the header's bottom hairline */
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  transition: color var(--duration-1) var(--ease-out);
}
.nav .mode-toggle--compact { align-self: center; }
.nav a:hover { color: var(--fg-primary); }
.nav a[aria-current="page"] { color: var(--fg-accent); border-bottom-color: var(--fg-accent); }


/* 04 · TYPE ROLES ---------------------------------------------------------- */

.eyebrow {
  font-family: var(--text-technical);
  font-size: var(--scale-100);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-accent);
  display: flex; align-items: center; gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.eyebrow::before { content: ""; width: 24px; height: 1px; background: var(--fg-accent); }

.display-xl {
  font-family: var(--text-display);
  font-size: clamp(var(--scale-700), 6vw, var(--scale-900));
  font-weight: 500;
  letter-spacing: -0.01em;
}
.display-lg {
  font-family: var(--text-display);
  font-size: clamp(var(--scale-600), 4.5vw, var(--scale-800));
  font-weight: 500;
  letter-spacing: -0.01em;
}
.display-lg em, .display-xl em { font-style: italic; color: var(--fg-accent); }

.lede {
  font-size: var(--scale-400);
  line-height: 1.55;
  color: var(--fg-secondary);
  max-width: var(--measure);
}


/* 05 · BUTTONS + LINKS ----------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-family: var(--text-technical);
  font-size: var(--scale-200);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-2);
  text-decoration: none;
  border: var(--line-1) solid transparent;
  transition: background var(--duration-1) var(--ease-out), border-color var(--duration-1) var(--ease-out);
}
.btn--primary { background: var(--bg-accent); color: var(--fg-on-accent); font-weight: 500; }
.btn--primary:hover { background: var(--bg-accent-hover); }
.btn--ghost { border-color: var(--border-strong); color: var(--fg-primary); }
.btn--ghost:hover { border-color: var(--fg-accent); color: var(--fg-accent); }

.prose a, .inline-link { color: var(--fg-accent); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--border-accent); }
.prose a:hover, .inline-link:hover { text-decoration-color: var(--fg-accent); }


/* 06 · HOME ---------------------------------------------------------------- */

.hero { padding-block: var(--space-32) var(--space-24); }

.hero .display-xl { max-width: 18ch; margin-bottom: var(--space-6); }

.case-grid {
  display: grid;
  /* 2-up for larger thumbnails; collapses to one column below 900px */
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-8);
  padding: 0; margin: var(--space-12) 0 0; list-style: none;
}

@media (max-width: 900px) {
  .case-grid { grid-template-columns: 1fr; gap: var(--space-6); }
}

.case-card {
  position: relative;
  display: block;
  background: var(--bg-raised);
  border: var(--line-1) solid var(--border-hairline);
  border-radius: var(--radius-3);
  padding: var(--space-8);
  text-decoration: none;
  transition: border-color var(--duration-2) var(--ease-out), background var(--duration-2) var(--ease-out);
}
.case-card:hover { border-color: var(--border-accent); background: var(--bg-raised-hover); }

/* Figma-style corner selection handles, revealed on hover.
   One pseudo-element draws all four squares as layered gradients
   (canvas-colored 5px fill over accent 7px outline at each corner),
   so cards need no helper markup and every card gets all corners. */
.case-card::after {
  content: ""; position: absolute; inset: -4px;
  pointer-events: none;
  background-image:
    linear-gradient(var(--bg-canvas), var(--bg-canvas)),
    linear-gradient(var(--bg-canvas), var(--bg-canvas)),
    linear-gradient(var(--bg-canvas), var(--bg-canvas)),
    linear-gradient(var(--bg-canvas), var(--bg-canvas)),
    linear-gradient(var(--fg-accent), var(--fg-accent)),
    linear-gradient(var(--fg-accent), var(--fg-accent)),
    linear-gradient(var(--fg-accent), var(--fg-accent)),
    linear-gradient(var(--fg-accent), var(--fg-accent));
  background-size: 5px 5px, 5px 5px, 5px 5px, 5px 5px, 7px 7px, 7px 7px, 7px 7px, 7px 7px;
  background-position:
    left 1px top 1px, right 1px top 1px, left 1px bottom 1px, right 1px bottom 1px,
    left top, right top, left bottom, right bottom;
  background-repeat: no-repeat;
  opacity: 0; transition: opacity var(--duration-2) var(--ease-out);
}
.case-card:hover::after { opacity: 1; }

.case-card__id {
  font-family: var(--text-technical);
  font-size: var(--scale-100);
  color: var(--fg-tertiary);
  letter-spacing: 0.06em;
  display: block; margin-bottom: var(--space-4);
}
.case-card:hover .case-card__id { color: var(--fg-accent); }

.case-card__title {
  font-family: var(--text-display);
  font-size: var(--scale-500);
  font-weight: 500;
  color: var(--fg-primary);
  margin-bottom: var(--space-3);
}

.case-card__desc { font-size: var(--scale-200); color: var(--fg-secondary); margin: 0; }

.case-card__tags {
  display: flex; flex-wrap: wrap; gap: var(--space-2);
  margin-top: var(--space-6);
}
.tag {
  font-family: var(--text-technical);
  font-size: var(--scale-100);
  color: var(--fg-tertiary);
  border: var(--line-1) solid var(--border-hairline);
  border-radius: var(--radius-1);
  padding: 2px var(--space-2);
}

.case-card--pending .case-card__title { color: var(--fg-secondary); }


/* 07 · CASE STUDY ---------------------------------------------------------- */

.case-hero { padding-block: var(--space-24) var(--space-16); }
.case-hero .display-lg { max-width: 22ch; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-6);
  margin-top: var(--space-12);
  padding-top: var(--space-6);
  border-top: var(--line-1) solid var(--border-hairline);
}
.meta-grid dt {
  font-family: var(--text-technical);
  font-size: var(--scale-100);
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--fg-tertiary);
  margin-bottom: var(--space-1);
}
.meta-grid dd { margin: 0; color: var(--fg-primary); font-size: var(--scale-200); }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-6);
  list-style: none; padding: 0; margin: var(--space-8) 0;
}
.metric {
  background: var(--bg-accent-wash);
  border: var(--line-1) solid var(--border-accent);
  border-radius: var(--radius-3);
  padding: var(--space-6);
}
.metric__value {
  font-family: var(--text-display);
  font-size: var(--scale-700);
  font-weight: 500;
  color: var(--fg-accent);
  display: block; line-height: 1;
  margin-bottom: var(--space-2);
}
.metric__label { font-size: var(--scale-200); color: var(--fg-secondary); }

/* Spec figure: image framed like an annotated Figma frame */
.spec-figure { margin: var(--space-12) 0; }

/* WIDTH VARIANTS — default is full container width. To center an image at a
   narrower width, add one class to the <figure>:
     <figure class="spec-figure spec-figure--narrow">   → 680px, centered
     <figure class="spec-figure spec-figure--medium">   → 920px, centered
   (captions center-align automatically with the frame) */
.spec-figure--narrow { max-width: 680px; margin-left: auto; margin-right: auto; }
.spec-figure--medium { max-width: 920px; margin-left: auto; margin-right: auto; }
.spec-figure__frame {
  position: relative;
  border: var(--line-1) solid var(--border-hairline);
  border-radius: var(--radius-2);
  overflow: hidden;
  background: var(--bg-raised);
}
.spec-figure__frame img { width: 100%; }
.spec-figure figcaption {
  display: flex; gap: var(--space-3); align-items: baseline;
  font-family: var(--text-technical);
  font-size: var(--scale-100);
  letter-spacing: 0.06em;
  color: var(--fg-tertiary);
  margin-top: var(--space-3);
}
.spec-figure figcaption .fig-id { color: var(--fg-accent); white-space: nowrap; }

/* light-background screenshots sit on a subtle well so they don't glare */
.spec-figure__frame--light { padding: var(--space-6); background: #F4F5F7; }

.principles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-6);
  list-style: none; padding: 0; margin: var(--space-8) 0;
}
.principle {
  background: var(--bg-raised);
  border: var(--line-1) solid var(--border-hairline);
  border-radius: var(--radius-3);
  padding: var(--space-6);
}
.principle h3 { font-family: var(--text-display); font-weight: 500; font-size: var(--scale-400); margin: 0 0 var(--space-2); }
.principle p { font-size: var(--scale-200); margin: 0; }
.principle__index {
  font-family: var(--text-technical); font-size: var(--scale-100);
  color: var(--fg-accent); display: block; margin-bottom: var(--space-3);
}

.pullquote {
  border-left: 2px solid var(--fg-accent);
  padding-left: var(--space-6);
  margin: var(--space-8) 0;
  font-family: var(--text-display);
  font-size: var(--scale-500);
  font-weight: 500;
  color: var(--fg-primary);
  line-height: 1.4;
  max-width: 32ch;
}

.case-nav {
  display: flex; justify-content: space-between; gap: var(--space-6);
  padding-block: var(--space-12);
}


/* 08 · ABOUT / CONTACT ------------------------------------------------------ */

.how-i-work {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-6);
  list-style: none; padding: 0; margin: var(--space-8) 0;
}

.contact-list { list-style: none; padding: 0; margin: var(--space-8) 0; max-width: 480px; }
.contact-list li {
  display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-4);
  padding: var(--space-4) 0;
  border-bottom: var(--line-1) solid var(--border-hairline);
  margin: 0;
}
.contact-list .label {
  font-family: var(--text-technical); font-size: var(--scale-100);
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--fg-tertiary);
}


/* 09 · TOKEN FOOTER --------------------------------------------------------- */

.site-footer {
  border-top: var(--line-1) solid var(--border-hairline);
  padding: var(--space-16) 0;
  margin-top: var(--space-24);
}

.token-readout {
  font-family: var(--text-technical);
  font-size: var(--scale-100);
  line-height: 1.9;
  color: var(--fg-tertiary);
  background: var(--bg-raised);
  border: var(--line-1) solid var(--border-hairline);
  border-radius: var(--radius-2);
  padding: var(--space-6);
  overflow-x: auto;
  margin: 0 0 var(--space-8);
}
.token-readout .t-name { color: var(--fg-secondary); }
.token-readout .t-value { color: var(--fg-accent); }
.token-readout .t-comment { color: var(--fg-tertiary); }

.site-footer__meta {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-4);
  font-family: var(--text-technical); font-size: var(--scale-100);
  color: var(--fg-tertiary);
}
.site-footer__meta a { color: var(--fg-secondary); text-decoration: none; }
.site-footer__meta a:hover { color: var(--fg-accent); }


/* 10 · GRID OVERLAY (press G) ----------------------------------------------- */

.grid-overlay {
  position: fixed; inset: 0; pointer-events: none; z-index: 200;
  display: none;
  background-image:
    linear-gradient(var(--red-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--red-line) 1px, transparent 1px);
  background-size: 8px 8px;
}
.grid-overlay.is-visible { display: block; }


/* 12 · MODES: DS (dark, default) / GENERALIST (light) ------------------------ */

/* Content that only shows in one mode */
html[data-mode="gen"] .mode-ds { display: none !important; }
html:not([data-mode="gen"]) .mode-gen { display: none !important; }

/* Segmented mode toggle */
.mode-toggle {
  display: inline-flex; align-items: center;
  border: var(--line-1) solid var(--border-strong);
  border-radius: 999px;
  padding: 3px;
  background: var(--bg-raised);
  gap: 2px;
}
.mode-toggle button {
  font-family: var(--text-technical);
  font-size: var(--scale-100);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-secondary);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  transition: background var(--duration-1) var(--ease-out), color var(--duration-1) var(--ease-out);
}
.mode-toggle button[aria-pressed="true"] {
  background: var(--bg-accent);
  color: var(--fg-on-accent);
}
.mode-toggle button:hover:not([aria-pressed="true"]) { color: var(--fg-primary); }

/* Featured toggle band on the home page, between hero and case grid */
.mode-band {
  padding: var(--space-8) 0;
}
.mode-band__inner {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: var(--space-4);
}
.mode-band__label {
  font-family: var(--text-technical);
  font-size: var(--scale-200);
  color: var(--fg-tertiary);
  margin: 0;
}
.mode-band__label .t-name { color: var(--fg-secondary); }

/* Compact toggle in the header */
.mode-toggle--compact button { padding: var(--space-1) var(--space-3); }


/* 13 · CASE CARD THUMBNAILS --------------------------------------------------- */

.case-card__thumb {
  aspect-ratio: 16 / 10;
  border: var(--line-1) solid var(--border-hairline);
  border-radius: var(--radius-2);
  overflow: hidden;
  margin-bottom: var(--space-6);
  background: #F4F5F7; /* screenshots are light — constant well in both modes */
}
.case-card__thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform var(--duration-2) var(--ease-out);
}
.case-card:hover .case-card__thumb img { transform: scale(1.02); }

/* Placeholder for cards awaiting artwork */
.thumb-placeholder {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  background:
    repeating-linear-gradient(-45deg,
      transparent 0, transparent 10px,
      var(--border-hairline) 10px, var(--border-hairline) 11px)
    var(--bg-raised);
}
.thumb-placeholder span {
  font-family: var(--text-technical);
  font-size: var(--scale-100);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-tertiary);
  background: var(--bg-raised);
  border: var(--line-1) solid var(--border-hairline);
  border-radius: var(--radius-1);
  padding: var(--space-1) var(--space-3);
}


/* 14 · CASE STUDY SUB-NAV ------------------------------------------------------
   Desktop (≥1100px): a vertical rail fixed to the left edge, Notion-style —
   tick marks that reveal their labels on hover; the active section's tick
   grows and turns accent red.
   Below 1100px: a horizontal sticky bar under the header. */

/* --- Horizontal bar (default, used below 1100px) --- */
.case-subnav {
  position: sticky;
  top: var(--header-h);
  z-index: 40;
  background: color-mix(in srgb, var(--bg-canvas) 90%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: var(--line-1) solid var(--border-hairline);
}
.case-subnav__inner {
  display: flex; gap: var(--space-6);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  max-width: var(--content-max);
  margin: 0 auto;
  padding-inline: var(--gutter);
}
/* trailing spacer: keeps the last link off the edge even in browsers that
   clip right-padding inside horizontal scrollers */
.case-subnav__inner::after { content: ""; flex: 0 0 1px; }
.case-subnav__inner::-webkit-scrollbar { display: none; }
.case-subnav a {
  font-family: var(--text-technical);
  font-size: var(--scale-100);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-tertiary);
  text-decoration: none;
  padding: var(--space-3) 0;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color var(--duration-1) var(--ease-out);
}
.case-subnav a:hover { color: var(--fg-primary); }
.case-subnav a.is-active { color: var(--fg-accent); border-bottom-color: var(--fg-accent); }

/* Anchored sections stop below the two sticky bars */
.case-section { scroll-margin-top: calc(var(--header-h) + 56px); }

/* --- Vertical rail (≥1100px) --- */
@media (min-width: 1100px) {
  .case-subnav {
    position: fixed;
    top: 50%;
    left: var(--space-6);
    transform: translateY(-50%);
    background: transparent;
    backdrop-filter: none;
    border-bottom: none;
    z-index: 40;
  }
  .case-subnav__inner {
    flex-direction: column;
    gap: var(--space-2);
    overflow: visible;
    max-width: none;
    margin: 0;
    padding-inline: 0;
  }
  .case-subnav__inner::after { display: none; }
  .case-subnav a {
    display: flex; align-items: center; gap: var(--space-3);
    padding: var(--space-1) 0;
    border-bottom: none;
  }
  /* the tick mark */
  .case-subnav a::before {
    content: "";
    width: 16px; height: 2px;
    background: var(--border-strong);
    border-radius: 1px;
    flex-shrink: 0;
    transition: width var(--duration-2) var(--ease-out), background var(--duration-1) var(--ease-out);
  }
  /* labels hidden until the rail is hovered or focused */
  .case-subnav a .subnav-label {
    opacity: 0;
    transform: translateX(-6px);
    transition: opacity var(--duration-2) var(--ease-out), transform var(--duration-2) var(--ease-out);
    background: color-mix(in srgb, var(--bg-canvas) 85%, transparent);
    backdrop-filter: blur(8px);
    padding: 2px var(--space-2);
    border-radius: var(--radius-1);
  }
  .case-subnav:hover a .subnav-label,
  .case-subnav:focus-within a .subnav-label,
  .case-subnav a.is-active .subnav-label {
    opacity: 1;
    transform: translateX(0);
  }
  /* the active label peeks for ~1.6s, then slides out, leaving only ticks.
     Hovering the rail cancels this and shows all labels. */
  .case-subnav:not(:hover):not(:focus-within) a.is-active .subnav-label {
    animation: subnav-label-peek 2.2s var(--ease-out) forwards;
  }
  @keyframes subnav-label-peek {
    0%, 72% { opacity: 1; transform: translateX(0); }
    100%    { opacity: 0; transform: translateX(-6px); }
  }
  .case-subnav a:hover::before { background: var(--fg-secondary); }
  .case-subnav a.is-active::before {
    width: 28px;
    background: var(--fg-accent);
  }
  .case-subnav a.is-active { border-bottom: none; }

  /* no horizontal bar height to clear on desktop */
  .case-section { scroll-margin-top: calc(var(--header-h) + var(--space-4)); }
}


/* 11 · ACCESSIBILITY + MOTION ------------------------------------------------ */



/* 17 · LAYOUT PATTERN LIBRARY --------------------------------------------------
   Reusable case-study layouts. Demo + copy-paste source: work/_layout-template.html
   All patterns are token-driven and work in both modes. */

/* --- Half & half split: copy one side, image the other ---
   .split--flip mirrors it; .split--sticky pins the copy while a tall
   media column scrolls past. */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-12);
  align-items: center;
  margin: var(--space-12) 0;
}
.split .spec-figure { margin: 0; }
.split--flip .split__copy { order: 2; }
.split--sticky { align-items: start; }
.split--sticky .split__copy {
  position: sticky;
  top: calc(var(--header-h) + var(--space-8));
}
.split--sticky .split__media .spec-figure { margin-bottom: var(--space-8); }

/* --- Portrait tile grid: 3 columns of 3:4 images --- */
.grid-portrait {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-6);
  margin: var(--space-12) 0;
}
.grid-portrait .spec-figure { margin: 0; }
.grid-portrait .spec-figure__frame { aspect-ratio: 3 / 4; }
.grid-portrait .spec-figure__frame img { width: 100%; height: 100%; object-fit: cover; }

/* --- Asymmetric split: main content 3/4, aside 1/4 --- */
.aside-split {
  display: grid;
  grid-template-columns: 3fr 1fr;
  gap: var(--space-12);
  align-items: start;
  margin: var(--space-12) 0;
}
.aside-split .spec-figure { margin: 0; }
.aside-note {
  font-family: var(--text-technical);
  font-size: var(--scale-200);
  color: var(--fg-secondary);
  border-left: 2px solid var(--fg-accent);
  padding-left: var(--space-4);
}

/* --- Bento grid: mixed-size tiles on a 4-column base ---
   Modifiers: .bento__item--wide (2 cols), .bento__item--tall (2 rows),
   .bento__item--text (padded text tile) */
.bento {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 180px;
  gap: var(--space-4);
  margin: var(--space-12) 0;
}
.bento__item {
  border: var(--line-1) solid var(--border-hairline);
  border-radius: var(--radius-3);
  overflow: hidden;
  background: var(--bg-raised);
}
.bento__item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bento__item--wide { grid-column: span 2; }
.bento__item--tall { grid-row: span 2; }
.bento__item--text {
  padding: var(--space-6);
  display: flex; flex-direction: column; justify-content: center;
}
.bento__item--text .metric__value { font-size: var(--scale-600); }

/* --- Carousel: scroll-snap track with prev/next buttons ---
   Needs data-carousel on the wrapper; buttons wired in site.js. */
.carousel { position: relative; margin: var(--space-12) 0; }
.carousel__track {
  display: flex;
  gap: var(--space-6);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  padding-bottom: var(--space-2);
}
.carousel__track::-webkit-scrollbar { display: none; }
.carousel__slide {
  flex: 0 0 min(560px, 82%);
  scroll-snap-align: start;
}
.carousel__slide .spec-figure { margin: 0; }
.carousel__btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  z-index: 2;
  width: 40px; height: 40px;
  border-radius: 999px;
  border: var(--line-1) solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--fg-primary);
  font-size: var(--scale-300);
  cursor: pointer;
  display: grid; place-items: center;
  transition: border-color var(--duration-1) var(--ease-out), color var(--duration-1) var(--ease-out);
}
.carousel__btn:hover { border-color: var(--fg-accent); color: var(--fg-accent); }
.carousel__btn--prev { left: calc(-1 * var(--space-2)); }
.carousel__btn--next { right: calc(-1 * var(--space-2)); }

/* --- Pattern library responsive collapse --- */
@media (max-width: 899px) {
  .split, .split--sticky { grid-template-columns: 1fr; gap: var(--space-8); }
  .split--flip .split__copy { order: 0; }
  .split--sticky .split__copy { position: static; }
  .aside-split { grid-template-columns: 1fr; }
  .bento { grid-template-columns: repeat(2, 1fr); grid-auto-rows: 150px; }
}
@media (max-width: 640px) {
  .grid-portrait { grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
}


/* Wider page gutters once the container no longer floats in free margin */
@media (max-width: 1280px) {
  :root { --gutter: 2.5rem; }   /* 40px on tablet */
}
@media (max-width: 640px) {
  :root { --gutter: 1.75rem; }  /* 28px on phones */
}


/* 15 · SCROLLYTELLING SECTION (pinned copy + image steps) ---------------------
   Structure: .scrolly[data-scrolly][style="--steps: N"]
     └ .scrolly__stage  (sticky, fills the viewport while the outer scrolls)
        ├ .scrolly__copy   > .scrolly-step × N
        └ .scrolly__media  > .scrolly-step × N
   JS in site.js maps scroll progress to the current step.
   Below 900px it degrades to a normal stacked one-column layout. */

.scrolly { height: calc(var(--steps, 3) * 85vh); }

.scrolly__stage {
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: var(--space-12);
  align-items: stretch;
}

.scrolly__copy, .scrolly__media { position: relative; }

.scrolly-step {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: center;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity var(--duration-2) var(--ease-out), transform var(--duration-2) var(--ease-out);
  pointer-events: none;
}
.scrolly-step.is-current {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.scrolly-step .step-index {
  font-family: var(--text-technical);
  font-size: var(--scale-100);
  color: var(--fg-accent);
  letter-spacing: 0.1em;
  margin-bottom: var(--space-3);
}
.scrolly-step h3 { margin-top: 0; }
.scrolly__media .spec-figure { margin: 0; }

@media (max-width: 899px) {
  .scrolly { height: auto; }
  .scrolly__stage { position: static; height: auto; display: flex; flex-direction: column; }
  /* interleave: each copy step is followed by its image */
  .scrolly__copy, .scrolly__media { display: contents; }
  .scrolly__copy .scrolly-step:nth-child(1) { order: 1; }
  .scrolly__media .scrolly-step:nth-child(1) { order: 2; }
  .scrolly__copy .scrolly-step:nth-child(2) { order: 3; }
  .scrolly__media .scrolly-step:nth-child(2) { order: 4; }
  .scrolly__copy .scrolly-step:nth-child(3) { order: 5; }
  .scrolly__media .scrolly-step:nth-child(3) { order: 6; }
  .scrolly__copy .scrolly-step:nth-child(4) { order: 7; }
  .scrolly__media .scrolly-step:nth-child(4) { order: 8; }
  .scrolly-step {
    position: static;
    opacity: 1; transform: none; pointer-events: auto;
    margin-bottom: var(--space-12);
  }
}


/* 16 · COLLAPSIBLE TOKEN READOUT ---------------------------------------------- */

.token-details { margin: 0 0 var(--space-8); }
.token-details summary {
  cursor: pointer;
  font-family: var(--text-technical);
  font-size: var(--scale-100);
  letter-spacing: 0.06em;
  color: var(--fg-tertiary);
  list-style: none;
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-1) 0;
  transition: color var(--duration-1) var(--ease-out);
}
.token-details summary::-webkit-details-marker { display: none; }
.token-details summary::before {
  content: "▸";
  color: var(--fg-accent);
  transition: transform var(--duration-1) var(--ease-out);
}
.token-details[open] summary::before { transform: rotate(90deg); }
.token-details summary:hover { color: var(--fg-primary); }
.token-details[open] summary { margin-bottom: var(--space-3); }
.token-details .token-readout { margin-bottom: 0; }


@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

@media (max-width: 720px) {
  :root { --header-h: 96px; } /* header wraps to two rows; sub-navs offset accordingly */
  .site-header__inner {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-h);
    padding-top: var(--space-3);
    row-gap: 0;
  }
  .logo { align-self: center; }
  .nav { width: 100%; justify-content: space-between; gap: var(--space-3); }
  .nav a { font-size: 12px; letter-spacing: 0.06em; }
  .case-subnav a { font-size: 11px; }
}

@media (max-width: 640px) {
  .hero { padding-block: var(--space-16); }
  .section { padding-block: var(--space-16); }
  .metrics { grid-template-columns: 1fr; }
}
