:root {
  --bg:           #0f0e0c;
  --surface:      #171512;
  --surface2:     #1e1c17;
  --border:       #28251f;
  --border2:      #332f27;
  --text:         #dedad2;
  --text-muted:   #a89e92;
  --text-dim:     #706860;
  --accent:       #4da8cf;
  --green:        #3db87a;
  --amber:        #c99b2c;
  --amber-bg:     #1a1508;
  --red:          #c4504a;
}

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

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Respect iPhone notch / home indicator */
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Header ──────────────────────────────────────────────────────────────── */

#header {
  height: 44px;
  padding: 0 16px;
  background: linear-gradient(180deg, #1e1c17 0%, var(--surface) 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

#header-logo {
  flex-shrink: 0;
  opacity: 0.9;
}

#header h1 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--text);
  text-transform: lowercase;
}

.vr {
  width: 1px;
  height: 16px;
  background: var(--border2);
  flex-shrink: 0;
}

#updated-label {
  margin-left: auto;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

/* ── Tonight bar — the go/no-go answer ───────────────────────────────────── */

#tonight-bar {
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

#tonight-score {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  flex-shrink: 0;
  line-height: 1.2;
}

#tonight-text {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}

#how-link {
  background: none;
  border: none;
  padding: 4px;
  margin-left: 6px;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.65;
  transition: opacity 0.15s ease;
  flex-shrink: 0;
}
#how-link:hover { opacity: 1; }

/* Score color states */
#tonight-score.go   { color: var(--green); }
#tonight-score.warn { color: var(--amber); }
#tonight-score.skip { color: var(--text-muted); }

/* ── Map ─────────────────────────────────────────────────────────────────── */

#map {
  flex: 1;
  min-height: 0;
  cursor: crosshair;
}

/* Remove sub-pixel seams between GeoRasterLayer canvas tiles */
.leaflet-layer canvas {
  display: block;
  border: none;
  outline: none;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* ── Legend ──────────────────────────────────────────────────────────────── */

.map-legend {
  background: rgba(15, 14, 12, 0.92) !important;
  border: 1px solid var(--border2) !important;
  border-radius: 6px !important;
  padding: 8px 10px !important;
  line-height: 1;
}

.legend-title {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 7px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
  font-size: 11px;
  color: var(--text-muted);
}

.legend-row:last-child { margin-bottom: 0; }

.swatch {
  width: 14px;
  height: 9px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ── Time bar / hour scrubber ────────────────────────────────────────────── */

#time-bar {
  padding: 10px 16px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#hour-label {
  display: block;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  margin-bottom: 10px;
}

#scrubber-wrap {
  position: relative;
  padding: 10px 0;
}

#hour-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: linear-gradient(
    to right,
    var(--accent) var(--slider-fill, 0%),
    rgba(255,255,255,0.18) var(--slider-fill, 0%)
  );
  border-radius: 3px;
  cursor: pointer;
  display: block;
  outline: none;
  border: none;
  position: relative;
  z-index: 1;
}

#hour-ticks {
  display: flex;
  justify-content: space-between;
  padding: 0 22px;
  margin-top: 4px;
}

#hour-ticks span {
  display: block;
  width: 1px;
  height: 4px;
  background: rgba(255,255,255,0.18);
  border-radius: 1px;
}

#hour-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 1px 5px rgba(0,0,0,0.5);
  cursor: grab;
  transition: transform 0.1s ease;
}

#hour-slider:active::-webkit-slider-thumb {
  cursor: grabbing;
  transform: scale(1.06);
}

#hour-slider::-moz-range-thumb {
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: #fff;
  border: none;
  box-shadow: 0 1px 5px rgba(0,0,0,0.5);
  cursor: grab;
}

#hour-slider::-moz-range-track {
  height: 6px;
  background: rgba(255,255,255,0.18);
  border-radius: 3px;
}

/* ── Info sheet ──────────────────────────────────────────────────────────── */

#info-sheet {
  position: fixed;
  left: 0;
  right: 0;
  /* bottom is set dynamically by positionSheet() in JS */
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 14px 14px 0 0;
  border-bottom: none;
  z-index: 1000;
  transform: translateY(calc(100% + 40px));
  visibility: hidden;
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 0.26s;
  padding: 0 18px 28px;
  max-height: 40vh;
  overflow-y: auto;
}

#info-sheet.open {
  transform: translateY(0);
  visibility: visible;
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s;
}

#sheet-peek {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 10px;
  gap: 10px;
  min-height: 44px;
}

#sheet-close {
  background: none;
  border: 1px solid var(--border2);
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

#sheet-location {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#sheet-score-label {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  flex-shrink: 0;
}

/* Expanded body */
#sheet-body {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

/* Score row — secondary display below Plan CTA */
#score-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 12px 0 4px;
  border-top: 1px solid var(--border);
}

#prob-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

#prob-label {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Plan this spot — primary CTA */
#plan-toggle {
  width: 100%;
  padding: 13px 16px;
  margin: 14px 0 0;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text);
  font: 500 15px/1 'DM Sans', system-ui, sans-serif;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

#plan-toggle::after {
  content: '›';
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
  transition: transform 0.18s ease;
}

#plan-toggle.expanded {
  border-color: var(--accent);
}

#plan-toggle.expanded::after {
  transform: translateY(-50%) rotate(90deg);
}

#plan-toggle:hover {
  border-color: var(--border2);
  background: #1a1916;
}

/* Plan section — slides open under the toggle */
#plan-section {
  display: none;
  flex-direction: column;
  padding: 12px 0 4px;
}

#plan-section.visible { display: flex; }

/* Departure row */
#plan-departure {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 0 10px;
  font-size: 13px;
}

#departure-from {
  color: var(--text-dim);
  flex-shrink: 0;
}

#departure-label {
  flex: 1;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#departure-edit {
  background: none;
  border: none;
  color: var(--accent);
  font: 400 13px 'DM Sans', system-ui, sans-serif;
  cursor: pointer;
  padding: 4px 0 4px 6px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

/* Navigate button — primary action, full-width */
#navigate-btn {
  width: 100%;
  padding: 14px 16px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #0a1a22;
  font: 600 15px/1 'DM Sans', system-ui, sans-serif;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  margin-bottom: 14px;
}

#navigate-btn:hover { opacity: 0.88; }
#navigate-btn:active { transform: scale(0.98); }

#navigate-btn:disabled {
  opacity: 0.32;
  cursor: default;
}

/* Lighting times */
#lighting-times {
  display: flex;
  flex-direction: column;
}

.lighting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.lighting-row:last-child { border-bottom: none; }

.lighting-label { color: var(--text-muted); }

.lighting-time {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* Why toggle */
#why-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-family: 'DM Sans', system-ui, sans-serif;
  cursor: pointer;
  padding: 10px 0 4px;
  text-align: left;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

#why-toggle::after { content: ' ›'; color: var(--accent); }
#why-toggle.expanded::after { content: ' ‹'; color: var(--accent); }

/* Contributing factors */
#why-factors {
  display: none;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

#why-factors.visible { display: flex; }

.why-bullet {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  padding-left: 14px;
  position: relative;
}

.why-bullet::before {
  content: '–';
  position: absolute;
  left: 0;
  color: var(--text-dim);
}

#approx-note {
  display: none;
  padding: 9px 12px;
  background: var(--surface2);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

#approx-note.visible { display: block; }

/* Desktop: side panel */
@media (min-width: 680px) {
  #info-sheet {
    left: 14px;
    right: auto;
    width: 268px;
    border-radius: 10px;
    border: 1px solid var(--border2);
    max-height: none;
    transform: translateX(-12px);
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.2s ease, opacity 0.2s ease, visibility 0s linear 0.2s;
  }

  #info-sheet.open {
    transform: translateX(0);
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transition: transform 0.2s ease, opacity 0.2s ease, visibility 0s;
  }

  #sheet-close { display: none; }
}

/* ── Loading ─────────────────────────────────────────────────────────────── */

#loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;
  background: var(--surface);
  border: 1px solid var(--border2);
  padding: 13px 22px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
  box-shadow: 0 16px 48px rgba(0,0,0,0.8);
}

#loading::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 9px;
  vertical-align: middle;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1;  }
  50%       { opacity: 0.15; }
}

/* ── Leaflet overrides ───────────────────────────────────────────────────── */

.leaflet-control-attribution {
  background: rgba(15, 14, 12, 0.85) !important;
  color: var(--text-dim) !important;
  font-size: 9px !important;
}
.leaflet-control-attribution a { color: var(--text-muted) !important; }

.leaflet-control-zoom a {
  background: var(--surface) !important;
  border-color: var(--border2) !important;
  color: var(--text-muted) !important;
  font-size: 15px !important;
}
.leaflet-control-zoom a:hover {
  background: var(--surface2) !important;
  color: var(--text) !important;
}

/* ── How it works modal ──────────────────────────────────────────────────── */

#how-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2001;
}
#how-modal.open { display: block; }

#how-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.28s ease;
}
#how-modal.open #how-backdrop { opacity: 1; }

#how-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  overflow: hidden;
}
#how-modal.open #how-sheet { transform: translateY(0); }

#how-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#how-title {
  flex: 1;
  font: 500 15px/1 'DM Sans', system-ui, sans-serif;
  color: var(--text);
  letter-spacing: 0.01em;
}
#how-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color 0.15s ease;
}
#how-close:hover { color: var(--text); }

#how-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 20px;
  -webkit-overflow-scrolling: touch;
}

.how-section {
  display: flex;
  gap: 14px;
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}
.how-section:last-child { border-bottom: none; }

.how-accent {
  flex-shrink: 0;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.6;
  align-self: stretch;
}

.how-section p {
  margin: 0;
  font: 400 14px/1.65 'DM Sans', system-ui, sans-serif;
  color: var(--text);
  opacity: 0.88;
}

#how-footer {
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom));
  text-align: center;
  font: 400 12px/1.4 'DM Sans', system-ui, sans-serif;
  color: var(--text-muted);
  opacity: 0.6;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Departure modal ─────────────────────────────────────────────────────── */

#departure-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2002;
}

#departure-modal.open { display: block; }

#departure-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.22s ease;
}

#departure-modal.open #departure-backdrop { opacity: 1; }

#departure-dialog {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-radius: 14px 14px 0 0;
  border: 1px solid var(--border2);
  border-bottom: none;
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
  padding: 0 20px calc(28px + env(safe-area-inset-bottom));
  max-height: 60vh;
  overflow-y: auto;
}

#departure-modal.open #departure-dialog { transform: translateY(0); }

#departure-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

#departure-title {
  font: 500 15px/1 'DM Sans', system-ui, sans-serif;
  color: var(--text);
}

#departure-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

#departure-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

#departure-input-wrap {
  position: relative;
  margin-bottom: 8px;
}

#departure-input {
  width: 100%;
  padding: 12px 40px 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text);
  font: 400 14px 'DM Sans', system-ui, sans-serif;
  outline: none;
  -webkit-appearance: none;
  transition: border-color 0.15s ease;
}

#departure-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  display: none;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.12s ease;
}

#departure-clear.visible { display: block; }
#departure-clear:hover { color: var(--text-muted); }

#departure-input:focus { border-color: var(--accent); }
#departure-input::placeholder { color: var(--text-dim); }

#departure-error {
  font-size: 12px;
  color: var(--red);
  min-height: 18px;
  margin-bottom: 6px;
  line-height: 1.4;
}


#departure-gps-btn {
  width: 100%;
  padding: 11px 14px;
  background: none;
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text-muted);
  font: 400 13px 'DM Sans', system-ui, sans-serif;
  cursor: pointer;
  margin-bottom: 10px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s ease, color 0.15s ease;
}

#departure-gps-btn:hover { border-color: var(--accent); color: var(--text); }

#departure-save-btn {
  width: 100%;
  padding: 13px 14px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #0a1a22;
  font: 600 14px/1 'DM Sans', system-ui, sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s ease;
}

#departure-save-btn:hover { opacity: 0.88; }
