/*!
 * 3das design system — app.css
 * Part of the 3das network website and admin panel.
 *
 * Sections
 *   1. Tokens (light default, dark via [data-theme] / prefers-color-scheme)
 *   2. Base & typography
 *   3. Structure (stack, cluster, split, grid, layout-sidebar)
 *   4. Admin shell (app, sidebar, topbar, content, page header, breadcrumbs)
 *   5. Public site (site header, hero, sections, footer) & auth
 *   6. Cards, stats, meters
 *   7. Buttons
 *   8. Badges, ranks, dots, pills, avatars, chips, kbd
 *   9. Tables, lists, timeline, leaderboard, server cards, profile header
 *  10. Forms
 *  11. Tabs, pagination
 *  12. Feedback (alerts, toasts, empty, spinner, skeleton)
 *  13. Overlays (modal, dropdown, autocomplete, palette)
 *  14. Charts, heatmap, legend
 *  15. Misc & utilities
 *  16. Styleguide-only helpers
 *  17. Motion, forced colors, print
 */

/* ==========================================================================
   1. Tokens
   ========================================================================== */

:root {
  color-scheme: light;

  /* Brand accent — layouts inject the validated setting as <html style="--accent:#xxxxxx"> */
  --accent: #4f8cff;

  --font: "Inter", "InterVariable", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* Motion: short, ease-out, transform/opacity only (all of it is switched off for reduced motion) */
  --ease: cubic-bezier(.2, .7, .2, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --dur-fast: 120ms;
  --dur: 150ms;
  --dur-slow: 220ms;
  --press-scale: .97;

  --sidebar-w: 248px;
  --topbar-h: 56px;
  --gutter: 32px;

  /* Light surfaces & ink */
  --bg: #f6f7f9;
  --bg-elev: #fbfbfc;
  --surface: #ffffff;
  --surface-2: #f4f5f7;
  --surface-3: #ebedf1;
  --surface-elev: #ffffff;
  --border: #e4e6eb;
  --border-strong: #d2d5dc;
  --text: #0f1115;
  --text-2: #4a4f5c;
  --text-3: #676c7a;

  /* Status (text/icon use) */
  --success: #157347;
  --warning: #9a5400;
  --danger: #c8323a;
  --info: #0a6f8c;
  /* Status fills (buttons) — AA with their on-colour */
  --success-fill: #157347;
  --warning-fill: #f5b324;
  --danger-fill: #c8323a;
  --on-warning: #1d1400;
  --soft-pct: 10%;

  /* Controls */
  --input-bg: #ffffff;
  --track: #eef0f3;
  --thumb: #ffffff;
  --code-bg: #f6f7f9;
  --overlay: rgb(15 17 21 / .42);
  --toast-bg: #ffffff;

  /* Elevation */
  --shadow-xs: 0 1px 1px rgb(16 18 24 / .04);
  --shadow: 0 1px 2px rgb(16 18 24 / .05), 0 1px 3px rgb(16 18 24 / .04);
  --shadow-lg: 0 18px 44px -14px rgb(16 18 24 / .24), 0 4px 12px -4px rgb(16 18 24 / .08);

  /* Avatars: "saturation lightness" pairs combined with --avatar-hue */
  --avatar-bg: 70% 93%;
  --avatar-fg: 45% 30%;

  /* Charts (categorical order is fixed; validated for this surface) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --grid: #eceef1;
  --axis: #d3d6dc;
  --area-opacity: .1;
  --heat-0: #edeff3;

  /* Accent derivatives (fallbacks; refined below when relative colours are supported) */
  --accent-fill: var(--accent);
  --accent-contrast: #ffffff;
  --accent-text: var(--accent);
  --accent-hover: color-mix(in oklab, var(--accent-fill), #000 10%);
  --accent-soft: color-mix(in srgb, var(--accent) var(--soft-pct), transparent);
  --accent-border: color-mix(in srgb, var(--accent) 35%, transparent);
  --ring: color-mix(in srgb, var(--accent) 24%, transparent);

  --success-soft: color-mix(in srgb, var(--success) var(--soft-pct), transparent);
  --warning-soft: color-mix(in srgb, var(--warning) var(--soft-pct), transparent);
  --danger-soft: color-mix(in srgb, var(--danger) var(--soft-pct), transparent);
  --info-soft: color-mix(in srgb, var(--info) var(--soft-pct), transparent);

  --heat-1: color-mix(in oklab, var(--accent) 26%, var(--heat-0));
  --heat-2: color-mix(in oklab, var(--accent) 48%, var(--heat-0));
  --heat-3: color-mix(in oklab, var(--accent) 72%, var(--heat-0));
  --heat-4: var(--accent);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0c0f;
    --bg-elev: #0f1014;
    --surface: #15161b;
    --surface-2: #1b1d23;
    --surface-3: #23252d;
    --surface-elev: #1a1b21;
    --border: #25272f;
    --border-strong: #33363f;
    --text: #ededf0;
    --text-2: #a5a8b4;
    --text-3: #868a97;
    --success: #3ccf8e;
    --warning: #f2b53c;
    --danger: #ff6b6f;
    --info: #4cc3e8;
    --success-fill: #177d50;
    --warning-fill: #f2b53c;
    --danger-fill: #cf3a40;
    --on-warning: #1d1400;
    --soft-pct: 14%;
    --input-bg: #101115;
    --track: #0f1014;
    --thumb: #2c2e37;
    --code-bg: #101115;
    --overlay: rgb(4 5 7 / .62);
    --toast-bg: #1e2027;
    --shadow-xs: 0 1px 1px rgb(0 0 0 / .3);
    --shadow: 0 1px 2px rgb(0 0 0 / .35);
    --shadow-lg: 0 24px 64px -16px rgb(0 0 0 / .72), 0 8px 20px -8px rgb(0 0 0 / .5);
    --avatar-bg: 30% 22%;
    --avatar-fg: 70% 80%;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --grid: #23252c;
    --axis: #34373f;
    --area-opacity: .12;
    --heat-0: #1f2128;
    --accent-hover: color-mix(in oklab, var(--accent-fill), #fff 12%);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0c0f;
  --bg-elev: #0f1014;
  --surface: #15161b;
  --surface-2: #1b1d23;
  --surface-3: #23252d;
  --surface-elev: #1a1b21;
  --border: #25272f;
  --border-strong: #33363f;
  --text: #ededf0;
  --text-2: #a5a8b4;
  --text-3: #868a97;
  --success: #3ccf8e;
  --warning: #f2b53c;
  --danger: #ff6b6f;
  --info: #4cc3e8;
  --success-fill: #177d50;
  --warning-fill: #f2b53c;
  --danger-fill: #cf3a40;
  --on-warning: #1d1400;
  --soft-pct: 14%;
  --input-bg: #101115;
  --track: #0f1014;
  --thumb: #2c2e37;
  --code-bg: #101115;
  --overlay: rgb(4 5 7 / .62);
  --toast-bg: #1e2027;
  --shadow-xs: 0 1px 1px rgb(0 0 0 / .3);
  --shadow: 0 1px 2px rgb(0 0 0 / .35);
  --shadow-lg: 0 24px 64px -16px rgb(0 0 0 / .72), 0 8px 20px -8px rgb(0 0 0 / .5);
  --avatar-bg: 30% 22%;
  --avatar-fg: 70% 80%;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --grid: #23252c;
  --axis: #34373f;
  --area-opacity: .12;
  --heat-0: #1f2128;
  --accent-hover: color-mix(in oklab, var(--accent-fill), #fff 12%);
}

/* Accent derivatives with relative colour syntax:
   - fill: dark enough for white text (unless the accent is very light, then dark text)
   - text: readable on the surface in each theme */
@supports (color: oklch(from red calc(clamp(0, (l - 0.5) * 1000, 1) * l) min(c, 0.3) h)) {
  :root {
    --accent-fill: oklch(from var(--accent) calc(clamp(0, (l - 0.76) * 1000, 1) * l + (1 - clamp(0, (l - 0.76) * 1000, 1)) * min(l, 0.52)) c h);
    --accent-contrast: oklch(from var(--accent-fill) clamp(0, (0.66 - l) * 1000, 1) 0 0);
    --accent-text: oklch(from var(--accent) min(l, 0.53) c h);
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --accent-text: oklch(from var(--accent) max(l, 0.72) c h);
    }
  }
  :root[data-theme="dark"] {
    --accent-text: oklch(from var(--accent) max(l, 0.72) c h);
  }
}

/* Theme switch: suppress transitions for one frame so everything flips at once */
:root[data-theme-switching] *,
:root[data-theme-switching] *::before,
:root[data-theme-switching] *::after {
  transition: none !important;
}

/* …or, when the visitor switches it themselves, colours glide over for a moment. These
   transitions exist only while [data-theme-fading] is set (never on page load). */
@media (prefers-reduced-motion: no-preference) {
  :root[data-theme-fading],
  :root[data-theme-fading] *,
  :root[data-theme-fading] *::before,
  :root[data-theme-fading] *::after {
    transition-property: background-color, border-color, color, fill, stroke, box-shadow, outline-color, text-decoration-color !important;
    transition-duration: 220ms !important;
    transition-timing-function: ease !important;
    transition-delay: 0s !important;
  }
}

/* ==========================================================================
   2. Base & typography
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  tab-size: 4;
  accent-color: var(--accent-fill);
  scrollbar-color: var(--border-strong) transparent;
  background: var(--bg);
}

html.is-scroll-locked {
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: "cv11", "ss03";
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.015em;
  color: var(--text);
}

h1 { font-size: 1.75rem; letter-spacing: -0.025em; }
h2 { font-size: 1.25rem; letter-spacing: -0.02em; }
h3 { font-size: 1rem; }
h4 { font-size: .875rem; }
h5, h6 { font-size: .8125rem; }

p, ul, ol, dl, figure, blockquote, pre {
  margin: 0;
}

a {
  color: var(--accent-text);
  text-decoration: none;
  text-underline-offset: 2px;
  transition: color var(--dur) var(--ease);
}

a:hover {
  text-decoration: underline;
}

strong, b {
  font-weight: 600;
}

small {
  font-size: 12.5px;
}

img, video, canvas {
  max-width: 100%;
  height: auto;
}

svg {
  flex-shrink: 0;
}

button, input, select, textarea, optgroup {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button {
  cursor: pointer;
}

hr {
  height: 1px;
  margin: 16px 0;
  border: 0;
  background: var(--border);
}

code, kbd, samp, pre {
  font-family: var(--mono);
}

table {
  border-collapse: collapse;
}

[hidden] {
  display: none !important;
}

::selection {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* Icons (SVG sprite) */
.icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  vertical-align: -0.2em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}

.icon--sm { width: 14px; height: 14px; }
.icon--lg { width: 20px; height: 20px; }
.icon--xl { width: 24px; height: 24px; }

/* ==========================================================================
   3. Structure
   ========================================================================== */

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.stack--sm { gap: 8px; }
.stack--lg { gap: 24px; }

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  gap: 8px;
  min-width: 0;
}

.split {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  justify-content: space-between;
  gap: 8px 16px;
  min-width: 0;
}

.grid {
  --grid-gap: 16px;
  --grid-min: 240px;
  display: grid;
  gap: var(--grid-gap);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--grid-min)), 1fr));
  min-width: 0;
}

.grid > * {
  min-width: 0;
}

/* "At most N columns, collapse when narrow": each column is at least
   max(minimum, 1/N of the row) wide, so auto-fit never exceeds N. */
.grid--2 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, max(320px, calc((100% - var(--grid-gap)) / 2))), 1fr));
}

.grid--3 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, max(250px, calc((100% - 2 * var(--grid-gap)) / 3))), 1fr));
}

.grid--4 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, max(150px, calc((100% - 3 * var(--grid-gap)) / 4))), 1fr));
}

.grid--auto {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
}

/* Main column + 340px aside that wraps below when the main column would get too narrow */
.layout-sidebar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 24px;
  min-width: 0;
}

.layout-sidebar > :first-child {
  flex: 999 1 0;
  min-width: min(100%, 56%);
}

.layout-sidebar > :last-child:not(:first-child) {
  flex: 1 1 340px;
  min-width: 0;
}

/* ==========================================================================
   4. Admin shell
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  height: var(--topbar-h);
  padding: 0 18px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
  white-space: nowrap;
}

.sidebar__brand:hover {
  text-decoration: none;
}

.sidebar__brand img,
.sidebar__brand > svg:not(.icon) {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  flex-shrink: 0;
}

.sidebar__brand .badge,
.sidebar__brand small {
  margin-left: 2px;
}

.sidebar__brand small {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.sidebar__nav {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-height: 0;
  padding: 6px 12px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.nav__section {
  margin: 18px 8px 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-3);
}

.sidebar__nav > .nav__section:first-child {
  margin-top: 6px;
}

.nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  text-decoration: none;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur-fast) var(--ease-out);
}

.nav__item:active {
  transform: scale(.98);
}

.nav__item .icon {
  width: 18px;
  height: 18px;
  color: var(--text-3);
  transition: color var(--dur) var(--ease);
}

.nav__item:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.nav__item:hover .icon {
  color: var(--text-2);
}

.nav__item.is-active,
.nav__item[aria-current="page"] {
  background: var(--surface-3);
  color: var(--text);
}

.nav__item.is-active .icon,
.nav__item[aria-current="page"] .icon {
  color: var(--accent-text);
}

.nav__item.is-active::before,
.nav__item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.nav__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  margin-left: auto;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--danger-fill);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.sidebar__footer {
  flex-shrink: 0;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.sidebar__footer .dropdown {
  display: block;
}

.sidebar__footer .dropdown > .btn,
.sidebar__footer .dropdown > button {
  width: 100%;
  height: auto;
  min-height: 44px;
  justify-content: flex-start;
  gap: 10px;
  padding: 6px 8px;
  text-align: left;
}

.sidebar__footer .dropdown__menu {
  left: 0;
  right: 0;
  top: auto;
  bottom: calc(100% + 6px);
  min-width: 0;
  transform-origin: bottom center;
}

.app__main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 var(--gutter);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
}

.topbar__title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.topbar .pill,
.topbar a.pill {
  height: 30px;
  padding: 0 11px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
}

.topbar a.pill:hover {
  color: var(--text);
  border-color: var(--border-strong);
  text-decoration: none;
}

.app [data-nav-toggle] {
  display: none;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px var(--gutter) 64px;
  min-width: 0;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  min-width: 0;
}

.page-header > :first-child {
  min-width: 0;
}

.page-header__title {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
}

.page-header__subtitle {
  margin-top: 4px;
  font-size: 14px;
  color: var(--text-2);
}

.page-header__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.breadcrumbs,
.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
}

.breadcrumbs a {
  color: var(--text-2);
}

.breadcrumbs a:hover {
  color: var(--text);
  text-decoration: none;
}

.breadcrumbs li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.breadcrumbs li + li::before,
.breadcrumbs > :not(ol) + :not(ol)::before {
  content: "/";
  margin-right: 6px;
  color: var(--border-strong);
  font-weight: 400;
}

.breadcrumbs [aria-current],
.breadcrumbs li:last-child,
.breadcrumbs > span:last-child {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .breadcrumbs,
.topbar .breadcrumbs ol {
  flex-wrap: nowrap;
  overflow: hidden;
}

.topbar .breadcrumbs > *,
.topbar .breadcrumbs li {
  flex-shrink: 0;
}

.topbar .breadcrumbs > :last-child,
.topbar .breadcrumbs li:last-child {
  flex-shrink: 1;
  min-width: 0;
}

/* Off-canvas sidebar below 1024px */
@media (max-width: 1023.98px) {
  :root {
    --gutter: 20px;
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 80;
    width: min(calc(var(--sidebar-w) + 24px), 86vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform .24s var(--ease), visibility 0s linear .24s;
  }

  .app.is-nav-open .sidebar {
    transform: none;
    visibility: visible;
    box-shadow: var(--shadow-lg);
    transition: transform .24s var(--ease), visibility 0s;
  }

  .app::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 75;
    background: var(--overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity .24s var(--ease);
  }

  .app.is-nav-open::after {
    opacity: 1;
    pointer-events: auto;
  }

  .app [data-nav-toggle] {
    display: inline-flex;
  }
}

@media (max-width: 640px) {
  :root {
    --gutter: 16px;
  }

  .content {
    gap: 20px;
    padding-top: 20px;
    padding-bottom: 48px;
  }

  .page-header__title {
    font-size: 21px;
  }

  .page-header__actions {
    width: 100%;
  }

  .topbar {
    gap: 8px;
  }

  .topbar .kbd {
    display: none;
  }

  /* Phones: the topbar shows only the current page, not the whole trail */
  .topbar .breadcrumbs > :not(:last-child):not(ol),
  .topbar .breadcrumbs li:not(:last-child) {
    display: none;
  }

  .topbar .breadcrumbs > :last-child::before,
  .topbar .breadcrumbs li:last-child::before {
    content: none;
  }
}

@media (max-width: 480px) {
  /* Search trigger becomes icon-only; its text stays available to screen readers */
  .topbar [data-palette-open] {
    width: var(--btn-h);
    padding: 0;
  }

  .topbar [data-palette-open] > span:not(.kbd) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

/* ==========================================================================
   5. Public site & auth
   ========================================================================== */

.site {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  font-size: 15px;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  min-width: 0;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: 8px 20px;
  width: 100%;
  max-width: 1200px;
  min-height: 64px;
  margin: 0 auto;
  padding: 0 24px;
}

.site-header__inner > form,
.site-header__inner > .site-search {
  flex: 0 1 280px;
  min-width: 0;
  margin-left: auto;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.025em;
  text-decoration: none;
}

.site-brand:hover {
  text-decoration: none;
}

.site-brand img,
.site-brand > svg:not(.icon) {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.site-nav__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur-fast) var(--ease-out);
}

.site-nav__item:active {
  transform: scale(.97);
}

.site-nav__item:hover {
  color: var(--text);
  background: var(--surface-2);
  text-decoration: none;
}

.site-nav__item.is-active,
.site-nav__item[aria-current="page"] {
  color: var(--text);
  background: var(--surface-3);
}

.site-main {
  flex: 1 0 auto;
  min-width: 0;
}

.site-footer {
  margin-top: 64px;
  padding: 32px 0 40px;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 13px;
}

.site-footer a {
  color: var(--text-2);
}

.site-footer a:hover {
  color: var(--text);
}

/* Hero */
.hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: 88px 0 64px;
  text-align: center;
}

.hero::before {
  content: "";
  position: absolute;
  inset: -40% -10% auto;
  z-index: -1;
  height: 130%;
  background:
    radial-gradient(42% 46% at 50% 38%, color-mix(in srgb, var(--accent) 26%, transparent), transparent 72%),
    radial-gradient(30% 30% at 74% 52%, color-mix(in srgb, var(--series-7) 10%, transparent), transparent 70%);
  filter: blur(8px);
  pointer-events: none;
}

.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--text) 6%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--text) 6%, transparent) 1px, transparent 1px);
  background-size: 56px 56px;
  background-position: center top;
  -webkit-mask-image: radial-gradient(60% 70% at 50% 30%, #000 20%, transparent 75%);
  mask-image: radial-gradient(60% 70% at 50% 30%, #000 20%, transparent 75%);
  pointer-events: none;
}

.hero > * {
  position: relative;
}

.hero__title {
  max-width: 900px;
  margin: 0 auto;
  font-size: clamp(2.4rem, 6.2vw, 4.4rem);
  font-weight: 700;
  line-height: 1.04;
  letter-spacing: -0.04em;
  color: var(--text);
  text-wrap: balance;
}

@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .hero__title {
    background: linear-gradient(180deg, var(--text) 35%, color-mix(in srgb, var(--text) 62%, transparent) 110%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
}

.hero__subtitle {
  max-width: 640px;
  margin: 18px auto 0;
  font-size: clamp(1rem, 1.6vw, 1.175rem);
  line-height: 1.6;
  color: var(--text-2);
  text-wrap: pretty;
}

.hero .cluster {
  justify-content: center;
}

.hero__title + .hero__subtitle + .cluster,
.hero__subtitle + .cluster {
  margin-top: 28px;
}

.hero__stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr));
  gap: 12px;
  max-width: 1000px;
  margin: 44px auto 0;
  text-align: left;
}

.hero__stats .stat {
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

/* Sections */
.section {
  padding: 40px 0;
}

.section + .section {
  padding-top: 8px;
}

.section__header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 16px;
}

.section__title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.section__link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}

.section__link:hover {
  color: var(--accent-text);
  text-decoration: none;
}

.section__link .icon {
  transition: transform var(--dur) var(--ease);
}

.section__link:hover .icon {
  transform: translateX(2px);
}

/* Auth */
.auth {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 32px 16px;
  overflow: hidden;
}

.auth::before {
  content: "";
  position: absolute;
  inset: -30% -20% auto;
  z-index: -1;
  height: 90%;
  background: radial-gradient(40% 50% at 50% 40%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 70%);
  pointer-events: none;
}

.auth__card {
  width: 100%;
  max-width: 400px;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.auth__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-align: center;
  text-decoration: none;
}

.auth__brand img,
.auth__brand > svg:not(.icon) {
  width: 44px;
  height: 44px;
  border-radius: 12px;
}

.auth__brand p,
.auth__brand small {
  font-size: 14px;
  font-weight: 400;
  letter-spacing: normal;
  color: var(--text-2);
}

@media (max-width: 760px) {
  /* Phones: brand + actions, then search, then scrollable nav; header scrolls away */
  .site-header {
    position: relative;
  }

  .site-header__inner {
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 10px 16px;
  }

  .site-brand {
    margin-right: auto;
  }

  .site-header__inner > form,
  .site-header__inner > .site-search {
    order: 9;
    flex: 1 1 100%;
    margin-left: 0;
  }

  .hero__stats {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr));
  }

  .site-nav {
    order: 10;
    width: 100%;
    margin: 0 -4px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .site-nav::-webkit-scrollbar {
    display: none;
  }

  .container {
    padding: 0 16px;
  }

  .hero {
    padding: 56px 0 44px;
  }

  .section {
    padding: 28px 0;
  }

  .auth__card {
    padding: 24px 20px;
  }
}

/* ==========================================================================
   6. Cards, stats, meters
   ========================================================================== */

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* A bare card (no header/body/footer parts) gets body padding itself */
.card:not(:has(.card__header, .card__body, .card__footer, .table-wrap)) {
  padding: 20px;
}

.card > :first-child {
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
}

.card > :last-child {
  border-bottom-left-radius: inherit;
  border-bottom-right-radius: inherit;
}

.card__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  min-height: 54px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

.card__header > :first-child {
  min-width: 0;
}

.card__title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.01em;
  color: var(--text);
}

.card__title .icon {
  color: var(--text-3);
}

.card__subtitle {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-3);
}

.card__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.card__body {
  flex: 1 1 auto;
  min-width: 0;
  padding: 20px;
}

.card--flush .card__body {
  padding: 0;
}

.card__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 60%, var(--surface));
}

.card__footer > :first-child:not(.btn):not(form) {
  margin-right: auto;
  color: var(--text-3);
  font-size: 13px;
}

.card--danger {
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

.card--danger .card__header {
  border-bottom-color: color-mix(in srgb, var(--danger) 22%, var(--border));
}

.card--danger .card__title,
.card--danger .card__title .icon {
  color: var(--danger);
}

.card--danger .card__footer {
  background: var(--danger-soft);
  border-top-color: color-mix(in srgb, var(--danger) 22%, var(--border));
}

a.card {
  color: inherit;
  text-decoration: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur-fast) var(--ease-out);
}

a.card:hover {
  border-color: var(--border-strong);
  text-decoration: none;
}

a.card:active {
  transform: scale(.995);
}

/* Stat tiles */
.stat {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat__label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 36px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}

.stat__value {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.025em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.stat__value small {
  margin-left: 2px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: normal;
  color: var(--text-3);
}

.stat__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  font-size: 12.5px;
  color: var(--text-3);
}

.stat__icon {
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-3);
}

.stat__icon .icon {
  width: 16px;
  height: 16px;
}

svg.stat__icon {
  width: 18px;
  height: 18px;
  top: 17px;
  right: 17px;
  padding: 0;
  border: 0;
  background: none;
}

.stat .chart {
  margin-top: 6px;
}

.stat--hero {
  padding: 22px 24px;
}

.stat--hero .stat__value {
  font-size: clamp(36px, 5vw, 48px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.035em;
}

.stat--hero .stat__label {
  font-size: 14px;
}

/* Meter */
.meter {
  position: relative;
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--accent) 16%, var(--surface-3));
}

.meter__bar {
  display: block;
  width: var(--pct, 0%);
  max-width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transform-origin: left center;
  transition: width .5s var(--ease), background-color var(--dur) var(--ease);
}

.meter--success { background: color-mix(in srgb, var(--success) 18%, var(--surface-3)); }
.meter--success .meter__bar { background: var(--success); }
.meter--warning { background: color-mix(in srgb, var(--warning-fill) 22%, var(--surface-3)); }
.meter--warning .meter__bar { background: var(--warning-fill); }
.meter--danger { background: color-mix(in srgb, var(--danger-fill) 18%, var(--surface-3)); }
.meter--danger .meter__bar { background: var(--danger-fill); }

/* ==========================================================================
   7. Buttons
   ========================================================================== */

.btn {
  --btn-h: 36px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--btn-h);
  min-width: 0;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  vertical-align: middle;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease),
    opacity var(--dur) var(--ease),
    transform var(--dur-fast) var(--ease-out);
}

.btn:hover {
  background: var(--surface-2);
  border-color: color-mix(in srgb, var(--text-3) 45%, var(--border-strong));
  text-decoration: none;
}

/* Tactile press: a quick, slight shrink (wide buttons shrink less so the edges barely move) */
.btn:active {
  transform: scale(var(--press-scale));
  transition-duration: var(--dur), var(--dur), var(--dur), var(--dur), var(--dur), 60ms;
}

.btn--block,
.btn--lg {
  --press-scale: .985;
}

.btn--icon {
  --press-scale: .92;
}

.btn .icon {
  width: 16px;
  height: 16px;
  margin-inline: -2px;
}

.btn .kbd {
  margin-left: 2px;
  margin-right: -6px;
}

.btn .badge,
.btn .pill {
  margin-right: -4px;
}

.btn--secondary {
  background: var(--surface);
}

.btn--primary {
  border-color: transparent;
  background: var(--accent-fill);
  color: var(--accent-contrast);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .14), 0 1px 2px rgb(0 0 0 / .14);
}

.btn--primary:hover {
  border-color: transparent;
  background: var(--accent-hover);
}

.btn--ghost {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--text-2);
}

.btn--ghost:hover {
  border-color: transparent;
  background: var(--surface-2);
  color: var(--text);
}

.btn--danger {
  border-color: transparent;
  background: var(--danger-fill);
  color: #fff;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .12), 0 1px 2px rgb(0 0 0 / .14);
}

.btn--danger:hover {
  border-color: transparent;
  background: color-mix(in oklab, var(--danger-fill), #000 12%);
}

.btn--warning {
  border-color: transparent;
  background: var(--warning-fill);
  color: var(--on-warning);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .2), 0 1px 2px rgb(0 0 0 / .12);
}

.btn--warning:hover {
  border-color: transparent;
  background: color-mix(in oklab, var(--warning-fill), #000 8%);
}

.btn--success {
  border-color: transparent;
  background: var(--success-fill);
  color: #fff;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .12), 0 1px 2px rgb(0 0 0 / .14);
}

.btn--success:hover {
  border-color: transparent;
  background: color-mix(in oklab, var(--success-fill), #000 12%);
}

.btn--sm {
  --btn-h: 30px;
  gap: 6px;
  padding: 0 10px;
  font-size: 13px;
  border-radius: 7px;
}

.btn--sm .icon {
  width: 14px;
  height: 14px;
}

.btn--lg {
  --btn-h: 44px;
  gap: 10px;
  padding: 0 20px;
  font-size: 15px;
  border-radius: 10px;
}

.btn--lg .icon {
  width: 18px;
  height: 18px;
}

.btn--icon {
  width: var(--btn-h);
  padding: 0;
}

.btn--icon .icon {
  margin: 0;
}

.btn--block {
  display: flex;
  width: 100%;
}

.btn:disabled,
.btn[aria-disabled="true"],
.btn.is-disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
  pointer-events: none;
}

/* Busy (submitting) button: the label fades out in place, so the width never changes, and a
   spinner fades in on top. Stays fully opaque even though app.js also disables it. */
.btn.is-loading,
.btn.is-loading:disabled {
  color: transparent !important;
  opacity: 1;
  cursor: progress;
  pointer-events: none;
}

.btn.is-loading > * {
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease);
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 16px;
  height: 16px;
  margin: auto;
  border: 2px solid var(--text-2);
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spinner-in var(--dur-slow) var(--ease-out) both, spin .7s linear infinite;
}

.btn--sm.is-loading::after {
  width: 14px;
  height: 14px;
}

.btn--primary.is-loading::after,
.btn--danger.is-loading::after,
.btn--success.is-loading::after {
  border-color: #fff;
  border-right-color: transparent;
}

.btn--primary.is-loading::after {
  border-color: var(--accent-contrast);
  border-right-color: transparent;
}

.btn--warning.is-loading::after {
  border-color: var(--on-warning);
  border-right-color: transparent;
}

/* Copy buttons: the icon morphs into a check and back */
.btn.is-copied .icon {
  color: var(--success);
}

.is-copied .icon,
.is-uncopied .icon {
  animation: icon-swap 260ms var(--ease-out);
}

.btn-group {
  display: inline-flex;
  align-items: stretch;
  min-width: 0;
}

.btn-group > .btn {
  border-radius: 0;
}

.btn-group > .btn:first-child {
  border-top-left-radius: var(--radius-sm);
  border-bottom-left-radius: var(--radius-sm);
}

.btn-group > .btn:last-child {
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
}

.btn-group > .btn + .btn {
  margin-left: -1px;
}

/* Joined buttons share borders, so they darken on press instead of shrinking */
.btn-group > .btn:active {
  transform: none;
  background: var(--surface-3);
}

.btn-group > .btn:hover,
.btn-group > .btn:focus-visible {
  z-index: 1;
}

.btn-group > .btn.is-active,
.btn-group > .btn[aria-pressed="true"] {
  z-index: 1;
  background: var(--surface-3);
  color: var(--text);
}

/* ==========================================================================
   8. Badges, ranks, dots, pills, avatars, chips, kbd
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  max-width: 100%;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
  text-decoration: none;
}

.badge .icon {
  width: 12px;
  height: 12px;
  margin-left: -1px;
}

a.badge:hover {
  text-decoration: none;
  filter: brightness(1.06);
}

.badge--neutral {
  background: var(--surface-3);
  color: var(--text-2);
}

.badge--accent {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 20%, transparent);
  color: var(--accent-text);
}

.badge--success {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 20%, transparent);
  color: var(--success);
}

.badge--warning {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 22%, transparent);
  color: var(--warning);
}

.badge--danger {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 20%, transparent);
  color: var(--danger);
}

.badge--info {
  background: var(--info-soft);
  border-color: color-mix(in srgb, var(--info) 20%, transparent);
  color: var(--info);
}

/* Rank badge: colour lives in the dot, the label stays in text ink */
.rank {
  --rc: var(--rank-color, var(--text-3));
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  max-width: 100%;
  padding: 0 9px 0 8px;
  border: 1px solid color-mix(in srgb, var(--rc) 32%, transparent);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--rc) 11%, transparent);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
}

.rank::before {
  content: "";
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--rc);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--rc) 22%, transparent);
}

/* Status dots */
.dot {
  position: relative;
  display: inline-block;
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--text-3);
  vertical-align: middle;
}

.dot--online {
  background: var(--success);
  animation: dot-pulse 2.6s var(--ease) infinite;
}

.dot--offline {
  background: color-mix(in srgb, var(--text-3) 70%, transparent);
}

.dot--warning {
  background: var(--warning);
}

@keyframes dot-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 45%, transparent); }
  70% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--success) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 0%, transparent); }
}

/* Counter pill */
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 20px;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-decoration: none;
  vertical-align: middle;
}

.tabs__item .pill,
.nav__item .pill {
  height: 18px;
  min-width: 18px;
  padding: 0 6px;
  font-size: 11px;
}

.tabs__item.is-active .pill {
  background: var(--accent-soft);
  color: var(--accent-text);
}

/* Avatars */
.avatar {
  --size: 32px;
  display: inline-grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 50%;
  background: hsl(var(--avatar-hue, 220) var(--avatar-bg));
  color: hsl(var(--avatar-hue, 220) var(--avatar-fg));
  box-shadow: inset 0 0 0 1px hsl(var(--avatar-hue, 220) 40% 50% / .16);
  font-size: calc(var(--size) * .38);
  font-weight: 600;
  line-height: 1;
  letter-spacing: .01em;
  text-transform: uppercase;
  vertical-align: middle;
  user-select: none;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar--sm { --size: 24px; font-size: 10px; }
.avatar--md { --size: 32px; }
.avatar--lg { --size: 44px; }
.avatar--xl { --size: 72px; font-size: 26px; letter-spacing: 0; }

/* Player chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  max-width: 100%;
  min-width: 0;
  padding: 0 10px 0 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease), transform var(--dur-fast) var(--ease-out);
}

a.chip:active,
.chip:has(a:active) {
  transform: scale(.96);
}

.chip:not(:has(.avatar)) {
  padding-left: 10px;
}

.chip .avatar {
  --size: 22px;
  font-size: 9px;
}

.chip a {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: inherit;
}

.chip .dot {
  margin-left: 2px;
}

a.chip:hover,
.chip:has(a:hover) {
  border-color: var(--border-strong);
  background: var(--surface-3);
  text-decoration: none;
}

.chip a:hover {
  text-decoration: none;
}

/* Keyboard key */
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text-2);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

/* ==========================================================================
   9. Tables, lists, timeline, leaderboard, server cards, profile header
   ========================================================================== */

.table-wrap {
  position: relative; /* contain absolutely positioned descendants (e.g. .sr-only) in the scroll box */
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.card--flush .table-wrap,
.card > .table-wrap {
  border: 0;
  border-radius: inherit;
  background: transparent;
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.table th {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .01em;
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.table th:first-child,
.table td:first-child {
  padding-left: 20px;
}

.table th:last-child,
.table td:last-child {
  padding-right: 20px;
}

.table tbody tr:last-child td,
.table tfoot tr:last-child td {
  border-bottom: 0;
}

.table tbody tr {
  transition: background-color var(--dur) var(--ease);
}

.table tbody tr:hover {
  background: color-mix(in srgb, var(--surface-2) 55%, transparent);
}

/* Inside cells, groups stay on one line; the table scrolls horizontally instead */
.table .cluster {
  flex-wrap: nowrap;
}

.table tr[data-href] {
  cursor: pointer;
}

.table tr[data-href]:hover {
  background: var(--surface-2);
}

.table tr[data-href]:active {
  background: var(--surface-3);
  transition-duration: 60ms;
}

.table tr[data-href]:focus-visible {
  outline-offset: -2px;
}

.table td a:not(.btn):not(.badge):not(.chip):not(.dropdown__item):not(.pill) {
  color: var(--text);
  font-weight: 500;
}

.table td a:not(.btn):not(.badge):not(.chip):not(.dropdown__item):not(.pill):hover {
  color: var(--accent-text);
  text-decoration: none;
}

.table .is-num,
.table th.is-num,
.table td.is-num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.table__actions,
.table td.table__actions,
.table th.table__actions {
  width: 1%;
  text-align: right;
  white-space: nowrap;
}

td.table__actions > * + * {
  margin-left: 4px;
}

td.table__actions .cluster {
  justify-content: flex-end;
  flex-wrap: nowrap;
}

.table--compact th {
  padding: 8px 12px;
}

.table--compact td {
  padding: 8px 12px;
  font-size: 13px;
}

.table--compact th:first-child,
.table--compact td:first-child {
  padding-left: 16px;
}

.table--compact th:last-child,
.table--compact td:last-child {
  padding-right: 16px;
}

.table th a.sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: inherit;
  text-decoration: none;
}

.table th a.sort:hover {
  color: var(--text);
  text-decoration: none;
}

.table th a.sort::after {
  content: "";
  width: 8px;
  height: 10px;
  background-color: currentColor;
  opacity: .45;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 10'%3E%3Cpath d='M4 0L7.5 4h-7zM4 10L.5 6h7z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 10'%3E%3Cpath d='M4 0L7.5 4h-7zM4 10L.5 6h7z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.table th a.sort.is-asc,
.table th a.sort.is-desc {
  color: var(--text);
}

.table th a.sort.is-asc::after,
.table th a.sort.is-desc::after {
  opacity: 1;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 10'%3E%3Cpath d='M4 1.5L7.5 6h-7z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 10'%3E%3Cpath d='M4 1.5L7.5 6h-7z'/%3E%3C/svg%3E");
}

.table th a.sort.is-desc::after {
  transform: rotate(180deg);
}

.table tfoot td {
  border-top: 1px solid var(--border);
  border-bottom: 0;
  font-weight: 600;
}

/* Lists */
.list {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.list__item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

.list__item:last-child {
  border-bottom: 0;
}

.card:not(.card--flush) .card__body .list__item {
  padding-left: 0;
  padding-right: 0;
}

.card:not(.card--flush) .card__body .list__item:first-child {
  padding-top: 0;
}

.card:not(.card--flush) .card__body .list__item:last-child {
  padding-bottom: 0;
}

a.list__item,
.list__item[data-href] {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease);
}

a.list__item:hover,
.list__item[data-href]:hover {
  background: var(--surface-2);
  text-decoration: none;
}

a.list__item:active,
.list__item[data-href]:active {
  background: var(--surface-3);
  transition-duration: 60ms;
}

.list__main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.list__main > * {
  min-width: 0;
}

.list__meta {
  font-size: 13px;
  color: var(--text-3);
}

.list__item > .list__meta {
  flex-shrink: 0;
  text-align: right;
  white-space: nowrap;
}

.list__actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

/* Timeline */
.timeline {
  position: relative;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline__item {
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: start;
  column-gap: 12px;
  padding-bottom: 18px;
}

.timeline__item:last-child {
  padding-bottom: 0;
}

.timeline__item:not(:last-child)::before {
  content: "";
  position: absolute;
  top: 32px;
  bottom: 4px;
  left: 13.5px;
  width: 1px;
  background: var(--border);
}

.timeline__icon {
  grid-column: 1;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-3);
}

.timeline__icon .icon {
  width: 14px;
  height: 14px;
}

.timeline__icon--danger {
  border-color: color-mix(in srgb, var(--danger) 26%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
}

.timeline__icon--warning {
  border-color: color-mix(in srgb, var(--warning) 28%, transparent);
  background: var(--warning-soft);
  color: var(--warning);
}

.timeline__icon--success {
  border-color: color-mix(in srgb, var(--success) 26%, transparent);
  background: var(--success-soft);
  color: var(--success);
}

.timeline__icon--info {
  border-color: color-mix(in srgb, var(--info) 26%, transparent);
  background: var(--info-soft);
  color: var(--info);
}

.timeline__icon--accent {
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.timeline__body {
  grid-column: 2;
  min-width: 0;
  padding-top: 4px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  overflow-wrap: anywhere;
}

.timeline__body a {
  font-weight: 500;
}

.timeline__item > .timeline__time {
  grid-column: 3;
  padding-top: 5px;
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

.timeline__body .timeline__time {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-3);
}

@media (max-width: 480px) {
  .timeline__item > .timeline__time {
    grid-column: 2;
    grid-row: 2;
    padding-top: 2px;
  }
}

/* Leaderboard */
.leaderboard {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard__row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 12px;
  row-gap: 6px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
  transition: background-color var(--dur) var(--ease);
}

.leaderboard__row:last-child {
  border-bottom: 0;
}

a.leaderboard__row:hover,
.leaderboard__row[data-href]:hover {
  background: var(--surface-2);
  text-decoration: none;
}

a.leaderboard__row:active,
.leaderboard__row[data-href]:active {
  background: var(--surface-3);
  transition-duration: 60ms;
}

.card:not(.card--flush) .card__body .leaderboard__row {
  padding-left: 0;
  padding-right: 0;
}

.leaderboard__pos {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--text-3);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.leaderboard__pos.is-1,
.leaderboard__pos.is-2,
.leaderboard__pos.is-3,
.leaderboard__row.is-1 .leaderboard__pos,
.leaderboard__row.is-2 .leaderboard__pos,
.leaderboard__row.is-3 .leaderboard__pos {
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .5), inset 0 -1px 0 rgb(0 0 0 / .08), 0 1px 2px rgb(0 0 0 / .18);
}

.leaderboard__pos.is-1,
.leaderboard__row.is-1 .leaderboard__pos {
  background: linear-gradient(150deg, #ffe48f 0%, #f3b833 55%, #d99a12 100%);
  color: #4a3200;
}

.leaderboard__pos.is-2,
.leaderboard__row.is-2 .leaderboard__pos {
  background: linear-gradient(150deg, #f6f8fb 0%, #cdd3dc 55%, #a5aebb 100%);
  color: #29303a;
}

.leaderboard__pos.is-3,
.leaderboard__row.is-3 .leaderboard__pos {
  background: linear-gradient(150deg, #f7cfa8 0%, #da925a 55%, #b46c35 100%);
  color: #3b1e07;
}

.leaderboard__player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 500;
}

.leaderboard__player > a,
.leaderboard__player > span:not(.avatar):not(.rank):not(.badge):not(.dot) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.leaderboard__player > a:hover {
  color: var(--accent-text);
  text-decoration: none;
}

.leaderboard__value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.leaderboard__value small,
.leaderboard__value .subtle {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-3);
}

.leaderboard__bar {
  position: relative;
  display: block;
  grid-column: 2 / -1;
  height: 4px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
}

.leaderboard__bar::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--pct, 0%);
  max-width: 100%;
  border-radius: inherit;
  background: var(--accent);
  transform-origin: left center;
}

/* Server cards */
.server-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: border-color var(--dur) var(--ease);
}

.server-card:hover {
  border-color: var(--border-strong);
}

.server-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.server-card__header > :first-child {
  min-width: 0;
}

.server-card__name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.server-card__name a {
  color: inherit;
}

.server-card__name a:hover {
  color: var(--accent-text);
  text-decoration: none;
}

.server-card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
  color: var(--text-2);
  font-size: 13px;
}

.server-card__meta > * {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.server-card__meta .icon {
  width: 14px;
  height: 14px;
  color: var(--text-3);
}

.server-card__players {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.server-card__players > li {
  display: contents;
}

.server-card.is-offline {
  background: color-mix(in srgb, var(--surface-2) 50%, var(--surface));
}

.server-card.is-offline .server-card__name {
  color: var(--text-2);
}

.server-card.is-offline .meter {
  background: var(--surface-3);
}

.server-card.is-offline .meter__bar {
  background: var(--text-3);
}

/* Profile header */
.profile-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 20px;
  min-width: 0;
}

.profile-header > .avatar {
  --size: 72px;
  font-size: 26px;
}

.profile-header__main {
  display: flex;
  flex: 1 1 280px;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.profile-header__name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
}

.profile-header__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  color: var(--text-2);
  font-size: 13px;
}

.profile-header__meta > * {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.profile-header__meta .icon {
  width: 14px;
  height: 14px;
  color: var(--text-3);
}

.profile-header__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

@media (max-width: 640px) {
  .profile-header > .avatar {
    --size: 56px;
    font-size: 20px;
  }

  .profile-header__name {
    font-size: 22px;
  }

  .profile-header__actions {
    width: 100%;
  }
}

/* ==========================================================================
   10. Forms
   ========================================================================== */

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  margin: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.field__label {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}

.field__label .subtle,
.field__label small {
  margin-left: 4px;
  font-weight: 400;
  color: var(--text-3);
}

.field__hint {
  color: var(--text-3);
  font-size: 12.5px;
  line-height: 1.45;
}

.field__error {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.45;
}

.field__error .icon {
  width: 14px;
  height: 14px;
}

.input,
.select,
.textarea {
  display: block;
  width: 100%;
  min-width: 0;
  height: 36px;
  margin: 0;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  box-shadow: var(--shadow-xs);
  font-size: 14px;
  line-height: 1.4;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-3);
  opacity: 1;
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: color-mix(in srgb, var(--text-3) 55%, var(--border-strong));
}

.input:focus,
.select:focus,
.textarea:focus,
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.input:disabled,
.select:disabled,
.textarea:disabled,
.input[readonly] {
  background: var(--surface-2);
  color: var(--text-2);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  opacity: .7;
  cursor: not-allowed;
}

.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"],
.field.has-error .input,
.field.has-error .select,
.field.has-error .textarea {
  border-color: var(--danger);
}

.input[aria-invalid="true"]:focus,
.field.has-error .input:focus {
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}

.input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
}

/* Clear button of search inputs, drawn in the theme's ink instead of the browser default */
.input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin: 0 -4px 0 6px;
  border-radius: 50%;
  background-color: var(--text-3);
  cursor: pointer;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M17 7L7 17M7 7l10 10'/%3E%3C/svg%3E") center / 14px no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M17 7L7 17M7 7l10 10'/%3E%3C/svg%3E") center / 14px no-repeat;
}

.input[type="search"]::-webkit-search-cancel-button:hover {
  background-color: var(--text);
}

.input[type="color"] {
  width: 52px;
  padding: 3px;
  cursor: pointer;
}

.input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 5px;
}

.input[type="color"]::-moz-color-swatch {
  border: 0;
  border-radius: 5px;
}

.input[type="file"] {
  height: auto;
  padding: 6px;
  font-size: 13px;
}

.input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.select {
  padding-right: 34px;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23868a97' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 15px;
  cursor: pointer;
  text-overflow: ellipsis;
}

.select[multiple],
.select[size] {
  height: auto;
  padding: 6px;
  background-image: none;
}

.select option {
  background: var(--surface);
  color: var(--text);
}

.textarea {
  height: auto;
  min-height: 88px;
  padding: 8px 12px;
  line-height: 1.5;
  resize: vertical;
}

.textarea--code {
  min-height: 120px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--code-bg);
}

.char-count {
  align-self: flex-end;
  margin-top: -2px;
  color: var(--text-3);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.char-count.is-warning {
  color: var(--warning);
}

.char-count.is-over {
  color: var(--danger);
  font-weight: 600;
}

/* Checkbox / radio (label wrapper) */
.checkbox {
  display: inline-flex;
  align-items: flex-start;
  gap: 9px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  cursor: pointer;
}

.checkbox input {
  position: relative;
  display: grid;
  place-content: center;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--input-bg);
  box-shadow: var(--shadow-xs);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur-fast) var(--ease-out);
}

.checkbox:active input:not(:disabled) {
  transform: scale(.88);
}

.checkbox input[type="radio"] {
  border-radius: 50%;
}

.checkbox input::before {
  content: "";
  width: 10px;
  height: 10px;
  background: var(--accent-contrast);
  transform: scale(0);
  transition: transform 120ms var(--ease);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1.5 5.2l2.3 2.3 4.7-5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1.5 5.2l2.3 2.3 4.7-5'/%3E%3C/svg%3E") center / contain no-repeat;
}

.checkbox input[type="radio"]::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  -webkit-mask: none;
  mask: none;
}

.checkbox input:indeterminate::before {
  width: 8px;
  height: 2px;
  border-radius: 1px;
  transform: scale(1);
  -webkit-mask: none;
  mask: none;
}

.checkbox input:checked,
.checkbox input:indeterminate {
  border-color: var(--accent-fill);
  background: var(--accent-fill);
}

.checkbox input:checked::before {
  transform: scale(1);
}

.checkbox input:hover:not(:checked):not(:disabled) {
  border-color: color-mix(in srgb, var(--text-3) 60%, var(--border-strong));
}

.checkbox input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.checkbox:has(input:disabled) {
  opacity: .6;
  cursor: not-allowed;
}

.checkbox input:disabled {
  background: var(--surface-2);
  cursor: not-allowed;
}

.checkbox small,
.checkbox .field__hint {
  display: block;
}

/* Switch: <label class="switch"><input type="checkbox"><span></span> Label</label> */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  user-select: none;
}

.switch > input {
  position: absolute;
  top: 50%;
  left: 0;
  width: 36px;
  height: 20px;
  margin: -10px 0 0;
  opacity: 0;
  cursor: pointer;
}

.switch > input + span {
  position: relative;
  flex-shrink: 0;
  width: 36px;
  height: 20px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  transition: background-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.switch > input + span::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / .25), 0 0 0 .5px rgb(0 0 0 / .06);
  transition: transform var(--dur-slow) var(--ease-out), width var(--dur-fast) var(--ease-out);
}

.switch > input:checked + span {
  background: var(--accent-fill);
  box-shadow: inset 0 0 0 1px transparent;
}

.switch > input:checked + span::after {
  transform: translateX(16px);
}

/* Pressing stretches the knob towards the side it will travel to */
.switch:active > input:not(:disabled) + span::after {
  width: 20px;
}

.switch:active > input:checked:not(:disabled) + span::after {
  transform: translateX(12px);
}

.switch > input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.switch:has(> input:disabled) {
  opacity: .6;
  cursor: not-allowed;
}

.switch > input:disabled {
  cursor: not-allowed;
}

/* Input group: input + button (or addon) joined into one control. Every part has the
   control height, the outer corners share the control radius and neighbouring borders
   overlap so there is never a double line. Hidden inputs inside are ignored. */
.input-group {
  position: relative;
  display: flex;
  align-items: stretch;
  width: 100%;
  min-width: 0;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs);
}

.input-group > * {
  border-radius: 0;
  box-shadow: none;
}

.input-group > :first-child,
.input-group > [type="hidden"] + :not([type="hidden"]) {
  border-top-left-radius: var(--radius-sm);
  border-bottom-left-radius: var(--radius-sm);
}

.input-group > :last-child {
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
}

.input-group > * + :not([type="hidden"]) {
  margin-left: -1px;
}

.input-group > [type="hidden"] + * {
  margin-left: 0;
}

.input-group > .input,
.input-group > .select,
.input-group > input,
.input-group > select {
  position: relative;
  flex: 1 1 auto;
  width: 1%;
  min-width: 0;
  height: 36px;
}

.input-group > .input:focus,
.input-group > .select:focus {
  z-index: 2;
  box-shadow: 0 0 0 3px var(--ring);
}

.input-group > .input[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.input-group > .btn {
  flex-shrink: 0;
  height: auto;
  min-height: 0;
}

/* Neutral buttons read as part of the field: addon background, same border as the input */
.input-group > .btn:not(.btn--primary, .btn--danger, .btn--warning, .btn--success) {
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
}

.input-group > .btn:not(.btn--primary, .btn--danger, .btn--warning, .btn--success):hover {
  background: var(--surface-3);
}

.input-group > .btn:hover {
  z-index: 1;
}

.input-group > .btn:focus-visible {
  z-index: 3;
}

.input-group > .btn:active {
  transform: none;
  filter: brightness(.94);
}

.input-group > :not(.input):not(.select):not(.btn):not(input):not(select):not(.dropdown) {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
  white-space: nowrap;
}

/* Search field: the search icon sits inside the input and is its submit button; an optional
   keyboard hint on the right fades out while typing. The whole field takes the focus ring.
   <form class="search-field" role="search">
     <input class="input" type="search" placeholder="…">
     <button class="search-field__submit" type="submit" aria-label="Search">icon('search')</button>
     <kbd class="kbd search-field__kbd" aria-hidden="true">Ctrl K</kbd>
   </form> */
.search-field {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  margin: 0;
}

.search-field > .input {
  flex: 1 1 auto;
  width: 100%;
  height: 36px;
  padding-left: 36px;
}

.search-field:has(> .search-field__kbd) > .input:placeholder-shown {
  padding-right: 64px;
}

.search-field:focus-within > .input {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.search-field__submit {
  position: absolute;
  top: 50%;
  left: 5px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin: -14px 0 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease), transform var(--dur-fast) var(--ease-out);
}

.search-field__submit .icon {
  width: 16px;
  height: 16px;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur) var(--ease-out);
}

.search-field:focus-within .search-field__submit {
  color: var(--text-2);
}

.search-field__submit:hover {
  background: var(--surface-2);
  color: var(--text);
}

.search-field__submit:active {
  transform: scale(.9);
}

.search-field__submit:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* While suggestions load, the icon turns into a small spinner */
.search-field__submit::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 14px;
  height: 14px;
  margin: auto;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease);
}

.search-field.is-busy .search-field__submit .icon {
  opacity: 0;
  transform: scale(.6);
}

.search-field.is-busy .search-field__submit::after {
  opacity: 1;
  animation: spin .7s linear infinite;
}

.search-field__kbd {
  position: absolute;
  top: 50%;
  right: 9px;
  margin-top: -10px;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur) var(--ease-out);
}

.search-field > .input:focus ~ .search-field__kbd,
.search-field > .input:not(:placeholder-shown) ~ .search-field__kbd {
  opacity: 0;
  transform: scale(.9);
}

@media (max-width: 760px), (hover: none) {
  .search-field__kbd {
    display: none;
  }

  .search-field:has(> .search-field__kbd) > .input:placeholder-shown {
    padding-right: 12px;
  }
}

/* Segmented radio group */
.segmented {
  position: relative;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--track);
}

.segmented > label {
  position: relative;
  z-index: 1;
  display: flex;
  margin: 0;
  cursor: pointer;
}

/* Sliding thumb added by app.js: it glides to the checked option, which then drops its own fill */
.segmented__thumb {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0;
  width: 0;
  height: 0;
  border-radius: 7px;
  background: var(--thumb);
  box-shadow: 0 1px 2px rgb(0 0 0 / .1), 0 0 0 1px var(--border);
  opacity: 0;
  pointer-events: none;
  transition:
    transform var(--dur-slow) var(--ease-out),
    width var(--dur-slow) var(--ease-out),
    height var(--dur-slow) var(--ease-out),
    opacity var(--dur-fast) var(--ease);
}

.segmented__thumb.is-visible {
  opacity: 1;
}

.segmented__thumb.is-instant {
  transition: none;
}

.segmented.has-thumb input:checked + span {
  background: transparent;
  box-shadow: none;
}

.segmented > label:active input:not(:disabled) + span {
  transform: scale(.96);
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.segmented input + span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  border-radius: 7px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur-fast) var(--ease-out);
}

.segmented input + span .icon {
  width: 14px;
  height: 14px;
}

/* Compact, icon-only variant (e.g. the footer theme switch) */
.segmented--sm {
  padding: 2px;
  border-radius: 9px;
}

.segmented--sm input + span {
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
}

.segmented--sm .segmented__thumb {
  border-radius: 6px;
}

.segmented > label:hover input:not(:checked):not(:disabled) + span {
  color: var(--text);
  background: color-mix(in srgb, var(--thumb) 45%, transparent);
}

.segmented input:checked + span {
  background: var(--thumb);
  color: var(--text);
  box-shadow: 0 1px 2px rgb(0 0 0 / .1), 0 0 0 1px var(--border);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.segmented input:disabled + span {
  opacity: .45;
  cursor: not-allowed;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

.form-actions > :first-child:not(.btn):not(button) {
  margin-right: auto;
  color: var(--text-3);
  font-size: 13px;
}

.form-actions--start {
  justify-content: flex-start;
}

/* Filter bar */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin: 0;
}

.filters > .input,
.filters > input,
.filters > .input-group,
.filters > .field {
  flex: 1 1 220px;
  width: auto;
}

.filters > .select,
.filters > select {
  flex: 0 1 auto;
  width: auto;
  min-width: 140px;
}

.filters > .segmented {
  flex: 0 1 auto;
}

.filters .input[type="search"],
.palette__input:first-child {
  padding-left: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23868a97' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20.5 20.5L16 16'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 16px;
}

@media (max-width: 640px) {
  .filters > .select,
  .filters > select,
  .filters > .btn {
    flex: 1 1 auto;
  }

  .form-actions {
    justify-content: stretch;
  }

  .form-actions > .btn {
    flex: 1 1 auto;
  }
}

/* ==========================================================================
   11. Tabs, pagination
   ========================================================================== */

.tabs {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  box-shadow: inset 0 -1px 0 var(--border);
}

/* Active-tab underline added by app.js: one bar that slides to the clicked tab
   (1px wide, sized with scaleX so it only ever animates transform) */
.tabs__indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 1;
  width: 1px;
  height: 2px;
  background: var(--accent);
  transform-origin: 0 0;
  opacity: 0;
  pointer-events: none;
  transition: transform var(--dur-slow) var(--ease-out), opacity var(--dur-fast) var(--ease);
}

.tabs__indicator.is-visible {
  opacity: 1;
}

.tabs__indicator.is-instant {
  transition: none;
}

.tabs.has-indicator .tabs__item.is-active,
.tabs.has-indicator .tabs__item[aria-current="page"],
.tabs.has-indicator .tabs__item[aria-selected="true"] {
  box-shadow: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tabs__item {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  padding: 10px 12px 11px;
  border: 0;
  background: none;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.tabs__item .icon {
  width: 15px;
  height: 15px;
  color: var(--text-3);
}

.tabs__item:hover {
  color: var(--text);
  text-decoration: none;
  box-shadow: inset 0 -2px 0 var(--border-strong);
}

.tabs__item.is-active,
.tabs__item[aria-current="page"],
.tabs__item[aria-selected="true"] {
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.tabs__item.is-active .icon,
.tabs__item[aria-current="page"] .icon,
.tabs__item[aria-selected="true"] .icon {
  color: var(--accent-text);
}

.tabs__item:focus-visible {
  outline-offset: -2px;
  border-radius: 6px;
}

.tabs__item .icon {
  transition: color var(--dur) var(--ease), transform var(--dur-fast) var(--ease-out);
}

.tabs__item:active .icon {
  transform: scale(.88);
}

/* The tab that was just clicked takes the active look while its page loads */
.tabs__item.is-pending {
  color: var(--text);
}

.tabs__item.is-pending .icon {
  color: var(--accent-text);
}

/* Pagination (markup from the pagination() helper) */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  min-width: 0;
  color: var(--text-3);
  font-size: 13px;
}

.pagination ul,
.pagination ol,
.pagination__pages {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pagination a:not(.btn),
.pagination span:not(.icon):not(.pagination__info):not(.sr-only),
.pagination__item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur-fast) var(--ease-out);
}

.pagination a:not(.btn):hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.pagination a:not(.btn):active {
  transform: scale(.94);
}

.pagination .is-active,
.pagination [aria-current="page"] {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.pagination .is-disabled,
.pagination [aria-disabled="true"] {
  opacity: .45;
  pointer-events: none;
}

.card__footer .pagination {
  width: 100%;
}

/* ==========================================================================
   12. Feedback
   ========================================================================== */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
  padding: 11px 14px;
  border: 1px solid color-mix(in srgb, var(--info) 26%, transparent);
  border-radius: 10px;
  background: var(--info-soft);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.alert > .icon {
  width: 18px;
  height: 18px;
  margin-top: 1px;
  color: var(--info);
}

.alert > div,
.alert > p {
  flex: 1 1 auto;
  min-width: 0;
}

.alert a {
  color: inherit;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
}

.alert [data-dismiss] {
  flex-shrink: 0;
  margin: -4px -6px -4px auto;
}

.alert--success {
  border-color: color-mix(in srgb, var(--success) 26%, transparent);
  background: var(--success-soft);
}

.alert--success > .icon { color: var(--success); }

.alert--error {
  border-color: color-mix(in srgb, var(--danger) 28%, transparent);
  background: var(--danger-soft);
}

.alert--error > .icon { color: var(--danger); }

.alert--warning {
  border-color: color-mix(in srgb, var(--warning) 30%, transparent);
  background: var(--warning-soft);
}

.alert--warning > .icon { color: var(--warning); }

.alert--info {
  border-color: color-mix(in srgb, var(--info) 26%, transparent);
  background: var(--info-soft);
}

.alert--info > .icon { color: var(--info); }

.alert.is-leaving {
  animation: fade-up-out .22s var(--ease) forwards;
}

/* Toasts */
.toast-region {
  position: fixed;
  inset: auto 20px 20px auto;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast-region[popover] {
  inset: auto 20px 20px auto;
  height: auto;
  margin: 0;
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
  color: inherit;
}

.toast-region[popover]:not(:popover-open) {
  display: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 12px 10px 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--toast-bg);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  line-height: 1.45;
  pointer-events: auto;
  animation: toast-in var(--dur-slow) var(--ease-out);
}

.toast > .icon {
  width: 18px;
  height: 18px;
  margin-top: 1px;
  color: var(--info);
}

.toast__message {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.toast__close {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin: -2px 0 -2px 4px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-3);
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur-fast) var(--ease-out);
}

.toast__close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.toast__close:active {
  transform: scale(.9);
}

.toast__close .icon {
  width: 14px;
  height: 14px;
}

.toast--success > .icon { color: var(--success); }
.toast--error > .icon { color: var(--danger); }
.toast--warning > .icon { color: var(--warning); }

.toast.is-leaving {
  pointer-events: none;
  animation: toast-out .18s var(--ease) forwards;
}

@media (max-width: 640px) {
  .toast-region,
  .toast-region[popover] {
    inset: auto 16px 16px 16px;
    width: auto;
    align-items: stretch;
  }
}

/* Empty state */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 48px 24px;
  color: var(--text-2);
  text-align: center;
}

.empty__icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: var(--shadow);
  color: var(--text-3);
}

.empty__icon .icon {
  width: 20px;
  height: 20px;
}

svg.empty__icon {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
}

.empty__title {
  margin: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.empty__text {
  max-width: 420px;
  color: var(--text-3);
  font-size: 14px;
  text-wrap: pretty;
}

.empty .btn {
  margin-top: 12px;
}

.card .empty {
  padding-top: 40px;
  padding-bottom: 40px;
}

/* Spinner & skeleton */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border: 2px solid color-mix(in srgb, currentColor 22%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  vertical-align: middle;
  animation: spin .7s linear infinite;
}

.skeleton {
  display: block;
  width: var(--w, auto);
  min-height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 40%, var(--surface-2) 60%);
  background-size: 300% 100%;
  color: transparent !important;
  animation: shimmer 1.6s ease-in-out infinite;
}

.skeleton * {
  visibility: hidden;
}

.skeleton--block {
  min-height: 72px;
  border-radius: var(--radius-sm);
}

/* Live regions ([data-refresh]) */
[data-refresh] {
  transition: opacity .2s var(--ease);
}

[data-refresh].is-stale {
  opacity: .55;
}

/* A live region that starts empty shows shimmer lines until its first fragment arrives */
[data-refresh].is-loading {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: min(100%, 200px);
  min-height: 20px;
}

[data-refresh].is-loading::before,
[data-refresh].is-loading::after {
  content: "";
  display: block;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 40%, var(--surface-2) 60%);
  background-size: 300% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
}

[data-refresh].is-loading::before {
  width: min(100%, 240px);
}

[data-refresh].is-loading::after {
  width: min(70%, 160px);
}

/* Cross-fade of a fragment whose structure changed: the old content fades out on top */
.refresh-ghost {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

[data-refresh].is-swapping {
  position: relative;
}

/* A value that changed in a live update briefly takes the accent colour */
.is-updated {
  animation: value-flash 1.4s var(--ease) both;
}

[data-refreshed] .meter__bar,
[data-refreshed] .leaderboard__bar::before {
  animation: none !important;
}

/* ==========================================================================
   13. Overlays
   ========================================================================== */

/* Modal (<dialog class="modal">) */
.modal {
  width: min(520px, calc(100vw - 32px));
  max-width: none;
  max-height: min(calc(100vh - 48px), 880px);
  max-height: min(calc(100dvh - 48px), 880px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface-elev);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.modal[open] {
  display: flex;
  flex-direction: column;
  animation: modal-in var(--dur-slow) var(--ease-out);
}

.modal::backdrop {
  background: var(--overlay);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade-in var(--dur-slow) var(--ease-out);
}

.modal.is-closing {
  pointer-events: none;
  animation: modal-out .16s var(--ease) forwards;
}

.modal.is-closing::backdrop {
  animation: fade-out .16s var(--ease) forwards;
}

.modal--sm { width: min(400px, calc(100vw - 32px)); }
.modal--lg { width: min(760px, calc(100vw - 32px)); }

.modal > form {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  margin: 0;
}

.modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  padding: 18px 20px 0;
}

.modal__header > :first-child {
  min-width: 0;
}

.modal__title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.modal__title .icon {
  width: 18px;
  height: 18px;
  color: var(--text-3);
}

.modal--danger .modal__title .icon {
  color: var(--danger);
}

.modal__header [data-modal-close] {
  flex-shrink: 0;
  margin: -6px -8px 0 auto;
}

.modal__header p,
.modal__header .modal__subtitle {
  margin-top: 2px;
  color: var(--text-3);
  font-size: 13px;
}

.modal__body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 14px 20px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--text-2);
}

.modal__body > p:first-child:last-child {
  line-height: 1.6;
}

.modal__body .form,
.modal__body .field__label,
.modal__body .checkbox,
.modal__body .switch {
  color: var(--text);
}

.modal__footer {
  display: flex;
  flex-wrap: wrap;
  flex-shrink: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 70%, var(--surface-elev));
}

.modal__footer > :first-child:not(.btn):not(button) {
  margin-right: auto;
  color: var(--text-3);
  font-size: 13px;
}

@media (max-width: 640px) {
  .modal,
  .modal--sm,
  .modal--lg {
    width: 100%;
    max-width: 100%;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    margin: auto 0 0;
    border-bottom: 0;
    border-radius: 16px 16px 0 0;
  }

  .modal[open] {
    animation-name: sheet-in;
  }

  .modal.is-closing {
    animation-name: sheet-out;
  }

  .modal__footer {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .modal__footer > .btn {
    flex: 1 1 auto;
  }
}

/* Dropdown ([data-dropdown]) */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown__menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  display: none;
  flex-direction: column;
  min-width: 200px;
  max-width: min(320px, calc(100vw - 24px));
  max-height: min(420px, calc(100vh - 32px));
  padding: 4px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface-elev);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  text-align: left;
  transform-origin: top right;
}

.dropdown.is-open > .dropdown__menu,
.dropdown.is-open > * > .dropdown__menu {
  display: flex;
  animation: pop-in .16s var(--ease-out);
}

/* Closing: app.js keeps the menu shown for a short fade, then hides it */
.dropdown__menu.is-closing {
  display: flex;
  pointer-events: none;
  animation: pop-out .12s var(--ease) forwards;
}

/* A trailing chevron in a dropdown trigger turns while the menu is open */
.dropdown [data-dropdown-toggle] > .icon:last-child,
.dropdown > .btn > .icon:last-child {
  transition: transform var(--dur-slow) var(--ease-out);
}

.dropdown.is-open [data-dropdown-toggle] > .icon:last-child:has(use[href*="#i-chevron-down"]),
.dropdown.is-open > .btn > .icon:last-child:has(use[href*="#i-chevron-down"]) {
  transform: rotate(180deg);
}

.dropdown__menu.is-up {
  top: auto;
  bottom: calc(100% + 6px);
  transform-origin: bottom right;
}

.dropdown__menu.is-start {
  right: auto;
  left: 0;
  transform-origin: top left;
}

.dropdown__menu.is-fixed {
  position: fixed;
  right: auto;
  bottom: auto;
}

.dropdown__menu > form {
  display: flex;
  flex-direction: column;
  margin: 0;
}

.dropdown__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 32px;
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.35;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.dropdown__item:active {
  background: var(--surface-3);
}

.dropdown__item .icon {
  width: 16px;
  height: 16px;
  color: var(--text-3);
}

.dropdown__item:hover,
.dropdown__item:focus-visible {
  outline: none;
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.dropdown__item:hover .icon,
.dropdown__item:focus-visible .icon {
  color: var(--text-2);
}

.dropdown__item.is-danger,
.dropdown__item.is-danger .icon {
  color: var(--danger);
}

.dropdown__item.is-danger:hover,
.dropdown__item.is-danger:focus-visible {
  background: var(--danger-soft);
  color: var(--danger);
}

.dropdown__item.is-active::after {
  content: "";
  width: 14px;
  height: 14px;
  margin-left: auto;
  background: var(--accent-text);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 12.5l5 5 10-11'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 12.5l5 5 10-11'/%3E%3C/svg%3E") center / contain no-repeat;
}

.dropdown__item:disabled,
.dropdown__item[aria-disabled="true"] {
  opacity: .45;
  pointer-events: none;
}

.dropdown__item .kbd,
.dropdown__item .badge,
.dropdown__item .rank {
  margin-left: auto;
}

.dropdown__divider {
  flex-shrink: 0;
  height: 1px;
  margin: 4px -4px;
  border: 0;
  background: var(--border);
}

.dropdown__menu > .subtle,
.dropdown__menu > .small,
.dropdown__menu > .muted {
  padding: 6px 10px 4px;
  font-size: 12px;
}

/* Autocomplete list (created by app.js for [data-player-autocomplete]) */
.autocomplete {
  position: fixed;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  min-width: 220px;
  max-height: 320px;
  padding: 4px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface-elev);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  transform-origin: top center;
  animation: pop-in .16s var(--ease-out);
}

.autocomplete__item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.autocomplete__item:active {
  background: var(--surface-3);
}

.autocomplete__item.is-active {
  background: var(--surface-2);
}

.autocomplete__label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.autocomplete__sub {
  flex-shrink: 0;
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-3);
  font-size: 12px;
}

.autocomplete__empty {
  padding: 10px;
  color: var(--text-3);
  font-size: 13px;
}

/* Command palette (<dialog class="palette">) */
.palette {
  width: min(640px, calc(100vw - 24px));
  max-width: none;
  max-height: min(540px, calc(100vh - 96px));
  max-height: min(540px, calc(100dvh - 96px));
  margin: 12vh auto auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface-elev);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.palette[open] {
  display: flex;
  flex-direction: column;
  animation: palette-in var(--dur-slow) var(--ease-out);
}

.palette.is-closing {
  pointer-events: none;
  animation: palette-out .14s var(--ease) forwards;
}

.palette::backdrop {
  background: var(--overlay);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: fade-in var(--dur-slow) var(--ease-out);
}

.palette.is-closing::backdrop {
  animation: fade-out .12s var(--ease) forwards;
}

.palette > form {
  display: contents;
}

.palette__input {
  display: block;
  flex-shrink: 0;
  width: 100%;
  height: 54px;
  margin: 0;
  padding: 0 18px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background-color: transparent;
  color: var(--text);
  font-size: 16px;
  outline: none;
  box-shadow: none;
}

.palette__input:first-child {
  padding-left: 46px;
  background-position: 18px center;
  background-size: 18px;
}

.palette__input::placeholder {
  color: var(--text-3);
}

.palette__input::-webkit-search-cancel-button {
  display: none;
}

.palette > :has(> .palette__input) {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-3);
}

.palette > :has(> .palette__input) .palette__input {
  flex: 1 1 auto;
  padding: 0;
  border-bottom: 0;
  background-image: none;
}

.palette__results {
  flex: 1 1 auto;
  min-height: 0;
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.palette__group {
  padding: 10px 10px 4px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.palette__item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  scroll-margin: 6px;
  transition: background-color 80ms var(--ease);
}

.palette__item:hover {
  text-decoration: none;
}

.palette__item .icon {
  width: 16px;
  height: 16px;
  color: var(--text-3);
}

.palette__item.is-selected {
  background: var(--surface-2);
  box-shadow: inset 2px 0 0 var(--accent);
}

.palette__item:active {
  background: var(--surface-3);
}

.palette__item.is-selected .icon {
  color: var(--text);
}

.palette__label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette__label mark {
  background: none;
  color: var(--accent-text);
  font-weight: 600;
}

.palette__sub {
  flex-shrink: 1;
  min-width: 0;
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-3);
  font-size: 12.5px;
}

.palette__hint {
  flex-shrink: 0;
  color: var(--text-3);
  font-size: 12px;
}

.palette__empty {
  padding: 28px 16px;
  color: var(--text-3);
  font-size: 14px;
  text-align: center;
}

.palette__status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  color: var(--text-3);
  font-size: 13px;
}

.palette__footer {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  padding: 9px 16px;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 60%, var(--surface-elev));
  color: var(--text-3);
  font-size: 12px;
}

.palette__footer span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

@media (max-width: 640px) {
  .palette {
    margin-top: 12px;
    max-height: calc(100dvh - 24px);
  }

  .palette__footer {
    display: none;
  }
}

/* ==========================================================================
   14. Charts, heatmap, legend
   ========================================================================== */

.chart {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  min-width: 0;
  color: var(--text-3);
  font-family: var(--font);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chart__plot {
  position: relative;
  width: 100%;
  min-width: 0;
}

.chart svg,
.heatmap svg {
  display: block;
  max-width: 100%;
  overflow: visible;
  -webkit-user-select: none;
  user-select: none;
}

.chart svg:focus-visible,
.heatmap svg:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 4px;
}

.chart__grid {
  stroke: var(--grid);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.chart__axis {
  stroke: var(--axis);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.chart__tick {
  fill: var(--text-3);
  font-size: 11px;
}

.chart__label {
  fill: var(--text-2);
  font-size: 12px;
}

a .chart__label:hover,
.chart__link:hover .chart__label {
  fill: var(--accent-text);
  text-decoration: underline;
}

.chart__value {
  fill: var(--text);
  font-size: 12px;
  font-weight: 600;
}

.chart__value--muted {
  fill: var(--text-2);
  font-weight: 500;
}

.chart__line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart__spark {
  fill: none;
  stroke: var(--text-3);
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart__area {
  stroke: none;
  opacity: var(--area-opacity);
}

.chart__dot {
  stroke: var(--surface);
  stroke-width: 2;
}

.chart__crosshair {
  stroke: var(--border-strong);
  stroke-width: 1;
  shape-rendering: crispEdges;
  pointer-events: none;
}

.chart__overlay {
  fill: transparent;
  cursor: crosshair;
  touch-action: pan-y;
}

.chart__bar {
  transition: opacity var(--dur) var(--ease), filter var(--dur) var(--ease);
}

.chart__bar.is-hover {
  filter: brightness(1.12) saturate(1.05);
}

.chart__hit {
  fill: transparent;
  cursor: default;
}

.chart__hit--link {
  cursor: pointer;
}

.chart__tooltip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
  max-width: 260px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-elev);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 120ms var(--ease), transform 120ms var(--ease);
}

.chart__tooltip.is-visible {
  opacity: 1;
  transform: none;
}

.chart__tooltip-title {
  color: var(--text-3);
  font-size: 11px;
  white-space: nowrap;
}

.chart__tooltip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.chart__tooltip-key {
  width: 12px;
  height: 2px;
  flex-shrink: 0;
  border-radius: 1px;
  background: var(--key, var(--series-1));
}

.chart__tooltip-value {
  color: var(--text);
  font-weight: 600;
}

.chart__tooltip-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-2);
}

.chart__empty {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 64px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-3);
  font-size: 13px;
}

/* Before charts.js has drawn a chart, its box holds the chart's height as a shimmer
   (the .js class comes from theme.js, so this never shows without JavaScript) */
.js .chart[data-chart]:not(.is-rendered) {
  min-height: 160px;
  min-height: attr(data-chart-height px, 160px);
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 40%, var(--surface-2) 60%);
  background-size: 300% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
}

.js .chart[data-chart="bar"]:not(.is-rendered) {
  min-height: 140px;
}

/* First draw: lines trace in, areas and bars grow, heatmap cells fade in column by column.
   --intro-shift (negative) lets a re-render during the intro continue where it was. */
.chart.is-intro .chart__line,
.chart.is-intro .chart__spark {
  stroke-dasharray: 1 1;
  animation: chart-draw 700ms var(--ease-out) both;
  animation-delay: var(--intro-shift, 0ms);
}

.chart.is-intro .chart__area {
  animation: chart-fade 600ms var(--ease-out) both;
  animation-delay: calc(var(--intro-shift, 0ms) + 150ms);
}

.chart.is-intro .chart__dot,
.chart.is-intro .chart__value {
  animation: chart-fade 300ms var(--ease-out) both;
  animation-delay: calc(var(--intro-shift, 0ms) + 450ms + var(--i, 0) * 35ms);
}

.chart.is-intro .chart__bar {
  transform-box: fill-box;
  transform-origin: 0 50%;
  animation: chart-grow-x 550ms var(--ease-out) both;
  animation-delay: calc(var(--intro-shift, 0ms) + var(--i, 0) * 35ms);
}

.chart.is-intro[data-chart="column"] .chart__bar {
  transform-origin: 50% 100%;
  animation-name: chart-grow-y;
}

.chart.is-intro[data-chart="bar"] .chart__value,
.chart.is-intro[data-chart="column"] .chart__value {
  animation-delay: calc(var(--intro-shift, 0ms) + 250ms + var(--i, 0) * 35ms);
}

.chart.is-intro .heatmap__cell:not(.heatmap__legend-cell) {
  animation: chart-fade 260ms var(--ease-out) both;
  animation-delay: calc(var(--intro-shift, 0ms) + var(--i, 0) * var(--intro-step, 14ms));
}

/* Heatmap */
.heatmap {
  position: relative;
  width: 100%;
  min-width: 0;
}

.heatmap__cell {
  fill: var(--heat-0);
  transition: stroke var(--dur) var(--ease);
}

.heatmap__cell[data-level="1"] { fill: var(--heat-1); }
.heatmap__cell[data-level="2"] { fill: var(--heat-2); }
.heatmap__cell[data-level="3"] { fill: var(--heat-3); }
.heatmap__cell[data-level="4"] { fill: var(--heat-4); }

.heatmap__cell.is-hover {
  stroke: var(--text);
  stroke-width: 1.5;
}

.heatmap__legend-cell {
  stroke: none;
}

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  min-width: 0;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.4;
}

.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.legend__key {
  width: 12px;
  height: 2px;
  flex-shrink: 0;
  border-radius: 1px;
  background: var(--key, var(--series-1));
}

.legend__key--rect {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* ==========================================================================
   15. Misc & utilities
   ========================================================================== */

.kv {
  display: grid;
  grid-template-columns: minmax(110px, max-content) minmax(0, 1fr);
  gap: 10px 24px;
  margin: 0;
  font-size: 14px;
}

.kv dt {
  color: var(--text-3);
}

.kv dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

@media (max-width: 480px) {
  .kv {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }

  .kv dd + dt {
    margin-top: 10px;
  }
}

.code {
  padding: .12em .4em;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--mono);
  font-size: .86em;
  overflow-wrap: anywhere;
}

.pre {
  display: block;
  max-height: 480px;
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre;
  tab-size: 2;
}

.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: .92em; }
.nowrap { white-space: nowrap; }

.truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

span.truncate,
a.truncate {
  display: inline-block;
  max-width: 100%;
  vertical-align: bottom;
}

.text-right { text-align: right; }
.text-center { text-align: center; }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.hidden {
  display: none !important;
}

.divider {
  flex-shrink: 0;
  width: 100%;
  height: 1px;
  margin: 4px 0;
  border: 0;
  background: var(--border);
}

/* ==========================================================================
   16. Styleguide-only helpers
   ========================================================================== */

.sg-swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr));
  gap: 12px;
}

.sg-swatch {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 12px;
}

.sg-swatch::before {
  content: "";
  height: 44px;
  background: var(--swatch);
  border-bottom: 1px solid var(--border);
}

.sg-swatch span {
  padding: 6px 10px 8px;
  font-family: var(--mono);
  color: var(--text-2);
}

.sg-type > * + * {
  margin-top: 10px;
}

.sg-icons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 136px), 1fr));
  gap: 8px;
}

.sg-icons > div {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 11.5px;
}

.sg-icons .icon {
  width: 20px;
  height: 20px;
  color: var(--text);
}

.sg-anchor {
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}

/* ==========================================================================
   17. Motion, forced colours, print
   ========================================================================== */

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes fade-up-out {
  to { opacity: 0; transform: translateY(-4px); }
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(.97) translateY(-2px); }
  to { opacity: 1; transform: none; }
}

@keyframes pop-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: scale(.97) translateY(-2px); }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to { opacity: 1; transform: none; }
}

@keyframes modal-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(6px) scale(.97); }
}

@keyframes palette-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(-6px) scale(.985); }
}

@keyframes page-in {
  from { opacity: 0; transform: translateY(6px); }
}

@keyframes btn-spinner-in {
  from { opacity: 0; }
}

@keyframes icon-swap {
  0% { opacity: 0; transform: scale(.5) rotate(-12deg); }
  60% { opacity: 1; transform: scale(1.12); }
  100% { opacity: 1; transform: none; }
}

@keyframes value-flash {
  from { color: var(--accent-text); }
}

@keyframes grow-x {
  from { transform: scaleX(0); }
}

@keyframes chart-draw {
  from { stroke-dashoffset: 1; }
  to { stroke-dashoffset: 0; }
}

@keyframes chart-fade {
  from { opacity: 0; }
}

@keyframes chart-grow-x {
  from { transform: scaleX(0); }
}

@keyframes chart-grow-y {
  from { transform: scaleY(0); }
}

@keyframes progress-trickle {
  0% { transform: scaleX(0); }
  8% { transform: scaleX(.3); }
  30% { transform: scaleX(.6); }
  60% { transform: scaleX(.8); }
  100% { transform: scaleX(.94); }
}

@keyframes reveal {
  from { opacity: 0; transform: translateY(-4px); }
}

@keyframes enter-up {
  from { opacity: 0; transform: translateY(8px); }
}

/* Items added live (e.g. new chat messages) slide in */
.is-entering {
  animation: enter-up var(--dur-slow) var(--ease-out) backwards;
}

/* Page content settles in on load (the frame — header, sidebar — stays put). The animation
   only fills backwards, so nothing is left transformed once it has played. Dialogs placed
   directly in the content keep their own open/close animations. */
/* (:where() gives these zero specificity, so any component animation — a modal opening,
   an alert leaving, a value flashing — always wins over them.) */
:where(.js .content, .js .site-main) > :where(:not(dialog)),
:where(.js .auth__card) {
  animation: page-in 280ms var(--ease-out) backwards;
}

:where(.js .content, .js .site-main) > :where(:not(dialog):nth-child(2)) { animation-delay: 30ms; }
:where(.js .content, .js .site-main) > :where(:not(dialog):nth-child(3)) { animation-delay: 60ms; }
:where(.js .content, .js .site-main) > :where(:not(dialog):nth-child(n+4)) { animation-delay: 90ms; }

/* Meters and leaderboard bars grow in on page load (not on live updates) */
.js .meter__bar,
.js .leaderboard__bar::before {
  animation: grow-x 700ms var(--ease-out) 120ms backwards;
}

details[open] > :not(summary) {
  animation: reveal var(--dur-slow) var(--ease-out);
}

/* Navigation progress bar (app.js): appears only when a page takes longer than ~150 ms */
.nav-progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 2000;
  width: auto;
  height: 2px;
  margin: 0;
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s var(--ease);
}

.nav-progress[popover]:not(:popover-open) {
  display: none;
}

.nav-progress__bar {
  height: 100%;
  background: var(--accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 70%, transparent);
  transform: scaleX(0);
  transform-origin: 0 50%;
}

.nav-progress.is-active {
  opacity: 1;
}

.nav-progress.is-active .nav-progress__bar {
  animation: progress-trickle 12s cubic-bezier(.08, .7, .2, 1) forwards;
}

.nav-progress.is-done {
  opacity: 0;
  transition: opacity .25s var(--ease) .12s;
}

.nav-progress.is-done .nav-progress__bar {
  transform: scaleX(1);
  animation: none;
  transition: transform .15s var(--ease);
}


@keyframes sheet-in {
  from { transform: translateY(100%); }
  to { transform: none; }
}

@keyframes sheet-out {
  from { transform: none; }
  to { transform: translateY(100%); }
}

@keyframes palette-in {
  from { opacity: 0; transform: translateY(-8px) scale(.985); }
  to { opacity: 1; transform: none; }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateX(16px); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }

  .dot--online,
  .skeleton,
  .js .chart[data-chart]:not(.is-rendered),
  [data-refresh].is-loading::before,
  [data-refresh].is-loading::after {
    animation: none !important;
  }

  .btn:active,
  .chip:active,
  .nav__item:active,
  .site-nav__item:active,
  .pagination a:active,
  .checkbox:active input,
  .segmented > label:active input + span,
  .search-field__submit:active,
  .toast__close:active,
  a.card:active {
    transform: none !important;
  }
}

@media (forced-colors: active) {
  .btn,
  .badge,
  .rank,
  .pill,
  .chip,
  .segmented input + span,
  .tabs__item.is-active {
    border: 1px solid CanvasText;
  }

  .dot,
  .rank::before,
  .meter__bar,
  .leaderboard__bar::before,
  .heatmap__cell,
  .chart__bar,
  .chart__line,
  .legend__key,
  .switch > input + span,
  .tabs__indicator,
  .nav-progress__bar {
    forced-color-adjust: none;
  }

  .tabs__indicator,
  .nav-progress__bar {
    background: Highlight;
  }

  .segmented__thumb {
    display: none;
  }

  .segmented.has-thumb input:checked + span {
    border: 1px solid Highlight;
  }

  .nav__item.is-active,
  .palette__item.is-selected,
  .dropdown__item:hover {
    outline: 2px solid Highlight;
  }
}

@media print {
  :root,
  :root[data-theme] {
    color-scheme: light;
    --bg: #fff;
    --bg-elev: #fff;
    --surface: #fff;
    --surface-2: #f5f5f5;
    --surface-3: #ececec;
    --surface-elev: #fff;
    --border: #d4d4d4;
    --border-strong: #bdbdbd;
    --text: #000;
    --text-2: #333;
    --text-3: #555;
    --shadow: none;
    --shadow-lg: none;
    --grid: #e5e5e5;
    --axis: #bbb;
  }

  .sidebar,
  .topbar,
  .site-header,
  .site-footer,
  .toast-region,
  .nav-progress,
  .filters,
  .pagination,
  .page-header__actions,
  .profile-header__actions,
  .card__actions,
  .table__actions,
  .btn,
  dialog,
  [data-nav-toggle] {
    display: none !important;
  }

  .app {
    display: block;
  }

  .content {
    max-width: none;
    padding: 0;
  }

  .card,
  .stat,
  .server-card {
    box-shadow: none;
    break-inside: avoid;
  }

  .table-wrap {
    overflow: visible;
  }

  .hero::before,
  .hero::after,
  .auth::before {
    display: none;
  }

  .hero__title {
    color: #000;
    background: none;
  }

  a {
    color: inherit;
  }
}

/* Cloudflare Turnstile on the sign-in card: fill the form width like the inputs. */
.cf-turnstile {
  width: 100%;
}

.cf-turnstile iframe {
  width: 100% !important;
}

/* Driving statistics: a compact overview, category navigation and progressive detail. */
.telemetry-nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
.telemetry-nav .tabs__item { flex: 0 0 auto; white-space: nowrap; }
.telemetry-metric-select { min-width: 220px; max-width: 100%; }
.site-preferences { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.unit-preference { display: inline-flex; align-items: center; gap: 8px; }
.unit-preference[hidden] { display: none; }
.unit-preference .select { min-height: 32px; width: auto; max-width: 190px; font-size: 12px; padding-block: 5px; }
.sidebar__footer > .unit-preference { display: flex; margin-top: 12px; justify-content: space-between; }
.sidebar__footer > .unit-preference[hidden] { display: none; }
.sidebar__footer .unit-preference .select { max-width: 165px; }
.telemetry-highlights { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.telemetry-highlight { position: relative; display: grid; gap: 6px; padding: 20px 24px; color: var(--text); transition: background var(--dur); min-width: 0; }
.telemetry-highlight + .telemetry-highlight { border-left: 1px solid var(--border); }
.telemetry-highlight:hover { background: var(--surface-2); text-decoration: none; }
.telemetry-highlight strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.telemetry-highlight > .icon { position: absolute; right: 20px; top: 50%; color: var(--text-3); }
.telemetry-feature { min-width: 0; }
.telemetry-feature .stat__value { font-size: clamp(23px, 2.8vw, 36px); overflow-wrap: anywhere; }
.telemetry-feature .stat__meta { display: block; margin: 0; line-height: 1.6; min-height: 3.2em; }
.telemetry-board-link { display: inline-flex; align-items: center; gap: 4px; margin-top: 8px; }
.telemetry-derived { display: flex; flex-wrap: wrap; gap: 24px 48px; padding: 0 4px; }
.telemetry-derived > div { display: grid; gap: 4px; }
.telemetry-derived strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.telemetry-details { padding: 0 !important; }
.telemetry-details summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 24px; cursor: pointer; font-weight: 600; list-style: none; }
.telemetry-details summary::-webkit-details-marker { display: none; }
.telemetry-details summary > :last-child { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.telemetry-details[open] summary { border-bottom: 1px solid var(--border); }
.telemetry-details[open] summary .icon { transform: rotate(180deg); }
.telemetry-stat-row { display: flex; align-items: center; gap: 16px; padding: 16px 24px; }
.telemetry-stat-row + .telemetry-stat-row { border-top: 1px solid var(--border); }
.telemetry-stat-row > :first-child { flex: 1; min-width: 0; }
.telemetry-stat-row > :first-child > span { font-weight: 500; }
.telemetry-stat-row p { margin: 4px 0 0; max-width: 66ch; line-height: 1.5; }
.telemetry-stat-row > strong { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.telemetry-stat-row > .btn { flex: 0 0 auto; }
.telemetry-usage { display: grid; gap: 6px; }
.telemetry-usage .split { gap: 12px; }
.telemetry-usage__track { height: 4px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; }
.telemetry-usage__track > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
@media (max-width: 640px) {
  .telemetry-highlights { grid-template-columns: 1fr; }
  .telemetry-highlight + .telemetry-highlight { border-left: 0; border-top: 1px solid var(--border); }
  .telemetry-highlight { padding: 16px 20px; }
  .telemetry-stat-row { gap: 10px; padding: 16px; flex-wrap: wrap; }
  .telemetry-stat-row > :first-child { flex-basis: calc(100% - 50px); }
  .telemetry-stat-row > strong { order: 3; width: 100%; text-align: left; }
  .telemetry-details summary { padding: 16px; }
  .telemetry-metric-select { width: 100%; min-width: 0; }
}
