:root {
  --bg: #f6f7fb;
  --bg-elevated: #eef1f7;
  --surface: #ffffff;
  --surface-hover: #f1f3f5;
  --input-bg: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --accent-glow: rgba(37, 99, 235, 0.18);
  --intrinsic-color: #0d7377;
  --intrinsic-bg: #e0f2f1;
  --instruction-color: #92400e;
  --instruction-bg: #fef3c7;
  --code-bg: #f1f5f9;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 2px 8px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --font-mono: "Iosevka Web", "JetBrains Mono", "SF Mono", "Cascadia Code", monospace;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --bg-elevated: #111a2e;
  --surface: #131c30;
  --surface-hover: #1e293b;
  --input-bg: #0f1830;
  --text: #e2e8f0;
  --text-secondary: #cbd5e1;
  --text-muted: #7b8aa5;
  --border: #263349;
  --border-strong: #37465f;
  --accent: #60a5fa;
  --accent-soft: #1b2b4a;
  --accent-glow: rgba(96, 165, 250, 0.25);
  --intrinsic-color: #5eead4;
  --intrinsic-bg: #134e4a;
  --instruction-color: #fbbf24;
  --instruction-bg: #78350f;
  --code-bg: #172238;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220;
    --bg-elevated: #111a2e;
    --surface: #131c30;
    --surface-hover: #1e293b;
    --input-bg: #0f1830;
    --text: #e2e8f0;
    --text-secondary: #cbd5e1;
    --text-muted: #7b8aa5;
    --border: #263349;
    --border-strong: #37465f;
    --accent: #60a5fa;
    --accent-soft: #1b2b4a;
    --accent-glow: rgba(96, 165, 250, 0.25);
    --intrinsic-color: #5eead4;
    --intrinsic-bg: #134e4a;
    --instruction-color: #fbbf24;
    --instruction-bg: #78350f;
    --code-bg: #172238;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  /* One column that fills the window; the bars above .layout take what
     they need and .layout gets the rest, so no offset can go stale. */
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-elevated) 100%);
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 2;
}
.header-left { display: flex; align-items: center; gap: 0.75rem; }
.header-right { display: flex; align-items: center; gap: 1rem; }
.logo {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}
.meta {
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: ui-monospace, monospace;
}
.meta.stale { border-color: var(--accent); color: var(--accent); }
.header-notice { color: var(--text-secondary); font-size: 0.8rem; }
.kind-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 16px;
  font-size: 0.85rem;
  /* The chips and the category select can wrap below ~1100 px instead of
     pushing the page horizontally. */
  flex-wrap: wrap;
}
.kind-label { color: var(--text-muted); margin-right: 4px; }
.cat-filter {
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1px 4px;
  cursor: pointer;
  /* A long option text must never size the select past its bar. */
  max-width: 100%;
}
.chip-count {
  color: var(--text-muted);
  margin-left: 6px;
  font-size: 0.75em;
}
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.35rem;
  display: flex;
  align-items: center;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

/* Search bar */
.search-bar {
  display: flex;
  gap: 0.55rem;
  padding: 0.7rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  align-items: center;
}
.search-wrap {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
  transition: color 0.15s ease;
}
.search-wrap input {
  width: 100%;
  height: 2.4rem;
  padding: 0 3rem 0 2.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--input-bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.92rem;
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.search-wrap input::placeholder { color: var(--text-muted); }
.search-wrap input:hover { border-color: var(--border-strong); }
.search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--surface);
}
.search-wrap:focus-within .search-icon { color: var(--accent); }
.search-wrap input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-hint {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 4px;
  padding: 0.12rem 0.4rem;
  pointer-events: none;
  box-shadow: 0 1px 0 var(--border);
}
.search-wrap:focus-within .search-hint { display: none; }

/* ISA toggle button */
.isa-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 2.4rem;
  padding: 0 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--input-bg);
  color: var(--text-secondary);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.isa-toggle-btn:hover {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.isa-toggle-btn[aria-expanded="true"],
.isa-toggle-btn.open {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ISA filter panel */
.isa-panel {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.isa-panel.hidden { display: none; }
.isa-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.isa-family-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  min-width: 0;
  flex: 1 1 auto;
}
.isa-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex: 0 0 auto;
}
.preset-btn {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  font: inherit;
  font-size: 0.75rem;
  line-height: 1.3;
}
.preset-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.preset-btn:hover { background: var(--surface-hover); color: var(--text); }
.isa-groups {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.isa-group {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  column-gap: 0.5rem;
  row-gap: 0.2rem;
}
/* .isa-group's display beats the UA rule for [hidden]. */
#sm-group[hidden] { display: none; }
.isa-group-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  cursor: pointer;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  white-space: nowrap;
}
.isa-group-label:hover { color: var(--text-secondary); }
.isa-group-label.family-active { color: var(--accent); }
.isa-group-items {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  min-width: 0;
}
.isa-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.75rem;
  cursor: pointer;
  user-select: none;
  color: var(--text-secondary);
  background: var(--bg);
}
.isa-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.isa-chip:hover { border-color: var(--accent); }
.isa-chip input { display: none; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* Results panel */
.results-panel {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.results-header {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.results-list {
  overflow-y: auto;
  flex: 1;
  outline: none;
}
.sm-hidden-note {
  padding: 0.6rem 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.result {
  padding: 0.35rem 0.75rem;
  border-left: 3px solid transparent;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  /* Fixed height enables O(1) viewport virtualisation (see app.js).
     Must match ROW_HEIGHT_PX there. */
  box-sizing: border-box;
  height: 68px;
  overflow: hidden;
  contain: layout paint style;
  content-visibility: auto;
  contain-intrinsic-size: 68px;
}
.result-summary {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  overflow: hidden;
}
.results-virtual {
  position: relative;
  width: 100%;
}
.results-virtual > .result {
  position: absolute;
  left: 0;
  right: 0;
}
.result:hover { background: var(--surface-hover); }
.result.active {
  border-left-color: var(--accent);
  background: var(--accent-soft);
}
.result.focused {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.result-kind {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
}
.result-kind.intrinsic { color: var(--intrinsic-color); background: var(--intrinsic-bg); }
.result-kind.instruction { color: var(--instruction-color); background: var(--instruction-bg); }
.result-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.3rem;
}
.result-isa {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #7c3aed;
  background: #ede9fe;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 50%;
  text-align: right;
}
[data-theme="dark"] .result-isa,
:root:not([data-theme="light"]) .result-isa {
  color: #c4b5fd;
  background: #2e1065;
}
.result-title {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin-top: 0.2rem;
  word-break: break-word;
  line-height: 1.3;
}
.result-meta {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.15rem;
}
.result-perf {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  font-weight: 600;
}
.result.intrinsic-kind .result-title { color: var(--intrinsic-color); }
.result.instruction-kind .result-title { color: var(--instruction-color); }
.result-summary {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-style: italic;
  margin-top: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Detail panel */
.detail-panel {
  overflow-y: auto;
  padding: 1rem;
  outline: none;
}
.detail-empty {
  color: var(--text-muted);
  padding: 2rem 0;
  text-align: center;
}

/* Detail header */
.detail-head {
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}
.detail-head h2 {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  line-height: 1.2;
  margin-top: 0.3rem;
  word-break: break-word;
}
.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.15rem 0.35rem;
  vertical-align: middle;
  opacity: 0;
  transition: opacity 0.15s;
}
.detail-head:hover .copy-btn,
.copy-btn:focus { opacity: 1; }
.copy-btn:hover { background: var(--surface-hover); color: var(--text); }
.detail-sub {
  font-family: var(--font-mono);
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 0.25rem;
  word-break: break-word;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
}
.chip {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  background: var(--code-bg);
  color: var(--text-secondary);
}

/* Sections */
.section { margin-top: 0.75rem; }
.section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.kv {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 0.3rem 0.75rem;
  font-size: 0.85rem;
}
.kv dt { color: var(--text-muted); font-weight: 600; }
.kv dd { word-break: break-word; }
/* Long source URLs are link text; they must wrap inside a 390px viewport. */
a { word-break: break-word; }

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
th, td {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  color: var(--text-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--code-bg);
  font-weight: 600;
}
tr:last-child td { border-bottom: 0; }
td.mono { font-family: var(--font-mono); }
td.highlight { font-weight: 600; color: var(--accent); }

/* Measurement groups */
.meas-group { margin-bottom: 0.5rem; }
.meas-group summary {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.3rem 0;
}
.meas-group summary:hover { color: var(--text); }

/* Cross-reference links */
a.xref {
  color: var(--accent);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
a.xref:hover { text-decoration: underline; }

/* Generic links */
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay.hidden { display: none; }
.overlay-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  max-width: 400px;
  width: 90%;
}
.overlay-content h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}
.shortcuts-table {
  border: none;
  width: 100%;
  margin-bottom: 0.75rem;
}
.shortcuts-table td {
  border-bottom: none;
  padding: 0.25rem 0.5rem;
}
.shortcuts-table kbd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--code-bg);
}

/* Compact metadata chips */
.kv-compact {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.4rem;
  margin-bottom: 0.4rem;
}
.kv-chip {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.78rem;
  line-height: 1.3;
  max-width: 100%;
}
.kv-chip-k {
  background: var(--bg-elevated);
  color: var(--text-muted);
  padding: 0.15rem 0.4rem;
  border-right: 1px solid var(--border);
  font-weight: 500;
}
.kv-chip-v {
  background: var(--surface);
  color: var(--text);
  padding: 0.15rem 0.4rem;
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40ch;
}
.kv-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  font-size: 0.78rem;
  margin-top: 0.2rem;
}
.kv-link {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}
.kv-link:hover { border-bottom-style: solid; }

/* Description sections */
.desc-section { margin-bottom: 0.5rem; }
.desc-section summary {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.3rem 0;
}
.desc-section summary:hover { color: var(--text); }
.desc-body {
  font-size: 0.82rem;
  line-height: 1.6;
  padding: 0.5rem 0;
  white-space: pre-wrap;
}
.desc-code {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.5;
  padding: 0.5rem 0.75rem;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  white-space: pre;
}

/* Doc source groups: doc_sources blocks in stored order. */
.doc-group { margin-bottom: 0.9rem; }
.doc-group-head { font-size: 0.92rem; margin: 0 0 0.35rem; }
.doc-family {
  font-size: 0.68rem;
  font-weight: 400;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 0.35rem;
  margin-left: 0.45rem;
  vertical-align: middle;
}
.doc-sub { font-size: 0.86rem; margin: 0.5rem 0 0.25rem; }
.doc-p, .doc-list, .doc-deflist, .doc-math, .doc-note, .doc-table { margin: 0.35rem 0; }
.doc-p, .doc-list, .doc-deflist, .doc-math { font-size: 0.84rem; line-height: 1.6; }
/* Math keeps its readable text in the mono face: same fallback as the
   TUI, which has no 2D formulas. */
.doc-math { font-family: var(--font-mono); }
.doc-list { padding-left: 1.15rem; }
.doc-note {
  border-left: 3px solid var(--accent);
  padding: 0.25rem 0.55rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}
.doc-note-kind { font-weight: 600; }
.doc-note-warning { border-left-color: #d97706; }
.doc-note-seealso { border-left-color: #0d7377; }
.doc-deflist dt { font-weight: 600; margin-top: 0.3rem; }
.doc-deflist dd { margin: 0 0 0 1.15rem; }
/* Inline runs, code captions and highlighted code inside doc blocks. */
.doc-p code, .doc-list code, .doc-deflist code, .doc-note code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--code-bg);
  border-radius: 3px;
  padding: 0 0.1em;
}
.doc-link, .doc-fnlink { color: var(--accent); }
.doc-fnlink {
  font: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}
.doc-math-inline { font-family: var(--font-mono); font-size: 0.95em; }
.doc-code-caption { font-size: 0.78rem; color: var(--text-muted); margin: 0.35rem 0 0.15rem; }
.desc-code code, pre.sig code { font: inherit; background: none; padding: 0; }
pre.desc-code code.hljs, pre.sig code.hljs { display: block; background: transparent; }
.doc-list .doc-list { margin: 0.15rem 0; }
.doc-table { border-collapse: collapse; }
.doc-table th, .doc-table td {
  border: 1px solid var(--border);
  padding: 0.2rem 0.5rem;
  text-align: left;
  font-size: 0.82rem;
}

.results-panel.collapsed { display: none; }

/* Responsive */
@media (max-width: 768px) {
  .isa-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .isa-presets {
    justify-content: flex-start;
  }
  .isa-group {
    grid-template-columns: 1fr;
  }
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 300px 1fr;
  }
  .results-panel { border-right: none; border-bottom: 1px solid var(--border); }
  .kv { grid-template-columns: 1fr; gap: 0.15rem; }
}

/* ── Annotate tab ───────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0.25rem;
  margin-left: 0.5rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--border);
}
.tab-btn {
  appearance: none;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  padding: 0.2rem 0.7rem;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
}
.tab-btn:hover { background: var(--surface-hover); color: var(--text); }
/* The pill highlight reads the same body[data-tab] bit that shows the
 * view: aria-selected alone drifts from the view on paths that flip the
 * view bit directly (screenshot captures set body.dataset.tab). */
body:not([data-tab="annotate"]) #tab-search,
body[data-tab="annotate"] #tab-annotate {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--border);
}

body[data-tab="annotate"] .search-bar,
body[data-tab="annotate"] #isa-panel,
body[data-tab="annotate"] #kind-bar,
body[data-tab="annotate"] .layout { display: none !important; }
body:not([data-tab="annotate"]) #annotate-view { display: none; }

#annotate-view {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  flex: 1 1 auto;
  min-height: 400px;
}
.annotate-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
}
.annotate-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.annotate-toolbar select,
.annotate-toolbar button {
  font: inherit;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem 0.55rem;
  cursor: pointer;
}
.annotate-toolbar button:hover { background: var(--surface-hover); }
.annotate-toolbar button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.annotate-toolbar button.primary:hover { filter: brightness(1.08); }
.annotate-status {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 12px;
  font-family: var(--font-mono);
}
.annotate-panes {
  display: grid;
  grid-template-columns: var(--ann-split, 1fr) 6px var(--ann-split-r, 2fr);
  gap: 0;
  flex: 1;
  min-height: 0;
}
.ann-splitter {
  cursor: col-resize;
  background: transparent;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  margin: 0 0.25rem;
  transition: background 0.15s ease;
}
.ann-splitter:hover,
.ann-splitter.dragging { background: var(--accent-soft); }
body.ann-resizing { cursor: col-resize; user-select: none; }
#ann-input,
#ann-output,
.ann-input-hl {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.45;
  padding: 0.7rem 0.9rem;
  overflow: auto;
  white-space: pre;
  tab-size: 4;
}

.ann-input-wrap { position: relative; min-height: 0; }
.ann-input-wrap > .ann-input-hl,
.ann-input-wrap > #ann-input {
  position: absolute;
  inset: 0;
  margin: 0;
}
.ann-input-hl {
  pointer-events: none;
  z-index: 0;
}
#ann-input {
  z-index: 1;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  resize: none;
  outline: none;
}
/* Global readable text selection: browser default low-contrasts against
 * highlight.js themes, and the annotate input's `color: transparent`
 * otherwise makes selections literally invisible. Force a dedicated
 * selection palette that works in both light and dark themes. */
::selection {
  background: var(--accent);
  color: #fff;
  -webkit-text-fill-color: #fff;
  text-shadow: none;
}
[data-theme="light"] ::selection {
  background: #ffd54a;    /* warm yellow — high contrast on light bg */
  color: #1a1a2e;
  -webkit-text-fill-color: #1a1a2e;
}
/* The hidden syntax-highlight mirror sits above the textarea visually
 * but is pointer-events:none; ensure its copy of selected text also
 * paints with the selection palette, not its transparent textarea
 * override. */
.ann-input-hl ::selection {
  background: var(--accent);
  color: #fff;
  -webkit-text-fill-color: #fff;
}
[data-theme="light"] .ann-input-hl ::selection {
  background: #ffd54a;
  color: #1a1a2e;
  -webkit-text-fill-color: #1a1a2e;
}
#ann-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
#ann-output { margin: 0; }
#ann-output .hl-comment { color: var(--text-muted); }
#ann-output .hl-perf    { color: var(--accent); }
#ann-output .hl-unknown { color: var(--instruction-color); }
/* Let highlight.js colour tokens, but keep our background / padding. */
#ann-output .hljs { background: transparent; padding: 0; color: inherit; }

/* Annotate line hover: the annotated line highlights, the record
 * (form key, summary, per-core table) shows in the fixed popover. */
#ann-output .ann-line:hover { background: var(--accent-soft); }
#ann-hover-pop {
  position: fixed;
  z-index: 60;
  max-width: min(620px, calc(100vw - 16px));
  /* Absolute guard; showAnnHover caps at the free space on the side it
     opens, so a long table scrolls instead of leaving the viewport. */
  max-height: calc(100vh - 16px);
  overflow: auto;
  padding: 0.5rem 0.7rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 0.82rem;
}
#ann-hover-pop table { width: auto; min-width: 100%; }
.ann-hover-key { margin-bottom: 0.3rem; }
.ann-hover-sum { color: var(--text-secondary); margin-bottom: 0.4rem; }

@media (max-width: 900px) {
  .annotate-panes { grid-template-columns: 1fr; grid-auto-rows: 1fr; }
  .ann-splitter   { display: none; }
  #annotate-view  { height: auto; flex: none; }
  #ann-input      { min-height: 220px; }
  #ann-output     { min-height: 220px; }
}

/* C3: detail head + tabs */
.detail-head .copy-btn { opacity: 1; width: auto; height: 28px; padding: 0 .5rem; font-size: .72rem; margin-left: .3rem; }
pre.sig { font-family: var(--font-mono); font-size: .85rem; border: 1px solid var(--border); border-radius: var(--radius);
  padding: .5rem .7rem; margin: .5rem 0 0; white-space: pre-wrap; word-break: break-word; background: var(--bg-elevated); }
.perf-line { margin-top: .5rem; font-size: .85rem; color: var(--text-secondary); cursor: pointer; font-family: var(--font-mono); }
.perf-line:hover { color: var(--accent); }
.detail-head .kv-links { margin-top: .4rem; }
button.perf-line { background: none; border: none; padding: 0; text-align: left; }
.detail-tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); margin: .6rem 0; }
.detail-tabs-wrap { display: flex; align-items: center; flex-wrap: wrap; gap: .2rem .4rem;
  border-bottom: 1px solid var(--border); margin: .6rem 0; }
.detail-tabs-wrap .detail-tabs { border-bottom: none; margin: 0; min-width: 0; }
.detail-tabs button { background: none; border: none; border-bottom: 2px solid transparent; padding: .35rem .7rem;
  font: inherit; font-size: .82rem; cursor: pointer; color: var(--text-secondary); }
.detail-tabs button[aria-pressed="true"] { color: var(--text); border-bottom-color: var(--accent); }
.detail-tabs button[hidden] { display: none; }
.detail-tabs button:disabled { opacity: .4; cursor: not-allowed; text-decoration: line-through; }
.detail-tabs-wrap button.detail-all { margin-left: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.detail-hidden { display: none !important; }

/* Below 1100px the detail panel is narrower than a wide perf table; the
   table scrolls inside its own container (page stays without horizontal
   scroll). Mirrors the 768px mobile rule. */
@media (max-width: 1100px) {
  #detail table { display: block; overflow-x: auto; }
  /* Perf tables scroll inside their own box. The table element stays a
     real table for assistive tech; width: max-content keeps it wider
     than the box so the box scrolls instead of the cells wrapping. */
  .perf-scroll { overflow-x: auto; }
  #detail .perf-scroll table { display: table; width: max-content; }
}

/* E1: results-or-detail, one at a time (mobile) */
#back-results { display: none; }
@media (max-width: 768px) {
  /* Mobile page scroll: reset the fixed-height clip the desktop body and
     .layout rules put on the page. */
  body { height: auto; }
  .layout { display: block; height: auto; overflow: visible; }
  body:not([data-mobile-view="detail"]) .detail-panel:not(:has(.detail-empty)) { display: none; }
  body[data-mobile-view="detail"] .results-panel { display: none; }
  body[data-mobile-view="detail"] #back-results { display: block; position: sticky; top: 0; z-index: 2; }
  .kind-bar { flex-wrap: wrap; }
  .kind-bar .kind-label { display: none; }
  .header-right .meta { display: none; }
  .layout, .results-panel, .detail-panel { min-width: 0; }
  .header { flex-wrap: wrap; row-gap: .3rem; padding: .4rem .6rem; }
  .header-left { min-width: 0; flex-wrap: wrap; }
  .header-right { gap: .5rem; }
  .search-bar { padding: .5rem .6rem; }
  .isa-panel { max-width: 100%; overflow-x: auto; }
  .detail-panel { padding: .6rem; }
  pre.sig, pre.desc-code { max-width: 100%; }
}
@media (max-width: 480px) {
  .header-right a.icon-btn { display: none; }
}
