/* ============================================================
   Buscemi Centrality Explorer: Modern Neutral palette
   Inter + JetBrains Mono (self-hosted). Indigo accent. Mobile-first.
   WCAG 2.2 AA contrast. Honours prefers-color-scheme,
   prefers-reduced-motion, prefers-contrast.
   ============================================================ */

/* Self-hosted variable fonts at docs/assets/fonts/. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("assets/fonts/InterVariable.woff2") format("woff2-variations"),
       url("assets/fonts/InterVariable.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("assets/fonts/JetBrainsMono-VariableFont_wght.woff2") format("woff2-variations"),
       url("assets/fonts/JetBrainsMono-VariableFont_wght.woff2") format("woff2");
}

/* -- 1. Design tokens --------------------------------------- */
:root {
  color-scheme: light dark;

  /* Neutral surfaces (slate) */
  --bg:         #ffffff;
  --surface:    #ffffff;
  --surface-2:  #f8fafc;   /* slate-50 */
  --surface-3:  #f1f5f9;   /* slate-100 */
  --border:     #e2e8f0;   /* slate-200 */
  --border-soft:#edf1f6;

  /* Text (slate) */
  --text:       #0f172a;   /* slate-900 */
  --text-soft:  #334155;   /* slate-700, ~10.3:1 on white */
  --muted:      #64748b;   /* slate-500, ~4.7:1 on white */

  /* Accent: indigo-600 on white = 7.6:1 */
  --accent:       #4f46e5;
  --accent-fg:    #ffffff;
  --accent-hover: #4338ca;
  --accent-soft:  #eef2ff; /* indigo-50 */
  --accent-softer:#f5f3ff;

  /* Link colour same as accent for consistency */
  --link:         #4f46e5;
  --link-hover:   #4338ca;

  /* Supporting */
  --success:    #059669;
  --danger:     #b91c1c;
  --focus:      #4f46e5;

  /* Edge-type colours for the viz + swatches */
  --edge-rfc:   #4f46e5;   /* indigo */
  --edge-id:    #94a3b8;   /* slate-400 */
  --edge-rep:   #f59e0b;   /* amber-500, the Buscemi nod */
  --source-ring:#f59e0b;

  /* Typography */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --fs-xs:  0.75rem;    /* 12 */
  --fs-sm:  0.875rem;   /* 14 */
  --fs-base: 0.9375rem; /* 15 */
  --fs-md:  1rem;       /* 16 */
  --fs-lg:  1.125rem;   /* 18 */
  --fs-xl:  1.375rem;   /* 22 */
  --fs-2xl: 1.75rem;    /* 28 */
  --fs-3xl: 2.25rem;    /* 36 */

  --lh-tight: 1.2;
  --lh-body:  1.6;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;
  --space-10: 4rem;

  /* Radii */
  --radius-sm: 6px;
  --radius:    10px;
  --radius-md: 12px;
  --radius-lg: 14px;
  --radius-xl: 16px;
  --radius-pill: 999px;

  /* Shadows (soft, slate-tinted) */
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.04);
  --shadow:    0 1px 3px rgba(15,23,42,0.06), 0 4px 16px rgba(15,23,42,0.05);
  --shadow-md: 0 2px 6px rgba(15,23,42,0.06), 0 8px 24px rgba(15,23,42,0.06);

  /* Transitions */
  --t-fast: 120ms ease;
  --t:      180ms ease;

  /* Layout */
  --content-max: 1200px;
  --touch-min:   40px;
}

/* Dark-mode tokens. Activated when EITHER:
   - the OS prefers dark AND no manual data-theme="light" override is set, OR
   - data-theme="dark" is explicitly set on :root.
   Block intentionally duplicated for the two activation paths. Keep in sync. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:         #0a0f1c;
    --surface:    #0f172a;
    --surface-2:  #131c2f;
    --surface-3:  #1b2540;
    --border:     #243049;
    --border-soft:#1a2338;
    --text:       #f1f5f9;
    --text-soft:  #cbd5e1;
    --muted:      #94a3b8;
    --accent:       #818cf8;
    --accent-fg:    #0a0f1c;
    --accent-hover: #a5b4fc;
    --accent-soft:  #1e1b4b;
    --accent-softer:#151430;
    --link:       #a5b4fc;
    --link-hover: #c7d2fe;
    --edge-rfc:   #818cf8;
    --edge-id:    #64748b;
    --edge-rep:   #fbbf24;
    --source-ring:#fbbf24;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.45);
    --shadow:    0 1px 3px rgba(0,0,0,0.50), 0 6px 20px rgba(0,0,0,0.40);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.55), 0 1px 3px rgba(0,0,0,0.45);
  }
}
:root[data-theme="dark"] {
  --bg:         #0a0f1c;
  --surface:    #0f172a;
  --surface-2:  #131c2f;
  --surface-3:  #1b2540;
  --border:     #243049;
  --border-soft:#1a2338;
  --text:       #f1f5f9;
  --text-soft:  #cbd5e1;
  --muted:      #94a3b8;
  --accent:       #818cf8;
  --accent-fg:    #0a0f1c;
  --accent-hover: #a5b4fc;
  --accent-soft:  #1e1b4b;
  --accent-softer:#151430;
  --link:       #a5b4fc;
  --link-hover: #c7d2fe;
  --edge-rfc:   #818cf8;
  --edge-id:    #64748b;
  --edge-rep:   #fbbf24;
  --source-ring:#fbbf24;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.45);
  --shadow:    0 1px 3px rgba(0,0,0,0.50), 0 6px 20px rgba(0,0,0,0.40);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.55), 0 1px 3px rgba(0,0,0,0.45);
}
/* Tell the browser which palette is active so form controls etc. follow. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

@media (prefers-contrast: more) {
  :root {
    --border: #000;
    --text-soft: #000;
    --muted: #222;
  }
}

/* -- 2. Reset + base ---------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01", "kern";
  text-rendering: optimizeLegibility;
}
body { min-height: 100vh; min-height: 100dvh; }
img, svg { max-width: 100%; height: auto; }
a { color: var(--link); text-decoration: none; font-weight: 500; }
a:hover { color: var(--link-hover); text-decoration: underline; text-underline-offset: 3px; }
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

:where(h1, h2, h3, h4, h5) { line-height: var(--lh-tight); letter-spacing: -0.015em; color: var(--text); }
h1 { font-size: var(--fs-2xl); font-weight: 700; margin: 0 0 var(--space-2) 0; }
h2 { font-size: var(--fs-xl); font-weight: 650; margin: 0 0 var(--space-2) 0; }
h3 {
  font-size: var(--fs-xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: var(--space-5) 0 var(--space-2) 0;
}
p { margin: 0 0 var(--space-4) 0; color: var(--text-soft); }
.muted { color: var(--muted); font-size: var(--fs-sm); }
.small { color: var(--muted); font-size: var(--fs-xs); }
em { font-style: italic; }

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-3);
  color: var(--text);
  padding: 1px 6px;
  border-radius: 4px;
}
abbr { text-decoration: underline dotted; cursor: help; }

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

/* -- 3. Layout ---------------------------------------------- */
.wrap {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: var(--space-4);
}
@media (min-width: 720px) { .wrap { padding-inline: var(--space-6); } }

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-fg);
  padding: var(--space-2) var(--space-4);
  z-index: 100;
  border-radius: 0 0 var(--radius) 0;
  font-weight: 600;
  font-size: var(--fs-sm);
}
.skip-link:focus-visible { left: 0; outline-offset: -2px; }

/* -- 4. Header ---------------------------------------------- */
.site-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border-soft);
  padding: var(--space-4) 0 0 0;
}

.brand {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-3);
  align-items: center;
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-soft);
  min-width: 0;
}
.brand-text { min-width: 0; } /* allow tagline to wrap inside grid */
/* Below 820px the 3-column layout gets cramped; move the status chip onto its own row. */
@media (max-width: 820px) {
  .brand { grid-template-columns: auto 1fr; }
  .brand-status { grid-column: 1 / -1; justify-self: start; }
}
@media (max-width: 420px) {
  .brand { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .brand-text { text-align: center; }
  .brand-status { justify-self: center; }
}

.brand-chrome {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.brand-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-soft);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  cursor: default;
  max-width: 100%;
  min-width: 0;
}

.theme-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 2px;
}
.theme-toggle button {
  background: transparent;
  border: none;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  cursor: pointer;
  color: var(--muted);
  padding: 0;
  transition: background var(--t-fast), color var(--t-fast);
}
.theme-toggle button:hover { color: var(--text); }
.theme-toggle button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.brand-status .text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand-status .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
}
.brand-status[data-state="loading"] .dot {
  background: var(--accent);
  animation: status-pulse 1.2s ease-in-out infinite;
}
.brand-status[data-state="ready"] .dot { background: var(--success); }
.brand-status[data-state="error"] .dot { background: var(--danger); }
.brand-status[data-state="error"] { color: var(--danger); border-color: var(--danger); }

@keyframes status-pulse {
  0%, 100% { opacity: 0.35; transform: scale(1); }
  50%      { opacity: 1;    transform: scale(1.15); }
}
@media (prefers-reduced-motion: reduce) {
  .brand-status .dot { animation: none; }
}

tr.loading-row td {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  padding: var(--space-5);
}

.brand-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: var(--shadow-sm);
  background: var(--surface-3);
  flex-shrink: 0;
}
.brand-avatar-fallback {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-weight: 700;
  border: 1px solid var(--border);
}

.brand-text h1 {
  font-size: var(--fs-md);
  font-weight: 650;
  margin: 0;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
@media (min-width: 520px) { .brand-text h1 { font-size: var(--fs-lg); } }
@media (min-width: 820px) { .brand-text h1 { font-size: var(--fs-xl); } }

.tagline {
  margin: var(--space-1) 0 0 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  max-width: 70ch;
}
.tagline a { color: var(--link); font-weight: 500; }

/* Tabs: pill-style segmented control */
.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin: var(--space-4) 0;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.tab {
  flex: 0 0 auto;
  min-height: var(--touch-min);
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: none;
  padding: var(--space-2) var(--space-4);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* -- 5. Main + panels --------------------------------------- */
main.wrap { padding-block: var(--space-5) var(--space-8); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
@media (min-width: 720px) { .panel { padding: var(--space-6); } }
.panel + .panel { margin-top: var(--space-5); }
.panel h3:first-child { margin-top: 0; }

/* -- 6. Load tab -------------------------------------------- */
.load-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin: var(--space-4) 0;
}
.inline {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--text-soft);
}

/* Buttons */
button.primary, button.secondary, button.preset {
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-min);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast), transform 80ms;
}
button.primary {
  background: var(--accent);
  color: var(--accent-fg);
  box-shadow: var(--shadow-sm);
}
button.primary:hover:not(:disabled) { background: var(--accent-hover); box-shadow: var(--shadow); }
button.primary:active:not(:disabled) { transform: translateY(1px); }
button.primary:disabled { opacity: 0.55; cursor: not-allowed; }

button.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
button.secondary:hover:not(:disabled) { background: var(--surface-2); }
button.secondary:active:not(:disabled) { transform: translateY(1px); }
button.secondary:disabled { opacity: 0.55; cursor: not-allowed; }

.progress {
  margin: var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}
.progress .bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width var(--t);
}
.progress-text {
  margin-top: var(--space-2);
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  color: var(--muted);
  word-break: break-word;
}

.summary {
  margin: var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-soft);
  white-space: pre-wrap;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}

details.advanced {
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}
details.advanced summary {
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text);
}
details.advanced label { display: block; margin-top: var(--space-3); }

/* -- 7. Form controls --------------------------------------- */
input[type="text"], input[type="search"], input[type="number"], select, textarea {
  font-family: inherit;
  font-size: var(--fs-sm);
  padding: var(--space-2) var(--space-3);
  min-height: var(--touch-min);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
input:hover:not(:disabled), select:hover, textarea:hover { border-color: var(--muted); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

/* Custom select: kill native chrome, add chevron, match button height. */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: pointer;
  padding-right: 36px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none'><path d='M1 1.5l5 5 5-5' stroke='%2364748b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}
select:hover { background-color: var(--surface-2); }
select:focus-visible {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none'><path d='M1 1.5l5 5 5-5' stroke='%234f46e5' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}
select::-ms-expand { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) select {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none'><path d='M1 1.5l5 5 5-5' stroke='%2394a3b8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  }
}
:root[data-theme="dark"] select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none'><path d='M1 1.5l5 5 5-5' stroke='%2394a3b8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 32px;
  min-height: 0;
  padding: 0;
  border: none;
  background: transparent;
}
input[type="checkbox"] { min-width: 18px; min-height: 18px; accent-color: var(--accent); }

/* -- 8. Tables ---------------------------------------------- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-inline: calc(-1 * var(--space-4));
  padding-inline: var(--space-4);
}

table.leaderboard, table.bc-ranking, table.edges {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  background: var(--surface);
}
table caption {
  text-align: left;
  font-size: var(--fs-sm);
  color: var(--muted);
  padding: var(--space-2) 0;
}
table th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
/* Only suppress selection on headers that are themselves click targets for
   sorting. Non-sortable th text is selectable. */
table.sortable thead th[data-col] { user-select: none; -webkit-user-select: none; }

/* Sortable column headers */
table.sortable thead th[data-col] {
  cursor: pointer;
  padding-right: 22px;
  position: sticky;
  top: 0;
  background-image: none;
  transition: color var(--t-fast);
}
table.sortable thead th[data-col]:hover { color: var(--text); }
table.sortable thead th[data-col]::after {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 6px;
  vertical-align: -1px;
  opacity: 0.35;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 12'><path d='M5 1 L1 6 H9 Z M5 11 L1 6 H9 Z' fill='currentColor'/></svg>") center/contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 12'><path d='M5 1 L1 6 H9 Z M5 11 L1 6 H9 Z' fill='currentColor'/></svg>") center/contain no-repeat;
}
table.sortable thead th[aria-sort="ascending"] { color: var(--accent); }
table.sortable thead th[aria-sort="ascending"]::after {
  opacity: 1;
  background: var(--accent);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 12'><path d='M5 1 L1 8 H9 Z' fill='currentColor'/></svg>") center/contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 12'><path d='M5 1 L1 8 H9 Z' fill='currentColor'/></svg>") center/contain no-repeat;
}
table.sortable thead th[aria-sort="descending"] { color: var(--accent); }
table.sortable thead th[aria-sort="descending"]::after {
  opacity: 1;
  background: var(--accent);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 12'><path d='M5 11 L1 4 H9 Z' fill='currentColor'/></svg>") center/contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 12'><path d='M5 11 L1 4 H9 Z' fill='currentColor'/></svg>") center/contain no-repeat;
}
table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
}
table tbody tr { transition: background var(--t-fast); }
table tbody tr.interactive { cursor: pointer; }
table tbody tr.interactive:hover,
table tbody tr.interactive:focus-within { background: var(--surface-2); }
table tbody tr.interactive td:first-child { color: var(--muted); }
table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 0.92em;
  white-space: nowrap;
}
table th.num { text-align: right; }

/* -- 9. Explorer -------------------------------------------- */
.explorer-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.explorer-header p { margin: 0; }

/* Source banner: flat, no gradient. Left accent strip + label chip. */
.source-banner {
  margin: var(--space-4) 0;
  padding: var(--space-4) var(--space-5);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-lg);
  display: grid;
  gap: var(--space-2);
}
.source-banner[data-set="false"] {
  border-left-color: var(--border);
  background: var(--surface-2);
}
.source-banner .label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.source-banner[data-set="false"] .label { color: var(--muted); }
.source-banner .name {
  font-size: var(--fs-xl);
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
}
.source-banner .stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-1);
  min-width: 0;
}
.source-banner .stat {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  color: var(--text-soft);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.source-banner .stat b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.source-banner .explainer {
  font-size: var(--fs-sm);
  color: var(--text-soft);
  margin-top: var(--space-2);
}

.explorer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-5);
  margin-top: var(--space-4);
}
.explorer-grid > * { min-width: 0; }
@media (min-width: 960px) {
  .explorer-grid { grid-template-columns: 340px minmax(0, 1fr); align-items: start; }
}

.controls {
  display: grid;
  gap: var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.controls h3 { margin-top: var(--space-4); }
.controls h3:first-child { margin-top: 0; }

.source-picker { position: relative; }
.source-picker input[type="search"] { width: 100%; }
.suggest {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 280px;
  overflow-y: auto;
  z-index: 20;
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  box-shadow: var(--shadow-md);
}
.suggest li {
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-sm);
  cursor: pointer;
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
}
.suggest li:hover, .suggest li.active { background: var(--accent-soft); color: var(--text); }

.source-presets {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-2);
}
button.preset {
  min-height: 32px;
  padding: var(--space-1) var(--space-3);
  font-size: var(--fs-xs);
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
}
button.preset:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

label.slider {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-1) var(--space-3);
  align-items: center;
  font-size: var(--fs-sm);
}
label.slider .lbl {
  grid-column: 1 / -1;
  font-weight: 500;
  color: var(--text);
}
label.slider input[type="range"] { grid-column: 1 / 2; }
label.slider output {
  grid-column: 2 / 3;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  background: var(--surface-3);
  color: var(--text);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  min-width: 3.5ch;
  text-align: right;
}

table.edges {
  font-size: var(--fs-xs);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  table-layout: fixed;
  width: 100%;
}
table.edges th, table.edges td { padding: var(--space-1) var(--space-2); }
table.edges th { background: var(--surface-2); position: static; }
table.edges th:first-child, table.edges td:first-child { width: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.edges th:not(:first-child), table.edges td:not(:first-child) { width: 74px; }
table.edges input[type="number"] {
  width: 100%;
  min-width: 0;
  min-height: 30px;
  padding: 2px var(--space-1);
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
}

.swatch {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: var(--space-1);
  vertical-align: middle;
  border: 1px solid rgba(15,23,42,0.12);
}
.swatch.rfc { background: var(--edge-rfc); }
.swatch.id  { background: var(--edge-id); }
.swatch.rep { background: var(--edge-rep); }
.swatch.star {
  background: var(--source-ring);
  border-radius: 0;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  border: none;
}

.explorer-main { display: grid; gap: var(--space-5); min-width: 0; }
.explorer-main > * { min-width: 0; }

.viz-wrap {
  position: relative;
  aspect-ratio: 16 / 10;
  min-height: 360px;
  max-height: 640px;
  min-width: 0;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
svg#viz {
  width: 100%;
  height: 100%;
  display: block;
  min-width: 0;
  max-width: 100%;
}

.viz-legend {
  position: absolute;
  bottom: var(--space-2);
  left: var(--space-2);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-1) var(--space-2);
  font-size: var(--fs-xs);
  color: var(--text-soft);
  display: flex;
  gap: var(--space-3);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.ranking {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.ranking h3 { margin-top: 0; }
.ranking h3 #ranking-source-name { color: var(--accent); font-family: var(--font-mono); text-transform: none; letter-spacing: 0; font-size: inherit; font-weight: 600; }

.lookup {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-soft);
  display: grid;
  gap: var(--space-2);
}
.lookup-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.lookup-label #lookup-source-name {
  color: var(--accent);
  font-family: var(--font-mono);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}
#bc-lookup { width: 100%; }

.lookup-results { display: grid; gap: var(--space-1); }
.lookup-hit {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
}
.lookup-hit.lookup-miss {
  grid-template-columns: 1fr auto auto;
  background: var(--surface);
}
.lookup-rank {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--muted);
  white-space: nowrap;
}
.lookup-name { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lookup-stat {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-soft);
  white-space: nowrap;
}
.lookup-stat b { color: var(--text); font-weight: 600; }
.lookup-badge {
  font-size: var(--fs-xs);
  color: var(--muted);
  font-style: italic;
  white-space: nowrap;
}
.lookup-reroot {
  min-height: 28px;
  padding: var(--space-1) var(--space-3);
  font-size: var(--fs-xs);
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.lookup-reroot:hover { background: var(--accent-soft); border-color: var(--accent); }
.lookup-note {
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-xs);
  color: var(--muted);
  font-style: italic;
}

/* Narrow viewports: stack lookup hit contents vertically. */
@media (max-width: 560px) {
  .lookup-hit {
    grid-template-columns: 1fr;
    gap: var(--space-1);
  }
  .lookup-hit.lookup-miss { grid-template-columns: 1fr; }
  .lookup-reroot { justify-self: start; }
}

#compute-status {
  margin-top: var(--space-2);
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  color: var(--muted);
  word-break: break-word;
}

/* -- 10. Board (leaderboard) controls ----------------------- */
.board-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin: var(--space-4) 0;
}
@media (min-width: 640px) {
  .board-controls { grid-template-columns: 2fr 2fr 1fr; align-items: end; }
}
.board-controls label {
  display: grid;
  gap: var(--space-1);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* -- 11. About page ----------------------------------------- */
/* No max-width on About prose; fill the panel. */
#tab-about ul { padding-inline-start: 1.2em; }
#tab-about li { margin-bottom: var(--space-2); color: var(--text-soft); }

.about-buscemi {
  float: right;
  margin: 0 0 var(--space-3) var(--space-4);
  width: 140px;
  max-width: 30%;
}
/* Clear the portrait's float at each h3 boundary so formula cards, lists,
   and other block content below don't get squeezed against it. */
#tab-about h3 { clear: both; }
.about-buscemi img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  background: var(--surface-3);
  aspect-ratio: 3 / 4;
  object-fit: cover;
}
.about-buscemi figcaption {
  font-size: var(--fs-xs);
  color: var(--muted);
  text-align: center;
  margin-top: var(--space-2);
  font-style: italic;
}
@media (max-width: 640px) {
  .about-buscemi { float: none; margin: 0 auto var(--space-4); width: 55%; }
}

.formula {
  display: block;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin: var(--space-2) 0 var(--space-4) 0;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-soft);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: nowrap;
}

/* Preamble to the formulas section. */
/* Formula pair: prose at full card width on top, math centred, plaintext
   centred beneath. Stacked, single column, at every viewport. */
.formula-pair {
  margin: var(--space-3) 0 var(--space-4) 0;
  padding: var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
  display: grid;
  gap: var(--space-3);
  min-width: 0;
  overflow: hidden;
}
.formula-intro {
  margin: 0;
  font-size: var(--fs-sm);
  line-height: 1.6;
  color: var(--text-soft);
}
.formula-intro strong { color: var(--text); font-weight: 600; }
.formula-intro em     { font-style: italic; }
.formula-math {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  font-size: 1em;
  color: var(--text);
}
.formula-math .katex-display { margin: 0; }
.formula-math .katex { font-size: 1.05em; }

.formula-pair figcaption {
  padding-top: var(--space-3);
  border-top: 1px dashed var(--border);
  color: var(--muted);
  font-size: var(--fs-xs);
  text-align: center;
  overflow-x: auto;
  overflow-y: hidden;
}
.formula-pair figcaption code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
  white-space: nowrap;
}

/* -- 12. Footer --------------------------------------------- */
.site-footer {
  padding: var(--space-5) 0 var(--space-6);
  margin-top: var(--space-8);
  color: var(--muted);
  font-size: var(--fs-xs);
  text-align: center;
  border-top: 1px solid var(--border-soft);
}

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

/* -- 14. Utility -------------------------------------------- */
[hidden] { display: none !important; }
.flex-row { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
