/* ============================================================
   Starscope design tokens
   Structure follows website-ui-designer/assets/design-tokens.css:
   1) primitives  2) semantic  3) component. Components may only
   reference layers 2 and 3.
   Direction: bold-creative (dark), with a light semantic override.
   Contrast values are asserted in tests/contrast.js.
   ============================================================ */
:root {
  /* ---------- Layer 1: primitives ---------------------------------- */
  --gray-0:   #FFFFFF;
  --gray-50:  #FAFAFB;
  --gray-100: #F5F5F7;
  --gray-200: #E4E4E9;
  --gray-300: #D4D4D8;
  --gray-400: #A6A6B2;
  --gray-500: #8A8A96;
  --gray-600: #71717A;
  --gray-700: #3F3F46;
  --gray-800: #2A2A32;
  --gray-900: #16161A;
  --gray-950: #0A0A0B;

  --red-400:    #FF6B4F;
  --red-500:    #FF4D2E;
  --red-600:    #E63A1C;
  --red-700:    #C42E13;
  --violet-400: #9B82FF;
  --violet-500: #7C5CFF;
  --violet-600: #6B48F0;
  --green-500:  #2ED47A;
  --amber-500:  #FFB020;
  --rose-500:   #FF3B5C;
  --cyan-500:   #22D3EE;

  --size-1: 4px;   --size-2: 8px;   --size-3: 12px;  --size-4: 16px;
  --size-5: 20px;  --size-6: 24px;  --size-8: 32px;  --size-10: 40px;
  --size-12: 48px; --size-16: 64px; --size-20: 80px; --size-24: 96px;
  --size-32: 128px;

  /* ---------- Layer 2: semantic ------------------------------------ */
  --bg:          var(--gray-950);
  --bg-subtle:   var(--gray-900);
  --surface:     var(--gray-900);
  --surface-2:   var(--gray-800);
  --surface-3:   #202027;
  --overlay:     rgba(10, 10, 11, 0.72);

  --border:        var(--gray-800);
  --border-strong: var(--gray-700);

  --text:         var(--gray-100);
  --text-muted:   var(--gray-400);
  --text-faint:   var(--gray-500);
  --text-inverse: var(--gray-950);

  --accent:          var(--red-500);
  --accent-hover:    var(--red-400);
  --accent-subtle:   rgba(255, 77, 46, 0.12);
  --accent-2:        var(--violet-500);
  --accent-2-hover:  var(--violet-400);
  --accent-2-subtle: rgba(124, 92, 255, 0.14);
  /* Dark ink on vermilion passes AA; white on vermilion does not. */
  --accent-contrast: var(--gray-950);

  --success: var(--green-500);  --success-subtle: rgba(46, 212, 122, 0.14);
  --warn:    var(--amber-500);  --warn-subtle:    rgba(255, 176, 32, 0.14);
  --danger:  var(--rose-500);   --danger-subtle:  rgba(255, 59, 92, 0.14);
  --info:    var(--cyan-500);   --info-subtle:    rgba(34, 211, 238, 0.12);

  --focus-ring: var(--violet-400);

  /* ---------- Space scale ------------------------------------------ */
  --space-1: var(--size-1);   --space-2: var(--size-2);
  --space-3: var(--size-3);   --space-4: var(--size-4);
  --space-5: var(--size-5);   --space-6: var(--size-6);
  --space-8: var(--size-8);   --space-10: var(--size-10);
  --space-12: var(--size-12); --space-16: var(--size-16);
  --space-20: var(--size-20); --space-24: var(--size-24);
  --space-32: var(--size-32);

  --section-y:        clamp(3.5rem, 8vw, 7.5rem);
  --section-y-tight:  clamp(2.5rem, 5vw, 4.5rem);
  --container-max:    1280px;
  --container-pad:    clamp(1rem, 3vw, 2rem);
  --measure:          68ch;

  /* ---------- Radius ----------------------------------------------- */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   16px;
  --radius-xl:   24px;
  --radius-full: 9999px;

  /* ---------- Elevation -------------------------------------------- */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.32);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.44);
  --glow-accent: 0 0 0 1px rgba(255, 77, 46, 0.35), 0 8px 32px rgba(255, 77, 46, 0.18);

  /* ---------- Typography ------------------------------------------- */
  --font-display: "Inter", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-body:    "Inter", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --text-hero: clamp(2.5rem, 1.5rem + 5vw, 5.5rem);
  --text-h1:   clamp(2rem, 1.35rem + 2.6vw, 3.5rem);
  --text-h2:   clamp(1.5rem, 1.2rem + 1.4vw, 2.25rem);
  --text-h3:   clamp(1.25rem, 1.1rem + 0.7vw, 1.5rem);
  --text-h4:   1.125rem;
  --text-body: 1rem;
  --text-sm:   0.875rem;
  --text-xs:   0.75rem;

  --weight-regular:  400;
  --weight-medium:   500;
  --weight-semibold: 600;
  --weight-bold:     700;
  --weight-black:    900;

  --leading-tight:   1.05;
  --leading-snug:    1.3;
  --leading-normal:  1.6;
  --leading-relaxed: 1.75;

  --tracking-display: -0.03em;
  --tracking-tight:   -0.015em;
  --tracking-normal:  0;
  --tracking-label:   0.12em;

  /* ---------- Motion ----------------------------------------------- */
  --dur-fast:   120ms;
  --dur-base:   200ms;
  --dur-slow:   320ms;
  --dur-slower: 500ms;
  --ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

  /* ---------- Z-index ---------------------------------------------- */
  --z-base: 0; --z-dropdown: 100; --z-sticky: 200;
  --z-modal: 300; --z-toast: 400; --z-tooltip: 500;

  /* ---------- Layer 3: component ----------------------------------- */
  --card-bg:      var(--surface);
  --card-border:  1px solid var(--border);
  --card-padding: var(--space-6);
  --card-radius:  var(--radius-lg);

  --btn-radius:   var(--radius-md);
  --btn-pad-y:    0.7rem;
  --btn-pad-x:    1.2rem;
  --btn-font:     var(--text-sm);
  --btn-weight:   var(--weight-semibold);
  --btn-dur:      var(--dur-fast);

  --input-bg:     var(--surface-2);
  --input-border: 1px solid var(--border);
  --input-radius: var(--radius-md);
  --input-pad:    0.7rem 0.9rem;

  --nav-height:   68px;
  --rail-width:   244px;
  --tabpanel-gap: var(--space-5);
  --row-padding:  var(--space-4) var(--space-5);
  --chip-bg:      var(--surface-2);
  --chip-color:   var(--text-muted);
}

/* Light theme overrides the SEMANTIC layer only. */
[data-theme="light"] {
  --bg:          var(--gray-50);
  --bg-subtle:   var(--gray-100);
  --surface:     var(--gray-0);
  --surface-2:   var(--gray-100);
  --surface-3:   var(--gray-200);
  --overlay:     rgba(17, 24, 39, 0.48);

  --border:        var(--gray-200);
  --border-strong: var(--gray-300);

  --text:         #111827;
  --text-muted:   #4B5563;
  --text-faint:   #5A6270;
  --text-inverse: var(--gray-0);

  --accent:          var(--red-700);
  --accent-hover:    var(--red-600);
  --accent-subtle:   rgba(196, 46, 19, 0.08);
  --accent-2:        #5B3BE0;
  --accent-2-hover:  #4A2ECB;
  --accent-2-subtle: rgba(91, 59, 224, 0.10);
  --accent-contrast: var(--gray-0);

  --success: #127A4B; --success-subtle: rgba(18, 122, 75, 0.10);
  --warn:    #8A5600; --warn-subtle:    rgba(138, 86, 0, 0.10);
  --danger:  #B3261E; --danger-subtle:  rgba(179, 38, 30, 0.09);
  --info:    #0E6E86; --info-subtle:    rgba(14, 110, 134, 0.10);

  --focus-ring: #5B3BE0;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);
  --glow-accent: 0 0 0 1px rgba(196, 46, 19, 0.22), 0 8px 28px rgba(196, 46, 19, 0.12);

  --input-bg:   var(--gray-0);
  --card-bg:    var(--gray-0);
  --chip-bg:    var(--gray-100);
  --chip-color: var(--text-muted);
}

/* ---------- base reset -------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}
p { margin: 0; text-wrap: pretty; }
img, svg, video { display: block; max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-sm); }
::selection { background: var(--accent); color: var(--accent-contrast); }

/* ---------- layout utilities -------------------------------------- */
.container { width: min(100% - (var(--container-pad) * 2), var(--container-max)); margin-inline: auto; }
.section { padding-block: var(--section-y); }
.section--tight { padding-block: var(--section-y-tight); }
.stack > * + * { margin-top: var(--space-4); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.grid-auto { display: grid; gap: var(--space-6); grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
.eyebrow {
  font-family: var(--font-mono); font-size: var(--text-xs);
  font-weight: var(--weight-medium); letter-spacing: var(--tracking-label);
  text-transform: uppercase; color: var(--text-faint);
}
.text-muted { color: var(--text-muted); }
.measure { max-width: var(--measure); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--space-4); top: calc(var(--nav-height) * -1);
  z-index: var(--z-toast); background: var(--accent); color: var(--accent-contrast);
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-md);
  transition: top var(--dur-base) var(--ease-out);
}
.skip-link:focus { top: var(--space-3); color: var(--accent-contrast); }

/* ---------- motion safety ----------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}


/* Starscope — page styles. Every value resolves to a token in tokens.css. */

/* ============ buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: var(--btn-pad-y) var(--btn-pad-x);
  border-radius: var(--btn-radius); border: 1px solid transparent;
  font-size: var(--btn-font); font-weight: var(--btn-weight);
  cursor: pointer; white-space: nowrap;
  transition: background-color var(--btn-dur), border-color var(--btn-dur),
              color var(--btn-dur), transform var(--btn-dur), box-shadow var(--btn-dur);
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: var(--accent-contrast); }
.btn--primary:hover { background: var(--accent-hover); color: var(--accent-contrast); box-shadow: var(--glow-accent); }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn--ghost:hover { border-color: var(--text-muted); color: var(--text); background: var(--surface-2); }
.btn--sm { padding: var(--space-2) var(--space-3); font-size: var(--text-xs); }
.btn--icon { padding: var(--space-2); min-width: 40px; min-height: 40px; }
.btn[disabled] { opacity: .55; cursor: default; box-shadow: none; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font-size: var(--text-sm); cursor: pointer; }
.linkbtn:hover { color: var(--accent-hover); text-decoration: underline; }

/* ============ header / nav ============ */
.site-header {
  position: sticky; top: 0; z-index: var(--z-sticky);
  height: var(--nav-height);
  border-bottom: 1px solid transparent;
  background: color-mix(in oklab, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  transition: border-color var(--dur-base) var(--ease-out);
}
.site-header[data-scrolled="true"] { border-bottom-color: var(--border); }
.nav { display: flex; align-items: center; gap: var(--space-6); height: 100%; }
.nav__brand { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--text); font-weight: var(--weight-bold); font-size: var(--text-h4); letter-spacing: var(--tracking-tight); }
.nav__brand:hover { color: var(--text); }
.nav__mark { width: 28px; height: 28px; border-radius: var(--radius-sm); background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; flex: none; }
.nav__mark svg { width: 18px; height: 18px; }
.nav__sub { font-family: var(--font-mono); font-size: 10px; letter-spacing: var(--tracking-label); color: var(--text-faint); padding-left: var(--space-2); border-left: 1px solid var(--border); }
.nav__links { display: none; gap: var(--space-6); margin-inline-start: auto; }
.nav__links a { color: var(--text-muted); font-size: var(--text-sm); transition: color var(--dur-fast); }
.nav__links a:hover, .nav__links a[aria-current="page"] { color: var(--text); }
.nav__actions { display: flex; align-items: center; gap: var(--space-2); margin-inline-start: auto; }
.nav__links + .nav__actions { margin-inline-start: 0; }
.status-pill {
  display: inline-flex; align-items: center; gap: var(--space-2);
  border: 1px solid var(--border); border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-3); color: var(--text-muted);
  font-size: var(--text-xs); font-family: var(--font-mono); white-space: nowrap;
}
.status-pill__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); flex: none; }
.nav__toggle { display: inline-flex; background: none; border: 1px solid var(--border); border-radius: var(--radius-md); min-width: 40px; min-height: 40px; align-items: center; justify-content: center; cursor: pointer; }
.mobile-menu { display: none; position: absolute; inset-inline: 0; top: var(--nav-height); background: var(--surface); border-bottom: 1px solid var(--border); padding: var(--space-4) var(--container-pad); }
.mobile-menu[data-open="true"] { display: grid; gap: var(--space-1); }
.mobile-menu a { padding: var(--space-3); border-radius: var(--radius-md); color: var(--text-muted); min-height: 44px; display: flex; align-items: center; }
.mobile-menu a:hover { background: var(--surface-2); color: var(--text); }
@media (min-width: 768px) {
  .nav__links { display: flex; }
  .nav__toggle { display: none; }
  .nav__actions { margin-inline-start: 0; }
}
@media (max-width: 1023px) { .status-pill { display: none; } }
@media (min-width: 1280px) { .nav__sub { display: inline; } }

/* ============ hero ============ */
.hero { position: relative; overflow: hidden; padding-block: clamp(3rem, 8vw, 6.5rem) var(--space-12); }
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(60% 70% at 85% 0%, var(--accent-2-subtle), transparent 70%);
}
.hero__grid { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-10); align-items: center; }
.hero__title { font-size: var(--text-hero); font-weight: var(--weight-black); line-height: var(--leading-tight); letter-spacing: var(--tracking-display); max-width: 16ch; margin-top: var(--space-5); }
.hero__title em { font-style: normal; background: linear-gradient(100deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero__sub { margin-top: var(--space-6); max-width: 50ch; color: var(--text-muted); font-size: 1.0625rem; }
.hero__actions { margin-top: var(--space-8); display: flex; flex-wrap: wrap; gap: var(--space-3); }
.hero__proof { margin-top: var(--space-6); display: flex; flex-wrap: wrap; gap: var(--space-4); color: var(--text-faint); font-size: var(--text-xs); font-family: var(--font-mono); }
.hero__proof span { display: inline-flex; align-items: center; gap: var(--space-2); }
.hero__proof i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); display: inline-block; }
.hero__visual { position: relative; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--surface); padding: var(--space-6); min-width: 0; }
.hero__visual-head { display: flex; justify-content: space-between; gap: var(--space-3); align-items: baseline; margin-bottom: var(--space-5); }
.hero__visual-head strong { font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.hero__visual-head span { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-faint); }
.sparkbars { display: flex; align-items: flex-end; gap: 3px; height: 128px; }
.sparkbars span { flex: 1; min-width: 2px; height: var(--h); border-radius: 2px 2px 0 0; background: linear-gradient(180deg, var(--accent), var(--accent-2)); opacity: .88; }
.sparkbars span:nth-child(3n) { opacity: .55; }
.hero__visual-foot { display: flex; justify-content: space-between; margin-top: var(--space-4); color: var(--text-faint); font-size: var(--text-xs); font-family: var(--font-mono); }
@media (min-width: 1024px) { .hero__grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: var(--space-16); } }

/* ============ KPI band ============ */
.kpis { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); padding-bottom: var(--space-12); }
.kpi { background: var(--card-bg); border: var(--card-border); border-radius: var(--radius-lg); padding: var(--space-5); }
.kpi__label { color: var(--text-faint); font-size: var(--text-xs); font-family: var(--font-mono); letter-spacing: var(--tracking-label); text-transform: uppercase; }
.kpi__value { font-family: var(--font-display); font-weight: var(--weight-bold); font-size: clamp(1.75rem, 1.2rem + 1.6vw, 2.5rem); letter-spacing: var(--tracking-tight); margin-top: var(--space-2); font-variant-numeric: tabular-nums; }
.kpi__note { color: var(--text-muted); font-size: var(--text-xs); margin-top: var(--space-1); }

/* ============ section head ============ */
.section-head { max-width: 64ch; margin-bottom: var(--space-8); }
.section-head h2 { font-size: var(--text-h2); }
.section-head p { margin-top: var(--space-3); color: var(--text-muted); }
.section-head__row { display: flex; flex-wrap: wrap; gap: var(--space-4); align-items: end; justify-content: space-between; }
.section-head__row .section-head { margin-bottom: 0; }

/* ============ workbench ============ */
.workbench { border-top: 1px solid var(--border); padding-block: var(--section-y-tight); scroll-margin-top: var(--nav-height); }
.wb { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); align-items: start; }
@media (min-width: 1024px) { .wb { grid-template-columns: var(--rail-width) minmax(0, 1fr); gap: var(--space-5); } }

.rail { background: var(--card-bg); border: var(--card-border); border-radius: var(--radius-lg); padding: var(--space-4); }
@media (min-width: 1024px) { .rail { position: sticky; top: calc(var(--nav-height) + var(--space-4)); max-height: calc(100dvh - var(--nav-height) - var(--space-8)); overflow-y: auto; } }
.rail__title { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-faint); letter-spacing: var(--tracking-label); text-transform: uppercase; padding: var(--space-1) var(--space-2) var(--space-3); display: flex; justify-content: space-between; gap: var(--space-2); }
.rail__list { display: flex; flex-wrap: wrap; gap: var(--space-1); }
@media (min-width: 1024px) { .rail__list { display: grid; } }
.side-item {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3); min-height: 40px;
  border: 1px solid transparent; border-radius: var(--radius-md);
  background: transparent; color: var(--text-muted); font-size: var(--text-sm);
  text-align: left; cursor: pointer; transition: background-color var(--dur-fast), color var(--dur-fast);
}
@media (max-width: 1023px) { .side-item { width: auto; border-color: var(--border); } }
.side-item:hover { background: var(--surface-2); color: var(--text); }
.side-item[aria-pressed="true"] { background: var(--accent-subtle); color: var(--accent); border-color: var(--accent); font-weight: var(--weight-semibold); }
.side-item.is-zero { opacity: .5; }
.side-item__count { font-size: var(--text-xs); color: var(--text-faint); font-variant-numeric: tabular-nums; }
.side-item[aria-pressed="true"] .side-item__count { color: var(--accent); }
.rail__divider { height: 1px; background: var(--border); margin-block: var(--space-4); }
.rail__tags { display: flex; flex-wrap: wrap; gap: var(--space-2); padding: var(--space-1) var(--space-2) var(--space-2); }
.rail__cta { margin-top: var(--space-3); background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-md); padding: var(--space-3); }
.rail__cta b { display: block; font-size: var(--text-sm); margin-bottom: var(--space-1); }
.rail__cta p { color: var(--text-muted); font-size: var(--text-xs); }
.rail__cta .btn { margin-top: var(--space-3); width: 100%; }

.panel { min-width: 0; }
.panel__head { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.tabs { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.tab {
  padding: var(--space-2) var(--space-4); min-height: 40px;
  border: 1px solid var(--border); border-radius: var(--radius-full);
  background: var(--card-bg); color: var(--text-muted); font-size: var(--text-sm); cursor: pointer;
  transition: background-color var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}
.tab:hover { color: var(--text); border-color: var(--border-strong); }
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); font-weight: var(--weight-semibold); }
.tab__badge { font-size: 10px; margin-left: var(--space-2); padding: 1px var(--space-2); border-radius: var(--radius-full); background: var(--surface-2); color: var(--text-muted); }
.tab[aria-selected="true"] .tab__badge { background: color-mix(in oklab, var(--accent-contrast) 16%, transparent); color: var(--accent-contrast); }
.panel__tools { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.hint { font-size: var(--text-xs); color: var(--text-muted); background: var(--accent-2-subtle); border: 1px solid var(--border); border-left: 3px solid var(--accent-2); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-3); }

.subbar { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; margin-bottom: var(--space-3); }
.subbar__label { font-size: var(--text-xs); color: var(--text-faint); font-family: var(--font-mono); letter-spacing: var(--tracking-label); }
.seg { padding: var(--space-1) var(--space-3); min-height: 32px; border: 1px solid var(--border); border-radius: var(--radius-full); background: transparent; color: var(--text-muted); font-size: var(--text-xs); cursor: pointer; }
.seg:hover { color: var(--text); border-color: var(--border-strong); }
.seg[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); font-weight: var(--weight-semibold); }

/* ============ toolbar ============ */
.toolbar { background: var(--card-bg); border: var(--card-border); border-radius: var(--radius-lg); padding: var(--space-4); display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); }
.field { display: grid; gap: var(--space-1); min-width: 0; }
.field > span { font-size: var(--text-xs); color: var(--text-faint); font-family: var(--font-mono); letter-spacing: var(--tracking-label); }
.field--wide { grid-column: span 2; }
@media (max-width: 599px) { .field--wide { grid-column: span 1; } }
.field input, .field select {
  width: 100%; background: var(--input-bg); border: var(--input-border);
  border-radius: var(--input-radius); padding: var(--input-pad);
  font-size: 1rem; color: var(--text); outline: none; min-height: 42px;
}
.field input:focus, .field select:focus { border-color: var(--focus-ring); box-shadow: 0 0 0 2px var(--accent-2-subtle); }
.field input::placeholder { color: var(--text-faint); }

/* One balanced toolbar row on wide desktops: search takes 2 of 6 columns. */
@media (min-width: 1200px) { .toolbar { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

/* Active filters must be visible, otherwise switching views looks broken. */
.filterbar { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; padding: var(--space-3) var(--space-1) 0; }
.filterbar:empty { display: none; }
.filterbar__label { font-size: var(--text-xs); color: var(--text-faint); font-family: var(--font-mono); letter-spacing: var(--tracking-label); }
.filter-chip { display: inline-flex; align-items: center; gap: var(--space-2); background: var(--accent-subtle); color: var(--accent); border: 1px solid var(--accent); border-radius: var(--radius-full); padding: 2px var(--space-2) 2px var(--space-3); font-size: var(--text-xs); }
.filter-chip button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px; }
.filter-chip button:hover { color: var(--text); }
.filterbar__clear { background: transparent; border: 0; color: var(--text-muted); font-size: var(--text-xs); text-decoration: underline; cursor: pointer; }

.summary { display: flex; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; align-items: center; color: var(--text-muted); font-size: var(--text-xs); padding: var(--space-4) var(--space-1) var(--space-3); }
.summary b { color: var(--text); font-weight: var(--weight-semibold); }
.summary__right { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.online-msg { color: var(--success); }

/* ============ repo rows ============ */
.list { display: grid; gap: var(--space-2); }
.repo { background: var(--card-bg); border: var(--card-border); border-radius: var(--radius-md); padding: var(--row-padding); display: flex; gap: var(--space-4); min-width: 0; transition: border-color var(--dur-fast), background-color var(--dur-fast); }
.repo:hover { border-color: var(--border-strong); }
.repo__rank { width: 30px; flex: none; text-align: center; font-family: var(--font-mono); font-size: var(--text-body); color: var(--text-faint); font-variant-numeric: tabular-nums; padding-top: 2px; }
/* Numbers are list positions, not awards: no podium highlighting. */
.repo__body { min-width: 0; flex: 1; }
.repo__title { font-size: 1rem; line-height: 1.45; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.repo__title a { font-weight: var(--weight-semibold); color: var(--text); overflow-wrap: anywhere; }
.repo__title a:hover { color: var(--accent); }
.repo__desc { color: var(--text-muted); font-size: var(--text-sm); margin-top: var(--space-1); overflow-wrap: anywhere; }
.repo__chips { margin-top: var(--space-3); display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.repo__stats { display: flex; flex-wrap: wrap; gap: var(--space-4); color: var(--text-faint); font-size: var(--text-xs); margin-top: var(--space-3); font-variant-numeric: tabular-nums; }
.repo__stats span { display: inline-flex; align-items: center; gap: var(--space-1); }
.lang-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

.badge { display: inline-flex; align-items: center; font-size: var(--text-xs); border-radius: var(--radius-sm); padding: 1px var(--space-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge--gain { background: var(--success-subtle); color: var(--success); font-weight: var(--weight-semibold); }
.badge--ratio { background: var(--warn-subtle); color: var(--warn); }
.badge--lic { background: transparent; border: 1px solid var(--border-strong); color: var(--text-muted); }
.badge--age { background: transparent; color: var(--text-faint); }
.badge--local { background: var(--surface-2); color: var(--text-muted); }
.badge--online { background: var(--info-subtle); color: var(--info); }

.chip { background: var(--chip-bg); color: var(--chip-color); border: 1px solid transparent; font-size: var(--text-xs); padding: 2px var(--space-2); border-radius: var(--radius-full); cursor: pointer; }
.chip:hover { background: var(--accent-subtle); color: var(--accent); border-color: var(--accent); }
.chip--cat { border-radius: var(--radius-sm); border-color: var(--border); background: transparent; }
.chip--cat:hover { border-color: var(--accent-2); color: var(--accent-2); background: var(--accent-2-subtle); }

/* ============ empty / status ============ */
.empty { background: var(--card-bg); border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); padding: var(--space-12) var(--space-6); text-align: center; }
.empty__title { font-size: var(--text-h4); font-weight: var(--weight-semibold); }
.empty__body { color: var(--text-muted); font-size: var(--text-sm); margin-top: var(--space-2); }
.empty__actions { display: flex; gap: var(--space-2); justify-content: center; flex-wrap: wrap; margin-top: var(--space-6); }

/* Progressive rendering: "all rows" without ever blocking the main thread. */
.loadmore { display: flex; gap: var(--space-3); align-items: center; justify-content: center; flex-wrap: wrap; padding: var(--space-6) 0 var(--space-4); }
.loadmore p { flex-basis: 100%; text-align: center; color: var(--text-muted); font-size: var(--text-xs); }
#listSentinel { height: 1px; }

/* ============ tag explorer ============ */
.tagpanel { background: var(--card-bg); border: var(--card-border); border-radius: var(--radius-lg); padding: var(--space-5); margin-bottom: var(--space-3); }
.tagpanel h3 { font-size: var(--text-h4); }
.tagpanel__sub { color: var(--text-muted); font-size: var(--text-sm); margin-top: var(--space-1); }
.tag-form { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: stretch; margin-top: var(--space-4); }
.tag-form__input { flex: 1; min-width: min(220px, 100%); font-size: 1rem; min-height: 44px; background: var(--input-bg); border: var(--input-border); border-radius: var(--input-radius); padding: var(--input-pad); outline: none; }
.tag-form__input:focus { border-color: var(--focus-ring); box-shadow: 0 0 0 2px var(--accent-2-subtle); }
.tag-form select { min-height: 44px; background: var(--input-bg); border: var(--input-border); border-radius: var(--input-radius); padding-inline: var(--space-3); font-size: var(--text-sm); }
.tag-form__advanced { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; margin-top: var(--space-3); }
.tag-form__advanced label { display: inline-flex; gap: var(--space-2); align-items: center; font-size: var(--text-xs); color: var(--text-faint); }
.tag-form__advanced input { font-size: var(--text-sm); min-height: 36px; background: var(--input-bg); border: var(--input-border); border-radius: var(--radius-sm); padding-inline: var(--space-2); }
.tag-form__note { flex: 1 1 320px; font-size: var(--text-xs); color: var(--text-faint); line-height: 1.6; }
.cloud { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px solid var(--border); }
.cloud__hint { flex-basis: 100%; font-size: var(--text-xs); color: var(--text-faint); }
.cloud button { border-radius: var(--radius-full); border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); padding: 2px var(--space-3); cursor: pointer; }
.cloud button:hover { border-color: var(--accent); color: var(--accent); }
.cloud button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.cloud button span { opacity: .65; margin-left: var(--space-1); }
.status { font-size: var(--text-xs); margin-top: var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); }
.status--info { background: var(--info-subtle); color: var(--info); }
.status--err { background: var(--danger-subtle); color: var(--danger); }
.related { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-top: var(--space-3); }
.related__label { font-size: var(--text-xs); color: var(--text-faint); }

/* ============ method / CTA / footer ============ */
.method { border-top: 1px solid var(--border); padding-block: var(--section-y-tight); scroll-margin-top: var(--nav-height); }
.method .grid-auto { gap: var(--space-4); }
.card { background: var(--card-bg); border: var(--card-border); border-radius: var(--card-radius); padding: var(--card-padding); }
.card__index { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--accent); letter-spacing: var(--tracking-label); }
.card h3 { font-size: var(--text-h4); margin-top: var(--space-3); }
.card p { color: var(--text-muted); font-size: var(--text-sm); margin-top: var(--space-2); }
.caveat { margin-top: var(--space-6); border-left: 3px solid var(--warn); background: var(--warn-subtle); border-radius: var(--radius-md); padding: var(--space-4); color: var(--text-muted); font-size: var(--text-sm); }
.caveat strong { color: var(--text); }
.cta-band { border: 1px solid var(--border); border-radius: var(--radius-xl); padding: clamp(2rem, 6vw, 4rem); background: radial-gradient(120% 140% at 0% 0%, var(--accent-subtle), transparent 60%), var(--surface); text-align: center; margin-bottom: var(--space-16); }
.cta-band h2 { font-size: var(--text-h1); }
.cta-band p { color: var(--text-muted); margin-top: var(--space-4); }
.cta-band .cluster { justify-content: center; margin-top: var(--space-8); }
.site-footer { border-top: 1px solid var(--border); padding-block: var(--space-12) var(--space-8); color: var(--text-muted); font-size: var(--text-sm); }
.footer-grid { display: grid; gap: var(--space-8); grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); }
.footer-grid h4 { font-size: var(--text-sm); color: var(--text); margin-bottom: var(--space-3); }
.footer-grid ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.footer-grid a { color: var(--text-muted); }
.footer-grid a:hover { color: var(--text); }
.footer-grid code { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-faint); }
/* ============ legal / data ============ */
.legal { padding: var(--space-16) 0 var(--space-12); margin-top: var(--space-16); border-top: 1px solid var(--border); }
.legal .card h3 { margin-bottom: var(--space-2); }
.legal .card p { color: var(--text-muted); font-size: var(--text-sm); line-height: 1.7; }
.legal .card a { color: var(--accent); text-decoration: underline; }
.legal .card a:hover { text-decoration: none; }

.footer-legal { margin-top: var(--space-10); padding-top: var(--space-6); border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: var(--space-4); justify-content: space-between; font-size: var(--text-xs); color: var(--text-faint); }

/* ============ entrance motion: one deliberate pass ============ */
@media (prefers-reduced-motion: no-preference) {
  [data-reveal] { opacity: 0; transform: translateY(20px); animation: reveal var(--dur-slower) var(--ease-out) forwards; }
  [data-reveal]:nth-child(2) { animation-delay: 60ms; }
  [data-reveal]:nth-child(3) { animation-delay: 120ms; }
  [data-reveal]:nth-child(4) { animation-delay: 180ms; }
}
@keyframes reveal { to { opacity: 1; transform: none; } }

/* ============ small-screen tuning ============ */
@media (max-width: 599px) {
  .nav__sub { display: none; }
  /* Snapshot time also lives in the hero eyebrow and the footer — the pill
     gives way so the nav fits language + theme + tags + menu at 360px. */
  .status-pill { display: none; }
  .nav__actions { gap: var(--space-1); }
  /* Tag exploration is the fourth workbench tab already; the nav button is
     redundant on phones and the nav must fit language + theme + menu. */
  #navTags { display: none; }
  .repo { gap: var(--space-2); padding: var(--space-3); }
  .repo__rank { width: 22px; font-size: var(--text-sm); }
  .repo__stats { gap: var(--space-3); }
  .hero__visual { padding: var(--space-4); }
  .btn { min-height: 44px; }
  .tab { min-height: 44px; }
  .seg { min-height: 36px; }
  .chip { min-height: 28px; }
}
@media (min-width: 1600px) { .container { --container-max: 1360px; } }

/* ============ runtime toasts (monitor.js) ============ */
#toastHost {
  position: fixed; top: calc(var(--nav-height) + var(--space-4)); right: var(--space-4);
  z-index: var(--z-toast); display: grid; gap: var(--space-2);
  max-width: min(92vw, 420px); pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: var(--space-3);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-lg);
  pointer-events: auto; opacity: 1;
  transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
.toast--err { border-color: var(--danger); border-left: 3px solid var(--danger); }
.toast__msg { color: var(--text); font-size: var(--text-sm); line-height: 1.55; }
.toast__close {
  flex: none; background: none; border: 0; color: var(--text-muted);
  font-size: var(--text-body); line-height: 1; cursor: pointer;
  min-width: 28px; min-height: 28px; border-radius: var(--radius-sm);
}
.toast__close:hover { color: var(--text); background: var(--surface-2); }
.toast--out { opacity: 0; transform: translateY(-6px); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* ============ favourites ============ */
.favbtn {
  flex: none; background: none; border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--text-faint); font-size: var(--text-body); line-height: 1;
  min-width: 30px; min-height: 30px; cursor: pointer;
  transition: color var(--dur-fast), background-color var(--dur-fast), border-color var(--dur-fast);
}
.favbtn:hover { color: var(--warn); background: var(--surface-2); }
.favbtn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.favbtn.is-on { color: var(--warn); }

/* ============ project detail sheet ============ */
.detail { position: fixed; inset: 0; z-index: var(--z-modal); }
.detail[hidden] { display: none; }
.detail__backdrop { position: absolute; inset: 0; background: var(--overlay); }
.detail__panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(94vw, 520px);
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  overflow-y: auto; overscroll-behavior: contain;
  padding: var(--space-6) var(--space-6) var(--space-10);
}
.detail__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-4); }
.detail__title { font-size: var(--text-h4); font-weight: var(--weight-bold); margin: 0; overflow-wrap: anywhere; }
.detail__link { color: var(--accent); font-size: var(--text-body); font-weight: var(--weight-semibold); overflow-wrap: anywhere; }
.detail__link:hover { color: var(--accent-hover); }
.detail__gains { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: var(--space-3) 0 0; }
.detail__desc { color: var(--text-muted); line-height: 1.7; margin: var(--space-4) 0; }
.detail__actions { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; margin: var(--space-2) 0 var(--space-4); }
.detail__stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-3); margin: var(--space-4) 0 0; }
.detail__stats > div { border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); background: var(--bg-subtle); }
.detail__stats dt { color: var(--text-faint); font-size: var(--text-xs); font-family: var(--font-mono); letter-spacing: var(--tracking-label); text-transform: uppercase; margin-bottom: var(--space-1); }
.detail__stats dd { margin: 0; color: var(--text); font-size: var(--text-body); font-variant-numeric: tabular-nums; }
@media (max-width: 599px) { .detail__panel { width: 100vw; border-left: 0; } }
