/* Proof maps — shared styles */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1f2430;
  --ink-2: #3b4252;
  --muted: #6b7280;
  --line: #e3e6eb;
  --line-2: #d3d8df;
  --accent: #2458d6;
  --accent-soft: #e8efff;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --warn: #9a5b00;
  --warn-soft: #fff4dc;
  --ok: #1d7a45;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* techniques: the same colours on the map, in the filter and in the legend */
  --t-model: #6d3fd8;
  --t-critic: #0b7285;
  --t-dominates: #c2410c;
  --t-height: #2f7d32;
  --t-load: #5f6b7a;
  --t-closer: #9a6700;
  --t-cone: #1f2a44;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 var(--sans);
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---------------- header ---------------- */
.top {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.brand { font-weight: 700; color: var(--ink); white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand svg { flex: none; }
.proj { min-width: 0; display: flex; align-items: baseline; gap: 10px; overflow: hidden; }
.proj-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj-sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--warn-soft); color: var(--warn); white-space: nowrap;
}
.links { margin-left: auto; display: flex; gap: 14px; font-size: 13px; white-space: nowrap; }
.links a { color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.links a img { width: 16px; height: 16px; border-radius: 3px; flex: none; }
.byline { font-size: 12.5px; color: var(--muted); }
.ki-mark { color: #1e9be0; font-weight: 700; }
.links a:hover { color: var(--accent); }

/* ---------------- buttons, inputs ---------------- */
.btn {
  border: 1px solid var(--line-2); background: var(--panel); border-radius: 6px;
  padding: 4px 10px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.small { padding: 1px 8px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
select, input[type=number], input[type=search], input[type=text] {
  border: 1px solid var(--line-2); border-radius: 6px; padding: 3px 6px; background: var(--panel);
}
input[type=number] { width: 72px; }
label.ctl { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
label.ctl > span { color: var(--muted); font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------------- index page ---------------- */
.wrap { max-width: 1040px; margin: 0 auto; padding: 24px 16px 40px; }
.intro { max-width: 70ch; color: var(--ink-2); }
.intro h1 { font-size: 22px; margin: 8px 0 8px; color: var(--ink); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; margin-top: 22px; }
.card {
  display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; color: var(--ink);
}
.card:hover { border-color: var(--accent); text-decoration: none; }
div.card { cursor: pointer; }
.card h3 a { color: var(--ink); }
.src-link { color: var(--ink-2); }
.src-link:hover { color: var(--accent); }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card .src { font-family: var(--mono); font-size: 12px; color: var(--muted); word-break: break-all; }
.card .nums { margin-top: 10px; font-size: 13px; color: var(--ink-2); }
.card .id { float: right; font-size: 12px; color: var(--muted); }
.empty { padding: 24px; border: 1px dashed var(--line-2); border-radius: 10px; color: var(--muted); }
footer.site { margin-top: 36px; font-size: 12.5px; color: var(--muted); }

/* ---------------- viewer shell ---------------- */
body.viewer { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.banner {
  display: flex; gap: 12px; align-items: center; padding: 6px 16px; font-size: 13px;
  background: var(--danger-soft); color: #7a1a1a; border-bottom: 1px solid #f3c7c7;
}
.banner .btn { border-color: #e5a5a5; }
.banner.warn { background: var(--warn-soft); color: #5c3b00; border-bottom-color: #f0d9a6; }
.banner .x { margin-left: auto; cursor: pointer; border: 0; background: none; font-size: 16px; color: inherit; }

.controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.controls .sep { width: 1px; align-self: stretch; background: var(--line); }
.controls.filters { padding-top: 6px; padding-bottom: 6px; background: #fafbfc; }
.controls .grow { flex: 1; }
#params { display: contents; }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line-2); border-radius: 999px; padding: 1px 9px 1px 3px;
  font-size: 12.5px; cursor: pointer; background: var(--panel); user-select: none;
}
.chip .g {
  display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 4px;
  font: 700 10.5px/1 var(--sans); color: #fff;
}
.chip.off { opacity: .45; }
.chip.off .g { background: #9aa3ad !important; }
.chip input { display: none; }

.viewline {
  padding: 6px 16px; font-size: 13px; color: var(--ink-2); background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.viewline b { color: var(--ink); }

.tabbar { display: flex; align-items: flex-end; gap: 8px; background: var(--bg); border-bottom: 1px solid var(--line); flex: none; }
.tabs {
  display: flex; gap: 2px; padding: 6px 12px 0; flex: 1; min-width: 0; overflow-x: auto;
}
.tabtools { display: flex; gap: 6px; padding: 4px 12px 5px 0; flex: none; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; font-size: 13px;
  border: 1px solid var(--line); border-bottom: 0; border-radius: 7px 7px 0 0;
  background: #eceef2; cursor: pointer; white-space: nowrap; max-width: 360px;
}
.tab span { overflow: hidden; text-overflow: ellipsis; }
.tab.active { background: var(--panel); font-weight: 600; }
.tab .close { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 0 0 2px; font-size: 14px; }
.tab .close:hover { color: var(--danger); }

main { flex: 1; display: flex; min-height: 0; }
#stage { position: relative; flex: 1; min-width: 0; background: var(--panel); }
.cy { position: absolute; inset: 0; }
.cy.hidden-tab { visibility: hidden; }

/* the tree of files on the left */
#tree { width: 290px; flex: none; display: flex; flex-direction: column; min-height: 0;
        border-right: 1px solid var(--line); background: var(--panel); }
.tree-head { display: flex; align-items: baseline; gap: 8px; padding: 10px 12px 6px; font-size: 13px; width: 100%;
             border: 0; background: none; cursor: pointer; text-align: left; color: var(--ink); }
.tree-head .grow { flex: 1; }
#tree-caret { color: var(--muted); font-size: 11px; }
.tree-head:hover #tree-caret { color: var(--ink); }
/* folded, like the legend: a narrow strip along the edge */
#tree.collapsed { width: 30px; }
#tree.collapsed #tree-q, #tree.collapsed .tree-body, #tree.collapsed .tree-foot { display: none; }
#tree.collapsed .tree-head { writing-mode: vertical-rl; padding: 10px 6px; height: 100%; align-items: center; }
#tree-q { margin: 0 12px 8px; padding: 5px 8px; border: 1px solid var(--line-2); border-radius: 6px; font-size: 13px; }
.tree-body { flex: 1; overflow-y: auto; padding: 0 6px 10px; font-size: 12.5px; }
.tf, .ti { display: flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 5px; cursor: pointer;
           white-space: nowrap; }
.tf:hover, .ti:hover { background: #f1f4f9; }
.tf .caret { width: 10px; flex: none; color: var(--muted); font-size: 10px; }
.tf .nm, .ti .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); }
.tf .ct { flex: none; color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.tf .ct b { color: var(--ink); }
.tf.boxed .nm { font-weight: 600; }
.tm { padding-left: 14px; }
.ti .kd { flex: none; min-width: 16px; height: 16px; padding: 0 3px; border-radius: 4px; color: #fff; font-size: 10px;
          font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.ti.off { color: #9aa3ad; }
.ti.off .kd { opacity: .45; }
.ti.sel { background: var(--accent-soft); }
.tmore { padding: 3px 8px 3px 30px; font-size: 12px; }
.tree-foot { padding: 6px 12px 8px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line); }

#side {
  width: 420px; flex: none; border-left: 1px solid var(--line); background: var(--panel);
  overflow-y: auto; padding: 14px 16px 24px;
}
#side h2 { font-size: 16px; margin: 6px 0 8px; line-height: 1.35; }
#side h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 6px; }
/* the proof: collapsed under the statement until asked for */
#side details.proof { margin: 10px 0 2px; }
/* names of what a statement uses, in its statement and proof: as in the tree */
#side pre.stmt a.ref { cursor: pointer; text-decoration: none; border-bottom: 1px solid currentColor; }
#side pre.stmt a.ref.on { color: var(--accent); }
#side pre.stmt a.ref.off { color: #7b8794; border-bottom-style: dotted; }
#side pre.stmt a.ref:hover { background: var(--accent-soft); }
#side details.proof summary { cursor: pointer; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
                              color: var(--muted); font-weight: 600; }
#side details.proof summary .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
#side details.proof pre.stmt { margin-top: 6px; max-height: 480px; }
#side pre.stmt {
  font: 12.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; background: #f7f8fa;
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; margin: 0; max-height: 300px; overflow: auto;
}
.kv { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv td { padding: 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.kv td:first-child { color: var(--muted); width: 38%; padding-right: 8px; }
.flags { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.flag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 5px; }
.flag.axiom { background: var(--danger-soft); color: var(--danger); }
.flag.bp { background: #fff6d6; color: #7a5a00; }
.flag.kind { background: #eef0f3; color: var(--ink-2); }
.flag.unasked { background: #f1f2f4; color: var(--muted); }
.name { font: 12.5px/1.45 var(--mono); word-break: break-all; color: var(--ink-2); }
.missing { color: var(--muted); font-style: italic; }
.nb { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.nb li { display: flex; gap: 6px; align-items: baseline; padding: 3px 0; border-bottom: 1px solid var(--line); }
.nb li a { flex: 1; cursor: pointer; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.help { font-size: 13px; color: var(--ink-2); }
.help p { margin: 6px 0; }
.help ul { margin: 6px 0; padding-left: 18px; }
.legend { display: grid; grid-template-columns: auto 1fr; gap: 5px 10px; font-size: 13px; align-items: center; }
.legend .g {
  display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 4px;
  font: 700 10.5px/1 var(--sans); color: #fff; cursor: pointer;
}
.legend .sw { width: 30px; height: 16px; border-radius: 4px; border: 1.5px solid #8a94a3; background: #fff; }
.legend .hint { color: var(--muted); font-size: 12px; }
.legend .row { display: contents; cursor: pointer; }
.legend .row.on > * { font-weight: 600; }

#status {
  display: flex; flex-wrap: wrap; gap: 4px 18px; padding: 5px 16px; font-size: 12.5px;
  color: var(--ink-2); background: var(--panel); border-top: 1px solid var(--line); flex: none;
}
#status b { font-weight: 600; color: var(--ink); }
#status a { cursor: pointer; }

.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.65);
  z-index: 5; font-size: 14px; color: var(--ink-2);
}
.overlay .card { display: flex; gap: 10px; align-items: center; }
.spin { width: 18px; height: 18px; border: 2px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: s 0.8s linear infinite; }
@keyframes s { to { transform: rotate(360deg); } }
.error {
  margin: 10px 0; padding: 10px 12px; background: var(--danger-soft); color: #6b1111; border-radius: 6px;
  font-size: 13px; white-space: pre-wrap; word-break: break-word;
}
.error pre { font: 12px/1.4 var(--mono); white-space: pre-wrap; margin: 6px 0 0; }

#tip {
  position: fixed; z-index: 20; pointer-events: none; max-width: 360px; padding: 6px 9px; font-size: 12.5px;
  background: #1f2430; color: #fff; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
}

/* ---------------- legend, floating in a corner of the graph ---------------- */
.legend-box {
  position: absolute; left: 12px; bottom: 12px; z-index: 4; max-width: 330px; max-height: calc(100% - 24px);
  display: flex; flex-direction: column;
  background: rgba(255,255,255,.96); border: 1px solid var(--line-2); border-radius: 8px;
  box-shadow: 0 4px 18px rgba(0,0,0,.08); font-size: 12.5px;
}
.legend-head { border: 0; background: none; cursor: pointer; text-align: left; padding: 6px 10px; font-weight: 600; font-size: 12.5px; }
#legend-body { overflow-y: auto; padding: 0 10px 10px; }
.legend-box.collapsed #legend-body { display: none; }
.legend-box h4 { margin: 8px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.legend-box .legend { gap: 3px 8px; font-size: 12.5px; }
.legend .ln { width: 30px; height: 0; border-top: 2px solid #a3acb8; }
.legend .ln.dash { border-top: 1.5px dashed #7d8ea3; }

/* ---------------- route popover ---------------- */
.pop {
  position: absolute; z-index: 25; top: 96px; left: 50%; transform: translateX(-50%); width: min(820px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: 0 10px 34px rgba(0,0,0,.16);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 10px;
}
.pop-row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.pop-row .grow { flex: 1; }
.pop-hint { font-size: 12.5px; }
.ac { position: relative; display: inline-block; }
.ac input { width: 300px; max-width: 70vw; font-family: var(--mono); font-size: 12.5px; }
.ac input.chosen { border-color: var(--ok); background: #f3fbf5; }
.ac-list {
  position: absolute; top: 100%; left: 0; z-index: 30; width: 460px; max-width: 86vw; max-height: 320px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.14);
}
.ac-list div { padding: 5px 9px; cursor: pointer; border-bottom: 1px solid var(--line); white-space: normal; }
.ac-list div:hover, .ac-list div.on { background: var(--accent-soft); }
.ac-list .n { font-family: var(--mono); font-size: 12.5px; }
.ac-list .d { color: var(--muted); font-size: 12px; }
.flag.def { background: #e2f2e5; color: #25603a; }
.flag.side { background: #eef7f0; color: #25603a; border: 1px dashed #3f8f55; }
details.note { margin-top: 8px; font-size: 12.5px; }
details.note summary { cursor: pointer; color: var(--muted); }
details.note p { margin: 6px 0 0; color: var(--ink-2); }
.tip-name { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.tip-kind { font-size: 11.5px; opacity: .75; margin: 1px 0 4px; }
.tip-expl { font-size: 13px; }

/* ---------------- search dropdown ---------------- */
#search-wrap input { width: 230px; font-family: var(--sans); font-size: 13px; }
#search-list { width: 520px; max-height: 60vh; }
#search-list .sec { padding: 5px 9px 3px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); background: #f6f7f9; cursor: default; border-bottom: 1px solid var(--line); }
#search-list .row { display: flex; gap: 8px; align-items: baseline; }
#search-list .row .n { flex: 1; word-break: break-all; }
#search-list .add { font-size: 11.5px; color: var(--accent); white-space: nowrap; }

/* ---------------- table tabs (data behind the metamodel) ---------------- */
.tbl { position: absolute; inset: 0; overflow: auto; padding: 12px 16px 24px; background: var(--panel); }
.tbl.hidden-tab { visibility: hidden; }
.tbl-head { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-bottom: 10px; }
.tbl-head h2 { font-size: 16px; margin: 0; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line-2);
  padding: 5px 8px; position: sticky; top: -12px; background: var(--panel); cursor: pointer; white-space: nowrap; }
table.data th.num, table.data td.num { text-align: right; }
table.data td { padding: 4px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr.row:hover td { background: #f5f8ff; cursor: pointer; }
table.data tr.row.on td { background: var(--accent-soft); }
table.data td.nm { font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
table.data td.ds { color: var(--ink-2); }
.more { margin: 12px 0; }

#side .g {
  display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 4px; flex: none;
  font: 700 10.5px/1 var(--sans); color: #fff;
}

/* ---------------- duplicates ---------------- */
.dstats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin: 6px 0 14px; max-width: 1000px; }
.dcard { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; background: #fafbfc; }
.dcard .v { font-size: 20px; font-weight: 700; }
.dcard .l { font-size: 12px; color: var(--muted); }
.dcard.big { border-color: var(--accent); background: var(--accent-soft); }
.dcard.big .v { color: var(--accent); }
.dgroup { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 10px 0; max-width: 1100px; }
.dg-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; font-size: 13.5px; }
.dstmt { font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; background: #f7f8fa;
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin: 0 0 6px; max-height: 120px; overflow: auto; }
.dcites { font-size: 12.5px; margin-top: 6px; }
.dcites > div { margin: 3px 0; }
.flag.citable { background: #e2f2e5; color: #25603a; }
.flag.refactor { background: var(--warn-soft); color: var(--warn); }

/* ---------------- metamodel panel ---------------- */
.math { margin: 8px 0 4px; font-size: 14px; }
.math .katex-display { margin: 6px 0; text-align: left; }
.math .katex-display > .katex { text-align: left; }
.defn { border-left: 3px solid var(--accent); background: #f7f9ff; padding: 6px 10px; margin: 8px 0; border-radius: 0 6px 6px 0; font-size: 13px; }
.checks { list-style: none; padding: 0; margin: 6px 0; font-size: 13px; }
.checks li { padding: 2px 0; }
.checks .ok { color: var(--ok); font-weight: 700; }
.checks .no { color: var(--danger); font-weight: 700; }
table.kv.click tr:hover td { background: #f5f8ff; cursor: pointer; }
.mk { font-weight: 800; }
.mk.H { color: #c62828; } .mk.I { color: #2458d6; } .mk.P { color: #1d7a45; } .mk.C { color: #9a6700; }
.words { font-family: var(--mono); font-size: 12px; max-height: 240px; overflow: auto; background: #f7f8fa;
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }

/* ---------------- datalog drawer ---------------- */
#drawer {
  position: fixed; right: 0; top: 0; bottom: 0; width: min(760px, 100vw); z-index: 30;
  background: var(--panel); border-left: 1px solid var(--line-2); box-shadow: -8px 0 30px rgba(0,0,0,.12);
  display: flex; flex-direction: column;
}
#drawer header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
#drawer header h2 { margin: 0; font-size: 15px; flex: 1; }
#drawer .dtabs { display: flex; gap: 4px; padding: 8px 14px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#drawer .dtabs button { border: 1px solid var(--line); border-bottom: 0; background: #eceef2; border-radius: 6px 6px 0 0; padding: 4px 10px; cursor: pointer; font-size: 13px; }
#drawer .dtabs button.active { background: var(--panel); font-weight: 600; }
#drawer .dbody { flex: 1; overflow: auto; padding: 0; }
#drawer pre.code {
  margin: 0; padding: 12px 16px; font: 12.5px/1.55 var(--mono); white-space: pre; tab-size: 4;
}
#drawer pre.code .c { color: #6a737d; }
#drawer pre.code .d { color: #0b5cad; font-weight: 600; }
#drawer pre.code .p { color: #b3261e; font-weight: 600; }
#drawer pre.code .s { color: #1d7a45; }
#drawer textarea { width: 100%; height: 100%; border: 0; padding: 12px 16px; font: 12.5px/1.55 var(--mono); resize: none; }
#drawer .dfoot { padding: 8px 14px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); }

/* ---------------- narrow screens ---------------- */
@media (max-width: 860px) {
  body.viewer { height: auto; min-height: 100vh; overflow: auto; }
  main { flex-direction: column; }
  #stage { height: 62vh; flex: none; }
  #side { width: auto; border-left: 0; border-top: 1px solid var(--line); }
  #tree { width: auto; max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
  #tree.collapsed { width: auto; }
  #tree.collapsed .tree-head { writing-mode: horizontal-tb; height: auto; }
  .links { display: none; }
  .top { flex-wrap: wrap; }
  .controls { padding: 8px 12px; }
}

/* front page: visits (counts only, from /api/visits) */
.visits { margin-top: 30px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px 14px; }
.visits .vhead { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.visits h2 { font-size: 17px; margin: 0; }
.visits .vsub { color: var(--muted); font-size: 12.5px; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 11px; background: #fafbfc; }
.tile b { display: block; font-size: 28px; line-height: 1.15; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.tile span { display: block; font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.tile small { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.vchart { margin-top: 18px; }
.vchart h3, .vlist h3 { font-size: 13px; margin: 0 0 6px; color: var(--ink-2); font-weight: 600; }
.vchart svg { display: block; }
.vcols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 26px; margin-top: 16px; }
.vrow { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) 40px; align-items: center; gap: 10px;
        font-size: 13px; padding: 3px 0; }
.vrow .lab { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vrow .bar { height: 8px; background: var(--accent-soft); border-radius: 4px; overflow: hidden; }
.vrow .bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.vrow b { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.vnote { margin: 14px 0 0; font-size: 12px; color: var(--muted); }
.vtip { position: fixed; z-index: 20; pointer-events: none; padding: 5px 9px; font-size: 12.5px; line-height: 1.4;
        background: #1f2430; color: #fff; border-radius: 6px; box-shadow: 0 4px 16px rgba(0, 0, 0, .18); }
@media (max-width: 720px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .vcols { grid-template-columns: minmax(0, 1fr); }
}

/* what a map leads to: a button that opens a searchable list */
.pick { position: relative; }
.pick-btn { font-family: var(--mono); font-size: 12.5px; font-weight: 600; max-width: 280px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.pick-panel { position: absolute; top: calc(100% + 4px); left: 0; z-index: 40; width: 500px; max-width: 86vw;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.14);
  padding: 8px; }
.pick-panel .pick-q { width: 100%; box-sizing: border-box; font-family: var(--mono); font-size: 12.5px; }
.pick-items { max-height: 340px; overflow-y: auto; margin-top: 6px; border-top: 1px solid var(--line); }
.pick-items > div { padding: 5px 8px; cursor: pointer; border-bottom: 1px solid var(--line); }
.pick-items > div:hover, .pick-items > div.on { background: var(--accent-soft); }
.pick-items > div.cur .n { font-weight: 700; }
.pick-items .row { display: flex; gap: 10px; align-items: baseline; }
.pick-items .n { font-family: var(--mono); font-size: 12.5px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pick-items .c { color: var(--muted); font-size: 12px; white-space: nowrap; }
.pick-items .d { color: var(--muted); font-size: 12px; }
.pick-foot { color: var(--muted); font-size: 12px; padding: 6px 2px 0; }
