/* ============================================================================
   Liquid Glass — a material, not a skin.
   ----------------------------------------------------------------------------
   Real glass does four things at once, and skipping any one of them is what
   makes most "glassmorphism" read as flat frosted plastic:

     1. FROST      backdrop blur + saturation lift (the diffuse transmission)
     2. REFRACTION the backdrop bends near the edges, like a lens bevel.
                   Done with an SVG displacement map applied to the backdrop —
                   this is the effect Apple's material is actually built on.
     3. SPECULAR   a bright rim where light catches the curved edge, plus a
                   moving sheen that tracks the pointer.
     4. DEPTH      a soft, wide, low-opacity shadow so it floats over content.

   Frost and refraction ship as one backdrop-filter on one element — see the
   note on .glass for why nesting them cannot work — declared twice so a
   browser without SVG-backdrop support still gets the plain frosted form.
   ========================================================================== */

:root {
  color-scheme: dark;

  --bg-0: #06070c;
  --text: rgba(255, 255, 255, 0.96);
  --text-2: rgba(235, 240, 255, 0.68);
  --text-3: rgba(220, 230, 255, 0.40);

  /* The glass material itself */
  --glass-tint: rgba(255, 255, 255, 0.055);
  --glass-tint-strong: rgba(255, 255, 255, 0.10);
  --glass-stroke: rgba(255, 255, 255, 0.16);
  --glass-stroke-lit: rgba(255, 255, 255, 0.55);
  --glass-blur: 22px;
  --glass-sat: 190%;

  --accent: #7aa2ff;
  --accent-2: #c58bff;
  --good: #5fdba7;
  --warn: #ffcf6b;
  --bad: #ff7a8a;

  --r-lg: 28px;
  --r-md: 20px;
  --r-sm: 14px;
  --r-pill: 999px;

  --shadow-float: 0 18px 50px -12px rgba(0, 0, 0, 0.65),
                  0 2px 8px rgba(0, 0, 0, 0.35);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "Inter", "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg-0: #eef1f8;
    --text: rgba(12, 16, 28, 0.94);
    --text-2: rgba(20, 26, 44, 0.62);
    --text-3: rgba(20, 26, 44, 0.38);
    --glass-tint: rgba(255, 255, 255, 0.42);
    --glass-tint-strong: rgba(255, 255, 255, 0.60);
    --glass-stroke: rgba(255, 255, 255, 0.75);
    --glass-stroke-lit: rgba(255, 255, 255, 0.95);
    --shadow-float: 0 18px 45px -14px rgba(20, 30, 60, 0.28),
                    0 2px 6px rgba(20, 30, 60, 0.10);
  }
}

* { box-sizing: border-box; }

/* The base colour goes on html ONLY. If body also carries a background it
   paints in the block-descendant step, which is AFTER negative z-index
   children — burying .backdrop under flat colour and leaving the glass with
   nothing but a solid tone to refract. */
html {
  background: var(--bg-0);
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { background: transparent; }

/* ---------------------------------------------------------------- backdrop
   Glass needs something worth refracting. A slow mesh of coloured blobs gives
   the material moving content to bend, which is what sells the effect. */
.backdrop {
  position: fixed;
  inset: -10%;
  z-index: -2;
  overflow: hidden;
  background: var(--bg-0);
}
.backdrop i {
  position: absolute;
  display: block;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.55;
  will-change: transform;
}
.backdrop i:nth-child(1) { width: 46vw; height: 46vw; left: -6vw;  top: -8vw;
  background: radial-gradient(circle, #4f7bff, transparent 68%);
  animation: drift-a 34s ease-in-out infinite; }
.backdrop i:nth-child(2) { width: 40vw; height: 40vw; right: -4vw; top: 8vh;
  background: radial-gradient(circle, #b25cff, transparent 68%);
  animation: drift-b 41s ease-in-out infinite; }
.backdrop i:nth-child(3) { width: 38vw; height: 38vw; left: 22vw; bottom: -12vw;
  background: radial-gradient(circle, #17c8b0, transparent 68%);
  animation: drift-c 47s ease-in-out infinite; }
.backdrop i:nth-child(4) { width: 30vw; height: 30vw; right: 18vw; bottom: -6vw;
  background: radial-gradient(circle, #ff5f9e, transparent 70%);
  animation: drift-a 53s ease-in-out infinite reverse; }

@keyframes drift-a { 50% { transform: translate3d(8vw, 10vh, 0) scale(1.15); } }
@keyframes drift-b { 50% { transform: translate3d(-10vw, 8vh, 0) scale(0.9); } }
@keyframes drift-c { 50% { transform: translate3d(6vw, -10vh, 0) scale(1.2); } }

/* A faint grain layer stops the big gradients from banding on OLED panels. */
.backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.16;
  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'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

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

/* ------------------------------------------------------------------- glass */
.glass {
  position: relative;
  border-radius: var(--r-lg);
  background: var(--glass-tint);
  border: 1px solid var(--glass-stroke);
  box-shadow: var(--shadow-float),
              /* the lit bevel: bright at top-left, faint at bottom-right */
              inset 0 1px 0 0 var(--glass-stroke-lit),
              inset 0 -1px 0 0 rgba(255, 255, 255, 0.08),
              inset 1px 0 0 0 rgba(255, 255, 255, 0.10),
              inset -1px 0 0 0 rgba(255, 255, 255, 0.10);
  /* Frost and refraction MUST be one declaration on one element. An element
     with a backdrop-filter becomes a "backdrop root" for its descendants, so a
     nested refraction layer would sample this panel's own interior instead of
     the page behind it, and the lensing would silently do nothing.
     Two declarations, progressive: a browser that rejects the url() form at
     parse time keeps the first line and still gets plain frost; one that
     accepts the syntax but cannot render SVG backdrops still has --glass-tint
     holding the text legible. Blur first, then displace, so the rim bends an
     already-frosted image instead of smearing a bent one. */
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat)) url(#lg-lens);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat)) url(#lg-lens);
}

/* True squircle corners where the browser can draw them (Chromium 139+). */
@supports (corner-shape: squircle) {
  .glass, .btn, .field, .chip { corner-shape: squircle; }
}

/* Specular highlight. A wide soft highlight that follows the pointer, over a
   fixed top-edge glint. --mx/--my are written by glass.js. */
.glass::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0.9;
  background:
    radial-gradient(160px 120px at var(--mx, 30%) var(--my, 0%),
                    rgba(255, 255, 255, 0.22), transparent 70%),
    linear-gradient(to bottom,
                    rgba(255, 255, 255, 0.14) 0%,
                    rgba(255, 255, 255, 0.03) 22%,
                    transparent 45%);
}

.glass > * { position: relative; z-index: 1; }

/* Variants */
.glass--flat   { box-shadow: inset 0 1px 0 0 rgba(255,255,255,0.28); border-radius: var(--r-md); }
.glass--strong { background: var(--glass-tint-strong); }
.glass--inset  {
  background: rgba(0, 0, 0, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.30);
}

/* ----------------------------------------------------------------- controls */
.btn {
  appearance: none;
  font: inherit;
  font-weight: 590;
  font-size: 14px;
  letter-spacing: 0.01em;
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--r-pill);
  border: 1px solid var(--glass-stroke);
  background: var(--glass-tint-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35),
              0 4px 14px -6px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: transform 140ms cubic-bezier(0.22, 1, 0.36, 1),
              background 180ms ease, box-shadow 180ms ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.17); transform: translateY(-1px); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn--primary {
  background: linear-gradient(160deg, rgba(122, 162, 255, 0.95), rgba(197, 139, 255, 0.85));
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
}
.btn--primary:hover { filter: brightness(1.08); background: linear-gradient(160deg, rgba(122,162,255,1), rgba(197,139,255,0.95)); }
.btn--danger { color: var(--bad); border-color: rgba(255, 122, 138, 0.35); }
.btn--sm { padding: 6px 13px; font-size: 12.5px; }
.btn--icon { padding: 8px 11px; border-radius: 50%; }

.field {
  font: inherit;
  font-size: 14px;
  width: 100%;
  color: var(--text);
  padding: 11px 15px;
  border-radius: var(--r-sm);
  background: rgba(0, 0, 0, 0.20);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.field::placeholder { color: var(--text-3); }
.field:focus {
  outline: none;
  border-color: rgba(122, 162, 255, 0.75);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.35), 0 0 0 3.5px rgba(122, 162, 255, 0.22);
}
select.field { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%23aab' stroke-width='1.6'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

/* iOS-style switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 50px; height: 30px; border-radius: var(--r-pill); flex: none;
  background: rgba(120, 120, 128, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.10);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: background 260ms cubic-bezier(0.22, 1, 0.36, 1);
  position: relative;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35), 0 0 0 0.5px rgba(0, 0, 0, 0.06);
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
}
.switch input:checked + .track { background: linear-gradient(160deg, #6ee7a8, #34c77b); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Sliders */
input[type="range"] {
  appearance: none; width: 100%; height: 28px; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 590; letter-spacing: 0.01em;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-2);
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip--on  { color: var(--good); border-color: rgba(95, 219, 167, 0.32); background: rgba(95,219,167,0.12); }
.chip--off { color: var(--bad);  border-color: rgba(255, 122, 138, 0.32); background: rgba(255,122,138,0.10); }
.chip--warn{ color: var(--warn); border-color: rgba(255, 207, 107, 0.32); background: rgba(255,207,107,0.10); }

/* ---------------------------------------------------------------- typography */
h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -0.02em; }
h1 { font-size: 26px; }
h2 { font-size: 17px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); font-weight: 620; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }

/* ------------------------------------------------------------------ motion */
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(0.985); }
                  to   { opacity: 1; transform: none; } }
.rise { animation: rise 420ms cubic-bezier(0.22, 1, 0.36, 1) both; }
