/* Signal frame: page ground, grain, crop marks, skip link, rail (with its two actions), the pause
   switch for live demos, colophon and shared readouts. Every vibehyper page (hub or plate) loads this
   file unchanged. */
@layer frame {
  html { overflow-x: clip; scroll-padding-top: calc(var(--rail-h) + 1rem); }

  body {
    background: var(--black);
    color: var(--ink);
    font: 400 var(--fs-body) / 1.35 var(--serif);
    padding-inline: var(--gutter);
    overflow-x: clip; /* the rail ruler is 100vw, which counts the scrollbar: trim it here (clip keeps sticky working) */
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;

    /* Signal grain, unchanged from the splash */
    &::before {
      content: '';
      position: fixed;
      inset: 0;
      background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
      pointer-events: none;
      z-index: 30;
    }
  }

  .rail, main > section, .colophon { max-inline-size: var(--page-max); margin-inline: auto; }

  a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
  a:hover { color: var(--accent-text); }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
  main[tabindex="-1"]:focus { outline: none; }   /* the skip link's target takes focus, not a ring */

  /* Skip link: hidden until focused, then a cream chip above the rail (SPEC §5) */
  .skip-link {
    position: fixed; top: 0.5rem; left: 0.5rem; z-index: 40;
    display: inline-flex; align-items: center; min-block-size: 44px; padding-inline: 1rem;
    background: var(--paper); color: var(--paper-ink); text-decoration: none;
    font: 500 var(--fs-label) / 1 var(--mono); letter-spacing: var(--track-label); text-transform: uppercase;
    &:not(:focus) { clip-path: inset(50%); inline-size: 1px; block-size: 1px; min-block-size: 0; overflow: hidden; white-space: nowrap; padding: 0; }
    &:hover { color: var(--paper-ink); }
  }
  code { font: 400 0.82em var(--mono); color: var(--ink); }
  em { font-style: italic; }

  .vh-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

  .kicker, .label {
    font: 500 var(--fs-label) / 1.3 var(--mono);
    letter-spacing: var(--track-label);
    text-transform: uppercase;
    color: var(--ink-3);
  }

  /* Crop marks: the frame's corners */
  .mark {
    position: fixed; width: 22px; height: 22px; opacity: 0.22; z-index: 25; pointer-events: none;
    &::before, &::after { content: ''; position: absolute; background: var(--white); }
    &::before { width: 1px; height: 100%; left: 50%; }
    &::after { height: 1px; width: 100%; top: 50%; }
  }
  .mark--tl { top: 10px; left: 10px; }
  .mark--tr { top: 10px; right: 10px; }
  .mark--bl { bottom: 10px; left: 10px; }
  .mark--br { bottom: 10px; right: 10px; }

  /* The rail: sticky, with a ruler for an underline. Every target in it is at least 44px tall. */
  .rail {
    position: sticky; top: 0; z-index: 20;
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: var(--col-gap);
    block-size: var(--rail-h);
    background: color-mix(in oklch, var(--black) 88%, transparent);
    backdrop-filter: blur(8px);
    font: 500 var(--fs-label) / 1 var(--mono); letter-spacing: var(--track-label); text-transform: uppercase;
    color: var(--ink-2);

    &::after {
      content: ''; position: absolute; bottom: 0; left: 50%; width: 100vw; translate: -50% 0; height: 9px;
      background:
        repeating-linear-gradient(90deg, var(--ink-2) 0 1px, transparent 1px 80px) bottom / 100% 9px no-repeat,
        repeating-linear-gradient(90deg, var(--hair-strong) 0 1px, transparent 1px 8px) bottom / 100% 4px no-repeat,
        linear-gradient(var(--hair), var(--hair)) bottom / 100% 1px no-repeat;
    }
  }
  .rail__mark {
    display: inline-flex; align-items: center; min-block-size: 44px;
    font: 400 1.5rem / 1 var(--serif); letter-spacing: -0.02em; text-transform: none; text-decoration: none; color: var(--ink);
    white-space: nowrap;
    & em { color: var(--accent); }
    & span { color: var(--accent); }
  }
  .rail__title { justify-self: center; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rail__meta {
    justify-self: end; white-space: nowrap;
    & b { color: var(--ink); font-weight: 500; }
    & a { display: inline-flex; align-items: center; min-block-size: 44px; text-decoration: none; }
  }

  /* Rail actions: Add yours (a link to the hub's #add) and the Pause live demos switch */
  .rail__actions { display: flex; align-items: center; gap: 0.375rem; }
  .rail__add, .rail__pause {
    display: inline-flex; align-items: center; gap: 0.55em; min-block-size: 44px; padding-inline: 0.75rem;
    border: 1px solid var(--hair-strong);
    font: inherit; letter-spacing: inherit; text-transform: inherit; color: var(--ink);
    text-decoration: none; white-space: nowrap;
    &:hover { border-color: var(--ink-2); color: var(--ink); }
  }
  .rail__add::before { content: '+' / ''; font-size: 1.35em; line-height: 0; color: var(--accent-text); }
  /* The switch shows its state by shape and fill, not colour: two bars while demos run; a solid
     triangle on an inverted (cream) chip while they are paused. Its name never changes. */
  .rail__pause {
    &::before {
      content: ''; flex: none; inline-size: 9px; block-size: 10px;
      background: linear-gradient(90deg, currentColor 0 3px, transparent 3px 6px, currentColor 6px);
    }
    &[aria-pressed="true"] {
      background: var(--paper); color: var(--paper-ink); border-color: var(--paper);
      &::before { background: currentColor; clip-path: polygon(0 0, 100% 50%, 0 100%); }
    }
  }

  @media (width < 52rem) {
    .rail { grid-template-columns: auto minmax(0, 1fr) auto; }
    .rail__title { display: none; }
  }
  @media (width < 40rem) {
    .rail { gap: 0.5rem; }
    .rail__vol { display: none; }
    .rail__mark { font-size: 1.3rem; }
    .rail__add { padding-inline: 0.6rem; }
    /* The switch keeps its full accessible name ("Pause live demos"); on a phone it shows only its glyph */
    .rail__pause { font-size: 0; gap: 0; padding: 0; inline-size: 44px; justify-content: center; }
  }
  @media (width < 40rem) {
    /* "← All projects" keeps its name; on a phone only the arrow shows */
    .rail__meta a { font-size: 0; }
    .rail__meta a::before { content: '\2190' / ''; font-size: 1.1rem; padding-inline: 0.75rem; }
  }
  @media (width < 22.5rem) {
    .rail__mark { font-size: 1.15rem; }
    .rail__meta { display: none; }   /* the cross-reference at the foot still leads to all projects */
  }

  /* Pause live demos (WCAG 2.2.2): scripts/live.js sets :root[data-paused] and stops the polling;
     this stops skin animation. An !important in the frame layer outranks the skin layer. */
  :root[data-paused] :is([data-skin], [data-live]),
  :root[data-paused] :is([data-skin], [data-live])::before,
  :root[data-paused] :is([data-skin], [data-live])::after,
  :root[data-paused] :is([data-skin], [data-live]) *,
  :root[data-paused] :is([data-skin], [data-live]) *::before,
  :root[data-paused] :is([data-skin], [data-live]) *::after { animation-play-state: paused !important; }

  /* Frame-owned pins inside a skin's stage (SPEC §6): <span data-note="A"></span> */
  [data-skin] [data-note]::before {
    content: attr(data-note);
    font: italic 400 1.25rem / 1 var(--serif); color: var(--accent-text);
  }

  /* Live readout fragment from /demo/status/<slug> */
  .vh-status {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px;
    background: var(--hair); border: 1px solid var(--hair);
    font: 400 var(--fs-mono) / 1.2 var(--mono);
  }
  .vh-status__item { background: var(--black); padding: 0.55rem 0.7rem; display: grid; gap: 0.3rem; }
  .vh-status dt { font-size: var(--fs-label); letter-spacing: var(--track-label); text-transform: uppercase; color: var(--ink-3); }
  .vh-status dd { color: var(--ink); font-variant-numeric: tabular-nums; }
  .vh-status__v--building, .vh-status__v--flaky { color: var(--accent-text); }
  .vh-status__v--passing::before, .vh-status__v--building::before, .vh-status__v--flaky::before {
    content: ''; display: inline-block; inline-size: 0.5em; block-size: 0.5em; margin-inline-end: 0.45em;
    background: currentColor; border-radius: 50%;
  }
  /* Placeholder projects only: a real project (placeholder:false) gets no status widget anywhere (SPEC §6).
     On an example it sits in .vh-sample, captioned as example data. A dashed hairline always means "example". */
  .vh-sample { display: grid; gap: 0.5rem; padding: 0.6rem; border: 1px dashed var(--hair-strong); }
  .vh-sample > figcaption, .vh-example {
    font: 500 var(--fs-label) / 1.3 var(--mono); letter-spacing: var(--track-label); text-transform: uppercase; color: var(--ink-3);
  }
  /* The Example mark on every placeholder (tile, row, sheet, featured fragment): visible, quiet, frame ink */
  .vh-example { display: inline-block; padding: 0.15rem 0.4rem; border: 1px dashed var(--hair-strong); line-height: 1; color: var(--ink-2); white-space: nowrap; }

  /* Colophon */
  .colophon {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: var(--col-gap);
    padding-block: 2rem 3.5rem; margin-block-start: var(--section);
    border-top: 1px solid var(--hair-strong);
    font: 400 var(--fs-label) / 1.6 var(--mono); letter-spacing: 0.06em; color: var(--ink-3);
  }
  /* The back cover: Signal's wordmark, full measure */
  .colophon__mark {
    grid-column: 1 / -1;
    margin-block: 1rem clamp(1.5rem, 4vw, 3rem);
    font: 400 clamp(3rem, 14.5vw, 15rem) / 0.8 var(--serif); letter-spacing: -0.05em;
    color: var(--ink);
    & em { color: var(--accent); }
    & span { color: var(--accent); }
  }
}
