:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --grouped-bg: rgba(118, 118, 128, 0.12);
  --text: #1c1c1e;
  --secondary-text: #8e8e93;
  --separator: rgba(60, 60, 67, 0.16);
  --accent: #007aff;
  --green: #34c759;
  --red: #ff3b30;
  --shadow: 0 -18px 50px rgba(0, 0, 0, 0.18);
  --sheet-height: min(58vh, 520px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: rgba(28, 28, 30, 0.84);
    --surface-solid: #1c1c1e;
    --grouped-bg: rgba(118, 118, 128, 0.24);
    --text: #ffffff;
    --secondary-text: #8e8e93;
    --separator: rgba(84, 84, 88, 0.65);
    --accent: #0a84ff;
    --green: #30d158;
    --red: #ff453a;
    --shadow: 0 -18px 50px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  overflow: hidden;
}

#map {
  position: fixed;
  inset: 0 0 var(--sheet-height) 0;
  background: var(--bg);
}

.map-shade {
  position: fixed;
  inset: 0 0 var(--sheet-height) 0;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(0, 0, 0, 0.18), transparent 22%),
    linear-gradient(to top, rgba(0, 0, 0, 0.12), transparent 28%);
  z-index: 500;
}

.status {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--separator);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14);
  backdrop-filter: saturate(180%) blur(28px);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  font-size: 13px;
  font-weight: 600;
  color: var(--secondary-text);
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 50%;
  background: var(--secondary-text);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--secondary-text) 16%, transparent);
}

.status.ok { color: var(--text); }
.status.ok .status-dot { background: var(--green); box-shadow: 0 0 0 4px color-mix(in srgb, var(--green) 18%, transparent); }
.status.err { color: var(--red); }
.status.err .status-dot { background: var(--red); box-shadow: 0 0 0 4px color-mix(in srgb, var(--red) 18%, transparent); }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--sheet-height);
  z-index: 1100;
  padding: 8px 14px calc(16px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--separator);
  border-radius: 28px 28px 0 0;
  box-shadow: var(--shadow);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.handle {
  width: 40px;
  height: 5px;
  margin: 2px auto 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--secondary-text) 45%, transparent);
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.header-copy { min-width: 0; }

.eyebrow {
  margin: 0 0 3px;
  color: var(--secondary-text);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.08;
  letter-spacing: -0.03em;
  font-weight: 700;
}

button {
  appearance: none;
  border: 0;
  font: inherit;
  cursor: pointer;
  min-height: 44px;
  transition: transform 160ms ease, opacity 160ms ease, background-color 160ms ease;
}

button:active { transform: scale(0.975); }
button:disabled { opacity: 0.45; cursor: default; }

.secondary-button {
  flex: 0 0 auto;
  padding: 0 15px;
  border-radius: 999px;
  background: var(--grouped-bg);
  color: var(--red);
  font-size: 14px;
  font-weight: 600;
}

.card {
  padding: 12px;
  margin-bottom: 12px;
  border-radius: 18px;
  background: var(--grouped-bg);
  border: 1px solid color-mix(in srgb, var(--separator) 65%, transparent);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 11px 12px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-solid);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  outline: none;
  box-shadow: inset 0 0 0 1px var(--separator);
}

input::placeholder { color: var(--secondary-text); }
input:focus { box-shadow: inset 0 0 0 2px var(--accent); }

.compact-button {
  padding: 0 14px;
  border-radius: 12px;
  background: var(--accent);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
}

.coords {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.coords label {
  color: var(--secondary-text);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.coords input {
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--secondary-text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.section-header-spaced { margin-top: 12px; }

.text-button {
  min-height: 36px;
  padding: 0 2px;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.presets {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 9px 0 2px;
  scrollbar-width: none;
}

.presets::-webkit-scrollbar { display: none; }

.presets button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 13px;
  border-radius: 999px;
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--separator);
  font-size: 13px;
  font-weight: 500;
}

.favorites {
  display: grid;
  gap: 8px;
  padding-top: 9px;
}

.favorite-item {
  display: flex;
  align-items: stretch;
  min-height: 52px;
  overflow: hidden;
  border-radius: 13px;
  background: var(--surface-solid);
  box-shadow: inset 0 0 0 1px var(--separator);
}

.favorite-main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 15px;
  font-weight: 600;
}

.favorite-main small {
  display: block;
  margin-top: 2px;
  color: var(--secondary-text);
  font-size: 11px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.delete-favorite {
  width: 48px;
  min-height: 52px;
  border-radius: 0;
  background: transparent;
  color: var(--red);
  border-left: 1px solid var(--separator);
  font-size: 22px;
  font-weight: 400;
}

.empty-favorites {
  padding: 12px;
  border-radius: 13px;
  background: color-mix(in srgb, var(--surface-solid) 55%, transparent);
  color: var(--secondary-text);
  font-size: 13px;
  line-height: 1.4;
}

.primary {
  position: sticky;
  bottom: 0;
  z-index: 3;
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  background: var(--accent);
  color: #ffffff;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  box-shadow: 0 8px 18px color-mix(in srgb, var(--accent) 28%, transparent);
}

.hint {
  margin: 10px 2px 0;
  color: var(--secondary-text);
  font-size: 12px;
  line-height: 1.45;
}

@media (min-width: 700px) {
  .sheet {
    left: 50%;
    right: auto;
    width: min(520px, calc(100% - 40px));
    transform: translateX(-50%);
    bottom: 20px;
    border-radius: 28px;
    border: 1px solid var(--separator);
  }

  #map, .map-shade { bottom: 0; }
}

@media (max-height: 700px) {
  :root { --sheet-height: 62vh; }
  h1 { font-size: 24px; }
}

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