:root {
  color-scheme: dark;
  --ink: #080b10;
  --panel: rgba(12, 17, 24, .94);
  --panel-solid: #111720;
  --text: #f4f6f8;
  --muted: #99a5b4;
  --line: rgba(255, 255, 255, .13);
  --gold: #ffd257;
  --green: #54e18b;
  --amber: #ffb84d;
  --red: #ff655f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body, #map, #app { width: 100%; height: 100%; margin: 0; }
html, body { overflow: hidden; background: var(--ink); color: var(--text); }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
#map { position: fixed; inset: 0; z-index: 0; background: #a9c8d2; }
#app { position: fixed; inset: 0; z-index: 500; pointer-events: none; }

.topbar {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  left: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  justify-content: space-between;
}

.brand {
  min-width: 0;
  padding: 9px 12px 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .3);
  backdrop-filter: blur(16px) saturate(1.2);
}
.brand p { margin: 0; color: var(--gold); font-size: 9px; font-weight: 800; letter-spacing: .16em; }
.brand h1 { margin: 1px 0 0; font-size: 18px; line-height: 1.05; letter-spacing: -.035em; }
.countdown { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; white-space: nowrap; }

.layer-chips {
  display: flex;
  max-width: 58vw;
  gap: 6px;
  overflow-x: auto;
  padding: 0 1px 4px;
  scrollbar-width: none;
  pointer-events: auto;
}
.layer-chips::-webkit-scrollbar { display: none; }
.chip {
  min-height: 42px;
  flex: none;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  color: #d4dae2;
  box-shadow: 0 7px 22px rgba(0, 0, 0, .24);
  font-size: 12px;
  font-weight: 720;
  cursor: pointer;
  backdrop-filter: blur(14px);
}
.chip[aria-pressed="true"] {
  border-color: rgba(255, 210, 87, .7);
  background: #292410;
  color: var(--gold);
}
.chip.loading::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 6px;
  border: 1px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.map-actions {
  position: absolute;
  top: calc(var(--safe-top) + 72px);
  right: 10px;
  display: grid;
  gap: 8px;
  pointer-events: auto;
}
.round-button {
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .3);
  font-size: 20px;
  cursor: pointer;
  backdrop-filter: blur(14px);
}
.round-button.active { color: var(--gold); border-color: rgba(255, 210, 87, .65); }

.map-hint {
  position: absolute;
  left: 50%;
  top: calc(var(--safe-top) + 78px);
  transform: translateX(-50%);
  max-width: min(74vw, 360px);
  margin: 0;
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 18px;
  background: rgba(8, 12, 17, .8);
  color: #dbe1e8;
  font-size: 11px;
  text-align: center;
  box-shadow: 0 5px 18px rgba(0, 0, 0, .25);
  pointer-events: none;
  backdrop-filter: blur(12px);
  transition: opacity .25s;
}

.sheet {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(var(--safe-bottom) + 8px);
  max-height: min(62dvh, 590px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 -12px 42px rgba(0, 0, 0, .38);
  pointer-events: auto;
  backdrop-filter: blur(20px) saturate(1.15);
  transition: max-height .22s ease;
}
.sheet.collapsed { max-height: 74px; }
.sheet-handle {
  display: block;
  width: 100%;
  height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.sheet-handle::before {
  content: "";
  display: block;
  width: 38px;
  height: 4px;
  margin: 10px auto 0;
  border-radius: 3px;
  background: rgba(255, 255, 255, .3);
}
.sheet-scroll {
  max-height: calc(min(62dvh, 590px) - 28px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 15px calc(14px + var(--safe-bottom));
}
.sheet.collapsed .sheet-scroll { overflow: hidden; }

.sheet-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin: 0 0 12px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .055);
}
.sheet-tab {
  min-height: 39px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}
.sheet-tab.active { background: rgba(255, 255, 255, .1); color: var(--text); }

.empty-state { padding: 8px 2px 16px; text-align: center; }
.empty-state .moon { display: block; margin-bottom: 8px; font-size: 35px; }
.empty-state h2 { margin: 0; font-size: 20px; letter-spacing: -.03em; }
.empty-state p { max-width: 330px; margin: 7px auto 14px; color: var(--muted); font-size: 12px; line-height: 1.45; }

.primary, .secondary {
  min-height: 46px;
  border-radius: 12px;
  font-weight: 780;
  cursor: pointer;
}
.primary {
  border: 1px solid #ffe496;
  background: var(--gold);
  color: #161303;
}
.secondary {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .065);
  color: var(--text);
}
.wide { width: 100%; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

.selection-heading {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.selection-heading > div:first-child { min-width: 0; flex: 1; }
.kicker { margin: 0 0 3px; color: var(--gold); font-size: 9px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.selection-heading h2 { margin: 0; overflow: hidden; font-size: 21px; letter-spacing: -.035em; text-overflow: ellipsis; white-space: nowrap; }
.coordinates { margin: 4px 0 0; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.status-pill {
  flex: none;
  padding: 6px 9px;
  border: 1px solid;
  border-radius: 15px;
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
}
.status-pill.good { border-color: rgba(84, 225, 139, .55); background: rgba(84, 225, 139, .12); color: var(--green); }
.status-pill.caution { border-color: rgba(255, 184, 77, .55); background: rgba(255, 184, 77, .12); color: var(--amber); }
.status-pill.bad { border-color: rgba(255, 101, 95, .55); background: rgba(255, 101, 95, .12); color: var(--red); }

.bearing-card {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 14px;
  align-items: center;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid rgba(255, 210, 87, .28);
  border-radius: 16px;
  background:
    radial-gradient(circle at 50px 50%, rgba(255, 210, 87, .09), transparent 42%),
    rgba(0, 0, 0, .2);
}
.compass {
  position: relative;
  width: 96px;
  height: 96px;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.08) 0 3%, transparent 4% 100%);
  box-shadow: inset 0 0 0 9px rgba(255, 255, 255, .025);
}
.compass::before, .compass::after {
  position: absolute;
  color: #b9c1cc;
  font-size: 9px;
  font-weight: 800;
}
.compass::before { content: "N"; top: 5px; left: 50%; transform: translateX(-50%); }
.compass::after { content: "S"; bottom: 5px; left: 50%; transform: translateX(-50%); }
.east, .west { position: absolute; top: 50%; color: #7f8a98; font-size: 8px; font-weight: 800; transform: translateY(-50%); }
.east { right: 6px; }
.west { left: 6px; }
.needle {
  position: absolute;
  inset: 10px;
  transform: rotate(var(--bearing));
  transition: transform .3s ease;
}
.needle::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 0;
  height: 0;
  border-right: 8px solid transparent;
  border-bottom: 34px solid var(--gold);
  border-left: 8px solid transparent;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .7));
  transform: translateX(-50%);
}
.needle::after {
  content: "";
  position: absolute;
  top: 32px;
  left: 50%;
  width: 7px;
  height: 7px;
  border: 2px solid #fff4c7;
  border-radius: 50%;
  background: #18140a;
  transform: translateX(-50%);
}
.bearing-copy strong { display: block; color: var(--gold); font-size: 24px; letter-spacing: -.035em; }
.bearing-copy span { display: block; margin-top: 1px; color: #d8dee6; font-size: 12px; }
.bearing-copy small { display: block; margin-top: 6px; color: var(--muted); font-size: 10px; line-height: 1.35; }
.compass-button {
  min-height: 32px;
  margin-top: 7px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, .06);
  color: #dce1e8;
  font-size: 10px;
  font-weight: 750;
  cursor: pointer;
}

.facts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 10px 0 0;
}
.fact {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .035);
}
.fact dt { color: var(--muted); font-size: 9px; font-weight: 720; letter-spacing: .07em; text-transform: uppercase; }
.fact dd { margin: 3px 0 0; color: var(--text); font-size: 14px; font-weight: 760; }
.fact small { display: block; margin-top: 2px; color: #7f8a98; font-size: 9px; line-height: 1.3; }
.fact .good { color: var(--green); }
.fact .caution { color: var(--amber); }
.fact .bad { color: var(--red); }

.warning {
  margin: 10px 0 0;
  padding: 10px 11px;
  border: 1px solid rgba(255, 184, 77, .25);
  border-radius: 12px;
  background: rgba(255, 184, 77, .07);
  color: #e7d5b9;
  font-size: 10px;
  line-height: 1.4;
}
.weather-note {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

.spot-list { margin: 0; padding: 0; list-style: none; }
.spot-list li + li { margin-top: 7px; }
.spot-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  width: 100%;
  min-height: 60px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, .035);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.spot-item strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.spot-item .score { color: var(--green); font-size: 12px; font-weight: 850; }
.spot-item small { grid-column: 1 / -1; color: var(--muted); font-size: 10px; }
.list-intro { margin: 0 0 10px; color: var(--muted); font-size: 10px; line-height: 1.4; }

.toast {
  position: absolute;
  left: 50%;
  top: calc(var(--safe-top) + 126px);
  max-width: min(88vw, 420px);
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-solid);
  color: #e8ecf0;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
  font-size: 11px;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.leaflet-control-zoom { display: none; }
.leaflet-control-attribution {
  max-width: 65vw;
  background: rgba(255, 255, 255, .72) !important;
  font-size: 8px !important;
}
.leaflet-top { top: calc(var(--safe-top) + 106px); }
.leaflet-marker-icon.user-dot {
  border: 3px solid white;
  border-radius: 50%;
  background: #2374ff;
  box-shadow: 0 1px 0 5px rgba(35, 116, 255, .2), 0 2px 8px rgba(0, 0, 0, .55);
}
.leaflet-marker-icon.pick-dot {
  border: 3px solid #090c10;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 2px white, 0 3px 10px rgba(0, 0, 0, .55);
}
.leaflet-image-layer.cloud-overlay { filter: blur(.7px); }

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

@media (min-width: 760px) {
  .topbar { right: 410px; }
  .sheet {
    top: 10px;
    right: 10px;
    bottom: 10px;
    left: auto;
    width: 390px;
    max-height: none;
    border-radius: 18px;
  }
  .sheet.collapsed { max-height: none; }
  .sheet-handle { display: none; }
  .sheet-scroll { max-height: 100%; padding-top: 15px; }
  .map-actions { right: 410px; }
  .map-hint { left: calc((100% - 400px) / 2); }
}

@media (max-width: 430px) {
  .brand p { display: none; }
  .brand h1 { font-size: 16px; }
  .countdown { font-size: 9px; }
  .chip { padding: 0 10px; }
  .bearing-card { grid-template-columns: 88px 1fr; gap: 10px; }
  .compass { width: 84px; height: 84px; }
}

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