:root {
  --bg: #f7f7f4;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #646a73;
  --line: #d9dbd6;
  --link: #9aa0a6;
  --related: #c2410c;
  --accent: #2f5fd0;
  --accent-soft: #e6edfb;
  --shadow: 0 8px 30px rgba(0, 0, 0, .12);
  --code-bg: #f1f2ef;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1d2024;
    --text: #e7e8ea;
    --muted: #9aa1ab;
    --line: #33373d;
    --link: #5b6169;
    --related: #fb923c;
    --accent: #7aa2ff;
    --accent-soft: #24304a;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
    --code-bg: #24272c;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }

.bar { position: fixed; inset: 0 0 auto 0; height: 56px; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); z-index: 20; }
.bar h1 { font-size: 17px; margin: 0; white-space: nowrap; }
.bar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.search { position: relative; flex: 1; max-width: 420px; }
.search input { width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.results { position: absolute; top: 42px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); max-height: 60vh; overflow: auto; }
.results button { display: block; width: 100%; text-align: left; padding: 8px 12px; border: 0; background: none; cursor: pointer; }
.results button:hover, .results button:focus { background: var(--accent-soft); outline: none; }
.toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; cursor: pointer; }

.btn { border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 7px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; font-size: 14px; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: wait; }
.icon-btn { border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--accent-soft); color: var(--text); }

main { position: fixed; inset: 56px 0 0 0; }
#map { position: absolute; inset: 0; }
#map svg { width: 100%; height: 100%; display: block; cursor: grab; }
#map svg:active { cursor: grabbing; }
.tree-link { fill: none; stroke: var(--link); stroke-width: 1.4px; }
.rel-link { fill: none; stroke: var(--related); stroke-width: 1.2px; stroke-dasharray: 5 4; opacity: .14; }
.rel-link.hot { opacity: .95; stroke-width: 2.2px; }
svg.has-selection .rel-link:not(.hot) { opacity: .05; }
.node circle { stroke-width: 2px; cursor: pointer; }
.node text { font-size: 13px; fill: var(--text); cursor: pointer; paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round; }
.node.kind-root text { font-size: 18px; font-weight: 700; }
.node.kind-area text { font-size: 15px; font-weight: 650; }
.node.kind-course text { font-size: 14px; font-weight: 600; }
.node.kind-section text { font-size: 12px; fill: var(--muted); }
.node.selected text { fill: var(--accent); font-weight: 700; }
.node.dim { opacity: .25; }
.node .badge { font-size: 10px; fill: var(--muted); stroke: none; }

.legend { position: absolute; left: 12px; bottom: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font-size: 12.5px; color: var(--muted); max-width: min(560px, calc(100% - 24px)); }
.legend span { display: inline-flex; align-items: center; gap: 6px; margin-right: 12px; white-space: nowrap; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend .dash { width: 18px; height: 0; border-top: 2px dashed var(--related); border-radius: 0; }
.status { position: absolute; right: 12px; bottom: 12px; font-size: 12px; color: var(--muted); }

.panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(760px, 52vw); background: var(--surface);
  border-left: 1px solid var(--line); box-shadow: var(--shadow); overflow-y: auto; padding: 14px 26px 60px; z-index: 10; }
.panel-head { display: flex; align-items: flex-start; gap: 10px; position: sticky; top: -14px; background: var(--surface); padding: 8px 0; z-index: 2; }
.panel-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.crumbs { font-size: 13px; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; cursor: pointer; }
.crumbs a:hover { color: var(--accent); }
.panel h2 { margin: 6px 0 10px; font-size: 24px; line-height: 1.25; }
.sections { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.sections a { font-size: 12.5px; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--text); text-decoration: none; cursor: pointer; }

.note { overflow-wrap: anywhere; }
.note h2, .note h3, .note h4 { margin: 1.4em 0 .4em; line-height: 1.3; scroll-margin-top: 70px; }
.note h3 { font-size: 19px; }
.note h4 { font-size: 16px; }
.note p { margin: .45em 0; }
.note ul, .note ol { padding-left: 1.4em; margin: .35em 0; }
.note li { margin: .15em 0; }
.note code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.note pre { background: var(--code-bg); padding: 12px 14px; border-radius: 8px; overflow-x: auto; }
.note pre code { background: none; padding: 0; font-size: 13px; }
.note .math-block { overflow-x: auto; margin: .6em 0; }
.note .tbl { overflow-x: auto; }
.note table { border-collapse: collapse; margin: .6em 0; font-size: 14px; }
.note th, .note td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; vertical-align: top; }
.note blockquote { border-left: 3px solid var(--line); margin: .6em 0; padding-left: 12px; color: var(--muted); }
.note .callout { background: var(--accent-soft); padding: 10px 14px; border-radius: 8px; margin: .6em 0; }
.note img { max-width: 100%; border-radius: 6px; }
.note a { color: var(--accent); }
.note a.mention { font-weight: 550; text-decoration: none; border-bottom: 1px solid currentColor; cursor: pointer; }
.note hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.muted { color: var(--muted); }

.links-box { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 12px; }
.links-box h3, .edit-box h3 { font-size: 15px; margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips a { font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; color: var(--text); cursor: pointer; }
.chips a:hover { border-color: var(--accent); color: var(--accent); }

.edit-box { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; }
.edit-box label { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.edit-box select, .edit-box textarea, .edit-box input, dialog input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.edit-box textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.hint { font-size: 12.5px; color: var(--muted); }
.newpage summary { cursor: pointer; color: var(--accent); font-size: 14px; margin: 6px 0; }
.newpage { display: grid; gap: 8px; }
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); padding: 18px 20px; width: min(360px, 92vw); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h3 { margin: 0 0 4px; }
.err { color: #c0392b; font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 16px; border-radius: 8px; font-size: 14px; z-index: 50; }

@media (max-width: 760px) {
  .bar { gap: 8px; padding: 0 10px; }
  .bar h1 { display: none; }
  .toggle { display: none; }
  .panel { width: 100%; padding: 10px 16px 60px; }
  .legend { display: none; }
}
