/* ============================================================
   NSM Dictionary — Phaistos-inspired theme
   black void · cream highlight · glassmorphism · warm prime glow
   ============================================================ */
:root {
  --bg:        #050507;
  --bg-2:      #0a0a0f;
  --ink:       #f4f1ea;
  --ink-dim:   rgba(244, 241, 234, 0.55);
  --ink-faint: rgba(244, 241, 234, 0.32);
  --cream:     #fff5e6;
  --line:      rgba(255, 255, 255, 0.10);
  --line-soft: rgba(255, 255, 255, 0.06);
  --glass:     rgba(255, 255, 255, 0.04);
  --glass-2:   rgba(255, 255, 255, 0.06);
  --good:      #d9c46a;   /* gold */
  --good-cyan: #7fe3c0;   /* teal-gold for strong good */
  --bad:       #e0566a;   /* crimson */
  --amber:     #e6b15e;   /* neutral */
  --radius:    14px;
  --maxw:      820px;
  --header-h:  62px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  background: radial-gradient(1200px 800px at 50% -10%, #11111a 0%, var(--bg) 60%, #000 100%);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overflow-x: hidden;
}
::selection { background: rgba(255, 245, 230, 0.18); }
a { color: inherit; text-decoration: none; }

/* ---------- header ---------- */
header.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--header-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 22px; z-index: 50;
  background: rgba(5, 5, 7, 0.72);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: baseline; gap: 10px; cursor: pointer; user-select: none; }
.brand .mark {
  font-family: 'Spectral', Georgia, serif; font-weight: 600; font-size: 22px;
  letter-spacing: .02em; color: var(--cream);
}
.brand .mark em { font-style: italic; color: var(--good); }
.brand .sub { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); }

.search-wrap { flex: 1; display: flex; justify-content: center; }
.search {
  position: relative; width: min(520px, 100%);
}
.search input {
  width: 100%; height: 38px; padding: 0 38px 0 38px;
  background: var(--glass); border: 1px solid var(--line);
  border-radius: 999px; color: var(--ink); font-size: 14.5px; font-family: inherit;
  outline: none; transition: border-color .2s, background .2s;
}
.search input:focus { border-color: rgba(255, 245, 230, .35); background: var(--glass-2); }
.search input::placeholder { color: var(--ink-faint); }
.search .icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-faint); pointer-events: none; }
.search .count { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--ink-faint); pointer-events: none; }

/* mode toggle */
.toggle { display: flex; background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.toggle button {
  appearance: none; border: 0; background: transparent; color: var(--ink-dim);
  font-family: inherit; font-size: 12.5px; font-weight: 500; letter-spacing: .03em;
  padding: 6px 16px; border-radius: 999px; cursor: pointer; transition: .2s;
}
.toggle button.active { background: var(--cream); color: #14110b; }

/* ---------- layout shells ---------- */
main { padding-top: var(--header-h); }
/* base-hide both views with ID specificity so the mode rules below always win */
#read-view, #graph-view { display: none; }
body[data-mode="read"]  #read-view  { display: grid; }
body[data-mode="graph"] #graph-view { display: block; }

/* ============================================================
   READ MODE  — Oxford / Wikipedia hybrid
   ============================================================ */
#read-view { grid-template-columns: 280px 1fr; min-height: calc(100vh - var(--header-h)); }

/* index rail */
.rail {
  border-right: 1px solid var(--line-soft); padding: 18px 0 60px;
  height: calc(100vh - var(--header-h)); position: sticky; top: var(--header-h);
  overflow-y: auto;
}
.rail h3 { font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-faint);
  padding: 0 22px; margin: 14px 0 8px; }
.rail .item {
  display: flex; align-items: center; gap: 9px; padding: 7px 22px; cursor: pointer;
  font-size: 14px; color: var(--ink-dim); border-left: 2px solid transparent; transition: .15s;
}
.rail .item:hover { color: var(--ink); background: var(--glass); }
.rail .item.active { color: var(--cream); border-left-color: var(--good); background: var(--glass); }
.rail .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 8px currentColor; }
.rail .item .pos { margin-left: auto; font-size: 10px; color: var(--ink-faint); letter-spacing: .02em; }
.rail .empty { padding: 16px 22px; color: var(--ink-faint); font-size: 13px; }

/* reading pane */
.pane { padding: 44px clamp(22px, 5vw, 70px) 120px; max-width: calc(var(--maxw) + 140px); }
.entry-head { display: flex; align-items: flex-start; gap: 18px; flex-wrap: wrap; }
.headword {
  font-family: 'Spectral', Georgia, serif; font-weight: 500; font-size: clamp(40px, 6vw, 60px);
  line-height: 1.02; letter-spacing: -.01em; color: var(--cream);
}
.valbar { margin-top: 14px; width: 200px; }
.valbar .track { height: 5px; border-radius: 99px; background: linear-gradient(90deg, var(--bad), var(--amber), var(--good-cyan)); opacity: .5; position: relative; }
.valbar .knob { position: absolute; top: 50%; width: 12px; height: 12px; border-radius: 50%; transform: translate(-50%, -50%); box-shadow: 0 0 12px currentColor, 0 0 2px #000; border: 2px solid #0a0a0f; }
.valbar .lbls { display: flex; justify-content: space-between; font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); margin-top: 6px; }

.meta-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.pos-tag { font-style: italic; color: var(--ink-dim); font-family: 'Spectral', serif; font-size: 16px; }
.lane {
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase; padding: 3px 9px;
  border-radius: 99px; border: 1px solid var(--line);
}
.lane.gold   { color: var(--good); border-color: rgba(217,196,106,.4); background: rgba(217,196,106,.08); }
.lane.sourced{ color: var(--good-cyan); border-color: rgba(127,227,192,.35); background: rgba(127,227,192,.07); }

.section-label { font-size: 10.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-faint);
  margin: 40px 0 14px; display: flex; align-items: center; gap: 12px; }
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--line-soft); }

/* the explication itself */
.explication {
  font-family: 'Spectral', Georgia, serif; font-size: 21px; line-height: 1.7; color: var(--ink);
  border-left: 2px solid rgba(217,196,106,.35); padding-left: 22px;
}
.explication .line { margin: 2px 0; }
.explication .line.indent { padding-left: 26px; color: var(--ink-dim); }

/* clickable tokens */
.tok { border-radius: 4px; padding: 0 2px; transition: background .15s; cursor: pointer; white-space: nowrap; }
.tok.prime {
  font-variant: small-caps; letter-spacing: .03em; font-weight: 600; font-family: 'Inter', sans-serif;
  font-size: .82em; padding: 1px 5px; border: 1px solid var(--line);
}
.tok.prime:hover { background: var(--glass-2); }
.tok.molecule {
  color: var(--good-cyan); border-bottom: 1px dashed rgba(127,227,192,.5);
}
.tok.molecule:hover { background: rgba(127,227,192,.12); }

/* compare-with-traditional-dictionary toggle */
.compare { margin-top: 22px; }
.compare-toggle {
  appearance: none; cursor: pointer; display: inline-flex; align-items: center; gap: 10px;
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink-dim); font-family: 'Inter', sans-serif; font-size: 13px; letter-spacing: .02em;
  padding: 8px 16px; transition: .18s;
}
.compare-toggle:hover { color: var(--ink); background: var(--glass-2); border-color: rgba(255, 245, 230, .3); }
.compare-toggle .ct-chev { transition: transform .2s; font-size: 11px; color: var(--ink-faint); }
.compare-toggle.open .ct-chev { transform: rotate(180deg); }
.trad-panel {
  margin-top: 14px; border: 1px solid var(--line-soft); border-left: 2px solid rgba(127, 227, 192, .45);
  border-radius: 12px; background: rgba(127, 227, 192, .035); padding: 18px 22px; max-width: 680px;
}
.trad-head { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 14px; }
.trad-head em { font-style: italic; color: var(--good-cyan); text-transform: none; letter-spacing: 0; font-family: 'Spectral', serif; font-size: 16px; }
.trad-pos { margin: 12px 0; }
.trad-pos-tag { font-family: 'Spectral', serif; font-style: italic; color: var(--ink-dim); font-size: 14px; margin-bottom: 4px; }
.trad-pos ol { margin: 0; padding-left: 22px; }
.trad-pos li { font-family: 'Spectral', serif; font-size: 15.5px; line-height: 1.6; color: var(--ink); margin: 5px 0; }
.trad-ex { display: block; color: var(--ink-faint); font-style: italic; font-size: 13.5px; margin-top: 2px; }
.trad-src { margin-top: 14px; font-size: 11.5px; color: var(--ink-faint); }
.trad-src a { color: var(--good-cyan); border-bottom: 1px solid var(--line); }
.trad-empty { font-family: 'Spectral', serif; font-size: 15px; color: var(--ink-dim); line-height: 1.6; }

/* chips strip */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--glass); font-size: 12.5px; cursor: pointer; transition: .15s;
}
.chip:hover { background: var(--glass-2); border-color: var(--line); transform: translateY(-1px); }
.chip .sc { font-variant: small-caps; letter-spacing: .04em; font-weight: 600; }
.chip .n { font-size: 10px; color: var(--ink-faint); }
.chip .swatch { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 7px currentColor; }
.chip.molecule { color: var(--good-cyan); }

.source-note { margin-top: 12px; font-size: 12.5px; color: var(--ink-faint); line-height: 1.6; max-width: 640px; }
.source-note a { color: var(--ink-dim); border-bottom: 1px solid var(--line); }
.source-note a:hover { color: var(--good-cyan); }

/* welcome / empty state */
.welcome { padding: 8vh 0 0; max-width: 640px; }
.welcome h1 { font-family: 'Spectral', serif; font-weight: 500; font-size: clamp(34px, 5vw, 52px); color: var(--cream); line-height: 1.08; }
.welcome p { margin-top: 18px; font-size: 16px; line-height: 1.7; color: var(--ink-dim); }
.welcome .stats { display: flex; gap: 30px; margin-top: 34px; }
.welcome .stat .num { font-family: 'Spectral', serif; font-size: 34px; color: var(--good); }
.welcome .stat .lab { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); margin-top: 2px; }
.welcome .hint { margin-top: 34px; font-size: 13px; color: var(--ink-faint); }
.welcome .hint kbd { font-family: inherit; padding: 2px 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--glass); color: var(--ink-dim); }

/* ============================================================
   GRAPH MODE
   ============================================================ */
#graph-view { position: relative; height: calc(100vh - var(--header-h)); }
/* explicit CSS size: a stylesheet rule beats the <canvas width/height> presentational
   hint, so the canvas's LAYOUT size never tracks its drawing-buffer size. Without this,
   a high-DPI ResizeObserver loop multiplies the canvas by devicePixelRatio every tick. */
#graph-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#graph-canvas:active { cursor: grabbing; }

/* crisp HTML node labels (projected over the canvas each frame) */
#node-labels { position: absolute; inset: 0; z-index: 4; pointer-events: none; overflow: hidden; }
.node-label {
  position: absolute; top: 0; left: 0; will-change: transform, opacity;
  font-family: 'Inter', sans-serif; font-size: 11px; font-weight: 500; letter-spacing: .02em;
  color: var(--ink); white-space: nowrap; text-shadow: 0 0 8px #000, 0 1px 2px #000;
  opacity: 0; transition: opacity .15s;
}

.pole-label {
  position: absolute; left: 50%; transform: translateX(-50%); z-index: 5; pointer-events: none;
  font-family: 'Spectral', serif; font-style: italic; letter-spacing: .04em;
  text-shadow: 0 0 18px currentColor; user-select: none;
}
.pole-label.good { top: 14px; color: var(--good); font-size: 22px; }
.pole-label.bad  { bottom: 14px; color: var(--bad); font-size: 22px; }
.pole-label .ax { display:block; font-family:'Inter',sans-serif; font-style:normal; font-size:9.5px; letter-spacing:.22em; text-transform:uppercase; color: var(--ink-faint); text-align:center; margin-top:2px; }

.graph-legend {
  position: absolute; left: 18px; bottom: 18px; z-index: 5;
  background: rgba(5,5,7,.55); border: 1px solid var(--line-soft); border-radius: 12px;
  padding: 13px 15px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); max-width: 230px;
}
.graph-legend h4 { font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 9px; }
.graph-legend .row { display: flex; align-items: center; gap: 9px; font-size: 12px; color: var(--ink-dim); margin: 5px 0; }
.graph-legend .row .sw { width: 11px; height: 11px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.graph-legend .tip { margin-top: 10px; font-size: 11px; color: var(--ink-faint); line-height: 1.5; }

/* hover tooltip */
.graph-tip {
  position: absolute; z-index: 8; pointer-events: none; max-width: 320px;
  background: rgba(8,8,12,.86); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 14px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s;
}
.graph-tip.show { opacity: 1; transform: translateY(0); }
.graph-tip .tw { font-family:'Spectral',serif; font-size: 18px; color: var(--cream); }
.graph-tip .tp { font-style: italic; color: var(--ink-faint); font-size: 12px; }
.graph-tip .te { margin-top: 7px; font-family:'Spectral',serif; font-size: 13px; color: var(--ink-dim); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.graph-tip .tkind { font-size: 9.5px; letter-spacing:.16em; text-transform:uppercase; color: var(--good); }

/* selected entry card in graph mode */
.graph-card {
  position: absolute; top: 18px; right: 18px; z-index: 6; width: 330px; max-height: calc(100% - 36px); overflow-y: auto;
  background: rgba(7,7,11,.8); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px;
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  opacity: 0; transform: translateX(12px); pointer-events: none; transition: .22s;
}
.graph-card.show { opacity: 1; transform: none; pointer-events: auto; }
.graph-card .gw { font-family:'Spectral',serif; font-size: 30px; color: var(--cream); line-height:1.05; }
.graph-card .gp { font-style: italic; color: var(--ink-dim); font-size: 14px; margin-top: 2px; }
.graph-card .gx { font-family:'Spectral',serif; font-size: 15px; line-height: 1.6; color: var(--ink); margin-top: 14px; }
.graph-card .open { margin-top: 16px; display: inline-flex; align-items:center; gap:7px; font-size: 12.5px; color: var(--good); cursor: pointer; }
.graph-card .open:hover { color: var(--good-cyan); }
.graph-card .close { position:absolute; top:14px; right:16px; color: var(--ink-faint); cursor:pointer; font-size:18px; line-height:1; }
.graph-card .close:hover { color: var(--ink); }

/* scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 9px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.16); }
::-webkit-scrollbar-track { background: transparent; }

/* responsive */
@media (max-width: 760px) {
  #read-view { grid-template-columns: 1fr; }
  .rail { display: none; }
  .search-wrap { display: none; }
  .graph-card { width: calc(100% - 36px); }
}

/* prime/molecule modal panel (the recursion leaf viewer) */
.modal-back {
  position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  opacity: 0; pointer-events: none; transition: opacity .18s;
}
.modal-back.show { opacity: 1; pointer-events: auto; }
.modal {
  width: min(560px, 100%); max-height: 80vh; overflow-y: auto;
  background: linear-gradient(180deg, #0c0c12, #08080c); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px 30px;
  transform: translateY(10px) scale(.99); transition: .2s;
}
.modal-back.show .modal { transform: none; }
.modal .kind { font-size: 10.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--good); }
.modal .title { font-family:'Spectral',serif; font-size: 36px; color: var(--cream); margin-top: 6px; display:flex; align-items:center; gap:14px; }
.modal .title .swatch { width: 16px; height: 16px; border-radius: 50%; box-shadow: 0 0 14px currentColor; }
.modal .cat { font-style: italic; color: var(--ink-dim); margin-top: 2px; }
.modal .body { margin-top: 18px; font-size: 14.5px; line-height: 1.7; color: var(--ink-dim); }
.modal .body strong { color: var(--ink); font-weight: 600; }
.modal .terminal { margin-top: 16px; padding: 12px 14px; border: 1px dashed var(--line); border-radius: 10px;
  font-size: 12.5px; color: var(--ink-faint); line-height: 1.6; }
.modal .exps { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.modal .exps span { padding: 4px 10px; border:1px solid var(--line); border-radius: 99px; font-size: 12.5px; color: var(--ink); }
.modal .usedby { margin-top: 18px; }
.modal .usedby .ttl { font-size: 10.5px; letter-spacing:.16em; text-transform:uppercase; color: var(--ink-faint); margin-bottom: 9px; }
.modal .usedby .chip { font-size: 12px; }
.modal .x { position: absolute; }
