/*
  The Capsule theme, applied (design/capsule/README.md has the rules, tokens.css the values). One material
  everywhere on the Capsule pages, the start screen, the fall, the wall, an open sheet and All moments:
  - no boxes behind type: type glows on the scene, held to 4.5:1 by a black halo (--cap-halo);
  - edges are lines of light you can see through (--cap-pass, --cap-ring), lit under the pointer and in focus;
  - colour comes only from the decades (--cap-1950s … --cap-2020s);
  - haze (--cap-haze) only where running text sits over the scene; it darkens, it never tints.
  Its own layer, after the site's `app` layer, so it is the last word on these pages without a specificity race.
  The splat walls (capsule-wall.css, splat-wall.js) keep their light; the dive and the wormhole are not styled here.
*/
@layer capsule {
  :root[data-home="capsule"] {
    color-scheme: dark;
    accent-color: var(--cap-ink);
  }

  :root[data-home="capsule"] ::selection {
    color: var(--cap-ink);
    background: color-mix(in oklab, var(--cap-ink) 24%, transparent);
  }

  /* ══ Controls: text and an icon, no container. A line of light comes up under them on hover; focus is a ring ══ */
  :root[data-home="capsule"] :is(.bar, .controls, .wall-end, .open-head, .years, .copy) :is(.button, .icon-button, .switch) {
    --c-ground: transparent;
    --c-ink: var(--cap-ink);
    position: relative;
    min-block-size: var(--control);
    margin: 0;
    padding-inline: var(--space-3);
    font: var(--cap-type-control);
    color: var(--cap-ink-soft);
    text-shadow: var(--cap-halo);
    background: none;
    border: 0;
    border-radius: var(--cap-r1);
    box-shadow: none;
    translate: none;
    transition: color var(--t-press) var(--ease-press), scale var(--t-press) var(--ease-press);
  }

  :root[data-home="capsule"] :is(.bar, .controls, .wall-end, .open-head, .years, .copy) :is(.button, .icon-button, .switch)::after {
    position: absolute;
    inset: auto var(--space-2) var(--space-1);
    block-size: var(--line);
    content: "";
    background: var(--cap-pass-lit);
    opacity: 0;
    scale: 0.6 1;
    transition: opacity var(--t-quick) var(--ease-arrive), scale var(--t-quick) var(--ease-arrive);
    pointer-events: none;
  }

  :root[data-home="capsule"] :is(.bar, .controls, .wall-end, .open-head, .years, .copy) :is(.button, .icon-button, .switch):is(:hover, [data-state~="hover"]):not([aria-disabled="true"]) {
    color: var(--cap-ink);
    background: none;
    border: 0;
    padding-inline: var(--space-3);
    text-decoration: none;
  }

  :root[data-home="capsule"] :is(.bar, .controls, .wall-end, .open-head, .years, .copy) :is(.button, .icon-button, .switch):is(:hover, [data-state~="hover"]):not([aria-disabled="true"])::after {
    opacity: 1;
    scale: 1 1;
  }

  :root[data-home="capsule"] :is(.bar, .controls, .wall-end, .open-head, .years, .copy) :is(.button, .icon-button, .switch):is(:active, [data-state~="pressed"]):not([aria-disabled="true"]) {
    color: var(--cap-ink);
    background: none;
    translate: none;
    scale: 0.96;
  }

  :root[data-home="capsule"] :is(.bar, .controls, .wall-end, .open-head, .years, .copy) :is(.button, .icon-button):focus-visible,
  :root[data-home="capsule"] :is(.bar, .controls, .wall-end, .open-head) .switch:has(input:focus-visible) {
    color: var(--cap-ink);
    background: none;
    outline: var(--line-strong) solid var(--cap-ink);
    outline-offset: var(--focus-offset);
  }

  :root[data-home="capsule"] .icon-button {
    padding-inline: 0;
  }

  /* over the moving scene or a photo (the fall, an open sheet) soft ink is not enough: controls are in full ink */
  :root[data-home="capsule"] :is(.controls, .open-head) :is(.button, .icon-button, .switch) {
    color: var(--cap-ink);
  }

  /* Sound: on is said in words and lit, never turned over into a white block */
  :root[data-home="capsule"] .switch:has(input:checked) {
    color: var(--cap-ink);
    background: none;
  }

  /* on: the same lit line as any control under the pointer, held (the words and the moving bars say "on") */
  :root[data-home="capsule"] .switch:has(input:checked)::after {
    opacity: 1;
    scale: 1 1;
  }

  :root[data-home="capsule"] .switch:has(input:checked):hover {
    color: var(--cap-ink);
    background: none;
  }

  :root[data-home="capsule"] [aria-disabled="true"] {
    opacity: 0.4;
  }

  /* links: ink, a line of light under them that lights up */
  :root[data-home="capsule"] :is(.present, .bar, .home-pop, .choices, .open-sheet, .years) .link {
    color: var(--cap-ink);
    text-shadow: var(--cap-halo);
    text-decoration: none;
    background: var(--cap-pass) 0 100% / 100% var(--line) no-repeat;
    transition: background-size var(--t-quick) var(--ease-arrive);
  }

  :root[data-home="capsule"] :is(.present, .bar, .home-pop, .choices, .open-sheet, .years) .link:hover {
    background-image: var(--cap-pass-lit);
    text-decoration: none;
  }

  :root[data-home="capsule"] :is(.present, .bar, .home-pop, .choices, .open-sheet, .years) .link:focus-visible {
    outline: var(--line-strong) solid var(--cap-ink);
    outline-offset: var(--focus-offset);
    border-radius: var(--line-strong);
  }

  /* ══ The bar: no capsule round it. Its groups on one line over the black, a line of light along its foot ══ */
  /* every item on one centre line: each word in the bar is trimmed to its capitals (text-box), so the centre of
     the bar is the centre of every word; two sizes only, 13 for a label and 14 for a value or a control */
  :root[data-home="capsule"] body[data-phase="ask"] .bar {
    inset: 0 0 auto;
    align-items: center;
    gap: var(--space-2);
    block-size: var(--cap-bar);
    /* (the end's controls carry their own --space-3 inside, so their words end on the margin too) */
    padding: env(safe-area-inset-top) max(calc(var(--cap-margin) - var(--space-3)), env(safe-area-inset-right)) 0 max(var(--cap-margin), env(safe-area-inset-left));
  }

  :root[data-home="capsule"] body .bar {
    color: var(--cap-ink);
    background: var(--cap-pass) 0 100% / 100% var(--line) no-repeat;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  /* over a wall the sheets scroll under it: a dusk falls from the top, under the same line (no box, no tint) */
  :root[data-home="capsule"] body:not([data-phase="ask"]) .bar {
    background:
      var(--cap-pass) 0 100% / 100% var(--line) no-repeat,
      linear-gradient(var(--cap-ground), color-mix(in oklab, var(--cap-ground) 88%, transparent) 72%, color-mix(in oklab, var(--cap-ground) 70%, transparent));
    -webkit-backdrop-filter: var(--cap-haze-blur);
    backdrop-filter: var(--cap-haze-blur);
  }

  :root[data-home="capsule"] body[data-phase="ask"] .bar :is(.bar-name, .stat-label, .stat-note, [data-newest], .button > .label, .switch .words) {
    line-height: 1;
    text-box: trim-both cap alphabetic;
  }

  :root[data-home="capsule"] .bar :is(.bar-name, .bar-home .mark) {
    font: var(--cap-type-mark);
    letter-spacing: var(--track-field);
    color: var(--cap-ink);
    text-shadow: var(--cap-halo);
  }

  :root[data-home="capsule"] .bar .stat-label,
  :root[data-home="capsule"] .bar .stat-note,
  :root[data-home="capsule"] .bar .cell-label {
    font: var(--cap-type-meta);
    letter-spacing: var(--cap-track-meta);
    color: var(--cap-ink-faint);
  }

  /* a figure is a value like any other: the control size, tabular, in ink; its label is the meta size */
  :root[data-home="capsule"] .bar :is(.stats, .stat, .stat-answer) {
    align-items: center;
    align-self: center;
  }

  :root[data-home="capsule"] body .bar > .stats {
    gap: var(--cap-gap);
    margin: 0 var(--space-3) 0 0;
  }

  :root[data-home="capsule"] .bar .stat {
    gap: var(--space-2);
  }

  :root[data-home="capsule"] .bar [data-stat="total"] .odometer,
  :root[data-home="capsule"] .bar [data-newest] {
    font: var(--cap-type-control);
    font-variant-numeric: tabular-nums;
    color: var(--cap-ink);
    text-shadow: var(--cap-halo);
  }

  /* the odometer's digits are columns a line tall (they roll), so they can't be trimmed: their box is cut to the
     capitals instead, the digit set where the trimmed words' capitals are */
  :root[data-home="capsule"] .bar [data-stat="total"] .odometer {
    line-height: 1;
  }

  :root[data-home="capsule"] .bar [data-stat="total"] .odo {
    align-items: start;
    block-size: 0.72em;
  }

  :root[data-home="capsule"] .bar [data-stat="total"] .odo-digit {
    block-size: 0.72em;
  }

  :root[data-home="capsule"] .bar [data-stat="total"] .odo-strip {
    translate: 0 calc(var(--d) * -1em - 0.14em);
  }

  /* the comma keeps its tail below the line */
  :root[data-home="capsule"] .bar [data-stat="total"] .odo-sep {
    line-height: 1;
    translate: 0 -0.14em;
  }

  /* the masthead's groups, parted by a short line of light instead of a rule the bar's full height */
  :root[data-home="capsule"] .bar :is(.dateline, nav, .switch) {
    border-inline-start: 0;
    background: none;
  }

  :root[data-home="capsule"] .bar .dateline .cell-answer {
    color: var(--cap-ink);
  }

  :root[data-home="capsule"] body .bar > .switch {
    margin-inline-start: var(--space-2);
  }

  /* ══ The command bar: a ring of light round the field; nothing fills it ══ */
  :root[data-home="capsule"] .field::before {
    padding: var(--line);
    background: var(--cap-ring);
    border: 0;
    border-radius: var(--cap-r3);
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    /* only the ring: the box's inside is cut out of it */
    mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
    transition: opacity var(--t-quick) var(--ease-arrive);
  }

  :root[data-home="capsule"] .field:has(.field-input:is(:hover, :focus-visible))::before {
    background: linear-gradient(160deg, var(--cap-ink), var(--cap-edge-lit) 40%, var(--cap-edge-lit));
  }

  :root[data-home="capsule"] :is(.field-input, .field-example, .field-prompt) {
    text-shadow: var(--cap-halo);
  }

  :root[data-home="capsule"] .field-input {
    font: var(--cap-type-field);
    color: var(--cap-ink);
    caret-color: var(--cap-ink);
  }

  :root[data-home="capsule"] .field-prompt {
    font: var(--cap-type-meta);
    letter-spacing: var(--cap-track-meta);
    color: var(--cap-ink-soft);
  }

  :root[data-home="capsule"] .field-example {
    color: var(--cap-ink-faint);
  }

  /* the selection after a wall is gone (paper.js no longer selects the name); one you make is a faint wash */
  :root[data-home="capsule"] .field-input::selection {
    color: var(--cap-ink);
    background: color-mix(in oklab, var(--cap-ink) 22%, transparent);
  }

  /* the Enter key: a small key of light */
  :root[data-home="capsule"] .home-enter {
    color: var(--cap-ink-faint);
    background: none;
    border: var(--line) solid var(--cap-edge);
    border-radius: var(--cap-r1);
    text-shadow: none;
  }

  :root[data-home="capsule"] .field:has(.field-input:not(:placeholder-shown)) .home-enter {
    color: var(--cap-ink);
    border-color: var(--cap-edge-lit);
    box-shadow: var(--cap-bloom);
  }

  /* the notes under it: the match line, Looking for, nothing found, the choices */
  :root[data-home="capsule"] :is(.field-note, .home-match) {
    font: var(--cap-type-meta);
    letter-spacing: var(--cap-track-meta);
    color: var(--cap-ink-soft);
    text-shadow: var(--cap-halo);
  }

  :root[data-home="capsule"] .field-note.unknown {
    color: var(--cap-ink);
  }

  :root[data-home="capsule"] .choices {
    gap: var(--space-3);
  }

  :root[data-home="capsule"] .choices .link {
    font: var(--cap-type-body);
  }

  :root[data-home="capsule"] .choice-note {
    font: var(--cap-type-meta);
    color: var(--cap-ink-faint);
    text-shadow: var(--cap-halo);
  }

  /* ══ The decades under the capsule: each a line of its decade's light, see-through, lit when pointed at ══ */
  :root[data-home="capsule"] .home-seg::before {
    inset: 0 0 auto;
    block-size: var(--line);
    background: linear-gradient(90deg, transparent, var(--seg) 10%, var(--seg) 90%, transparent);
    border-radius: 0;
    opacity: 1;
    filter: drop-shadow(0 0 3px color-mix(in oklab, var(--seg) 70%, transparent));
    scale: 1 1;
    transition: opacity var(--t-quick) var(--ease-arrive), filter var(--t-quick) var(--ease-arrive), block-size var(--t-quick) var(--ease-arrive);
  }

  :root[data-home="capsule"] .home-seg:is(:hover, :focus-visible, [aria-expanded="true"])::before {
    block-size: var(--line-strong);
    opacity: 1;
    scale: 1 1;
    filter: drop-shadow(0 0 6px var(--seg));
  }

  :root[data-home="capsule"] .home-seg {
    flex-wrap: nowrap;
    align-items: flex-end;
    align-content: normal;
    padding-block: 0 var(--space-3);
    color: var(--cap-ink-soft);
    text-shadow: var(--cap-halo);
    border-radius: var(--cap-r1);
  }

  /* each decade's face has its own capitals' height: the names are sized by it (so 2000s is as tall as 1950s), and
     cut at their baseline, so every name and count stands on one line */
  :root[data-home="capsule"] :is(.home-seg-name, .home-seg-short, .home-seg-n) {
    line-height: 1;
    text-box: trim-both cap alphabetic;
  }

  :root[data-home="capsule"] :is(.home-seg-name, .home-seg-short) {
    font-size-adjust: cap-height 0.72;
  }

  :root[data-home="capsule"] .home-seg:is(:hover, :focus-visible, [aria-expanded="true"]) {
    color: var(--cap-ink);
  }

  :root[data-home="capsule"] .home-seg-n {
    font: var(--cap-type-meta);
    color: var(--cap-ink-faint);
  }

  /* a band too narrow for its name (a phone on its side): '50s, and no count; the full name stays for readers */
  :root[data-home="capsule"] .home-seg-short {
    display: none;
    font-family: var(--face);
    font-weight: var(--weight);
    font-size: var(--text-2);
    line-height: 1;
  }

  /* all the decades show their counts or none do, and all are named in full or all short (paper.js measures the
     narrowest band and says which) */
  :root[data-home="capsule"] .home-timeline ol[data-tight] .home-seg-n {
    display: none;
  }

  /* so narrow that even '50s and '60s would touch: every other decade's name steps down a line, nothing overlaps */
  :root[data-home="capsule"] .home-timeline ol[data-tightest] > li:nth-child(odd) .home-seg {
    padding-block-end: var(--space-5);
  }

  :root[data-home="capsule"] .home-timeline ol[data-tightest] > li:nth-child(even) .home-seg {
    padding-block-end: var(--space-1);
  }

  :root[data-home="capsule"] .home-timeline ol[data-tighter] {
    & .home-seg-name {
      position: absolute;
      inline-size: var(--line);
      block-size: var(--line);
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }

    & .home-seg-short {
      display: inline;
    }
  }

  :root[data-home="capsule"] .home-seg:focus-visible {
    outline: var(--line-strong) solid var(--cap-ink);
    outline-offset: var(--focus-offset);
  }

  /* ══ Panels: a decade's moments, the credits. Haze, a ring of light, nothing tinted ══ */
  :root[data-home="capsule"] :is(.home-pop, .present > .credits[open], .years) {
    color: var(--cap-ink);
    background: var(--cap-haze);
    border: var(--line) solid var(--cap-edge-faint);
    border-radius: var(--cap-r3);
    box-shadow: inset 0 var(--line) 0 color-mix(in oklab, var(--cap-ink) 22%, transparent);
    -webkit-backdrop-filter: var(--cap-haze-blur);
    backdrop-filter: var(--cap-haze-blur);
  }

  :root[data-home="capsule"] .home-pop {
    padding: var(--space-5);
  }

  /* liquid glass (liquid.js): a highlight on the glass where the pointer is, and a rim of light round it */
  :root[data-home="capsule"] [data-glass]:is(:popover-open, [open]) {
    isolation: isolate;
    box-shadow:
      inset 0 var(--line) 0 color-mix(in oklab, var(--cap-ink) 34%, transparent),
      inset 0 calc(var(--line) * -1) 0 color-mix(in oklab, var(--cap-ink) 10%, transparent),
      inset 0 0 0 var(--line) color-mix(in oklab, var(--cap-ink) 6%, transparent);
  }

  :root[data-home="capsule"] [data-glass]:is(:popover-open, [open])::after {
    position: absolute;
    inset: 0;
    content: "";
    background:
      radial-gradient(55% 65% at var(--lx, 22%) var(--ly, 0%), color-mix(in oklab, var(--cap-ink) 13%, transparent), transparent 72%),
      linear-gradient(180deg, color-mix(in oklab, var(--cap-ink) 8%, transparent), transparent 28%);
    border-radius: inherit;
    mix-blend-mode: plus-lighter;
    pointer-events: none;
  }

  /* where the browser bends a backdrop (Chromium): the lens at the rim, and the scene's colour coming through */
  :root[data-home="capsule"] [data-glass][data-liquid]:is(:popover-open, [open]) {
    background: color-mix(in oklab, var(--cap-ground) 64%, transparent);
    -webkit-backdrop-filter: blur(2px) saturate(1.9);
    backdrop-filter: var(--cap-lens) blur(2px) saturate(1.9) brightness(1.06);
  }

  :root[data-home="capsule"] .home-pop-title {
    text-shadow: var(--cap-halo), 0 0 18px color-mix(in oklab, var(--seg) 60%, transparent);
  }

  :root[data-home="capsule"] .home-pop-title {
    padding-block-end: var(--space-3);
    border: 0;
    background: linear-gradient(90deg, var(--seg), transparent) 0 100% / 100% var(--line-strong) no-repeat;
    text-shadow: 0 0 18px color-mix(in oklab, var(--seg) 60%, transparent);
  }

  :root[data-home="capsule"] .home-pop .link {
    font: var(--cap-type-body);
  }

  :root[data-home="capsule"] .home-pop [data-decade-wall] {
    color: var(--cap-ink-soft);
  }

  /* ══ On this day: lined up with the command bar, the same light; a card is its year's light and its name ══ */
  /* (onthisday.js floats it over the foot; here it is held a group's gap under the command bar's ring instead,
     --otd-top from paper.js; it still steps aside on its own when the two leave it no room) */
  :root[data-home="capsule"] .otd--float {
    inset-block: calc(var(--otd-top, 60%) + var(--cap-gap)) auto !important;
    inset-inline: max(var(--cap-margin), calc((100% - var(--cap-measure)) / 2));
    color: var(--cap-ink);
  }

  :root[data-home="capsule"] .otd-head {
    margin-block-end: var(--space-3);
  }

  :root[data-home="capsule"] .otd-title {
    font: var(--cap-type-meta);
    font-weight: 700;
    letter-spacing: var(--cap-track-meta);
    color: var(--cap-ink-soft);
    text-shadow: var(--cap-halo);
  }

  :root[data-home="capsule"] .otd-date {
    font: var(--cap-type-meta);
    color: var(--cap-ink-faint);
  }

  /* five days fit the command bar's width without scrolling; a phone scrolls them */
  :root[data-home="capsule"] .otd-list {
    grid-auto-columns: minmax(8rem, 1fr);
    gap: var(--cap-gap-tight);
  }

  :root[data-home="capsule"] .otd-card {
    position: relative;
    padding: var(--space-3) var(--space-3) var(--space-2);
    color: var(--cap-ink);
    background: none;
    border: 0;
    border-radius: var(--cap-r2);
    text-shadow: var(--cap-halo);
  }

  /* its ring, in its decade's light coming in from the top */
  :root[data-home="capsule"] .otd-card::before {
    position: absolute;
    inset: 0;
    padding: var(--line);
    content: "";
    background: linear-gradient(170deg, var(--otd-ink), color-mix(in oklab, var(--otd-ink) 30%, transparent) 45%, var(--cap-edge-faint));
    border-radius: inherit;
    mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
    opacity: 0.85;
    transition: opacity var(--t-quick) var(--ease-arrive);
    pointer-events: none;
  }

  :root[data-home="capsule"] .otd-card:hover::before {
    opacity: 1;
    filter: drop-shadow(0 0 6px var(--otd-ink));
  }

  :root[data-home="capsule"] .otd-card:hover {
    scale: 1;
  }

  :root[data-home="capsule"] .otd-year {
    color: var(--otd-ink);
    font-size: var(--text-3);
  }

  :root[data-home="capsule"] .otd-name {
    font: var(--cap-type-control);
    line-height: 1.25;
    color: var(--cap-ink);
  }

  :root[data-home="capsule"] .otd-meta {
    font: var(--cap-type-meta);
    color: var(--cap-ink-faint);
    opacity: 1;
  }

  :root[data-home="capsule"] .otd-card:focus-visible {
    outline: var(--line-strong) solid var(--cap-ink);
    outline-offset: var(--focus-offset);
  }

  /* ══ The foot: what the capsule is, the versions, the credits; small, soft, in the corners ══ */
  :root[data-home="capsule"] .present > .home-caption {
    font: var(--cap-type-meta);
    letter-spacing: var(--cap-track-meta);
    color: var(--cap-ink-soft);
    text-shadow: var(--cap-halo);
  }

  /* one margin for everything on the start screen: the bar's, the capsule's, the foot's */
  :root[data-home="capsule"] .present {
    padding-inline: max(var(--cap-margin), env(safe-area-inset-left)) max(var(--cap-margin), env(safe-area-inset-right));
  }

  /* 18: the field's notes (Enter falls to, Looking for, nothing found) take the room under it: On this day goes */
  :root[data-home="capsule"] .present:has(:is(.home-match, .field-status, .field-note.unknown):not(:empty)) .otd--float,
  :root[data-home="capsule"] .present:has(.choices:not([hidden])) .otd--float {
    visibility: hidden;
  }

  :root[data-home="capsule"] .present > .home-versions {
    gap: var(--space-2) var(--space-5);
  }

  :root[data-home="capsule"] :is(.home-versions .link, .credits summary) {
    font: var(--cap-type-meta);
    letter-spacing: var(--cap-track-meta);
    color: var(--cap-ink-soft);
    background-image: none;
  }

  :root[data-home="capsule"] :is(.home-versions .link, .credits summary):hover,
  :root[data-home="capsule"] .home-versions [aria-current="page"] {
    color: var(--cap-ink);
    background: var(--cap-pass-lit) 0 100% / 100% var(--line) no-repeat;
  }

  :root[data-home="capsule"] .present > .credits[open] {
    padding: var(--space-5);
  }

  :root[data-home="capsule"] .credits-note {
    color: var(--cap-ink-soft);
  }

  /* ══ The wall pointed at in the capsule: its name beside the eye, glowing, no slip of paper ══ */
  :root[data-home="capsule"] .home-tip {
    padding: 0;
    font: var(--cap-type-control);
    color: var(--cap-ink);
    background: none;
    border: 0;
    box-shadow: none;
    text-shadow: var(--cap-halo);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  /* ══ The word on its way: light, not a slip of paper ══ */
  :root[data-home="capsule"] .word.travelling {
    padding: 0;
    color: var(--cap-ink);
    background: none;
    text-shadow: var(--cap-halo), 0 0 28px color-mix(in oklab, var(--cap-ink) 35%, transparent);
  }

  /* ══ The fall: the status, the decade, the year, Walls passed and the controls glow on the wormhole, no boxes ══
     The wormhole is at its brightest round its middle and its photos come right up to the corners, so type alone
     can't hold 4.5:1 there: the corner the HUD is in, and the foot the controls are on, are dusked by a soft
     gradient of black (a scrim, never a box), and the type has its halo on top. Every piece sits flush on one edge,
     the page's margin inside the safe area, on the grid: 13 the status, the decade's name, 16 its line, the year,
     13 Walls passed. scripts/capsule-hud-contrast.mjs measures it from the rendered frames. */
  :root[data-home="capsule"] .hud {
    inset: max(var(--cap-margin), env(safe-area-inset-top)) auto auto max(var(--cap-margin), env(safe-area-inset-left));
    gap: 0;
    max-inline-size: min(30rem, calc(100vw - 2 * var(--cap-margin)));
  }

  /* the dusk under the type: a dark field just larger than what it holds, blurred so far it has no edge (whatever
     the HUD's size on any screen, the type is always well inside it) */
  :root[data-home="capsule"] .hud::before,
  :root[data-home="capsule"] .controls::before {
    position: absolute;
    inset: calc(var(--space-5) * -1) calc(var(--space-6) * -1);
    z-index: -1;
    content: "";
    background: color-mix(in oklab, var(--cap-ground) 86%, transparent);
    border-radius: var(--cap-r3);
    filter: blur(var(--space-6));
    pointer-events: none;
  }

  /* the HUD's reaches up and left past the screen's edge, so the corner itself is dark */
  :root[data-home="capsule"] .hud::before {
    inset-block-start: calc(var(--space-9) * -1);
    inset-inline-start: calc(var(--space-9) * -1);
  }

  :root[data-home="capsule"] :is(.hud-status, .hud-narration, .hud-year, .hud-passed, .controls) {
    padding: 0;
    color: var(--cap-ink);
    background: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    text-shadow: 0 0 2px var(--cap-ground), 0 0 6px var(--cap-ground), 0 0 12px color-mix(in oklab, var(--cap-ground) 80%, transparent);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  :root[data-home="capsule"] .hud-status {
    margin-block-end: var(--space-4);
    font: var(--cap-type-meta);
    letter-spacing: var(--cap-track-meta);
  }

  /* the decade: its name glowing in its colour, its line in ink under it, a line of its light at the foot */
  :root[data-home="capsule"] .hud-narration {
    gap: var(--space-2);
    margin-block-end: var(--space-3);
    padding-block-end: var(--space-3);
    background: linear-gradient(90deg, var(--decade-glow), transparent) 0 100% / 100% var(--line) no-repeat;
  }

  :root[data-home="capsule"] .hud-decade {
    text-shadow: 0 0 2px var(--cap-ground), 0 0 6px var(--cap-ground), 0 0 20px var(--glow);
  }

  :root[data-home="capsule"] .hud-line {
    font: var(--cap-type-body);
    color: var(--cap-ink);
  }

  :root[data-home="capsule"] .hud-year {
    margin-inline-start: -0.04em;
    text-shadow: 0 0 2px var(--cap-ground), 0 0 8px var(--cap-ground), 0 0 22px var(--glow);
  }

  :root[data-home="capsule"] .hud-passed {
    margin-block-start: var(--space-2);
    font: var(--cap-type-meta);
    letter-spacing: var(--cap-track-meta);
    color: var(--cap-ink);
  }

  /* the controls: one row on a dusk rising from the screen's foot */
  :root[data-home="capsule"] .controls {
    inset: auto 0 max(var(--space-4), env(safe-area-inset-bottom)) 0;
    gap: var(--space-1) var(--space-2);
    max-inline-size: calc(100% - 2 * var(--cap-margin));
  }

  :root[data-home="capsule"] .controls .hint {
    padding-inline: var(--space-3);
    font: var(--cap-type-meta);
    color: var(--cap-ink);
    background: none;
    box-shadow: none;
  }

  :root[data-home="capsule"] [data-boost] .controls .hint {
    color: var(--cap-ink);
    background: none;
    box-shadow: none;
    text-shadow: var(--cap-halo), 0 0 14px var(--glow);
  }

  /* ── The fall, the wormhole's part (splat-tunnel.js; the wormhole session keeps this block): the rolling year,
     the controls on a phone, the HUD on a short screen. The wormhole itself dims behind the HUD and the controls
     (shade() in splat-tunnel.js), so a photo or a streak passing there never takes the type's contrast. ── */

  /* the year rolls under a soft fade at its top and foot, not in boxes: each digit's cell no longer clips (a clipped
     halo made a dark box behind the type, and a digit cut in half), the row fades what rolls in and out */
  :root[data-home="capsule"] .hud-year {
    padding: 0 0.3em;
    margin-inline-start: calc(-0.3em - 0.04em);
    -webkit-mask-image: linear-gradient(transparent, #000 0.14em, #000 calc(100% - 0.14em), transparent);
    mask-image: linear-gradient(transparent, #000 0.14em, #000 calc(100% - 0.14em), transparent);
  }

  :root[data-home="capsule"] .hud-year .digit {
    overflow: visible;
  }

  /* a phone: two even rows, the hint and the speed on one, Skip, Home and Sound on the other */
  @media (width < 30rem) {
    :root[data-home="capsule"] .controls {
      display: grid;
      grid-template-columns: repeat(3, auto);
      grid-template-areas: "hint dial dial" "skip home sound";
      place-items: center;
      justify-content: center;
      gap: var(--space-1) var(--space-1);
    }

    :root[data-home="capsule"] .controls .hint {
      grid-area: hint;
      padding-inline: var(--space-1);
    }

    :root[data-home="capsule"] .controls .speed-dial {
      grid-area: dial;
      gap: var(--space-1);
      padding: 0;
    }

    :root[data-home="capsule"] .controls [data-skip] {
      grid-area: skip;
    }

    :root[data-home="capsule"] .controls [data-abort] {
      grid-area: home;
    }

    :root[data-home="capsule"] .controls .switch {
      grid-area: sound;
    }
  }

  /* a phone on its side: the HUD stays in its corner, clear of the title in the hole */
  @media (min-aspect-ratio: 4/5) and (height < 32rem) {
    :root[data-home="capsule"] .hud {
      max-inline-size: min(20rem, 26vw);
    }

    :root[data-home="capsule"] .hud-status {
      margin-block-end: var(--space-2);
    }

    :root[data-home="capsule"] .hud-narration {
      margin-block-end: var(--space-2);
      padding-block-end: var(--space-2);
    }

    :root[data-home="capsule"] .hud-year {
      font-size: clamp(2.25rem, 11vh, 3rem);
    }
  }

  /* ══ The bar over a wall: the site's own height for it (on a phone two rows, the wall's name and date under the
     controls), the notch above it, and the wall starting under all of it ══ */
  :root[data-home="capsule"] {
    --wall-bar: calc(var(--bar) + env(safe-area-inset-top));
  }

  /* a phone's two rows need a little more than the site's 96, so the name and date sit inside the bar's line */
  @media (width < 37.5rem) {
    :root[data-home="capsule"] {
      --wall-bar: calc(var(--bar) + var(--space-3) + env(safe-area-inset-top));
    }
  }

  :root[data-home="capsule"] body:not([data-phase="ask"]) .bar {
    block-size: var(--wall-bar);
  }

  :root[data-home="capsule"] .wall {
    inset-block-start: var(--wall-bar);
  }

  /* the wall's name, date, years and sources: every label on one line and every value hanging from the next, the
     group centred in the bar (the name is bigger, so centring each cell put the labels at different heights) */
  :root[data-home="capsule"] body:not([data-phase="ask"]) .bar .dateline {
    align-items: flex-start;
    align-self: center;
  }

  :root[data-home="capsule"] body:not([data-phase="ask"]) .bar .dateline :is(.cell-title, [data-cell]) {
    align-content: start;
  }

  /* ══ A wall's phone end, the Share bubble, Another year ══ */
  :root[data-home="capsule"] body:not([data-phase="ask"]) .wall-end {
    background: var(--cap-pass) 0 0 / 100% var(--line) no-repeat, color-mix(in oklab, var(--cap-ground) 82%, transparent);
    border: 0;
  }

  :root[data-home="capsule"] .bubble {
    color: var(--cap-ink);
    background: var(--cap-haze);
    border: var(--line) solid var(--cap-edge-faint);
    border-radius: var(--cap-r1);
    -webkit-backdrop-filter: var(--cap-haze-blur);
    backdrop-filter: var(--cap-haze-blur);
  }

  :root[data-home="capsule"] .years {
    padding: var(--space-5);
  }

  :root[data-home="capsule"] .years-input {
    color: var(--cap-ink);
    background: none;
    border: var(--line) solid var(--cap-edge);
    border-radius: var(--cap-r1);
  }

  /* ══ An open sheet: its page keeps the glass it reads on (capsule-wall.css); Close and the photo's credit glow ══ */
  :root[data-home="capsule"] .open-sheet {
    border-radius: 0;
  }

  /* Close floats over the photo and, scrolled, over the page's text; the credit lies on the photo: both on a haze */
  :root[data-home="capsule"] .spread-credit {
    padding: var(--space-1) var(--space-2);
    font: var(--cap-type-meta);
    color: var(--cap-ink);
    background: var(--cap-haze);
    border-radius: var(--cap-r1);
    text-shadow: var(--cap-halo);
    -webkit-backdrop-filter: var(--cap-haze-blur);
    backdrop-filter: var(--cap-haze-blur);
  }

  :root[data-home="capsule"] .open-head .button {
    background: var(--cap-haze);
    border-radius: var(--cap-r1);
    -webkit-backdrop-filter: var(--cap-haze-blur);
    backdrop-filter: var(--cap-haze-blur);
  }

  /* below the photo, Close has a row of its own as the page scrolls: a dusk under it, the page's text going under the
     dusk and never under the button */
  :root[data-home="capsule"] .open-head::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    block-size: calc(var(--control) + var(--space-3) * 2 + var(--space-4));
    background: linear-gradient(var(--cap-ground) calc(var(--control) + var(--space-3) * 2), transparent);
    pointer-events: none;
  }

  /* it comes in over the first 48 px of scrolling (and is simply there where scroll timelines are not) */
  @supports (animation-timeline: scroll()) {
    :root[data-home="capsule"] .open-head::before {
      animation: cap-dusk linear both;
      animation-timeline: scroll(nearest block);
      animation-range: 0 var(--space-7);
    }
  }

  @keyframes cap-dusk {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  /* ══ All moments: black, each moment a tile of its decade's light (as the walls are), its name glowing ══ */
  /* its name once, in its own title; not again in the bar as a "Wall" (and on a phone, no second row for it) */
  :root[data-home="capsule"] body[data-phase="archive"] .bar .dateline {
    display: none;
  }

  @media (width < 37.5rem) {
    :root[data-home="capsule"]:has(body[data-phase="archive"]) {
      --bar: var(--cap-bar);
    }

    :root[data-home="capsule"] body[data-phase="archive"] .bar {
      grid-template-areas: "home . nav sound";
      grid-template-rows: auto;
      block-size: var(--cap-bar);
    }
  }

  /* the wall's sheets on the page's margin, as everything else is (and clear of a notch on a phone on its side) */
  :root[data-home="capsule"] .sheets {
    padding-inline: max(var(--cap-margin), env(safe-area-inset-left)) max(var(--cap-margin), env(safe-area-inset-right));
  }

  /* 13: tiles at least 13rem wide (two on a phone), so a moment's name keeps its size and two or three lines */
  :root[data-home="capsule"] .archive-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(13rem, calc(50% - var(--cap-gap-tight))), 1fr));
  }
  :root[data-home="capsule"] .archive {
    color: var(--cap-ink);
    background: var(--cap-ground);
    padding-block-start: var(--space-6);
  }

  :root[data-home="capsule"] .archive-title {
    font: var(--cap-type-figure);
    color: var(--cap-ink);
  }

  :root[data-home="capsule"] .archive-grid {
    gap: var(--cap-gap-tight);
  }

  :root[data-home="capsule"] .tile-link {
    position: relative;
    color: var(--cap-ink);
    background: radial-gradient(120% 90% at 30% 0%, color-mix(in oklab, var(--ground) 62%, transparent), color-mix(in oklab, var(--ground) 18%, transparent) 72%), var(--cap-ground);
    border-radius: var(--cap-r2);
    text-shadow: var(--cap-halo);
  }

  :root[data-home="capsule"] .tile-link::before {
    position: absolute;
    inset: 0;
    padding: var(--line);
    content: "";
    /* its decade's light coming in at the top, mixed with ink so a black tile's edge shows as well as a bright one's */
    background: linear-gradient(170deg, color-mix(in oklab, var(--ground) 60%, var(--cap-ink)), var(--cap-edge) 45%, var(--cap-edge-faint));
    border-radius: inherit;
    mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
    pointer-events: none;
  }

  :root[data-home="capsule"] .tile-label {
    font: var(--cap-type-meta);
    color: var(--cap-ink-soft);
  }

  :root[data-home="capsule"] .tile::before {
    border-radius: var(--cap-r2);
  }

  :root[data-home="capsule"] .tile-link:focus-visible {
    outline: var(--line-strong) solid var(--cap-ink);
    outline-offset: var(--focus-offset);
  }

  /* ══ A phone, or any screen taller than 4:5: the capsule stands (home.js), the past at its foot ══════════════
     The capsule takes the height there is, its decades beside it; under it the hint, then the thumb's reach: the
     command bar, On this day as a row of whole cards that snaps, and the foot. Nothing scrolls sideways but the row. */
  @media (max-aspect-ratio: 4/5) {
    :root[data-home="capsule"] {
      --otd-room: 7.25rem; /* On this day's head and a row of cards, held for it so nothing below moves */
    }

    /* the capsule (as wide as it stands, --stage-w from paper.js) and its decades, centred as one pair */
    :root[data-home="capsule"] .present {
      grid-template-columns: minmax(0, 1fr) var(--stage-w, 9rem) 7.5rem minmax(0, 1fr);
      grid-template-rows: minmax(10rem, 1fr) auto auto var(--otd-room) auto;
      grid-template-areas:
        ".        stage    time     ."
        "caption  caption  caption  caption"
        "ask      ask      ask      ask"
        "otd      otd      otd      otd"
        "versions versions credits  credits";
      gap: 0 var(--space-4);
      padding: calc(env(safe-area-inset-top) + var(--cap-bar) + var(--space-3)) max(var(--cap-margin), env(safe-area-inset-right)) max(var(--space-3), env(safe-area-inset-bottom)) max(var(--cap-margin), env(safe-area-inset-left));
    }

    :root[data-home="capsule"] .present > :is(.home-stage, .ask, .home-caption, .home-versions, .credits) {
      margin-inline: 0;
    }

    :root[data-home="capsule"] .home-stage {
      grid-area: stage;
      inline-size: auto;
      block-size: 100%;
      aspect-ratio: auto;
      max-block-size: none;
      min-block-size: 0;
    }

    /* the decades, one above another beside their bands (paper.js puts each at its band's height) */
    :root[data-home="capsule"] .home-timeline {
      grid-area: time;
      overflow: visible;
    }

    :root[data-home="capsule"] .home-timeline ol,
    :root[data-home="capsule"] .home-timeline ol[data-placed] {
      position: relative;
      display: block;
      block-size: 100%;
      padding: 0;
      overflow: visible;
      mask: none;
      animation: none;
      pointer-events: none;
    }

    :root[data-home="capsule"] .home-timeline ol[data-standing] > li {
      position: absolute;
      inset: var(--y) 0 auto;
      block-size: var(--h);
      inline-size: auto;
      margin: 0;
    }

    :root[data-home="capsule"] .home-timeline ol[data-standing] .home-seg {
      flex-wrap: nowrap;
      align-content: center;
      align-items: center;
      gap: var(--space-2);
      min-block-size: 0;
      padding: 0 0 0 var(--space-3);
    }

    /* its line runs up beside the band */
    :root[data-home="capsule"] .home-timeline ol[data-standing] .home-seg::before {
      inset: 0 auto 0 0;
      inline-size: var(--line);
      block-size: auto;
      background: linear-gradient(180deg, transparent, var(--seg) 12%, var(--seg) 88%, transparent);
    }

    :root[data-home="capsule"] .home-timeline ol[data-standing] .home-seg:is(:hover, :focus-visible, [aria-expanded="true"])::before {
      inline-size: var(--line-strong);
      block-size: auto;
    }

    :root[data-home="capsule"] .home-timeline ol[data-standing] .home-seg-name {
      font-size: var(--text-3);
    }

    /* the hint, under the capsule */
    :root[data-home="capsule"] .present > .home-caption {
      grid-area: caption;
      display: block;
      justify-self: center;
      max-inline-size: none;
      margin: var(--space-3) 0 0;
      text-align: center;
    }

    :root[data-home="capsule"] .ask {
      grid-area: ask;
      justify-self: stretch;
      inline-size: auto;
      margin-block-start: var(--space-4);
    }

    /* On this day has its own row here, so it never needs to step aside for room (it still does while you type) */
    :root[data-home="capsule"] .otd--float[data-aside]:not([data-typing]) {
      visibility: visible;
    }

    :root[data-home="capsule"] .otd--float[data-aside]:not([data-typing]) .otd-card {
      pointer-events: auto;
    }

    /* On this day: whole cards, two to the width, a swipe snapping to the next */
    :root[data-home="capsule"] .otd--float {
      inset-inline: max(var(--cap-margin), env(safe-area-inset-left)) max(var(--cap-margin), env(safe-area-inset-right));
    }

    :root[data-home="capsule"] .otd-list {
      grid-auto-columns: calc((100% - var(--cap-gap-tight)) / 2);
      scroll-snap-type: x mandatory;
      overscroll-behavior-x: contain;
    }

    :root[data-home="capsule"] .otd-list > li {
      scroll-snap-align: start;
    }

    /* the foot, folded into one band under it: the four versions two by two, the credits at the end of the last row */
    :root[data-home="capsule"] .present > .home-versions {
      grid-area: versions;
      display: grid;
      grid-template-columns: repeat(2, max-content);
      align-self: end;
      justify-content: start;
      gap: var(--space-2) var(--space-5);
    }

    :root[data-home="capsule"] .present > .credits {
      grid-area: credits;
      align-self: end;
    }

    /* a finger holds the capsule: the browser leaves that gesture to it (and only on the capsule) */
    :root[data-home="capsule"] .home-scene {
      touch-action: none;
      -webkit-touch-callout: none;
      user-select: none;
    }
  }

  /* the wall a finger is on is named above it, never under it */
  :root[data-home="capsule"] .home-tip[data-touch] {
    transform: translate(-50%, -100%);
  }

  /* ══ A phone's bar: one row, the same rules (the name at the start, the count, Surprise me and Sound at the end) ══ */
  @media (width < 37.5rem) {
    :root[data-home="capsule"] {
      --cap-bar: 3.5rem;
    }

    :root[data-home="capsule"] body .bar {
      gap: var(--space-1);
    }

    :root[data-home="capsule"] body .bar > .bar-name {
      margin-inline-end: auto;
    }

    :root[data-home="capsule"] body .bar > .stats {
      flex: none;
      margin: 0 var(--space-2) 0 0;
    }

    :root[data-home="capsule"] body .bar :is(.button, .switch) {
      padding-inline: var(--space-2);
    }

    /* the end's controls carry --space-2 inside here, so the bar gives that back and their words end on the margin */
    :root[data-home="capsule"] body[data-phase="ask"] .bar {
      padding-inline-end: max(calc(var(--cap-margin) - var(--space-2)), env(safe-area-inset-right));
    }

    :root[data-home="capsule"] body .bar > .switch {
      margin-inline-start: 0;
    }
  }

  /* a phone on its side: the capsule lies, and only what fits under it stays (the strip steps aside) */
  @media (min-aspect-ratio: 4/5) and (height < 32rem) {
    /* a set height (the rest of the screen less the bar, the decades and the field), so its row is its height */
    :root[data-home="capsule"] .home-stage {
      block-size: max(5rem, calc(100dvh - 19.25rem));
      min-block-size: 0;
      max-block-size: none;
      aspect-ratio: auto;
    }

    :root[data-home="capsule"] .present {
      grid-template-rows: 0 auto auto auto minmax(0, 1fr) 0 auto;
      row-gap: 0;
    }

    :root[data-home="capsule"] .ask {
      margin-block-start: var(--space-2);
    }

    :root[data-home="capsule"] .present > .home-caption,
    :root[data-home="capsule"] .otd--float {
      display: none;
    }
  }

  /* ══ Where see-through light can't be shown ══ */
  @media (prefers-reduced-transparency: reduce) {
    :root[data-home="capsule"] :is(.home-pop, .present > .credits[open], .years, .bubble) {
      background: var(--cap-ground);
      backdrop-filter: none;
    }

    :root[data-home="capsule"] [data-glass]::after {
      content: none;
    }
  }

  /* forced colours drop gradients and shadows: the lines become borders in the system's colours */
  @media (forced-colors: active) {
    :root[data-home="capsule"] .field::before {
      mask: none;
      background: none;
      border: var(--line) solid CanvasText;
    }

    :root[data-home="capsule"] :is(.otd-card, .tile-link, .home-seg) {
      border: var(--line) solid CanvasText;
    }

    :root[data-home="capsule"] :is(.bar, .controls, .wall-end, .open-head, .years, .copy) :is(.button, .icon-button, .switch):hover {
      outline: var(--line) solid Highlight;
    }
  }
}
