/* ==========================================================================
   Components: case study (and later, home).
   Values come from tokens.css. Component breakpoints use container queries
   on .case, so they respond to the content column's width, not the window.
   ========================================================================== */

/* --- Case study frame --------------------------------------------------- */

.case {
  container: case / inline-size;
  font-size: var(--text-prose);
}

.case-hero,
.case-section,
.next-case {
  padding: calc(var(--section-space) / 2) var(--cell-pad);
}

/* Section divider: one line from the rail's edge to the window's right
   edge (past the content column). Drawn as a single element so it can't
   misalign; .site clips the overflow, so the page never scrolls sideways. */
.case-section,
.next-case {
  position: relative;
}

.case-section::before,
.next-case::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  border-top: var(--hairline);
  pointer-events: none;
}

.case-hero {
  padding-top: var(--space-7);
}

/* Title fills the content column: no character cap, and plain wrapping
   (not balanced or "pretty") so the first line runs as far as it can. */
.case-hero h1 {
  text-wrap: wrap;
}

/* Title block (H1 + dek), closed by a divider that runs from the rail's edge
   to the window's right edge, like the section dividers. */
.case-hero__head {
  position: relative;
  padding-bottom: var(--space-7);
}

.case-hero__head::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: calc(-1 * var(--cell-pad));
  width: 100vw;
  border-top: var(--hairline);
  pointer-events: none;
}

.case-hero__head + .meta-bar {
  margin-top: var(--space-7);
}

.case-dek {
  max-width: var(--measure);
  margin-top: var(--space-4);
  font-size: var(--text-quote);
  line-height: var(--leading-quote);
  color: var(--ink-2);
}

/* Eyebrow, then headline */
.section-head {
  max-width: var(--measure);
  margin-bottom: var(--space-6);
}

.section-head > .eyebrow + h2 {
  margin-top: var(--space-3);
}

/* Vertical rhythm inside a section */
.flow > * + * {
  margin-top: var(--flow-space, var(--space-6));
}

.flow > h3 {
  --flow-space: var(--space-7);
}

.flow > h3 + * {
  --flow-space: var(--space-4);
}

.prose ul,
.prose ol,
ul.list,
ol.list {
  padding-left: 1.25em;
}

.prose li + li,
.list li + li {
  margin-top: var(--space-2);
}

/* "+" marker in place of the draft's typed ">". Drawn as text at the same
   size and line height as the item, so it sits exactly on the first line.
   The "/ ''" part keeps screen readers from reading "plus". */
.prose ul,
ul.list {
  list-style: none;
  padding-left: 1em;
}

.prose ul > li,
ul.list > li {
  position: relative;
}

.prose ul > li::before,
ul.list > li::before {
  content: "+";
  content: "+" / "";
  position: absolute;
  left: -1em;
}

.prose ul ul {
  margin-top: var(--space-2);
}

.prose ul ul > li::before {
  content: "–";
  content: "–" / "";
}

/* A ruled grid: every line is a real border, so thin lines render at the
   same weight everywhere (fractional gaps blur; borders snap to pixels).
   The grid draws its top and left edges; each cell draws its right and
   bottom edges. Works for full rows, which is every current use. */
.ruled-grid {
  display: grid;
  border-top: var(--hairline);
  border-left: var(--hairline);
}

.ruled-grid > * {
  padding: var(--space-5);
  border-right: var(--hairline);
  border-bottom: var(--hairline);
}

/* --- Meta bar ----------------------------------------------------------- */

.meta-bar {
  margin-top: var(--space-7);
  grid-template-columns: 1fr;
  font-size: var(--text-body);
}

.meta-bar dt {
  margin-bottom: var(--space-1);
}

@container case (min-width: 40rem) {
  .meta-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* --- Figure ------------------------------------------------------------- */

/* Figures end where the text ends: same measure as .prose (both inherit
   the case study's prose font size, so 68ch matches). */
.figure {
  max-width: var(--measure);
  margin-top: var(--space-7);
}

.figure__frame {
  display: grid;
  place-items: center;
  padding: var(--space-3);
  background: var(--panel);
}

.figure__frame img {
  width: 100%;
  max-width: var(--figure-max);
}

.figure figcaption {
  max-width: var(--measure);
  margin-top: var(--space-3);
}

/* Phones only: diagram text is too small to read at this width, so offer
   the full-size file, where pinch-zoom works. */
.figure__zoom {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-target);
}

@container case (min-width: 40rem) {
  .figure__zoom {
    display: none;
  }
}

.figure--hero .figure__frame {
  aspect-ratio: var(--hero-ratio);
}

.figure--hero .figure__frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@container case (min-width: 40rem) {
  .figure__frame {
    padding: var(--space-5);
  }
}

@container case (min-width: 48rem) {
  .figure__frame {
    padding: var(--space-6);
  }
}

/* Three-up screenshot slot */
.figure__grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
}

.figure__grid > * {
  display: grid;
  place-items: center;
  aspect-ratio: var(--thumb-ratio);
  padding: var(--space-4);
  background: var(--panel);
  text-align: center;
}

/* A screenshot in the slot: the whole image on the panel, linked to its full size */
.figure__grid > .figure__shot {
  display: block;
  aspect-ratio: auto;
  padding: var(--space-3);
}

.figure__shot img {
  width: 100%;
  height: auto;
}

@container case (min-width: 40rem) {
  .figure__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Optional aside that holds a secondary figure */
.aside-details {
  max-width: var(--measure);
  margin-top: var(--space-5);
  border-block: var(--hairline);
}

.aside-details > summary,
.minor-bets > summary,
.collapse > summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap-target);
  cursor: pointer;
  list-style: none;
}

.aside-details > summary::-webkit-details-marker,
.minor-bets > summary::-webkit-details-marker,
.collapse > summary::-webkit-details-marker {
  display: none;
}

/* Plus that turns into a minus, drawn with gradients (no text to announce) */
.aside-details > summary::before,
.minor-bets > summary::before,
.collapse > summary::before {
  content: "";
  flex: none;
  width: 0.75rem;
  height: 0.75rem;
  background:
    linear-gradient(currentColor, currentColor) center / 100% var(--stroke) no-repeat,
    linear-gradient(currentColor, currentColor) center / var(--stroke) 100% no-repeat;
}

.aside-details[open] > summary::before,
.minor-bets[open] > summary::before,
.collapse[open] > summary::before {
  background: linear-gradient(currentColor, currentColor) center / 100% var(--stroke) no-repeat;
}

.aside-details > .figure {
  margin-top: var(--space-2);
  margin-bottom: var(--space-5);
}

/* --- Quotes ------------------------------------------------------------- */

.pull-quote {
  max-width: var(--measure);
  padding-left: var(--space-5);
  border-left: var(--quote-rule);
}

.pull-quote blockquote,
.pull-statement {
  font-family: var(--font-display);
  font-size: var(--text-quote);
  line-height: var(--leading-quote);
}

.pull-quote figcaption,
.quote figcaption {
  margin-top: var(--space-3);
}

/* A statement set large, without quote semantics (it isn't anyone's words) */
.pull-statement {
  max-width: var(--measure);
}

/* Inline quote set: same markup as the pull quote, at body size */
.quote-set > * + * {
  margin-top: var(--space-5);
}

.quote {
  padding-left: var(--space-4);
  border-left: var(--hairline);
}

/* --- Claim cards -------------------------------------------------------- */

.claims {
  grid-template-columns: 1fr;
}

.claims strong {
  display: block;
  margin-bottom: var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-h3);
  line-height: var(--leading-h3);
}

@container case (min-width: 40rem) {
  .claims {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* --- Two groups side by side (scope decisions / constraints) ------------ */

.split {
  display: grid;
  gap: var(--space-6);
  grid-template-columns: 1fr;
}

.split > * > * + * {
  margin-top: var(--space-4);
}

@container case (min-width: 48rem) {
  .split {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-7);
  }
}

/* --- Callout box -------------------------------------------------------- */

.callout {
  max-width: var(--measure);
  padding: var(--space-5);
  border: var(--border-strong);
}

.callout > .eyebrow {
  margin-bottom: var(--space-3);
}

/* --- Bet cards ---------------------------------------------------------- */

.bets {
  grid-template-columns: 1fr;
}

.bet > * + * {
  margin-top: var(--space-3);
}

.bet__wrong {
  padding-top: var(--space-3);
  border-top: var(--hairline);
  font-style: italic;
}

@container case (min-width: 40rem) {
  .bets {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* --- Gap list ----------------------------------------------------------- */

.gap-list {
  max-width: var(--measure);
}

.gap-list > li {
  padding-block: var(--space-4);
  border-top: var(--hairline);
}

.gap-list > li:last-child {
  border-bottom: var(--hairline);
}

/* Collapsible on small screens only; main.js closes it there. */
.collapse > summary {
  border-top: var(--hairline);
}

@container case (min-width: 40rem) {
  .collapse > summary {
    display: none;
  }
}

/* --- Hypothesis chain cards --------------------------------------------- */

.chains {
  display: grid;
  gap: var(--space-5);
  grid-template-columns: 1fr;
}

.chain,
.minor-bets {
  border: var(--hairline);
  padding: var(--space-5);
}

.chain > h4 {
  margin-bottom: var(--space-4);
}

.chain__steps > li {
  position: relative;
  padding: var(--space-4);
  background: var(--panel);
}

.chain__steps > li + li {
  margin-top: var(--space-7);
}

/* Decorative arrow between steps: a line and a chevron, no text content */
.chain__steps > li + li::before,
.chain__steps > li + li::after {
  content: "";
  position: absolute;
  left: var(--space-5);
}

.chain__steps > li + li::before {
  bottom: calc(100% + var(--space-2));
  height: calc(var(--space-7) - var(--space-4));
  border-left: var(--stroke) solid var(--ink-2);
}

.chain__steps > li + li::after {
  bottom: calc(100% + var(--space-2));
  width: 0.5rem;
  height: 0.5rem;
  margin-left: calc(-0.25rem + var(--stroke) / 2);
  border-right: var(--stroke) solid var(--ink-2);
  border-bottom: var(--stroke) solid var(--ink-2);
  transform: rotate(45deg);
}

.chain__label {
  display: block;
  margin-bottom: var(--space-1);
}

.chain__steps ol {
  margin-top: var(--space-2);
  padding-left: 1.5em;
}

.chain__steps ol > li + li {
  margin-top: var(--space-2);
}

.minor-bets {
  margin-top: var(--space-5);
}

.minor-bets > ul {
  margin-top: var(--space-3);
}

@container case (min-width: 56rem) {
  .chains {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* --- Verdict chip ------------------------------------------------------- */

.verdict {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border: var(--border-strong);
  font-size: var(--text-small);
  line-height: var(--leading-small);
  white-space: nowrap;
}

.verdict__icon {
  font-size: var(--text-body);
  line-height: 1;
}

/* --- Findings card ------------------------------------------------------ */

.finding {
  border: var(--hairline);
}

.finding > * {
  padding: var(--space-5);
}

.finding > * + * {
  border-top: var(--hairline);
}

.finding__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.finding__body {
  display: grid;
  gap: var(--space-6);
  grid-template-columns: 1fr;
}

.finding__body > .prose {
  font-size: inherit;
}

.finding__built {
  font-size: var(--text-body);
}

@container case (min-width: 40rem) {
  .finding__body {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    gap: var(--space-7);
  }
}

/* --- Verdict table ------------------------------------------------------ */

.table-scroll {
  overflow-x: auto;
  border: var(--hairline);
}

.verdict-table {
  width: 100%;
  min-width: var(--table-min);
  border-collapse: collapse;
  font-size: var(--text-body);
  text-align: left;
}

.verdict-table th,
.verdict-table td {
  padding: var(--space-3) var(--space-4);
  vertical-align: top;
  border-bottom: var(--hairline);
}

.verdict-table tr:last-child > * {
  border-bottom: 0;
}

.verdict-table thead th {
  font-weight: var(--weight-regular);
}

.verdict-table tbody th {
  font-weight: var(--weight-regular);
  width: 34%;
}

.verdict-table td:nth-child(2) {
  width: 1%;
}

/* --- Next case study ---------------------------------------------------- */

.next-case > * + * {
  margin-top: var(--space-3);
}

/* ==========================================================================
   Home
   ========================================================================== */

.home {
  container: home / inline-size;
}

/* --- Project row ---------------------------------------------------------
   Text cell and image cell, ruled like a spec sheet. A linked row uses a
   stretched link: one <a> on the title whose ::after covers the whole row. */

.project {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
}

/* Row line: a real element (not a border) so it can drop off the page during
   the page transition. It runs from the window's left edge, across the rail,
   to the right edge, like the draft. .site clips the overflow. */
.project__rule {
  position: absolute;
  right: 0;
  bottom: 0;
  width: calc(100% + 100vw);
  border-bottom: var(--hairline);
  pointer-events: none;
  view-transition-class: grid-rule;
}

.project:nth-of-type(1) .project__rule { view-transition-name: grid-rule-1; }
.project:nth-of-type(2) .project__rule { view-transition-name: grid-rule-2; }
.project:nth-of-type(3) .project__rule { view-transition-name: grid-rule-3; }
.project:nth-of-type(4) .project__rule { view-transition-name: grid-rule-4; }
.project:nth-of-type(5) .project__rule { view-transition-name: grid-rule-5; }
.project:nth-of-type(6) .project__rule { view-transition-name: grid-rule-6; }
.project:nth-of-type(7) .project__rule { view-transition-name: grid-rule-7; }
.project:nth-of-type(8) .project__rule { view-transition-name: grid-rule-8; }
.project:nth-of-type(9) .project__rule { view-transition-name: grid-rule-9; }
.project:nth-of-type(10) .project__rule { view-transition-name: grid-rule-10; }

.project__text {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--cell-pad);
}

.project__title {
  font-family: var(--font-display);
  font-size: var(--text-h2);
  line-height: var(--leading-h2);
}

.project__link {
  text-decoration: none;
}

.project__link::after {
  content: "";
  position: absolute;
  inset: 0;
}

/* Focus ring goes around the whole row, not just the title text */
.project__link:focus-visible {
  outline: none;
}

.project__link:focus-visible::after {
  outline: var(--focus-ring);
  outline-offset: calc(-1 * var(--space-1));
}

/* Label (company · years) sits close above the title */
.project__head {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* Small outlined label, e.g. "Coming soon". Opaque, so it reads cleanly over
   a placeholder image. */
.badge {
  display: inline-block;
  background: var(--bg);
  padding: 0 var(--space-2);
  border: var(--hairline);
  color: var(--ink);
}

.project__desc {
  max-width: var(--measure);
}

.project__problems > .eyebrow {
  margin-bottom: var(--space-2);
}

/* No extra gap between bullets: they read as evenly spaced lines */
.project__problems .list li + li {
  margin-top: 0;
}

/* Tags line. Sits at the bottom of the text cell, with a little more room
   above it (16px gap + 8px) so it reads as apart from the bullets, matching the
   visual space under the title. Each tag is a list item; shown as one
   comma-separated line. */
.project__meta {
  margin-top: auto;
}

ul.project__tags {
  padding: var(--space-2) 0 0;
  list-style: none;
}

.project__tags li {
  display: inline;
}

.project__tags li:not(:last-child)::after {
  content: ", ";
}

.project__media {
  padding: var(--cell-pad);
  padding-top: 0;
}

.project__frame,
.about__frame {
  display: grid;
  place-items: center;
  padding: var(--space-5);
  background: var(--panel);
  text-align: center;
}

.project__frame {
  aspect-ratio: var(--thumb-ratio);
}

/* With an image: no panel, no padding. The image sits on the page at the
   cell's full width; the panel and 16:10 box remain only for placeholders. */
.project__frame:has(img) {
  display: block;
  aspect-ratio: auto;
  padding: 0;
  background: none;
}

.project__frame img {
  width: 100%;
  height: auto;
}

/* Decorative screen inside a "Coming soon" panel: anchored top-right with
   room around it (35px top, 25px right; half that on phones), filling the rest of the panel and
   cropping from its left and bottom edges (where the image is already cut
   off), so it works at any frame shape. The badge sits on top. */
.project__frame:has(.project__inset) {
  position: relative;
  overflow: hidden;
}

.project__inset {
  position: absolute;
  inset: var(--placeholder-inset-top-phone) var(--placeholder-inset-right-phone) 0 0;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: right top;
  pointer-events: none;
}

.project__frame .badge {
  position: relative;
}

/* Thin stroke drawn around an image whose own stroke was cropped off (so the
   stroke survives the cropping below). Color comes from the data file. */
.project__frame--stroke {
  position: relative;
}

.project__frame--stroke::after {
  content: "";
  position: absolute;
  inset: 0;
  border: var(--rule-width) solid var(--image-stroke);
  pointer-events: none;
}

@container home (min-width: 40rem) {
  .project__inset {
    inset: var(--placeholder-inset-top) var(--placeholder-inset-right) 0 0;
  }

  .project {
    grid-template-columns: minmax(var(--project-text-min), var(--project-text)) minmax(0, var(--project-media));
  }

  .project__media {
    display: flex;
    flex-direction: column;
    padding-top: var(--cell-pad);
    border-left: var(--hairline);
  }

  /* Side by side, the image (or placeholder) fills the cell's full height,
     cropping equally from both sides when the cell is narrower than the image.
     The image is taken out of the flow so the text cell sets the row height. */
  .project__frame,
  .project__frame:has(img) {
    position: relative;
    flex: 1;
    aspect-ratio: auto;
  }

  .project__frame img {
    position: absolute;
    inset: 0;
    height: 100%;
    object-fit: cover;
    object-position: var(--image-align, center) center;
  }
}

/* --- About ------------------------------------------------------------- */

.about {
  display: grid;
  grid-template-columns: 1fr;
}

.about__portrait,
.about__bio {
  padding: var(--cell-pad);
}

.about__portrait {
  padding-bottom: 0;
}

.about__frame {
  aspect-ratio: var(--portrait-ratio);
  max-width: var(--portrait-max);
}

/* A photo fills its frame edge to edge (the padding is for placeholders) */
.about__frame:has(img) {
  padding: 0;
}

.about__frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* About blurb: labeled parts, each label a small subhead in the eyebrow
   style (like "Design problems"; the accent font applies when it is on) */
.about__part + .about__part {
  margin-top: var(--space-5);
}

.about__label {
  margin: 0 0 var(--space-2);
  font-weight: var(--weight-regular);
}

.about__part > p:not(.about__label) {
  margin: 0;
}

.about__bio > .eyebrow {
  margin-bottom: var(--space-4);
}

@container home (min-width: 40rem) {
  .about {
    grid-template-columns: minmax(var(--project-text-min), var(--project-text)) minmax(0, var(--project-media));
  }

  .about__portrait {
    padding-bottom: var(--cell-pad);
  }

  .about__bio {
    border-left: var(--hairline);
  }
}
