/* ————————————————————————————————————————————————
   Orthographica — ink & paper, type-foundry dark
   ———————————————————————————————————————————————— */

:root {
  --bg: #0f0e0b;
  --bg-raised: #16140f;
  --bg-card: #1a1712;
  --ink: #ece5d3;
  --ink-dim: #a89e8c;
  --ink-faint: #6f675a;
  --hairline: rgba(236, 229, 211, 0.13);
  --hairline-soft: rgba(236, 229, 211, 0.07);
  --accent: #d8b45c;

  --c-alphabet:    #7fb2ff;
  --c-abjad:       #f0a35e;
  --c-abugida:     #7fd694;
  --c-syllabary:   #cf9bf5;
  --c-logographic: #f07373;
  --c-featural:    #55d4c1;

  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, "Helvetica Neue", sans-serif;
  --mono: "JetBrains Mono", "SF Mono", Menlo, monospace;
  --native: -apple-system, "Helvetica Neue", "Noto Sans", "Arial Unicode MS", sans-serif;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  background-image: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(216, 180, 92, 0.06), transparent);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(216, 180, 92, 0.35); }

/* ——— Header ——— */

#topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  background: rgba(15, 14, 11, 0.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--hairline);
  padding: 13px 28px 0;
}

.brand-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.brand h1 {
  font-family: var(--serif);
  font-weight: 560;
  font-size: 30px;
  letter-spacing: 0.01em;
  font-variation-settings: "opsz" 100;
  line-height: 1;
}

.brand h1::first-letter { color: var(--accent); }

.tagline {
  margin-top: 5px;
  color: var(--ink-dim);
  font-size: 12.5px;
  font-style: italic;
  font-family: var(--serif);
}

.tabs { display: flex; gap: 2px; border: 1px solid var(--hairline); border-radius: 8px; padding: 3px; background: var(--bg-raised); }

.tabs button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: 600 11px/1 var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 9px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.tabs button:hover { color: var(--ink); }
.tabs button.active { background: var(--ink); color: var(--bg); }

/* ——— Controls ——— */

.controls {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 11px 0 9px;
}

.meta-row {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 0 0 10px;
}

.seg { display: flex; border: 1px solid var(--hairline); border-radius: 7px; overflow: hidden; }

.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: 500 12px/1 var(--sans);
  padding: 8px 13px;
  cursor: pointer;
  border-left: 1px solid var(--hairline-soft);
  transition: 0.15s;
}
.seg button:first-child { border-left: 0; }
.seg button:hover { color: var(--ink); }
.seg button.active { background: var(--accent); color: #14110a; font-weight: 600; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--ink-dim);
  font: 500 12px/1 var(--sans);
  padding: 7px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: 0.15s;
}
.chip:hover { color: var(--ink); border-color: rgba(236, 229, 211, 0.3); }
.chip.active { color: var(--ink); background: rgba(236, 229, 211, 0.08); border-color: var(--chip-c, var(--ink)); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--chip-c, var(--ink-faint)); }
.chip .arrow { font-family: var(--mono); font-size: 12px; }

.search-wrap { margin-left: auto; }

#search {
  appearance: none;
  background: var(--bg-raised);
  border: 1px solid var(--hairline);
  border-radius: 7px;
  color: var(--ink);
  font: 400 13px/1 var(--sans);
  padding: 7px 11px;
  width: 230px;
  outline: none;
  transition: border-color 0.15s;
}
#search:focus { border-color: var(--accent); }
#search::placeholder { color: var(--ink-faint); }

.statsbar {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.03em;
}
.statsbar b { color: var(--accent); font-weight: 500; }

/* ——— Stage ——— */

#stage { padding: 22px 28px 60px; min-height: 60vh; }

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.view-note {
  color: var(--ink-faint);
  font-size: 12px;
  font-style: italic;
  font-family: var(--serif);
  flex: 1 1 380px;
  max-width: 760px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--ink-dim);
  white-space: nowrap;
}

.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item svg { display: block; flex: none; }
.legend-glyph { font-size: 14px; color: var(--ink-faint); line-height: 1; }

.empty-state {
  padding: 90px 0;
  text-align: center;
  color: var(--ink-faint);
  font-family: var(--serif);
  font-style: italic;
  font-size: 17px;
}

svg text { user-select: none; }

/* Lineage */
#lineage-svg { display: block; width: 100%; cursor: grab; }
#lineage-svg:active { cursor: grabbing; }
.tree-label { font: 400 9.5px var(--sans); fill: var(--ink-dim); cursor: pointer; }
.tree-label:hover { fill: var(--ink); }
.tree-node { cursor: pointer; }
.tree-link { fill: none; stroke: var(--ink); stroke-opacity: 0.14; }

/* Timeline */
#timeline-axis { position: sticky; z-index: 40; background: rgba(15, 14, 11, 0.95); backdrop-filter: blur(10px); border-bottom: 1px solid var(--hairline-soft); }
.tl-row { cursor: pointer; }
.tl-row:hover .tl-name { fill: var(--ink); }
.tl-row:hover .tl-bar { filter: brightness(1.3); }
.tl-name { font: 400 10.5px var(--sans); fill: var(--ink-dim); }
.tl-tick { font: 400 10px var(--mono); fill: var(--ink-faint); }
.tl-grid { stroke: var(--ink); stroke-opacity: 0.06; }
.tl-now { stroke: var(--accent); stroke-opacity: 0.5; stroke-dasharray: 2 4; }

/* Glyph field */
.gf-node { cursor: pointer; }
.gf-node circle { transition: filter 0.15s; }
.gf-node:hover circle { filter: brightness(1.35); }
.gf-glyph { font-family: var(--native); pointer-events: none; }
.gf-cluster-label { font: 600 11px var(--sans); fill: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.14em; }
.gf-cluster-count { font: 400 10px var(--mono); fill: var(--ink-faint); }

/* Atlas */
.atlas-land { fill: #1c1913; stroke: rgba(236, 229, 211, 0.1); stroke-width: 0.5; }
.atlas-graticule { fill: none; stroke: rgba(236, 229, 211, 0.05); }
.atlas-dot { cursor: pointer; }
.atlas-dot:hover { stroke: var(--ink); }

/* Specimens */
.specimen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 14px;
}

.specimen {
  background: var(--bg-card);
  border: 1px solid var(--hairline-soft);
  border-radius: 10px;
  padding: 16px 16px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}
.specimen:hover {
  transform: translateY(-3px);
  border-color: rgba(236, 229, 211, 0.28);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.specimen .code-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
}

.specimen .sample {
  font-family: var(--native);
  font-size: 34px;
  line-height: 1.25;
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  color: var(--ink);
  border-top: 1px solid var(--hairline-soft);
  border-bottom: 1px solid var(--hairline-soft);
  padding: 10px 2px;
}
.specimen .sample.long { font-size: 22px; }
.specimen .sample.vert { writing-mode: vertical-lr; }
.specimen .sample.unencoded {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-faint);
  flex-direction: column;
  gap: 6px;
}
.specimen .sample.unencoded::before { content: "◌"; font-size: 30px; opacity: 0.45; font-style: normal; }

.specimen h3 { font-family: var(--serif); font-weight: 540; font-size: 16.5px; line-height: 1.2; }

.specimen .meta {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--ink-dim);
}
.specimen .meta .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* ——— Detail panel ——— */

#panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(430px, 92vw);
  background: var(--bg-raised);
  border-left: 1px solid var(--hairline);
  box-shadow: -30px 0 70px rgba(0, 0, 0, 0.55);
  transform: translateX(103%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0.24, 1);
  z-index: 100;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#panel.open { transform: translateX(0); }

#panel-close {
  position: sticky;
  top: 14px;
  float: right;
  margin: 14px 16px 0 0;
  appearance: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: var(--bg-raised);
  color: var(--ink-dim);
  font-size: 17px;
  cursor: pointer;
  z-index: 2;
}
#panel-close:hover { color: var(--ink); border-color: var(--ink-dim); }

#panel-body { padding: 26px 26px 46px; }

.p-eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.p-status { padding: 3px 8px; border-radius: 4px; font-weight: 500; }
.p-status.Living { background: rgba(127, 214, 148, 0.14); color: var(--c-abugida); }
.p-status.Historical { background: rgba(240, 115, 115, 0.13); color: var(--c-logographic); }
.p-status.Constructed { background: rgba(207, 155, 245, 0.14); color: var(--c-syllabary); }

#panel h2 {
  font-family: var(--serif);
  font-weight: 560;
  font-size: 27px;
  line-height: 1.12;
  margin: 10px 0 16px;
}

.p-hero {
  background: var(--bg);
  border: 1px solid var(--hairline-soft);
  border-radius: 10px;
  padding: 26px 18px;
  text-align: center;
  font-family: var(--native);
  font-size: 42px;
  line-height: 1.3;
  margin-bottom: 8px;
  overflow-x: auto;
}
.p-hero.long { font-size: 27px; }
.p-hero.vert { writing-mode: vertical-lr; min-height: 150px; }
.p-hero.unencoded { font-family: var(--serif); font-style: italic; font-size: 14px; color: var(--ink-faint); }

.p-hero-caption {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 11.5px;
  color: var(--ink-faint);
  margin-bottom: 18px;
}

.p-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.p-badge {
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 11.5px;
  color: var(--ink-dim);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.p-badge .dot { width: 8px; height: 8px; border-radius: 50%; }

.p-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--hairline-soft);
  border: 1px solid var(--hairline-soft);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 22px;
}
.p-stat { background: var(--bg-card); padding: 13px 15px; }
.p-stat .v { font-family: var(--serif); font-size: 21px; font-weight: 540; color: var(--ink); line-height: 1.1; }
.p-stat .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-faint); margin-top: 4px; }

.p-section { margin-bottom: 22px; }
.p-section h4 {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--hairline-soft);
}

.p-chain { display: flex; flex-direction: column; }
.p-chain a {
  color: var(--ink-dim);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 0 4px 16px;
  position: relative;
  transition: color 0.12s;
}
.p-chain a::before { content: "└"; position: absolute; left: 0; color: var(--ink-faint); font-family: var(--mono); font-size: 11px; }
.p-chain a:first-child::before { content: "◦"; }
.p-chain a:hover { color: var(--accent); }
.p-chain .self { color: var(--ink); font-weight: 600; pointer-events: none; }
.p-chain .self::before { color: var(--accent); }
.p-chain a:nth-child(2) { padding-left: 16px; }
.p-chain .indent-0 { padding-left: 0; }

.p-links { display: flex; flex-wrap: wrap; gap: 6px; }
.p-links a {
  color: var(--ink-dim);
  text-decoration: none;
  font-size: 12px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 4px 10px;
  transition: 0.12s;
}
.p-links a:hover { color: var(--accent); border-color: var(--accent); }

.p-quirks { font-size: 13.5px; line-height: 1.65; color: var(--ink-dim); }
.p-quirks em { color: var(--ink); font-family: var(--serif); }

.p-langs { font-size: 12.5px; color: var(--ink-dim); line-height: 1.7; }
.p-langs .langs-toggle { color: var(--accent); text-decoration: none; white-space: nowrap; }
.p-langs .langs-toggle:hover { text-decoration: underline; }

/* ——— Footer ——— */

#colophon {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  padding: 18px 28px 30px;
  border-top: 1px solid var(--hairline-soft);
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
}

/* ——— Tooltip ——— */
#tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 200;
  background: rgba(22, 20, 15, 0.97);
  border: 1px solid var(--hairline);
  border-radius: 7px;
  padding: 8px 11px;
  font-size: 12px;
  color: var(--ink);
  max-width: 240px;
  opacity: 0;
  transition: opacity 0.1s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
#tooltip .t-sub { color: var(--ink-faint); font-size: 10.5px; font-family: var(--mono); margin-top: 2px; }

@media (max-width: 780px) {
  #topbar { padding: 14px 16px 0; }
  #stage { padding: 16px 16px 48px; }
  .search-wrap { margin-left: 0; width: 100%; }
  #search { width: 100%; }
}
