:root {
  /* Theme (auto): default to light, override to dark via prefers-color-scheme. */
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panelHover: #eef2ff;
  --text: #111827;
  --muted: #6b7280;
  --border: rgba(17, 24, 39, 0.12);

  /* Reusable tinted surfaces (avoid hard-coding white overlays). */
  --surfaceSoft: rgba(17, 24, 39, 0.06);
  --surfaceSofter: rgba(17, 24, 39, 0.04);
  --buttonSecondaryBg: rgba(17, 24, 39, 0.05);
  --progressTrackBg: rgba(17, 24, 39, 0.12);

  --accent: #2563eb;
  --accentHover: #1d4ed8;
  --positive: #059669;
  --negative: #dc2626;
  --error: #dc2626;
  --highlight: #b45309;
  --trace: #b45309;
  --warning: #b45309;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0e1a;
    --panel: #111827;
    --panelHover: #1a2332;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: rgba(255, 255, 255, 0.08);

    --surfaceSoft: rgba(255, 255, 255, 0.05);
    --surfaceSofter: rgba(255, 255, 255, 0.03);
    --buttonSecondaryBg: rgba(255, 255, 255, 0.05);
    --progressTrackBg: rgba(255, 255, 255, 0.1);

    --accent: #60a5fa;
    --accentHover: #93c5fd;
    --positive: #34d399;
    --negative: #f87171;
    --error: #ef4444;
    --highlight: #fbbf24;
    --trace: #fbbf24;
    --warning: #fb923c;
  }
}

/* Explicit overrides (Light/Dark) take precedence over system auto mode. */
:root[data-theme="light"] {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panelHover: #eef2ff;
  --text: #111827;
  --muted: #6b7280;
  --border: rgba(17, 24, 39, 0.12);
  --surfaceSoft: rgba(17, 24, 39, 0.06);
  --surfaceSofter: rgba(17, 24, 39, 0.04);
  --buttonSecondaryBg: rgba(17, 24, 39, 0.05);
  --progressTrackBg: rgba(17, 24, 39, 0.12);
  --accent: #2563eb;
  --accentHover: #1d4ed8;
  --positive: #059669;
  --negative: #dc2626;
  --error: #dc2626;
  --highlight: #b45309;
  --trace: #b45309;
  --warning: #b45309;
}

:root[data-theme="dark"] {
  --bg: #0a0e1a;
  --panel: #111827;
  --panelHover: #1a2332;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: rgba(255, 255, 255, 0.08);
  --surfaceSoft: rgba(255, 255, 255, 0.05);
  --surfaceSofter: rgba(255, 255, 255, 0.03);
  --buttonSecondaryBg: rgba(255, 255, 255, 0.05);
  --progressTrackBg: rgba(255, 255, 255, 0.1);
  --accent: #60a5fa;
  --accentHover: #93c5fd;
  --positive: #34d399;
  --negative: #f87171;
  --error: #ef4444;
  --highlight: #fbbf24;
  --trace: #fbbf24;
  --warning: #fb923c;
}

/* Keyboard focus visibility (WCAG SC 2.4.7). */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

html, body {
  height: 100%;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  /* iOS Safari can auto-inflate text sizes (even with a viewport meta), which
     breaks our tight mobile layout. Keep text sizing stable across iPhone. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
  color: var(--text);
}

/* App shell
 *
 * iOS Safari/PWA note:
 * - Avoid hard-coding a header height (it can wrap on iPhone).
 * - Use a flex column layout so the header takes its natural height and the
 *   main content fills the remaining viewport.
 */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Header */
.appHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.appHeader h1 {
  font-size: 16px;
  font-weight: 600;
}

.headerControls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.browseGroup {
  display: flex;
  align-items: center;
  gap: 6px;
}

.button.themeToggle {
  width: 38px;
  min-width: 38px;
  padding: 6px 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.input, .select {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

.inputSmall, .selectSmall {
  padding: 5px 8px;
  font-size: 12px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(96, 165, 250, 0.15);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.button:hover {
  background: rgba(96, 165, 250, 0.25);
  border-color: var(--accent);
}

.buttonSmall {
  padding: 4px 8px;
  font-size: 12px;
}

.buttonSecondary {
  background: var(--buttonSecondaryBg);
}

.statusInline {
  font-size: 12px;
  color: var(--muted);
  margin-left: 8px;
}

.statusInline.ok {
  color: var(--positive);
}
.statusInline.bad {
  color: var(--negative);
}
.statusInline.warn {
  /* Used for non-fatal states (e.g., loaded from cache while offline). */
  color: #f59e0b;
}

/* Progress bar for loading large files */
.progressContainer {
  width: 120px;
  height: 6px;
  background: var(--progressTrackBg);
  border-radius: 3px;
  overflow: hidden;
  margin-left: 8px;
}

.progressBar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.15s ease-out;
}

.progressBar.indeterminate {
  width: 30%;
  animation: progressIndeterminate 1.2s ease-in-out infinite;
}

@keyframes progressIndeterminate {
  0% {
    transform: translateX(-100%);
  }
  50% {
    transform: translateX(250%);
  }
  100% {
    transform: translateX(-100%);
  }
}

/* Explorer layout */
.explorer {
  display: flex;
  flex-direction: column;
  /* Fill the remaining space under the header (see body flex shell). */
  flex: 1 1 auto;
  min-height: 0; /* Allow inner scroll containers to size correctly. */
}

/* Trace bar */
.traceBar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  background: rgba(251, 191, 36, 0.08);
  border-bottom: 1px solid var(--border);
  min-height: 40px;
}

.traceLabel {
  font-size: 12px;
  color: var(--trace);
  font-weight: 600;
}

.pathLabel {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  flex: 1;
  overflow-x: auto;
}

.breadcrumb li {
  display: flex;
  align-items: center;
  gap: 4px;
}

.breadcrumb li::after {
  content: "→";
  color: var(--muted);
  margin: 0 4px;
}

.breadcrumb li:last-child::after {
  display: none;
}

.breadcrumb button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
}

.breadcrumb button:hover {
  background: rgba(96, 165, 250, 0.15);
}

.breadcrumb li:last-child button {
  color: var(--trace);
  font-weight: 600;
}

.breadcrumbEllipsis {
  color: var(--muted);
  font-size: 12px;
  padding: 2px 4px;
  cursor: help;
}

/* Trace bar button group */
.traceButtons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Main explorer area */
.explorerMain {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Current neuron panel (left) */
.currentNeuron {
  width: 320px;
  min-width: 280px;
  padding: 20px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.currentNeuron h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 16px;
  word-break: break-all;
  font-family: ui-monospace, monospace;
}

.propList {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  font-size: 13px;
}

.propList dt {
  color: var(--muted);
}

.propList dd {
  font-family: ui-monospace, monospace;
  word-break: break-all;
}

.propList dd a.inlineLink {
  color: var(--accent);
  text-decoration: underline;
  font-weight: 600;
}

.propList dd.positive {
  color: var(--positive);
}
.propList dd.negative {
  color: var(--negative);
}
.propList dd.error {
  color: var(--error);
  font-weight: 600;
}
.propList dd.highlight {
  color: var(--highlight);
  font-weight: 600;
}

/* Neuron detail cards (#107) */
.neuronCards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

@media (max-width: 639px) {
  .neuronCards {
    grid-template-columns: 1fr;
  }
}

.neuronCard {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  animation: cardSlideUp 180ms ease-out both;
}

.neuronCard.noMotion {
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  .neuronCard {
    animation: none;
  }
}

@keyframes cardSlideUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.neuronCardTitle {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 8px;
}

/* Squash badge colour variants */
.propList dd.squashBadge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
}

.propList dd.squashBadge--blue {
  background: rgba(37, 99, 235, 0.12);
  color: #2563eb;
}

.propList dd.squashBadge--purple {
  background: rgba(139, 92, 246, 0.12);
  color: #8b5cf6;
}

.propList dd.squashBadge--green {
  background: rgba(5, 150, 105, 0.12);
  color: #059669;
}

.propList dd.squashBadge--orange {
  background: rgba(217, 119, 6, 0.12);
  color: #d97706;
}

.propList dd.squashBadge--grey {
  background: var(--surfaceSoft);
  color: var(--muted);
}

@media (prefers-color-scheme: dark) {
  .propList dd.squashBadge--blue {
    background: rgba(96, 165, 250, 0.15);
    color: #93c5fd;
  }
  .propList dd.squashBadge--purple {
    background: rgba(167, 139, 250, 0.15);
    color: #c4b5fd;
  }
  .propList dd.squashBadge--green {
    background: rgba(52, 211, 153, 0.15);
    color: #6ee7b7;
  }
  .propList dd.squashBadge--orange {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
  }
}

:root[data-theme="dark"] .propList dd.squashBadge--blue {
  background: rgba(96, 165, 250, 0.15);
  color: #93c5fd;
}
:root[data-theme="dark"] .propList dd.squashBadge--purple {
  background: rgba(167, 139, 250, 0.15);
  color: #c4b5fd;
}
:root[data-theme="dark"] .propList dd.squashBadge--green {
  background: rgba(52, 211, 153, 0.15);
  color: #6ee7b7;
}
:root[data-theme="dark"] .propList dd.squashBadge--orange {
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
}

/* Sparkline & histogram inline SVGs */
.sparkline {
  display: block;
  width: 100%;
  height: 36px;
  margin-top: 8px;
}

.sparklineLine {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sparklineDot {
  fill: var(--accent);
}

.errorHistogram {
  display: block;
  width: 100%;
  height: 28px;
  margin-top: 8px;
}

/* Tabs (Details / Issues / Candidates) */
.tabRow {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.tabBtn {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--buttonSecondaryBg);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.tabBtn.isActive {
  border-color: var(--accent);
  background: rgba(96, 165, 250, 0.18);
}

.tabPanel {
  display: none;
}

.tabPanel.isActive {
  display: block;
}

/* Candidate/issue panels */
.panelSectionTitle {
  margin-top: 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.issueList, .candidateList {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.issueRow, .candidateRow {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surfaceSofter);
  cursor: pointer;
}

.issueRow:hover, .candidateRow:hover {
  background: var(--panelHover);
}

.issueRowTitle, .candidateRowTitle {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  margin-bottom: 6px;
  color: var(--text);
  word-break: break-word;
}

.candidateDiagram {
  width: 100%;
  max-width: 320px;
  margin-top: 8px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: rgba(96, 165, 250, 0.06);
}

.candidateDiagramText {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  fill: var(--text);
}

.candidateDiagramGhost {
  stroke: var(--warning);
  stroke-dasharray: 5 4;
  fill: transparent;
}

.candidateDiagramOldEdge {
  stroke: var(--warning);
  stroke-width: 3;
  opacity: 0.7;
}

.candidateDiagramNewEdge {
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-dasharray: 6 5;
  opacity: 0.95;
}

.candidateDiagramNode {
  fill: var(--panel);
  stroke: var(--border);
  stroke-width: 1.5;
}

.candidateDiffGrid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
  margin-top: 10px;
  font-size: 12px;
}

.candidateDiffGrid dt {
  color: var(--muted);
}

.candidateDiffGrid dd {
  font-family: ui-monospace, monospace;
  word-break: break-word;
}

/* Impact breakdown to outputs (heuristic attribution). */
.impactBreakdown {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.impactBreakdownHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.impactBreakdownTitle {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.impactBreakdownTruncated {
  font-size: 11px;
  color: var(--warning);
  background: rgba(251, 146, 60, 0.15);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.impactBreakdownNote {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
  margin-bottom: 10px;
}

.impactBreakdownRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
}

.impactBreakdownOut {
  font-family: ui-monospace, monospace;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.impactBreakdownStats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.impactBreakdown .stat {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  padding: 2px 6px;
  background: var(--surfaceSoft);
  border-radius: 4px;
  white-space: nowrap;
}

.impactBreakdownPaths {
  list-style: none;
  padding-left: 0;
  margin: 0 0 8px 0;
}

.impactBreakdownPaths li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  padding: 2px 0;
}

.impactBreakdownBtn {
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(96, 165, 250, 0.12);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.impactBreakdownBtn:hover {
  background: rgba(96, 165, 250, 0.22);
  border-color: var(--accent);
}

.impactPath {
  font-family: ui-monospace, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.impactPathScore {
  font-family: ui-monospace, monospace;
  white-space: nowrap;
}

/* Modal (path inspector). */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 1000;
}

.modal.isOpen {
  display: block;
}

.modalBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modalPanel {
  position: relative;
  width: min(980px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  margin: 12px auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Mobile: use more of the vertical space for modals. */
@media (max-width: 639px) {
  .modalPanel {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    margin: 8px auto;
  }
}

.modalHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.modalTitle {
  font-weight: 600;
  color: var(--text);
}

.modalBody {
  padding: 12px 14px;
  overflow: auto;
}

/* Observations dashboard */
.obsSummary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.obsControls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 12px;
}

.obsList {
  display: grid;
  gap: 8px;
}

.obsRow {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surfaceSofter);
  cursor: pointer;
}

.obsRow:hover {
  background: var(--panelHover);
}

.obsRowTitle {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  margin-bottom: 6px;
  color: var(--text);
  word-break: break-word;
}

.obsRowTitle .obsAlias {
  color: var(--positive);
  font-weight: 600;
}

.obsRowTitle .obsUuid {
  color: var(--muted);
  margin-left: 8px;
}

.obsRowMuted {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 6px;
}

.modalFooter {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.modalKvp {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

.modalKvp dt {
  color: var(--muted);
}

.modalKvp dd {
  font-family: ui-monospace, monospace;
  word-break: break-word;
}

.pathList {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pathItem {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surfaceSofter);
  overflow: hidden;
}

.pathItem summary {
  cursor: pointer;
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.pathItem summary::-webkit-details-marker {
  display: none;
}

.pathSummaryPath {
  font-family: ui-monospace, monospace;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.pathSummaryScore {
  font-family: ui-monospace, monospace;
  color: var(--accent);
  white-space: nowrap;
}

.pathDetails {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.pathEquation {
  font-family: ui-monospace, monospace;
  color: var(--text);
  margin-top: 6px;
  word-break: break-word;
}

/* Flow arrow */
.flowArrow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  font-size: 24px;
  color: var(--muted);
  background: var(--bg);
}

/* Synapse list (right) */
.synapseList {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.synapseHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.synapseHeader {
  /* Keep controls reachable when the inbound list is long. On mobile we scroll
     the whole explorer surface, so sticky headers make a big difference. */
  position: sticky;
  top: 0;
  z-index: 10;
}

.synapseTools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filterDetails summary {
  list-style: none;
}

.filterDetails summary::-webkit-details-marker {
  display: none;
}

.filterPanel {
  margin-top: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surfaceSofter);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.filterItem {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.filterItem span {
  color: var(--muted);
}

.filterCheckbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding-top: 2px;
}

.filterCheckbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.showMoreRow {
  display: flex;
  justify-content: center;
  padding: 10px 0 14px 0;
}

.synapseHeader h2 {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  background: rgba(96, 165, 250, 0.2);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}

.sortControls {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.synapseListScroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* Individual synapse row */
.synapseRow {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
  margin: 4px 0;
  background: var(--panel);
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}

.synapseRow:hover {
  background: var(--panelHover);
  border-color: var(--accent);
}

.synapseRow.inTrace {
  border-color: var(--trace);
  background: rgba(251, 191, 36, 0.08);
}

.synapseRow.candidateReplaceEdge {
  border-color: var(--warning);
  background: rgba(251, 146, 60, 0.12);
}

.synapseRow.candidateReplaceEdge:hover {
  border-color: var(--warning);
}

.synapseFrom {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.synapseFrom .neuronUuid {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, monospace;
  font-size: 13px;
}

.synapseFrom .neuronType {
  font-size: 11px;
  color: var(--muted);
}

.synapseStats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.synapseStats .stat {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  padding: 2px 6px;
  background: var(--surfaceSoft);
  border-radius: 4px;
  white-space: nowrap;
}

.synapseStats .stat.positive {
  color: var(--positive);
}
.synapseStats .stat.negative {
  color: var(--negative);
}
.synapseStats .stat.error {
  color: var(--error);
  background: rgba(239, 68, 68, 0.15);
}
.synapseStats .stat.highlight {
  color: var(--highlight);
  background: rgba(251, 191, 36, 0.15);
}

/* Inline weight colour chip (#105) */
.weightChip {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

/* Synapse colour legend (#105) */
.synapseLegend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.synapseLegend summary {
  cursor: pointer;
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
}

.synapseLegend .legendItems {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 4px;
}

.synapseLegend .legendSwatch {
  display: inline-block;
  width: 18px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

@media (max-width: 639px) {
  .synapseLegend {
    padding: 4px 8px;
  }
}

.synapseNav {
  color: var(--accent);
  font-size: 16px;
}

/* Empty state */
.emptyState {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  font-size: 14px;
}

/* Alias styling */
.aliasName {
  display: block;
  color: var(--positive);
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}

.uuidSmall {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}

.neuronAlias {
  display: block;
  color: var(--positive);
  font-weight: 500;
  font-size: 13px;
}

.neuronUuidSmall {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}

/* Tooltip indicator */
.hasTooltip {
  cursor: help;
  border-bottom: 1px dotted var(--muted);
}

.hasTooltip:hover {
  color: var(--text);
}

/* Touch devices (iOS Safari/PWA): press-and-hold tooltips should not also
   trigger text selection/callouts on the underlying element. */
@media (hover: none) {
  .hasTooltip,
  .synapseStats .stat,
  .impactBreakdown .stat,
  .neuronAlias,
  .aliasName {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
}

/* Neuron label/description block under the title (mobile-friendly). */
.neuronDescription {
  margin: -8px 0 12px 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surfaceSofter);
  color: var(--muted);
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Touch tooltip UI (press-and-hold on mobile). */
.touchTooltip {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  max-width: 560px;
  margin: 0 auto;
  z-index: 9999;
  display: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.touchTooltip.isOpen {
  display: block;
}

.touchTooltipHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surfaceSofter);
}

.touchTooltipTitle {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.touchTooltipClose {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  background: var(--buttonSecondaryBg);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.touchTooltipBody {
  padding: 10px 12px;
  color: var(--muted);
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Suspicious - very low impact that should be prunable */
.suspicious {
  border-color: var(--warning) !important;
  background: rgba(251, 146, 60, 0.1) !important;
}

.propList dd.suspicious,
.synapseStats .stat.suspicious {
  color: var(--warning);
  background: rgba(251, 146, 60, 0.15);
}

/* ==========================================================================
   Responsiveness — Issue #108 holistic overhaul
   Breakpoints: Mobile <640px | Tablet 640–1024px | Desktop >1024px
   ========================================================================== */

/* Safe-area insets for notched devices (iPhone X+). */
@supports (padding: env(safe-area-inset-top)) {
  .appHeader {
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
  }
  .traceBar {
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
  }
}

/* ---------- Header: collapsible URL input on mobile (#108) ---------- */
.headerUrlDetails {
  display: contents; /* transparent on desktop — children flow normally */
}

.headerUrlDetails summary {
  display: none; /* hidden on desktop */
}

/* ---------- Tablet (640–1024px): collapsible synapse panel ---------- */

/* Synapse panel toggle button — hidden on desktop & mobile. */
.synapsePanelToggle {
  display: none;
}

@media (min-width: 640px) and (max-width: 1023px) {
  .appHeader {
    align-items: flex-start;
    gap: 10px;
  }

  .headerControls {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  #fetchUrl.input {
    flex: 1 1 260px;
    min-width: 180px;
  }

  .traceBar {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  /* Full-width neuron panel when synapse panel is hidden. */
  .explorerMain {
    position: relative;
  }

  .currentNeuron {
    width: auto;
    min-width: 0;
    flex: 1;
  }

  /* Synapse panel slides in from the right on tablet. */
  .synapseList {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(400px, 55vw);
    background: var(--panel);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
    transform: translateX(100%);
    transition: transform 0.25s ease;
    z-index: 20;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .synapseList.isPanelOpen {
    transform: translateX(0);
  }

  .synapsePanelToggle {
    display: inline-flex;
  }

  .flowArrow {
    display: none;
  }

  .synapseHeader {
    flex-wrap: wrap;
    gap: 10px;
  }

  .sortControls {
    width: 100%;
    justify-content: space-between;
  }
}

/* ---------- Mobile (<640px): single-column vertical stack ---------- */

/* Bottom tab bar — only visible on mobile. */
.mobileTabBar {
  display: none;
}

@media (max-width: 639px) {
  .appHeader {
    padding: 10px 14px;
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .appHeader h1 {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 14px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Collapse URL input into <details> on mobile. */
  .headerUrlDetails {
    display: block;
    width: 100%;
  }

  .headerUrlDetails summary {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 12px;
    color: var(--muted);
    padding: 4px 0;
    list-style: none;
  }

  .headerUrlDetails summary::-webkit-details-marker {
    display: none;
  }

  .headerUrlDetails .headerUrlInner {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
  }

  .headerControls {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }

  #fetchUrl.input {
    flex: 1 1 100%;
    min-width: 0;
  }

  #fetchBtn.button {
    flex: 1 1 100%;
    min-height: 44px;
    padding: 6px 10px;
  }

  .browseGroup {
    flex: 1 1 100%;
    width: 100%;
  }

  #fileBtn.button {
    flex: 1 1 auto;
    min-height: 44px;
    padding: 6px 10px;
  }

  #themeToggle.themeToggle {
    flex: 0 0 auto;
  }

  .progressContainer {
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
    margin-left: 0;
  }

  .statusInline {
    flex: 1 1 100%;
    margin-left: 0;
    word-break: break-word;
  }

  /* Trace bar sticky at top with horizontal scroll breadcrumb. */
  .traceBar {
    padding: 8px 14px;
    flex-wrap: wrap;
    row-gap: 8px;
    position: sticky;
    top: 0;
    z-index: 15;
    background: rgba(251, 191, 36, 0.08);
  }

  .breadcrumb {
    flex: 1 1 100%;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Compact trace buttons as toolbar. */
  .traceButtons {
    flex: 1 1 100%;
    justify-content: flex-start;
    gap: 4px;
  }

  .traceButtons .button {
    min-height: 44px;
    min-width: 44px;
  }

  /* Single-column stack. */
  .explorerMain {
    flex-direction: column;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .currentNeuron {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
    overflow: visible;
    padding: 14px;
  }

  .flowArrow {
    display: none;
  }

  .synapseList {
    overflow: visible;
  }

  .synapseListScroll {
    overflow: visible;
    flex: 0 0 auto;
    padding: 8px 12px;
  }

  .synapseHeader {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }

  .sortControls {
    width: 100%;
    justify-content: space-between;
  }

  /* Synapse rows: single column, touch-friendly spacing. */
  .synapseRow {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px;
    min-height: 44px;
  }

  .synapseStats {
    justify-content: flex-start;
  }

  .synapseNav {
    display: none;
  }

  /* Bottom tab bar for mobile navigation. */
  .mobileTabBar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--panel);
    border-top: 1px solid var(--border);
    padding: 4px 0;
    padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
    justify-content: space-around;
  }

  .mobileTabBtn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    min-width: 64px;
    min-height: 44px;
    border: none;
    background: none;
    color: var(--muted);
    font-size: 10px;
    cursor: pointer;
    border-radius: 8px;
  }

  .mobileTabBtn .mobileTabIcon {
    font-size: 18px;
    line-height: 1;
  }

  .mobileTabBtn.isActive {
    color: var(--accent);
    background: rgba(96, 165, 250, 0.1);
  }

  /* Desktop tab row hidden on mobile — replaced by bottom tab bar. */
  .tabRow {
    display: none;
  }

  /* Add bottom padding so content isn't hidden behind bottom tab bar. */
  .explorer {
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
  }

  /* Neuron details collapsible card. */
  .neuronDetailsCollapsible summary {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    list-style: none;
  }

  .neuronDetailsCollapsible summary::-webkit-details-marker {
    display: none;
  }

  .neuronDetailsCollapsible summary::before {
    content: "▶";
    font-size: 10px;
    transition: transform 0.15s ease;
  }

  .neuronDetailsCollapsible[open] summary::before {
    transform: rotate(90deg);
  }
}

/* Preserve notch-safe padding on mobile viewports. */
@supports (padding: env(safe-area-inset-top)) {
  @media (max-width: 639px) {
    .appHeader {
      padding-top: calc(10px + env(safe-area-inset-top));
      padding-right: calc(14px + env(safe-area-inset-right));
      padding-bottom: 10px;
      padding-left: calc(14px + env(safe-area-inset-left));
    }

    .traceBar {
      padding-top: 8px;
      padding-right: calc(14px + env(safe-area-inset-right));
      padding-bottom: 8px;
      padding-left: calc(14px + env(safe-area-inset-left));
    }
  }
}

/* ---------- Touch-friendly sizing (#108) ---------- */

/* All interactive elements: minimum 44×44px touch target on touch devices. */
@media (hover: none), (pointer: coarse) {
  .button,
  .tabBtn,
  .breadcrumb button,
  .synapseRow,
  .obsRow,
  .issueRow,
  .candidateRow,
  .topoNode {
    min-height: 44px;
  }

  .button,
  .tabBtn {
    min-width: 44px;
  }

  /* Adequate spacing between synapse rows for fat-finger tapping. */
  .synapseRow {
    margin: 6px 0;
  }

  .breadcrumb button {
    padding: 8px 10px;
  }
}

/* ==========================================================================
   Creature overview dashboard (#103)
   ========================================================================== */

.overviewDashboard {
  flex: 1;
  padding: 24px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overviewGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.overviewCard {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  min-width: 0;
  overflow: hidden;
  animation: overviewFadeIn 0.4s ease both;
}

.overviewCard:nth-child(2) {
  animation-delay: 0.08s;
}
.overviewCard:nth-child(3) {
  animation-delay: 0.16s;
}

@keyframes overviewFadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .overviewCard {
    animation: none;
  }
}

.overviewCardTitle {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 14px;
}

/* Metrics list */
.overviewMetricsList {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 12px;
  align-items: baseline;
}

.overviewMetricsList dt {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.overviewMetricsList dd {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  word-break: break-word;
  overflow-wrap: break-word;
  min-width: 0;
}

/* Activation distribution */
.overviewActivationList {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.overviewActivationChip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--surfaceSoft);
  font-size: 13px;
  color: var(--text);
}

.overviewActivationChip .chipCount {
  font-weight: 700;
  color: var(--accent);
}

/* Topology diagram */
.overviewTopologyDiagram {
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: auto;
  padding: 12px 0;
  min-height: 80px;
}

.topoSvg {
  display: block;
}

.topoSvg .topoNode:hover circle {
  filter: brightness(1.2);
}

.topoSkipSummary {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  text-align: center;
}

/* Overview actions */
.overviewActions {
  text-align: center;
  margin-top: 20px;
}

/* Topology card spans full width when grid has room */
.overviewCardTopology {
  grid-column: 1 / -1;
}

@media (max-width: 639px) {
  .overviewGrid {
    grid-template-columns: 1fr;
  }

  .overviewDashboard {
    padding: 16px 14px;
  }

  .overviewCard {
    padding: 14px;
  }

  .overviewCardTitle {
    font-size: 12px;
  }

  .overviewMetricsList {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .overviewMetricsList dd {
    font-size: 14px;
  }
}

/* ==========================================================================
   Issue #53/#116: Hide URL/Fetch/Browse controls when snapshot is loaded
   ========================================================================== */

/* Hide the loading controls once a snapshot is loaded (all viewports).
   Users can press "Clear" to reveal them again. (#116) */
body.snapshotLoaded .headerUrlDetails {
  display: none;
}

/* ==========================================================================
   Issue #104: Smooth animated transitions when navigating between neurons
   ========================================================================== */

/* CSS custom properties for transition durations (configurable). */
:root {
  --transition-crossfade: 180ms;
  --transition-breadcrumb: 200ms;
  --transition-synapse-fade: 180ms;
  --transition-synapse-stagger: 25ms;
}

/* Neuron panel cross-fade: opacity + slight vertical slide. */
.currentNeuron {
  transition: opacity var(--transition-crossfade) ease;
}

.currentNeuron.transitionOut {
  opacity: 0;
  transform: translateY(6px);
}

.currentNeuron.transitionIn {
  opacity: 0;
  transform: translateY(-6px);
}

/* Breadcrumb directional slide. */
.breadcrumb li {
  opacity: 1;
  transform: translateX(0);
  transition:
    opacity var(--transition-breadcrumb) ease,
    transform var(--transition-breadcrumb) ease;
}

.breadcrumb.slideDeeper li {
  animation: breadcrumbSlideDeeper var(--transition-breadcrumb) ease both;
}

.breadcrumb.slideBack li {
  animation: breadcrumbSlideBack var(--transition-breadcrumb) ease both;
}

@keyframes breadcrumbSlideDeeper {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes breadcrumbSlideBack {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Synapse row staggered fade-in. */
.synapseRow.fadeIn {
  animation: synapseFadeIn var(--transition-synapse-fade) ease both;
}

@keyframes synapseFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Skip all navigation transitions when reduced motion is preferred. */
@media (prefers-reduced-motion: reduce) {
  .currentNeuron,
  .currentNeuron.transitionOut,
  .currentNeuron.transitionIn {
    transition: none;
    opacity: 1;
    transform: none;
  }

  .breadcrumb.slideDeeper li,
  .breadcrumb.slideBack li {
    animation: none;
  }

  .synapseRow.fadeIn {
    animation: none;
  }
}
