/* MoonAnalytics viewer. Tokens first; dark follows the system unless Settings picks a theme (data-theme). */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --sidebar: #f8f8f7;
  --surface: #ffffff;
  --surface-2: #f5f5f3;
  --surface-3: #ebebe8;
  --ink: #1b1b1a;
  --ink-2: #545350;
  --muted: #8b8a85;
  --grid: #ecebe7;
  --axis: #cfcec7;
  --hairline: rgba(20, 20, 18, 0.08);
  --hairline-strong: rgba(20, 20, 18, 0.15);
  --accent: #5e6ad2;
  --accent-soft: rgba(94, 106, 210, 0.11);
  --accent-ink: #ffffff;
  --s-1: #2a78d6; --s-2: #eb6834; --s-3: #1baf7a; --s-4: #eda100;
  --s-5: #e87ba4; --s-6: #008300; --s-7: #6250d6; --s-8: #e34948;
  --good: #1a9a4b; --warning: #c98500; --critical: #d03b3b;
  --heat-1: #ffe08a; --heat-2: #f5a54a; --heat-3: #e0482b; --heat-4: #8b1022;
  --level-low: #b9bfc8; --level-high: #e8ebef; --level-edge: #7c8592; --level-hub: #9fc7a8; --level-pit: #d6a3a3; --level-wall: #8a93a0; --level-door: #d98a00;
  --entity-object: #9aa0a8;
  --stage: radial-gradient(120% 90% at 50% 0%, #fbfbfa 0%, #ebebe7 100%);
  --popover-shadow: 0 16px 48px rgba(0, 0, 0, 0.16), 0 2px 6px rgba(0, 0, 0, 0.06);
  --skeleton: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  --radius: 8px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b8a85' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #161618; --sidebar: #111113; --surface: #1a1a1d; --surface-2: #222226; --surface-3: #2d2d32;
    --ink: #ececea; --ink-2: #b2b1ac; --muted: #7d7c78; --grid: #26262a; --axis: #3a3a3f;
    --hairline: rgba(255, 255, 255, 0.07); --hairline-strong: rgba(255, 255, 255, 0.13);
    --accent: #8189e6; --accent-soft: rgba(129, 137, 230, 0.16); --accent-ink: #101014;
    --s-1: #4d9bff; --s-2: #ff8a4c; --s-3: #2fd38f; --s-4: #ffc23d;
    --s-5: #ff7fb2; --s-6: #6fd36f; --s-7: #a796ff; --s-8: #ff5a5f;
    --good: #3fcf6f; --warning: #ffc23d; --critical: #ff6b6b;
    --heat-1: #6a2a6e; --heat-2: #c43c4e; --heat-3: #f28b3b; --heat-4: #ffe680;
    --level-low: #23272e; --level-high: #3f4652; --level-edge: #6d7684; --level-hub: #3c5a47; --level-pit: #5e3a3c; --level-wall: #9fb0c6; --level-door: #ffb547;
    --entity-object: #7d838c;
    --stage: radial-gradient(120% 90% at 50% 0%, #1d1e21 0%, #0c0c0d 100%);
    --popover-shadow: 0 20px 60px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161618; --sidebar: #111113; --surface: #1a1a1d; --surface-2: #222226; --surface-3: #2d2d32;
  --ink: #ececea; --ink-2: #b2b1ac; --muted: #7d7c78; --grid: #26262a; --axis: #3a3a3f;
  --hairline: rgba(255, 255, 255, 0.07); --hairline-strong: rgba(255, 255, 255, 0.13);
  --accent: #8189e6; --accent-soft: rgba(129, 137, 230, 0.16); --accent-ink: #101014;
  --s-1: #4d9bff; --s-2: #ff8a4c; --s-3: #2fd38f; --s-4: #ffc23d;
  --s-5: #ff7fb2; --s-6: #6fd36f; --s-7: #a796ff; --s-8: #ff5a5f;
  --good: #3fcf6f; --warning: #ffc23d; --critical: #ff6b6b;
  --heat-1: #6a2a6e; --heat-2: #c43c4e; --heat-3: #f28b3b; --heat-4: #ffe680;
  --level-low: #23272e; --level-high: #3f4652; --level-edge: #6d7684; --level-hub: #3c5a47; --level-pit: #5e3a3c; --level-wall: #9fb0c6; --level-door: #ffb547;
  --entity-object: #7d838c;
  --stage: radial-gradient(120% 90% at 50% 0%, #1d1e21 0%, #0c0c0d 100%);
  --popover-shadow: 0 20px 60px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 400 13.5px/1.5 var(--font); -webkit-font-smoothing: antialiased; min-height: 100vh; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 14px; letter-spacing: -0.005em; }
h3 { font-size: 13px; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
b, strong { font-weight: 600; }
code, .mono { font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
kbd { font: 11px var(--font); color: var(--muted); border: 1px solid var(--hairline-strong); border-radius: 4px; padding: 0 5px; line-height: 17px; background: var(--surface); }
.note, .muted { color: var(--muted); font-size: 12.5px; }
.icon { flex: none; display: block; }
[hidden] { display: none !important; }
.spacer { flex: 1 1 auto; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 14px 10px; background: var(--sidebar);
  border-right: 1px solid var(--hairline); overflow: auto; z-index: 30; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 12px; font-weight: 600; font-size: 14px; }
.brand-mark { width: 20px; height: 20px; border-radius: 6px; flex: none; background: conic-gradient(from 210deg, var(--s-1), var(--s-7), var(--s-8), var(--s-4), var(--s-1)); }
.nav-search { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px 0 10px; margin-bottom: 8px; border-radius: 7px; border: 1px solid var(--hairline-strong);
  background: var(--surface); color: var(--muted); font: 13px var(--font); cursor: pointer; text-align: left; }
.nav-search span { flex: 1; }
.nav-search:hover { color: var(--ink-2); border-color: var(--axis); }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-link { display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 10px; border-radius: 6px; color: var(--ink-2); font-size: 13.5px; }
.nav-link .icon { color: var(--muted); }
.nav-link:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.nav-link.active { background: var(--surface-3); color: var(--ink); font-weight: 600; }
.nav-link.active .icon { color: var(--ink); }
.nav-link span:first-of-type { flex: 1; }
.nav-count { font-size: 11.5px; color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.nav-group { color: var(--muted); font-size: 11.5px; font-weight: 600; padding: 18px 10px 6px; }
.sidebar-foot { margin-top: auto; padding-top: 12px; }
.editor-badge { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 7px; font-size: 12px; color: var(--good);
  background: color-mix(in srgb, var(--good) 9%, transparent); border: 1px solid color-mix(in srgb, var(--good) 28%, transparent); }
.main-col { min-width: 0; display: flex; flex-direction: column; }
.main { padding: 0 32px 72px; min-width: 0; }
.mobile-bar { display: none; }
.scrim { display: none; }

/* ---------- page header ---------- */
.page-header { position: sticky; top: 0; z-index: 20; margin: 0 -32px; padding: 14px 32px 0; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--hairline); }
.page-header:not(:has(.tabs)) { padding-bottom: 14px; }
.header-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; min-height: 34px; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--ink); text-decoration: none; }
.crumb-here { color: var(--ink); font-weight: 600; }
.crumb-sep { color: var(--axis); }
.tabs { display: flex; gap: 2px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { display: inline-flex; align-items: center; gap: 7px; padding: 8px 10px 10px; color: var(--muted); font-size: 13.5px; border-bottom: 2px solid transparent;
  margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--ink); text-decoration: none; }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
.page-body { display: grid; gap: 16px; padding-top: 20px; min-width: 0; }
.scope-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.scope-picker { display: flex; align-items: center; gap: 8px; }
.scope-select { font-weight: 600; min-width: 150px; }
.compare-control { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); padding-left: 10px; border-left: 1px solid var(--hairline-strong); }
.compare-control.on { color: var(--accent); }
.compare-control.on select { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background-color: var(--accent-soft); color: var(--ink); }
.scope-line { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-top: 8px; color: var(--ink-2); font-size: 12.5px; }
.scope-line .icon { color: var(--muted); }
.scope-filters { display: inline-flex; align-items: center; gap: 10px; white-space: nowrap; }
.run-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; margin-top: 6px; color: var(--ink-2); font-size: 13px; }
.run-meta .sep { color: var(--axis); }

/* ---------- controls ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.toolbar.center { justify-content: center; }
.tab-toolbar { justify-content: flex-start; }
.card-toolbar { margin-bottom: 10px; }
.label { color: var(--muted); font-size: 12.5px; }
.button, .ghost { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 32px; padding: 0 12px; border-radius: 7px;
  font: 600 13px var(--font); cursor: pointer; white-space: nowrap; text-decoration: none; }
.button { border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); }
.button:hover { filter: brightness(1.08); text-decoration: none; }
.ghost { border: 1px solid var(--hairline-strong); background: var(--surface); color: var(--ink-2); font-weight: 400; }
.ghost:hover { color: var(--ink); background: var(--surface-2); text-decoration: none; }
.button.small, .ghost.small { height: 26px; padding: 0 9px; font-size: 12.5px; gap: 5px; }
.icon-only { width: 32px; padding: 0; }
.ghost.small.icon-only { width: 28px; }
.button:disabled, .ghost:disabled { opacity: 0.45; cursor: default; filter: none; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 6px; border: 0; background: transparent;
  color: var(--muted); cursor: pointer; padding: 0; }
.icon-button:hover { color: var(--ink); background: var(--surface-3); }
.engine-actions { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible, summary:focus-visible, .hit:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
select, input[type="text"], input[type="url"], input[type="password"], input[type="date"], input[type="search"], input[type="number"] {
  height: 32px; border-radius: 7px; border: 1px solid var(--hairline-strong); background-color: var(--surface); color: var(--ink); font: 13px var(--font); padding: 0 10px; max-width: 100%; }
select { appearance: none; -webkit-appearance: none; padding-right: 28px; background-image: var(--chevron); background-repeat: no-repeat; background-position: right 8px center; background-size: 14px; cursor: pointer; }
select.small, input.small { height: 28px; font-size: 12.5px; }
select:hover, input:hover { border-color: var(--axis); }
select.bare { border: 0; background-color: transparent; height: 30px; padding-left: 4px; color: var(--ink-2); }
input[type="range"] { accent-color: var(--accent); }
label.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
label.check input { accent-color: var(--accent); margin: 0; width: 14px; height: 14px; }
label.field { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
label.field.grow { flex: 1 1 260px; }
label.field.grow select { flex: 1; min-width: 0; }
.segmented { display: inline-flex; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--hairline); padding: 2px; gap: 2px; }
.segmented button { height: 26px; padding: 0 11px; border: 0; border-radius: 6px; background: transparent; color: var(--ink-2); font: 13px var(--font); cursor: pointer; white-space: nowrap; }
.segmented button:hover { color: var(--ink); }
.segmented button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--hairline-strong); }
.segmented.compact button { height: 24px; padding: 0 9px; font-size: 12.5px; }
.split { gap: 8px; }
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.search-field { display: inline-flex; align-items: center; gap: 2px; height: 32px; padding-left: 10px; border: 1px solid var(--hairline-strong); border-radius: 7px; background: var(--surface); color: var(--muted); }
.search-field input { border: 0; height: 30px; background: transparent; min-width: 160px; }
.search-field input:focus-visible { outline: none; }
.search-field:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.list-meta { display: flex; align-items: center; gap: 10px; }
.load-more { margin-top: 4px; }

/* ---------- cards, sections ---------- */
.card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card.bar { padding: 10px 14px; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 6px 16px; margin-bottom: 12px; }
.card-head.compact { align-items: center; margin-bottom: 8px; }
.card-titles { display: grid; gap: 2px; min-width: 0; max-width: 80ch; }
.card-actions { display: flex; gap: 8px; align-items: center; }
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 10px 16px; padding-top: 12px; border-top: 1px solid var(--hairline); }
.sample-section { display: grid; gap: 16px; min-width: 0; }
.part { display: grid; gap: 16px; min-width: 0; }
.subsection { font-size: 15px; margin-top: 8px; }
.chart-title { margin-bottom: 8px; }
.legend-note { margin-top: 10px; }
.warning-note { display: flex; align-items: center; gap: 8px; color: var(--warning); }
/* auto-fill, not auto-fit: charts measure their card while it is still the only one in the grid. */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 16px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--ink-2); font-size: 12.5px; margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; display: inline-block; }
.key { width: 14px; height: 3px; border-radius: 2px; flex: none; display: inline-block; }
.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 600; color: var(--ink-2);
  background: var(--surface-2); border: 1px solid var(--hairline-strong); white-space: nowrap; }
.badge.critical { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, transparent); background: color-mix(in srgb, var(--critical) 9%, transparent); }
.badge.warning { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 40%, transparent); background: color-mix(in srgb, var(--warning) 9%, transparent); }
.badge.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); background: color-mix(in srgb, var(--good) 9%, transparent); }
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius); font-size: 13px; border: 1px solid var(--hairline-strong); }
.banner.problem { color: var(--critical); background: color-mix(in srgb, var(--critical) 7%, transparent); border-color: color-mix(in srgb, var(--critical) 30%, transparent); }
.banner.good { color: var(--good); background: color-mix(in srgb, var(--good) 7%, transparent); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.banner span { flex: 1; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty-state { display: grid; justify-items: center; gap: 8px; text-align: center; padding: 48px 20px; }
.empty-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); background: var(--surface-2); border: 1px solid var(--hairline); }
.empty-title { font-size: 15px; font-weight: 600; }
.empty-text { color: var(--ink-2); max-width: 58ch; }
.empty-state .toolbar { margin-top: 8px; }
details.disclosure { padding: 0; }
details.disclosure > summary { display: flex; align-items: center; gap: 8px; padding: 12px 16px; cursor: pointer; list-style: none; font-weight: 600; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary .icon { color: var(--muted); transition: transform 120ms; }
details.disclosure[open] > summary .icon { transform: rotate(90deg); }
details.disclosure > summary .note { font-weight: 400; }
details.disclosure > :not(summary) { margin: 0 16px 16px; }
details > summary.note { cursor: pointer; margin-top: 10px; }

/* ---------- skeletons ---------- */
.skeleton-wrap { display: grid; gap: 16px; }
.skeleton-card { display: grid; gap: 14px; }
.skeleton-line, .skeleton-block { border-radius: 6px; background: var(--skeleton); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; }
.skeleton-line { height: 12px; }
.skeleton-line.short { width: 32%; }
.skeleton-block { height: 140px; }
.skeleton-tile { display: grid; gap: 12px; }
.skeleton-tile .skeleton-line:not(.short) { height: 22px; width: 60%; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton-line, .skeleton-block { animation: none; } }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.tile .label { display: block; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; margin-top: 2px; }
.tile .sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--ink-2); font-size: 12px; min-height: 18px; }
.tile .sub .delta { margin-left: 0; min-width: 0; }

/* ---------- charts, tooltip ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; overflow: visible; }
.chart text { font-family: var(--font); }
.hit { cursor: default; }
.tooltip { position: fixed; z-index: 60; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--hairline-strong);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: var(--popover-shadow); max-width: 340px; display: none; }
.tooltip .t-title { color: var(--ink-2); margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; }
.tooltip .t-row b { font-variant-numeric: tabular-nums; }
.tooltip .t-row span { color: var(--ink-2); }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; max-height: 520px; border-radius: var(--radius); border: 1px solid var(--hairline); background: var(--surface); }
.table-wrap.tall { max-height: 720px; }
.table-wrap.fill { max-height: calc(100vh - 210px); min-height: 240px; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 12px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--grid); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 220px; }
th { color: var(--muted); font-size: 12px; font-weight: 600; position: sticky; top: 0; background: var(--surface-2); z-index: 1; border-bottom-color: var(--hairline-strong); }
th .icon { display: inline-block; vertical-align: -2px; margin-left: 4px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
tbody tr:hover td { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
tr.selected td { background: var(--accent-soft); }
tr.dim td { opacity: 0.45; }
td input[type="text"] { height: 28px; width: 160px; }
.more { color: var(--muted); font-size: 12px; padding: 6px 2px; }
.more:empty { display: none; }

/* The metric table: metric rows x scope (or day) columns, the metric column pinned while the columns scroll. */
.metric-wrap { max-height: 72vh; }
.metric-table td.metric, .metric-table th.metric { position: sticky; left: 0; background: var(--surface); min-width: 240px; max-width: 340px; white-space: normal; z-index: 1; }
.metric-table thead th.metric { background: var(--surface-2); z-index: 2; }
.metric-table td.metric { box-shadow: inset -1px 0 0 var(--grid); }
.metric-table td.indent { padding-left: 26px; color: var(--ink-2); }
.metric-table th.group { min-width: 140px; text-align: right; vertical-align: bottom; }
.metric-table .group-name { color: var(--ink); font-size: 13px; font-weight: 600; }
.metric-table .group-sub { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; margin-top: 3px; font-weight: 400; }
.metric-table td.baseline { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.metric-table tr.section td { background: var(--surface-2); font-weight: 600; padding-top: 9px; }
.metric-table tr.section .note { font-weight: 400; }
.metric-table tr.subhead td { color: var(--ink); font-weight: 600; padding-top: 10px; }
.metric-table tr.more-row td { padding-top: 2px; padding-bottom: 6px; }
.metric-table tr:hover td.metric, .metric-table tr.selected td.metric { background: var(--surface-2); }
.delta { display: inline-block; min-width: 52px; margin-left: 8px; padding: 0 5px; border-radius: 4px; font-size: 11.5px; font-weight: 600; text-align: right; }
.delta.flat { color: var(--muted); font-weight: 400; }
.share-bar { display: inline-block; width: 42px; height: 5px; margin-right: 8px; border-radius: 3px; background: var(--surface-3); vertical-align: middle; overflow: hidden; }
.share-bar > span { display: block; height: 100%; background: var(--accent); }

/* ---------- run page ---------- */
.moments { list-style: none; margin: 0; padding: 0; display: grid; }
.moment { display: grid; grid-template-columns: 64px 10px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--grid); }
.moment:last-child { border-bottom: 0; }
.moment:hover { background: var(--surface-2); }
.moment-t { color: var(--muted); text-align: right; }
.moment-title { font-weight: 600; }
.moment-what .muted { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.moment-actions { display: flex; gap: 6px; }

/* ---------- settings ---------- */
.form { display: grid; gap: 12px; max-width: 560px; }
.form-row { display: grid; grid-template-columns: 120px minmax(0, 1fr); align-items: center; gap: 12px; }
.form-label { color: var(--ink-2); font-size: 13px; }

/* ---------- toast, drop, palette ---------- */
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 70; display: flex; align-items: flex-start; gap: 10px; max-width: min(460px, calc(100vw - 40px));
  padding: 10px 10px 10px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--hairline-strong); box-shadow: var(--popover-shadow); font-size: 13px; }
.toast > .icon { margin-top: 2px; color: var(--muted); }
.toast.problem > .icon { color: var(--critical); }
.toast-text { flex: 1; color: var(--ink); overflow-wrap: anywhere; }
.drop-overlay { position: fixed; inset: 0; z-index: 80; display: none; align-items: center; justify-content: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); border: 2px dashed var(--accent); font-size: 17px; font-weight: 600; }
body.dragging .drop-overlay { display: flex; }
dialog.palette { width: min(620px, calc(100vw - 32px)); max-height: min(560px, calc(100vh - 120px)); margin: 12vh auto auto; padding: 0; border: 1px solid var(--hairline-strong);
  border-radius: 12px; background: var(--surface); color: var(--ink); box-shadow: var(--popover-shadow); overflow: hidden; }
dialog.palette[open] { display: flex; flex-direction: column; }
dialog.palette::backdrop { background: rgba(0, 0, 0, 0.32); }
.palette-search { display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--hairline); color: var(--muted); }
.palette-input { flex: 1; border: 0 !important; height: 50px !important; font-size: 15px !important; background: transparent !important; padding: 0 !important; }
.palette-input:focus-visible { outline: none; }
.palette-list { overflow: auto; padding: 6px; flex: 1; }
.palette-group { color: var(--muted); font-size: 11.5px; font-weight: 600; padding: 10px 10px 4px; }
.palette-item { display: flex; align-items: center; gap: 10px; padding: 0 10px; height: 36px; border-radius: 7px; cursor: pointer; color: var(--ink-2); }
.palette-item.on { background: var(--surface-2); color: var(--ink); }
.palette-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-hint { color: var(--muted); font-size: 12px; white-space: nowrap; }
.palette-empty { padding: 28px; text-align: center; color: var(--muted); }
.palette-foot { display: flex; gap: 16px; padding: 8px 14px; border-top: 1px solid var(--hairline); color: var(--muted); font-size: 12px; }
.palette-foot kbd { margin-right: 3px; }

/* ---------- 3D stage (Replay, Map) ---------- */
.stage { position: relative; height: min(70vh, 780px); min-height: 400px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--hairline); background: var(--stage); }
.stage canvas.gl { display: block; width: 100%; height: 100%; }
.stage .labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.stage .hud { position: absolute; left: 12px; top: 12px; font-size: 12.5px; color: var(--ink-2); pointer-events: none; }
.stage .hud:empty { display: none; }
.stage .overlay { position: absolute; inset: 0; pointer-events: none; }
.stage .panel { position: absolute; pointer-events: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 84%, transparent); backdrop-filter: blur(10px); border: 1px solid var(--hairline-strong); }
.stage .panel.top-right { top: 12px; right: 12px; min-width: 230px; }
.stage .panel.bottom-left { left: 12px; bottom: 12px; flex-direction: row; flex-wrap: wrap; gap: 6px 14px; padding: 7px 11px; font-size: 12px; color: var(--ink-2); align-items: center; }
.stage .panel-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stage .panel-label { font-size: 12px; color: var(--muted); min-width: 42px; }
.stage .panel input[type="range"] { flex: 1; min-width: 90px; }
.stage .slice-value { color: var(--ink-2); min-width: 34px; text-align: right; }
.stage .pill { position: absolute; left: 0; top: 0; display: inline-flex; align-items: center; gap: 5px; font-size: 11px; line-height: 1; padding: 4px 7px 4px 6px; border-radius: 999px;
  white-space: nowrap; background: rgba(12, 12, 14, 0.78); color: #f1f1ef; border: 1px solid rgba(255, 255, 255, 0.12); will-change: transform; }
:root[data-theme="light"] .stage .pill { background: rgba(255, 255, 255, 0.92); color: #111; border-color: rgba(0, 0, 0, 0.12); }
.stage .pill .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.stage .pill.player { font-weight: 600; }
.stage .pill.target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); font-weight: 600; }
.stage .pill.dead { opacity: 0.55; text-decoration: line-through; }
.stage .pill.loot { font-size: 10.5px; padding: 3px 6px; }
.stage .pill.event { background: rgba(12, 12, 14, 0.66); font-size: 10.5px; padding: 3px 7px 3px 6px; }
:root[data-theme="light"] .stage .pill.event { background: rgba(255, 255, 255, 0.9); }
.stage .fly-hint { position: absolute; left: 12px; top: 12px; font-size: 12px; color: var(--ink-2); padding: 5px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 84%, transparent); border: 1px solid var(--hairline-strong); pointer-events: none; display: none; }
.stage .fly-hint.on { display: block; }
.kind-toggle { display: inline-flex; align-items: center; gap: 6px; }
.kind-toggle .glyph { display: inline-block; width: 10px; height: 10px; }
.kind-toggle .glyph.player { border-radius: 5px 5px 3px 3px; background: var(--s-1); }
.kind-toggle .glyph.enemy { transform: rotate(45deg) scale(0.8); background: var(--s-8); }
.kind-toggle .glyph.event { width: 3px; height: 12px; border-radius: 2px; background: var(--s-4); }
.kind-toggle .glyph.mask { border-radius: 50%; background: transparent; border: 3px solid var(--s-2); width: 11px; height: 11px; }
.kind-toggle .glyph.pickup { transform: rotate(45deg) scale(0.7); background: var(--s-7); border-radius: 2px; }
.kind-toggle .glyph.door { width: 10px; height: 9px; border: 2px solid var(--level-door); border-bottom: 0; background: transparent; border-radius: 2px 2px 0 0; }
.ramp { display: inline-block; width: 120px; height: 8px; border-radius: 4px; vertical-align: middle; background: linear-gradient(90deg, var(--heat-1), var(--heat-2), var(--heat-3), var(--heat-4)); }
.heat-legend .ramp { width: 140px; }

/* ---------- replay ---------- */
.replay { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; }
.replay .side { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 16px; height: min(70vh, 780px); min-height: 400px; }
.replay .side .card { display: flex; flex-direction: column; min-height: 0; padding: 12px 14px; }
.replay .side h3 { margin-bottom: 8px; }
.replay .side .scroll { overflow: auto; min-height: 0; flex: 1; }
.target-card { max-height: 320px; }
.target-name { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.target-name b { font-size: 14px; }
.target-name .mono { margin-left: auto; font-size: 11px; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 12.5px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.transport { padding: 10px 14px 6px; }
.transport .toolbar { margin-bottom: 6px; }
.transport .play { min-width: 44px; justify-content: center; }
.time-readout { font-size: 13px; color: var(--ink); min-width: 120px; }
.ctx-readout { font-size: 12.5px; }
.timeline { position: relative; width: 100%; height: 64px; cursor: pointer; touch-action: none; }
.timeline canvas { width: 100%; height: 100%; display: block; }
.timeline-cursor { position: absolute; left: 0; top: 0; bottom: 14px; width: 2px; background: var(--ink); pointer-events: none; border-radius: 1px; box-shadow: 0 0 0 1px var(--surface); }
.event-log { font-size: 12.5px; }
.event-log .log-row { padding: 4px 6px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: flex-start; }
.event-log .log-row .swatch { margin-top: 5px; }
.event-log .log-row:hover { background: var(--surface-2); }
.event-log .log-row.future { opacity: 0.38; }
.event-log .log-row.current { background: var(--accent-soft); }
.event-log .t { color: var(--muted); font-family: var(--mono); font-size: 11px; flex: none; width: 46px; text-align: right; padding-top: 1px; }
.event-log .what { min-width: 0; }
.event-log .what b { font-weight: 600; }
.event-log .props { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- enemy filter ---------- */
.enemy-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--hairline); }
.card.bar > .enemy-filter:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.enemy-filter .panel-label { font-size: 12.5px; color: var(--muted); }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.chip { height: 26px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--hairline-strong); background: transparent; color: var(--muted); font: 12.5px var(--font); cursor: pointer; text-decoration: line-through; }
.chip.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--ink); text-decoration: none; }
.enemy-filter details.types { position: relative; }
.enemy-filter details.types summary { cursor: pointer; font-size: 12.5px; color: var(--ink-2); list-style: none; padding: 3px 10px; border-radius: 7px; border: 1px solid var(--hairline-strong); }
.enemy-filter details.types summary::-webkit-details-marker { display: none; }
.enemy-filter details.types[open] summary { background: var(--surface-2); }
.enemy-filter details.types > :not(summary) { position: absolute; z-index: 10; }
.enemy-filter .type-list { top: 32px; left: 0; display: grid; gap: 4px; min-width: 220px; max-height: 320px; overflow: auto; padding: 10px 12px 44px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--hairline-strong); box-shadow: var(--popover-shadow); }
.enemy-filter details.types > button { top: auto; left: 12px; margin-top: -38px; }

@media (prefers-reduced-motion: no-preference) {
  .button, .ghost, .segmented button, .nav-link, .tab, .icon-button { transition: background-color 120ms, color 120ms, border-color 120ms, filter 120ms; }
}

/* ---------- narrow windows: the sidebar slides in ---------- */
/* Crashes */
.crash-cell { display: grid; gap: 2px; min-width: 260px; }
.crash-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.crash-title a { color: var(--ink); }
.crash-reason { font-size: 12px; overflow-wrap: anywhere; }
.build-chips { display: inline-flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.build-chip { display: inline-flex; gap: 4px; align-items: center; height: 20px; padding: 0 7px; border-radius: 999px; font-size: 11.5px;
  background: var(--surface-2); border: 1px solid var(--hairline); font-variant-numeric: tabular-nums; }
.build-chip b { font-weight: 600; color: var(--ink-2); }
.crash-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.crash-main, .crash-side { display: grid; gap: 16px; min-width: 0; }
.crash-error, .crash-trail { margin: 0; padding: 10px 12px; border-radius: 6px; background: var(--surface-2); font-family: var(--mono); font-size: 12px;
  white-space: pre-wrap; overflow-wrap: anywhere; }
.crash-error { color: var(--critical); }
.stack { font-family: var(--mono); font-size: 12px; border-radius: 6px; background: var(--surface-2); padding: 6px 0; overflow-x: auto; }
.stack .frame { padding: 2px 12px; white-space: pre; color: var(--ink-2); }
.stack .frame.ours { color: var(--ink); font-weight: 600; background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.stack .frame.plumbing { color: var(--muted); opacity: 0.7; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.log-view { max-height: 520px; overflow: auto; margin-top: 10px; border-radius: 6px; background: var(--surface-2); padding: 6px 0;
  font-family: var(--mono); font-size: 12px; }
.log-line { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 10px; padding: 1px 12px 1px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.log-line.error { color: var(--critical); background: color-mix(in srgb, var(--critical) 8%, transparent); }
.log-line.warning { color: var(--warning); }
.log-no { text-align: right; color: var(--muted); user-select: none; }
.log-view mark { background: color-mix(in srgb, var(--warning) 45%, transparent); color: inherit; border-radius: 2px; }

@media (max-width: 900px) {
  .crash-grid { grid-template-columns: minmax(0, 1fr); }
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 264px; transform: translateX(-100%); transition: transform 180ms ease; box-shadow: none; }
  body.nav-open .sidebar { transform: none; box-shadow: var(--popover-shadow); }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, 0.3); }
  .mobile-bar { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 10px; border-bottom: 1px solid var(--hairline); background: var(--sidebar); position: sticky; top: 0; z-index: 22; }
  .mobile-title { flex: 1; font-weight: 600; }
  .main { padding: 0 16px 56px; }
  .page-header { margin: 0 -16px; padding: 12px 16px 0; position: static; }
  .metric-table td.metric, .metric-table th.metric { min-width: 150px; }
  .metric-table th.group { min-width: 110px; }
  .page-header:not(:has(.tabs)) { padding-bottom: 12px; }
  .compare-control { border-left: 0; padding-left: 0; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .replay { grid-template-columns: minmax(0, 1fr); }
  .replay .side { height: auto; }
  .stage .panel.top-right { min-width: 0; }
  .moment { grid-template-columns: 52px 10px minmax(0, 1fr); }
  .moment-actions { grid-column: 3; }
  .form-row { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .table-wrap.fill { max-height: none; }
  .search-field input { min-width: 0; width: 120px; }
}
