/* ---------- Glass material + native motion (GAME_BIBLE.md §25) ----------
   One material for every surface that floats over the game: the live canvas is the backdrop, so the
   blur samples the world itself. Three weights:
   - thin    for HUD pieces over the playfield
   - regular for cards and sheets
   - thick   where text is dense
   Each panel gets a specular top edge and a hairline rim.
   Solid fallback when backdrop-filter is missing, for "Reduce transparency", or with html.no-glass. */
:root {
  --g-thin: rgba(14, 18, 36, .34);
  --g-clear: rgba(8, 10, 22, .38); /* the one tint of clear (lensed) glass */
  --g-reg: rgba(12, 14, 28, .74);
  --g-thick: rgba(11, 14, 28, .7);
  --g-blur-thin: blur(12px) saturate(165%);
  --g-blur: blur(30px) saturate(115%);
  --g-rim: rgba(255, 255, 255, .13);
  --g-spec: linear-gradient(180deg, rgba(255, 255, 255, .1), rgba(255, 255, 255, .02) 38%, rgba(255, 255, 255, 0) 60%);
  --g-edge: inset 0 1px 0 rgba(255, 255, 255, .2), inset 0 0 0 .5px rgba(255, 255, 255, .06);
  --g-drop: 0 10px 32px rgba(0, 0, 0, .32), 0 1px 3px rgba(0, 0, 0, .24);
  /* Spring curves: a critically-damped settle and a soft overshoot, for CSS-driven motion. */
  --spring: linear(0, .006, .025 2.8%, .101 6.1%, .539 18.9%, .721 25.3%, .849 31.5%, .937 38.1%, .968 41.8%, .991 45.7%, 1.006 50.1%, 1.015 55%, 1.017 63.9%, 1.001);
  --spring-pop: linear(0, .009, .035 2.1%, .141, .281 6.7%, .723 12.9%, .938 16.7%, 1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%, 1.129 32.8%, 1.051 39.6%, 1.017 43.1%, .991, .977 51%, .974 53.8%, .975 57.1%, .997 69.8%, 1.003 76.9%, 1);
}

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  /* Thin: HUD over the playfield. */
  html:not(.no-glass) :is(.vitals, .skills, .minimap-shell, .chip, .rankbox, .menu-btns, .buff, .pm, .toast, .chatlog, #chatInput) {
    background: var(--g-spec), var(--g-thin);
    -webkit-backdrop-filter: var(--g-blur-thin); backdrop-filter: var(--g-blur-thin);
    border-color: var(--g-rim);
    box-shadow: var(--g-edge), var(--g-drop);
  }
  html:not(.no-glass) .mapname { background: linear-gradient(180deg, rgba(10, 13, 28, .55), rgba(10, 13, 28, 0)); }
  html:not(.no-glass) #minimap { background: rgba(6, 9, 20, .38); }
  html:not(.no-glass) .slot, html:not(.no-glass) .menu-btns button { background: rgba(255, 255, 255, .05); border-color: rgba(255, 255, 255, .1); }
  html:not(.no-glass) .menu-btns button:hover { background: rgba(255, 255, 255, .14); }
  html:not(.no-glass) .bar { background: rgba(0, 0, 0, .42); }

  /* Regular: the login card over the title scene, and every window or sheet over the game. */
  html:not(.no-glass) .login-card,
  html:not(.no-glass) .win, html:not(.no-glass) .win.solid {
    background: var(--g-spec), var(--g-reg);
    -webkit-backdrop-filter: var(--g-blur); backdrop-filter: var(--g-blur);
    border-color: var(--g-rim);
    box-shadow: var(--g-edge), var(--g-drop);
  }
  html:not(.no-glass) .win-head { border-bottom-color: rgba(255, 255, 255, .08); }
  /* A phone sheet fills the screen and carries dense text: thick glass, so the controls and HUD
     under it read as a soft glow, not as shapes. */
  html.touch:not(.no-glass) .win, html.touch:not(.no-glass) .win.solid {
    background: var(--g-spec), rgba(10, 13, 26, .8);
    -webkit-backdrop-filter: blur(32px) saturate(160%); backdrop-filter: blur(32px) saturate(160%);
  }
  html:not(.no-glass) .win-body::-webkit-scrollbar-thumb { border-color: transparent; background-clip: padding-box; }
  /* Thick: insets inside a sheet (lists, cards, item tiles, inputs) keep text crisp over the blur. */
  html:not(.no-glass) .win :is(.card, .li, .cell, .ocard, .offer, .eqslot, .av-card, .av-rail, .av-ofcard, .bq-card, .step-name, .pick, select) {
    background-color: rgba(8, 10, 22, .42);
    border-color: rgba(255, 255, 255, .09);
  }
  html:not(.no-glass) :is(.av-stage .av-frame) {
    background: radial-gradient(118% 92% at 50% 30%, rgba(80, 92, 150, .22), rgba(6, 8, 18, .34));
    border-color: rgba(255, 255, 255, .1);
  }
  html:not(.no-glass) .login-card :is(input, .tab, .step-name, .step .ar, .class-card) { background-color: rgba(6, 8, 20, .42); border-color: rgba(255, 255, 255, .1); }
  html:not(.no-glass) .win :is(input, textarea) { background-color: rgba(6, 8, 20, .5); }
  html:not(.no-glass) .win.modal-bg::before { background: rgba(2, 4, 12, .28); }
  /* Sticky bars inside a sheet are glass too, so content slides under a frosted edge. */
  html:not(.no-glass) .ab-filters {
    background: rgba(12, 15, 30, .55); box-shadow: none;
    -webkit-backdrop-filter: blur(18px) saturate(160%); backdrop-filter: blur(18px) saturate(160%);
  }

  /* Touch controls: round glass discs over the playfield. */
  html.touch:not(.no-glass) :is(.tc-btn, #tc-pad) {
    background: var(--g-spec), rgba(14, 18, 36, .28);
    -webkit-backdrop-filter: var(--g-blur-thin); backdrop-filter: var(--g-blur-thin);
    border-color: rgba(255, 255, 255, .16);
    box-shadow: var(--g-edge), 0 6px 18px rgba(0, 0, 0, .28);
  }
  html.touch:not(.no-glass) #tc-knob { background: rgba(255, 255, 255, .22); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 2px 8px rgba(0, 0, 0, .3); }
}

/* "Reduce transparency" (where the browser reports it): solid panels, same layout. */
@media (prefers-reduced-transparency: reduce) {
  :is(.vitals, .skills, .minimap-shell, .chip, .rankbox, .menu-btns, .buff, .pm, .toast, .chatlog, #chatInput, .login-card, .win, .tc-btn, #tc-pad) {
    -webkit-backdrop-filter: none !important; backdrop-filter: none !important;
  }
  :is(.login-card, .win) { background: #121628 !important; }
  :is(.vitals, .skills, .minimap-shell, .chip, .rankbox, .menu-btns, .buff, .pm, .toast, .chatlog, .tc-btn, #tc-pad) { background: rgba(14, 18, 34, .96) !important; }
}

/* ---------- Motion: springs and press feedback ---------- */
@keyframes winSpring { from { transform: translate(-50%, -50%) scale(.94); opacity: 0; } 40% { opacity: 1; } }
.win { animation: winSpring .42s var(--spring) both; }
.toast { animation: toastSpring .45s var(--spring-pop) both; }
@keyframes toastSpring { from { transform: translateY(-10px) scale(.92); opacity: 0; } 30% { opacity: 1; } }
/* Press: the control sinks a little and springs back on release, like a native button. */
:is(.btn, .tab, .win-tabs button, .av-tabs button, .menu-btns button, .class-card, .av-card, .av-rail, .av-ofcard, .bq-card, .step .ar, .sw, .win-head .x) {
  transition: transform .32s var(--spring), background-color .15s, border-color .15s, color .15s;
}
:is(.btn, .tab, .win-tabs button, .av-tabs button, .menu-btns button, .class-card, .av-card, .av-rail, .av-ofcard, .bq-card, .step .ar, .win-head .x):active:not(:disabled) {
  transform: scale(.95); transition-duration: .08s;
}
.sw:active { transform: scale(.88); transition-duration: .08s; }
html.touch * { -webkit-tap-highlight-color: transparent; }

@media (prefers-reduced-motion: reduce) {
  .win, .toast { animation: none; }
  :is(.btn, .tab, .win-tabs button, .av-tabs button, .menu-btns button, .class-card, .av-card, .av-rail, .av-ofcard, .bq-card, .step .ar, .sw, .win-head .x) { transition: none; }
  :is(.btn, .tab, .win-tabs button, .av-tabs button, .menu-btns button, .class-card, .av-card, .av-rail, .av-ofcard, .bq-card, .step .ar, .sw, .win-head .x):active { transform: none; }
}

/* ---------- Touch sheets: swipe down to dismiss (client/ui.js mountSheet) ---------- */
html.touch .sheet {
  position: absolute; inset: 0; overflow-x: hidden; overflow-y: auto; pointer-events: auto;
  scroll-snap-type: y mandatory; overscroll-behavior: contain; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
html.touch .sheet::-webkit-scrollbar { display: none; }
html.touch .sheet-gap { height: 100%; scroll-snap-align: start; pointer-events: none; }
html.touch .sheet-page { position: relative; height: 100%; scroll-snap-align: start; scroll-snap-stop: always; }
html.touch .sheet .win { animation: sheetIn .36s var(--spring) both; }
/* The body scrolls on its own; pulled down at its top, the next drag carries the sheet. */
html.touch .sheet .win-body { overscroll-behavior-y: auto; }
@keyframes sheetIn { from { transform: translateY(42%); } }
/* The dim behind follows the sheet as it is dragged (scroll-driven, off the main thread). */
@supports (animation-timeline: scroll()) {
  html.touch .sheet { animation: sheetDim linear both; animation-timeline: scroll(self); }
  @keyframes sheetDim { from { background-color: rgba(2, 4, 12, 0); } to { background-color: rgba(2, 4, 12, .3); } }
}
@media (prefers-reduced-motion: reduce) { html.touch .sheet .win { animation: none; } }

/* ---------- Clear glass (client/glass-lens.js) ----------
   While the WebGL lens runs (html.lens), these pieces drop the frost: the lens draws the world under
   them sharp, refracted at the rim with a colour fringe. A whisper of tint and a hairline keep the
   shape readable. Dense surfaces stay frosted. The base list uses :where() so the overrides below win
   (#tc-pad in an :is() list would give every rule ID-level specificity). */
#lens { position: fixed; pointer-events: none; image-rendering: auto; }
html.lens:not(.no-glass) :where(.menu-btns, .chip-row .chip, .rankbox, .skills, .vitals, .minimap-shell, .buff, .pm, .toast, #tc-pad, .tc-btn:not(.tc-gone), .menu-toggle, .hud-chat) {
  background: var(--g-clear) !important; /* one tint for every piece of clear glass */
  -webkit-backdrop-filter: none !important; backdrop-filter: none !important;
  border-color: rgba(255, 255, 255, .16) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 8px 24px rgba(0, 0, 0, .22) !important;
}
/* Icons on clear glass: full white, a touch larger. */
html.lens:not(.no-glass) .menu-btns button { background: rgba(255, 255, 255, .06) !important; border-color: rgba(255, 255, 255, .12) !important; color: #fff; }
html.lens:not(.no-glass) .menu-btns .mi { opacity: 1; filter: none; }
/* Touch chat and menu buttons are glass like every other control (clear under the lens, frosted without it). */
html.touch:not(.no-glass):not(.lens) :is(.menu-toggle, .hud-chat) {
  background: var(--g-spec), rgba(10, 13, 28, .42) !important;
  -webkit-backdrop-filter: var(--g-blur-thin); backdrop-filter: var(--g-blur-thin);
  border-color: rgba(255, 255, 255, .16) !important; box-shadow: var(--g-edge), 0 6px 18px rgba(0, 0, 0, .25);
}
/* A toast's message colour is for dark backgrounds; on glass it is the accent bar on the left. */
html:not(.no-glass) .toast { color: var(--t1) !important; border-left: 3px solid var(--toast-c, var(--accent)) !important; }
html.lens:not(.no-glass) :is(.vitals, .rankbox, .chip, .buff, .pm, .toast, .menu-btns, .skills, .minimap-shell) :is(*, *::before),
html.lens:not(.no-glass) :is(.vitals, .rankbox, .chip, .buff, .pm, .toast) { text-shadow: none !important; }
html.lens:not(.no-glass) .mapname { background: linear-gradient(180deg, rgba(8, 10, 22, .5), rgba(8, 10, 22, 0)); }
