/* =============================================================================
   MATERIAL — how a surface is physically drawn.

   ONE class, two materials. `.mat` is glass under [data-family="glass"] and a
   solid card under [data-family="traditional"]. Components mark up a surface
   once and never learn which family is active — that is the whole reason a
   family switch costs nothing at the component layer.

   Elevation is `data-level="0|1|2|3"`. Higher means closer to the viewer: more
   tint, a harder rim, a longer shadow.

   TWO RULES YOU MUST NOT BREAK
   ----------------------------
   1. GLASS CANNOT SAMPLE GLASS. A backdrop-filter samples what is painted
      behind it, and that includes another backdrop-filter — so nested glass
      compounds the blur into grey mush and stacks the rims into a double edge.
      Apple's own guidance says the same: a container provides the sampling
      region and its children draw flat on top of it.

      Use `.mat` for the outermost floating surface, and `.mat-inset` for
      anything inside it that needs to read as a separate plane. Nesting is
      neutralised below rather than trusted to discipline — but see the note on
      that rule, because neutralising it badly is its own bug.

   2. NEVER WRITE A CUSTOM PROPERTY FROM ITSELF. `--glass-tint-alpha:
      calc(var(--glass-tint-alpha) + 0.08)` looks like a nudge and is a
      dependency cycle: every property in a cycle computes to the
      guaranteed-invalid value, and every property that substitutes it becomes
      invalid at computed-value time. Measured in Chrome 148, that one line
      turned `background-color` into `rgba(0, 0, 0, 0)` and the entire
      five-layer `box-shadow` into `none`.

      Hover, press and elevation therefore write SEPARATE delta properties —
      `--glass-tint-delta`, `--glass-rim-top-delta`, `--glass-shadow-2-boost` —
      which the base rule folds in. Same effect, no cycle.

   A NOTE ON COST
   --------------
   A `.mat` is a backdrop sample, a blended noise layer and a sheen layer.
   Twenty-seven of them on one page measured up to 46 ms per scroll repaint here,
   against 21 ms once all but three became `.mat-inset`. So `.mat` is for the
   few surfaces genuinely floating over something; anything repeated in a grid
   is a `.mat-inset` on the page ground.
   ========================================================================== */

@layer eduai.material {
  /* ⚠ `border: 0` IS LEAD, NOT TIDYING. The rim is `box-shadow`, so the material
     never sets `border` — and `<dialog>` and `<fieldset>` arrive from the UA
     stylesheet with one anyway, in `currentColor`. On the dialog that measured a
     2.4px solid `#F5F5F7` frame drawn over a 1px 37%-white rim: two edges, the
     wrong one twice as thick and twenty times as bright, and the corner radius
     eaten by it. Forced colours restores a real border below, and that rule
     comes later in this layer, so it still wins. */
  .mat {
    position: relative;
    border: 0;
    /* THE CARD RADIUS. Every content surface in the prototype - panel, tile,
       sheet body - is `--r-card`, and 22 is the chrome radius the sidebar and
       the topbar restate for themselves. */
    border-radius: var(--r-md);
    color: var(--text);
    transition:
      background-color var(--dur-base) var(--ease-out),
      box-shadow var(--dur-base) var(--ease-out),
      transform var(--dur-fast) var(--ease-out);
  }

  /* Superellipse corners where the browser has them. Circular arcs elsewhere,
     which is the correct fallback rather than a broken one. */
  @supports (corner-shape: squircle) {
    .mat,
    .mat-inset,
    .btn,
    .field {
      corner-shape: superellipse(calc(2 + var(--glass-corner-smooth) * 2));
    }

    /* ⚠ ROUND IN THE GLASS FAMILY (owner, 2026-10-03), as liqui draws every surface. At
       `superellipse(4)` a 22px card corner reads like a circular 8px one - the radius
       computes the same and the curve hugs the box corner - so the cards and buttons
       rendered visibly squarer than the approved prototype. The traditional family keeps
       its superellipse. */
    [data-family="glass"] :is(.mat, .mat-inset, .btn, .field) {
      corner-shape: round;
    }
  }

  /* ---------------------------------------------------------------------------
     GLASS
     ------------------------------------------------------------------------ */

  [data-family="glass"] .mat,
  [data-family="glass"] :is(.mat-inset, .empty-state, .table-scroll):not(.mat *):not(.mat-inset *) {
    /* ⚠ THE CONTAINING BLOCK FOR THE SPECULAR AND GRAIN LAYERS, AND WITHOUT IT
       THEY ESCAPE THE SURFACE ENTIRELY. Both are `position: absolute; inset: 0`
       (see ::before and ::after below), which resolves against the nearest
       POSITIONED ancestor — and `.mat` sets `position: relative` in the base
       layer while `.mat-inset` never has.

       Measured on the landing page 2026-09-26: each `.lp-card.mat-inset` is
       395x151, and its ::before computed to 1248x732 — the size of the section
       that happened to be `position: relative`. Three cards each painted that
       full-section rectangle at 0.18 opacity in `screen` blend, and stacked
       they read as a washed-out grey panel over the whole feature block.

       It hid inside the app because an inset there sits within a `.mat`, which
       `:not(.mat *)` excludes from these rules — so the layers are not drawn at
       all and there is nothing to escape. The landing page is the first place a
       glass inset sits directly on the page ground. */
    position: relative;
    /* The effective tint, folded once and read three times below.

       `max()` against the nested floor is what lets a popover inside another
       glass surface stay legible: it cannot blur (rule 1), so it has nothing to
       quiet the page behind it, and the tint has to carry that alone. Without
       the floor a level-3 menu inside the topbar rendered at 30% opacity over
       unblurred page text.

       The reduce-transparency fold is the second half: at 1 the surface becomes
       genuinely opaque, not merely frostier. */
    /* ⚠ THE LADDER IS A MULTIPLE OF THE MODE'S OWN TINT, NOT AN ABSOLUTE ALPHA.
       It used to be absolute - level 2 was a flat 0.68 - and that only worked
       while the dark tint was a near-black, where 0.68 of it still reads dark.
       The tint is white in both modes now, and a flat 0.68 turned a level-2
       surface into #ADB1B8: the render gate measured `--text` on it at 1.98
       against a 4.5 threshold, on six elements at once.

       As a multiple it scales with whichever tint the mode actually has. Dark
       base 0.07 gives 0.14 and 0.20 at the top of the ladder, which lands near
       `--surface-2` and `--surface-3` - the same places the opaque family puts
       those levels. Light base 0.30 gives 0.60 and 0.84, unchanged in feel.

       `--glass-tint-step` is a SEPARATE property folded in here rather than a
       write back into `--glass-tint-alpha`; see rule 2 in the header. */
    --tint-fold: max(
      calc(var(--glass-tint-alpha) * var(--glass-tint-step, 1) + var(--glass-tint-delta)),
      calc(var(--glass-tint-alpha) * var(--glass-nested-mult, 0))
    );

    /* ⚠ THE LIQUI MATERIAL (owner, 2026-10-03). The tint is liqui's: a 135-degree gradient
       from `--lq-tint` to `--lq-tint-deep`, scaled by `--lq-tier` - liqui's own
       `0.25 + 0.75 * frost` at its default frost of 0.35, i.e. 0.5125. It is painted in
       `background-image` below, with the sheen. `--tint-fold` above is kept for the studio;
       on glass it no longer reaches paint.

       What `background-color` carries now is only the reduce-transparency floor: at 0 it
       is clear, at 1 it is the opaque surface, so a viewer who asked the OS for less
       transparency still gets a solid pane under the same tint. */
    --lq-tier: 0.5125;
    /* 0 here; the clear tier and every nested pane set 1. See `--lq-wash` in tokens.css. */
    --lq-wash-on: 0;
    /* liqui's catch-light rim, three inset hairlines: lit top, half-lit left, dim
       bottom-right. Every glass surface carries it. */
    --lq-shine:
      inset 0 1px 1px var(--lq-rim-hi),
      inset 1px 0 1px var(--lq-rim-spread) color-mix(in srgb, var(--lq-rim-hi) 60%, transparent),
      inset -1px -1px 1px var(--lq-rim-lo);
    /* Nothing by default. A surface that floats - the shell chrome, a dialog, a menu -
       sets this to `--lq-shadow` through its level. liqui draws no drop shadow under a
       panel that sits on the page, and neither does this. */
    --lq-elevation: 0 0 0 0 transparent;
    background-color: color-mix(
      in oklab,
      var(--surface-1) calc(var(--a11y-reduce-transparency) * 100%),
      transparent
    );
    /* liqui's panel radius - 22px, the chrome radius - rather than the 16px control
       radius `.mat` takes in the traditional family. */
    border-radius: var(--r-lg);

    /* THE LENS IS APPENDED, NOT SUBSTITUTED. `--glass-lens` is written per
       element by the refraction driver and defaults to nothing, so a surface it
       has not reached — or a browser that cannot refract at all — keeps exactly
       this frosted chain rather than losing it. Safari drops the WHOLE
       backdrop-filter value when it sees an SVG reference anywhere in it, which
       is why the driver refuses to write the property there at all. */
    /* ⚠ NO HAND-WRITTEN WEBKIT-PREFIXED COPY OF THIS PROPERTY, ANYWHERE IN THE CODEBASE. The build minifies
       with lightningcss, which treats the prefixed and unprefixed pair as one property and keeps
       the LAST - so a `-webkit-` line under this one shipped alone, Chrome ignored it, and every
       glass surface in production computed `backdrop-filter: none` (found live 2026-09-29, after
       the tint went to 0 and nothing was left to hide it). Written once, unprefixed, lightningcss
       adds the `-webkit-` copy itself for the Safari targets. `theme/materialCss.test.ts` holds it. */
    /* `--lq-blur-scale` and `--lq-blur-floor` are liqui's frost rule - twice the blur,
       never under 10px - written as SEPARATE properties so the frost tier never writes
       `--glass-blur` from itself (rule 2 in the header). */
    backdrop-filter:
      blur(calc(max(var(--glass-blur) * var(--lq-blur-scale, 1), var(--lq-blur-floor, 0px)) * (1 - var(--a11y-reduce-transparency) * 0.999)))
      saturate(var(--glass-saturate))
      brightness(var(--glass-brightness))
      contrast(var(--glass-contrast))
      var(--glass-lens, );

    /* liqui's rim and liqui's shadow. The five-layer stack that stood here - hairline,
       top highlight, bottom lift, contact and ambient - is replaced, not added to: two
       rims drawn over one edge read as a moulded bezel, which the owner had already
       taken off the dialog for exactly that reason. */
    box-shadow: var(--lq-shine), var(--lq-elevation);

    /* The sheen lives on the ELEMENT, not on a pseudo-element, and that is not
       an aesthetic choice — it is what leaves `::before` free to carry the
       specular arc at its own opacity. Putting both on one layer meant the arc
       inherited that layer's opacity of 1 and rendered at full strength: a
       blown-out white halo around every card, against the 0.42 the knob asks
       for. A background-image paints above background-color, so the sheen sits
       exactly where it did.

       Its alpha is folded through reduce-transparency here rather than by a
       layer opacity, for the same reason. */
    background-image:
      linear-gradient(
        var(--glass-sheen-angle),
        rgb(var(--light-rgb) / calc(var(--glass-sheen-alpha) * (1 - var(--a11y-reduce-transparency)))) 0%,
        rgb(var(--light-rgb) / 0) var(--glass-sheen-size)
      ),
      /* liqui's tint */
      linear-gradient(
        135deg,
        color-mix(in srgb, var(--lq-tint) calc(var(--lq-tier) * 100%), transparent),
        color-mix(in srgb, var(--lq-tint-deep) calc(var(--lq-tier) * 100%), transparent)
      ),
      /* liqui's clear wash, under the tint - only where `--lq-wash-on` is 1 */
      linear-gradient(
        135deg,
        color-mix(in srgb, var(--lq-wash) calc(var(--lq-wash-on) * 100%), transparent),
        color-mix(in srgb, var(--lq-wash-deep) calc(var(--lq-wash-on) * 100%), transparent)
      );

    /* THE QUIETEST TIER STEPS UP ONE ON TRANSLUCENT GROUND. Tertiary text is
       tuned against the opaque surfaces the contrast lock knows about; on glass
       the ground is whatever the page painted behind it, and the render gate put
       `--text-tertiary` at 4.08 against a 4.5 threshold over a decorative
       backdrop. Measured in the prototype for comparison: the same pair, the same
       backdrop, 4.08 there too - it is a property of the values, not of this
       implementation, and it stays hidden only while the scene behind a card
       happens to be dark.

       So inside a glass surface the tertiary role resolves to the secondary one.
       That is one step of grey - #98989F to #A1A1A6, all but invisible - and it
       is what makes the pair measurable instead of dependent on the wallpaper.
       Opaque surfaces are untouched: they keep the tier the lock priced. */
    --text-tertiary: var(--text-secondary);

    /* Paint containment. backdrop-filter is the most expensive thing in this
       stylesheet; bounding it keeps rasterisation off the rest of the page. */
    isolation: isolate;
  }

  /* The specular arc — the band of light along the bezel that makes the rim
     read as polished glass rather than merely transparent.

     Written per element by the refraction driver, because it is generated from
     the same rounded-rect distance field as the displacement map and is
     therefore a function of the surface's own size. Defaults to `none`, so a
     surface the driver has not reached, a frosted tier and every non-Chromium
     browser all simply do not draw it. */
  [data-family="glass"] .mat::before,
  [data-family="glass"] :is(.mat-inset, .empty-state, .table-scroll):not(.mat *):not(.mat-inset *)::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    /* ⚠ THE SHAPE HAS TO COME WITH THE RADIUS. `corner-shape` is not inherited and `.mat::before`
       is not in the list that sets it, so this layer drew CIRCULAR corners inside a box drawn with
       superellipse(4) ones - a second curve up to 4px off the first, lit by the specular line. */
    corner-shape: inherit;
    pointer-events: none;
    opacity: calc(var(--glass-specular) * (1 - var(--a11y-reduce-transparency)));
    /* SCREEN, NOT NORMAL. The specular image is a lit arc on a dark field, so
       painting it normally lays the whole field down as well - against the old
       near-black tint that was invisible, and the moment the tint went white it
       showed as a hard ghost rectangle inside every card. `screen` takes only
       the light out of it and can never darken, which is what a highlight is
       and what the prototype has always used here. */
    mix-blend-mode: screen;
    background-image: var(--glass-specular-image, none);
    background-size: 100% 100%;
    background-repeat: no-repeat;
  }

  /* Grain. backdrop-filter bands badly across wide gradients; a couple of
     percent of noise hides it and costs nothing. */
  [data-family="glass"] .mat::after,
  [data-family="glass"] :is(.mat-inset, .empty-state, .table-scroll):not(.mat *):not(.mat-inset *)::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    corner-shape: inherit;
    pointer-events: none;
    opacity: calc(var(--glass-noise-alpha) * (1 - var(--a11y-reduce-transparency)));
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
  }

  /* --- rendering tiers ----------------------------------------------------
     `auto` is the rule above. These two are the downgrades, exposed so a slow
     device or a person who does not want the effect can step down without
     leaving the theme. `frost` is also what every non-Chromium browser gets by
     default, so it is a tier the design has to work in regardless.            */

  [data-tier="frost"] .mat,
  [data-tier="frost"] :is(.mat-inset, .empty-state, .table-scroll):not(.mat *):not(.mat-inset *) {
    --glass-lens: ;
    --glass-specular-image: none;
    /* liqui's frost: `max(blur * 2, 10px)`. With no lens to carry the edge, the heavier
       frost is what reads as glass - and it is the owner's default tier (2026-10-03). */
    --lq-blur-scale: 2;
    --lq-blur-floor: var(--lq-frost-floor);
  }

  [data-tier="clear"] .mat,
  [data-tier="clear"] :is(.mat-inset, .empty-state, .table-scroll):not(.mat *):not(.mat-inset *) {
    --glass-lens: ;
    --glass-specular-image: none;
    backdrop-filter: none;
    /* No blur to carry legibility, so the tint has to - liqui's clear tier runs the tint
       at full strength over a neutral wash. Same reasoning as the nested case. */
    --glass-nested-mult: 2.8;
    --lq-tier: 1;
    --lq-wash-on: 1;
  }
  [data-tier="clear"] .mat::after,
  [data-tier="clear"] :is(.mat-inset, .empty-state, .table-scroll):not(.mat *):not(.mat-inset *)::after {
    display: none;
  }

  /* --- elevation ----------------------------------------------------------
     `--glass-shadow-2-boost` rather than multiplying the alpha by itself. See
     rule 2 in the header.                                                     */

  /* ⚠ LEVEL 0 IS NOT FLOATING GLASS, so it does not get a backdrop sample.
     It is the FLAT plane - no elevation, no shadow - and the traditional arm
     below already learned what that means for text: a plane that shows the page
     through itself sits on whatever the page happens to have painted THERE, and
     the compiler cannot lock a contrast ratio against an unknown ground. The
     note under `[data-family="traditional"] .mat[data-level="0"]` records the
     measurement that forced it.

     Glass had the same hole and it stayed hidden only while the tint was a
     near-black, which darkened the composite enough to carry the quietest text
     by accident. With a white tint the accident stopped: the render gate put
     `--text-tertiary` at 4.08 in the dark and 4.41 in the light against a 4.5
     threshold, on a level-0 surface over a decorative backdrop.

     So level 0 paints `--surface-1` and stops sampling. It keeps the rim and the
     radius, so it still belongs to the material - it simply is not a pane with
     anything behind it. Nothing in the product asks for this level today; the
     theme studio does, and it is the surface a future flat panel would use. */
  [data-family="glass"] .mat[data-level="0"] {
    --glass-tint-step: 0;
    --glass-shadow-2-alpha: 0;
    --glass-shadow-1-alpha: 0;
    --glass-lens: ;
    --glass-specular-image: none;
    background-color: var(--surface-1);
    backdrop-filter: none;
  }
  /* ⚠ A LEVEL ON A `.mat` IS WHAT MAKES IT FLOAT. The shell's sidebar and top bar carry
     `data-level="1"`, a dialog `2`, a menu `3`: those take liqui's elevated shadow. A
     panel with no level is a pane on the page and takes the rim only, as liqui's
     non-elevated surfaces do. */
  [data-family="glass"] .mat:is([data-level="1"], [data-level="2"], [data-level="3"]) {
    --lq-elevation: var(--lq-shadow);
  }
  [data-family="glass"] .mat[data-level="2"] {
    --glass-tint-step: 2;
    --glass-shadow-2-y: 20px;
    --glass-shadow-2-blur: 48px;
  }
  [data-family="glass"] .mat[data-level="3"] {
    --glass-tint-step: 2.8;
    --glass-blur: 40px;
    --glass-shadow-2-y: 32px;
    --glass-shadow-2-blur: 72px;
    --glass-shadow-2-boost: 1.4;
  }

  /* --- nesting ------------------------------------------------------------
     Neutralise the BLUR, and nothing else.

     The previous version of this rule also replaced the box-shadow with a
     single hairline and pinned the tint to a flat 30%. That is what the only
     `data-level="3"` surface in the app — the account menu, which lives inside
     the topbar `.mat` — actually rendered as: a dropdown at 30% opacity with no
     drop shadow at all, floating over unblurred page text. Everything the
     level-3 rule set was written and then read by nothing.

     A nested surface still needs its elevation, its rim and its shadow. What it
     cannot have is a backdrop sample. So: drop the filter and the lens, raise
     the tint floor to compensate for the blur it is not allowed to have, and
     leave the rest of the material alone.                                     */

  [data-family="glass"] .mat .mat {
    backdrop-filter: none;
    --glass-lens: ;
    --glass-specular-image: none;
    --glass-nested-mult: 3;
    /* It cannot blur, so it reads the way liqui's clear tier does. */
    --lq-tier: 1;
    --lq-wash-on: 1;
  }
  /* The grain exists to hide backdrop-filter's banding. With no backdrop filter
     there is no banding, and the noise is just noise. */
  [data-family="glass"] .mat .mat::after {
    display: none;
  }

  /* ---------------------------------------------------------------------------
     TRADITIONAL
     Solid, bordered, quietly shadowed. Not "glass with the blur turned off" —
     a different material with its own elevation logic.
     ------------------------------------------------------------------------ */

  [data-family="traditional"] .mat {
    background-color: var(--surface-1);
    border: var(--solid-border-width) solid
      color-mix(in oklab, var(--border) calc(var(--solid-border-alpha) * 100%), transparent);
    box-shadow:
      0 var(--solid-shadow-1-y) var(--solid-shadow-1-blur) rgb(var(--shadow-rgb) / var(--solid-shadow-1-alpha)),
      0 var(--solid-shadow-2-y) var(--solid-shadow-2-blur)
        rgb(var(--shadow-rgb) / calc(var(--solid-shadow-2-alpha) * var(--glass-shadow-2-boost)));
  }

  /* ⚠ THE PAGE COLOUR, NOT `transparent`. Level 0 is the flat plane — no elevation, no
     shadow — and painting nothing was the obvious way to say so. It has one consequence
     that is invisible until something is measured: text on a transparent plane sits on
     whatever the page happens to have painted THERE, which the theme compiler cannot
     know and therefore cannot lock a contrast ratio against.

     The render gate caught it. `--text-tertiary` on a level-0 mat over a decorative
     backdrop measured 4.62 against a 4.5 threshold on one rasteriser and 4.08 on
     another — the same element, the same colours, differing only in how the glyphs were
     antialiased. Headroom that thin is not a pass, it is a coin toss.

     `--bg` is the fix rather than `--surface-1` because it keeps the appearance: level 0
     showed the page through itself, and now it paints the page instead. What changes is
     only the case that was broken — over a coloured backdrop it stays the page colour
     rather than letting an unknown ground reach the type. And `--bg` is the FIRST of the
     grounds `runtime.ts` locks every text role against, so the ratio is now guaranteed by
     the same measurement that guarantees the rest. */
  [data-family="traditional"] .mat[data-level="0"] {
    background-color: var(--bg);
    box-shadow: none;
  }
  [data-family="traditional"] .mat[data-level="2"] {
    background-color: var(--surface-2);
    box-shadow:
      0 calc(var(--solid-shadow-1-y) * 2) calc(var(--solid-shadow-1-blur) * 2)
        rgb(var(--shadow-rgb) / calc(var(--solid-shadow-1-alpha) * 1.4)),
      0 calc(var(--solid-shadow-2-y) * 2) calc(var(--solid-shadow-2-blur) * 2)
        rgb(var(--shadow-rgb) / calc(var(--solid-shadow-2-alpha) * 1.6));
  }
  [data-family="traditional"] .mat[data-level="3"] {
    background-color: var(--surface-2);
    box-shadow:
      0 calc(var(--solid-shadow-1-y) * 4) calc(var(--solid-shadow-1-blur) * 4)
        rgb(var(--shadow-rgb) / calc(var(--solid-shadow-1-alpha) * 1.6)),
      0 calc(var(--solid-shadow-2-y) * 4) calc(var(--solid-shadow-2-blur) * 4)
        rgb(var(--shadow-rgb) / calc(var(--solid-shadow-2-alpha) * 2));
  }

  /* ---------------------------------------------------------------------------
     INSET — a plane *inside* a material. Safe to nest; never blurs.
     ------------------------------------------------------------------------ */

  .mat-inset {
    border-radius: var(--r-md);
    background-color: var(--surface-sunken);
  }

  /* THE BORDER IS THE NESTED CASE'S ALONE. An inset inside a material gets no rim
     from the rules above — they do not select it — so a real border is the only
     edge it can have. An inset on the page ground IS selected by them, rim and
     all, and a border there is a second line drawn on top of the first: the
     filter bar measured a 0.8px solid 37%-white border over a 1px 37%-white
     inset rim, which is the same doubling the dialog had. */
  :is(.mat, .mat-inset) .mat-inset {
    border: 1px solid var(--border-subtle);
  }
  /* An inner plane is opaque, and that is the prototype's answer too: every
     alert and every list row inside a panel there is a solid `--surface-2`. A
     tint mix would now light it up, since the tint is white in both modes. */
  [data-family="glass"] .mat-inset {
    background-color: var(--surface-2);
  }
  /* THE OWNER'S CALL, 2026-10-18: no fill. An inner plane inside a glass material
     drew a solid `--surface-2` - near-white in light, slate in dark - and read as a
     white card pasted behind the text. It now lets the material it sits in show
     through and keeps only its edge. It still never blurs: glass cannot sample glass. */
  [data-family="glass"] :is(.mat, .mat-inset) .mat-inset {
    background-color: transparent;
    border-color: rgb(var(--light-rgb) / calc(var(--glass-edge-alpha) * 0.8));
  }
  /* An inset that is not inside anything is not an inset. It is the outermost
     floating surface on the page ground, rule 1 does not apply to it, and the
     rules above therefore draw it as the full material — blur, rim, lens and
     all. That is what the prototype does with every card on the page, and it is
     why a stat tile now reads as glass rather than as a flat tint on the scene.

     It needs nothing else from here. Its edge is the rim those rules draw, the
     same one `.mat` has, and the border that used to be added on top of it is
     gone — see the nested-only border above. */

  /* ---------------------------------------------------------------------------
     INTERACTION
     Glass responds to a press by getting momentarily denser and lifting — the
     same gesture a physical button makes. Traditional just tints.
     ------------------------------------------------------------------------ */

  .mat--interactive {
    cursor: pointer;
  }

  [data-family="glass"] .mat--interactive:hover {
    --glass-tint-delta: 0.08;
    --glass-rim-top-delta: 0.12;
    --lq-tier: 0.7;
  }
  [data-family="glass"] .mat--interactive:active {
    --glass-tint-delta: 0.12;
    --lq-tier: 0.8;
    transform: scale(0.985);
  }
  [data-family="traditional"] .mat--interactive:hover {
    background-color: var(--surface-2);
  }
  [data-family="traditional"] .mat--interactive:active {
    background-color: var(--surface-3);
  }

  /* ---------------------------------------------------------------------------
     FORCED COLOURS

     Windows high contrast replaces every author colour with a system one and,
     critically, does not paint box-shadows at all. Since every boundary in this
     material is a shadow rim or a translucent tint, a card, a dialog, a panel
     and the account menu all become unbounded blocks of text — the structure of
     the page disappears entirely.

     So in forced-colors the material stops being glass and becomes what the
     mode is actually built for: a real border in a system colour.
     ------------------------------------------------------------------------ */

  @media (forced-colors: active) {
    .mat,
    .mat-inset {
      background-color: Canvas;
      border: 1px solid CanvasText;
      box-shadow: none;
      backdrop-filter: none;
      forced-color-adjust: none;
      color: CanvasText;
    }
    .mat::before,
    .mat::after {
      display: none;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .mat,
    .mat--interactive:active {
      transition: none;
      transform: none;
    }
  }

  /* ⚠ THE QUIET TEXT STEPS DOWN ONE IN LIGHT GLASS (2026-10-03), as liqui's own secondary
     text does (`--lq-text-dim`). The compiler locks `--text-secondary` and the field
     placeholder against OPAQUE grounds - `--bg`, `--surface-1` - and in the glass family
     neither is what sits under text any more: it is liqui's backdrop, or a frosted pane
     over it. Measured on the render with the liqui material, light mode: dialog labels at
     3.72 to 4.5, the date placeholder at 3.6, page placeholders at 3.4 to 3.7.

     Derived, not typed: half way from the secondary role to the primary one in OKLab, so
     it follows a reseeded palette and stays a step quieter than body text. Dark mode is
     untouched - every pair there measured above 4.5 as shipped. */
  /* ⚠ TWO STEPS, NOT ONE, BECAUSE OF RULE 2 IN THE HEADER. `--text-secondary` lives on the
     root, and redefining it there from itself is a dependency cycle - the property would
     compute to nothing. So the stepped-down values are composed on the root under their
     own names, and `body` - a different element - points the two roles at them. */
  [data-family="glass"][data-mode="light"] {
    --lq-text-dim: color-mix(in oklab, var(--text-secondary) 50%, var(--text));
    --lq-placeholder: color-mix(in oklab, var(--field-placeholder) 50%, var(--text));
  }
  [data-family="glass"][data-mode="light"] body {
    --text-secondary: var(--lq-text-dim);
    --field-placeholder: var(--lq-placeholder);
    /* The tertiary tier resolves to the secondary one, as it already does inside every
       glass surface (see the glass arm above) - and for the same reason: the page ground
       is liqui's backdrop now, not the opaque `--bg` the tier was priced against. A
       `.tiny` line on the page measured 3.69 without this. */
    --text-tertiary: var(--lq-text-dim);
  }

  /* ---------------------------------------------------------------------------
     THE BACKDROP - liqui's, copied (owner, 2026-10-03).

     Glass is only legible as glass where there is something behind it with edges.
     A flat page under a frosted pane reads as a grey rectangle; the same pane over a
     near-white ground with soft colour and still rules reads as a sheet you can see
     through. `GlassBackdrop.tsx` renders these five layers once, fixed behind the
     whole document, in the glass family only. Colours are tokens (tokens.css,
     `--bd-*`); the colour fields are the only layer that moves, and not at all under
     reduced motion.
     ------------------------------------------------------------------------ */
  .glass-backdrop {
    position: fixed;
    inset: 0;
    z-index: -10;
    overflow: hidden;
    background-color: var(--bd-base);
    pointer-events: none;
  }

  .glass-backdrop__aurora {
    position: absolute;
    inset: -30%;
    background-image:
      radial-gradient(38% 34% at 18% 22%, var(--bd-aurora-1) 0%, transparent 62%),
      radial-gradient(34% 32% at 82% 18%, var(--bd-aurora-2) 0%, transparent 60%),
      radial-gradient(42% 38% at 72% 78%, var(--bd-aurora-3) 0%, transparent 64%),
      radial-gradient(30% 28% at 28% 88%, var(--bd-aurora-4) 0%, transparent 58%);
    opacity: var(--bd-aurora-strength);
    animation: glass-backdrop-drift calc(var(--dur-indicator) * 58) var(--ease-in-out) infinite alternate;
    will-change: transform;
  }

  /* The grid is what makes the refraction legible: a line under a lens bends. */
  .glass-backdrop__rules {
    position: absolute;
    inset: 0;
    background-image:
      repeating-linear-gradient(to right, var(--bd-rule) 0 1px, transparent 1px var(--bd-grid)),
      repeating-linear-gradient(to bottom, var(--bd-rule) 0 1px, transparent 1px var(--bd-grid));
    mask-image: radial-gradient(120% 90% at 50% 30%, black 30%, transparent 92%);
  }

  .glass-backdrop__rings {
    position: absolute;
    top: -18vmax;
    right: -14vmax;
    width: 78vmax;
    height: 78vmax;
    border-radius: 50%;
    background-image: repeating-radial-gradient(
      circle at center,
      var(--bd-rule-strong) 0 var(--bd-ring-line),
      transparent var(--bd-ring-line) 5.4vmax
    );
    mask-image: radial-gradient(circle at center, black 42%, transparent 72%);
  }

  .glass-backdrop__band {
    position: absolute;
    inset-inline: -20%;
    bottom: 12%;
    height: 26vmax;
    background-image: repeating-linear-gradient(
      108deg,
      var(--bd-rule-strong) 0 var(--bd-band-line),
      transparent var(--bd-band-line) 3.2vmax
    );
    mask-image: linear-gradient(to bottom, transparent, black 45%, transparent);
  }

  .glass-backdrop__vignette {
    position: absolute;
    inset: 0;
    background-image: radial-gradient(130% 110% at 50% 0%, transparent 45%, var(--bd-vignette) 100%);
  }

  @media (prefers-reduced-motion: reduce) {
    .glass-backdrop__aurora {
      animation: none;
    }
  }
}

@keyframes glass-backdrop-drift {
  from {
    transform: translate3d(0, 0, 0) scale(1.04) rotate(0deg);
  }
  to {
    transform: translate3d(-4%, 3%, 0) scale(1.16) rotate(4deg);
  }
}
