/* =====================================================================
   Liquid Glass kit — material (CSS)
   Pair with liquid-glass.js. Works on its own as CSS-only glass in every
   browser; the JS adds background adaptation and the Chromium rim lens.

   Use:  <div class="glass">…</div>
   Variants:  .glass--frost   thicker slab for busy / moving backgrounds
              .glass--heavy   thickest, for dialogs and forms
              .glass--tint    accent-coloured glass with fixed white ink
   Theme:  <html data-theme="light|dark">  (liquid-glass.js sets it if missing)
   ===================================================================== */

/* ---------- Settings you may override on :root ---------- */
:root{
  --glass-scale-light:1.1;   /* tint strength, light mode (0–1.5; 1 = as designed) */
  --glass-scale-dark:.85;    /* tint strength, dark mode */
  --glass-accent-r:150; --glass-accent-g:58; --glass-accent-b:16;  /* .glass--tint colour (keep white text ≥ 4.5:1) */
  --glass-scale:var(--glass-scale-light);
}
[data-theme="dark"]{ --glass-scale:var(--glass-scale-dark); }

/* ---------- Registered tokens: surfaces glide between states ---------- */
@property --g-r      {syntax:'<number>';inherits:true;initial-value:255}
@property --g-g      {syntax:'<number>';inherits:true;initial-value:255}
@property --g-b      {syntax:'<number>';inherits:true;initial-value:255}
@property --g-thin   {syntax:'<number>';inherits:true;initial-value:.06}
@property --g-dense  {syntax:'<number>';inherits:true;initial-value:.22}
@property --g-sat    {syntax:'<number>';inherits:true;initial-value:1.8}
@property --g-bright {syntax:'<number>';inherits:true;initial-value:1.06}
@property --g-light  {syntax:'<number>';inherits:true;initial-value:1}
@property --g-blur   {syntax:'<length>';inherits:true;initial-value:2px}
@property --g-density{syntax:'<number>';inherits:false;initial-value:.35}
@property --g-keep   {syntax:'<number>';inherits:false;initial-value:1}
@property --g-boost  {syntax:'<number>';inherits:false;initial-value:1}
@property --glass-scale{syntax:'<number>';inherits:true;initial-value:1}
@property --ink      {syntax:'<color>';inherits:true;initial-value:rgb(0 0 0 / .86)}
@property --ink-2    {syntax:'<color>';inherits:true;initial-value:rgb(60 60 67 / .8)}
@property --ink-solid{syntax:'<color>';inherits:true;initial-value:#000}
@property --ink-op   {syntax:'<number>';inherits:true;initial-value:.86}

/* ---------- State 1: light glass, dark ink (default) ---------- */
:is(.glass,.glass-btn){
  --g-r:255; --g-g:255; --g-b:255;
  --g-thin:.06; --g-dense:.22;
  --g-sat:1.8; --g-bright:1.06; --g-light:1;
  --edge:
    inset 1.5px 1.5px 1px -1px rgb(255 255 255 / .95),
    inset -1.5px -1.5px 1px -1px rgb(255 255 255 / .55),
    inset 0 0 0 .5px rgb(255 255 255 / .3),
    0 0 0 .5px rgb(0 0 0 / .06),
    0 6px 24px rgb(0 0 0 / .08),
    inset 0 10px 14px -12px rgb(255 255 255 / .55),
    inset 10px 0 14px -12px rgb(255 255 255 / .35),
    inset 0 -10px 14px -12px rgb(0 0 0 / .08);
  --ink:rgb(0 0 0 / .86); --ink-2:rgb(60 60 67 / .8);
  --ink-solid:#000; --ink-op:.86; --ink-blend:multiply;

  /* Derived */
  --g-alpha:min(1, calc((var(--g-thin) + var(--g-density) * (var(--g-dense) - var(--g-thin))) * var(--glass-scale)));
  --g-filter:
    blur(var(--g-blur))
    saturate(calc(var(--g-sat) * var(--g-keep)))
    brightness(calc((1 + (var(--g-bright) - 1) * min(var(--glass-scale), 1)) * var(--g-boost)));

  /* The four declarations that make the material */
  background:
    radial-gradient(ellipse at 0 0, rgb(255 255 255 / calc(.3 * var(--g-light))), transparent 55%),
    rgb(var(--g-r) var(--g-g) var(--g-b) / var(--g-alpha));
  -webkit-backdrop-filter:var(--g-filter);
  backdrop-filter:var(--g-filter) var(--lens,);   /* --lens is set per surface by liquid-glass.js */
  box-shadow:var(--edge);
  color:var(--ink);

  border:1px solid transparent;
  transition:
    --g-r .4s, --g-g .4s, --g-b .4s, --g-thin .4s, --g-dense .4s,
    --g-sat .4s, --g-bright .4s, --g-light .4s, --g-blur .4s, --g-density .4s,
    --g-keep .4s, --g-boost .25s, --glass-scale .4s,
    --ink .4s, --ink-2 .4s, --ink-solid .4s, --ink-op .4s,
    box-shadow .4s, color .4s;
}

/* ---------- State 2: light mode over a dark area (set by JS) ---------- */
[data-theme="light"] :is(.glass,.glass-btn)[data-ink="light"]{
  --g-r:16; --g-g:18; --g-b:22;
  --g-thin:.10; --g-dense:.44;   /* spec said .30; raised so text passes 4.5:1 over busy photos */
  --g-sat:1.7; --g-bright:.85; --g-light:.3;
  --edge:
    inset 0 1px 0 0 rgb(255 255 255 / .28),
    inset 0 0 0 0 rgb(255 255 255 / 0),
    inset 0 0 0 0 rgb(255 255 255 / 0),
    0 0 0 .5px rgb(0 0 0 / .35),
    0 6px 24px rgb(0 0 0 / .12),
    inset 0 10px 14px -12px rgb(255 255 255 / .12),
    inset 10px 0 14px -12px rgb(255 255 255 / 0),
    inset 0 -10px 14px -12px rgb(0 0 0 / .15);
  --ink:rgb(255 255 255 / .94); --ink-2:rgb(235 235 245 / .64);
  --ink-solid:#fff; --ink-op:.94; --ink-blend:plus-lighter;
}

/* ---------- State 3: dark mode ---------- */
[data-theme="dark"] :is(.glass,.glass-btn){
  --g-r:20; --g-g:20; --g-b:24;
  --g-thin:.16; --g-dense:.56;   /* spec said .38; raised so text passes 4.5:1 over busy photos */
  --g-sat:1.6; --g-bright:.8; --g-light:.33;
  --edge:
    inset 1.5px 1.5px 1px -1px rgb(255 255 255 / .32),
    inset -1.5px -1.5px 1px -1px rgb(255 255 255 / .18),
    inset 0 0 0 .5px rgb(255 255 255 / .1),
    0 0 0 .5px rgb(0 0 0 / .5),
    0 6px 24px rgb(0 0 0 / .35),
    inset 0 10px 14px -12px rgb(255 255 255 / .18),
    inset 10px 0 14px -12px rgb(255 255 255 / .12),
    inset 0 -10px 14px -12px rgb(0 0 0 / .25);
  --ink:rgb(255 255 255 / .94); --ink-2:rgb(235 235 245 / .64);
  --ink-solid:#fff; --ink-op:.94; --ink-blend:plus-lighter;
}

/* ---------- Variants ---------- */
/* Frost: busy or moving things behind (tested: text ≥ 5.6:1 with a black/white disc right behind) */
:is(.glass,.glass-btn).glass--frost{ --g-blur:10px; --g-thin:.45; --g-dense:.5; }
[data-theme="dark"] :is(.glass,.glass-btn).glass--frost{ --g-thin:.62; --g-dense:.62; }
/* Heavy: dialogs and forms */
:is(.glass,.glass-btn).glass--heavy{ --g-blur:18px; --g-thin:.5; --g-dense:.55; }
[data-theme="dark"] :is(.glass,.glass-btn).glass--heavy{ --g-thin:.55; --g-dense:.62; }
/* Tint: accent glass, fixed white ink, never adapted */
:is(.glass,.glass-btn).glass--tint,
[data-theme] :is(.glass,.glass-btn).glass--tint{
  --g-r:var(--glass-accent-r,150); --g-g:var(--glass-accent-g,58); --g-b:var(--glass-accent-b,16);
  --g-thin:.85; --g-dense:.85; --g-light:.6;
  --ink:#fff; --ink-2:#fff; --ink-solid:#fff; --ink-op:1; --ink-blend:normal;
}

/* ---------- Hover: brighten the glass, don't lift it ---------- */
:is(a,button,summary,[role="button"]):is(.glass,.glass-btn):hover{ --g-boost:1.14; }

/* ---------- Ink: everything drawn on the glass ---------- */
:is(.glass,.glass-btn) :is(h1,h2,h3,h4,h5,h6,p,span,li,dt,dd,label,figcaption,strong,b,em,small,a){ mix-blend-mode:var(--ink-blend); }
:is(.glass,.glass-btn) :is(svg,.glass-icon){ color:var(--ink-solid); opacity:var(--ink-op); mix-blend-mode:var(--ink-blend); }
:is(.glass,.glass-btn) .glass-ink-2{ color:var(--ink-2); }
:is(.glass,.glass-btn) :focus-visible{ mix-blend-mode:normal; }
:is(.glass,.glass-btn) :is(img,video,canvas,picture){ mix-blend-mode:normal; }

/* ---------- Rows and fields: a lighter layer of the same glass, never a grey wash ---------- */
.glass-row{ border-radius:12px; transition:background .2s; color:var(--ink); }
.glass-row:hover{ background:rgb(255 255 255 / .42); box-shadow:inset 0 0 0 .5px rgb(255 255 255 / .9); }
.glass-row[aria-selected="true"],.glass-row[aria-current="page"]{ background:rgb(255 255 255 / .76); box-shadow:inset 0 0 0 .5px #fff; }
[data-theme="dark"] .glass-row:hover,[data-theme="light"] [data-ink="light"] .glass-row:hover{ background:rgb(255 255 255 / .1); box-shadow:inset 0 0 0 .5px rgb(255 255 255 / .2); }
[data-theme="dark"] .glass-row[aria-selected="true"],[data-theme="dark"] .glass-row[aria-current="page"]{ background:rgb(255 255 255 / .16); }
.glass-field{ font:inherit; color:var(--ink); border-radius:14px; padding:12px 14px;
  background:rgb(255 255 255 / .42); border:1px solid rgb(60 60 67 / .28); box-shadow:inset 0 1px 2px rgb(0 0 0 / .06); }
.glass-field::placeholder{ color:var(--ink-2); }
.glass-field:focus{ background:rgb(255 255 255 / .76); }
[data-theme="dark"] .glass-field{ background:rgb(255 255 255 / .07); border-color:rgb(255 255 255 / .24); box-shadow:inset 0 1px 2px rgb(0 0 0 / .3); }
[data-theme="dark"] .glass-field:focus{ background:rgb(255 255 255 / .14); }

/* ---------- Dialog backdrop (use with <dialog class="glass glass--heavy" data-glass-lens="off">) ---------- */
dialog:is(.glass,.glass-btn){ color:var(--ink); }
dialog:is(.glass,.glass-btn)::backdrop{ background:rgb(20 14 8 / .22); -webkit-backdrop-filter:blur(8px); backdrop-filter:blur(8px); }
[data-theme="dark"] dialog:is(.glass,.glass-btn)::backdrop{ background:rgb(0 0 0 / .45); }

/* ---------- Fallbacks ---------- */
@supports not ((backdrop-filter:blur(1px)) or (-webkit-backdrop-filter:blur(1px))){
  :is(.glass,.glass-btn){ background:rgb(var(--g-r) var(--g-g) var(--g-b)); }
}
@media (prefers-reduced-transparency:reduce){
  :is(.glass,.glass-btn){ background:rgb(var(--g-r) var(--g-g) var(--g-b)); -webkit-backdrop-filter:none; backdrop-filter:none; }
}
@media (forced-colors:active){
  :is(.glass,.glass-btn){ -webkit-backdrop-filter:none; backdrop-filter:none; background:Canvas; box-shadow:none;
    outline:1px solid CanvasText; outline-offset:-1px; }
  :is(.glass,.glass-btn) *{ mix-blend-mode:normal !important; }
}
@media (prefers-reduced-motion:reduce){
  :is(.glass,.glass-btn){ transition:none; }
}
