/* Небесный разведчик — карта неба на весь экран.
   Крупные кнопки: пользуются ночью, на холоде, иногда в перчатках. */

:root {
  color-scheme: dark;
  --bg: #02040a;
  --panel: rgba(12, 17, 30, 0.86);
  --panel-solid: #0d1220;
  --line: rgba(120, 140, 190, 0.22);
  --fg: #eef1f8;
  --dim: #a0a9bf;
  --faint: #677089;
  --accent: #a9bcff;
  --accent-fg: #02040a;
  --ok: #7fe0a8;
  --warn: #ffd36b;
  --danger: #ff8a80;
  --tap: 50px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Красный ночной режим: только красный свет. Зелёная и синяя составляющие не больше 0x20 —
   иначе глаза теряют привычку к темноте. Состояния различаются яркостью, а не оттенком. */
[data-theme="red"] {
  --bg: #000;
  --panel: rgba(14, 0, 0, 0.92);
  --panel-solid: #0e0000;
  --line: rgba(150, 16, 8, 0.45);
  --fg: #e81c0c;
  --dim: #a01208;
  --faint: #5a0a04;
  --accent: #ff2410;
  --accent-fg: #000;
  --ok: #ff2410;
  --warn: #ff3018;
  --danger: #ff3018;
}
[data-theme="red"] ::selection { background: #400000; color: var(--fg); }
input { caret-color: var(--accent); }
::placeholder { color: var(--faint); opacity: 1; }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Флажки и ползунок рисуем сами: системные — серые и белые, в ночном режиме слепят. */
input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  margin: 0;
  border: 2px solid var(--dim);
  border-radius: 7px;
  background: transparent;
  display: grid;
  place-items: center;
}
input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"]:checked::after {
  content: '';
  width: 6px;
  height: 11px;
  border: solid var(--accent-fg);
  border-width: 0 3px 3px 0;
  transform: translateY(-1px) rotate(45deg);
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--line); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -11px;
  border-radius: 50%;
  background: var(--accent);
  border: 0;
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line); }
input[type="range"]::-moz-range-thumb { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); border: 0; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- небо и камера ---- */
.sky {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
  z-index: 1;
}
.camera {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  display: none;
  background: #000;
}
.red-filter { display: none; }
body.ar .camera { display: block; }
/* В красном режиме видео камеры тоже красное: умножаем на чистый красный. */
[data-theme="red"] body.ar .red-filter {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #ff0000;
  mix-blend-mode: multiply;
  pointer-events: none;
}

/* ---- верхняя панель ---- */
.hud-top {
  position: fixed;
  z-index: 5;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 10px) 8px calc(env(safe-area-inset-left) + 10px);
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.hud-actions { margin-left: auto; display: flex; }

.chip, .round {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: var(--tap);
  border-radius: 25px;
  border: 1px solid var(--line);
  background: var(--panel);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--fg);
  font-weight: 600;
  font-size: 16px;
}
.chip { padding: 0 14px 0 11px; min-width: 0; }
#place-btn { flex: 0 1 auto; max-width: 48vw; }
#mode-btn { padding: 0 16px; }
.hud-actions { flex: none; gap: 6px; }
.chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip svg, .round svg { width: 22px; height: 22px; flex: none; }
.round { width: var(--tap); justify-content: center; padding: 0; flex: none; }
.chip:active, .round:active { filter: brightness(1.25); }

.hud-stack {
  position: fixed;
  z-index: 30; /* выше экрана приветствия и листов: сообщения должны быть видны всегда */
  top: calc(env(safe-area-inset-top) + 68px);
  left: calc(env(safe-area-inset-left) + 12px);
  right: calc(env(safe-area-inset-right) + 12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.hud-stack > * { pointer-events: auto; max-width: 100%; }
.banner {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid var(--warn);
  background: var(--panel-solid);
  color: var(--warn);
  font-weight: 600;
  text-align: center;
}

/* Компаса нет — предупреждение прямо на карте (нажатие открывает подстройку). */
.compass-chip {
  width: max-content;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 22px;
  border: 1px solid var(--warn);
  background: var(--panel-solid);
  color: var(--warn);
  font-size: 15px;
  font-weight: 600;
}

/* Подпись того, что под прицелом, — над прицелом, чтобы карточка снизу её не закрывала. */
.center-hint {
  position: fixed;
  z-index: 8;
  left: 50%;
  top: calc(50% - 76px);
  transform: translateX(-50%);
  margin: 0;
  padding: 5px 12px;
  border-radius: 14px;
  background: var(--panel);
  color: var(--fg);
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  pointer-events: none;
}

.hud-stack > .toast {
  pointer-events: none;
  width: 100%;
  margin: 0;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  color: var(--fg);
  font-size: 16px;
  text-align: center;
}

.calib {
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--accent);
}
.calib p { margin: 0 0 8px; }
body.calibrating .center-hint { display: none; }
@media (max-height: 500px) {
  .calib { display: flex; align-items: center; gap: 12px; padding: 8px 12px; }
  .calib p { margin: 0; font-size: 14px; }
  .calib .btn { width: auto; margin: 0; min-height: 44px; }
}

/* ---- нижняя панель: шкала времени ---- */
.hud-bottom {
  position: fixed;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px calc(env(safe-area-inset-right) + 8px) calc(env(safe-area-inset-bottom) + 10px) calc(env(safe-area-inset-left) + 8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.hud-bottom > * { pointer-events: auto; }
.timebar {
  width: 100%;
  max-width: 560px;
  display: grid;
  grid-template-columns: 1fr 1fr 2.2fr 1fr 1fr;
  gap: 6px;
  align-items: stretch;
}
.tb {
  min-height: 56px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-weight: 650;
  font-size: 15px;
  padding: 0 2px;
  white-space: nowrap;
}
.tb:active { filter: brightness(1.3); }
.tb { display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05; }
.tb b { font-size: 17px; font-weight: 700; }
.tb small { font-size: 12px; font-weight: 600; color: var(--dim); }
.time-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  touch-action: none;
  cursor: ew-resize;
  line-height: 1.15;
  padding-bottom: 6px;
  background-image: repeating-linear-gradient(90deg, transparent 0 9px, var(--line) 9px 10px);
  background-size: 100% 6px;
  background-repeat: no-repeat;
  background-position: bottom;
}
.time-main { font-size: 21px; font-weight: 750; font-variant-numeric: tabular-nums; }
.time-date { font-size: 12px; color: var(--dim); }
.time-offset { font-size: 13px; color: var(--dim); font-variant-numeric: tabular-nums; }
body.shifted .time-offset { color: var(--fg); font-weight: 700; }
.now-btn {
  min-height: 44px;
  padding: 0 22px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--dim);
  font-weight: 700;
  font-size: 15px;
  display: none;
}
.now-btn.active { display: block; background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.hud-bottom { flex-direction: column-reverse; }
body.shifted .card { bottom: calc(env(safe-area-inset-bottom) + 136px); }

/* ---- карточка объекта ---- */
.card {
  position: fixed;
  z-index: 7;
  left: calc(env(safe-area-inset-left) + 8px);
  right: calc(env(safe-area-inset-right) + 8px);
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  max-width: 560px;
  margin: 0 auto;
  max-height: 44vh;
  max-height: 44dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  -webkit-user-select: text;
  user-select: text;
}
.card-head { display: flex; align-items: flex-start; gap: 10px; justify-content: space-between; }
.card-buttons { display: flex; gap: 8px; flex: none; }
.chip.small { min-height: 50px; padding: 0 14px; font-size: 15px; }
.card { min-height: 96px; }
.card h2 { margin: 2px 0 0; font-size: 23px; line-height: 1.15; }
.card-sub { margin: 3px 0 0; color: var(--dim); font-size: 14px; }
.card h3 { margin: 14px 0 6px; font-size: 13px; letter-spacing: .05em; text-transform: uppercase; color: var(--dim); }
.rows { margin: 10px 0 0; }
.rows div { display: grid; grid-template-columns: 104px 1fr; gap: 8px; padding: 4px 0; border-top: 1px solid var(--line); }
.rows div:first-child { border-top: 0; }
.rows dt { color: var(--dim); font-size: 14px; line-height: 1.35; }
.rows dd { margin: 0; font-size: 15px; font-weight: 550; line-height: 1.35; }
.card-note { margin: 10px 0 0; color: var(--dim); font-size: 15px; }
.card-lead { margin: 10px 0 2px; font-size: 16px; font-weight: 600; line-height: 1.35; color: var(--ok); }
/* С датчиками карточка ниже прицела: объект в центре экрана остаётся виден.
   (В широкой раскладке карточка сбоку и прицел не закрывает.) */
@media (max-width: 699px) {
  body.live .card { max-height: max(96px, calc(50vh - 84px - env(safe-area-inset-bottom) - 60px)); }
  body.live .card { max-height: max(96px, calc(50dvh - 84px - env(safe-area-inset-bottom) - 60px)); }
  body.live.shifted .card { max-height: max(96px, calc(50dvh - 136px - env(safe-area-inset-bottom) - 60px)); }
}
.passes { list-style: none; margin: 0; padding: 0; }
.passes li { display: flex; flex-direction: column; padding: 7px 0 7px 12px; border-left: 3px solid var(--faint); margin: 4px 0; }
.passes li.vis { border-left-color: var(--ok); }
.passes li b { font-size: 16px; }
.passes li span { color: var(--dim); font-size: 14px; }
.card-actions { display: flex; gap: 8px; }
.card-actions .btn { margin-top: 12px; }

/* ---- общие элементы ---- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 54px;
  margin: 10px 0 0;
  padding: 10px 18px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  font-size: 17px;
  font-weight: 650;
}
[data-theme="red"] .btn { background: rgba(255, 60, 40, 0.06); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn:active { filter: brightness(1.15); }
.btn[disabled] { opacity: .55; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.muted { color: var(--dim); }
.small { font-size: 14px; }
.error { color: var(--danger); font-weight: 600; }

/* ---- первый запуск ---- */
.welcome {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow-y: auto;
  background: radial-gradient(ellipse at 50% 0%, rgba(40, 60, 120, 0.35), transparent 60%), var(--bg);
  padding: calc(env(safe-area-inset-top) + 28px) 20px calc(env(safe-area-inset-bottom) + 24px);
}
[data-theme="red"] .welcome { background: var(--bg); }
.welcome-box { max-width: 520px; margin: 0 auto; }
.welcome h1 { font-size: 32px; line-height: 1.1; margin: 10px 0 14px; }
.welcome .lead { font-size: 19px; margin: 0 0 16px; }
.perms { list-style: none; padding: 0; margin: 0 0 12px; }
.perms li { padding: 10px 0; border-top: 1px solid var(--line); color: var(--dim); }
.perms li b { color: var(--fg); }
/* Кнопки приветствия всегда видны, даже в альбомной ориентации на маленьком экране. */
.welcome-actions {
  position: sticky;
  bottom: calc(-24px - env(safe-area-inset-bottom));
  padding: 4px 0 calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
}
@media (max-height: 500px) {
  .welcome h1 { font-size: 24px; margin: 0 0 8px; }
  .welcome .lead { font-size: 16px; margin-bottom: 8px; }
  .perms li { padding: 6px 0; font-size: 14px; }
}

/* ---- листы ---- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 25; /* выше экрана приветствия: из него открывается выбор места */
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  padding: 14px 16px calc(env(safe-area-inset-bottom) + 20px);
  -webkit-user-select: text;
  user-select: text;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h2 { margin: 0; font-size: 22px; }
.sheet h3 { margin: 18px 0 6px; font-size: 13px; letter-spacing: .05em; text-transform: uppercase; color: var(--dim); }
.sheet p { margin: 6px 0; }
.field { display: block; margin: 14px 0 0; }
.field > span { display: block; color: var(--dim); font-size: 15px; margin-bottom: 6px; }
.field input[type="search"], .field input[type="text"] {
  width: 100%;
  min-height: 54px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 18px; /* ≥16px — иначе iOS приближает страницу при вводе */
}
.field input[type="range"] { width: 100%; height: 44px; accent-color: var(--accent); }
.pick { list-style: none; margin: 6px 0 0; padding: 0; }
.pick li + li { border-top: 1px solid var(--line); }
.pick button {
  width: 100%;
  min-height: 56px;
  padding: 8px 4px;
  background: none;
  border: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.pick button b { font-size: 18px; }
.pick button span { color: var(--dim); font-size: 14px; }
.pick button[disabled] { opacity: .45; }
.pick .muted { padding: 10px 4px; }
.modes button { min-height: 72px; }
.modes button.current { box-shadow: inset 4px 0 0 var(--accent); padding-left: 14px; }
.modes button.current b::after { content: ' — сейчас'; font-weight: 500; color: var(--dim); }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.toggles label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 6px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  font-size: 15px;
}
.toggles input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.segmented { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 6px; }
.segmented button {
  min-height: 50px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: none;
  font-weight: 600;
  font-size: 15px;
}
.segmented button.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; }

@media (min-width: 700px) {
  .card { left: auto; right: calc(env(safe-area-inset-right) + 16px); width: min(420px, calc(50vw - 60px)); }
}

/* Узкие экраны (iPhone SE, mini, «Увеличенный» режим): у места остаётся только значок. */
@media (max-width: 389px) {
  #place-name { display: none; }
  #place-btn { padding: 0; width: var(--tap); justify-content: center; }
  #mode-btn { padding: 0 12px; }
}
