/* Tokens follow the main site's style.scss */
:root {
  --bg: #fcfcfa;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --line: #e6e4df;
  --accent: #2f5bd3;
  --code-bg: #f2f1ed;
  --land: #efede6;
  --coast: #dcd8cf;
  --en: #2f5bd3;
  --nl: #d0611c;
  --sh: #3d3a35;
  --gold: #b8860b;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Charter", "Palatino Linotype", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212; --text: #e8e6e3; --muted: #9a9894; --line: #2a2a2a; --accent: #8fb0ff;
    --code-bg: #1d1d1d; --land: #1d1d1b; --coast: #2e2d2a;
    --en: #8fb0ff; --nl: #ff9d5c; --sh: #d9d4ca; --gold: #e6be5a;
  }
}
:root[data-theme="dark"] {
  --bg: #121212; --text: #e8e6e3; --muted: #9a9894; --line: #2a2a2a; --accent: #8fb0ff;
  --code-bg: #1d1d1d; --land: #1d1d1b; --coast: #2e2d2a;
  --en: #8fb0ff; --nl: #ff9d5c; --sh: #d9d4ca; --gold: #e6be5a;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 var(--sans); -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent); text-decoration-color: currentColor; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- top bar --- */
.bar {
  display: flex; align-items: center; gap: 1rem; padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--line); position: relative; z-index: 5; background: var(--bg);
}
.home { color: var(--muted); text-decoration: none; font-size: 0.9rem; white-space: nowrap; }
.home::before { content: "← "; }
.home:hover { color: var(--text); }
.brand { font: 600 1.15rem/1 var(--sans); letter-spacing: -0.01em; margin: 0; }
.search { flex: 1; display: flex; gap: 0.5rem; max-width: 30rem; margin-left: auto; }
.dir {
  display: inline-flex; align-items: center; gap: 0.3rem; padding: 0 0.7rem; height: 2.4rem;
  border: 1px solid var(--line); border-radius: 99px; background: var(--bg); cursor: pointer;
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.04em; white-space: nowrap;
}
.dir [data-from] { color: var(--en); }
.dir [data-to] { color: var(--nl); }
.dir.rev [data-from] { color: var(--nl); }
.dir.rev [data-to] { color: var(--en); }
.dir .arrow { color: var(--muted); }
.dir:hover { border-color: var(--muted); }
.field { position: relative; flex: 1; min-width: 0; }
#q {
  width: 100%; height: 2.4rem; padding: 0 0.9rem; border: 1px solid var(--line); border-radius: 99px;
  background: var(--bg); color: var(--text); font: 1.05rem var(--serif);
}
#q:focus { outline: none; border-color: var(--accent); }
#suggest {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: 0.3rem 0;
  list-style: none; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px #0002; max-height: 20rem; overflow: auto;
}
#suggest li { padding: 0.35rem 0.9rem; cursor: pointer; font-family: var(--serif); }
#suggest li[aria-selected="true"], #suggest li:hover { background: var(--code-bg); }
.help {
  display: grid; place-items: center; width: 2.1rem; height: 2.1rem; flex: none;
  border: 1px solid var(--line); border-radius: 50%; text-decoration: none;
  font-weight: 600; color: var(--muted);
}
.help:hover { color: var(--accent); border-color: var(--accent); }
.help + .help { margin-left: -0.5rem; }

/* --- app grid --- */
.app {
  display: grid; grid-template-columns: minmax(0, 1fr) 24rem;
  grid-template-rows: auto minmax(22rem, 1fr) auto;
  grid-template-areas: "head panel" "stage panel" "time panel";
  height: calc(100vh - 3.9rem); min-height: 36rem;
}
.head { grid-area: head; padding: 1.1rem 1.25rem 0.4rem; }
.stage { grid-area: stage; position: relative; min-height: 0; overflow: hidden; }
.timeline { grid-area: time; }
.panel { grid-area: panel; border-left: 1px solid var(--line); overflow-y: auto; padding: 1.1rem 1.25rem 2rem; }

.lede { font: 1.15rem/1.55 var(--serif); margin: 0 0 0.4rem; max-width: 40rem; }
.try { color: var(--muted); margin: 0; font-size: 0.95rem; }
.try a { font-family: var(--serif); color: var(--text); }

.title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.7rem; margin: 0; font-weight: 400; }
.title .w { font: italic 2rem/1.2 var(--serif); }
.title .w.en { color: var(--en); }
.title .w.nl { color: var(--nl); }
.title .to { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.55rem 0 0.2rem; }
.chip {
  border: 1px solid var(--line); border-radius: 99px; padding: 0.05rem 0.65rem; background: none;
  cursor: pointer; font: italic 0.95rem var(--serif);
}
.chip[aria-pressed="true"] { border-color: currentColor; }
.chip.en[aria-pressed="true"] { color: var(--en); }
.chip.nl[aria-pressed="true"] { color: var(--nl); }
.chip[disabled] { opacity: 0.45; cursor: default; }
.chip:not([disabled]):hover { border-color: var(--muted); }
.head > .note:not(:first-of-type) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.formhint { margin: 0.35rem 0 0; font-size: 0.88rem; color: var(--muted); }
.formhint em { font-family: var(--serif); color: var(--text); }
.formhint a { color: var(--accent); text-decoration-color: currentColor; white-space: nowrap; }
.formhint.strong { color: var(--text); background: color-mix(in srgb, var(--accent) 9%, transparent);
  border-left: 3px solid var(--accent); padding: 0.35rem 0.7rem; border-radius: 0 6px 6px 0; max-width: 46rem; }
.summary { margin: 0.4rem 0 0; font: 1.05rem/1.5 var(--serif); max-width: 46rem; }
.summary em { font-style: italic; }
.note { color: var(--muted); font-size: 0.85rem; margin: 0.25rem 0 0; }
.notfound { font: 1.05rem var(--serif); }

/* --- map --- */
#map { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map:active { cursor: grabbing; }
#map .sea { fill: var(--bg); }
#map .land { fill: var(--land); stroke: var(--coast); stroke-width: 0.6; vector-effect: non-scaling-stroke; }
#map .grat { fill: none; stroke: var(--line); stroke-width: 0.5; opacity: 0.6; vector-effect: non-scaling-stroke; }
#map .halo { stroke: none; }
#map .halo.en { fill: var(--en); }
#map .halo.nl { fill: var(--nl); }
#map .halo.sh, #map .halo.lca { fill: var(--sh); }
#map .dot { stroke: var(--bg); stroke-width: 1.5; }
#map .dot.en, #map .arc.en { fill: var(--en); }
#map .dot.nl { fill: var(--nl); }
#map .dot.sh { fill: var(--sh); }
#map .dot.lca { fill: var(--gold); }
#map .ring { fill: none; stroke: var(--gold); stroke-width: 2; }
#map .arc { fill: none; stroke-width: 1.8; stroke-linecap: round; }
#map .arc.en { stroke: var(--en); fill: none; }
#map .arc.nl { stroke: var(--nl); }
#map .arc.sh { stroke: var(--sh); }
#map .arc.ghost-en { stroke: var(--en); }
#map .arc.ghost-nl { stroke: var(--nl); }
.ls { stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; }
#map .arc.bor, .ls.bor { stroke-dasharray: 6 4; }
#map .arc.der, #map .arc.cal, .ls.der { stroke-dasharray: 1.5 4; }
#map .arc.cmp { stroke-width: 1.1; opacity: 0.7; }
#map .arc.ghost, .ls.ghost { stroke-dasharray: 0.1 4.5; stroke-width: 2.4; opacity: 0.85; }
#map .lab { font: italic 14px var(--serif); fill: var(--text); paint-order: stroke; stroke: var(--bg); stroke-width: 3.5px; stroke-linejoin: round; }
#map .lab .ln { font: 10px var(--sans); font-style: normal; fill: var(--muted); letter-spacing: 0.02em; }
#map .lab.cur { font-weight: 700; font-size: 16px; }
#map .lab.dim { opacity: 0.55; }
#map .lab.lca { fill: var(--gold); }
#map g.node { cursor: pointer; }
#map g.node.flash .dot { animation: flash 0.9s ease-out 2; }
@keyframes flash { 50% { r: 9; } }

.legend {
  position: absolute; left: 0.9rem; bottom: 0.7rem; font-size: 0.75rem; color: var(--muted);
  background: color-mix(in srgb, var(--bg) 85%, transparent); padding: 0.45rem 0.6rem; border-radius: 8px;
  display: grid; gap: 0.1rem; pointer-events: none;
}
.legend .sw { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; margin-right: 0.4rem; vertical-align: -0.05rem; }
.sw.en { background: var(--en); } .sw.nl { background: var(--nl); } .sw.sh { background: var(--sh); }
.legend .styles { display: flex; flex-wrap: wrap; gap: 0.1rem 0.7rem; margin-top: 0.2rem; }
.legend .styles svg { vertical-align: middle; margin-right: 0.25rem; }
.unmapped { position: absolute; right: 0.9rem; bottom: 0.7rem; max-width: 16rem; font-size: 0.75rem; color: var(--muted); text-align: right; }

.zoomctl { position: absolute; top: 0.8rem; right: 0.9rem; display: flex; flex-direction: column; gap: 0.3rem; align-items: flex-end; }
.zoomctl button {
  min-width: 2.1rem; height: 2.1rem; padding: 0 0.6rem; border: 1px solid var(--line); border-radius: 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); cursor: pointer; font-size: 1.05rem; line-height: 1;
  display: grid; place-items: center; color: var(--text);
}
.zoomctl button.txt { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.02em; }
.zoomctl button:hover:not(:disabled) { border-color: var(--muted); }
.zoomctl button:disabled { opacity: 0.4; cursor: default; }
#map .lens { cursor: pointer; outline: none; }
#map .lensbg { fill: color-mix(in srgb, var(--bg) 90%, transparent); stroke: var(--line); stroke-width: 1; filter: drop-shadow(0 2px 4px #0002); }
#map .lens circle:not(.lensbg), #map .lens path { fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#map .lens .ico-undo { display: none; }
#map .lens.undo .ico-undo { display: inline; }
#map .lens.undo .ico-zoom { display: none; }
#map .lens:hover .lensbg, #map .lens:focus-visible .lensbg { stroke: var(--accent); }
#map .lens:hover path, #map .lens:hover circle:not(.lensbg), #map .lens:focus-visible path { stroke: var(--accent); }
.maphint { position: absolute; top: 0.9rem; left: 50%; transform: translateX(-50%); font-size: 0.75rem; color: var(--muted);
  background: color-mix(in srgb, var(--bg) 85%, transparent); padding: 0.15rem 0.6rem; border-radius: 99px;
  pointer-events: none; transition: opacity 0.6s; white-space: nowrap; }
.maphint.gone { opacity: 0; }

/* --- timeline --- */
.timeline {
  display: flex; align-items: center; gap: 0.9rem; padding: 0.4rem 1.25rem 0.8rem;
  border-top: 1px solid var(--line);
}
.play {
  width: 2.3rem; height: 2.3rem; flex: none; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg); cursor: pointer; display: grid; place-items: center;
}
.play svg { fill: currentColor; }
.play:hover { border-color: var(--muted); }
.track { flex: 1; position: relative; padding-top: 0.4rem; }
#scrub { width: 100%; margin: 0; accent-color: var(--text); }
#ticks { width: 100%; height: 30px; display: block; overflow: visible; }
#ticks text { font: 10.5px var(--sans); fill: var(--muted); text-anchor: middle; }
#ticks line { stroke: var(--line); }
#ticks .mk { stroke-width: 2.5; stroke-linecap: round; }
#ticks .mk.en { stroke: var(--en); } #ticks .mk.nl { stroke: var(--nl); } #ticks .mk.sh, #ticks .mk.lca { stroke: var(--sh); }
.year { min-width: 6.5rem; text-align: right; font: 600 1.05rem var(--sans); font-variant-numeric: tabular-nums; }

/* --- panel --- */
.panel h2 { font: 600 0.78rem var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 1.4rem 0 0.5rem; }
.panel h2:first-child { margin-top: 0.2rem; }
.panel h2 .k { display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 50%; margin-right: 0.4rem; }
.panel .k.en { background: var(--en); } .panel .k.nl { background: var(--nl); } .panel .k.sh { background: var(--sh); }
.chain { list-style: none; margin: 0; padding: 0; position: relative; }
.chain li { position: relative; padding: 0 0 0.75rem 1.1rem; }
.chain li::before { content: ""; position: absolute; left: 0.24rem; top: 0.55rem; bottom: -0.3rem; border-left: 1.5px solid var(--line); }
.chain li:last-child::before { display: none; }
.chain li::after { content: ""; position: absolute; left: 0; top: 0.35rem; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--c, var(--muted)); }
.chain.en { --c: var(--en); } .chain.nl { --c: var(--nl); } .chain.sh { --c: var(--sh); }
.chain li.lca::after { background: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 30%, transparent); }
.chain .via { display: block; font-size: 0.72rem; color: var(--muted); letter-spacing: 0.02em; margin: -0.1rem 0 0.1rem; }
.chain button.form { all: unset; cursor: pointer; font: italic 1.12rem var(--serif); }
.chain button.form:hover, .chain button.form:focus-visible { color: var(--accent); }
.chain .lang { font-size: 0.8rem; color: var(--muted); margin-left: 0.35rem; }
.chain .gloss { display: block; font: 0.9rem var(--serif); color: var(--muted); }
.chain .wk { font-size: 0.75rem; color: var(--muted); text-decoration: none; margin-left: 0.3rem; }
.chain .wk:hover { color: var(--accent); }
.chain .parts { font-size: 0.85rem; color: var(--muted); }
.chain .parts i { font-family: var(--serif); color: var(--text); }
.unc { color: var(--gold); font-weight: 700; margin-left: 0.2rem; cursor: help; }
.badge { font: 600 0.65rem var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--gold); margin-left: 0.4rem; }
.ghost { border: 1px dashed var(--line); border-radius: 10px; padding: 0.7rem 0.85rem 0.2rem; margin-bottom: 0.7rem; }
.ghost p { margin: 0 0 0.6rem; font: 0.95rem/1.45 var(--serif); }
.ghost .dead { color: var(--muted); }
.panel .empty { color: var(--muted); font: 0.95rem var(--serif); }

.foot { padding: 1rem 1.25rem 2rem; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.8rem; }
.foot p { margin: 0 0 0.4rem; max-width: 60rem; }

/* --- family tree --- */
.thint { margin: -0.2rem 0 0.6rem; font-size: 0.78rem; color: var(--muted); }
#treewrap { margin: 0 -0.4rem 0.6rem; }
#tree { display: block; overflow: visible; touch-action: pan-y; cursor: ns-resize; user-select: none; -webkit-user-select: none; }
#tree .tbg { fill: transparent; }
#tree .te { fill: none; stroke-width: 2; stroke-linecap: round; transition: opacity 0.15s; }
#tree .te.en { stroke: var(--en); } #tree .te.nl { stroke: var(--nl); } #tree .te.sh { stroke: var(--sh); }
#tree .te.bor { stroke-dasharray: 6 4; }
#tree .te.der, #tree .te.cal { stroke-dasharray: 1.5 4; }
#tree .te.cmp { stroke-width: 1.3; }
#tree .te.ghost { stroke-dasharray: 0.1 5; stroke-width: 2.6; }
#tree .te.future { opacity: 0.18; }
#tree .tn { cursor: pointer; outline: none; }
#tree .tn .dot { stroke: var(--bg); stroke-width: 1.5; }
#tree .dot.en { fill: var(--en); } #tree .dot.nl { fill: var(--nl); } #tree .dot.sh { fill: var(--sh); } #tree .dot.lca { fill: var(--gold); }
#tree .ring { fill: none; stroke: var(--gold); stroke-width: 2; }
#tree .tf { font: italic 14.5px var(--serif); fill: var(--text); }
#tree .tl { font: 10px var(--sans); fill: var(--muted); letter-spacing: 0.02em; }
#tree .tg { font: 12px var(--serif); fill: var(--muted); }
#tree .tn.ghost .tf { font-size: 13.5px; }
#tree .tn.cur .tf { font-weight: 700; }
#tree .tn.future { opacity: 0.3; }
#tree .tn:hover .tf, #tree .tn:focus-visible .tf { fill: var(--accent); }
#tree .tn.flash .dot { animation: flash 0.9s ease-out 2; }
#tree .yl line { stroke: var(--text); stroke-width: 1; opacity: 0.35; stroke-dasharray: 3 3; }
#tree .ylbg { fill: var(--text); }
#tree .ylt { font: 600 10.5px var(--sans); fill: var(--bg); font-variant-numeric: tabular-nums; }
.ghostbox { border: 1px dashed var(--line); border-radius: 10px; padding: 0.6rem 0.8rem 0.1rem; margin-bottom: 0.7rem; }
.ghostbox p { margin: 0 0 0.5rem; font: 0.95rem/1.45 var(--serif); }
.ghostbox .route { font-size: 0.88rem; color: var(--muted); }
.ghostbox .rl { font: 0.7rem var(--sans); letter-spacing: 0.02em; }
.ghostbox .dead { color: var(--muted); }
button.wl { all: unset; cursor: pointer; font-style: italic; color: var(--text); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 0.2em; }
button.wl:hover, button.wl:focus-visible { color: var(--accent); text-decoration-color: currentColor; }
.card { position: sticky; bottom: -2rem; margin: 0.8rem -1.25rem -2rem; padding: 0.75rem 1.25rem 1rem;
  background: var(--bg); border-top: 1px solid var(--line); box-shadow: 0 -6px 16px color-mix(in srgb, var(--bg) 80%, transparent); }
.card:empty { display: none; }
.card .cf { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.1rem 0.45rem; }
.card .form { font: italic 1.3rem var(--serif); }
.card .form.en { color: var(--en); } .card .form.nl { color: var(--nl); }
.card .lang { font-size: 0.85rem; color: var(--muted); }
.card .wk { margin-left: auto; font-size: 0.78rem; color: var(--muted); text-decoration: none; }
.card .wk:hover { color: var(--accent); }
.card .cg { font: 0.95rem/1.4 var(--serif); color: var(--muted); margin-top: 0.15rem; }
.card .cv { font-size: 0.85rem; color: var(--muted); margin-top: 0.2rem; }
.card .cv i { font-family: var(--serif); color: var(--text); }

/* --- small screens --- */
@media (max-width: 860px) {
  .bar { flex-wrap: wrap; padding: 0.7rem 1rem; gap: 0.6rem; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .help { margin-left: auto; }
  .app { display: block; height: auto; min-height: 0; }
  .head { padding: 0.9rem 1rem 0.3rem; }
  .stage { height: 62vh; min-height: 20rem; }
  .timeline { padding: 0.4rem 1rem 0.8rem; gap: 0.6rem; }
  .year { min-width: 5rem; font-size: 0.95rem; }
  .panel { border-left: 0; border-top: 1px solid var(--line); padding: 1rem; }
  .title .w { font-size: 1.6rem; }
  .legend { font-size: 0.7rem; left: 0.5rem; bottom: 0.5rem; }
  .unmapped { display: none; }
  .card { margin: 0.8rem -1rem 0; bottom: 0; }
  .maphint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
