:root {
  color-scheme: dark;
  --bg: #080c14;
  --surface: #0f1622;
  --surface-2: #172032;
  --line: rgba(255, 255, 255, 0.09);
  --grid: #1f2a3c;
  --axis: #33405a;
  --ink: #f2f5fa;
  --ink-2: #b4bfd0;
  --muted: #7c8799;
  --accent: #4cc2ff;
  --warn: #fab219;
  --bad: #ec6a5a;
  --good: #2fc46a;
  --series-ws: #3987e5;
  --series-gust: #d95926;
  --series-hs: #199e70;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.4 var(--font);
  overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; touch-action: manipulation; }

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  height: 100vh;
  height: 100dvh;
}

/* ---------- верхняя панель ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--accent); margin-right: 6px; }
.brand h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: 0.01em; color: var(--ink); }
.brand-sub { color: var(--muted); white-space: nowrap; }

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  padding: 5px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 550;
}
.seg button:hover { color: var(--ink); background: rgba(255, 255, 255, 0.05); }
.seg button.on { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1); }
.seg.small button { padding: 3px 10px; font-size: 12px; }

.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); cursor: pointer; white-space: nowrap; user-select: none; }
.chk input { accent-color: var(--accent); margin: 0; width: 14px; height: 14px; }
.chk:hover { color: var(--ink); }

.status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  min-width: 0;
  font-size: 12px;
}
.status .st { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status i { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.status[data-state="loading"] i { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.status[data-state="warn"] i { background: var(--warn); }
.status[data-state="error"] i { background: var(--bad); }
@keyframes pulse { 50% { opacity: 0.25; } }

.icon-btn {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.icon-btn:hover { color: var(--ink); background: rgba(255, 255, 255, 0.06); }
.text-btn {
  flex: none;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.text-btn:hover { color: var(--ink); background: rgba(255, 255, 255, 0.06); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- карты ---------- */

.maps {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1px;
  background: var(--line);
  min-height: 0;
}
.mapwrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg); }
.map { position: absolute; inset: 0; background: #0b1422; }
.leaflet-container { font: inherit; background: #0b1422; cursor: crosshair; }
.leaflet-dragging .leaflet-container, .leaflet-container.leaflet-drag-target { cursor: grabbing; }

.maptitle {
  position: absolute;
  z-index: 800;
  top: 10px;
  left: 10px;
  padding: 5px 11px;
  border-radius: 8px;
  background: rgba(10, 15, 24, 0.82);
  border: 1px solid var(--line);
  font-weight: 600;
  pointer-events: none;
  backdrop-filter: blur(6px);
}
.maphint {
  position: absolute;
  z-index: 800;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(10, 15, 24, 0.82);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}

.legend {
  position: absolute;
  z-index: 800;
  right: 10px;
  bottom: 26px;
  padding: 8px 12px 7px;
  border-radius: 10px;
  background: rgba(10, 15, 24, 0.86);
  border: 1px solid var(--line);
  pointer-events: none;
  backdrop-filter: blur(6px);
  max-width: calc(100% - 20px);
}
/* на общей карте правый нижний угол — это побережье Калининграда, легенду уводим на Норвегию */
#wrapBaltic .legend { top: 48px; left: 10px; right: auto; bottom: auto; }
.lg-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 6px; white-space: nowrap; }
.lg-title { font-weight: 600; }
.lg-src { color: var(--muted); font-size: 11.5px; }
.lg-bar, .lg-ticks { width: 338px; max-width: 100%; }
.lg-bar { display: flex; height: 9px; border-radius: 3px; overflow: hidden; }
.lg-bar i { flex: 1 1 0; min-width: 0; }
.lg-ticks { position: relative; height: 15px; margin-top: 3px; }
.lg-ticks span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 10.5px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.lg-ticks span:first-child { transform: none; }
.lg-ticks span:last-child { transform: translateX(-100%); }

.readout {
  position: absolute;
  z-index: 900;
  top: 0;
  left: 0;
  min-width: 168px;
  padding: 7px 10px 8px;
  border-radius: 9px;
  background: rgba(10, 15, 24, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  white-space: nowrap;
}
.ro-coord { color: var(--muted); font-size: 11.5px; margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.ro-row { display: flex; align-items: center; gap: 7px; line-height: 19px; }
.ro-k { width: 54px; color: var(--ink-2); }
.ro-v { font-weight: 650; font-variant-numeric: tabular-nums; }
.ro-x { color: var(--ink-2); }
.dir-arrow { flex: none; color: var(--ink-2); vertical-align: -2px; }

/* подписи на карте */
.lbl { white-space: nowrap; pointer-events: none; }
.lbl span {
  position: absolute;
  color: #fff;
  text-shadow: 0 0 3px #05080f, 0 0 3px #05080f, 0 0 6px #05080f;
}
.lbl-city i {
  position: absolute;
  left: -2.5px;
  top: -2.5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1.5px rgba(5, 8, 15, 0.85);
}
.lbl-city span { top: -8px; left: 7px; font: 550 11.5px/16px var(--font); }
.lbl-city.lbl-l span { left: auto; right: 7px; }
.lbl-city.lbl-t span { left: 0; top: -22px; transform: translateX(-50%); }
.lbl-water span {
  transform: translate(-50%, -50%);
  font: italic 500 12px/1 var(--font);
  letter-spacing: 0.09em;
  color: rgba(255, 255, 255, 0.82);
}

.leaflet-bar { border: 1px solid var(--line) !important; border-radius: 8px !important; overflow: hidden; box-shadow: none !important; }
.leaflet-bar a, .leaflet-bar a:hover {
  background: rgba(10, 15, 24, 0.86);
  color: var(--ink-2);
  border-bottom-color: var(--line);
}
.leaflet-bar a:hover { color: var(--ink); background: rgba(23, 32, 50, 0.95); }
.leaflet-bar a.bm-view { display: grid; place-items: center; }
.leaflet-bar a.bm-view.on, .leaflet-bar a.bm-view.on:hover { color: var(--accent); background: rgba(23, 32, 50, 0.95); }
/* на большом экране «всё море» — отдельная карта слева, вторая кнопка там не нужна */
.leaflet-bar a.bm-wide { display: none; }
.leaflet-bar a.leaflet-disabled { background: rgba(10, 15, 24, 0.86); color: #46505f; }
.leaflet-control-attribution {
  background: rgba(8, 12, 20, 0.7) !important;
  color: var(--muted) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--ink-2) !important; }

/* ---------- шкала времени ---------- */

.timebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.play .ic-pause, .play.on .ic-play { display: none; }
.play.on .ic-pause { display: inline; }
.play { color: var(--ink); }

.timeline {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: 38px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  cursor: pointer;
  touch-action: none;
  user-select: none;
}
.tl-days { position: absolute; inset: 0; overflow: hidden; border-radius: 7px; }
.tl-day { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--axis); overflow: hidden; }
.tl-day:first-child { border-left: 0; }
.tl-day:nth-child(even) { background: rgba(255, 255, 255, 0.035); }
.tl-day span { position: absolute; left: 8px; top: 4px; color: var(--ink-2); font-size: 12px; white-space: nowrap; }
.tl-tick { position: absolute; bottom: 0; width: 1px; height: 6px; background: var(--axis); }
.tl-tick.noon { height: 10px; }
.tl-tick em { position: absolute; bottom: 9px; left: 0; transform: translateX(-50%); font-style: normal; font-size: 10px; color: var(--muted); }
.tl-now { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--muted); opacity: 0.8; pointer-events: none; }
.tl-now::after {
  content: "";
  position: absolute;
  top: -4px;
  left: -3px;
  border: 4px solid transparent;
  border-top-color: var(--muted);
}
.tl-thumb {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 4px;
  margin-left: -2px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(76, 194, 255, 0.22);
  pointer-events: none;
}

.timelabel { flex: none; display: flex; align-items: baseline; gap: 8px; min-width: 276px; justify-content: flex-end; white-space: nowrap; }
.timelabel b { font-size: 14px; font-weight: 600; }
.tl-clock { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tl-zone { color: var(--muted); font-size: 11px; }
.tl-rel { color: var(--muted); font-size: 12px; min-width: 76px; text-align: right; }

/* ---------- прогноз в точке ---------- */

.panel { background: var(--surface); border-top: 1px solid var(--line); padding: 8px 14px 10px; min-width: 0; }
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.panel-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; margin-right: auto; white-space: nowrap; overflow: hidden; }
.panel-title b { font-size: 14px; font-weight: 600; }
.panel-title span { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.panel-title .panel-note { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }

/* сводка на выбранный момент */
.panel-now { flex: none; display: flex; gap: 22px; white-space: nowrap; }
.stat { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.stat-k { color: var(--ink-2); font-size: 12px; }
.stat-line { display: inline-flex; align-items: baseline; gap: 4px; }
.stat-v { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-u { color: var(--ink-2); font-size: 12px; }
.stat-x { display: inline-flex; gap: 8px; color: var(--ink-2); font-size: 12px; }
.stat .dir-arrow { align-self: center; color: var(--ink); }
.stat:nth-child(2) .dir-arrow { display: none; } /* у порывов направления нет */

.charts { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.chart { margin: 0; min-width: 0; }
.chart figcaption { display: flex; align-items: center; gap: 14px; height: 20px; color: var(--ink-2); font-size: 12px; }
.chart figcaption b { color: var(--ink); font-weight: 600; font-size: 12.5px; }
.key { display: inline-flex; align-items: center; gap: 6px; }
.key i { width: 14px; height: 2px; border-radius: 1px; }
.plot { height: clamp(112px, 19vh, 172px); }
.plot svg { display: block; }

.c-grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.c-axis { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.c-band { fill: rgba(255, 255, 255, 0.022); }
.c-tick { fill: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.c-day { fill: var(--ink-2); font-size: 11px; }
.c-dir path { fill: none; stroke: var(--ink-2); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.c-now { stroke: var(--muted); stroke-width: 1; }
.c-cursor line { stroke: #fff; stroke-width: 1; opacity: 0.9; }
.c-cursor path { fill: #fff; }
.c-hover line { stroke: rgba(255, 255, 255, 0.45); stroke-width: 1; }
.c-dot { stroke: var(--surface); stroke-width: 2; }
.c-hit { cursor: crosshair; }

.chart-tip {
  position: absolute;
  z-index: 5;
  padding: 7px 10px 8px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  white-space: nowrap;
}
.tip-time { color: var(--ink-2); font-size: 11.5px; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 7px; line-height: 19px; }
.tip-key { flex: none; width: 12px; height: 2px; border-radius: 1px; }
.tip-row b { font-weight: 650; font-variant-numeric: tabular-nums; min-width: 58px; }
.tip-row span { color: var(--ink-2); }

.table-wrap { overflow-x: auto; padding-bottom: 4px; }
.ftable { border-collapse: separate; border-spacing: 2px; font-size: 12px; font-variant-numeric: tabular-nums; }
.ftable th, .ftable td { padding: 3px 0; min-width: 44px; height: 24px; text-align: center; white-space: nowrap; border-radius: 4px; }
.ftable td { cursor: pointer; color: var(--ink); }
.ftable th { font-weight: 500; color: var(--ink-2); }
.ftable .ft-label { position: sticky; left: 0; z-index: 1; min-width: 104px; padding-right: 10px; text-align: left; background: var(--surface); color: var(--ink-2); border-radius: 0; }
.ftable .ft-day { text-align: left; padding-left: 6px; color: var(--ink); font-weight: 600; background: rgba(255, 255, 255, 0.04); }
.ftable .ft-time { cursor: pointer; color: var(--muted); }
.ftable .ft-tint { font-weight: 600; }
.ftable .ft-dir { margin-left: 3px; color: var(--ink-2); font-size: 11px; }
.ftable .ft-cur { box-shadow: 0 0 0 2px var(--accent); }
.ftable th.ft-cur { color: var(--ink); }

.toast {
  position: fixed;
  z-index: 2000;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  color: var(--ink);
  pointer-events: none;
}

/* ---------- узкие экраны ---------- */

.legend-strip, .panel-toggle, #layerSeg small { display: none; }

@media (max-width: 1250px) {
  .maphint { display: none; }
}
@media (max-width: 1100px) {
  .brand-sub, .tl-rel, .tl-zone { display: none; }
  .timelabel { min-width: 0; }
}

/* На сенсорном экране курсора нет: значения в точке показывает шторка прогноза */
@media (hover: none) {
  .readout { display: none !important; }
}

/* ---------- телефон: одна карта на экране, прогноз — шторкой снизу ---------- */
/* Экран маленький, поэтому остаётся только главное: слой, карта, цифры в точке и время.
   Название, галочки, кнопка обновления и подписи легенды на телефоне убраны. */

@media (max-width: 860px) {
  body { font-size: 14px; overscroll-behavior: none; }
  .app { grid-template-rows: auto auto minmax(0, 1fr) auto; }

  .topbar { flex-wrap: wrap; gap: 4px 8px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); }
  .brand, .chk, #btnRefresh { display: none; }
  #layerSeg { display: flex; flex: 1 0 100%; padding: 2px; }
  #layerSeg button { flex: 1; padding: 7px 0; font-size: 14px; }
  #layerSeg small { display: inline; }
  /* строка состояния нужна, только когда что-то не так: загрузка, нет связи, лимит */
  .status { flex: 1 0 100%; margin: 0; font-size: 11.5px; }
  .status[data-state="ok"] { display: none; }
  .st-pre { display: none; }
  .st-text { display: inline-block; }
  .st-text::first-letter { text-transform: uppercase; }

  .mapwrap .legend { display: none; }
  .legend-strip {
    display: block;
    position: static;
    max-width: none;
    padding: 5px 10px 2px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: var(--surface);
    backdrop-filter: none;
  }
  .legend-strip .lg-head { display: none; }
  .legend-strip .lg-bar, .legend-strip .lg-ticks { width: 100%; }
  .legend-strip .lg-bar { height: 5px; }
  .legend-strip .lg-ticks { height: 13px; margin-top: 1px; }
  .legend-strip .lg-ticks span { font-size: 10px; }

  .maps { grid-template-columns: minmax(0, 1fr); position: relative; }
  /* одна карта; масштаб переключают две кнопки в углу: «домик» и «всё море» */
  #wrapBaltic { display: none; }
  .leaflet-bar a.bm-wide { display: grid; }
  .leaflet-touch .leaflet-bar a.bm-view, .leaflet-bar a.bm-view { width: 40px; height: 40px; line-height: 40px; }
  .maptitle, .maphint, .leaflet-control-zoom { display: none; }
  .leaflet-top .leaflet-control { margin: 8px 8px 0 0; }
  .leaflet-control-attribution { font-size: 9px !important; }

  .timebar { flex-wrap: wrap; gap: 5px 6px; padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .timebar .icon-btn { width: 34px; height: 32px; }
  .timebar .text-btn { height: 32px; padding: 0 10px; }
  #btnPlay { order: 1; }
  #btnPrev { order: 2; }
  .timelabel { order: 3; flex: 1 1 0; min-width: 0; justify-content: center; gap: 6px; }
  .timelabel b { font-size: 13px; }
  .tl-clock { font-size: 17px; }
  #btnNext { order: 4; }
  #btnNow { order: 5; }
  .timeline { order: 6; flex: 1 0 100%; height: 28px; }
  .tl-day span { top: 2px; left: 5px; font-size: 10.5px; }
  .tl-tick { height: 4px; }
  .tl-tick.noon { height: 7px; }
  .tl-thumb { width: 6px; margin-left: -3px; }

  .panel {
    position: fixed;
    z-index: 1500;
    left: 0;
    right: 0;
    bottom: var(--timebar-h, 80px);
    max-height: 68dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px 12px 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-bottom: 0;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
  }
  .panel .icon-btn { width: 32px; height: 32px; }
  .panel .text-btn { height: 32px; padding: 0 12px; }
  .panel-head { flex-wrap: wrap; gap: 6px 8px; margin-bottom: 0; }
  .panel-title { flex: 1 1 0; display: block; margin: 0; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; }
  .panel-title b { display: block; }
  .panel-title #panelCoord { font-size: 12px; }
  .panel-title #panelPlace:not(:empty) + #panelCoord, .panel-title .panel-note { display: none; }
  .panel-toggle { display: inline-block; order: 2; }
  #panelClose { order: 3; }
  .panel-now { order: 4; flex: 1 0 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
  .stat { flex-direction: column; align-items: flex-start; gap: 0; }
  .stat-v { font-size: 21px; }
  .stat-x { display: block; line-height: 1.3; min-height: 32px; }
  .stat-x span { display: block; }
  #panelMode { order: 5; margin-top: 2px; }
  .charts { grid-template-columns: minmax(0, 1fr); gap: 2px; margin-top: 8px; }
  .plot { height: 124px; }
  .c-hit { touch-action: pan-y; }
  .table-wrap { margin-top: 8px; }

  /* свёрнутая шторка — две короткие строки: где точка и три цифры */
  .panel.collapsed { padding: 6px 12px 8px; cursor: pointer; }
  .panel.collapsed .panel-head { gap: 3px 8px; }
  .panel.collapsed .panel-title { font-size: 12px; }
  .panel.collapsed .panel-title b, .panel.collapsed #panelClose { display: none; }
  .panel.collapsed .panel-toggle { height: 24px; padding: 0 9px; font-size: 12px; border-radius: 6px; }
  .panel.collapsed .panel-now { display: flex; justify-content: space-between; gap: 4px; }
  .panel.collapsed .stat { flex-direction: row; align-items: baseline; gap: 4px; }
  .panel.collapsed .stat-k { font-size: 11.5px; }
  .panel.collapsed .stat-v { font-size: 19px; }
  .panel.collapsed .stat-x, .panel.collapsed .stat:nth-child(2) .stat-u { display: none; }
  .panel.collapsed #panelMode, .panel.collapsed .charts, .panel.collapsed .table-wrap { display: none !important; }

  .toast { top: 45%; bottom: auto; max-width: calc(100% - 32px); text-align: center; white-space: normal; border-radius: 14px; }
}

/* совсем узкий телефон: единицы в свёрнутой шторке не помещаются */
@media (max-width: 374px) {
  .panel.collapsed .stat-u { display: none; }
}

/* телефон на боку: места по высоте мало — убираем и шкалу цветов */
@media (max-width: 860px) and (max-height: 480px) {
  .legend-strip { display: none; }
  .panel { max-height: 80dvh; }
}
