/* Case study pages. Tokens (colours, grid, fonts) come from tokens.css. */

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

/* Plain paper: the case studies have no graph paper behind them (Kevin had it
   taken off, 2026-11-25). The layout is still set on the canvas's grid, 20 and
   100 px (case.js), there are just no lines drawn. */
body {
  font-family: var(--font-sans);
  color: var(--ink);
  background-color: var(--paper);
  -webkit-font-smoothing: antialiased;
}

/* The graph paper, as on the canvas, for a page that asks for it: the 404 page. */
.on-paper {
  background-image:
    linear-gradient(to right, var(--line-major) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line-major) 1px, transparent 1px),
    linear-gradient(to right, var(--line-minor) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line-minor) 1px, transparent 1px);
  background-size:
    var(--grid-major) var(--grid-major),
    var(--grid-major) var(--grid-major),
    var(--grid-minor) var(--grid-minor),
    var(--grid-minor) var(--grid-minor);
  background-position: center top;
}

a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-color: var(--frame-line);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: text-decoration-color 0.2s;
}

a:hover {
  text-decoration-color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

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

/* ── Top bar (same chips as the canvas) ─────────────────── */

.bar {
  position: sticky;
  top: 0;
  z-index: var(--z-ui);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
  font-size: 0.875rem;
}

.bar-chip {
  display: flex;
  gap: 20px;
  padding: 8px 12px;
  border: 1px solid var(--frame-line);
  border-radius: var(--radius);
  background: var(--sheet);
}

.bar-name {
  font-weight: 500;
  text-decoration: none;
}

/* An icon: a moon to switch to dark, a sun to switch to light (set by the script). */
.theme-toggle {
  display: grid;
  place-items: center;
  align-self: center;
  margin: -4px;
  padding: 4px; /* a bigger target than the icon */
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: color 0.2s;
}

.theme-toggle:hover {
  color: var(--accent);
}

.theme-toggle svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Opened in the canvas's overlay (the page sets .is-embedded on <html> when it
   is in a frame): the overlay has its own Close, so the bar goes. */
.is-embedded .bar {
  display: none;
}

/* ── Layout ─────────────────────────────────────────────── */

/* A sticky sidebar with the title, the slides beside it. case.js rounds the
   page width, the grids' columns, the top padding and each slide's height to
   the graph paper; these are the values it starts from. */
.case {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  column-gap: 100px;
  align-items: start;
  width: min(100% - 32px, 1700px);
  margin: 0 auto;
  padding: 48px 0 0;
}

/* Room after the last slide, so the end is not abrupt. It is part of the
   slides' column rather than the page's padding: the sidebar can stay in view
   down to the very end of the page, instead of being pushed up under the top
   bar over the last stretch. */
.case-body {
  padding-bottom: 240px;
}

/* the only text: a title, one paragraph of context, a few facts and the way out */
.case-head {
  position: sticky;
  top: 76px; /* below the top bar */
}

.is-embedded .case-head {
  top: 32px; /* no top bar in the canvas overlay */
}

.case-head h1 {
  font-size: clamp(2.5rem, 1.8rem + 1.6vw, 3.5rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.045em;
}

.case-lede {
  margin-top: 20px;
  font-size: clamp(1.0625rem, 1rem + 0.25vw, 1.1875rem);
  line-height: 1.4;
  letter-spacing: -0.01em;
  text-wrap: pretty;
}

.case-facts {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 28px;
  font-size: 0.9375rem;
}

.case-facts dt {
  color: var(--ink-soft);
}

.case-facts dd {
  margin-top: 2px;
  font-weight: 500;
}

/* ── Slides: one after another, a steady gap between them ── */

.shot {
  display: flex;
  flex-direction: column;
  margin-top: 20px;
  overflow: hidden;
  border: 1px solid var(--frame-line);
  border-radius: var(--radius);
  background: var(--sheet);
  box-shadow: var(--shadow);
}

.case-body > .shot:first-child,
.case-body > .shots:first-child {
  margin-top: 0;
}

/* Whatever height a slide is rounded to, its content fills it: a picture or
   film is cropped a little at the edges (object-fit), a backdrop (.stage)
   grows and keeps its content centred. */
.shot > img,
.shot > video,
.shot > svg {
  display: block;
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: cover;
}

.shot > .stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.shot figcaption {
  padding: 10px 14px;
  border-top: 1px solid var(--frame-line);
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.shots {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  align-items: start;
  gap: 20px;
  margin-top: 20px;
}

.shots .shot {
  margin-top: 0;
}

/* ── The way out ────────────────────────────────────────── */

.case-end {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 32px;
}

.button {
  display: inline-block;
  padding: 10px 16px;
  border: 1px solid var(--frame-line);
  border-radius: var(--radius);
  background: var(--sheet);
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
  transition: translate 0.2s var(--ease-out), transform 0.2s var(--ease-out), box-shadow 0.2s, background-color 0.2s, border-color 0.2s;
}

.button-primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

/* Under the pointer a button lifts a pixel off the page, onto a shadow, and
   changes shade (tokens.css); pressed, it goes back down. */
@media (hover: hover) {
  .button:hover {
    translate: 0 -1px;
    border-color: var(--line-hover);
    background: var(--sheet-hover);
    box-shadow: var(--shadow);
  }

  .button-primary:hover {
    border-color: var(--ink-hover);
    background: var(--ink-hover);
  }
}

.button:active {
  translate: none;
  transform: scale(0.98);
  box-shadow: none;
}

/* A button that lifts must not leave the pointer: resting on its bottom edge,
   the pointer lost the button as it rose, the button dropped back under it,
   and so on, a flicker. So it reaches a little further down than it shows
   (the same as the canvas's buttons, styles.css). */
.button {
  position: relative;
}

.button::after {
  content: "";
  position: absolute;
  inset: 0 0 -3px; /* from the padding edge: the border, the pixel it lifts, and one to spare */
}

/* ── Short windows: the sidebar stays in view, so all of it has to fit
   between the top bar and the bottom of the window. In a window under about
   830 px tall its type and gaps ease down with the window's height; taller
   windows are untouched. Where it still doesn't fit (case.js checks), it
   scrolls with the page instead of sitting cut off at the bottom. ── */

@media (min-width: 1200px) {
  .case-head h1 {
    font-size: min(clamp(2.5rem, 1.8rem + 1.6vw, 3.5rem), max(2rem, 6.2vh));
  }

  .case-lede {
    margin-top: min(20px, 2.4vh);
    font-size: min(clamp(1.0625rem, 1rem + 0.25vw, 1.1875rem), max(0.875rem, 2.3vh));
  }

  .case-facts {
    gap: min(14px, 1.7vh);
    margin-top: min(28px, 3.4vh);
  }

  .case-end {
    margin-top: min(32px, 3.9vh);
  }

  .case-head.is-loose {
    position: static;
  }
}

/* ── Below 1200 px: no sidebar. The header sits above the slides in two
   columns: the title, the paragraph and the way out on the left, the facts
   on the right. ── */

@media (max-width: 1199px) {
  .case {
    grid-template-columns: minmax(0, 1fr);
    width: min(100% - 32px, 1100px);
    padding-top: 40px;
  }

  .case-head {
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    grid-template-areas:
      "title facts"
      "lede facts"
      "end facts";
    grid-template-rows: auto auto 1fr;
    column-gap: 100px;
  }

  .case-head h1 {
    grid-area: title;
  }

  .case-lede {
    grid-area: lede;
    max-width: 62ch;
  }

  .case-end {
    grid-area: end;
    align-self: start;
  }

  .case-facts {
    grid-area: facts;
    margin-top: 0;
    padding-top: 6px; /* level with the title's cap height */
  }

  .case-body {
    margin-top: 60px;
  }
}

/* Phones: the facts go under the paragraph, side by side. */
@media (max-width: 699px) {
  .case-head {
    display: block;
  }

  .case-facts {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px 40px;
    margin-top: 28px;
    padding-top: 0;
  }

  .case-body {
    margin-top: 32px;
  }
}

@media (max-width: 699px) {
  .shots {
    grid-template-columns: 1fr;
  }
}

/* Phones: less room after the last slide. */
@media (max-width: 699px) {
  .case-body {
    padding-bottom: 120px;
  }
}

/* Phones: the page is set on the grid the list's graph paper has there
   (tokens.css): an even number of squares between the same 16 px margins, so
   the slides are as wide as the list's cards. The gaps between slides are one
   square; case.js rounds the heights to whole squares. (No lines are drawn on
   a case study; a page on paper gets the fitted paper.) */
@media (max-width: 699px) {
  .on-paper {
    background-image: var(--paper-image);
    background-size: var(--paper-size);
    background-position: var(--paper-position);
  }

  .case {
    width: calc(100% - 2 * var(--page-pad));
  }

  .shot,
  .shots {
    margin-top: var(--grid-y);
  }

  .shots {
    gap: var(--grid-y);
  }

  /* Above the title. case.js moves it by up to half a square either way, to put
     the first slide on a line. In the canvas's overlay the sheet has just risen
     into view, with no top bar above the title to clear: a third less. */
  .case {
    padding-top: 50px;
  }

  .is-embedded .case {
    padding-top: 33px;
  }
}

@media (prefers-reduced-motion: reduce) {
  a,
  .button,
  .theme-toggle {
    transition: none;
  }
}
