:root {
  --paper: #f6f1e7;
  --paper-2: #efe8da;
  --ink: #1d1a16;
  --ink-2: #4a433a;
  --muted: #7d7467;
  --line: #d9d0c0;
  --accent: #c0652b;

  --rel-inh: #2f7a4e;
  --rel-bor: #c0652b;
  --rel-der: #3f66a8;
  --rel-calque: #8a6d2f;
  --rel-root: #5b3f8f;
  --rel-cog: #7a3d8a;
  --rel-noncog: #9a8f80;
  --rel-affix: #1d7e86;
  --rel-doublet: #a33a5c;
  --rel-cousin: #8f877c;

  --serif: "Gentium Plus", "Gentium Book Plus", "Noto Serif", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15130f;
    --paper-2: #1e1b16;
    --ink: #ece4d4;
    --ink-2: #c9bfae;
    --muted: #8f8577;
    --line: #342f27;
    --rel-inh: #5fb986;
    --rel-bor: #e5905a;
    --rel-der: #7da0e0;
    --rel-calque: #c9a861;
    --rel-root: #a98be0;
    --rel-cog: #c07fd0;
    --rel-noncog: #7d756a;
    --rel-affix: #5cbcc4;
    --rel-doublet: #e07a9b;
    --rel-cousin: #6f675c;
  }
}
:root[data-theme="dark"] {
  --paper: #15130f; --paper-2: #1e1b16; --ink: #ece4d4; --ink-2: #c9bfae; --muted: #8f8577; --line: #342f27;
  --rel-inh: #5fb986; --rel-bor: #e5905a; --rel-der: #7da0e0; --rel-calque: #c9a861; --rel-root: #a98be0;
  --rel-cog: #c07fd0; --rel-noncog: #7d756a; --rel-affix: #5cbcc4; --rel-doublet: #e07a9b; --rel-cousin: #6f675c;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
a { color: inherit; }

/* ---------- top bar ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 5;
}
.brand {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--rel-bor);
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--rel-inh);
}
.search { position: relative; flex: 1 1 220px; min-width: 0; max-width: 640px; }
#q {
  width: 100%;
  font: inherit;
  font-family: var(--serif);
  font-size: 20px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink);
  outline: none;
}
#q:focus { border-color: var(--accent); }
.suggest {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,.18);
  max-height: 60vh;
  overflow: auto;
  z-index: 10;
}
.suggest-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  padding: 8px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.suggest-item:last-child { border-bottom: 0; }
.suggest-item:hover, .suggest-item.active { background: var(--paper-2); }
.suggest-item .w { font-family: var(--serif); font-size: 18px; }
.suggest-item .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; align-self: center; white-space: nowrap; }
.suggest-item .g { grid-column: 1 / -1; color: var(--ink-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ghost {
  font: inherit;
  font-size: 13px;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.ghost:hover { border-color: var(--accent); color: var(--ink); }

/* ---------- layout ---------- */
#main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  min-height: 0;
}
.stage { position: relative; min-height: 70vh; }
#graph { width: 100%; height: 100%; display: block; min-height: 70vh; }
.panel {
  border-left: 1px solid var(--line);
  padding: 20px 22px 32px;
  overflow: auto;
  max-height: calc(100vh - 61px);
  position: sticky;
  top: 61px;
}
@media (max-width: 900px) {
  #main { grid-template-columns: 1fr; }
  .stage { min-height: 70vh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); position: static; max-height: none; }
  .top { flex-wrap: wrap; }
  .brand { font-size: 22px; }
}

/* ---------- empty state ---------- */
.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 24px;
  pointer-events: none;
}
.empty > * { pointer-events: auto; }
.empty h1 { font-family: var(--serif); font-weight: 400; font-size: 32px; margin: 0 0 12px; max-width: 24ch; }
.empty p { max-width: 54ch; color: var(--ink-2); margin: 0 0 10px; }
.examples a { font-family: var(--serif); font-size: 18px; margin: 0 8px; }
.credit { font-size: 12px; color: var(--muted); margin-top: 18px; }

/* ---------- graph ---------- */
.edge { fill: none; stroke-width: 1.2; opacity: .55; }
.edge.cousin { stroke-dasharray: 3 4; opacity: .35; }
.node { cursor: pointer; }
.node circle { stroke: var(--paper); stroke-width: 2; }
.node .word { font-family: var(--serif); font-size: 16px; fill: var(--ink); }
.node .word.unknown { fill: var(--ink-2); }
.node .meta { font-family: var(--sans); font-size: 10.5px; fill: var(--muted); letter-spacing: .04em; }
.node .gloss { font-family: var(--sans); font-size: 11px; fill: var(--ink-2); }
.node:hover .word, .node.hot .word { fill: var(--accent); }
.node.more .word { font-family: var(--sans); font-size: 12px; fill: var(--muted); }
.center .word { font-size: 30px; font-weight: 700; fill: var(--ink); }
.center .meta { font-size: 11px; fill: var(--muted); letter-spacing: .08em; }
.center .gloss { font-size: 12.5px; fill: var(--ink-2); }
.center-ring { fill: var(--paper-2); stroke: var(--line); }
.sector-label { font-family: var(--sans); font-size: 10px; fill: var(--muted); letter-spacing: .12em; text-transform: uppercase; }
.tip {
  position: absolute;
  max-width: 320px;
  background: var(--ink);
  color: var(--paper);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  pointer-events: none;
  z-index: 4;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.tip b { font-family: var(--serif); font-size: 16px; font-weight: 400; }
.tip .r { opacity: .7; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }

/* ---------- panel ---------- */
.panel-lang { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.panel-word { font-family: var(--serif); font-size: 34px; font-weight: 400; margin: 2px 0 0; line-height: 1.1; word-break: break-word; }
.panel-roman { color: var(--muted); font-style: italic; font-family: var(--serif); }
.entries { margin: 16px 0 8px; }
.entry { border-top: 1px solid var(--line); padding: 10px 0; }
.entry .pos { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--accent); }
.entry .g { font-family: var(--serif); font-size: 16px; margin: 2px 0 4px; }
.entry .e { font-size: 13px; color: var(--ink-2); }
.entry .e summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.groups h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 18px 0 6px; display: flex; align-items: center; gap: 8px; }
.groups h3::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--muted)); }
.groups ul { list-style: none; margin: 0; padding: 0; }
.groups li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 10px; padding: 3px 0; align-items: baseline; }
.groups li a { font-family: var(--serif); font-size: 16px; text-decoration: none; }
.groups li a:hover { color: var(--accent); }
.groups li .l { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.groups li .g { grid-column: 1 / -1; font-size: 12.5px; color: var(--ink-2); }
.groups button { font: inherit; font-size: 12px; color: var(--muted); background: none; border: 0; padding: 4px 0; cursor: pointer; text-decoration: underline; }
.panel-foot { font-size: 12px; color: var(--muted); margin-top: 24px; }

/* ---------- legend ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: 6px; vertical-align: -1px; }
.legend .meta { margin-left: auto; }
