/* Глубина метро Петербурга.
 * Решения: светлая база (гранит и невская вода), тёмная по системе; цвет несут
 * только линии метро, интерфейс - чернилами; Golos Text с кириллицей; шторка
 * снизу под палец, на широком экране - панель слева. */
:root {
  --paper: #E9ECEF;
  --panel: #FFFFFF;
  --ink: #12161B;
  --ink-2: #4A525E;
  --ink-3: #858D98;
  --line: #DCE0E5;
  --chip: #F0F2F4;
  --shadow: 0 1px 2px rgba(18, 22, 27, .06), 0 12px 32px rgba(18, 22, 27, .10);
  --r: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0D1015; --panel: #161A21; --ink: #EDF0F4; --ink-2: #AEB5BF; --ink-3: #7A828D;
    --line: #262C35; --chip: #1E232B; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0D1015; --panel: #161A21; --ink: #EDF0F4; --ink-2: #AEB5BF; --ink-3: #7A828D;
  --line: #262C35; --chip: #1E232B; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper); color: var(--ink); overflow: hidden;
  font: 15px/1.45 "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
/* Подложка под заголовком: линии не читаются поверх текста, когда кадр сдвинут вверх. */
body::before { content: ''; position: fixed; left: 0; right: 0; top: 0; height: calc(150px + env(safe-area-inset-top, 0px)); pointer-events: none; z-index: 1;
  background: linear-gradient(var(--paper) 55%, color-mix(in srgb, var(--paper) 0%, transparent)); }
.head, .topbar { z-index: 3; }
/* В разрезе строка про растяжение и сводка не нужны: они про 3D-вид и мешают вкладкам линий. */
body.profile-on .head .meta, body.profile-on .scale-note { display: none; }

.head {
  position: fixed; left: 16px; top: calc(14px + env(safe-area-inset-top, 0px));
  pointer-events: none; max-width: calc(100% - 210px);
}
.head h1 { margin: 0; font-size: 17px; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; text-wrap: balance; }
.head .meta { margin: 2px 0 0; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.scale-note { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-2); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.scale-note button {
  pointer-events: auto; border: 0; cursor: pointer; background: var(--panel); color: var(--ink); font-size: 12.5px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; box-shadow: var(--shadow); transition: background-color 120ms ease, transform 100ms ease;
}
.scale-note button:active { transform: scale(.98); }
.scale-note button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.scale-note button[aria-pressed="true"] { background: var(--ink); color: var(--panel); }
.transfer { margin: 0; font-size: 14px; color: var(--ink-2); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.transfer em { font-style: normal; }
.transfer span { display: inline-flex; align-items: center; gap: 5px; color: var(--ink); font-weight: 500; }
.transfer i { width: 8px; height: 8px; border-radius: 50%; }
.fact { margin: 0; font-size: 13.5px; color: var(--ink-2); text-wrap: pretty; }
.fact b { color: var(--ink); font-weight: 600; }
.topbar { position: fixed; right: 16px; top: calc(12px + env(safe-area-inset-top, 0px)); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 3; }
.toprow { display: flex; gap: 8px; align-items: center; }
/* Подписи станций - второй строкой под видами (просьба владельца). */
/* Кнопки подписей - тот же вид, что у «3D / Сверху / Разрез» (просьба владельца). */
.labels-seg button { white-space: nowrap; }
.views { display: flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--panel); box-shadow: var(--shadow); }
.theme {
  width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--panel); box-shadow: var(--shadow); cursor: pointer;
  display: grid; place-items: center; color: var(--ink); transition: transform 100ms ease;
}
.theme:active { transform: scale(.96); }
.theme:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.theme svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme .moon { fill: currentColor; stroke: none; }
.theme[data-mode="dark"] .moon, .theme[data-mode="light"] .sun { display: none; }
.card { position: relative; }
.close {
  position: absolute; right: -4px; top: -4px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--chip);
  display: grid; place-items: center; cursor: pointer; color: var(--ink-2); transition: background-color 120ms ease;
}
.close:hover { color: var(--ink); }
.close:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.close svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.views button {
  border: 0; background: transparent; padding: 7px 13px; border-radius: 999px; font-size: 13px; font-weight: 600;
  color: var(--ink-2); cursor: pointer; transition: background-color 160ms ease, color 160ms ease;
}
.views button[aria-selected="true"], .views button[aria-checked="true"] { background: var(--ink); color: var(--panel); }
.views button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Районы - серые подписи на поверхности, как на бумажной карте */
.districts { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.district { position: absolute; left: 0; top: 0; visibility: hidden; font-size: 13px; font-weight: 700; color: color-mix(in srgb, var(--ink) 38%, transparent); white-space: nowrap; transform-origin: center; }
@media (min-width: 900px) { .district { font-size: 17px; } }
/* Подписи станций поверх сцены */
.labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.label {
  position: absolute; left: 0; top: 0; visibility: hidden; will-change: transform;
  background: var(--panel); color: var(--ink); border-radius: 4px; padding: 2px 7px 2px 6px;
  font-size: 11.5px; line-height: 1.35; font-weight: 500; white-space: nowrap; box-shadow: 0 1px 3px rgba(0,0,0,.14);
  display: flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums;
  border-left: 3px solid var(--c, var(--ink));
}
.label i { display: none; }
.label b { font-weight: 500; color: var(--ink-3); }
.label.sel { font-size: 13px; padding: 4px 9px 4px 8px; box-shadow: var(--shadow); border-left-width: 4px; }
.label.sel b { color: var(--ink); font-weight: 700; }
@media (min-width: 900px) { .label { font-size: 12px; } }

/* Шторка */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: var(--panel); border-radius: var(--r) var(--r) 0 0; box-shadow: var(--shadow);
  padding: 6px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 14px;
  max-height: 72vh; overflow-y: auto; overscroll-behavior: contain;
  transition: max-height 240ms cubic-bezier(.2,.8,.2,1);
}
.sheet[data-state="peek"] { max-height: 214px; }
/* Свёрнута свайпом вниз: видна только полоска, карта на весь экран. */
.sheet[data-state="hidden"] { max-height: calc(30px + env(safe-area-inset-bottom, 0px)); overflow: hidden; }
.sheet.dragging { transition: none; }
.grip { touch-action: none; }
body.profile-on .sheet[data-state="open"] { max-height: 46vh; }
.grip { display: block; width: calc(100% + 32px); height: 26px; border: 0; background: var(--panel); cursor: pointer; padding: 0; flex: none;
  position: sticky; top: -6px; z-index: 2; margin: -6px -16px 0; }
.grip span { display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; }

.search { position: relative; }
.search input {
  width: 100%; border: 0; border-radius: 12px; background: var(--chip); padding: 12px 14px; font-size: 16px; outline: none;
}
.search input:focus-visible { box-shadow: 0 0 0 2px var(--ink); }
.results {
  list-style: none; margin: 6px 0 0; padding: 4px; border-radius: 12px; background: var(--panel); box-shadow: var(--shadow);
  max-height: 260px; overflow-y: auto; position: absolute; left: 0; right: 0; z-index: 3;
}
.results button {
  width: 100%; display: flex; align-items: center; gap: 10px; border: 0; background: none; text-align: left;
  padding: 10px; border-radius: 8px; cursor: pointer; transition: background-color 120ms ease;
}
.results button:hover, .results button:focus-visible { background: var(--chip); outline: none; }
.results i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.results span { flex: 1; }
.results b { font-variant-numeric: tabular-nums; color: var(--ink-2); font-weight: 500; }

.card { display: flex; flex-direction: column; gap: 10px; }
.card-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); padding-right: 40px; }
.card-line i { width: 10px; height: 10px; border-radius: 50%; }
.card h2 { margin: 0; font-size: 24px; line-height: 1.15; font-weight: 700; letter-spacing: -.015em; text-wrap: balance; }
.depth { margin: 0; display: flex; align-items: baseline; gap: 8px; }
.depth b { font-size: 56px; line-height: 1; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.depth span { font-size: 15px; color: var(--ink-2); }
.status { margin: 0; font-size: 13px; font-weight: 600; color: var(--ink); background: var(--chip); border-radius: 8px; padding: 6px 10px; align-self: flex-start; }

.compare { display: flex; flex-direction: column; gap: 8px; }
.compare p { margin: 0; color: var(--ink-2); font-size: 14px; text-wrap: pretty; }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; font-size: 12.5px; color: var(--ink-2); }
.bar .track { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--chip); overflow: hidden; }
.bar .fill { height: 100%; border-radius: 3px; background: var(--ink-3); }
.bar.me .fill { background: var(--c, var(--ink)); }
.bar.me { color: var(--ink); font-weight: 600; }
.bar b { font-weight: 600; font-variant-numeric: tabular-nums; }

.facts { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.facts div { display: flex; flex-direction: column; gap: 2px; }
.facts dt { font-size: 12px; color: var(--ink-3); }
.facts dd { margin: 0; font-size: 14px; }
.src { margin: 0; font-size: 12.5px; color: var(--ink-3); }
.src a { color: var(--ink-2); }

.overview { display: flex; flex-direction: column; gap: 14px; }
.tops { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.tops::-webkit-scrollbar { display: none; }
.top {
  flex: none; display: flex; flex-direction: column; gap: 2px; text-align: left; border: 0; cursor: pointer;
  background: var(--chip); border-radius: 12px; padding: 10px 12px; min-width: 132px;
  transition: background-color 120ms ease, transform 100ms ease;
}
.top:active { transform: scale(.98); }
.top:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.top small { font-size: 12px; color: var(--ink-3); }
.top span { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.top span i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.top b { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

.setting { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-2); }
.seg { display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--chip); }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 6px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--ink-2); cursor: pointer; transition: background-color 160ms ease, color 160ms ease; }
.seg button[aria-checked="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }
.seg button:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }
.scale { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; font-size: 13px; color: var(--ink-2); }
.scale input { grid-column: 1 / -1; width: 100%; accent-color: var(--ink); }
.scale output { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.hint { margin: 0; font-size: 13px; color: var(--ink-3); }
.foot { font-size: 11.5px; line-height: 1.45; color: var(--ink-3); }

/* Разрез по линии */
.profile {
  position: fixed; left: 0; right: 0; top: calc(64px + env(safe-area-inset-top, 0px)); bottom: calc(var(--sheet-h, 214px) + 8px);
  display: flex; flex-direction: column; gap: 10px; padding: 0 16px; z-index: 2; background: var(--paper);
}
.profile-lines { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: none; }
.profile-lines::-webkit-scrollbar { display: none; }
.profile-lines button {
  flex: none; display: flex; align-items: center; gap: 6px; border: 0; background: var(--panel); border-radius: 999px;
  padding: 7px 12px; font-size: 13px; font-weight: 500; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.05);
  transition: background-color 160ms ease, color 160ms ease;
}
.profile-lines button i { width: 9px; height: 9px; border-radius: 50%; }
.profile-lines button[aria-selected="true"] { background: var(--ink); color: var(--panel); }
.profile-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.profile-scroll svg { display: block; height: 100%; min-height: 300px; }
.p-grid { stroke: var(--line); stroke-width: 1; }
.p-axis { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.p-surface { stroke: var(--ink-3); stroke-width: 1.5; stroke-dasharray: 5 5; }
.p-ref { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 2 4; }
.p-ref-t { fill: var(--ink-2); font-size: 11.5px; }
.p-name { fill: var(--ink-2); font-size: 12px; }
.p-depth { fill: var(--ink); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.p-st { cursor: pointer; }
.p-st:focus-visible circle { stroke: var(--ink); stroke-width: 3; }

/* На телефоне заголовок под верхней панелью: рядом с тремя кнопками вида ему не хватает места. */
@media (max-width: 899px) {
  .head { top: calc(106px + env(safe-area-inset-top, 0px)); max-width: calc(100% - 32px); }
  .topbar { left: 16px; }
  body::before { height: calc(244px + env(safe-area-inset-top, 0px)); }
  .profile { top: calc(156px + env(safe-area-inset-top, 0px)); }
}
@media (min-width: 900px) {
  .head { left: 404px; }
  .sheet {
    left: 16px; top: calc(16px + env(safe-area-inset-top, 0px)); bottom: 16px; right: auto; width: 372px;
    border-radius: var(--r); max-height: none; padding: 16px 18px;
  }
  .sheet[data-state="peek"] { max-height: none; }
  .grip { display: none; }
  .tops { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; margin: 0; padding: 0; }
  .top { min-width: 0; }
  .top span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
  .top span i { display: inline-block; margin-right: 6px; vertical-align: middle; }
  .profile { left: 404px; bottom: 16px; top: 76px; }
  body.profile-on .sheet[data-state="open"] { max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
body.profile-on .labels-seg { display: none; }
