/* ==========================================================================
   Airy Glass foundation
   Theme: follows the OS by default. Force with <html data-theme="light|dark">.
   Material: glass by default. Force solid with <html data-material="solid">.
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Content layer */
  --canvas: light-dark(#f5f5f7, #0f0f11);
  --surface: light-dark(#ffffff, #1c1c1e);
  --surface-2: light-dark(#f0f0f3, #2a2a2d);
  --thumb: light-dark(#ffffff, #4a4a4f);

  /* Labels */
  --label: light-dark(#1d1d1f, #f5f5f7);
  --label-2: light-dark(rgb(29 29 31 / .74), rgb(245 245 247 / .8));
  --label-3: light-dark(rgb(29 29 31 / .62), rgb(245 245 247 / .62));

  /* Lines and fills */
  --separator: light-dark(rgb(0 0 0 / .1), rgb(255 255 255 / .13));
  --fill: light-dark(rgb(118 118 128 / .12), rgb(118 118 128 / .24));
  --fill-strong: light-dark(rgb(118 118 128 / .2), rgb(118 118 128 / .36));
  --control-line: light-dark(rgb(0 0 0 / .42), rgb(255 255 255 / .46));

  /* Accent: swap these three together, then rerun the audit */
  --accent: #0071e3;
  --on-accent: #ffffff;
  --accent-text: light-dark(#0066cc, #6cb4ff);

  /* Status text */
  --success: light-dark(#14782f, #4cd97b);
  --warning: light-dark(#8a5000, #ffc14d);
  --danger: light-dark(#c9001a, #ff7b73);

  /* Materials. Each pairs with the fixed blur in the classes below. */
  --mat-thin: light-dark(rgb(255 255 255 / .58), rgb(34 34 37 / .7));
  --mat-regular: light-dark(rgb(255 255 255 / .74), rgb(34 34 37 / .8));
  --mat-thick: light-dark(rgb(250 250 252 / .88), rgb(34 34 37 / .9));
  --mat-solid: light-dark(#fbfbfd, #242427);
  --mat-media: rgb(0 0 0 / .56);

  /* Glass edge */
  --edge-line: light-dark(rgb(0 0 0 / .08), rgb(255 255 255 / .14));
  --edge-light: light-dark(rgb(255 255 255 / .95), rgb(255 255 255 / .2));
  --sheen: linear-gradient(to bottom, light-dark(rgb(255 255 255 / .42), rgb(255 255 255 / .08)), transparent 58%);

  /* Elevation: wide, soft, low. */
  --shadow-1: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .05);
  --shadow-2: 0 2px 6px rgb(0 0 0 / .05), 0 12px 36px rgb(0 0 0 / .1);
  --shadow-3: 0 4px 12px rgb(0 0 0 / .08), 0 28px 72px rgb(0 0 0 / .18);

  /* Ambient glow: pale tints of the brand, never a second accent */
  --glow-1: light-dark(#b7d9ff, #123c69);
  --glow-2: light-dark(#ffe6cf, #3a2a1e);
  --tabbar-clearance: 0px;

  /* Space, on a 4px base */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px;
  --s-8: 32px; --s-10: 40px; --s-12: 48px; --s-16: 64px; --s-20: 80px; --s-30: 120px;
  --gutter: clamp(16px, 4vw, 40px);
  --section: clamp(72px, 11vw, 144px);

  /* Radius */
  --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-xl: 28px; --r-pill: 999px;

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  /* Motion */
  --ease: cubic-bezier(.32, .72, 0, 1);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --t-1: 120ms; --t-2: 220ms; --t-3: 360ms; --t-4: 520ms;
}
/* Vivid glass: more visible, with less protection. Use only over backdrops you
   control, and let the audit decide whether the page keeps it. */
:root[data-glass="vivid"] {
  --mat-thin: light-dark(rgb(255 255 255 / .34), rgb(34 34 37 / .52));
  --mat-regular: light-dark(rgb(255 255 255 / .5), rgb(34 34 37 / .6));
  --mat-thick: light-dark(rgb(250 250 252 / .72), rgb(34 34 37 / .78));
  --glow-1: light-dark(#a6d1ff, #17508f);
  --glow-2: light-dark(#ffd6b8, #5a3820);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 88px; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--label);
  font: 400 17px/1.47 var(--font);
  letter-spacing: -.012em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: .18em; }
button, input, select, textarea { font: inherit; letter-spacing: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
svg { display: block; }

/* ---------- Type roles ---------- */
.t-display { font: 600 clamp(44px, 7.4vw, 88px)/1.04 var(--font-display); letter-spacing: -.035em; text-wrap: balance; }
.t-title-1 { font: 600 clamp(32px, 4.4vw, 48px)/1.08 var(--font-display); letter-spacing: -.028em; text-wrap: balance; }
.t-title-2 { font: 600 clamp(24px, 2.6vw, 30px)/1.16 var(--font-display); letter-spacing: -.022em; }
.t-title-3 { font: 600 20px/1.25 var(--font-display); letter-spacing: -.017em; }
.t-lead { font: 400 clamp(19px, 1.9vw, 22px)/1.4 var(--font); letter-spacing: -.016em; color: var(--label-2); text-wrap: pretty; }
.t-body { font: 400 17px/1.47 var(--font); letter-spacing: -.012em; }
.t-callout { font: 400 15px/1.42 var(--font); letter-spacing: -.009em; }
.t-footnote { font: 400 13px/1.38 var(--font); letter-spacing: -.004em; color: var(--label-2); }
.t-num { font-variant-numeric: tabular-nums; }

/* ---------- Materials: the fallback ladder ----------
   Rung 1: readable and solid, in every browser.
   Rung 2: translucent only where backdrop-filter exists.
   Rung 3: back to solid when the person or the app asks for it.
   Prefixed values stay hard-coded: Safari has been reported not to resolve
   custom properties inside -webkit-backdrop-filter. */
.glass-thin, .glass, .glass-thick, .glass-media {
  background: var(--mat-solid);
  box-shadow: inset 0 1px 0 var(--edge-light), inset 0 0 0 1px var(--edge-line), var(--shadow-2);
}
.glass-media {
  background: rgb(28 28 30 / .94);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / .16), var(--shadow-2);
}

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .glass-thin {
    background: var(--sheen), var(--mat-thin);
    -webkit-backdrop-filter: blur(16px) saturate(170%);
    backdrop-filter: blur(16px) saturate(170%);
  }
  .glass {
    background: var(--sheen), var(--mat-regular);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
  }
  .glass-thick {
    background: var(--sheen), var(--mat-thick);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
  }
  .glass-media {
    background: var(--mat-media);
    -webkit-backdrop-filter: blur(16px) saturate(150%);
    backdrop-filter: blur(16px) saturate(150%);
  }
}

@media (prefers-reduced-transparency: reduce) {
  .glass-thin, .glass, .glass-thick {
    background: var(--mat-solid);
    -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  .glass-media {
    background: rgb(28 28 30 / .94);
    -webkit-backdrop-filter: none; backdrop-filter: none;
  }
}
:root[data-material="solid"] .glass-thin,
:root[data-material="solid"] .glass,
:root[data-material="solid"] .glass-thick {
  background: var(--mat-solid);
  -webkit-backdrop-filter: none; backdrop-filter: none;
}
:root[data-material="solid"] .glass-media {
  background: rgb(28 28 30 / .94);
  -webkit-backdrop-filter: none; backdrop-filter: none;
}
@media (prefers-contrast: more) {
  :root {
    --label-2: var(--label); --label-3: var(--label);
    --separator: light-dark(rgb(0 0 0 / .4), rgb(255 255 255 / .45));
    --edge-line: light-dark(rgb(0 0 0 / .55), rgb(255 255 255 / .6));
    --control-line: var(--label);
    --mat-thin: var(--mat-solid); --mat-regular: var(--mat-solid); --mat-thick: var(--mat-solid);
  }
}

/* ---------- Ambient backdrop: gives glass something to catch ---------- */
.ambient {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(70vmax 48vmax at 8% -6%, var(--glow-1), transparent 66%),
    radial-gradient(64vmax 46vmax at 96% 104%, var(--glow-2), transparent 68%);
}

/* ---------- Scroll edge: content fades before it reaches a floating bar ---------- */
.scroll-edge-top {
  position: fixed; inset: 0 0 auto; height: 96px; z-index: 40; pointer-events: none;
  background: linear-gradient(to bottom, var(--canvas) 18%, transparent);
}

/* ---------- Floating navigation ---------- */
.nav {
  position: fixed; z-index: 50; top: var(--s-3);
  left: 50%; transform: translateX(-50%);
  width: min(1040px, calc(100% - 2 * var(--s-3)));
  min-height: 56px; padding: var(--s-2) var(--s-2) var(--s-2) var(--s-5);
  display: flex; align-items: center; gap: var(--s-4);
  border-radius: var(--r-pill);
}
.nav__brand { font: 600 17px/1 var(--font-display); letter-spacing: -.02em; color: var(--label); }
.nav__links { display: flex; gap: var(--s-1); margin-inline: auto; }
.nav__link { padding: 10px 14px; border-radius: var(--r-pill); color: var(--label); font-size: 15px; }
.nav__link:hover { background: var(--fill); text-decoration: none; }
.nav__link[aria-current] { background: var(--fill); font-weight: 500; }
@media (max-width: 760px) { .nav__links { display: none; } .nav > .btn:last-child { margin-left: auto; } }

/* ---------- Bottom tab bar (phone) ---------- */
.tabbar {
  position: fixed; z-index: 50; left: var(--s-4); right: var(--s-4);
  bottom: max(var(--s-3), env(safe-area-inset-bottom));
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  gap: 2px; padding: 5px; border-radius: var(--r-pill);
}
.tabbar__item {
  min-height: 54px; padding: 6px 4px; border: 0; border-radius: var(--r-pill); background: none;
  display: grid; place-items: center; align-content: center; gap: 2px;
  font-size: 12px; font-weight: 500; letter-spacing: 0; color: var(--label); cursor: pointer;
}
.tabbar__item[aria-current] { background: var(--fill); color: var(--accent-text); }

/* ---------- Floating sidebar ---------- */
.sidebar {
  position: fixed; z-index: 45; top: var(--s-3); bottom: var(--s-3); left: var(--s-3);
  width: 256px; padding: 10px; border-radius: var(--r-lg);
  display: flex; flex-direction: column; gap: 2px; overflow: auto;
}
.sidebar__item {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 40px; padding: var(--s-2) var(--s-3); border-radius: var(--r-sm);
  color: var(--label); font-size: 15px;
}
.sidebar__item:hover { background: var(--fill); text-decoration: none; }
.sidebar__item[aria-current] { background: var(--fill-strong); font-weight: 500; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 44px; padding: 10px 20px; border: 0; border-radius: var(--r-pill);
  font-size: 15px; font-weight: 500; letter-spacing: -.009em; line-height: 1.2;
  white-space: nowrap; cursor: pointer; user-select: none;
  transition: transform var(--t-1) var(--ease-out), background-color var(--t-2) var(--ease-out), opacity var(--t-2);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .42; cursor: not-allowed; transform: none; }
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn--secondary { background: var(--fill); color: var(--label); }
.btn--secondary:hover { background: var(--fill-strong); }
.btn--plain { background: none; color: var(--accent-text); padding-inline: 12px; }
.btn--plain:hover { background: var(--fill); }
.btn--danger { background: var(--fill); color: var(--danger); }
.btn--lg { min-height: 52px; padding: 14px 28px; font-size: 17px; }
.btn--icon { width: 44px; padding: 0; }

/* ---------- Segmented control ---------- */
.segmented {
  display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: relative;
  padding: 3px; border-radius: var(--r-pill); background: var(--fill);
}
.segmented__item {
  position: relative; z-index: 1; min-height: 40px; padding: 6px 16px; border: 0; border-radius: var(--r-pill);
  background: none; font-size: 14px; font-weight: 500; color: var(--label); cursor: pointer;
  transition: background-color var(--t-2) var(--ease);
}
.segmented__item[aria-pressed="true"], .segmented__item[aria-selected="true"] {
  background: var(--thumb); box-shadow: var(--shadow-1);
}
@media (pointer: coarse) { .segmented__item { min-height: 44px; } }

/* ---------- Switch ---------- */
.switch { position: relative; display: inline-flex; flex: none; width: 52px; height: 32px; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.switch__track {
  width: 100%; height: 100%; border-radius: var(--r-pill); background: var(--fill-strong);
  box-shadow: inset 0 0 0 1px var(--control-line);
  transition: background-color var(--t-2) var(--ease), box-shadow var(--t-2) var(--ease);
}
.switch__knob {
  position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3), 0 0 0 .5px rgb(0 0 0 / .08);
  transition: transform var(--t-3) var(--ease), width var(--t-2) var(--ease);
}
.switch input:checked + .switch__track { background: var(--accent); box-shadow: none; }
.switch input:checked ~ .switch__knob { transform: translateX(20px); }
.switch input:active ~ .switch__knob { width: 30px; }
.switch input:checked:active ~ .switch__knob { transform: translateX(16px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--accent-text); outline-offset: 2px; }

/* ---------- Text field ---------- */
.field { display: grid; gap: 6px; }
.field__label { font-size: 13px; font-weight: 500; color: var(--label-2); }
.input {
  width: 100%; min-height: 44px; padding: 10px 14px; border: 0; border-radius: var(--r-md);
  background: var(--fill); color: var(--label); font-size: 16px;
  box-shadow: inset 0 0 0 1px var(--control-line);
  transition: box-shadow var(--t-2) var(--ease-out), background-color var(--t-2);
}
.input::placeholder { color: var(--label-3); opacity: 1; }
.input:focus { outline: none; background: var(--surface); box-shadow: inset 0 0 0 2px var(--accent-text), 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.input--search { border-radius: var(--r-pill); padding-left: 40px; }

/* ---------- Inset grouped list ---------- */
.group { background: var(--surface); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-1); }
.group__row {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 52px; padding: 12px var(--s-4); position: relative; color: inherit;
}
.group__row + .group__row::before {
  content: ""; position: absolute; top: 0; left: var(--s-4); right: 0; height: 1px; background: var(--separator);
}
button.group__row { width: 100%; border: 0; background: none; text-align: left; cursor: pointer; }
.group__row:focus-visible { outline-offset: -2px; border-radius: var(--r-md); }
a.group__row:hover, button.group__row:hover { background: var(--fill); text-decoration: none; }
.group__meta { margin-left: auto; color: var(--label-2); font-size: 15px; }
.section-head { padding: 0 var(--s-4) var(--s-2); font-size: 15px; font-weight: 600; letter-spacing: -.01em; }

/* ---------- Card ---------- */
.card { background: var(--surface); border-radius: var(--r-lg); padding: var(--s-6); box-shadow: var(--shadow-1); }

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.table th { padding: 10px var(--s-4); text-align: left; font-size: 13px; font-weight: 500; color: var(--label-2); }
.table td { padding: 14px var(--s-4); border-top: 1px solid var(--separator); }
.table .num { text-align: right; }
.table tr.is-clickable { position: relative; }
.table tr.is-clickable:hover { background: var(--fill); }
.table__link { color: inherit; font: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
.table__link::after { content: ""; position: absolute; inset: 0; }
.table__link:hover { text-decoration: none; }
.table__link:focus-visible { outline: none; }
.table__link:focus-visible::after { outline: 2px solid var(--accent-text); outline-offset: -2px; }

/* ---------- Badge ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--r-pill);
  background: var(--fill); font-size: 13px; font-weight: 500; color: var(--label);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge--success { color: var(--success); }
.badge--warning { color: var(--warning); }
.badge--danger { color: var(--danger); }

/* ---------- Menu or popover ---------- */
.menu { min-width: 220px; padding: 6px; border-radius: var(--r-lg); }
.menu__item {
  display: flex; width: 100%; align-items: center; gap: var(--s-3); min-height: 40px; padding: 8px 12px;
  border: 0; border-radius: var(--r-md); background: none; text-align: left; font-size: 15px; cursor: pointer;
}
.menu__item:hover { background: var(--fill); }

/* ---------- Sheet or dialog ---------- */
.scrim { position: fixed; inset: 0; z-index: 60; background: rgb(0 0 0 / .28); }
.sheet {
  position: fixed; z-index: 61; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(480px, calc(100% - 2 * var(--s-4))); max-height: calc(100dvh - 2 * var(--s-6));
  overflow: auto; padding: var(--s-6); border-radius: var(--r-xl);
}
.sheet.glass-thick { box-shadow: inset 0 1px 0 var(--edge-light), inset 0 0 0 1px var(--edge-line), var(--shadow-3); }
dialog.sheet { margin: 0; border: 0; color: inherit; max-width: none; }
dialog.sheet::backdrop { background: rgb(0 0 0 / .28); }
@media (max-width: 600px) {
  .sheet { top: auto; bottom: var(--s-2); transform: translateX(-50%); width: calc(100% - 2 * var(--s-2)); }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 70; left: 50%; bottom: calc(var(--s-6) + var(--tabbar-clearance)); transform: translateX(-50%);
  display: flex; align-items: center; gap: var(--s-3);
  width: max-content; max-width: calc(100% - 2 * var(--s-4));
  padding: 12px var(--s-5); border-radius: var(--r-pill); font-size: 15px;
}

/* ---------- Layout ---------- */
.wrap { width: min(1120px, 100%); margin-inline: auto; padding-inline: var(--gutter); }
.wrap--narrow { width: min(680px, 100%); margin-inline: auto; padding-inline: var(--gutter); }
.section { padding-block: var(--section); }
.stack > * + * { margin-top: var(--stack, var(--s-4)); }
.measure { max-width: 62ch; }

/* ---------- Motion ---------- */
/* Uses individual transform properties so it composes with positioning transforms. */
@keyframes materialize { from { opacity: 0; scale: .96; translate: 0 6px; } }
.materialize { animation: materialize var(--t-3) var(--ease) both; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important; animation-iteration-count: 1 !important;
    transition-duration: 1ms !important; scroll-behavior: auto !important;
  }
  .btn:active { transform: none; }
}

/* ---------- Forced colors: last, so it wins over component rules ---------- */
@media (forced-colors: active) {
  .glass-thin, .glass, .glass-thick, .glass-media {
    background: Canvas; color: CanvasText; border: 1px solid CanvasText; box-shadow: none;
    -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  .btn, .input, .segmented__item, .switch__track, .nav__link, .tabbar__item, .sidebar__item, .menu__item { border: 1px solid ButtonText; }
  .btn--primary, [aria-current], [aria-pressed="true"], [aria-selected="true"], .switch input:checked + .switch__track {
    forced-color-adjust: none; background: Highlight; color: HighlightText;
  }
  .switch__knob { forced-color-adjust: none; background: ButtonText; }
}
