@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-panel: rgba(20, 22, 34, 0.96);
  --text-primary: #e6e6e6;
  --text-muted: #8b949e;
  --text-dimmed: #6e7681;
  --border-subtle: rgba(240, 246, 252, 0.1);
  --d-foundations: #A78BFA;
  --d-category-theory: #5B8DEF;
  --d-algebra: #EF5B5B;
  --d-homological-algebra: #EFB85B;
  --d-topology: #5BEF7B;
  --d-algebraic-topology: #5BD3EF;
  --d-geometry: #B8EF5B;
  --d-algebraic-geometry: #EF5BD3;
  --panel-width: 440px;
  --header-height: 60px;
  --tspeed: 260ms;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body.graph-page { overflow: hidden; }

#header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-height);
  background: var(--bg-secondary); border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; z-index: 100; gap: 20px;
}
.header-left { display: flex; flex-direction: column; justify-content: center; flex-shrink: 0; gap: 2px; }
.header-title { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.header-title a { color: var(--text-primary); text-decoration: none; }
.header-subtitle { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.header-controls { display: flex; align-items: center; gap: 14px; }

.view-nav { display: flex; gap: 4px; background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-subtle); border-radius: 8px; padding: 3px; }
.view-nav a { padding: 5px 14px; border-radius: 6px; font-size: 12px; font-weight: 600;
  color: var(--text-muted); text-decoration: none; transition: all var(--tspeed) ease; }
.view-nav a:hover { color: var(--text-primary); }
.view-nav a.active { background: rgba(91,141,239,0.25); color: var(--text-primary); }

.search-container { position: relative; min-width: 200px; max-width: 300px; }
.search-input { width: 100%; padding: 8px 32px 8px 14px; background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-subtle); border-radius: 8px; color: var(--text-primary);
  font-size: 13px; font-family: var(--font); outline: none; transition: border-color var(--tspeed) ease; }
.search-input::placeholder { color: var(--text-dimmed); }
.search-input:focus { border-color: rgba(91,141,239,0.5); background: rgba(255,255,255,0.09); }
.search-clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-dimmed); font-size: 16px; cursor: pointer; }
.search-clear:hover { color: var(--text-primary); }

.domain-filters { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.domain-toggle { padding: 5px 12px; border-radius: 20px; font-size: 11px; font-weight: 600;
  font-family: var(--font); cursor: pointer; transition: all var(--tspeed) ease; border: 1.5px solid;
  background: transparent; display: inline-flex; align-items: center; gap: 6px; }
.domain-toggle .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.domain-toggle:not(.active) { opacity: 0.45; }
.domain-toggle:not(.active):hover { opacity: 0.8; }

/* ===== Graph ===== */
#graph-container { position: fixed; top: var(--header-height); left: 0; right: 0; bottom: 0; overflow: hidden; }
#graph-svg { width: 100%; height: 100%; display: block; cursor: grab; }
#graph-svg:active { cursor: grabbing; }
.node circle { cursor: pointer; transition: stroke-width 120ms ease; }
.node text { font-size: 11px; fill: var(--text-primary); pointer-events: none;
  text-anchor: middle; paint-order: stroke; stroke: var(--bg-primary); stroke-width: 3px; font-weight: 500; }
.link { stroke-opacity: 0.28; transition: stroke-opacity var(--tspeed) ease; }
.link.dimmed { stroke-opacity: 0.05; }
.node.dimmed { opacity: 0.16; }
.arrow { fill: var(--text-dimmed); }

.tooltip { position: absolute; padding: 10px 14px; background: rgba(22,27,34,0.96);
  border: 1px solid var(--border-subtle); border-radius: 8px; font-size: 12px; pointer-events: none;
  max-width: 300px; z-index: 300; backdrop-filter: blur(8px); line-height: 1.5; opacity: 0;
  transition: opacity 120ms ease; box-shadow: 0 4px 16px rgba(0,0,0,0.35); }
.tooltip.show { opacity: 1; }
.tooltip-title { font-weight: 600; margin-bottom: 3px; }
.tooltip-body { color: var(--text-muted); font-size: 11px; }

/* ===== Side panel (graph) ===== */
.side-panel { position: fixed; top: 0; right: 0; bottom: 0; width: var(--panel-width);
  background: var(--bg-panel); border-left: 3px solid var(--text-muted); transform: translateX(100%);
  transition: transform var(--tspeed) ease; z-index: 200; display: flex; flex-direction: column;
  overflow: hidden; backdrop-filter: blur(12px); }
.side-panel.visible { transform: translateX(0); }
.panel-close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(240,246,252,0.2); border-radius: 8px;
  color: var(--text-primary); cursor: pointer; font-size: 18px; line-height: 1; z-index: 1; }
.panel-close:hover { background: rgba(255,255,255,0.18); }
.panel-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
  border-radius: 12px; font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; margin: 22px 24px 10px; }
.panel-badge .dot { width: 8px; height: 8px; border-radius: 50%; }
.panel-content { padding: 0 24px 28px; overflow-y: auto; flex: 1; }
.panel-content::-webkit-scrollbar { width: 6px; }
.panel-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }

/* ===== Markdown body (shared by panel + wiki) ===== */
.md-body { font-size: 14.5px; line-height: 1.7; color: var(--text-muted); }
.md-body h1 { font-size: 24px; color: #fff; letter-spacing: -0.02em; margin: 4px 0 14px; }
.md-body h2 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-dimmed); margin: 22px 0 8px; }
.md-body p { margin-bottom: 10px; }
.md-body strong { color: var(--text-primary); font-weight: 600; }
.md-body em { color: var(--text-primary); font-style: italic; }
.md-body blockquote { border-left: 3px solid var(--accent, var(--text-muted)); padding: 4px 0 4px 16px;
  margin: 0 0 18px; color: var(--text-primary); font-size: 16px; line-height: 1.55; font-weight: 500; }
/* Backtick spans in the entries are math, not code — set them in a serif
   stack with real math-glyph coverage (superscripts, double-struck, script),
   matching the visuals. Menlo/monospace lacks these glyphs entirely. */
.md-body code { background: rgba(255,255,255,0.08); padding: 1px 6px; border-radius: 4px;
  font-family: 'STIX Two Math', 'STIX Two Text', 'Cambria Math', 'Times New Roman', serif;
  font-size: 1em; color: #edeef2; }
.md-body pre { background: rgba(255,255,255,0.04); border: 1px solid var(--border-subtle);
  border-radius: 8px; padding: 12px 14px; overflow-x: auto; margin: 0 0 14px; }
.md-body pre code { background: none; padding: 0; font-size: 15px; line-height: 1.6; }
.md-body ul { margin: 0 0 12px; padding-left: 20px; }
.md-body li { margin-bottom: 6px; }
.md-body a { color: #7aa7ff; text-decoration: none; border-bottom: 1px dotted rgba(122,167,255,0.4); }
.md-body a:hover { border-bottom-style: solid; }

/* ===== Continuous reading, cross-view + site links ===== */
.term-block { border-top: 1px solid var(--border-subtle); padding: 40px 0 48px; }
.term-block:first-child { border-top: none; padding-top: 8px; }
.related-h { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-dimmed); margin: 26px 0 8px; }
.cross-view { float: right; font-size: 11px; color: var(--text-dimmed); text-decoration: none;
  border: 1px solid var(--border-subtle); padding: 3px 10px; border-radius: 12px;
  margin: 6px 0 8px 14px; white-space: nowrap;
  transition: color var(--tspeed) ease, border-color var(--tspeed) ease; }
.cross-view:hover { color: #7aa7ff; border-color: rgba(122,167,255,0.4); }
.site-link { font-size: 12px; color: var(--text-dimmed); text-decoration: none; white-space: nowrap; }
.site-link:hover { color: var(--text-primary); }

/* ===== Term article extras (badge, prereqs, visuals, lifted sections) ===== */
.term-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: -6px 0 14px; }
.standing-badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 10px;
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--standing); background: color-mix(in srgb, var(--standing) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--standing) 40%, transparent); cursor: help; }
.term-aliases { font-size: 12px; color: var(--text-dimmed); }
.term-aliases span { background: rgba(255,255,255,0.05); padding: 2px 8px; border-radius: 6px; margin-left: 6px; }
.prereq-row { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; }
.prereq-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dimmed); margin-right: 2px; }
.prereq-chip { font-size: 12px; color: var(--accent, var(--text-muted)); cursor: pointer;
  background: rgba(255,255,255,0.05); border: 1px solid color-mix(in srgb, var(--accent, #8b949e) 35%, transparent);
  padding: 2px 10px; border-radius: 12px; transition: background var(--tspeed) ease; }
.prereq-chip:hover { background: color-mix(in srgb, var(--accent, #8b949e) 18%, transparent); }
.term-visual { margin: 0 0 18px; background: #fff; border-radius: 10px; padding: 10px;
  border: 1px solid var(--border-subtle); }
.term-visual img { display: block; width: 100%; height: auto; border-radius: 6px; }
.term-extra { margin: 14px 0 0; border: 1px solid var(--border-subtle); border-radius: 8px;
  background: rgba(255,255,255,0.02); }
.term-extra summary { padding: 8px 14px; font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-dimmed); cursor: pointer; user-select: none; }
.term-extra summary:hover { color: var(--text-muted); }
.term-extra[open] summary { border-bottom: 1px solid var(--border-subtle); }
.term-extra .md-body { padding: 10px 14px 4px; font-size: 13.5px; }

/* ===== Relations list ===== */
.relations { margin-top: 8px; }
.relation-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 6px;
  font-size: 13px; color: var(--text-primary); cursor: pointer; transition: background var(--tspeed) ease; }
.relation-item:hover { background: rgba(255,255,255,0.06); }
.relation-item .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.relation-item .rel-target { font-weight: 500; }
.relation-item .rel-verb { font-size: 10px; color: var(--text-dimmed); margin-left: auto;
  text-transform: uppercase; letter-spacing: 0.04em; background: rgba(255,255,255,0.05);
  padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.relation-dir-in .rel-verb::before { content: "← "; }

/* ===== Legend + stats ===== */
.legend { position: fixed; bottom: 20px; left: 20px; background: rgba(22,27,34,0.85);
  border: 1px solid var(--border-subtle); border-radius: 10px; padding: 12px 16px; z-index: 50;
  backdrop-filter: blur(8px); }
.legend-title { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-dimmed); margin-bottom: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-muted);
  margin-bottom: 4px; cursor: default; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.stats-overlay { position: fixed; bottom: 20px; right: 20px; background: rgba(22,27,34,0.6);
  border: 1px solid var(--border-subtle); border-radius: 8px; padding: 10px 14px; z-index: 50;
  backdrop-filter: blur(8px); }
.stats-row { display: flex; justify-content: space-between; gap: 16px; font-size: 11px; line-height: 1.8; }
.stats-label { color: var(--text-dimmed); }
.stats-value { color: var(--text-muted); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ===== Wiki / flat terms view ===== */
.wiki-layout { display: grid; grid-template-columns: 320px 1fr; height: 100vh;
  padding-top: var(--header-height); }
.wiki-sidebar { border-right: 1px solid var(--border-subtle); overflow-y: auto; padding: 18px 0 60px; }
.wiki-domain-group { margin-bottom: 14px; }
.wiki-domain-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  padding: 4px 24px; display: flex; align-items: center; gap: 8px; }
.wiki-domain-label .dot { width: 8px; height: 8px; border-radius: 50%; }
.wiki-term { padding: 6px 24px 6px 40px; font-size: 14px; color: var(--text-muted); cursor: pointer;
  border-left: 2px solid transparent; transition: all 160ms ease; }
.wiki-term:hover { color: var(--text-primary); background: rgba(255,255,255,0.04); }
.wiki-term.active { color: #fff; background: rgba(91,141,239,0.12); border-left-color: var(--accent, #5B8DEF); }
.wiki-term .essence { display: block; font-size: 11px; color: var(--text-dimmed); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wiki-main { overflow-y: auto; padding: 40px 56px 80px; }
.wiki-reading { max-width: 720px; margin: 0 auto; }
.wiki-empty { color: var(--text-dimmed); font-size: 14px; text-align: center; margin-top: 80px; }
.wiki-aliases { font-size: 12px; color: var(--text-dimmed); margin-bottom: 18px; }
.wiki-aliases span { background: rgba(255,255,255,0.05); padding: 2px 8px; border-radius: 6px; margin-right: 6px; }
.wiki-sidebar::-webkit-scrollbar, .wiki-main::-webkit-scrollbar { width: 8px; }
.wiki-sidebar::-webkit-scrollbar-thumb, .wiki-main::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

@media (max-width: 900px) {
  .wiki-layout { grid-template-columns: 1fr; }
  .wiki-sidebar { display: none; }
  .wiki-sidebar.open { display: block; position: fixed; inset: var(--header-height) 0 0 0; z-index: 80; background: var(--bg-primary); }
  .wiki-main { padding: 24px; }
  .side-panel { width: 100%; }
  .domain-filters { display: none; }
}
