:root {
  --bg: #14181c;
  --panel: #1d2329;
  --panel-2: #242b32;
  --text: #e8ecef;
  --text-dim: #9aa5ad;
  --accent: #ffb648;
  --shade-route: #3f8ad1;
  --sun-route: #ef7f37;
  --direct-route: #6b7885;
  --border: #2c333a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
}

#sidebar {
  width: 320px;
  flex-shrink: 0;
  padding: 20px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  height: 100vh;
}

#mapWrap {
  flex: 1;
  position: relative;
  height: 100vh;
}

#map {
  width: 100%;
  height: 100%;
}

#mapOverlay {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}

#mapOverlay > * {
  pointer-events: auto;
}

#mapCompass:empty {
  display: none;
}

#mapCompass .compass {
  margin: 0;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.sidebar-toggle {
  display: none;
}

/* Phones/small tablets: side-by-side squeezes the map to near-zero width,
   which is what breaks pinch-zoom and pan (the page scrolls instead of the
   Leaflet container getting the touch events). Stack instead, and let the
   panel collapse down to a header bar so it doesn't permanently cover the
   map — it was fixed at 45vh with no way to get it out of the way. */
@media (max-width: 680px) {
  body {
    flex-direction: column;
  }

  #sidebar {
    position: relative;
    width: 100%;
    height: auto;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-top: 52px;
    transition: max-height 0.2s ease;
  }

  #sidebar.collapsed {
    max-height: 52px;
    overflow: hidden;
  }

  #mapWrap {
    flex: 1;
    height: auto;
    min-height: 40vh;
  }

  #mapOverlay {
    top: 10px;
    right: 10px;
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    position: absolute;
    top: 10px;
    left: 20px;
    right: 20px;
    width: auto;
    margin: 0;
    padding: 8px;
    font-size: 12.5px;
    font-weight: 600;
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
  }
}

h1 {
  font-size: 18px;
  margin: 0 0 4px;
  font-weight: 600;
}

h1 span {
  color: var(--accent);
}

.byline {
  font-size: 11.5px;
  color: var(--text-dim);
  margin: 0 0 16px;
}

.hint {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0 0 18px;
}

label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin: 14px 0 6px;
}

input[type="datetime-local"],
input[type="range"],
input[type="text"] {
  width: 100%;
}

input[type="datetime-local"],
input[type="text"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px;
  font-size: 13px;
}

input[type="text"]::placeholder {
  color: var(--text-dim);
}

.addr-field {
  position: relative;
}

.addr-field input[type="text"] {
  padding-right: 34px;
}

.locate-btn {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 5px;
  color: var(--text-dim);
  cursor: pointer;
}

.locate-btn:hover {
  color: var(--accent);
  background: var(--panel-2);
}

.locate-btn.loading {
  opacity: 0.5;
  pointer-events: none;
}

.locate-btn.loading svg {
  animation: locate-pulse 1s ease-in-out infinite;
}

@keyframes locate-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.suggestions {
  display: none;
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 180px;
  overflow-y: auto;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.suggestions.open {
  display: block;
}

.suggestion {
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.suggestion:last-child {
  border-bottom: none;
}

.suggestion:hover {
  background: var(--panel);
  color: var(--accent);
}

button {
  width: 100%;
  margin-top: 14px;
  padding: 10px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #1a1200;
  transition: opacity 0.15s;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
}

.panel {
  margin-top: 16px;
  font-size: 12.5px;
  line-height: 1.7;
}

.panel:empty {
  display: none;
}

.panel b {
  color: var(--text);
}

.panel .row {
  display: flex;
  justify-content: space-between;
  color: var(--text-dim);
}

.panel .row b {
  color: var(--text);
}

.capped-note {
  margin-top: 6px;
  color: var(--accent);
  font-size: 11.5px;
  line-height: 1.5;
}

#legend {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

#legend div {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

#legend div:last-child {
  margin-bottom: 0;
}

.swatch {
  width: 18px;
  height: 4px;
  border-radius: 2px;
  display: inline-block;
}

.swatch.shade { background: var(--shade-route); height: 3px; }
.swatch.sun { background: var(--sun-route); height: 3px; }
.swatch.direct { background: var(--direct-route); height: 3px; border-top: 2px dashed var(--direct-route); background: none; }

.export-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.export-actions:empty {
  display: none;
}

.export-actions button,
.export-actions a {
  margin-top: 0;
  flex: 1;
  font-size: 12px;
  padding: 8px 6px;
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.export-actions svg {
  flex-shrink: 0;
}

.error {
  margin-top: 14px;
  font-size: 12.5px;
  color: #ff6b6b;
}

.error:empty { display: none; }

.app-version {
  margin-top: 20px;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.6;
}

.leaflet-container {
  background: #dfe4e8;
}

.compass {
  margin-top: 10px;
  text-align: center;
}

.compass-ring {
  position: relative;
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-2);
}

.compass-n {
  position: absolute;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: 600;
  color: var(--text-dim);
}

.compass-needle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 27px;
  transform-origin: 50% 100%;
}

.compass-needle::after {
  content: "";
  position: absolute;
  top: -3px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}

.compass-needle.sun {
  background: var(--accent);
}
.compass-needle.sun::after {
  border-bottom: 6px solid var(--accent);
}

.compass-needle.shadow {
  background: #5b6b7a;
}
.compass-needle.shadow::after {
  border-bottom: 6px solid #5b6b7a;
}

.compass-legend {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
}

.compass-legend .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

.compass-legend .dot.sun { background: var(--accent); }
.compass-legend .dot.shadow { background: #5b6b7a; }

.shadow-arrow-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: rgba(20, 24, 28, 0.75);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}
