:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #d9dce2;
  --text: #1c1f26;
  --muted: #6b7280;
  --accent: #b4530a;
  --accent-soft: #f6e4d6;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 6px 20px rgba(0,0,0,.06);
  --sign-filter: none;
  --radius: 10px;
}
:root[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1d2026;
  --surface-2: #23272f;
  --border: #333842;
  --text: #e7e9ee;
  --muted: #9aa1ad;
  --accent: #e8944e;
  --accent-soft: #3a2a1b;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.4);
  /* invert the black SVG glyphs so they show on dark bg */
  --sign-filter: invert(1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
    Cantarell, 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; display: block; flex: 0 0 auto;
}
.brand-title { font-size: 17px; margin: 0; letter-spacing: .3px; font-weight: 700; display: block; }
.subtitle { margin: 0; font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab {
  border: none; background: transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; font-size: 14px; cursor: pointer;
  font-weight: 600;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent); }

.icon-btn {
  margin-left: auto; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); width: 40px; height: 40px; border-radius: 10px; cursor: pointer;
  font-size: 16px; display: grid; place-items: center;
}
.icon-btn:hover { border-color: var(--accent); }
.tabs + .icon-btn { margin-left: auto; }

/* ---------- Layout ---------- */
main { max-width: 1200px; margin: 0 auto; padding: 20px; }
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Toolbar / filters ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field.grow { flex: 1 1 240px; min-width: 200px; }
.field label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; }
.field input, .field select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 8px; font-size: 14px; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.btn {
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 600; font-size: 14px;
}
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }

.result-meta { color: var(--muted); font-size: 13px; margin: 2px 2px 10px; }
.result-meta.inline { align-self: center; margin: 0 0 0 auto; }

/* ---------- Texts table ---------- */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow);
}
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid thead th {
  position: sticky; top: 0; background: var(--surface-2); text-align: left;
  padding: 10px 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.grid th.num, .grid td.num { text-align: right; }
.grid tbody tr { border-bottom: 1px solid var(--border); cursor: pointer; }
.grid tbody tr:hover { background: var(--surface-2); }
.grid td { padding: 8px 12px; vertical-align: middle; }
.col-id { width: 64px; }
.col-text { min-width: 320px; }
.mono { font-family: ui-monospace, Menlo, Monaco, Consolas, monospace; font-size: 13px; color: var(--muted); }
.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}

/* ---------- Rendered signs in a text ---------- */
.text-render { display: flex; flex-direction: column; gap: 4px; }
.text-line { display: flex; align-items: flex-end; gap: 3px; flex-wrap: wrap; }
.glyph { height: 34px; width: auto; filter: var(--sign-filter); }
.glyph.lg { height: 74px; }
.glyph-missing {
  display: inline-grid; place-items: center; height: 34px; min-width: 22px; padding: 0 4px;
  border: 1px dashed var(--muted); border-radius: 4px; color: var(--muted); font-size: 11px;
}
.glyph-missing.lg { height: 74px; min-width: 44px; font-size: 14px; }
.edge { width: 3px; align-self: stretch; min-height: 30px; border-radius: 2px; }
.edge.complete { background: var(--border); }
.edge.broken { background: repeating-linear-gradient(45deg, var(--muted), var(--muted) 2px, transparent 2px, transparent 4px); }

/* ---------- Pager ---------- */
.pager { display: flex; gap: 6px; align-items: center; justify-content: center; margin: 16px 0 4px; flex-wrap: wrap; }
.pager button {
  min-width: 36px; height: 36px; padding: 0 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); border-radius: 8px; cursor: pointer; font-size: 14px;
}
.pager button:hover:not(:disabled) { border-color: var(--accent); }
.pager button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pager button:disabled { opacity: .4; cursor: default; }
.pager .gap { color: var(--muted); padding: 0 2px; }

/* ---------- Signs gallery ---------- */
.gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px;
}
.sign-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 8px 8px; text-align: center; box-shadow: var(--shadow);
}
.sign-card .box { height: 76px; display: grid; place-items: center; }
.sign-card img { max-height: 72px; max-width: 100%; filter: var(--sign-filter); }
.sign-card .cap { font-size: 12px; color: var(--muted); margin-top: 6px; }
.sign-card .cap b { color: var(--text); }

/* ---------- About ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.prose { max-width: 760px; }
.prose h2 { margin-top: 0; }
.prose h3 { margin: 24px 0 8px; }
.prose a { color: var(--accent); text-decoration: none; }
.prose a:hover { text-decoration: underline; }
.prose code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 13px; }
.refs { margin: 0 0 8px; padding-left: 20px; }
.refs li { margin-bottom: 10px; line-height: 1.5; }
.muted { color: var(--muted); }
.stats { list-style: none; padding: 0; display: flex; gap: 24px; flex-wrap: wrap; margin: 18px 0; }
.stats li { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 18px; }
.stats .n { font-size: 26px; font-weight: 700; color: var(--accent); display: block; }
.stats .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.modal-panel {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; width: min(760px, 92vw); max-height: 88vh; overflow: auto; box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 20px; }
.detail-signs { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 18px; }
.detail-code { font-family: ui-monospace, Menlo, Monaco, Consolas, monospace; color: var(--muted); margin-top: 10px; font-size: 13px; word-break: break-all; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px 22px; align-items: start; }
.meta-item .k { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; }
.meta-item .v { font-size: 14px; margin-top: 2px; word-break: break-word; }

/* ---------- Sign detail modal ---------- */
.sign-hero { display: flex; gap: 18px; flex-wrap: wrap; align-items: stretch; margin-bottom: 18px; }
.glyph-panel { flex: 1 1 150px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; text-align: center; min-width: 140px; }
.glyph-panel .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.glyph-panel img { max-height: 120px; max-width: 100%; filter: var(--sign-filter); }
.glyph-panel .none { color: var(--muted); font-size: 13px; padding: 30px 0; }
.sign-stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.sign-stats .st { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; }
.sign-stats .st .n { font-size: 22px; font-weight: 700; color: var(--accent); display: block; }
.sign-stats .st .l { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.persite h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 0 0 10px; }
.persite-row { display: grid; grid-template-columns: 160px 1fr 48px; gap: 10px; align-items: center; margin-bottom: 5px; font-size: 13px; }
.persite-row .site { text-align: right; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.persite-row .barwrap { background: var(--surface-2); border-radius: 5px; overflow: hidden; height: 16px; }
.persite-row .bar { height: 100%; background: var(--accent); border-radius: 5px; }
.persite-row .cnt { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.sign-actions { margin-top: 20px; }

.empty { text-align: center; color: var(--muted); padding: 48px 12px; }

/* ================= analysis views ================= */
.tabs { flex-wrap: wrap; }
.chart .hint { font-size: 11px; color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; }
.small { font-size: 12px; }
.muted.small { margin: 8px 0 0; }
.toolbar.tight { padding: 0 0 12px; box-shadow: none; border: none; background: transparent; margin: 0; }

/* headline stat cards */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-cards .sc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-cards .sc .n { font-size: 27px; font-weight: 700; color: var(--accent); display: block; line-height: 1.1; }
.stat-cards .sc .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* hero */
.hero { display: flex; gap: 28px; align-items: center; margin-bottom: 16px; padding: 26px 28px;
  background: radial-gradient(760px 340px at 90% 8%, var(--accent-soft) 0%, var(--surface) 58%); }
.hero-main { flex: 1 1 340px; min-width: 0; }
.hero-kicker { text-transform: uppercase; letter-spacing: 2px; font-size: 12px; font-weight: 700; color: var(--accent); margin: 0 0 8px; }
.hero-title { font-size: 42px; line-height: 1.04; margin: 0 0 14px; letter-spacing: -.5px; }
.hero-tag { font-size: 15px; color: var(--muted); line-height: 1.55; max-width: 640px; margin: 0 0 20px; }
.hero-tag b { color: var(--text); }
.hero-tag strong { color: var(--text); }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.hero-side { flex: 0 0 auto; width: 300px; max-width: 100%; text-align: center; }
.hero-inscription { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px 18px; display: flex; justify-content: center; align-items: center; min-height: 96px; }
.hero-inscription .glyph.lg { height: 56px; }
.hero-cap { font-size: 11px; color: var(--muted); margin-top: 8px; line-height: 1.45; }
.hero-cap .mono { font-size: 11px; }
@media (max-width: 720px) {
  .hero { flex-direction: column; align-items: stretch; padding: 20px; }
  .hero-side { width: 100%; }
  .hero-title { font-size: 30px; }
}

/* chart grid + cards */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 16px; }
.chart-grid.two { grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); }
.card.chart { padding: 16px 18px; }
.card.chart > h3 { margin: 0 0 12px; font-size: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card > h3 { margin-top: 0; }

/* horizontal bar chart */
.hbars { display: flex; flex-direction: column; gap: 6px; }
.hbar { display: grid; grid-template-columns: 120px 1fr 52px; gap: 10px; align-items: center; font-size: 13px; }
.hbar.glyphrow { grid-template-columns: 34px 56px 1fr 52px; }
.hbar .lab { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .lab.r { text-align: right; }
.hbar .lab.clk { cursor: pointer; }
.hbar .lab.clk:hover { color: var(--accent); text-decoration: underline; }
.hbar .track { background: var(--surface-2); border-radius: 5px; height: 18px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--accent); border-radius: 5px; min-width: 2px; }
.hbar .v { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.gly { height: 26px; width: auto; max-width: 40px; filter: var(--sign-filter); vertical-align: middle; }
.hbar .gly { max-width: 34px; }

/* vertical histogram */
.histo { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 6px; }
.histo .col { flex: 1 1 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 4px; }
.histo .hb { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; }
.histo .hx { font-size: 10px; color: var(--muted); }

/* zipf svg */
.zipf-svg { width: 100%; height: 300px; display: block; }
.zipf-svg .dot { fill: var(--accent); opacity: .7; }
.zipf-svg .axis { stroke: var(--border); stroke-width: 1; }
.zipf-svg .tick { fill: var(--muted); font-size: 10px; }
.zipf-svg .grid { stroke: var(--border); stroke-width: .5; opacity: .5; }

/* positional stacked bar (in table + legend) */
.posbar { display: flex; height: 16px; width: 130px; border-radius: 4px; overflow: hidden; background: var(--surface-2); }
.posbar span { height: 100%; }
.seg-initial { background: #e8944e; }
.seg-medial  { background: #7aa2c4; }
.seg-terminal{ background: #b4530a; }
.seg-solo    { background: #9aa1ad; }
.pos-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); align-items: center; }
.pos-legend .k { display: inline-flex; align-items: center; gap: 6px; }
.pos-legend .sw { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }

/* neighbours */
.neigh-body { display: grid; grid-template-columns: 1fr 90px 1fr; gap: 16px; align-items: start; margin-top: 8px; }
.neigh-col h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.neigh-center { text-align: center; }
.neigh-center .big { height: 70px; filter: var(--sign-filter); }
.neigh-center .lab { font-size: 12px; color: var(--muted); margin-top: 6px; }
.neigh-center .endstat { font-size: 12px; color: var(--text); margin-top: 10px; }
@media (max-width: 700px){ .neigh-body { grid-template-columns: 1fr; } }

/* matrix heatmap */
.matrix-wrap { overflow: auto; margin-top: 10px; }
table.matrix { border-collapse: collapse; }
table.matrix th { font-size: 10px; color: var(--muted); font-weight: 600; padding: 2px; }
table.matrix th.rowh { position: sticky; left: 0; background: var(--surface); text-align: right; padding-right: 6px; z-index: 1; }
table.matrix th.colh { height: 40px; }
table.matrix th.colh img, table.matrix th.rowh img { height: 20px; filter: var(--sign-filter); vertical-align: middle; }
table.matrix td { width: 20px; height: 20px; text-align: center; border: 1px solid var(--surface-2); }
table.matrix td.d { outline: 1px solid var(--border); }

/* crosstab */
.crosstab { border-collapse: collapse; font-size: 12px; width: 100%; }
.crosstab th, .crosstab td { border: 1px solid var(--border); padding: 5px 8px; text-align: right; }
.crosstab th { background: var(--surface-2); color: var(--muted); position: sticky; top: 0; }
.crosstab th.corner, .crosstab td.rowlab { text-align: left; position: sticky; left: 0; background: var(--surface-2); color: var(--text); z-index: 1; }

/* site footer */
.site-footer { text-align: center; color: var(--muted); font-size: 13px; padding: 22px 16px 30px;
  border-top: 1px solid var(--border); margin-top: 8px; }
.site-footer a { color: var(--accent); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* Analysis dropdown menu */
.tab .caret { font-size: 9px; opacity: .7; display: inline-block; transition: transform .15s; }
.tab[aria-expanded="true"] .caret { transform: rotate(180deg); }
.subtabs { position: fixed; z-index: 60; display: flex; gap: 22px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 14px 16px; max-width: calc(100vw - 16px); }
.subtabs[hidden] { display: none; }
.subtabs .dd-group { display: flex; flex-direction: column; gap: 2px; min-width: 118px; }
.subtabs .subgroup { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted);
  font-weight: 700; margin: 0 0 5px; padding-left: 8px; }
.subtab { border: none; background: transparent; color: var(--text); padding: 7px 10px; border-radius: 7px;
  font-size: 13px; cursor: pointer; font-weight: 500; text-align: left; white-space: nowrap; }
.subtab:hover { background: var(--surface-2); }
.subtab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.colh4 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 0 0 10px; }

/* entropy */
.entropy-nums { display: flex; flex-wrap: wrap; gap: 20px; margin-top: 14px; }
.entropy-nums .en { font-size: 13px; color: var(--muted); }
.entropy-nums .en b { color: var(--text); font-size: 16px; }

/* segments list */
.seg-row { display: grid; grid-template-columns: auto 1fr 120px; gap: 12px; align-items: center;
  padding: 6px 0; border-bottom: 1px solid var(--border); }
.seg-row .glyphs { display: flex; gap: 3px; align-items: center; flex-wrap: wrap; }
.seg-row .track { background: var(--surface-2); border-radius: 5px; height: 16px; overflow: hidden; }
.seg-row .fill { height: 100%; background: var(--accent); border-radius: 5px; }
.seg-row .v { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* positional heatmap */
table.posheat { border-collapse: collapse; }
table.posheat th { font-size: 10px; color: var(--muted); font-weight: 600; padding: 2px 4px; }
table.posheat th.rowh { position: sticky; left: 0; background: var(--surface); text-align: right; }
table.posheat th.rowh img { height: 20px; filter: var(--sign-filter); vertical-align: middle; }
table.posheat td { width: 34px; height: 22px; text-align: center; border: 1px solid var(--surface-2); font-size: 10px; color: rgba(255,255,255,.55); }

/* similarity clusters */
.clusters { display: flex; flex-direction: column; gap: 10px; }
.cluster { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; padding: 8px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; }
.cluster .cl-lbl { font-size: 11px; color: var(--muted); margin-right: 6px; }
.simcard { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
  padding: 4px 6px; border-radius: 6px; }
.simcard:hover { background: var(--surface-2); }
.simcard img { height: 34px; filter: var(--sign-filter); }
.simcard .cap { font-size: 11px; color: var(--muted); }

/* duplicates */
.dupgroup { display: flex; align-items: center; gap: 14px; padding: 8px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.dupgroup .seq { display: flex; gap: 3px; align-items: center; flex-wrap: wrap; }
.dupgroup .seq img { height: 30px; filter: var(--sign-filter); }
.dupgroup .cnt { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 700; }
.dupgroup .where { font-size: 12px; color: var(--muted); }
.dup-pair { display: flex; flex-direction: column; gap: 3px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.dup-pair .seq img { height: 26px; filter: var(--sign-filter); }
.dup-pair .seq img.diff { outline: 2px solid var(--accent); border-radius: 3px; }
.dup-pair .seq { display: flex; gap: 3px; align-items: center; flex-wrap: wrap; }

/* map */
.map-wrap { overflow: hidden; border-radius: 10px; background: #dfe7ee; border: 1px solid var(--border); margin-top: 8px; }
:root[data-theme="dark"] .map-wrap { background: #10151c; }
.map-wrap svg { width: 100%; height: auto; display: block; }
.map-land { fill: #eef2f5; stroke: #b8c2cc; stroke-width: 0.5; stroke-linejoin: round; }
:root[data-theme="dark"] .map-land { fill: #222834; stroke: #39424f; }
.map-site { fill: var(--accent); fill-opacity: .68; stroke: #fff; stroke-width: .6; cursor: pointer; }
:root[data-theme="dark"] .map-site { stroke: #0b0e13; }
.map-site:hover { fill-opacity: .95; }
.map-label { fill: var(--text); font-size: 11px; font-weight: 600; paint-order: stroke; stroke: #eef2f5; stroke-width: 3px; pointer-events: none; }
:root[data-theme="dark"] .map-label { stroke: #10151c; }
.map-legend text { fill: var(--muted); font-size: 11px; }
.map-legend circle { fill: none; stroke: var(--muted); }

/* timeline */
.timeline-svg { width: 100%; height: auto; display: block; }
.timeline-svg .tl-axis { stroke: var(--border); stroke-width: 1; }
.timeline-svg .tl-cnt { fill: var(--text); font-size: 11px; font-weight: 600; }
.timeline-svg .tl-lab { fill: var(--muted); font-size: 10px; }
.timeline-svg .tl-date { fill: var(--muted); font-size: 9px; }

/* modal graphical extras */
.map-wrap.mini { max-width: 100%; margin-top: 6px; }
.modal-body h3.sd-h { font-size: 13px; margin: 18px 0 8px; }
.text-chrono { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 16px; }
.text-chrono > div { flex: 1 1 300px; min-width: 260px; }
.chrono-cap { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* network */
#network svg { width: 100%; height: auto; display: block; }
#network image { filter: var(--sign-filter); }
#network .edge { stroke: var(--accent); fill: none; }
#network .nodedot { fill: var(--surface-2); stroke: var(--border); }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; }
  .subtitle { display: none; }
}

/* ================= mobile phones ================= */
@media (max-width: 640px) {
  html { -webkit-text-size-adjust: 100%; }

  /* top bar: brand + horizontally-scrollable primary tabs + toggle on one row */
  .topbar { flex-wrap: nowrap; gap: 8px; padding: 9px 12px; }
  .brand { gap: 0; flex: 0 0 auto; }
  .brand-mark { width: 34px; height: 34px; font-size: 19px; border-radius: 10px; }
  .brand > div { display: none; } /* hide title text on phones; logo mark stays */
  .tabs { margin-left: 2px; flex: 1 1 auto; min-width: 0; flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; white-space: nowrap; padding: 9px 11px; }
  .icon-btn { flex: 0 0 auto; margin-left: 2px; width: 38px; height: 38px; }

  /* Analysis dropdown: full-width panel, groups stacked */
  .subtabs { flex-direction: column; gap: 10px; max-height: 72vh; overflow-y: auto; max-width: none; }
  .subtabs .dd-group { min-width: 0; }
  .subtab { padding: 9px 11px; }

  main { padding: 12px; }
  .card, .card.chart { padding: 14px 13px; }
  .card > h3, .card.chart > h3 { font-size: 14px; }

  /* toolbars: fields wrap two-up, search & reset full width */
  .toolbar { padding: 12px; gap: 10px; }
  .toolbar .field { flex: 1 1 44%; min-width: 0; }
  .toolbar .field.grow { flex: 1 1 100%; }
  .toolbar .field input, .toolbar .field select { width: 100%; }
  .toolbar .btn { flex: 1 1 100%; }
  .result-meta.inline { flex: 1 1 100%; margin: 2px 0 0; text-align: left; }

  /* tables: tighter; drop low-priority columns from the Texts grid */
  .grid th, .grid td { padding: 7px 8px; font-size: 13px; }
  .col-text { min-width: 180px; }
  #txtTable th:nth-child(4), #txtTable td:nth-child(4),
  #txtTable th:nth-child(6), #txtTable td:nth-child(6),
  #txtTable th:nth-child(7), #txtTable td:nth-child(7) { display: none; }

  /* bar charts: narrower label/value columns */
  .hbar { grid-template-columns: 82px 1fr 44px; gap: 8px; }
  .hbar.glyphrow { grid-template-columns: 28px 42px 1fr 44px; }
  .persite-row { grid-template-columns: 110px 1fr 40px; }

  /* modals */
  .modal-panel { width: 94vw; max-height: 90vh; }
  .modal-head { padding: 14px 16px; }
  .modal-body { padding: 16px 14px; }
  .meta-grid { gap: 12px 16px; }
  .text-chrono > div { flex: 1 1 100%; }
  .sign-stats .st { padding: 9px 13px; }
  .sign-stats .st .n { font-size: 20px; }

  /* signs gallery: a touch smaller so 3–4 per row */
  .gallery { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }

  .pager button { min-width: 40px; height: 40px; }
}
