/* Frost-over for HUD text. Owned by fx/frost.js.

   Mark any HUD text with [data-ice]. fx/frost.js drives:
     --frost      on <html>, 0..1 eased coverage of the whole pane
     --thaw-dir   on <html>, 1 (melting down/forward) or -1 (up/back)
     --frost-l    inline on each [data-ice] element: its LOCAL frost, so a
                  label ices when the crystals reach its corner and melts the
                  moment the wipe passes it (falls back to --frost)
     .is-frosted  on <html> while any frost is on the glass

   Everything is a pure function of the variables: no transitions, so the
   text never lags the shader. Nothing here changes layout except the
   letter-spacing creep, which is tiny and only affects the label's own box.

   Optional hooks for the HUD author:
     --ice-ink    base text colour if you set `color` on the [data-ice]
                  element itself (otherwise the inherited colour is used)
     --ice-ls     base letter-spacing (default 0em); the creep adds to it
   Colour and letter-spacing use :where() (zero specificity), so any HUD rule
   wins over them; set the two hooks above to keep the effect. The halo and
   blur are frost-owned and apply at normal specificity. */

:root {
  --frost-ice: #dff3fb;      /* the pale rime colour */
  --frost-glow: 206 236 248; /* halo rgb */
}

[data-ice] {
  --_f: var(--frost-l, var(--frost, 0));
  /* rime crust on the upper edges, a tight cold rim, then a soft halo */
  text-shadow:
    0 calc(var(--_f) * -0.045em) 0 rgb(246 252 255 / calc(var(--_f) * 0.75)),
    0 0 calc(var(--_f) * 0.07em) rgb(236 248 255 / calc(var(--_f) * 0.9)),
    0 0 calc(var(--_f) * 0.55em) rgb(var(--frost-glow) / calc(var(--_f) * 0.5)),
    0 0 calc(var(--_f) * 1.6em) rgb(var(--frost-glow) / calc(var(--_f) * 0.28)),
    /* the HUD's own legibility halo (ice.css / crystals.css set --ice-halo) */
    var(--ice-halo, 0 0 0 transparent);
}

/* Long copy keeps the frost character but stays readable while someone stands
   still to read it: at most ~35% of the effect, and never blurred. HUD labels
   and mono rows keep the full effect. */
.beat__line[data-ice] {
  --_f: calc(var(--frost-l, var(--frost, 0)) * 0.35);
}
.is-frosted .beat__line[data-ice] { filter: none; }

:where([data-ice]) {
  /* drift toward ice, but only 30%: dark ink stays legible on the frosted
     (now paler) corners, light ink barely changes on the night legs */
  color: color-mix(in oklab, var(--ice-ink, currentColor) calc(100% - var(--_f) * 30%), #9fd2e8);
  letter-spacing: calc(var(--ice-ls, 0em) + var(--_f) * 0.035em);
}

/* a hair of blur only while frost is on the glass (a filter would otherwise
   create a stacking context on every label all the time) */
.is-frosted [data-ice] {
  filter: blur(calc(var(--_f) * 0.32px));
}

@media (prefers-reduced-motion: reduce) {
  .is-frosted [data-ice] { filter: none; }
}
