:root {
  --bg: #0b0f17;
  --panel: rgba(18, 24, 36, 0.92);
  --panel-border: rgba(120, 140, 180, 0.22);
  --text: #e8eef5;
  --muted: #8da0b6;
  --accent: #36c5f0;
  --accent-2: #27d3a2;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 50% 38%, #15233f 0%, #0a1020 48%, #04060c 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

#graph { position: fixed; inset: 0; }

/* ---- Always-on labels (HTML overlay synced to 3D positions) ---- */
#labels { position: fixed; inset: 0; z-index: 5; overflow: hidden; pointer-events: none; }
.node-label {
  position: absolute;
  left: 0; top: 0;
  color: #eaf1f8;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  text-shadow: 0 1px 3px #000, 0 0 7px rgba(0,0,0,0.85);
  transform: translate(-50%, -50%);
  will-change: transform;
}
.node-label.lvl-root { font-size: 18px; }
.node-label.lvl-provider, .node-label.lvl-domain { font-size: 15px; }
.node-label.lvl-service { font-size: 13.5px; }
.node-label.lvl-course { font-size: 13px; color: #ffd2e3; }
.node-label.lvl-feature, .node-label.lvl-concept { font-size: 12px; }
.node-label.lvl-video { font-size: 11px; font-weight: 500; color: #c3cedb; }
.node-label.lvl-section { font-size: 10px; font-weight: 500; color: #9fb0c4; }
.node-label.focus { color: #fff; text-shadow: 0 0 10px rgba(120,200,255,0.9), 0 1px 3px #000; }

/* ---- Error bar ---- */
#errbar {
  position: fixed;
  left: 0; right: 0; top: 0;
  z-index: 50;
  background: #c5221f;
  color: #fff;
  font-size: 12.5px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  padding: 8px 38px 8px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}
#errbar.hidden { display: none; }
#errbar .x { position: absolute; right: 10px; top: 6px; cursor: pointer; font-size: 16px; }

/* ---- Top bar ---- */
#topbar {
  position: fixed;
  top: 14px;
  left: 16px;
  z-index: 10;
  max-width: 60vw;
}
.brand {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
  text-shadow: 0 1px 6px rgba(0,0,0,0.6);
}
#breadcrumb {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
#breadcrumb .crumb { cursor: pointer; color: var(--muted); }
#breadcrumb .crumb:hover { color: var(--text); text-decoration: underline; }
#breadcrumb .crumb.current { color: var(--accent); cursor: default; text-decoration: none; }
#breadcrumb .sep { opacity: 0.5; }

/* ---- Controls ---- */
#controls {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 10;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
#controls input,
#controls button {
  font: inherit;
  font-size: 12.5px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 7px 11px;
  backdrop-filter: blur(6px);
}
#controls input { width: 180px; }
#controls input:focus { outline: none; border-color: var(--accent); }
#controls button { cursor: pointer; transition: background 0.15s, border-color 0.15s; }
#controls button:hover { background: rgba(40, 52, 74, 0.95); border-color: var(--accent); }
#controls button.active { background: rgba(54,197,240,0.16); border-color: var(--accent); color: var(--text); }
#btn-more { display: none; }      /* ⋯ overflow trigger — phones only */
#ctrl-menu { display: contents; } /* desktop: the menu's buttons flow inline with the row */
/* Detail panel open -> slide the controls out from under it (it used to cover them). */
body.detail-open #controls { right: calc(min(420px, 92vw) + 16px); }
body.detail-open #enrich-panel, body.detail-open #next-panel { right: calc(min(420px, 92vw) + 16px); }

/* ---- Live search dropdown ---- */
#search-wrap { position: relative; }
#search-results {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40;
  width: 300px; max-height: 330px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px;
  backdrop-filter: blur(8px); box-shadow: 0 14px 40px rgba(0,0,0,0.5); padding: 4px;
}
#search-results.hidden { display: none; }
.sr-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px;
  border-radius: 7px; cursor: pointer; font-size: 12.5px;
}
.sr-item:hover, .sr-item.active { background: rgba(54,197,240,0.14); }
.sr-item .cdot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.sr-item .sr-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-item .sr-sub { color: var(--muted); font-size: 10.5px; flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Per-node command panel ---- */
#cmd {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 10;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 12px;
  backdrop-filter: blur(6px);
  width: 232px;
}
#cmd.hidden { display: none; }
#cmd-collapse {
  position: absolute; top: 8px; right: 10px;
  border: none; background: rgba(255,255,255,0.06); color: var(--text);
  width: 22px; height: 22px; border-radius: 6px; cursor: pointer; font-size: 15px; line-height: 1;
}
#cmd-collapse:hover { background: rgba(255,255,255,0.14); }
#cmd h4 { margin: 0 0 4px; padding-right: 24px; font-size: 12px; color: var(--text); line-height: 1.3; }
.cmd-hint { margin: 0 0 9px; font-size: 10.5px; color: var(--muted); line-height: 1.35; }
.cmd-actions { display: flex; flex-direction: column; gap: 6px; }
.cmd-more-toggle {
  width: 100%; margin-top: 7px; padding: 5px 8px; font: inherit; font-size: 11px;
  color: var(--muted); background: transparent; border: none; cursor: pointer; text-align: left;
}
.cmd-more-toggle:hover { color: var(--text); }
#cmd-more { margin-top: 2px; }
#cmd-more.hidden { display: none; }
.cmd-btn {
  text-align: left;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  padding: 7px 9px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.cmd-btn:hover:not(:disabled) { background: rgba(54,197,240,0.14); border-color: var(--accent); }
.cmd-btn:disabled { opacity: 0.4; cursor: default; }
.cmd-undo {
  margin-top: 8px; width: 100%; text-align: center; font: inherit; font-size: 11.5px;
  color: var(--muted); background: transparent; border: 1px dashed var(--panel-border);
  border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.cmd-undo:hover:not(:disabled) { color: var(--text); border-color: var(--accent); border-style: solid; }
.cmd-undo:disabled { opacity: 0.4; cursor: default; }
.syn-box { margin-top: 8px; }
.syn-box.hidden { display: none; }
#syn-input, #pair-input, #instruct-input, #setparent-input { width: 100%; font: inherit; font-size: 12px; padding: 7px 9px; border-radius: 8px; background: rgba(255,255,255,0.06); border: 1px solid var(--accent); color: var(--text); }
#syn-input::placeholder, #pair-input::placeholder, #instruct-input::placeholder, #setparent-input::placeholder { color: var(--muted); }

/* ---- Preview of proposed AI changes ---- */
#preview {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(4, 7, 13, 0.62); backdrop-filter: blur(3px);
}
#preview.hidden { display: none; }
.preview-card {
  width: min(560px, 92vw); max-height: 82vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px;
  padding: 20px 22px; box-shadow: 0 24px 70px rgba(0,0,0,0.55);
}
.preview-card h3 { margin: 0 0 4px; font-size: 16px; color: var(--text); }
.preview-sub { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; line-height: 1.5; }
.preview-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.preview-list li {
  display: flex; gap: 9px; align-items: flex-start; font-size: 13px; line-height: 1.45; color: #d3deeb;
  background: rgba(255,255,255,0.04); border: 1px solid var(--panel-border); border-radius: 9px; padding: 9px 11px;
}
.preview-list li.destructive { background: rgba(232,90,90,0.10); border-color: rgba(232,90,90,0.45); color: #f1c9c9; }
.pv-icon { flex: none; }
.preview-warn { margin: 12px 0 0; font-size: 11.5px; color: #f1b6b6; line-height: 1.45; }
.preview-warn.hidden { display: none; }
.preview-actions { display: flex; gap: 10px; margin-top: 18px; }
.pv-apply, .pv-discard { font: inherit; font-size: 13px; border-radius: 9px; padding: 9px 16px; cursor: pointer; border: 1px solid var(--panel-border); }
.pv-apply { background: var(--accent); color: #04121b; border-color: var(--accent); font-weight: 600; }
.pv-apply:hover:not(:disabled) { filter: brightness(1.08); }
.pv-apply:disabled { opacity: 0.5; cursor: default; }
.pv-discard { background: transparent; color: var(--muted); }
.pv-discard:hover { color: var(--text); border-color: var(--accent); }
.cmd-status { font-size: 11px; color: var(--muted); margin-top: 8px; min-height: 14px; line-height: 1.4; }
.cmd-status.run { color: var(--accent-2); }
.cmd-status.err { color: var(--err); }

/* ---- Detail panel ---- */
#detail {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 20;
  width: min(420px, 92vw);
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  padding: 22px 22px 30px;
  overflow-y: auto;
  transition: transform 0.25s ease;
  box-shadow: -12px 0 40px rgba(0,0,0,0.45);
}
#detail.hidden { transform: translateX(105%); }
#detail-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
#detail-close:hover { background: rgba(255,255,255,0.14); }

/* Study tools at the top of the detail panel (read/learn actions, not edits) */
#detail-tools { display: flex; gap: 8px; margin: 0 40px 14px 0; }
#detail-tools button {
  font: inherit; font-size: 12px; font-weight: 600; color: var(--text); cursor: pointer;
  background: rgba(54,197,240,0.10); border: 1px solid rgba(54,197,240,0.35); border-radius: 8px; padding: 6px 11px;
}
#detail-tools button:hover:not(:disabled) { background: rgba(54,197,240,0.2); border-color: var(--accent); }
#detail-tools button:disabled { opacity: 0.5; cursor: default; }
#dt-path-box { margin: -6px 0 12px; }
#dt-path-box.hidden { display: none; }
#dt-path-box input { width: 100%; font: inherit; font-size: 12px; padding: 7px 9px; border-radius: 8px; background: rgba(255,255,255,0.06); border: 1px solid var(--accent); color: var(--text); }
#dt-path-box input::placeholder { color: var(--muted); }

.d-type {
  display: inline-block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 700;
  color: #06121f;
}
.d-title { font-size: 21px; font-weight: 700; margin: 12px 0 6px; line-height: 1.25; }
.d-path { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.d-desc { font-size: 14px; line-height: 1.55; color: #cfdae8; }

.d-section-title {
  margin: 20px 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  border-top: 1px solid var(--panel-border);
  padding-top: 14px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--panel-border);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip:hover { background: rgba(255,255,255,0.12); }
.chip .w { color: var(--muted); font-size: 10.5px; }
.chip .cdot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* Rendered note content */
.d-badge {
  display: inline-block;
  margin: 8px 0 2px;
  font-size: 11px;
  font-weight: 600;
  color: #d9c9ff;
  background: rgba(155, 123, 255, 0.16);
  border: 1px solid rgba(155, 123, 255, 0.4);
  border-radius: 999px;
  padding: 3px 10px;
}
.d-source-note {
  margin: 12px 0 6px;
  font-size: 11.5px;
  color: var(--muted);
  background: rgba(54, 197, 240, 0.08);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 9px;
}
.d-content { margin-top: 6px; font-size: 13.5px; line-height: 1.6; color: #d4deec; }
.d-content h4, .d-content h5 { margin: 16px 0 6px; color: #fff; font-size: 14px; }
.d-content p { margin: 8px 0; }
.d-content ul { margin: 8px 0; padding-left: 20px; }
.d-content li { margin: 4px 0; }
.d-content strong { color: #fff; }
.d-content code { background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.d-file { font-size: 11.5px; color: var(--muted); margin-top: 16px; word-break: break-word; }

/* Topic "from the lectures" excerpts */
.d-excerpt { margin: 10px 0; padding-left: 11px; border-left: 2px solid var(--panel-border); }
.d-excerpt a.exlink { color: var(--accent); font-weight: 600; font-size: 13px; cursor: pointer; }
.d-excerpt a.exlink:hover { text-decoration: underline; }
.d-excerpt p { margin: 4px 0 0; font-size: 12.5px; line-height: 1.5; color: #b9c6d6; }

/* Per-member descriptions inside a quasi-synonym (merged) bubble */
.d-syn { margin: 0 0 12px; }
.d-syn-label { font-size: 12px; font-weight: 600; color: var(--accent-2); margin-bottom: 3px; }
.d-desc.d-muted { color: var(--muted); font-style: italic; }

/* Keyword cross-links inside descriptions */
a.exlink { color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: none; border-bottom: 1px dashed rgba(120,170,255,0.55); }
a.exlink:hover { border-bottom-color: var(--accent); background: rgba(120,170,255,0.12); }

/* A node's own unique keywords */
.d-keywords { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.d-kw-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin-right: 2px; }
.kw { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: rgba(120,170,255,0.10); border: 1px solid rgba(120,170,255,0.28); color: #bcd0ea; }

.legend-note { margin-top: 10px; font-size: 10.5px; line-height: 1.4; color: var(--muted); border-top: 1px solid var(--panel-border); padding-top: 8px; }

/* ---- Enrichment monitor ---- */
#enrich-panel {
  position: fixed;
  top: 64px;
  right: 16px;
  z-index: 25;
  width: 300px;
  max-height: 78vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 14px 14px 12px;
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
}
#enrich-panel.hidden { display: none; }
#enrich-panel h3 { margin: 0 0 8px; font-size: 13px; }
#enrich-close {
  position: absolute; top: 8px; right: 10px;
  border: none; background: rgba(255,255,255,0.06); color: var(--text);
  width: 24px; height: 24px; border-radius: 6px; cursor: pointer; font-size: 16px; line-height: 1;
}
.enrich-state { font-size: 12.5px; font-weight: 600; margin-bottom: 8px; }
.enrich-state.run { color: var(--accent-2); }
.enrich-state.err { color: var(--err); }
.enrich-bar { height: 7px; background: rgba(255,255,255,0.08); border-radius: 5px; overflow: hidden; }
#enrich-fill { height: 100%; width: 0%; background: var(--accent-2); transition: width 0.4s ease; }
.enrich-meta { font-size: 11.5px; color: var(--muted); margin: 7px 0 10px; line-height: 1.45; }
.enrich-lessons { font-size: 12px; margin: 0 0 10px; }
.lessons-sum { color: #cdd9e8; padding: 7px 9px; background: rgba(255,255,255,0.04); border: 1px solid var(--panel-border); border-radius: 8px; }
.lessons-sum .muted { color: var(--muted); }
.lessons-sum b.pend { color: var(--accent); }
.lessons-pending { margin-top: 6px; font-size: 11px; }
.lessons-pending summary { cursor: pointer; color: var(--muted); }
.lessons-pending summary:hover { color: var(--text); }
.lessons-pending ul { margin: 6px 0 0; padding-left: 16px; max-height: 160px; overflow: auto; color: #b9c6d6; line-height: 1.5; }
.enrich-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.enrich-actions button {
  flex: 1; padding: 7px; font-size: 12px; font-weight: 600; cursor: pointer;
  border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
.enrich-actions button.secondary { background: #fff; color: var(--accent); }
.enrich-actions button:disabled { opacity: 0.5; cursor: default; }
.enrich-log { font-size: 11px; line-height: 1.5; max-height: 32vh; overflow-y: auto; }
.enrich-log .row { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; border-top: 1px solid rgba(255,255,255,0.05); }
.enrich-log .ok { color: #bfe6d4; }
.enrich-log .bad { color: #f0b3b1; }
.enrich-log .t { color: var(--muted); flex: none; }
.enrich-note { font-size: 10.5px; color: var(--muted); line-height: 1.45; margin: 10px 0 0; }

/* ---- HUD + toast ---- */
#hud {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 10;
  text-align: right;
  font-size: 11.5px;
  color: var(--muted);
  pointer-events: none;
}
#hud .hint { display: block; margin-top: 3px; opacity: 0.8; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 30;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  backdrop-filter: blur(6px);
  transition: opacity 0.25s;
}
#toast.hidden { opacity: 0; pointer-events: none; }

/* node hover tooltip (3d-force-graph injects .scene-tooltip) */
.scene-tooltip { font-family: inherit !important; }
.tt b { font-size: 13px; }
.tt span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }

/* Overview sub-labels (topic counts under top-level labels) */
.node-label .lbl-sub { display: block; font-size: 10px; font-weight: 500; color: #9fb2c8; margin-top: 1px; }

/* ---- Colour legend ---- */
#legend { position: fixed; left: 16px; bottom: 16px; z-index: 9; font-size: 11.5px; }
body.cmd-open #legend { left: 268px; } /* sit beside the edit panel when it's open */
#legend-toggle {
  font: inherit; font-size: 11.5px; color: var(--muted); cursor: pointer;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 8px; padding: 6px 10px;
}
#legend-toggle:hover { color: var(--text); border-color: var(--accent); }
#legend-body {
  margin-top: 8px; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 10px 12px; backdrop-filter: blur(6px); display: grid; grid-template-columns: auto auto; gap: 4px 18px;
}
#legend.collapsed #legend-body { display: none; }
.lg-row { display: flex; align-items: center; gap: 7px; color: #c8d4e2; }
.lg-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.lg-line { width: 16px; height: 3px; border-radius: 2px; flex: none; }
.lg-head { grid-column: 1 / -1; font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin-top: 4px; }

/* ---- Next-up panel ---- */
#next-panel {
  position: fixed; top: 64px; right: 16px; z-index: 25; width: 300px; max-height: 70vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 14px; backdrop-filter: blur(8px); box-shadow: 0 10px 30px rgba(0,0,0,0.45);
}
#next-panel.hidden { display: none; }
#next-panel h3 { margin: 0 0 6px; font-size: 13px; }
#next-close { position: absolute; top: 8px; right: 10px; border: none; background: rgba(255,255,255,0.06); color: var(--text); width: 24px; height: 24px; border-radius: 6px; cursor: pointer; font-size: 16px; line-height: 1; }
.next-hint { font-size: 11px; color: var(--muted); margin: 0 0 10px; line-height: 1.45; }
.next-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px; cursor: pointer; font-size: 12.5px; }
.next-row:hover { background: rgba(54,197,240,0.12); }
.next-row .cdot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.next-row .nx-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.next-row .nx-note { color: var(--muted); font-size: 10.5px; flex: none; }

/* ---- Quiz overlay ---- */
#quiz { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(4,7,13,0.62); backdrop-filter: blur(3px); }
#quiz.hidden { display: none; }
.quiz-q { font-size: 15px; line-height: 1.55; color: #eaf1f8; margin: 6px 0 4px; }
.quiz-a { margin-top: 12px; font-size: 13.5px; line-height: 1.55; color: #bfe6d4; background: rgba(39,211,162,0.08); border: 1px solid rgba(39,211,162,0.35); border-radius: 9px; padding: 10px 12px; }
.quiz-a.hidden { display: none; }
#quiz-next.hidden, #quiz-reveal.hidden { display: none; }

/* Pathfinder chain in the detail panel */
.d-pathfind { margin: 12px 0 4px; padding: 10px 11px; background: rgba(255,212,121,0.07); border: 1px solid rgba(255,212,121,0.3); border-radius: 9px; }
.d-pathfind .pf-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.6px; color: #ffd479; margin-bottom: 7px; }
.d-pathfind .pf-pred { font-size: 10.5px; color: var(--muted); margin: 0 2px; }

/* =========================================================================
   Phones (≤700px): search row pinned on top, panels become bottom sheets,
   most controls collapse under ⋯, one sheet open at a time.
   ========================================================================= */
@media (max-width: 700px) {
  /* ---- Top: full-width control row, brand + breadcrumb underneath ---- */
  #controls {
    top: 10px; left: 10px; right: 10px;
    z-index: 26; /* above the bottom sheets, so the ⋯ menu is never buried */
    flex-wrap: nowrap; gap: 6px;
  }
  body.detail-open #controls { right: 10px; } /* the sheet is below, not beside */
  #search-wrap { flex: 1; min-width: 0; }
  #controls input { width: 100%; min-height: 42px; font-size: 16px; } /* 16px: stops iOS zoom-on-focus */
  #controls > button { min-height: 42px; min-width: 42px; padding: 7px 10px; font-size: 15px; flex: none; }
  #btn-up .txt, #btn-reset .txt { display: none; } /* icon-only Up / Home */
  #search-results { width: calc(100vw - 20px); max-height: 50vh; }
  .sr-item { padding: 11px 10px; font-size: 14px; }

  #topbar { top: 62px; left: 12px; max-width: calc(100vw - 24px); }
  .brand { font-size: 14px; }
  #breadcrumb { font-size: 11.5px; }

  /* ---- ⋯ overflow menu ---- */
  #btn-more { display: inline-block; }
  #ctrl-menu {
    display: none;
    position: absolute; top: calc(100% + 8px); right: 0;
    flex-direction: column; gap: 6px;
    min-width: 176px; padding: 8px;
    background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px;
    box-shadow: 0 14px 40px rgba(0,0,0,0.5); backdrop-filter: blur(8px);
  }
  #ctrl-menu.open { display: flex; }
  #ctrl-menu button { width: 100%; min-height: 44px; text-align: left; font-size: 14px; }

  /* ---- Bottom sheets (shared grab handle) ---- */
  #detail::before, #cmd::before, #next-panel::before, #enrich-panel::before {
    content: ""; display: block; width: 42px; height: 4px; border-radius: 2px;
    background: rgba(255,255,255,0.28); margin: 0 auto 12px;
  }

  #detail {
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; height: 58vh;
    border-left: none; border-top: 1px solid var(--panel-border);
    border-radius: 16px 16px 0 0;
    padding: 12px 16px calc(26px + env(safe-area-inset-bottom));
    box-shadow: 0 -14px 44px rgba(0,0,0,0.5);
  }
  #detail.hidden { transform: translateY(110%); }
  #detail-close { width: 36px; height: 36px; }
  #detail-tools button { padding: 10px 14px; font-size: 13px; }
  .chip { padding: 8px 11px; font-size: 13px; }
  .d-title { font-size: 18px; }

  #cmd {
    left: 0; right: 0; bottom: 0; width: 100%;
    max-height: 58vh; overflow-y: auto;
    border-left: none; border-right: none; border-bottom: none;
    border-radius: 16px 16px 0 0;
    padding: 12px 16px calc(22px + env(safe-area-inset-bottom));
    font-size: 13px;
  }
  body.detail-open #cmd { display: none; } /* one sheet at a time */
  .cmd-btn { padding: 12px; font-size: 13.5px; }
  .cmd-more-toggle { padding: 10px 8px; font-size: 12.5px; }
  .cmd-undo { padding: 11px; }
  #cmd-collapse { width: 34px; height: 34px; font-size: 18px; }

  #next-panel, #enrich-panel {
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; max-height: 58vh;
    border-left: none; border-right: none; border-bottom: none;
    border-radius: 16px 16px 0 0;
    padding-bottom: calc(22px + env(safe-area-inset-bottom));
  }
  body.detail-open #next-panel, body.detail-open #enrich-panel { right: 0; }
  .next-row { padding: 11px 10px; font-size: 14px; }
  #next-close, #enrich-close { width: 34px; height: 34px; }

  /* ---- Legend + HUD: hidden while a sheet covers their corner ---- */
  body.cmd-open #legend { left: 16px; }
  #legend-body { max-width: calc(100vw - 32px); }
  body.detail-open #legend, body.cmd-open #legend { display: none; }
  #hud { right: 10px; bottom: 10px; font-size: 10.5px; max-width: 62vw; }
  body.detail-open #hud, body.cmd-open #hud { display: none; }

  /* ---- Node labels: smaller type (the count cap lives in app.js) ---- */
  .node-label { font-size: 10.5px; }
  .node-label.lvl-root { font-size: 15px; }
  .node-label.lvl-provider, .node-label.lvl-domain { font-size: 13px; }
  .node-label.lvl-service { font-size: 12px; }
  .node-label.lvl-course { font-size: 11.5px; }
  .node-label.lvl-feature, .node-label.lvl-concept { font-size: 10.5px; }
  .node-label.lvl-video { font-size: 10px; }
  .node-label .lbl-sub { font-size: 9px; }

  /* ---- Modals + inputs ---- */
  .preview-card { width: calc(100vw - 24px); max-height: 86vh; padding: 16px; }
  .preview-actions { flex-wrap: wrap; }
  .pv-apply, .pv-discard { flex: 1; min-height: 44px; padding: 12px 16px; }
  #syn-input, #pair-input, #instruct-input, #setparent-input, #dt-path-box input { font-size: 16px; }
}

/* ---------------------------------------------------------------------------
   Read-only public build. build-public.mjs stamps data-mode="readonly" on
   <html> in the exported copy only — local dev (web/index.html) never has
   this attribute, so none of this applies there.
--------------------------------------------------------------------------- */
html[data-mode="readonly"] #btn-cmd,
html[data-mode="readonly"] #btn-enrich,
html[data-mode="readonly"] #btn-rebuild,
html[data-mode="readonly"] #dt-quiz,
html[data-mode="readonly"] #cmd,
html[data-mode="readonly"] #enrich-panel {
  display: none !important;
}
/* The edit panel normally nudges the legend aside when open (see line ~461);
   it's hidden here, so cancel the nudge or the legend leaves a dead gap. */
html[data-mode="readonly"] body.cmd-open #legend { left: 16px; }

#ro-badge {
  display: none;
}
html[data-mode="readonly"] #ro-badge {
  display: inline-block;
  margin-top: 7px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--muted);
  background: rgba(54, 197, 240, 0.12);
  border: 1px solid rgba(54, 197, 240, 0.35);
  border-radius: 20px;
  padding: 2px 9px;
}
