/* tinyblue.dev — shared design system
 * Apple-inspired tokens, primitives, and utility classes used across the
 * tinyblue.dev root + sub-apps. Light/dark via [data-theme] OR
 * prefers-color-scheme. Cross-tab sync via `tb_theme` in localStorage.
 *
 * Hard rules:
 *   • No emojis. Glyphs come from tinyblue-system.js (window.TB.glyph).
 *   • Tabular numerics on stat/number-heavy pages.
 *   • All interactive elements get :focus-visible rings.
 *   • Respects prefers-reduced-motion.
 */

/* ─────────────────────────────────────────────────────────────── tokens ── */
:root {
  /* Typography */
  --tb-font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display",
    "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  --tb-font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code",
    Menlo, Monaco, Consolas, monospace;

  /* Surfaces */
  --tb-bg: #fbfbfd;
  --tb-surface: #ffffff;
  --tb-surface-2: #f5f5f7;
  --tb-surface-3: #ececef;

  /* Ink */
  --tb-ink: #1d1d1f;
  --tb-ink-2: #424245;
  --tb-ink-3: #6e6e73;
  --tb-ink-4: #86868b;

  /* Hairlines */
  --tb-hairline: rgba(0, 0, 0, 0.08);
  --tb-hairline-strong: rgba(0, 0, 0, 0.14);

  /* Accent — deep tinyblue */
  --tb-accent: #1f4e8a;
  --tb-accent-hover: #1a4276;
  --tb-accent-2: #2997ff;
  --tb-accent-soft: rgba(31, 78, 138, 0.08);
  --tb-accent-ring: rgba(31, 78, 138, 0.28);

  /* Semantic */
  --tb-ok: #34c759;
  --tb-warn: #ff9f0a;
  --tb-bad: #ff453a;
  --tb-info: #0a84ff;

  /* Geometry */
  --tb-radius-sm: 8px;
  --tb-radius-md: 12px;
  --tb-radius-card: 16px;
  --tb-radius-lg: 22px;
  --tb-radius-pill: 999px;

  --tb-maxw: 1120px;
  --tb-gutter: clamp(20px, 4vw, 48px);

  /* Shadows */
  --tb-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.04),
                 0 4px 14px rgba(0, 0, 0, 0.04);
  --tb-shadow-2: 0 2px 6px rgba(0, 0, 0, 0.06),
                 0 18px 48px rgba(0, 0, 0, 0.08);
  --tb-shadow-soft: 0 20px 60px -20px rgba(0, 0, 0, 0.15);

  /* Motion */
  --tb-ease: cubic-bezier(0.32, 0.72, 0, 1);
  --tb-d-fast: 160ms;
  --tb-d: 240ms;
  --tb-d-slow: 700ms;

  color-scheme: light dark;
}

/* Dark — explicit attribute wins over media query */
[data-theme="dark"] {
  --tb-bg: #000000;
  --tb-surface: #161617;
  --tb-surface-2: #1d1d1f;
  --tb-surface-3: #2a2a2c;
  --tb-ink: #f5f5f7;
  --tb-ink-2: #d2d2d7;
  --tb-ink-3: #a1a1a6;
  --tb-ink-4: #6e6e73;
  --tb-hairline: rgba(255, 255, 255, 0.10);
  --tb-hairline-strong: rgba(255, 255, 255, 0.18);
  --tb-accent: #5b8def;
  --tb-accent-hover: #84a6f1;
  --tb-accent-soft: rgba(91, 141, 239, 0.14);
  --tb-accent-ring: rgba(91, 141, 239, 0.34);
  --tb-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5),
                 0 4px 14px rgba(0, 0, 0, 0.4);
  --tb-shadow-2: 0 2px 6px rgba(0, 0, 0, 0.55),
                 0 18px 48px rgba(0, 0, 0, 0.55);
  --tb-shadow-soft: 0 24px 70px -20px rgba(0, 0, 0, 0.7);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tb-bg: #000000;
    --tb-surface: #161617;
    --tb-surface-2: #1d1d1f;
    --tb-surface-3: #2a2a2c;
    --tb-ink: #f5f5f7;
    --tb-ink-2: #d2d2d7;
    --tb-ink-3: #a1a1a6;
    --tb-ink-4: #6e6e73;
    --tb-hairline: rgba(255, 255, 255, 0.10);
    --tb-hairline-strong: rgba(255, 255, 255, 0.18);
    --tb-accent: #5b8def;
    --tb-accent-hover: #84a6f1;
    --tb-accent-soft: rgba(91, 141, 239, 0.14);
    --tb-accent-ring: rgba(91, 141, 239, 0.34);
    --tb-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5),
                   0 4px 14px rgba(0, 0, 0, 0.4);
    --tb-shadow-2: 0 2px 6px rgba(0, 0, 0, 0.55),
                   0 18px 48px rgba(0, 0, 0, 0.55);
    --tb-shadow-soft: 0 24px 70px -20px rgba(0, 0, 0, 0.7);
  }
}

/* ───────────────────────────────────────────────────────── base reset ── */
.tb-scope, .tb-scope * { box-sizing: border-box; }

.tb-scope {
  font-family: var(--tb-font-sans);
  color: var(--tb-ink);
  background: var(--tb-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ────────────────────────────────────────────────────────── typography ─ */
.tb-display {
  font-size: clamp(48px, 8vw, 104px);
  line-height: 0.98;
  letter-spacing: -0.04em;
  font-weight: 600;
}
.tb-h1 {
  font-size: clamp(36px, 5.2vw, 64px);
  line-height: 1.04;
  letter-spacing: -0.03em;
  font-weight: 600;
}
.tb-h2 {
  font-size: clamp(28px, 3.4vw, 44px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 600;
}
.tb-h3 {
  font-size: 22px;
  line-height: 1.25;
  letter-spacing: -0.015em;
  font-weight: 600;
}
.tb-body {
  font-size: 16px;
  line-height: 1.55;
  letter-spacing: -0.011em;
  color: var(--tb-ink-2);
}
.tb-lede {
  font-size: clamp(18px, 1.6vw, 22px);
  line-height: 1.45;
  letter-spacing: -0.012em;
  color: var(--tb-ink-2);
  max-width: 62ch;
}
.tb-mono {
  font-family: var(--tb-font-mono);
  font-size: 13px;
  letter-spacing: 0.01em;
}
.tb-tnum { font-variant-numeric: tabular-nums; }

.tb-eyebrow {
  display: inline-block;
  font-family: var(--tb-font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tb-accent);
  padding: 4px 10px;
  border: 1px solid var(--tb-accent-ring);
  border-radius: var(--tb-radius-pill);
  background: var(--tb-accent-soft);
}

/* ──────────────────────────────────────────────────────── primitives ─── */
.tb-card {
  background: var(--tb-surface);
  border: 1px solid var(--tb-hairline);
  border-radius: var(--tb-radius-card);
  padding: 24px;
  transition:
    transform var(--tb-d) var(--tb-ease),
    box-shadow var(--tb-d) var(--tb-ease),
    border-color var(--tb-d) var(--tb-ease);
}
.tb-card--hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--tb-shadow-2);
  border-color: var(--tb-hairline-strong);
}
.tb-card--glass {
  background: color-mix(in srgb, var(--tb-surface) 70%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
}

.tb-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-family: var(--tb-font-mono);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  border-radius: var(--tb-radius-pill);
  background: var(--tb-surface-2);
  color: var(--tb-ink-3);
  border: 1px solid var(--tb-hairline);
}

.tb-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--tb-radius-pill);
  background: var(--tb-surface-2);
  color: var(--tb-ink);
  border: 1px solid var(--tb-hairline);
  cursor: pointer;
  transition: background var(--tb-d-fast) var(--tb-ease),
              border-color var(--tb-d-fast) var(--tb-ease);
}
.tb-chip:hover {
  background: var(--tb-surface-3);
  border-color: var(--tb-hairline-strong);
}
.tb-chip[aria-pressed="true"] {
  background: var(--tb-accent-soft);
  color: var(--tb-accent);
  border-color: var(--tb-accent-ring);
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 22px;
  border-radius: var(--tb-radius-pill);
  font-family: var(--tb-font-sans);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1;
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    transform var(--tb-d-fast) var(--tb-ease),
    background var(--tb-d-fast) var(--tb-ease),
    color var(--tb-d-fast) var(--tb-ease),
    border-color var(--tb-d-fast) var(--tb-ease),
    box-shadow var(--tb-d-fast) var(--tb-ease);
  text-decoration: none;
}
.tb-btn-filled {
  background: var(--tb-accent);
  color: #fff;
}
.tb-btn-filled:hover {
  background: var(--tb-accent-hover);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: var(--tb-shadow-1);
}
.tb-btn-outline {
  background: transparent;
  color: var(--tb-ink);
  border-color: var(--tb-hairline-strong);
}
.tb-btn-outline:hover {
  background: var(--tb-surface-2);
  color: var(--tb-ink);
  transform: translateY(-1px);
}
.tb-btn-ghost {
  background: transparent;
  color: var(--tb-ink-2);
}
.tb-btn-ghost:hover {
  background: var(--tb-surface-2);
  color: var(--tb-ink);
}
.tb-btn:focus-visible {
  outline: 2px solid var(--tb-accent-ring);
  outline-offset: 2px;
}
.tb-btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

.tb-input {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--tb-radius-md);
  background: var(--tb-surface);
  color: var(--tb-ink);
  border: 1px solid var(--tb-hairline-strong);
  font-family: var(--tb-font-sans);
  font-size: 15px;
  line-height: 1.4;
  letter-spacing: -0.01em;
  outline: none;
  transition: border-color var(--tb-d-fast) var(--tb-ease),
              box-shadow var(--tb-d-fast) var(--tb-ease);
}
.tb-input::placeholder { color: var(--tb-ink-4); }
.tb-input:focus {
  border-color: var(--tb-accent);
  box-shadow: 0 0 0 4px var(--tb-accent-ring);
}

/* Glyphs always inherit currentColor */
.tb-glyph {
  width: 1em;
  height: 1em;
  display: inline-block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.15em;
  flex-shrink: 0;
}
.tb-glyph--solid { fill: currentColor; stroke: none; }
/* Sized helpers — used in eyebrows, list items, badges. Override the 1em default. */
.tb-glyph--sm { width: 14px; height: 14px; }
.tb-glyph--md { width: 18px; height: 18px; }
.tb-glyph--lg { width: 22px; height: 22px; }
.tb-glyph--xl { width: 26px; height: 26px; }
/* Inline eyebrow glyph: small gap between glyph and label */
.eyebrow .tb-glyph { margin-right: 6px; vertical-align: -0.18em; opacity: 0.95; }
/* Glyph bullets — replaces ::before circle. */
.glyph-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.glyph-list li { display: flex; align-items: flex-start; gap: 10px; color: var(--ink-soft); font-size: 15.5px; line-height: 1.55; }
.glyph-list li .tb-glyph { flex-shrink: 0; margin-top: 0.22em; color: var(--tb-blue); }
/* Inline stat annotation — small glyph next to a stat label */
.stat__label .tb-glyph { margin-right: 6px; color: var(--tb-blue); opacity: 0.85; vertical-align: -0.18em; }
.stat__value .tb-glyph { margin-left: 6px; color: var(--tb-blue); opacity: 0.8; vertical-align: -0.05em; }
/* Changelog list-item glyphs */
.changelog-entry ul.glyph-list li::before { display: none; }
.changelog-entry ul.glyph-list { padding-left: 0; }
/* Timeline row glyph cell */
.timeline-row__glyph { color: var(--tb-blue); display: inline-flex; align-items: center; margin-right: 6px; vertical-align: -0.18em; }
/* Belt-and-suspenders: child shapes that lack an explicit fill/stroke inherit
   from the parent SVG. Some browsers compute getComputedStyle(child).stroke
   as 'none' for raw <circle>/<path> elements without an explicit attribute
   even when the parent SVG has stroke set via CSS — set them defensively. */
.tb-glyph > * {
  fill: inherit;
  stroke: inherit;
  stroke-width: inherit;
  stroke-linecap: inherit;
  stroke-linejoin: inherit;
  vector-effect: non-scaling-stroke;
}
.tb-glyph--solid > * { stroke: none; fill: inherit; }

.tb-icon-box {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: var(--tb-accent-soft);
  color: var(--tb-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

/* Status dots */
.tb-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: var(--tb-ink-3);
  flex: 0 0 auto;
}
.tb-dot--ok   { background: var(--tb-ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--tb-ok) 18%, transparent); }
.tb-dot--warn { background: var(--tb-warn); }
.tb-dot--bad  { background: var(--tb-bad); }
.tb-dot--info { background: var(--tb-info); }

/* Hairline divider */
.tb-rule {
  border: 0;
  height: 1px;
  background: var(--tb-hairline);
  margin: 0;
}

/* ───────────────────────────────────────────────────────── tables ────── */
.tb-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}
.tb-table thead th {
  position: sticky;
  top: 0;
  background: var(--tb-surface);
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--tb-ink-3);
  padding: 12px 14px;
  border-bottom: 1px solid var(--tb-hairline-strong);
  z-index: 1;
}
.tb-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--tb-hairline);
  color: var(--tb-ink-2);
}
.tb-table tbody tr:hover td {
  background: var(--tb-surface-2);
  color: var(--tb-ink);
}
.tb-table tbody tr:last-child td { border-bottom: 0; }
.tb-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ────────────────────────────────────────────────────── theme toggle ── */
.tb-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  padding: 0;
  border-radius: var(--tb-radius-pill);
  background: transparent;
  color: var(--tb-ink-2);
  border: 1px solid var(--tb-hairline);
  cursor: pointer;
  transition: background var(--tb-d-fast) var(--tb-ease),
              color var(--tb-d-fast) var(--tb-ease),
              border-color var(--tb-d-fast) var(--tb-ease);
}
.tb-theme-toggle:hover {
  background: var(--tb-surface-2);
  color: var(--tb-ink);
}
.tb-theme-toggle .tb-glyph { width: 16px; height: 16px; }

/* ─────────────────────────────────────────────────────────── reveal ─── */
.tb-reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity var(--tb-d-slow) var(--tb-ease),
              transform var(--tb-d-slow) var(--tb-ease);
  will-change: opacity, transform;
}
.tb-reveal.is-in {
  opacity: 1;
  transform: none;
}

/* ──────────────────────────────────────────────── reduced motion ────── */
@media (prefers-reduced-motion: reduce) {
  .tb-reveal { opacity: 1; transform: none; transition: none; }
  .tb-card, .tb-btn { transition: none; }
}

/* ──────────────────────────────────────────────── focus ring (a11y) ─── */
.tb-scope a:focus-visible,
.tb-scope button:focus-visible,
.tb-scope [tabindex]:focus-visible {
  outline: 2px solid var(--tb-accent-ring);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ─────────────────────────────────────────────────────── layout aux ─── */
.tb-stack-v { display: flex; flex-direction: column; gap: 16px; }
.tb-stack-h { display: flex; align-items: center; gap: 16px; }
.tb-cluster { display: flex; flex-wrap: wrap; gap: 8px; }
.tb-spacer-sm { height: 16px; }
.tb-spacer-md { height: 32px; }
.tb-spacer-lg { height: 64px; }
.tb-grow { flex: 1 1 auto; }
.tb-spaced { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
