/* Latitude Explorer */

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

:root {
  --bg: #0a0a0a;
  --bg-elevated: #141414;
  --bg-hover: #1a1a1a;
  --border: #262626;
  --text: #fafafa;
  --text-muted: #737373;
  --accent: #a78bfa;
  --accent-dim: rgba(167, 139, 250, 0.15);
  --orange: #fb923c;
  --blue: #60a5fa;
  --band-color: rgba(255, 255, 255, 0.15);
  --shadow-color: rgba(0, 0, 0, 0.5);
  --bg-overlay: rgba(10, 10, 10, 0.85);
  --bg-offscreen: rgba(255, 255, 255, 0.03);
  --cold: #67e8f9;
  --hot: #fca5a5;
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --bg-elevated: #ffffff;
  --bg-hover: #e5e5e5;
  --border: #d4d4d4;
  --text: #171717;
  --text-muted: #525252;
  --accent: #7c3aed;
  --accent-dim: rgba(124, 58, 237, 0.1);
  --orange: #f97316;
  --blue: #2563eb;
  --band-color: rgba(0, 0, 0, 0.1);
  --shadow-color: rgba(0, 0, 0, 0.15);
  --bg-overlay: rgba(255, 255, 255, 0.9);
  --bg-offscreen: rgba(0, 0, 0, 0.03);
  --cold: #06b6d4;
  --hot: #ef4444;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'IBM Plex Sans', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
}

.hidden {
  display: none !important;
}

/* App layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 16px;
  height: 48px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header h1 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-muted);
}

/* Search */
.search-wrapper {
  position: relative;
}

#city-search {
  width: 200px;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

#city-search::placeholder {
  color: var(--text-muted);
}

#city-search:focus {
  border-color: var(--accent);
}

/* Dropdown */
.dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  max-height: 280px;
  overflow-y: auto;
  z-index: 1000;
}

.dropdown-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  cursor: pointer;
  transition: background 0.1s;
}

.dropdown-item:hover,
.dropdown-item.active {
  background: var(--bg-hover);
}

.dropdown-item .city {
  font-weight: 500;
}

.dropdown-item .country {
  color: var(--text-muted);
  font-size: 12px;
}

/* Unit toggles */
.unit-toggles {
  display: flex;
  gap: 8px;
}

.unit-toggles select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 8px;
  cursor: pointer;
  outline: none;
}

.unit-toggles select:focus {
  border-color: var(--accent);
}

/* Theme toggle */
.theme-toggle {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 32px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
}

.theme-toggle .icon-sun {
  display: none;
}

.theme-toggle .icon-moon {
  display: block;
}

[data-theme="light"] .theme-toggle .icon-sun {
  display: block;
}

[data-theme="light"] .theme-toggle .icon-moon {
  display: none;
}

/* Location info */
.location-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.location-info .city-name {
  font-weight: 500;
}

.location-info .country-name {
  color: var(--text-muted);
}

.location-info .lat-value {
  font-family: 'IBM Plex Mono', monospace;
  color: var(--accent);
  font-size: 12px;
  padding: 2px 6px;
  background: var(--accent-dim);
}

/* Main */
.main {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Map */
.map-container {
  flex: 1;
  position: relative;
  min-width: 0;
}

#map {
  width: 100%;
  height: 100%;
  background: var(--bg);
}

/* Big percentage displays */
.pop-big {
  position: absolute;
  left: 3.5vw;
  font-family: 'IBM Plex Mono', monospace;
  font-size: clamp(16px, 4vw, 32px);
  font-weight: 600;
  z-index: 501;
  text-shadow: 0 2px 20px var(--shadow-color);
  pointer-events: none;
  opacity: 0.6;
}

.pop-big.north {
  color: var(--blue);
}

.pop-big.south {
  color: var(--orange);
}

.pop-big .pop-label {
  font-size: 0.5em;
  font-weight: 400;
}

/* Population stats overlay */
.pop-stats {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-overlay);
  backdrop-filter: blur(8px);
  padding: 6px 16px;
  font-size: clamp(11px, 1.8vw, 14px);
  z-index: 502;
  text-align: center;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.pop-stats .pop-text {
  color: var(--text-muted);
}

.pop-stats .pop-value {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: clamp(22px, 4.5vw, 32px);
}

.pop-stats .pop-value.north {
  color: var(--blue);
}

.pop-stats .pop-value.south {
  color: var(--orange);
}

.pop-stats .pop-value.band {
  color: var(--accent);
}

/* Leaflet tooltip */
.city-tooltip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 12px;
  padding: 8px 10px;
  box-shadow: 0 4px 12px var(--shadow-color);
  animation: tooltipFadeIn 100ms ease;
}

@keyframes tooltipFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.city-tooltip .cold {
  color: var(--cold);
}

.city-tooltip .hot {
  color: var(--hot);
}

.leaflet-tooltip-top:before {
  border-top-color: var(--bg-elevated);
}

/* Cities panel */
.cities-panel {
  width: 280px;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.panel-header {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.reference-city {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  margin-bottom: 2px;
}

.panel-title {
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.panel-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
}

/* Cities list */
.cities-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.city-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.city-item:hover {
  background: var(--bg-hover);
}

.city-item.offscreen {
  background: var(--bg-offscreen);
}

.city-item.offscreen:hover {
  background: var(--bg-hover);
}

.city-item .info {
  min-width: 0;
}

.city-item .name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.city-item .country {
  font-size: 11px;
  color: var(--text-muted);
}

.city-item .meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
  margin-left: 12px;
}

.city-item .pop {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--blue);
}

.city-item .dist {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
}

.city-item .temp {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
}

.city-item .temp .cold {
  color: var(--cold);
}

.city-item .temp .hot {
  color: var(--hot);
}

/* Leaflet overrides */
.leaflet-container {
  background: var(--bg);
  font-family: 'IBM Plex Sans', sans-serif;
}

.leaflet-control-zoom {
  border: none !important;
}

.leaflet-control-zoom a {
  background: var(--bg-elevated) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  width: 28px !important;
  height: 28px !important;
  line-height: 26px !important;
  font-size: 14px !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-hover) !important;
}

.leaflet-control-zoom-in {
  border-bottom: none !important;
}

.leaflet-control-attribution {
  background: var(--bg-overlay) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
  padding: 2px 6px !important;
}

.leaflet-control-attribution a {
  color: var(--text-muted) !important;
}

.leaflet-popup-content-wrapper {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px var(--shadow-color);
}

.leaflet-popup-tip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-top: none;
  border-left: none;
}

.leaflet-popup-content {
  margin: 10px 12px;
  font-size: 12px;
  line-height: 1.4;
}

.leaflet-popup-content strong {
  font-weight: 500;
}

/* Scrollbar */
.cities-list::-webkit-scrollbar,
.dropdown::-webkit-scrollbar {
  width: 6px;
}

.cities-list::-webkit-scrollbar-track,
.dropdown::-webkit-scrollbar-track {
  background: transparent;
}

.cities-list::-webkit-scrollbar-thumb,
.dropdown::-webkit-scrollbar-thumb {
  background: var(--border);
}

/* Footer */
.footer {
  padding: 6px 16px;
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  text-align: center;
}

.data-sources-link {
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px dotted var(--text-muted);
  transition: color 0.15s;
}

.data-sources-link:hover {
  color: var(--text);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 24px;
  max-width: 400px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-content h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.modal-content ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-content li {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-content li strong {
  color: var(--text);
  font-weight: 500;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.modal-close:hover {
  color: var(--text);
}

/* Intro modal */
.intro-content {
  text-align: left;
  max-width: 480px;
  padding: 20px;
}

.intro-content h2 {
  font-size: 20px;
  margin-bottom: 16px;
}

.intro-content p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 20px;
}

.intro-screenshot {
  width: 100%;
  max-width: 640px;
  height: auto;
  border-radius: 6px;
  margin-bottom: 16px;
  background: var(--bg);
  aspect-ratio: 640 / 240;
  object-fit: cover;
}

.intro-start {
  background: var(--orange);
  color: var(--bg);
  border: none;
  padding: 8px 18px;
  border-radius: 0;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.intro-start:hover {
  opacity: 0.9;
}

@media (max-width: 768px) {
  .intro-content {
    max-width: 100%;
    padding: 16px;
  }

  .intro-content h2 {
    font-size: 18px;
  }

  .intro-screenshot {
    max-width: 100%;
  }
}

/* Mobile bottom panel */
.mobile-cities-panel {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 8px 12px 16px;
  z-index: 1000;
  flex-direction: column;
  gap: 6px;
  touch-action: manipulation;
}

.mobile-panel-header {
  text-align: center;
}

.mobile-reference-city {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
}

.mobile-panel-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.mobile-panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mobile-nav-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.mobile-nav-btn:hover {
  background: var(--bg-hover);
}

.mobile-nav-btn:active {
  background: var(--border);
}

.mobile-nav-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.mobile-city-card {
  flex: 1;
  min-width: 0;
  text-align: center;
  padding: 0 4px;
}

.mobile-city-name {
  font-weight: 500;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-city-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  margin-top: 3px;
}

.mobile-city-dots {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 5px;
}

.mobile-city-dots .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border);
}

.mobile-city-dots .dot.active {
  background: var(--accent);
}

/* Mobile population stat in header */
.mobile-pop-stat {
  display: none;
  width: 100%;
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  text-align: center;
  padding-top: 4px;
}

.mobile-pop-stat .pop-value {
  color: var(--accent);
  font-weight: 500;
}

/* Mobile */
@media (max-width: 768px) {
  .main {
    flex-direction: column;
  }

  /* Hide desktop sidebar on mobile */
  .cities-panel {
    display: none !important;
  }

  /* Show mobile bottom panel */
  .mobile-cities-panel:not(.hidden) {
    display: flex;
  }

  /* Show mobile pop stat */
  .mobile-pop-stat:not(.hidden) {
    display: block;
  }

  .header {
    flex-direction: column;
    height: auto;
    padding: 10px 12px;
    gap: 6px;
    align-items: stretch;
  }

  .header-left {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    width: 100%;
  }

  /* Hide header title on mobile - shown in bottom panel instead */
  .header h1.desktop-title {
    display: none;
  }

  .header-left .search-wrapper {
    flex: 1;
  }

  .header-left .unit-toggles {
    flex-shrink: 0;
  }

  .location-info {
    display: none !important;
  }

  .unit-toggles {
    gap: 4px;
  }

  #city-search {
    font-size: 16px; /* Prevent iOS zoom */
    width: 100%;
  }

  /* Hide the "X M at this latitude" box on mobile - shown in header instead */
  .pop-stats {
    display: none !important;
  }

  /* Adjust pop-big labels for mobile */
  .pop-big {
    font-size: clamp(24px, 6vw, 36px);
    opacity: 0.9;
    left: 3.5vw;
    transform: none;
  }

  .pop-big.north {
    transform: translateY(-10vh);
  }

  .pop-big.south {
    transform: translateY(10vh);
  }

  /* Adjust map for bottom panel */
  .map-container {
    padding-bottom: 80px;
  }

  /* Footer above bottom panel */
  .footer {
    position: fixed;
    bottom: 72px;
    left: 0;
    right: 0;
    z-index: 999;
    background: var(--bg-overlay);
    border: none;
    padding: 4px 12px;
  }
}
