:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --border: #dcdcd7;
  --edge: #b9b9b3;
  --accent: #d6001c;          /* RPI red */
  --accent-soft: #fde8ea;
  --anc: #2563eb;             /* prerequisite chain */
  --anc-soft: #e6eefe;
  --desc: #0f8a5f;            /* unlocked courses */
  --desc-soft: #e2f4ec;
  --l1: #f59e0b;
  --l2: #10b981;
  --l4: #3b82f6;
  --l6: #8b5cf6;
  --l9: #64748b;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131315; --surface: #1d1d20; --surface-2: #26262a; --text: #ececee; --muted: #9a9aa2;
    --border: #34343a; --edge: #4c4c54; --accent: #ff4d5e; --accent-soft: #3a1a1f;
    --anc: #6ea0ff; --anc-soft: #1a2640; --desc: #3fcf98; --desc-soft: #15302a;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131315; --surface: #1d1d20; --surface-2: #26262a; --text: #ececee; --muted: #9a9aa2;
  --border: #34343a; --edge: #4c4c54; --accent: #ff4d5e; --accent-soft: #3a1a1f;
  --anc: #6ea0ff; --anc-soft: #1a2640; --desc: #3fcf98; --desc-soft: #15302a;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); flex: none;
  -webkit-mask: none; position: relative; }
.logo::after { content: ""; position: absolute; inset: 7px; border: 2px solid #fff; border-radius: 50%; border-right-color: transparent; }
h1 { font-size: 15px; margin: 0; letter-spacing: -.01em; }
.sub { margin: 0; font-size: 12px; color: var(--muted); }

.search { position: relative; flex: 1 1 260px; max-width: 380px; }
.search svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%);
  fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; pointer-events: none; }
.search input {
  width: 100%; padding: 7px 10px 7px 32px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); outline: none;
}
.search input:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
#search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  max-height: 340px; overflow: auto;
}
#search-results li { padding: 6px 8px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
#search-results li[aria-selected="true"], #search-results li:hover { background: var(--surface-2); }
#search-results .code { font-weight: 600; white-space: nowrap; }
#search-results .title { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#search-results .none { color: var(--muted); cursor: default; }

.filters { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-left: auto; }
.group { display: flex; align-items: center; gap: 8px; }
.label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.chips { display: flex; gap: 4px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 3px 10px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.chip[aria-pressed="false"] { color: var(--muted); background: transparent; }
.chip[aria-pressed="false"] .dot { background: transparent !important; outline: 1.5px solid var(--edge); }
select { padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.switch { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; }
.switch input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 5px 12px; cursor: pointer; }
.filters-toggle { display: none; }

/* ---------- stage ---------- */
main { position: relative; flex: 1; min-height: 0; }
#graph { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; user-select: none; }
#graph.panning { cursor: grabbing; }

.link { transition: opacity .2s; animation: fade .35s ease-out; cursor: pointer; }
.edge { fill: none; stroke: var(--c, var(--edge)); stroke-width: 1.5; stroke-opacity: .6; transition: stroke-width .2s, stroke-opacity .2s; pointer-events: none; }
.hit { fill: none; stroke: transparent; stroke-width: 9; }
.edge.or { stroke-dasharray: 5 4; }
.edge.coreq { stroke-dasharray: 1.5 3.5; stroke-linecap: round; }
@keyframes fade { from { opacity: 0; } }

.node { cursor: pointer; transition: transform .45s cubic-bezier(.2, .7, .2, 1), opacity .2s; }
.node.entering { animation: fade .35s ease-out; }
.node rect.card { fill: var(--surface); stroke: var(--border); stroke-width: 1; rx: 8px; }
.node rect.stripe { rx: 2px; }
.node .code { font-weight: 650; font-size: 12.5px; fill: var(--text); }
.node .title { font-size: 11px; fill: var(--muted); }
.node.junction rect.card { rx: 9px; fill: var(--surface-2); stroke: var(--edge); }
.node.junction .jlabel { font-size: 10px; font-weight: 650; fill: var(--muted); letter-spacing: .02em; }
.node.external rect.card { fill: var(--surface-2); stroke-dasharray: 3 3; }
.node.stale .code { fill: var(--muted); }
.node:hover rect.card { stroke: var(--text); }
.node:focus { outline: none; }
.node:focus-visible rect.card { stroke: var(--accent); stroke-width: 2; }

/* selection highlighting */
.has-sel .node { opacity: .28; }
.has-sel .link { opacity: .12; }
.has-sel .node.sel, .has-sel .node.anc, .has-sel .node.desc { opacity: 1; }
.node.sel rect.card { stroke: var(--accent); stroke-width: 2.5; fill: var(--accent-soft); }
.node.anc rect.card { stroke: var(--anc); stroke-width: 1.5; fill: var(--anc-soft); }
.node.desc rect.card { stroke: var(--desc); stroke-width: 1.5; fill: var(--desc-soft); }
.has-sel .link.anc, .has-sel .link.desc { opacity: 1; }
.has-sel .link.anc .edge, .has-sel .link.desc .edge { stroke-width: 2.2; stroke-opacity: 1; }

/* hover: one course's direct links (wins over selection styling) */
#graph.has-hov .node { opacity: .25; }
#graph.has-hov .link { opacity: .07; }
#graph.has-hov .node.hov, #graph.has-hov .node.sel { opacity: 1; }
#graph.has-hov .link.hov { opacity: 1; }
#graph.has-hov .link.hov .edge { stroke-width: 2.6; stroke-opacity: 1; }

.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }

.pill {
  position: absolute; top: 12px; left: 12px;
  display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; border-radius: 999px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: 13px; white-space: nowrap; max-width: calc(100% - 24px); z-index: 2;
}
.pill span { overflow: hidden; text-overflow: ellipsis; }
.pill .icon-btn { width: 24px; height: 24px; background: transparent; border: none; color: inherit; font-size: 12px; }

.legend {
  position: absolute; left: 12px; bottom: 12px; display: flex; gap: 14px; flex-wrap: wrap; align-items: center;
  padding: 6px 12px; border-radius: 8px; background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border); font-size: 12px; color: var(--muted); backdrop-filter: blur(6px);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.ln { display: inline-block; width: 22px; border-top: 2px solid var(--muted); }
.ln.or { border-top-style: dashed; }
.ln.co { border-top-style: dotted; }
.jdot { font-style: normal; font-size: 10px; font-weight: 650; padding: 0 6px; border-radius: 9px; border: 1px solid var(--edge); background: var(--surface-2); }
.stats { padding-left: 10px; border-left: 1px solid var(--border); }

.zoom { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; cursor: pointer; font-size: 17px; line-height: 1;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- detail panel ---------- */
.panel {
  position: absolute; top: 12px; right: 12px; bottom: 12px; width: min(400px, calc(100% - 24px));
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  overflow: auto; padding: 20px 20px 24px; animation: slide .25s ease-out;
}
@keyframes slide { from { transform: translateX(16px); opacity: 0; } }
.panel .close { position: absolute; top: 12px; right: 12px; box-shadow: none; border-color: transparent; }
.panel .eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .05em; color: var(--accent); text-transform: uppercase; }
.panel h2 { font-size: 20px; line-height: 1.25; margin: 2px 32px 6px 0; letter-spacing: -.01em; }
.panel .meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.panel .actions { display: flex; gap: 8px; margin: 14px 0 4px; flex-wrap: wrap; }
.panel .btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 20px 0 8px; }
.panel p { margin: 0; }
.panel .desc { color: var(--text); }
.panel .note { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.panel .notice { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; font-size: 13px; color: var(--muted); margin-top: 12px; }

.tree { margin: 0; padding: 0; list-style: none; }
.tree .tree { padding-left: 12px; margin-top: 4px; border-left: 2px solid var(--border); }
.tree > li { margin: 4px 0; }
.tree .op { font-size: 12px; color: var(--muted); font-weight: 600; }
.crs {
  display: inline-flex; align-items: baseline; gap: 6px; padding: 3px 9px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); text-align: left; max-width: 100%;
}
.crs:hover { border-color: var(--text); }
.crs b { font-weight: 600; white-space: nowrap; }
.crs .t { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crs .g { font-size: 11px; color: var(--muted); background: var(--surface-2); padding: 0 5px; border-radius: 4px; white-space: nowrap; }
.crs-list { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.terms { display: flex; flex-wrap: wrap; gap: 4px; }
.terms span { font-size: 12px; background: var(--surface-2); border-radius: 5px; padding: 1px 7px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tags span { font-size: 12px; border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; }

.footer-note { position: absolute; right: 56px; bottom: 14px; font-size: 11px; color: var(--muted); }

/* ---------- small screens ---------- */
@media (max-width: 820px) {
  .topbar { gap: 10px; padding: 8px 12px; }
  .sub { display: none; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .filters-toggle { display: block; margin-left: auto; }
  .filters { display: none; order: 4; flex-basis: 100%; margin: 0; gap: 10px 16px; }
  .filters.open { display: flex; }
  .legend { display: none; }
  .panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 62%; animation-name: rise; }
  @keyframes rise { from { transform: translateY(16px); opacity: 0; } }
}
