/* ==========================================================================
   field.css — the field of type (field.js), wherever it is used.

   Add data-type-field to any element and set these on it to tune it. The
   values here are the defaults; the home hero overrides some in story.css.
   ========================================================================== */

/* zero specificity: a component that is already positioned (the name gate is
   fixed) keeps its own position; anything else becomes the field's frame */
:where([data-type-field]) {
  position: relative;
  isolation: isolate;
}
[data-type-field] {

  /* size: one character cell and its letter, px (unitless) */
  --grid-cell-w: 4.9;
  --grid-cell-h: 8.5;
  --grid-font: 7;

  /* the grid at rest */
  --grid-ink: var(--ink-faint);
  --grid-alpha: 0.05;
  --grid-ink-panel: var(--on-accent);     /* on a [data-field-panel] */
  --grid-alpha-panel: 0.12;

  /* the pointer and the scroll */
  --stir-radius: 90;                     /* the cursor spotlight's reach, px */
  --scroll-sparks: 0;                     /* single cells lit per fast scroll step (0 = off) */

  /* the stars: random characters that slowly brighten and fade */
  --twinkle-ink: var(--ink);
  --twinkle-ink-panel: var(--grid-ink-panel);
  --twinkle-alpha: 0.45;                  /* how bright a star gets, 0–1 (0 = off) */
  --twinkle-density: 0.006;               /* share of cells lit at once (0.006 = 0.6%) */
  --twinkle-time: 2.8;                    /* seconds a star takes to come and go */

  /* the layer: -1 sits behind the element's content */
  --field-z: -1;
}
@media (min-width: 600px) {
  [data-type-field] {
    --grid-cell-w: 5.6;
    --grid-cell-h: 9.5;
    --grid-font: 8;
  }
}

.type-field {
  position: absolute;
  inset: 0;
  z-index: var(--field-z);
  pointer-events: none;
}
/* the name gate covers the page: fields under it rest (field.js), and are
   hidden; the gate's own field is the one that shows */
html[data-gate="ask"] .type-field:not(.gate .type-field),
html[data-gate="leaving"] .type-field:not(.gate .type-field) { visibility: hidden; }

/* a face drawn by the field: its SVG keeps the space and steps aside */
.type-field--drawn [data-field-face] { visibility: hidden; }

/* stars only: the twinkle without the grid, the spotlight or the sparks.
   Used on the light chapter after the hero (dark stars on the light). */
[data-type-field].stars-only {
  --grid-alpha: 0;
  --grid-alpha-panel: 0;
  --stir-radius: 0;
  --scroll-sparks: 0;
  --twinkle-alpha: 0.35;          /* peak of a star, 0–1 */
}

/* pinned (data-field-pin): one screen of field that stays in place while the
   element scrolls past, and leaves with its bottom edge */
[data-field-pin] { overflow: clip; }   /* the field leaves with the element, never past its edge */
.type-field.type-field--pinned {
  position: sticky;
  top: 0;
  display: block;
}
