/* Палитра — от самого места: светлый известняк Нарвской крепости, тёмная вода реки,
   синий эстонского флага для данных. Тёмная тема — та же река ночью. */
:root {
  color-scheme: light;
  --page: #eceeeb;
  --surface: #fbfcfa;
  --surface-2: #eff1ee;
  --ink: #0f1e2b;
  --ink-2: #3e4b57;
  --muted: #5c6873;
  --grid: #e2e6e5;
  --axis: #c2c9cc;
  --border: rgba(15, 30, 43, 0.11);
  --series: #0072ce;
  --series-wash: rgba(0, 114, 206, 0.1);
  --series-dot: rgba(0, 114, 206, 0.28);
  --typical: #96a1aa;
  --band: rgba(15, 30, 43, 0.035);
  --good: #127a42;
  --serious: #b0500d;
  --critical: #c8352e;
  --frame-bg: #101a22;
  --shadow: 0 1px 2px rgba(15, 30, 43, 0.05);
  --radius: 14px;
  --gutter: 16px; /* поля страницы; на телефоне меньше, у выреза экрана — по safe-area */
  --sans: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0b1016;
    --surface: #121921;
    --surface-2: #1a232c;
    --ink: #e8edf1;
    --ink-2: #b8c2ca;
    --muted: #8a96a1;
    --grid: #212b34;
    --axis: #36434e;
    --border: rgba(232, 237, 241, 0.1);
    --series: #3d9bf0;
    --series-wash: rgba(61, 155, 240, 0.15);
    --series-dot: rgba(61, 155, 240, 0.38);
    --typical: #6a7782;
    --band: rgba(232, 237, 241, 0.035);
    --good: #34c26f;
    --serious: #f0965c;
    --critical: #ef6a60;
    --frame-bg: #070b0f;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0b1016;
  --surface: #121921;
  --surface-2: #1a232c;
  --ink: #e8edf1;
  --ink-2: #b8c2ca;
  --muted: #8a96a1;
  --grid: #212b34;
  --axis: #36434e;
  --border: rgba(232, 237, 241, 0.1);
  --series: #3d9bf0;
  --series-wash: rgba(61, 155, 240, 0.15);
  --series-dot: rgba(61, 155, 240, 0.38);
  --typical: #6a7782;
  --band: rgba(232, 237, 241, 0.035);
  --good: #34c26f;
  --serious: #f0965c;
  --critical: #ef6a60;
  --frame-bg: #070b0f;
  --shadow: none;
}

* { box-sizing: border-box; }

html { scrollbar-gutter: stable; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
/* Пока открыто окно, страница под ним не прокручивается */
html:has(dialog[open]) { overflow: hidden; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 400 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration-color: var(--axis); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
button, input, select, textarea { font: inherit; color: inherit; }
button, summary, select, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
/* Одна и та же рамка фокуса у всех кнопок и ссылок — видна только при работе с клавиатуры */
:is(a, button, summary, select, input, textarea):focus-visible { outline: 2px solid var(--series); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--series) 22%, transparent); }
[hidden] { display: none !important; }
/* Набор значков: в разметке, но на странице не занимает места */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.shell {
  width: min(1120px, 100% - 2 * max(var(--gutter), env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px)));
  margin: 0 auto;
}

/* Шапка */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 0; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  flex: none; width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; background: var(--ink); color: var(--page);
}
.brand-name { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.2; }
.brand-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; line-height: 1.3; }
.topbar-side { display: flex; align-items: center; gap: 10px; }
.clock { margin-left: 4px; text-align: right; color: var(--muted); font-size: 12px; line-height: 1.3; white-space: nowrap; }
.clock strong { display: block; color: var(--ink); font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.lang-select {
  height: 36px; padding: 0 8px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); font-size: 13px; font-weight: 500; cursor: pointer;
}
.link-button {
  padding: 0; border: 0; background: none; cursor: pointer; font-size: 14px; color: var(--ink-2);
  text-decoration: underline; text-decoration-color: var(--axis); text-underline-offset: 3px;
}
.how-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px 0 12px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--ink);
  font-size: 13px; font-weight: 500; line-height: 1; white-space: nowrap; cursor: pointer;
}
.how-button span { overflow: hidden; text-overflow: ellipsis; }
.how-button svg { width: 15px; height: 15px; flex: none; color: var(--series); }
@media (hover: hover) {
  .link-button:hover { color: var(--ink); text-decoration-color: currentColor; }
  .how-button:hover, .lang-select:hover { background: var(--surface-2); }
}

/* Часы работы перехода и открыт ли он сейчас */
.notice {
  display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin: 16px 0 0; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-size: 14px; color: var(--ink-2);
}
.crossing-status {
  display: inline-flex; align-items: center; gap: 7px; padding: 3px 10px 3px 9px; border-radius: 999px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  color: var(--good); background: color-mix(in srgb, var(--good) 11%, transparent);
}
.crossing-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.crossing-status[data-state="soon"] { color: var(--serious); background: color-mix(in srgb, var(--serious) 11%, transparent); }
.crossing-status[data-state="closed"] { color: var(--ink-2); background: var(--surface-2); }
.crossing-status[data-state="closed"]::before { background: var(--muted); }

.intro { padding: 26px 0 0; max-width: 760px; }
.intro h1 { margin: 0; font-size: clamp(25px, 3.3vw, 34px); font-weight: 700; line-height: 1.12; letter-spacing: -0.015em; text-wrap: balance; }
.intro p { margin: 10px 0 0; color: var(--ink-2); font-size: 15px; text-wrap: pretty; }

main { padding: 24px 0 48px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.icon-button {
  display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; flex: none;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface); cursor: pointer;
}
@media (hover: hover) {
  .icon-button:hover:not(:disabled) { background: var(--surface-2); }
}
.icon-button:disabled { opacity: 0.35; cursor: default; }

/* Отклик на нажатие — на телефоне нет наведения, кнопке нужно «продавливаться» */
.icon-button, .how-button, .share-button, .toggle, .segmented button, .primary-button {
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
:is(.icon-button, .how-button, .share-button, .toggle, .segmented button, .primary-button):active:not(:disabled) {
  transform: scale(0.96);
}

/* Сейчас */
.now-grid { display: grid; grid-template-columns: minmax(290px, 0.8fr) minmax(0, 1.6fr); gap: 16px; }
.now-card { padding: 22px 22px 20px; display: flex; flex-direction: column; gap: 16px; }
.eyebrow { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--ink-2); font-size: 14px; font-weight: 500; }
/* Точка «в эфире»: пульсирует, пока кадры свежие, серая — когда данные устарели */
.live-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--axis); }
.live-dot[data-live="true"] { background: var(--good); animation: live-pulse 2.4s ease-out infinite; }
@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 55%, transparent); }
  70%, 100% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--good) 0%, transparent); }
}
.now-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.share-button {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px 0 10px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  font-size: 13px; color: var(--ink-2); cursor: pointer;
}
@media (hover: hover) {
  .share-button:hover { color: var(--ink); background: var(--surface-2); }
}

.toast {
  position: fixed; z-index: 50; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--ink); color: var(--page); font-size: 14px; box-shadow: 0 10px 30px rgba(8, 15, 22, 0.25);
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } }
.hero { display: flex; align-items: baseline; gap: 10px; margin-top: 6px; }
.hero-number { font-size: clamp(68px, 9vw, 100px); font-weight: 600; line-height: 0.92; letter-spacing: -0.04em; }
.hero-unit { color: var(--ink-2); font-size: 18px; }
.hero-meta { margin: 10px 0 0; color: var(--muted); font-size: 13px; }

/* Очередь фигурками (app.js → renderQueueStrip) */
.queue-strip { margin-top: 16px; }
.queue-figures { display: flex; flex-wrap: wrap; gap: 8px 3px; }
.qp { position: relative; flex: none; width: 10px; height: 25px; color: var(--ink); }
.qp::before, .qp::after { content: ""; position: absolute; left: 0; background: currentColor; }
.qp::before { top: 0; left: 1.5px; width: 7px; height: 7px; border-radius: 50%; }
.qp::after { top: 9px; width: 10px; height: 16px; border-radius: 4px 4px 2px 2px; }
.qp.over { color: var(--serious); }
.qp.ghost::before, .qp.ghost::after { background: none; box-shadow: inset 0 0 0 1.25px var(--typical); }
.queue-scale { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }

.facts { display: grid; gap: 10px; margin: 0; padding: 14px 0 0; border-top: 1px solid var(--border); }
.fact { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 14px; }
.fact dt { color: var(--ink-2); }
.fact dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.fact-next { flex-direction: column; align-items: stretch; gap: 2px; padding-top: 10px; border-top: 1px solid var(--border); }
.fact-next dd { text-align: left; }
.fact-next dd small { display: block; color: var(--muted); font-size: 13px; font-weight: 400; }

.verdict {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  background: var(--surface-2); font-size: 14px; font-weight: 500;
}
.verdict svg { flex: none; }
.verdict[data-tone="good"] { color: var(--good); background: color-mix(in srgb, var(--good) 9%, var(--surface)); }
.verdict[data-tone="serious"] { color: var(--serious); background: color-mix(in srgb, var(--serious) 9%, var(--surface)); }
.verdict[data-tone="neutral"] { color: var(--ink-2); }

.alert {
  margin: 0; padding: 10px 12px; border-radius: 10px; font-size: 13px;
  color: var(--critical); background: color-mix(in srgb, var(--critical) 10%, transparent);
}

/* Кадр */
.frame-card { overflow: hidden; display: flex; flex-direction: column; }
.frame-head {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 12px;
  padding: 12px 14px 12px 18px; border-bottom: 1px solid var(--border);
}
.frame-title { margin: 0; font-size: 14px; font-weight: 600; white-space: nowrap; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 9px; background: var(--surface-2); }
.segmented button {
  border: 0; background: transparent; padding: 5px 10px; border-radius: 7px;
  font-size: 13px; color: var(--ink-2); white-space: nowrap; cursor: pointer;
}
@media (hover: hover) {
  .segmented button:hover { color: var(--ink); }
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 500; box-shadow: 0 1px 2px rgba(8, 15, 22, 0.14); }
.frame { position: relative; flex: 1; min-height: 220px; background: var(--frame-bg); display: grid; place-items: center; }
.frame img { display: block; width: 100%; height: 100%; object-fit: contain; }
.frame-empty { color: #b5bec5; font-size: 14px; padding: 24px; text-align: center; }
.frame-foot {
  display: flex; justify-content: space-between; gap: 12px; padding: 10px 18px;
  color: var(--muted); font-size: 12px; border-top: 1px solid var(--border);
}

/* Разделы */
.section { margin-top: 44px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.section-title { margin: 0; font-size: 23px; font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
.section-sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; min-height: 1em; }

.day-nav { display: inline-flex; align-items: center; gap: 4px; }
.day-label {
  position: relative; display: grid; place-items: center; min-width: 150px; height: 36px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.day-label input {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0;
}
.day-label input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.day-label:focus-within { outline: 2px solid var(--series); outline-offset: 2px; }
@media (hover: hover) {
  .day-label:hover { background: var(--surface-2); }
}

.toolbar-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.toggle {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px 0 11px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  font-size: 13px; color: var(--ink-2); cursor: pointer;
}
.toggle svg { color: var(--muted); }
@media (hover: hover) {
  .toggle:hover { color: var(--ink); border-color: var(--axis); }
}
/* Включённый слой графика — синим, как сами данные; выключенный — нейтральный */
.toggle[aria-pressed="true"] {
  background: color-mix(in srgb, var(--series) 9%, var(--surface));
  border-color: color-mix(in srgb, var(--series) 45%, transparent);
  color: var(--ink);
}
.toggle[aria-pressed="true"] svg { color: var(--series); }

.chart-card { padding: 16px 18px 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0 0 4px; padding: 0; list-style: none; font-size: 13px; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 8px; }
.key { width: 16px; height: 2px; border-radius: 1px; background: var(--series); }
.key.typical { height: 2px; background: repeating-linear-gradient(90deg, var(--typical) 0 5px, transparent 5px 8px); }
.key-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--series-dot); }
.key-band { width: 14px; height: 10px; border-radius: 2px; background: var(--surface-2); border: 1px solid var(--grid); }

.chart { position: relative; height: 300px; touch-action: pan-y; }
.chart.loading { opacity: 0.5; transition: opacity 0.2s; }
.chart > svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .band { fill: var(--band); }
.chart .tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-wash); }
.chart .frame-dot { fill: var(--series-dot); }
.chart .typical { fill: none; stroke: var(--typical); stroke-width: 1.75; stroke-dasharray: 5 4; stroke-linejoin: round; stroke-linecap: round; }
.chart .now-line { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .crosshair { stroke: var(--ink-2); stroke-width: 1; pointer-events: none; }
.chart .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; pointer-events: none; }
.chart .dot.selected { fill: var(--surface); stroke: var(--series); stroke-width: 3; }
.chart .overlay { fill: transparent; cursor: pointer; outline: none; }
.chart .overlay:focus-visible { stroke: var(--series); stroke-width: 2; }
.chart .marker-line { stroke: var(--grid); stroke-width: 1; }
.chart .marker-line.next { stroke: var(--axis); }
.chart .marker { cursor: pointer; outline: none; color: var(--ink-2); }
.chart .marker-hit { fill: transparent; }
.chart .marker-bg { fill: var(--surface); stroke: var(--axis); stroke-width: 1; }
.chart .marker.past { opacity: 0.45; }
.chart .marker.next { color: var(--surface); }
.chart .marker.next .marker-bg { fill: var(--ink); stroke: var(--ink); }
.chart .marker:hover .marker-bg, .chart .marker:focus-visible .marker-bg { stroke: var(--ink); stroke-width: 2; }
.chart .marker-badge { fill: var(--ink-2); stroke: var(--surface); stroke-width: 1.5; }
.chart .marker-badge-text { fill: var(--surface); font-size: 8px; font-weight: 700; }
.chart .marker-time { fill: var(--ink); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-empty {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  color: var(--muted); font-size: 14px; text-align: center; pointer-events: none;
}
.chart-note { margin: 8px 0 0; font-size: 13px; color: var(--ink-2); }
.chart-note.muted { margin-top: 2px; color: var(--muted); }

.tooltip {
  position: absolute; z-index: 5; top: 0; left: 0; width: 256px; padding: 10px 10px 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(8, 15, 22, 0.18); pointer-events: none; font-size: 13px;
}
.tooltip .tt-value { font-size: 20px; font-weight: 600; line-height: 1.2; }
.tooltip .tt-value small { font-size: 13px; font-weight: 400; color: var(--ink-2); }
.tooltip .tt-time { color: var(--muted); margin-top: 2px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; color: var(--ink-2); }
.tooltip .tt-row .key { flex: none; }
.tooltip .tt-row b { color: var(--ink); font-weight: 600; }
.tooltip .tt-hint { margin-top: 6px; color: var(--muted); font-size: 12px; }
.tooltip img { display: block; width: 100%; margin-top: 8px; border-radius: 8px; background: var(--frame-bg); aspect-ratio: 3 / 1; object-fit: cover; }
.tooltip .tt-arrival { display: flex; gap: 8px; align-items: flex-start; }
.tooltip .tt-arrival + .tt-arrival { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.tooltip .tt-arrival svg { flex: none; margin-top: 2px; color: var(--ink); }
.tooltip .tt-arrival-title { font-weight: 600; color: var(--ink); }

.stats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; align-items: end; gap: 16px;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border);
}
.stat-label { display: block; color: var(--muted); font-size: 13px; }
.stat-value { display: block; font-size: 26px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 13px; font-weight: 400; color: var(--muted); }
.stat-samples { color: var(--muted); font-size: 13px; text-align: right; }

/* Прибытия и закономерности */
.split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; margin-top: 16px; align-items: start; }
.panel { padding: 18px 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-title { margin: 0; font-size: 17px; font-weight: 600; line-height: 1.3; }
.panel-sub { margin: 6px 0 10px; color: var(--muted); font-size: 13px; }
.panel-empty { margin: 8px 0; color: var(--ink-2); font-size: 14px; }
.panel-foot { margin: 12px 0 0; color: var(--muted); font-size: 12px; }
.pill {
  flex: none; padding: 3px 10px; border-radius: 999px; background: var(--ink); color: var(--page);
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap;
}

.arrivals { list-style: none; margin: 0; padding: 0; }
.arrival {
  display: grid; grid-template-columns: 32px 48px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 9px 0; border-top: 1px solid var(--border); font-size: 14px;
}
.arrival.past, .arrival.closed { opacity: 0.55; }
.arrival-icon {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--border); color: var(--ink-2);
}
.arrival.next .arrival-icon { background: var(--ink); border-color: var(--ink); color: var(--page); }
.arrival-time { font-weight: 600; font-variant-numeric: tabular-nums; }
.arrival-body { display: flex; flex-direction: column; min-width: 0; }
.arrival-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arrival-sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arrival-impact {
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink);
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; cursor: help;
}
#arrivals-past { margin-top: 8px; }

.insight { margin: 10px 0 0; font-size: 14px; color: var(--ink-2); }
.insight strong { color: var(--ink); white-space: nowrap; }
.insight-label { margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
.insight-routes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 14px; }
.wave { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 10px; }
.wave.past { opacity: 0.55; }
.wave-icons { display: flex; gap: 2px; color: var(--ink-2); }
.wave.next .wave-icons { color: var(--ink); }
.wave-body { display: flex; flex-direction: column; min-width: 0; }
.wave-time { font-weight: 600; font-variant-numeric: tabular-nums; }
.wave-items { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Таблица */
details.table-view { margin-top: 12px; font-size: 14px; }
details.table-view summary {
  position: relative; display: inline-block; padding-right: 20px; border-radius: 6px;
  cursor: pointer; color: var(--ink-2); list-style: none;
}
details.table-view summary::-webkit-details-marker { display: none; }
/* Стрелка как у частых вопросов */
details.table-view summary::after {
  content: ""; position: absolute; top: 50%; right: 3px; width: 6px; height: 6px; margin-top: -5px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg); transition: transform 0.15s ease, margin-top 0.15s ease;
}
details.table-view[open] summary::after { margin-top: -1px; transform: rotate(-135deg); }
@media (hover: hover) {
  details.table-view summary:hover { color: var(--ink); }
}
.table-scroll { overflow-x: auto; margin-top: 10px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; }

/* Как работает сервис — три колонки текста под линией, без отдельных карточек */
.service { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 32px; }
.service-item { padding: 18px 0 0; border-top: 1px solid var(--axis); }
.service-item h3 { margin: 14px 0 6px; font-size: 16px; font-weight: 600; }
.service-item p { margin: 0; color: var(--ink-2); font-size: 14px; max-width: 42ch; text-wrap: pretty; }
.service-icon {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); color: var(--series);
}

/* Вопросы — одним списком в общей рамке */
.faq { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.faq-item + .faq-item { border-top: 1px solid var(--border); }
.faq-item summary {
  position: relative; padding: 16px 48px 16px 20px;
  cursor: pointer; font-weight: 600; font-size: 15px; list-style: none;
}
.faq-item summary:focus-visible { outline-offset: -2px; border-radius: var(--radius); }
.faq-item summary::-webkit-details-marker { display: none; }
@media (hover: hover) {
  .faq-item summary:hover { background: var(--surface-2); }
}
/* Стрелка справа: перенос длинного вопроса не уходит под значок */
.faq-item summary::after {
  content: ""; position: absolute; top: 50%; right: 22px; width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform 0.15s ease, margin-top 0.15s ease;
}
.faq-item[open] summary::after { margin-top: -2px; transform: rotate(-135deg); }
.faq-item p { margin: 0; padding: 0 20px 18px; color: var(--ink-2); font-size: 14px; max-width: 78ch; }

footer {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap;
  padding: 22px 0 calc(32px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border);
  color: var(--muted); font-size: 13px;
}
footer p { margin: 0 0 4px; }
.site-counter { display: flex; align-items: center; gap: 16px; white-space: nowrap; font-size: 13px; font-variant-numeric: tabular-nums; }
.site-counter strong { color: var(--ink-2); font-weight: 600; }
.legal-info { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 12px; }
.legal-info strong { color: var(--ink-2); font-weight: 600; }

/* Окна */
.modal {
  width: min(560px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 0;
  border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 60px rgba(8, 15, 22, 0.32);
}
.modal[open] { animation: modal-in 0.2s cubic-bezier(0.2, 0.8, 0.2, 1); }
.modal::backdrop { background: rgba(8, 15, 22, 0.58); }
.modal[open]::backdrop { animation: fade-in 0.2s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.985); } }
@keyframes fade-in { from { opacity: 0; } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 16px 12px 20px; }
.modal-title { margin: 0; font-size: 17px; font-weight: 600; }
.how-dialog { width: min(540px, calc(100% - 32px)); }
/* Шапка окна на месте, прокручиваются только шаги — без расчётов от 100vh,
   который на телефоне больше видимой области из-за адресной строки */
.how-dialog[open] { display: flex; flex-direction: column; overflow: hidden; }
.how-dialog .modal-head { flex: none; border-bottom: 1px solid var(--border); }
.how-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.modal-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.lightbox { width: min(1100px, calc(100% - 32px)); }
.lightbox-body { position: relative; background: var(--frame-bg); min-height: 120px; display: grid; place-items: center; }
.lightbox-body img { display: block; width: 100%; height: auto; max-height: 70vh; max-height: min(70vh, 100dvh - 150px); object-fit: contain; }
/* Свайп листает кадры (app.js), вертикальная прокрутка и щипок работают как обычно */
#lightbox .lightbox-body { touch-action: pan-y pinch-zoom; user-select: none; -webkit-user-select: none; }
.lightbox-nav, .timelapse-controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; font-size: 14px; }
.lightbox-nav span { color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: center; }
.timelapse-controls input { flex: 1; accent-color: var(--series); }
.timelapse-overlay {
  position: absolute; left: 12px; bottom: 12px; padding: 4px 10px; border-radius: 8px;
  background: rgba(8, 15, 22, 0.66); color: #fff; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.timelapse-overlay:empty { display: none; }
.timelapse-status { margin: 0; padding: 40px 16px; color: #d3dade; font-size: 14px; }

.steps { margin: 0; padding: 16px 20px 20px; display: grid; gap: 22px; list-style: none; }
.how-step { display: grid; gap: 10px; min-width: 0; }
.how-step-copy { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; }
.how-step-number {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-2); color: var(--ink-2); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.steps h3 { margin: 1px 0 4px; font-size: 14px; font-weight: 600; }
.steps p { margin: 0; color: var(--ink-2); font-size: 14px; }
.how-visual { height: auto; aspect-ratio: 16 / 9; margin-left: 30px; overflow: hidden; border-radius: 8px; background: var(--frame-bg); }
.how-visual img { display: block; width: 100%; height: 100%; object-fit: contain; }
.how-visual.zone { aspect-ratio: auto; min-height: 60px; }
.how-visual.zone img { height: auto; }
.how-visual.chart { position: relative; height: auto; background: var(--surface); touch-action: auto; }
.how-visual.chart > svg { display: block; width: 100%; height: 100%; overflow: hidden; }
.how-visual.chart .how-line { fill: none; stroke: var(--ink-2); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.how-visual.chart .dot { fill: var(--ink-2); }
.how-visual.chart .tooltip { width: min(256px, calc(100% - 12px)); }
.how-visual-empty { display: grid; width: 100%; height: 100%; place-items: center; color: var(--muted); font-size: 13px; }
.how-actions { display: flex; justify-content: flex-end; padding: 0 20px 20px; }

.contact-form { display: grid; gap: 10px; padding: 0 20px 20px; }
.contact-form p { margin: 0; color: var(--ink-2); font-size: 14px; }
.contact-form textarea, .contact-form input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--page); font-size: 14px; resize: vertical;
}
.contact-form textarea:focus-visible, .contact-form input:focus-visible { outline-offset: 0; border-color: var(--series); }
.contact-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.contact-actions span { color: var(--ink-2); font-size: 13px; }
.primary-button {
  height: 38px; padding: 0 18px; border: 0; border-radius: 10px; background: var(--ink); color: var(--page);
  font-weight: 600; font-size: 14px; cursor: pointer;
}
@media (hover: hover) {
  .primary-button:hover:not(:disabled) { background: var(--ink-2); }
}
.primary-button:disabled { opacity: 0.5; cursor: default; }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 860px) {
  .now-grid, .split { grid-template-columns: 1fr; }
  .chart { height: 260px; }
  .topbar { flex-wrap: wrap; }

  /* Кадр во всю ширину: высота по пропорциям снимка, без чёрных полос сверху и снизу.
     Пока снимка нет, место держит заглушка; размеры в <img> не дают странице прыгать. */
  .frame { min-height: 0; }
  .frame img { height: auto; }
  .frame-empty { display: grid; place-items: center; min-height: 180px; }

  /* «Как работает сервис» в одну колонку: значок слева от заголовка, пункты разделены линией */
  .service { grid-template-columns: 1fr; gap: 0; }
  .service-item { display: grid; grid-template-columns: 36px minmax(0, 1fr); column-gap: 14px; padding: 16px 0; }
  .service-item:last-child { padding-bottom: 0; }
  .service-icon { grid-row: span 2; }
  .service-item h3 { margin: 6px 0 4px; }
}

@media (max-width: 560px) {
  :root { --gutter: 12px; }
  .topbar { padding: 14px 0; }
  .brand-name { font-size: 16px; }
  .brand-sub { display: none; }
  /* Вторая строка шапки: «как это работает» берёт свободное место, тема, язык и часы — справа */
  .topbar-side { width: 100%; gap: 8px; }
  .how-button { flex: 1 1 auto; min-width: 0; height: 44px; font-size: 14px; }
  .icon-button { width: 44px; height: 44px; }
  .lang-select { height: 44px; }
  .share-button { height: 40px; }

  /* iOS увеличивает страницу при фокусе на поле со шрифтом мельче 16px */
  .lang-select, .day-label input, .contact-form textarea, .contact-form input { font-size: 16px; }

  /* Часы работы перехода: статус сверху, под ним текст и ссылка */
  #notice { flex-direction: column; align-items: flex-start; gap: 6px; padding: 12px 14px 4px; }

  /* Текстовые ссылки и кнопки-ссылки: зона нажатия выше, вид тот же */
  #notice a, .frame-foot a, .link-button, footer a { display: inline-block; padding-block: 8px; }
  #arrivals-past { margin-top: 0; }
  details.table-view summary { padding-block: 8px; }
  /* «Написать нам» и счётчик — одной строкой: у ссылки зона нажатия выше, поэтому по центру, а не по верху */
  footer { align-items: center; }

  .intro { padding-top: 20px; }
  main { padding-top: 16px; }
  .now-card { padding: 18px 16px 16px; }
  .section { margin-top: 34px; }
  .section-title { font-size: 20px; }
  .chart-card { padding: 12px 10px 10px; }
  .chart { height: 240px; }
  .legend { gap: 4px 14px; font-size: 12px; }
  .day-nav { width: 100%; }
  .day-label { flex: 1; min-width: 0; }

  /* Переключатели графика — лентой с подписями: листается вбок и доходит до края экрана,
     обрезанная подпись у края подсказывает, что там есть ещё */
  .toolbar-row {
    flex-wrap: nowrap; justify-content: flex-start; gap: 6px;
    margin: -4px calc(-1 * var(--gutter)) 4px; padding: 4px var(--gutter); /* поля — под рамку фокуса */
    overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
  }
  .toolbar-row::-webkit-scrollbar { display: none; }
  .toggles { flex: none; flex-wrap: nowrap; }
  .toggle { flex: none; height: 40px; white-space: nowrap; }

  .frame-head { padding-left: 14px; }
  .segmented { flex: 1 0 auto; }
  .segmented button { flex: 1; min-height: 36px; padding-inline: 8px; }
  .frame-foot { flex-direction: column; gap: 0; padding: 8px 14px; }

  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  .stat-samples { grid-column: 1 / -1; text-align: left; }
  .stat-value { font-size: 22px; }
  .arrival { grid-template-columns: 28px 44px minmax(0, 1fr) auto; gap: 8px; }
  .arrival-icon { width: 28px; height: 28px; }
  .panel { padding: 16px; }
  .faq-item summary { padding-left: 16px; }
  .faq-item p { padding-inline: 16px; }

  /* Окна — шторкой снизу во всю ширину: ближе к большому пальцу, кадр крупнее.
     Форма связи остаётся по центру, чтобы экранная клавиатура её не перекрывала. */
  .modal:not(#contact) {
    width: 100%; max-width: 100%; margin: auto 0 0;
    max-height: calc(100% - 24px); max-height: calc(100dvh - 24px);
    border-width: 1px 0 0; border-radius: 18px 18px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    animation: sheet-in 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  #contact { width: calc(100% - 24px); }
  .modal-head { align-items: center; padding: 12px 12px 10px 16px; }
  .steps { padding: 14px 16px 18px; }
  .how-visual { margin-left: 0; }
  .how-actions { padding: 0 16px 16px; }
  .how-actions .primary-button { width: 100%; height: 44px; }
  .contact-form { padding: 0 16px 16px; }
  .contact-actions .primary-button { height: 44px; }
  .lightbox-nav, .timelapse-controls { padding: 10px 12px; }
  .timelapse-controls input { height: 32px; }
}

/* Самые узкие телефоны (320–374px): чтобы подпись «как это работает» влезла целиком */
@media (max-width: 374px) {
  .topbar-side { gap: 6px; }
  .how-button { gap: 0; padding: 0 10px; font-size: 13px; }
  .how-button svg { display: none; }
  #theme-toggle { width: 40px; }
  .clock { margin-left: 0; }
}

@keyframes sheet-in { from { transform: translateY(100%); } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
