:root {
  color-scheme: light dark;
  --app-bg: var(--tg-theme-bg-color, #ffffff);
  --section-bg: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --bottom-bg: var(--tg-theme-bottom-bar-bg-color, var(--section-bg));
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #74777b);
  --subtitle: var(--tg-theme-subtitle-text-color, var(--hint));
  --accent: var(--tg-theme-button-color, #3390ec);
  --accent-text: var(--tg-theme-accent-text-color, var(--accent));
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --separator: var(--tg-theme-section-separator-color, rgba(60, 60, 67, .18));
  --danger: var(--tg-theme-destructive-text-color, #ff3b30);
  --card-shadow: 0 8px 28px rgba(0, 0, 0, .13), 0 1px 3px rgba(0, 0, 0, .08);
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--tg-content-safe-area-inset-right, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--tg-content-safe-area-inset-left, 0px));
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --app-bg: var(--tg-theme-bg-color, #17212b);
    --section-bg: var(--tg-theme-section-bg-color, #182533);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #0e1621);
    --bottom-bg: var(--tg-theme-bottom-bar-bg-color, #182533);
    --text: var(--tg-theme-text-color, #f5f5f5);
    --hint: var(--tg-theme-hint-color, #8b9bab);
    --separator: var(--tg-theme-section-separator-color, rgba(255, 255, 255, .13));
    --card-shadow: 0 10px 32px rgba(0, 0, 0, .34), 0 1px 2px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; }
html, body, #app, #map { width: 100%; height: 100%; margin: 0; }
html { background: var(--secondary-bg); }
body {
  overflow: hidden;
  color: var(--text);
  background: var(--secondary-bg);
  font-size: 15px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button { font: inherit; -webkit-appearance: none; }
#app { position: relative; overflow: hidden; background: var(--secondary-bg); }
#map { z-index: 1; background: #d9dce0; }

.top-card,
.bottom-card,
.error-card,
.map-action {
  position: absolute;
  z-index: 500;
  border: .5px solid var(--separator);
  color: var(--text);
  background: color-mix(in srgb, var(--section-bg) 95%, transparent);
  box-shadow: var(--card-shadow);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  backdrop-filter: saturate(160%) blur(18px);
}

.top-card {
  top: calc(var(--safe-top) + 10px);
  right: calc(var(--safe-right) + 12px);
  left: calc(var(--safe-left) + 12px);
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  overflow: hidden;
  padding: 12px 14px 13px;
  border-radius: 18px;
}
.header-copy { min-width: 0; flex: 1; }
.eyebrow {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 2px;
  overflow: hidden;
  color: var(--tg-theme-section-header-text-color, var(--accent-text));
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .055em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}
.eyebrow > span {
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
h1 {
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -.015em;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.state {
  min-height: 30px;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border: .5px solid var(--separator);
  border-radius: 999px;
  color: var(--hint);
  background: color-mix(in srgb, var(--secondary-bg) 78%, transparent);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.state-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.state.saving .state-dot { animation: state-pulse 1.25s ease-in-out infinite; }
.state.ready {
  border-color: color-mix(in srgb, var(--accent) 26%, transparent);
  color: var(--accent-text);
  background: color-mix(in srgb, var(--accent) 11%, var(--section-bg));
}
.state.error { color: var(--danger); }
.progress-track {
  position: absolute;
  right: 14px;
  bottom: 0;
  left: 14px;
  height: 2px;
  overflow: hidden;
  border-radius: 999px;
  background: transparent;
}
.progress-track > span {
  width: 0;
  height: 100%;
  display: block;
  border-radius: inherit;
  background: var(--accent);
  transition: width .22s ease;
}

.bottom-card {
  right: calc(var(--safe-right) + 12px);
  bottom: calc(var(--safe-bottom) + 12px);
  left: calc(var(--safe-left) + 12px);
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 11px 11px 13px;
  border-radius: 18px;
}
.location-copy { min-width: 0; display: flex; flex: 1; align-items: center; gap: 11px; }
.location-copy > div { min-width: 0; display: flex; flex: 1; flex-direction: column; }
.location-copy strong,
.location-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.location-copy strong { color: var(--text); font-size: 15px; font-weight: 600; }
.location-copy span { color: var(--subtitle); font-size: 12px; }
.location-orb {
  width: 34px;
  height: 34px;
  display: grid;
  flex: 0 0 34px;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 13%, var(--section-bg));
}
.location-orb > span {
  width: 11px;
  height: 11px;
  border: 2px solid var(--section-bg);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
#locate {
  min-height: 44px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 13px;
  padding: 0 16px;
  color: var(--button-text);
  background: var(--accent);
  font-size: 14px;
  font-weight: 650;
  box-shadow: 0 2px 5px color-mix(in srgb, var(--accent) 28%, transparent);
}
#locate:active, .map-action:active { transform: scale(.96); opacity: .88; }
.telegram-hosted #locate { display: none; }

.map-action {
  top: calc(var(--safe-top) + 96px);
  right: calc(var(--safe-right) + 12px);
  width: 44px;
  height: 44px;
  display: grid;
  padding: 0;
  place-items: center;
  border-radius: 14px;
  transition: transform .12s ease, opacity .12s ease;
}
.map-action svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: var(--accent-text);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.error-card {
  top: 50%;
  right: calc(var(--safe-right) + 22px);
  left: calc(var(--safe-left) + 22px);
  transform: translateY(-50%);
  padding: 20px 18px;
  border-radius: 18px;
  color: var(--danger);
  font-weight: 550;
  text-align: center;
}
.user-puck {
  width: 21px;
  height: 21px;
  border: 3px solid #ffffff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35), 0 0 0 7px color-mix(in srgb, var(--accent) 20%, transparent);
}

.leaflet-control-attribution {
  margin-right: 8px !important;
  margin-bottom: calc(var(--safe-bottom) + 94px) !important;
  padding: 2px 5px !important;
  border-radius: 6px 0 0 0;
  color: var(--hint) !important;
  background: color-mix(in srgb, var(--section-bg) 86%, transparent) !important;
  font-size: 9px !important;
}
.leaflet-control-attribution a { color: var(--accent-text) !important; }
.leaflet-control-zoom {
  margin-top: calc(var(--safe-top) + 96px) !important;
  margin-left: calc(var(--safe-left) + 12px) !important;
  border: .5px solid var(--separator) !important;
  border-radius: 14px !important;
  box-shadow: var(--card-shadow) !important;
  overflow: hidden;
}
.leaflet-control-zoom a {
  width: 43px !important;
  height: 42px !important;
  border-color: var(--separator) !important;
  color: var(--accent-text) !important;
  background: color-mix(in srgb, var(--section-bg) 95%, transparent) !important;
  font-size: 22px !important;
  line-height: 42px !important;
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}
.leaflet-control-zoom a.leaflet-disabled { color: var(--hint) !important; }

@keyframes state-pulse {
  0%, 100% { opacity: .38; transform: scale(.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

@media (max-width: 350px) {
  .top-card, .bottom-card { right: 8px; left: 8px; }
  .state { padding: 0 8px; }
  h1 { font-size: 16px; }
  #locate { padding: 0 12px; }
}

@media (min-width: 700px) {
  .top-card { right: auto; width: min(420px, calc(100% - 24px)); }
  .bottom-card { right: auto; width: min(480px, calc(100% - 24px)); }
}

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