/*
  The Capsule theme's walls (Karan, 22 November: "Made of splats"). Linked only on /capsule/ (scripts/home-pages.mjs),
  after paper.css and home.css, in the same layer. Paper, the original site, never loads it.

  - The wall is print black. Each sheet is a card of light: splat-wall.js draws its ground (and a face's photo) as
    glowing splats on a canvas under the sheets, and marks the page data-splat-wall while it can. Then the sheet's own
    ground is only a faint veil of that colour under its type, enough to keep every line at 4.5:1 or better; the
    type itself stays in the DOM. Without WebGL (and in the poster's print frame) the grounds stay solid.
  - Paper's extras are off: the tooth, the seams, the folds, the curl and its peel, the living wall's lean and sheen.
  - The bar on a wall, the phone's wall end and an open sheet are glass: see-through black, blurred, a hairline edge.
*/
@layer app {
  :root[data-home="capsule"] {
    /* how much of a sheet's ground lies under its type, over the splats (contrast measured: scripts/capsule-contrast.mjs) */
    --veil: 45%;
    --card-radius: var(--cap-r2, var(--space-4)); /* a card, on the Capsule system's scale (design/capsule) */
    --glass: color-mix(in oklab, var(--black) 62%, transparent);
    --glass-edge: color-mix(in oklab, var(--stock) 16%, transparent);
    --glass-blur: blur(var(--space-5)) saturate(150%);
  }

  /* the page under everything is black, so glass over it is dark glass */
  :root[data-home="capsule"] {
    background: var(--black);
  }

  /* the fall's canvases keep their last frame under a wall; through the glass bar they would show */
  :root[data-home="capsule"] body:is([data-phase="wall"], [data-phase="archive"]) :is(.fall, .tunnel, .worm) {
    visibility: hidden;
  }

  /* ── The wall: cards of light on black, a little black between them ───────────────────────── */
  /* the wall keeps clear of the home indicator */
  :root[data-home="capsule"] .wall {
    padding-block-end: env(safe-area-inset-bottom);
    background: var(--black);
  }

  /* the cards a group on the system's grid: --cap-gap-tight between them and round them, clear of a notch on its side */
  :root[data-home="capsule"] .sheets {
    position: relative;
    z-index: var(--z-raised);
    gap: var(--cap-gap-tight, var(--space-2));
    padding: var(--cap-gap-tight, var(--space-2)) max(var(--cap-gap-tight, var(--space-2)), env(safe-area-inset-right)) var(--cap-gap-tight, var(--space-2)) max(var(--cap-gap-tight, var(--space-2)), env(safe-area-inset-left));
  }

  /* the canvas: under the sheets, inside the wall, scrolling with them; splat-wall.js sets its box */
  .splat-wall {
    position: absolute;
    z-index: 0;
    display: block;
    pointer-events: none;
  }

  :root[data-home="capsule"] .sheet {
    --c: 0;
    /* type sits the system's card inset from the card's edge */
    --sheet-pad: var(--cap-pad, var(--space-4));
    border-radius: var(--card-radius);
  }

  /* no tooth, no seams, no folds, no cut corner: a card's edge is the edge of its light */
  :root[data-home="capsule"] .sheet-front {
    background-image: none;
    border-radius: var(--card-radius);
    clip-path: none;
  }

  /* the curl, its fold and its roll, and the story only the curl showed */
  :root[data-home="capsule"] :is(.curl, .sheet-flap, .sheet-roll, .sheet-under) {
    display: none;
  }

  /* the living wall stays flat: the splats under it can't lean, and the black hole answers the pointer instead */
  :root[data-home="capsule"] .sheet[data-living] {
    translate: none;
    transform: none;
  }

  :root[data-home="capsule"] .sheet::before,
  :root[data-home="capsule"] .sheet-front::after {
    content: none;
  }

  /* the splats are the ground: the sheet keeps only a veil of it under the type, and its photo is splats too */
  :root[data-splat-wall] .sheet-front {
    background-color: color-mix(in oklab, var(--ground) var(--veil), transparent);
  }

  :root[data-splat-wall] .halftone {
    display: none;
  }

  /* what someone said hangs its opening quote into the card's padding, never past the card's edge */
  :root[data-home="capsule"] [data-lane="people"] .sheet-answer {
    text-indent: calc(-1 * min(1em * 0.45, var(--sheet-pad) - var(--space-1)));
  }

  /* a short desktop (1024 to 1279): the outer columns a little wider, so the face and the sheet after it are never
     a narrow strip; the middle ones give the room */
  @media (min-width: 1024px) and (max-width: 1279px) {
    :root[data-home="capsule"] .sheets {
      grid-template-columns: 1.6fr 1.6fr repeat(8, minmax(0, 1fr)) 1.3fr 1.3fr;
    }
  }

  /* a face card: the photo keeps half of it under the label, the name and its whole credit sit at the card's foot,
     and the photo (the whole face, splat-wall.js) takes all the room between */
  :root[data-home="capsule"] [data-lane="face"] .sheet-label {
    margin-block-end: max(0px, calc(50cqb - 1lh));
  }

  /* the way to the moment a sheet leads to: a lit edge in the card's corner, not an inverted block, and the label
     starts under it, so a long label is never covered */
  :root[data-home="capsule"] .follow {
    inset: var(--space-2) var(--space-2) auto auto;
    color: var(--ink);
    background: color-mix(in oklab, var(--ground) 72%, transparent);
    border: var(--line) solid color-mix(in oklab, var(--ink) 55%, transparent);
    border-radius: var(--cap-r1, var(--space-2));
    /* one line, always as tall as the room the label leaves it; cut short if the card is narrow (its name is whole
       for a screen reader) */
    display: block;
    overflow: hidden;
    line-height: calc(var(--control) - 2 * var(--line));
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  :root[data-home="capsule"] .follow:is(:hover, [data-state~="hover"]) {
    color: var(--ink);
    background: color-mix(in oklab, var(--ground) 72%, transparent);
    border-color: var(--ink);
    outline: none;
  }

  :root[data-home="capsule"] .sheet:has(.follow) .sheet-label {
    margin-block-start: calc(var(--control) + var(--space-3) - var(--sheet-pad));
    padding-inline-end: 0;
  }

  /* a face's photo lies between its label and its name (splat-wall.js), so neither needs a patch of ground: no
     chip, no block */
  :root[data-splat-wall] [data-lane="face"] :is(.sheet-label, .sheet-answer) {
    background: none;
    outline: none;
  }

  /* ── Glass: the bar over a wall, the phone's wall end ───────────────────────────────────── */
  :root[data-home="capsule"] body:not([data-phase="ask"]) :is(.bar, .wall-end) {
    --now-ground: var(--black);
    --now-ink: var(--stock);
    --now-ink-soft: color-mix(in srgb, var(--stock) 66%, var(--black));
    --now-ink-disabled: color-mix(in srgb, var(--stock) 40%, var(--black));
    --now-inverse-ground: var(--stock);
    --now-inverse-ink: var(--black);
    --ground: var(--now-ground);
    --ink: var(--now-ink);
    color: var(--now-ink);
    background: var(--glass);
    background-image: none;
    outline: none;
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
  }

  :root[data-home="capsule"] body:not([data-phase="ask"]) .bar {
    border-block-end-color: var(--glass-edge);
  }

  :root[data-home="capsule"] body:not([data-phase="ask"]) .wall-end {
    position: relative;
    z-index: var(--z-raised);
    border-block-start: var(--line) solid var(--glass-edge);
  }

  /* ── An open sheet: a glass page tinted with its sheet's colour, the wall's light blurred behind it ─── */
  :root[data-home="capsule"] .open-sheet {
    --sheet-ground: var(--ground);
    --glass-tint: color-mix(in oklab, var(--sheet-ground) 22%, var(--black));
    color: var(--stock);
    background: color-mix(in oklab, var(--glass-tint) 80%, transparent);
    -webkit-backdrop-filter: blur(var(--space-6)) saturate(160%);
    backdrop-filter: blur(var(--space-6)) saturate(160%);
  }

  /* inside it, stock on the tint: the page's own pairs follow */
  :root[data-home="capsule"] .open-sheet > * {
    --ground: var(--glass-tint);
    --ink: var(--stock);
    --paper: var(--glass-tint);
    --deep: var(--stock);
  }

  /* the title starts under the photo, on the glass like the rest of the page: no band, no edge, never over a photo */
  :root[data-home="capsule"] .open-sheet .spread-title {
    margin-block-start: 0;
    background: transparent;
  }

  /* on a wide screen the photo is a shorter page, so the title beside it has no dead space above it */
  @media (min-width: 1024px) {
    :root[data-home="capsule"] .open-sheet {
      --hero: min(calc(100dvh * 0.6), calc(var(--space-9) * 4));
    }
  }

  /* a wide screen: the story on the left; the facts, the links and the photos down the right beside it, so the right
     column has no dead space under the links */
  @media (min-width: 1024px) {
    :root[data-home="capsule"] .open-sheet .page {
      grid-template-areas: "story aside" "story strip" "next next";
      grid-template-rows: auto 1fr auto;
      align-items: start;
    }

    :root[data-home="capsule"] .open-sheet .page-story {
      grid-area: story;
    }

    :root[data-home="capsule"] .open-sheet .page-aside {
      grid-area: aside;
    }

    :root[data-home="capsule"] .open-sheet .page-strip {
      grid-area: strip;
      flex-wrap: wrap;
      margin-inline: 0;
      padding-inline: 0;
      overflow: visible;
    }

    :root[data-home="capsule"] .open-sheet .page-connections {
      grid-area: next;
    }
  }

  /* a fact's label on its value's baseline */
  :root[data-home="capsule"] .open-sheet .page-facts {
    align-items: baseline;
  }

  /* a photo still coming in is a faint frame of light, not a grey box */
  :root[data-home="capsule"] .open-sheet :is(.spread-media, .page-photo img, .page-photo.is-loading, .connection-photo) {
    background: color-mix(in oklab, var(--stock) 5%, transparent);
  }

  /* where see-through is asked not to be: the same colours, solid */
  @media (prefers-reduced-transparency: reduce) {
    :root[data-home="capsule"] body:not([data-phase="ask"]) :is(.bar, .wall-end) {
      background: var(--black);
      backdrop-filter: none;
    }

    :root[data-home="capsule"] .open-sheet {
      background: var(--glass-tint);
      backdrop-filter: none;
    }
  }

  /* forced colours can't reach the canvas's light: the sheets take the system's colours instead */
  @media (forced-colors: active) {
    :root[data-splat-wall] .splat-wall {
      display: none;
    }

    :root[data-home="capsule"] .sheet-front {
      border: var(--line) solid CanvasText;
    }
  }
}
