/* Карта родословной: полосы по областям, древо связей, шкала эпох */
body[data-view="map"] { overflow: hidden; }
body[data-view="map"] .site-footer { display: none; }

.map-view {
  display: grid; grid-template-rows: auto auto 1fr; grid-template-columns: minmax(0, 1fr);
  height: calc(100dvh - var(--header-h));
}
@media (max-width: 760px) { .map-view { height: calc(100dvh - var(--header-h) - 64px - env(safe-area-inset-bottom)); } body[data-view="map"] { padding-bottom: 0; } }

/* ---------- Тулбар ---------- */
.map-toolbar { display: flex; align-items: center; gap: 10px 16px; padding: 10px var(--gutter) 8px; }
.map-links { display: inline-flex; flex: none; gap: 2px; padding: 2px; border: 1px solid var(--rule-strong); border-radius: 999px; }
.map-links button { border: 0; border-radius: 999px; padding: 6px 11px; background: transparent; color: var(--ink-2); font-size: var(--t-sm); line-height: 1.3; white-space: nowrap; cursor: pointer; }
.map-links button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.map-links button:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
.map-find { position: relative; display: flex; align-items: center; flex: 0 1 300px; }
.map-find > svg { position: absolute; left: 10px; width: 16px; height: 16px; color: var(--ink-3); pointer-events: none; }
.map-find input {
  width: 100%; height: 36px; padding: 0 12px 0 34px;
  border: 1px solid var(--rule-strong); border-radius: var(--radius-ui); background: var(--paper-2); font-size: var(--t-sm);
}
.map-find input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 20%, transparent); }
.map-find-results {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; width: min(380px, 90vw); list-style: none; padding: 6px;
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: 10px; box-shadow: 0 18px 40px -16px rgb(0 0 0 / 0.35);
}
.map-find-results li { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.map-find-results li[aria-selected="true"], .map-find-results li:hover { background: color-mix(in oklab, var(--ink) 7%, transparent); }
.mf-name { font-family: var(--serif); font-size: var(--t-md); }
.mf-dates { font-size: var(--t-xs); color: var(--ink-3); }

.map-switch { display: inline-flex; align-items: center; gap: 8px; font-size: var(--t-sm); color: var(--ink-2); cursor: pointer; user-select: none; white-space: nowrap; }
.map-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.map-switch .sw { width: 32px; height: 18px; border-radius: 999px; background: var(--rule-strong); position: relative; transition: background 0.2s; flex: none; }
.map-switch .sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--paper-2); transition: transform 0.2s var(--ease); box-shadow: 0 1px 2px rgb(0 0 0 / 0.25); }
.map-switch input:checked + .sw { background: var(--accent); }
.map-switch input:checked + .sw::after { transform: translateX(14px); }
.map-switch input:focus-visible + .sw { outline: 2px solid var(--accent); outline-offset: 2px; }

.map-pop-wrap { position: relative; }
.map-pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; width: 340px; padding: 14px 16px;
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: 10px; box-shadow: 0 18px 40px -16px rgb(0 0 0 / 0.35);
}
.map-filter-pop { width: 380px; }
.map-filter-btn { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.map-filter-btn svg { width: 16px; height: 16px; }
.map-filter-btn.is-active { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.mf-group { margin: 12px 0 6px; font-size: var(--t-xs); font-weight: 600; color: var(--ink-3); }
.mf-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.mf-reset { margin-top: 12px; }
.lg-title { font-family: var(--serif); font-size: var(--t-lg); margin-bottom: 10px; }
.map-legend-pop ul { list-style: none; display: grid; gap: 8px; }
.map-legend-pop li { display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: center; font-size: var(--t-sm); color: var(--ink-2); }
.map-legend-pop li svg { width: 40px; height: 14px; overflow: visible; }
.map-legend-pop .edge { stroke-opacity: 0.9; }
.edge.sec-legend { stroke: var(--ink-2); stroke-width: 1.4; fill: none; }
.lg-note { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--rule); font-size: var(--t-xs); color: var(--ink-3); line-height: 1.5; }
.zoom-ctrls { margin-left: auto; display: flex; align-items: center; gap: 2px; }

/* Чистый вид скрывает также маршруты, подписи линий и области попадания. */
.map-svg[data-link-mode="none"] :is(.m-edges, .m-edge-hits, .m-life, .m-cmp, .m-contexts, .m-trail, .m-stubs, .m-elabels, .m-dur) { display: none; }

@media (max-width: 1100px) {
  body[data-view="map"] .search-trigger { min-width: 0; width: 38px; padding: 0; justify-content: center; border-color: transparent; background: none; }
  body[data-view="map"] .search-trigger :is(span, kbd) { display: none; }
  body[data-view="map"] .main-nav a { white-space: nowrap; }
  .map-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: 8px 12px; }
  .map-find { grid-column: 1; grid-row: 1; min-width: 0; }
  .map-filter-wrap { grid-column: 2; grid-row: 1; }
  .map-legend-wrap { grid-column: 3; grid-row: 1; }
  .zoom-ctrls { grid-column: 4; grid-row: 1; margin-left: 0; }
  .map-links { grid-column: 1 / -1; grid-row: 2; justify-self: start; }
}

/* ---------- Шкала эпох ---------- */
.era-nav { display: flex; gap: 8px; padding: 0 var(--gutter) 8px; border-bottom: 1px solid var(--rule); }
.era-nav-track { flex: 1 1 0; min-width: 0; }
.era-nav-track { position: relative; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; cursor: pointer; touch-action: pan-x; }
.era-nav-track::-webkit-scrollbar { display: none; }
.era-nav-track.dragging { cursor: grabbing; }
.en-seg {
  flex: 1 1 0; min-width: 0; display: grid; gap: 1px; padding: 6px 8px 7px; text-align: left;
  border: 0; border-top: 3px solid var(--c); border-radius: 0 0 6px 6px; background: color-mix(in oklab, var(--c) 6%, transparent);
  transition: background 0.2s;
}
.en-seg:hover { background: color-mix(in oklab, var(--c) 16%, transparent); }
.en-seg.in-view { background: color-mix(in oklab, var(--c) 14%, transparent); }
.en-name { font-size: 12px; font-weight: 500; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.en-seg.in-view .en-name { color: var(--ink); }
.en-count { font-size: 11px; color: var(--ink-3); }
.era-nav-window {
  position: absolute; top: 0; bottom: 0; left: 0; width: 0; pointer-events: none;
  border: 2px solid var(--accent); border-radius: 6px; box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 14%, transparent);
}
.era-nav[hidden], .map-era-labels[hidden], .me-label[hidden] { display: none; }
.map-time-vertical { grid-template-rows: auto 1fr; }
/* Отдельные плашки поверх карты, без сплошной боковой панели. */
.map-era-labels { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.me-label {
  position: absolute; right: 38px; transform: translateY(-50%); height: var(--era-label-h, 24px);
  display: flex; align-items: center; padding: 0 7px; max-width: 112px; border: 1px solid var(--rule); border-right: 2px solid var(--c);
  border-radius: 5px; background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  color: var(--ink-2); font: 500 10.5px/14px var(--sans); white-space: nowrap;
  cursor: pointer; pointer-events: auto;
}
.me-label:hover { background: var(--paper-2); color: var(--ink); }
.me-label:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.me-leaders { position: absolute; inset: 0; width: 100%; height: 100%; overflow: hidden; }
.me-leaders path { fill: none; stroke-width: 1; opacity: 0.6; }

/* ---------- Полотно ---------- */
.map-stage { position: relative; overflow: hidden; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; outline-offset: -3px; }
.map-stage.dragging { cursor: grabbing; }
.map-svg { position: absolute; inset: 0; }
.era-line { stroke: var(--rule); stroke-width: 1; }

.axis-bg { fill: var(--paper); }
.axis-line { stroke: var(--rule-strong); }
.axis-strip { opacity: 0.85; }
.axis-start { font-size: 11px; fill: var(--ink-2); font-weight: 500; }
.tick { stroke: var(--rule-strong); }
.tick-label { font-size: 11px; fill: var(--ink-3); text-anchor: middle; }

/* Стволы: от точки зарождения до последнего потомка; чернила, толщина — вес родословной. */
.life { fill: none; stroke: var(--ink-2); stroke-width: calc(1.1px + var(--w, 0) * 0.32px); stroke-opacity: 0.55; stroke-linecap: round; transition: stroke-opacity 0.25s; }
.z0 .life { stroke-width: calc(0.8px + var(--w, 0) * 0.26px); stroke-opacity: 0.42; }
/* Длительность выбранного стиля: полоса цвета эпохи под точкой и стволом. */
.dur { fill: none; stroke-width: 6; stroke-opacity: 0.55; stroke-linecap: round; pointer-events: none; }
.dur.hover { stroke-opacity: 0.3; }
.dur-legend { fill: none; stroke: var(--era-xix); stroke-width: 6; stroke-opacity: 0.55; stroke-linecap: round; }

/* Ветви и связи: чернила; тип — штрихом и словом, статус — толщиной. Подложка цвета бумаги
   делает пересечения «мостиками», чтобы они не выглядели узлами. */
.edge { fill: none; stroke: var(--ink-2); stroke-linecap: round; stroke-linejoin: round; transition: stroke 0.3s, stroke-opacity 0.3s, stroke-width 0.3s; }
.edge-g .case { fill: none; stroke: var(--paper); stroke-width: 5; stroke-linecap: butt; stroke-dasharray: 0 9 100000; }
.edge.tree { stroke-opacity: 0.55; stroke-width: calc(1.1px + var(--w, 0) * 0.32px); }
.z0 .edge.tree { stroke-opacity: 0.42; stroke-width: calc(0.8px + var(--w, 0) * 0.26px); }
.z0 .edge-g .case { stroke-width: 3; }
.edge.sec { stroke-opacity: 0.45; stroke-width: 1.1; }
.show-all .edge.sec { stroke-opacity: 0.22; }
.edge.rel-influence { stroke-width: 1; }
.edge.st-verified { stroke: var(--ink); stroke-opacity: 0.95; }
.edge-g.near .edge { stroke: var(--ink); stroke-opacity: 0.9; stroke-width: 1.8; }
.edge.lg { stroke-opacity: 0.9; stroke-width: 1.5; }
.edge.lg.st-verified { stroke: var(--ink); stroke-opacity: 1; }
.edge.lg.st-unverified { stroke-opacity: 0.45; }
.edge.lg.weight { stroke-width: 3.2; }
/* Визуальные сопоставления — отдельный слой: цвет акцента, редкий пунктир. */
.edge.cmp { stroke: var(--accent); stroke-opacity: 0.55; stroke-width: 1.3; stroke-dasharray: 2 5; }
.edge.cmp.near { stroke-opacity: 0.95; stroke-width: 1.8; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.lg-layers { display: grid; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--rule); }

/* Оборванные далёкие связи: отростки и парные подписи */
.edge-g.stub .case { display: none; }
.edge-g.stub .edge { stroke-opacity: 0.6; }
.stub-label { font-family: var(--sans); font-size: 11px; fill: var(--ink-3); text-anchor: end; pointer-events: none; paint-order: stroke; stroke: var(--paper); stroke-width: 4px; stroke-linejoin: round; }
.stub-label.out-label { text-anchor: start; }
.ep-go { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ep-go .chip { font-size: var(--t-xs); }

/* Ориентиры общего вида: миниатюры крупных узлов родословной */
.node.lm-on .ring { display: block; }

/* Подложки подписей: цвет бумаги, чтобы линия уходила под название */
.plate { fill: var(--paper); fill-opacity: 0.94; pointer-events: none; opacity: var(--label-zoom, 1); transition: opacity 0.25s; }
.has-hover .plate:not(.near) { opacity: calc(var(--label-zoom, 1) * 0.28); }
.has-selection .plate:not(.lit) { opacity: calc(var(--label-zoom, 1) * 0.16); }
.plate.out { opacity: calc(var(--label-zoom, 1) * 0.12); }

/* Узлы и подписи */
.node { cursor: pointer; outline: none; opacity: var(--node-zoom, 1); }
.node .hit { fill: transparent; }
.node .dot { stroke: var(--paper); stroke-width: 1.5; }
.node .ring { fill: none; stroke-width: 2; display: none; }
.z2 .node .ring { display: block; }
.map-svg:not(.z2) .node:not(.lm-on) .thumb-img { display: none; }
.z2 .node .dot { stroke: none; }
.label {
  opacity: var(--label-zoom, 1);
  fill: var(--ink); paint-order: stroke; stroke: var(--paper); stroke-width: 4px; stroke-linejoin: round;
  font-family: var(--sans); font-size: 14px; font-weight: 500; cursor: pointer; transition: opacity 0.25s;
}
.label.t1 { font-family: var(--serif); font-size: 16px; font-weight: 600; }
.label.t3 { font-size: 13px; font-weight: 400; fill: var(--ink-2); }
.label .l-dates { display: none; font-family: var(--sans); font-size: 11px; font-weight: 400; fill: var(--ink-3); }
.z2 .label .l-dates { display: inline; }
.label:hover { fill: var(--accent); }
.node:focus-visible .dot, .node:focus-visible .ring { stroke: var(--accent); stroke-width: 3; }

/* Фильтр: несовпавшие стили бледнеют, но остаются на своих местах. */
.node.out { opacity: calc(var(--node-zoom, 1) * 0.12); }
.label.out { opacity: calc(var(--label-zoom, 1) * 0.12); }
.life.out { stroke-opacity: 0.06; }
.edge-g.out .edge { stroke-opacity: 0.06; }
.edge-g.out .case { display: none; }

/* Наведение: стиль и его прямые связи */
.has-hover .node:not(.near) { opacity: calc(var(--node-zoom, 1) * 0.28); }
.has-hover .label:not(.near) { opacity: calc(var(--label-zoom, 1) * 0.28); }
.has-hover .life:not(.near) { stroke-opacity: 0.08; }
.has-hover .edge-g:not(.near) .edge { stroke-opacity: 0.08; }

/* Выбор: крупный план связей или вся родословная */
.has-selection .node:not(.lit) { opacity: calc(var(--node-zoom, 1) * 0.16); }
.has-selection .label:not(.lit) { opacity: calc(var(--label-zoom, 1) * 0.16); }
.has-selection .life:not(.lit) { stroke-opacity: 0.06; }
.has-selection .life.lit { stroke-opacity: 0.55; }
.has-selection .life.is-selected { stroke: var(--ink); stroke-opacity: 0.9; }
.has-selection .edge-g .edge { stroke-opacity: 0.06; }
.has-selection .edge-g:not(.hl) .case { display: none; }
.has-selection .edge-g.hl .edge { stroke: var(--ink); stroke-opacity: 0.9; stroke-width: 2; }
.has-selection .edge-g.hl .edge.st-unverified { stroke-opacity: 0.7; }
.mode-line .edge-g.hl .edge { stroke-opacity: 0.45; stroke-width: 1.4; }
.mode-line .edge-g.hl.desc .edge { stroke-opacity: 0.8; stroke-width: 2; }
.mode-line .edge-g.hl.main .edge { stroke: var(--accent); stroke-opacity: 1; stroke-width: 3.2; }
.has-selection .edge.cmp:not(.near) { stroke-opacity: 0.05; }
.node.is-selected .dot, .node.is-selected .ring { stroke: var(--ink); stroke-width: 3; }
.label.is-selected { fill: var(--ink); font-weight: 700; }
/* Контекст не должен перекрывать чтение морей на общем плане. */
.map-svg .edge.context:not(.near) { stroke-opacity: var(--context-alpha, 0.35); stroke-width: 1.1; }
.map-svg .edge.context.st-unverified:not(.near) { stroke-opacity: calc(var(--context-alpha, 0.35) * 0.6); }
.map-svg .edge.context.near { stroke-opacity: 0.85; stroke-width: 1.8; }
.map-svg .edge.context.st-unverified.near { stroke-opacity: 0.5; }
.has-selection .edge.context:not(.near), .has-hover .edge.context:not(.near) { stroke-opacity: 0.06; }
.elabel {
  font-family: var(--sans); font-size: 11.5px; font-weight: 500; fill: var(--ink-2); text-anchor: middle; pointer-events: none;
  paint-order: stroke; stroke: var(--paper); stroke-width: 5px; stroke-linejoin: round;
}
.sel-year { font-size: 11px; font-weight: 600; fill: var(--ink-2); text-anchor: middle; paint-order: stroke; stroke: var(--paper); stroke-width: 4px; pointer-events: none; }
.sel-year.end { text-anchor: middle; }

/* Метки связей за краем экрана */
.map-offscreen { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.oc-chip {
  position: absolute; left: 0; top: 0; pointer-events: auto; display: inline-flex; align-items: center; gap: 8px;
  max-width: 230px; padding: 5px 10px 5px 8px; text-align: left;
  background: var(--paper-2); border: 1px solid var(--rule-strong); border-radius: 999px;
  box-shadow: 0 6px 18px -10px rgb(0 0 0 / 0.4); font-size: var(--t-xs); color: var(--ink-2); cursor: pointer;
}
.oc-chip:hover { border-color: var(--ink-2); color: var(--ink); }
.oc-arrow { font-size: 15px; line-height: 1; color: var(--ink); }
.oc-text { display: grid; line-height: 1.15; min-width: 0; }
.oc-rel { font-size: 10.5px; color: var(--ink-3); }
.oc-name { font-family: var(--serif); font-size: var(--t-sm); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Миникарта — отдельное окошко в углу полотна, как в играх: вся карта и рамка видимой части. */
.mm-box { position: absolute; left: 14px; bottom: 14px; z-index: 4; display: flex; align-items: flex-start; gap: 4px; }
.minimap {
  position: relative; width: 248px; height: 104px; cursor: crosshair; touch-action: none; overflow: hidden;
  background: color-mix(in oklab, var(--paper-2) 92%, transparent); border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: 0 10px 28px -14px color-mix(in oklab, var(--ink) 45%, transparent), 0 1px 2px color-mix(in oklab, var(--ink) 8%, transparent);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.minimap canvas { position: absolute; inset: 0; display: block; }
.mm-frame { position: absolute; left: 0; top: 0; border: 1.5px solid var(--ink); border-radius: 3px; background: color-mix(in oklab, var(--ink) 7%, transparent); pointer-events: none; }
.mm-toggle {
  display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border-radius: 7px; cursor: pointer;
  background: var(--paper-2); border: 1px solid var(--rule); color: var(--ink-2);
}
.mm-toggle svg { width: 16px; height: 16px; }
.mm-toggle:hover { color: var(--ink); border-color: var(--ink-3); }
.mm-ic-show { display: none; }
.mm-box.collapsed .minimap, .mm-box.collapsed .mm-ic-hide { display: none; }
.mm-box.collapsed .mm-ic-show { display: block; }
.mm-box.collapsed .mm-toggle { width: 38px; height: 38px; border-radius: 10px; box-shadow: 0 6px 18px -10px color-mix(in oklab, var(--ink) 45%, transparent); }
.mm-box.collapsed .mm-toggle svg { width: 20px; height: 20px; }

/* Подсказка */
.map-tip {
  position: absolute; left: 0; top: 0; z-index: 6; pointer-events: none;
  display: grid; grid-template-columns: 72px 1fr; gap: 12px; width: 330px; padding: 10px;
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: 0 14px 40px -14px rgb(0 0 0 / 0.4);
}
.map-tip[hidden] { display: none; }
.map-tip .thumb { width: 72px; height: 72px; display: block; overflow: hidden; background: var(--ph); border-radius: 6px; }
.map-tip .thumb img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.3s; }
.map-tip .thumb img.is-loaded { opacity: 1; }
.tip-text { display: grid; align-content: start; gap: 2px; }
.tip-name { font-family: var(--serif); font-size: var(--t-lg); line-height: 1.15; }
.tip-dates { font-size: var(--t-xs); color: var(--ink-3); }
.tip-sum { margin-top: 4px; font-size: var(--t-sm); color: var(--ink-2); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tip-rel { margin-top: 4px; font-size: var(--t-xs); color: var(--accent); }

/* Объяснение связи */
.map-edge-pop {
  position: absolute; left: 0; top: 0; z-index: 7; width: min(320px, calc(100% - 16px)); padding: 12px 14px;
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: 0 14px 40px -14px rgb(0 0 0 / 0.4); font-size: var(--t-sm); line-height: 1.45; cursor: auto;
  max-height: calc(100% - 48px); overflow-y: auto; overscroll-behavior: contain;
}
.map-edge-pop[hidden] { display: none; }
.ep-head { font-family: var(--serif); font-size: var(--t-lg); line-height: 1.25; }
.ep-kind { margin-top: 4px; color: var(--ink-2); }
.ep-note { margin-top: 8px; color: var(--ink-2); }
.ep-src { margin-top: 8px; font-size: var(--t-xs); color: var(--ink-3); }
.ep-src a { color: inherit; }

/* Панель выбранного стиля */
.map-panel {
  position: absolute; z-index: 8; top: 12px; right: 12px; bottom: 12px; width: min(380px, calc(100% - 24px));
  overflow-y: auto; overscroll-behavior: contain; cursor: auto;
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: 12px;
  box-shadow: 0 24px 60px -24px rgb(0 0 0 / 0.45);
  animation: panel-in 0.35s var(--ease);
}
.map-panel[hidden] { display: none; }
@keyframes panel-in { from { opacity: 0; transform: translateX(16px); } }
.mp-close { position: absolute; top: 8px; right: 8px; z-index: 2; background: color-mix(in oklab, var(--paper-2) 80%, transparent); }
.mp-art { display: block; }
.mp-art .art-frame { border-radius: 12px 12px 0 0; }
.mp-body { padding: 16px 18px 20px; display: grid; gap: 6px; }
.mp-name { font-family: var(--serif); font-size: var(--t-3xl); line-height: 1.08; letter-spacing: -0.01em; margin-top: 4px; }
.mp-orig { color: var(--ink-3); font-size: var(--t-sm); }
.mp-sum { margin-top: 8px; font-family: var(--serif); font-size: var(--t-lg); line-height: 1.5; color: var(--ink-2); }
.mp-rel { margin-top: 12px; }
.mp-rel h3 { font-size: var(--t-xs); font-weight: 600; color: var(--ink-3); margin-bottom: 6px; }
.mp-rel ul { list-style: none; display: grid; gap: 4px; }
.mp-node {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; text-align: left;
  border: 1px solid var(--rule); border-radius: 6px; background: none; font-family: var(--serif); font-size: var(--t-md);
}
.mp-node:hover { border-color: var(--ink-3); }
.mp-node-rel { display: block; font-family: var(--sans); font-size: 11px; color: var(--ink-3); }
.mp-rel-note { margin: 4px 2px 6px; font-size: var(--t-xs); color: var(--ink-2); line-height: 1.45; }
.mp-origin { margin-top: 10px; font-size: var(--t-sm); color: var(--ink-2); }
.mp-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.mp-kind { font-size: var(--t-xs); color: var(--ink-3); }
.mp-modes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.mp-open { margin-top: 16px; justify-content: center; }

.map-loading { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--serif); font-size: var(--t-xl); color: var(--ink-3); }
.map-hint { position: absolute; left: 304px; bottom: 14px; font-size: var(--t-xs); color: var(--ink-3); pointer-events: none; background: color-mix(in oklab, var(--paper) 85%, transparent); padding: 4px 9px; border-radius: 6px; }

@media (max-width: 900px) {
  .map-switch { font-size: var(--t-xs); }
}
@media (max-width: 760px) {
  .map-toolbar { gap: 8px; padding: 8px var(--gutter); }
  .map-find { flex: 1 1 0; min-width: 0; }
  .map-switch { gap: 6px; font-size: 12px; }
  .map-switch .sw { width: 28px; height: 16px; }
  .map-switch .sw::after { width: 12px; height: 12px; }
  .map-switch input:checked + .sw::after { transform: translateX(12px); }
  .zoom-ctrls .chip { padding: 0 10px; font-size: 12px; }
  .zoom-ctrls .icon-btn { display: none; }
  .map-links { justify-self: stretch; }
  .map-links button { flex: 1; padding: 6px 8px; font-size: 12px; }
  .map-filter-btn .mfb-label { max-width: 96px; overflow: hidden; text-overflow: ellipsis; }
  .map-filter-pop { position: fixed; left: 8px; right: 8px; top: calc(var(--header-h) + 58px); width: auto; max-height: 68dvh; overflow-y: auto; }
  .minimap { width: 136px; height: 60px; }
  .mm-box { left: 10px; bottom: 10px; }
  .map-hint { display: none; }

  /* Легенда нужна и на телефоне: в ней слои и объяснение статусов связей. */
  .map-legend-pop { position: fixed; left: 8px; right: 8px; top: calc(var(--header-h) + 58px); width: auto; max-height: 68dvh; overflow-y: auto; }
  .zoom-ctrls { margin-left: 0; }
  .en-seg { flex: 0 0 auto; min-width: 84px; }
  .map-panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 46%; animation-name: sheet-in; }
  .mp-art .art-frame { aspect-ratio: 21 / 9 !important; }
  @keyframes sheet-in { from { opacity: 0; transform: translateY(24px); } }
}
.map-stage:has(.map-panel:not([hidden])) .map-hint { display: none; }
.map-stage:has(.mm-box.collapsed) .map-hint { left: 62px; }
.map-hint { transition: opacity .4s ease; }
.map-hint.is-gone { opacity: 0; }
@media (min-width: 761px) and (max-height: 820px) { .minimap { width: 208px; height: 84px; } .map-hint { left: 264px; } }
@media (max-width: 760px) { .map-stage:has(.map-panel:not([hidden])) .mm-box { display: none; } }

/* Маршрут по карте: трек и цепочка стилей */
.m-trail .trail-path { fill: none; stroke: var(--ink); stroke-width: 3.5; stroke-opacity: 0.85; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.map-trail { position: absolute; left: 290px; bottom: 14px; z-index: 3; max-width: min(620px, calc(100% - 720px)); display: flex; align-items: center; gap: 4px; padding: 4px 6px; background: color-mix(in srgb, var(--paper) 92%, transparent); border: 1px solid var(--rule); border-radius: var(--radius-ui); font: 12px var(--sans); }
.map-trail[hidden] { display: none; }
.map-trail ol { display: flex; flex-wrap: wrap; gap: 2px; margin: 0; padding: 0; list-style: none; }
.map-trail li + li::before { content: '→'; margin: 0 4px; color: var(--ink-3); }
.map-trail button { font: inherit; color: var(--ink-2); background: none; border: 0; padding: 2px 4px; border-radius: 4px; cursor: pointer; }
.map-trail button:hover { background: var(--paper-3); }
.map-trail button.is-last { color: var(--ink); font-weight: 600; }
.map-trail .mt-clear { margin-left: 4px; color: var(--ink-3); }
@media (max-width: 760px) { .map-trail { left: 12px; bottom: auto; top: 8px; max-width: calc(100% - 24px); } .map-trail ol { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; scrollbar-width: none; } }

/* Туманности: слой на canvas под деревом, названия — в SVG */
.map-neb { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
.map-svg { position: relative; z-index: 1; }
.m-nebnames { pointer-events: none; }

/* Желоба по краям: сжатые стили — только точки */
.node.gutter .thumb-img, .node.gutter .ring { display: none; }
.node.gutter .dot { stroke-width: 0.8; }

/* Узкий экран: карта повёрнута на 90° — время сверху вниз; размер и поворот задаёт resize() */
.map-stage.rot .map-svg, .map-stage.rot .map-neb { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none; max-height: none; }
.map-stage.rot .mm-box { display: none; }

/* Масштаб меняет предмет чтения: моря → части → отдельные эстетики. */
.mm-box.is-quiet { display: none; }
.map-hint { display: none; }
.label, .plate { transition: none; }
.m-nebnames .region-name { pointer-events: visiblePainted; cursor: pointer; outline: none; }
.region-name:hover, .region-name:focus-visible { filter: brightness(0.75); text-decoration: underline; text-underline-offset: 4px; }
[data-theme="dark"] .region-name:hover, [data-theme="dark"] .region-name:focus-visible { filter: brightness(1.25); }
.summary-case { fill: none; stroke: var(--paper); stroke-linecap: round; pointer-events: none; }
.summary-line { fill: none; stroke: var(--ink-2); stroke-dasharray: 5 6; stroke-linecap: round; pointer-events: none; }
.summary-port { fill: var(--paper); stroke: var(--ink-2); stroke-width: 1.1; pointer-events: none; }
.summary-hit { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: pointer; outline: none; }
.summary-hit:focus-visible { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 3 5; }
.summary-records { display: grid; gap: 4px; margin-top: 10px; }
.map-edge-pop [data-close-edge] { position: absolute; top: 5px; right: 5px; width: 26px; height: 26px; }
.map-edge-pop .ep-head { padding-right: 28px; }
.summary-records button { text-align: left; padding: 8px; border: 0; border-radius: 5px; background: var(--paper); font: inherit; font-size: 12px; cursor: pointer; }
.summary-records button:hover { background: color-mix(in oklab, var(--accent) 9%, var(--paper)); }
.summary-records small { display: block; margin-top: 3px; color: var(--ink-3); }
.map-levels { position: absolute; z-index: 5; bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 2px; padding: 4px; border: 1px solid var(--rule); border-radius: 999px; background: var(--paper-2); box-shadow: 0 3px 18px rgb(0 0 0 / 0.06); white-space: nowrap; }
.map-levels[hidden] { display: none; }
.map-levels button { border: 0; background: transparent; border-radius: 999px; padding: 6px 11px; font-size: 12px; color: var(--ink-3); cursor: pointer; }
.map-levels button[aria-current] { background: var(--ink); color: var(--paper); }
.map-levels button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.map-levels > span { color: var(--ink-3); font-size: 12px; }
.map-levels .map-browse { border-left: 1px solid var(--rule); border-radius: 0 99px 99px 0; padding-inline: 11px; font-size: 15px; line-height: 1; }
.map-stage:has(.mm-box:not(.is-quiet)):not(.rot) .map-levels { left: auto; right: 14px; transform: none; }
.map-stage:has(.map-panel:not([hidden])) .map-levels { display: none; }
.map-directory { position: absolute; z-index: 10; left: 14px; bottom: 64px; width: min(350px, calc(100% - 28px)); max-height: calc(100% - 80px); overflow-y: auto; overscroll-behavior: contain; background: var(--paper-2); border: 1px solid var(--rule); border-radius: 12px; padding: 14px; box-shadow: 0 10px 35px rgb(0 0 0 / 0.14); }
.map-directory[hidden] { display: none; }
.md-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.md-head strong { font: 600 21px var(--serif); }
.map-directory > p { font-size: 12px; color: var(--ink-3); line-height: 1.5; margin: 5px 0 12px; }
.md-list { display: grid; gap: 3px; }
.md-list button { display: flex; align-items: center; gap: 9px; border: 0; border-radius: 5px; padding: 8px; background: transparent; color: var(--ink); text-align: left; font-size: 13px; line-height: 1.35; cursor: pointer; }
.md-list button:hover { background: color-mix(in oklab, var(--ink) 6%, transparent); }
.md-list i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); flex: none; }
.md-list small { margin-left: auto; color: var(--ink-3); }
.map-directory details { font-size: 13px; margin-top: 12px; border-top: 1px solid var(--rule); padding-top: 12px; }
.map-directory summary { cursor: pointer; color: var(--ink-2); padding: 4px; }
@media (max-width: 760px) {
  .map-levels { bottom: 10px; }
  .map-stage:has(.map-panel:not([hidden])) .map-levels { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .label, .plate, .edge, .life { transition: none; }
}
