/*
 * Спокойное тёмное оформление рассчитано на использование ночью,
 * на улице, с рук. Брендовый цвет — только небольшой навигационный акцент.
 *
 * Правила, которым подчинено всё остальное:
 *   - фон почти чёрный, чистого белого текста нет нигде: белое пятно
 *     на весь экран сбивает адаптацию глаз к темноте на десятки минут;
 *   - читаемый шрифт и цели нажатия не меньше 44 px;
 *   - в ночном режиме остаётся только красный: к нему глаз в темноте
 *     наименее чувствителен, и адаптация почти не теряется;
 *   - на основном экране минимум текста, всё внимание на карту и указатель.
 */

:root {
  --bg: #07070a;
  --bg-raised: #101017;
  --text: #c8c5d0;
  --text-dim: #7d7a89;
  --text-bright: #e6e3ec;
  --accent: #2f7772;
  --accent-soft: #173b39;
  --accent-text: #6eaaa5;
  --button-text: #d8d5df;
  --ok: #4f9d69;
  --warn: #b2762c;
  --border: #23222c;
  --focus: #76aaa6;

  --radius: 14px;

  color-scheme: dark;
}

/*
 * Ночной режим. Всё в красном, яркость заметно ниже обычной темы.
 */
:root[data-theme='night'] {
  --bg: #060102;
  --bg-raised: #150406;
  --text: #b84038;
  --text-dim: #6e2420;
  --text-bright: #d75046;
  --accent: #8f1f1a;
  --accent-soft: #4a0d0d;
  --accent-text: #c93a30;
  --button-text: #d75046;
  --ok: #a03028;
  --warn: #a83a25;
  --border: #340c0c;
  --focus: #7a2a22;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  /* Стрелку тянут пальцем по всему экрану — случайное выделение мешает. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  padding:
    env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
  transition: background-color 0.4s ease;
  overflow-x: hidden;
  position: relative;
}

.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.skip-link {
  position: absolute;
  left: -9999px;
}
.skip-link:focus {
  left: 12px;
  top: 12px;
  z-index: 10;
  background: var(--bg-raised);
  color: var(--text-bright);
  padding: 8px 12px;
  border-radius: 8px;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  min-height: 48px;
  max-width: 620px;
  margin: 0 auto;
}

.brand-lockup {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--accent-text);
}

.brand-lockup__mark {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
}

.brand {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Экраны ---------- */

main {
  padding: 0 20px 32px;
  max-width: 560px;
  margin: 0 auto;
}

.screen[hidden] {
  display: none;
}

.screen {
  animation: fade-in 0.25s ease;
  position: relative;
}

.screen--center {
  min-height: calc(100svh - 140px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 18px;
}

.screen--start {
  justify-content: center;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.hero-title {
  font-size: clamp(38px, 12vw, 56px);
  font-weight: 500;
  line-height: 1.05;
  margin: 0;
  color: var(--text-bright);
  letter-spacing: -0.02em;
}

.hero-sub {
  margin: 0;
  color: var(--text-dim);
  max-width: 30ch;
  font-size: 17px;
}

.step-title {
  font-size: clamp(24px, 7vw, 32px);
  font-weight: 500;
  margin: 0;
  color: var(--text-bright);
  line-height: 1.15;
}

.hint {
  font-size: 14px;
  color: var(--text-dim);
  max-width: 34ch;
  margin: 0;
}

.hint--wide {
  max-width: none;
  margin-top: 12px;
}

/* ---------- Кнопки ---------- */

.primary-button {
  font: inherit;
  font-size: 17px;
  font-weight: 500;
  color: var(--button-text);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 14px 22px;
  min-height: 52px;
  width: 100%;
  max-width: 300px;
  cursor: pointer;
  transition:
    transform 0.16s ease,
    background-color 0.16s ease;
}

.primary-button:active {
  background: var(--accent);
  transform: translateY(2px);
}

.ghost-button {
  font: inherit;
  font-size: 15px;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  min-height: 44px;
  cursor: pointer;
}

.ghost-button:active {
  border-color: var(--accent-text);
  color: var(--accent-text);
}

.ghost-button[aria-pressed='true'] {
  color: var(--accent-text);
  border-color: var(--accent-soft);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.start-credit {
  margin: 10px 0 0;
  color: var(--text-dim);
  font-size: 12px;
}

.start-credit a {
  color: var(--accent-text);
  font-weight: 400;
  text-decoration-color: var(--accent-soft);
  text-underline-offset: 3px;
}

.stacked-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 340px;
}

/* ---------- Индикатор ожидания ---------- */

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent-text);
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Экран наведения ---------- */

.screen--aim {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  padding:
    calc(72px + env(safe-area-inset-top))
    calc(14px + env(safe-area-inset-right))
    calc(14px + env(safe-area-inset-bottom))
    calc(14px + env(safe-area-inset-left));
}

.aim-arrow {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 3;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  color: var(--accent-text);
  transition: transform 0.1s linear, opacity 0.18s ease;
  will-change: transform;
}

.aim-arrow[hidden] {
  display: none;
}

.aim-arrow svg {
  width: 100%;
  height: 100%;
  display: block;
}

.aim-arrow--found {
  color: var(--ok);
}

.aim-arrow--below {
  color: var(--warn);
}

.sky-status {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(calc(100vw - 28px), 430px);
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-raised);
  text-align: center;
}

.aim-primary {
  font-size: clamp(20px, 5.6vw, 24px);
  font-weight: 500;
  color: var(--text-bright);
  margin: 0;
  line-height: 1.15;
  min-height: 1.2em;
}

.aim-secondary {
  font-size: 14px;
  color: var(--text-dim);
  margin: 4px 0 0;
}

.banner {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warn);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text-dim);
  text-align: left;
  margin: 0 0 4px;
  pointer-events: auto;
  max-width: 430px;
}

.banner[hidden] {
  display: none;
}

.banner-action {
  display: block;
  margin-top: 8px;
  font: inherit;
  color: var(--accent-text);
  background: none;
  border: none;
  padding: 4px 0;
  text-decoration: underline;
  cursor: pointer;
}

.found-note {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0;
  font-size: 16px;
  text-align: left;
  color: var(--text);
}

/* ---------- Ручная инструкция ---------- */

.manual-direction {
  font-size: clamp(24px, 7.5vw, 32px);
  font-weight: 500;
  color: var(--text-bright);
  margin: 18px 0 4px;
  line-height: 1.15;
}

.manual-altitude {
  font-size: 19px;
  color: var(--text);
  margin: 0 0 8px;
}

.altitude-figure {
  margin: 8px 0 20px;
}

.altitude-figure svg {
  width: 100%;
  height: auto;
  max-width: 340px;
  display: block;
}

.alt-arc {
  stroke: var(--border);
  stroke-width: 2;
  stroke-dasharray: 3 5;
}

.alt-ground {
  stroke: var(--border);
  stroke-width: 2;
}

.alt-ray {
  stroke: var(--border);
  stroke-width: 1.5;
}

.alt-target {
  stroke: var(--accent-text);
  stroke-width: 3;
}

.alt-dot {
  fill: var(--accent-text);
}

.alt-label {
  fill: var(--text-dim);
  font-size: 9px;
  font-family: inherit;
}

.steps {
  padding-left: 22px;
  margin: 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 16px;
}

.steps li::marker {
  color: var(--accent-text);
  font-weight: 500;
}

.manual-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0;
}

/* ---------- Выбор города ---------- */

.search-input {
  font: inherit;
  font-size: 17px;
  width: 100%;
  padding: 14px 16px;
  margin: 14px 0;
  min-height: 52px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-bright);
  -webkit-user-select: text;
  user-select: text;
}

.search-input::placeholder {
  color: var(--text-dim);
}

.city-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.city-list li + li {
  border-top: 1px solid var(--border);
}

.city-button {
  font: inherit;
  font-size: 18px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  padding: 16px 4px;
  min-height: 56px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.city-button:active {
  color: var(--accent-text);
}

.city-button__tz {
  font-size: 13px;
  color: var(--text-dim);
}

/* ---------- Раскрывающееся пояснение ---------- */

.explainer {
  margin-top: 26px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  width: 100%;
  max-width: 40ch;
  text-align: left;
}

.explainer summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 15px;
  padding: 8px 0;
  min-height: 40px;
  display: flex;
  align-items: center;
}

.explainer p {
  font-size: 15px;
  color: var(--text-dim);
  margin: 4px 0 8px;
}

/* ---------- AR-карта небесного купола ---------- */

.ar {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: var(--bg);
}

.ar[hidden] {
  display: none;
}

.ar__video,
.ar__sky,
.ar__scrim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.ar__video {
  object-fit: cover;
  display: block;
  opacity: 0;
  filter: brightness(0.72) saturate(0.75);
  transition: opacity 0.25s ease;
}

body.camera-active .ar__video {
  opacity: 1;
}

:root[data-theme='night'] .ar__video {
  filter: brightness(0.5) grayscale(1) sepia(1) hue-rotate(-35deg) saturate(3.2);
}

.ar__sky {
  z-index: 1;
  display: block;
}

.ar__scrim {
  z-index: 2;
  background: linear-gradient(
    to bottom,
    rgba(4, 4, 8, 0.56) 0%,
    rgba(4, 4, 8, 0.04) 25%,
    rgba(4, 4, 8, 0.08) 70%,
    rgba(4, 4, 8, 0.64) 100%
  );
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

body.camera-active .ar__scrim {
  opacity: 1;
}

/* Камера продолжает работать, но нижний режим визуально оставляет только компас. */
body.down-compass-active .ar__scrim {
  opacity: 0;
}

body.down-compass-active .ar__reticle {
  display: none;
}

body.down-compass-active .sky-status {
  bottom: calc(76px + env(safe-area-inset-bottom));
}

.ar__reticle {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border: 1px solid var(--text-dim);
  border-radius: 50%;
  opacity: 0.34;
}

.ar__marker {
  position: absolute;
  z-index: 4;
  left: 0;
  top: 0;
  width: 128px;
  height: 128px;
  margin: -64px 0 0 -64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--accent-text);
  transition: transform 0.1s linear;
  will-change: transform;
}

.ar__marker[hidden] {
  display: none;
}

.ar__ring {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  opacity: 0.82;
}

.ar__label {
  position: absolute;
  top: calc(100% - 18px);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-bright);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
}

.ar__marker--found {
  color: var(--ok);
}

.ar__marker--found .ar__label {
  top: auto;
  bottom: calc(100% - 22px);
}

.ar__marker--found .ar__ring {
  stroke-width: 3;
}

.ar-toggle,
.sky-controls,
.target-card {
  pointer-events: auto;
}

.ar-notice {
  margin: 6px 0 0;
  max-width: 38ch;
  text-align: center;
}

.ar-notice[hidden] {
  display: none;
}

.sky-controls {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(calc(100vw - 28px), 430px);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sky-controls[hidden] {
  display: none;
}

.target-card {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(calc(100vw - 28px), 430px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--ok);
  border-radius: 10px;
  background: var(--bg-raised);
  color: var(--text);
  font-size: 14px;
  text-align: left;
}

.target-card[hidden] {
  display: none;
}

.target-card strong {
  color: var(--ok);
  font-size: 18px;
  font-weight: 500;
  line-height: 1.2;
}

body.sky-active {
  background: transparent;
  overflow: hidden;
}

body.sky-active main {
  position: relative;
  z-index: 1;
}

body.sky-active .topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  max-width: none;
  padding:
    calc(8px + env(safe-area-inset-top))
    calc(14px + env(safe-area-inset-right))
    12px
    calc(14px + env(safe-area-inset-left));
  background: linear-gradient(to bottom, rgba(7, 7, 10, 0.82), transparent);
}

/* ---------- debug ---------- */

.debug {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: rgba(4, 4, 8, 0.94);
  border-top: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--text-dim);
  max-height: 62svh;
  overflow-y: auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  -webkit-user-select: text;
  user-select: text;
}

.debug[hidden] {
  display: none;
}

.debug__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  color: var(--accent-text);
}

.debug__toggle {
  font: inherit;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 4px 8px;
}

.debug__values {
  margin: 0 0 8px;
  white-space: pre-wrap;
  line-height: 1.5;
}

.debug--collapsed .debug__values,
.debug--collapsed .debug__form {
  display: none;
}

.debug__form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.debug__form label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.debug__form input {
  font: inherit;
  background: #0d0d14;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px;
  min-height: 32px;
  -webkit-user-select: text;
  user-select: text;
}

.debug__buttons {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
}

.debug__buttons button {
  font: inherit;
  flex: 1;
  background: var(--accent-soft);
  color: var(--text-bright);
  border: none;
  border-radius: 6px;
  padding: 8px;
  min-height: 34px;
}

.debug__hint {
  grid-column: 1 / -1;
  margin: 4px 0 0;
  opacity: 0.7;
}

/*
 * Панель отладки занимает нижнюю часть экрана, поэтому содержимое
 * поджимается вверх — иначе проверять нечего, всё под панелью.
 */
body.has-debug main {
  padding-bottom: 64svh;
}

body.has-debug .screen--center,
body.has-debug .screen--aim {
  min-height: 36svh;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* На коротких экранах сжимаются только второстепенные отступы. */
@media (max-width: 699px) and (max-height: 700px) {
  .screen--start {
    gap: 14px;
  }

  .hero-title {
    font-size: 38px;
  }

  .screen--start .hero-sub {
    font-size: 15px;
  }

  .screen--start .hint {
    font-size: 12px;
  }

  .screen--start .explainer {
    margin-top: 8px;
  }

  .start-credit {
    font-size: 12px;
  }
}

/* На широком экране приложение остаётся узкой колонкой: оно про телефон. */
@media (min-width: 700px) {
  main {
    padding-top: 12px;
  }
}
