* { box-sizing: border-box; }

:root {
  --bg: #0b1020;
  --fg: #e0e6ed;
  --border: #1a2540;
  --accent: #5b9ef5;
  --muted: #8892a6;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
}

body.red-mode {
  --bg: #1a0202;
  --fg: #e0c0c0;
  --border: #4a0202;
  --accent: #ff6b6b;
}

header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  z-index: 1000;
}

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

.header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

#search-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--fg);
  font-size: 14px;
  min-width: 200px;
}

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

button {
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

button:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--accent);
}

button:active {
  background: rgba(255, 255, 255, 0.1);
}

main {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: calc(100% - 56px);
}

#map {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
}

#panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 360px;
  max-height: calc(100vh - 96px);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px);
  transition: all 0.2s ease;
}

#panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
}

.close-btn {
  padding: 4px 8px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
}

.close-btn:hover {
  color: var(--fg);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.info-row {
  margin-bottom: 12px;
  font-size: 14px;
}

.info-label {
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 4px;
}

.info-value {
  color: var(--fg);
  font-weight: 600;
}

.zone-badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  margin-right: 8px;
}

.mw-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.mw-section h3 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--accent);
}

.mw-line {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 8px;
}

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

.mw-value {
  color: var(--fg);
  font-weight: 500;
}

.button-group {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.button-group button {
  flex: 1;
}

.btn-primary {
  background: var(--accent);
  color: #000;
  font-weight: 600;
  border: none;
}

.btn-primary:hover {
  opacity: 0.9;
}

/* Legend */
#legend {
  list-style: none;
  margin: 0;
  padding: 12px 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  font-size: 12px;
}

#legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 2px;
  border: 1px solid var(--border);
}

/* Leaflet popup customization */
.mw-popup .leaflet-popup-content {
  background: var(--bg) !important;
  border: 1px solid var(--border) !important;
  border-radius: 6px !important;
  color: var(--fg) !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
}

.mw-popup .leaflet-popup-content-wrapper {
  background: transparent !important;
  border-radius: 6px !important;
  padding: 0 !important;
}

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

/* Milky Way Preview Styling */
.mw-preview {
  padding: 12px;
  background: rgba(13, 19, 48, 0.9);
  border-radius: 6px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 100%;
}

.mw-preview-head {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.mw-play-btn {
  padding: 6px 10px;
  font-size: 12px;
  min-width: 40px;
  background: rgba(91, 158, 245, 0.2);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 4px;
  cursor: pointer;
}

.mw-play-btn:hover {
  background: rgba(91, 158, 245, 0.3);
}

.mw-preview-time {
  font-weight: 600;
  color: var(--accent);
  min-width: 50px;
}

.mw-preview-stat {
  font-size: 12px;
  color: var(--muted);
  flex: 1;
  text-align: right;
}

.mw-preview-dir {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

.mw-preview-slider {
  width: 100%;
  height: 6px;
  cursor: pointer;
  accent-color: var(--accent);
}

.mw-preview-sky {
  background: #040714;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.mw-preview-ends {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

.mw-preview-large {
  max-width: none;
  width: 100%;
}

/* Mobile */
@media (max-width: 720px) {
  header {
    flex-direction: column;
    height: auto;
    padding: 12px 8px;
    gap: 8px;
  }

  header h1 {
    font-size: 14px;
  }

  .header-controls {
    width: 100%;
    gap: 4px;
    justify-content: space-between;
  }

  #search-input {
    flex: 1;
    min-width: auto;
    font-size: 13px;
    padding: 6px 8px;
  }

  button {
    padding: 6px 8px;
    font-size: 11px;
    min-width: 36px;
  }

  main {
    top: 70px;
    height: calc(100% - 70px);
  }

  #map {
    top: 0;
  }

  #panel {
    width: calc(100% - 16px);
    bottom: 12px;
    right: 8px;
    left: 8px;
    max-height: 50vh;
    border-radius: 6px;
  }

  .panel-header {
    padding: 8px 12px;
  }

  .panel-header h2 {
    font-size: 14px;
  }

  .panel-content {
    padding: 12px;
    font-size: 13px;
  }

  .info-row {
    margin-bottom: 8px;
    font-size: 12px;
  }

  .mw-section {
    margin-top: 12px;
    padding-top: 12px;
  }

  .mw-section h3 {
    font-size: 13px;
    margin-bottom: 8px;
  }

  .mw-line {
    font-size: 12px;
    margin-bottom: 6px;
  }

  .button-group {
    margin-top: 10px;
    gap: 6px;
  }

  .mw-preview {
    padding: 10px;
    gap: 8px;
  }

  .mw-preview-head {
    font-size: 12px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .mw-preview-time {
    min-width: auto;
  }

  .mw-preview-stat {
    font-size: 11px;
    flex-basis: 100%;
    text-align: left;
  }

  .mw-preview-dir {
    font-size: 11px;
    flex-basis: 100%;
  }

  .mw-preview-slider {
    height: 5px;
  }

  .mw-play-btn {
    padding: 5px 8px;
    font-size: 11px;
    min-width: 36px;
  }

  .mw-preview-ends {
    font-size: 10px;
  }
}

/* Ultra-mobile (phones < 360px) */
@media (max-width: 360px) {
  header h1 {
    font-size: 12px;
  }

  header {
    padding: 8px 6px;
  }

  #search-input {
    font-size: 12px;
    padding: 5px 6px;
  }

  button {
    padding: 5px 6px;
    font-size: 10px;
  }

  main {
    top: 60px;
    height: calc(100% - 60px);
  }

  #map {
    top: 0;
  }

  #panel {
    max-height: 45vh;
    border-radius: 4px;
  }

  .mw-preview-head {
    flex-direction: column;
    gap: 3px;
  }

  .mw-preview-time {
    font-size: 11px;
  }
}

/* Modal responsive */
@media (max-width: 720px) {
  #mw-modal {
    padding: 10px !important;
  }

  #mw-modal > div {
    max-width: 100% !important;
    max-height: calc(100vh - 20px) !important;
    gap: 4px !important;
    padding: 10px !important;
  }

  #mw-modal button {
    padding: 5px 10px !important;
    font-size: 11px !important;
  }

  .mw-preview-sky {
    min-height: 200px;
  }
}
