* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #05060d;
  --panel-bg: rgba(16, 18, 34, 0.82);
  --panel-border: rgba(120, 140, 255, 0.18);
  --accent: #7c9cff;
  --accent-2: #ffd479;
  --text: #e8ecff;
  --text-dim: #9aa3c7;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
}

/* ===== 3D scene ===== */
#scene-container {
  position: absolute;
  inset: 0;
  z-index: 1;
}

#scene-container canvas {
  display: block;
}

/* ===== Satellite picture-in-picture ===== */
#sat-view {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 320px;
  z-index: 6;
  pointer-events: none;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.5));
}

#sat-view.hidden { display: none; }

.sat-view-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 28px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: rgba(16, 18, 34, 0.92);
  border: 1px solid var(--accent);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  letter-spacing: 0.3px;
}

.sat-view-bar {
  pointer-events: auto; /* so the fullscreen button is clickable */
}

.sat-view-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

#sat-view-fov {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

#sat-fullscreen-btn {
  pointer-events: auto;
  width: 22px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: rgba(124, 156, 255, 0.15);
  border: 1px solid rgba(124, 156, 255, 0.3);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

#sat-fullscreen-btn:hover {
  background: rgba(124, 156, 255, 0.35);
}

.sat-view-frame {
  height: 210px;
  border: 1px solid var(--accent);
  border-top: none;
  border-radius: 0 0 12px 12px;
  /* transparent: the WebGL scissor viewport renders behind this box */
}

/* Fullscreen satellite view */
#sat-view.fullscreen {
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9;
}

#sat-view.fullscreen .sat-view-bar {
  border-radius: 0;
  border-left: none;
  border-right: none;
}

#sat-view.fullscreen .sat-view-frame {
  height: calc(100vh - 28px);
  border-radius: 0;
  border: none;
}

/* ===== Orbital element sliders ===== */
.slider-row {
  margin-top: 12px;
}

.slider-row label {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-bottom: 5px;
}

.slider-row label span {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.num-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.num-input {
  width: 48px;
  background: rgba(6, 8, 18, 0.7);
  border: 1px solid rgba(124, 156, 255, 0.3);
  border-radius: 6px;
  color: var(--accent);
  font-size: 11.5px;
  text-align: right;
  padding: 2px 4px;
  outline: none;
  font-variant-numeric: tabular-nums;
}

.num-input:focus {
  border-color: var(--accent);
}

/* trim spinner size in webkit */
.num-input::-webkit-inner-spin-button,
.num-input::-webkit-outer-spin-button {
  height: 14px;
}

.slider-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 4px;
  background: rgba(124, 156, 255, 0.22);
  outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #0e1020;
}

.slider-row input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #0e1020;
}

#coord-readout {
  position: absolute;
  bottom: 18px;
  right: 22px;
  font-size: 12px;
  color: var(--text-dim);
  background: rgba(10, 12, 24, 0.55);
  padding: 6px 12px;
  border-radius: 8px;
  letter-spacing: 0.4px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

/* ===== Loading ===== */
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-dim);
  font-size: 14px;
  letter-spacing: 0.5px;
  z-index: 5;
  transition: opacity 0.6s ease;
}

#loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(124, 156, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Panel ===== */
#panel {
  position: absolute;
  top: 22px;
  left: 22px;
  z-index: 10;
  width: 340px;
  max-width: calc(100vw - 44px);
  max-height: calc(100vh - 44px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  scrollbar-width: thin;
  scrollbar-color: rgba(124, 156, 255, 0.4) transparent;
}

#panel::-webkit-scrollbar {
  width: 8px;
}
#panel::-webkit-scrollbar-thumb {
  background: rgba(124, 156, 255, 0.35);
  border-radius: 8px;
}
#panel::-webkit-scrollbar-track {
  background: transparent;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

#minimize-btn {
  margin-left: auto;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(124, 156, 255, 0.12);
  border: 1px solid rgba(124, 156, 255, 0.25);
  color: var(--text);
  border-radius: 9px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

#minimize-btn:hover { background: rgba(124, 156, 255, 0.28); }
#minimize-btn:active { transform: scale(0.92); }

.logo {
  font-size: 34px;
  filter: drop-shadow(0 0 10px rgba(255, 212, 121, 0.5));
}

.brand-text h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.brand-text p {
  font-size: 12px;
  color: var(--text-dim);
}

/* ===== Search ===== */
.search-box {
  position: relative;
  display: flex;
  gap: 8px;
}

#search-input {
  flex: 1;
  background: rgba(6, 8, 18, 0.7);
  border: 1px solid rgba(124, 156, 255, 0.25);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 156, 255, 0.15);
}

#search-input::placeholder {
  color: var(--text-dim);
}

#search-btn {
  background: linear-gradient(135deg, #7c9cff, #5b74e6);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, filter 0.2s;
}

#search-btn:hover { filter: brightness(1.12); }
#search-btn:active { transform: scale(0.96); }

#suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: rgba(14, 16, 32, 0.98);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  overflow: hidden;
  z-index: 20;
  display: none;
}

#suggestions.show { display: block; }

.suggestion {
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  transition: background 0.12s;
}

.suggestion:last-child { border-bottom: none; }
.suggestion:hover, .suggestion.active {
  background: rgba(124, 156, 255, 0.16);
}

.suggestion .s-coords {
  color: var(--text-dim);
  font-size: 11px;
  margin-top: 2px;
}

.hint {
  margin-top: 12px;
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.6;
}

.hint code {
  background: rgba(124, 156, 255, 0.14);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--accent);
  font-size: 11px;
}

/* ===== Result ===== */
.result {
  margin-top: 16px;
  padding: 14px;
  background: rgba(255, 212, 121, 0.07);
  border: 1px solid rgba(255, 212, 121, 0.25);
  border-radius: 12px;
  animation: fadeIn 0.4s ease;
}

.result.hidden { display: none; }

.result-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-2);
}

.result-coords {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.result-desc {
  font-size: 12.5px;
  color: var(--text);
  margin-top: 8px;
  line-height: 1.5;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Quick list ===== */
.quick-list { margin-top: 18px; }

.quick-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

#location-select {
  width: 100%;
  background: rgba(6, 8, 18, 0.7);
  border: 1px solid rgba(124, 156, 255, 0.25);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 13.5px;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237c9cff' stroke-width='3'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#location-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 156, 255, 0.15);
}

#location-select optgroup {
  color: var(--accent-2);
  background: #10122a;
  font-size: 12px;
}

#location-select option {
  color: var(--text);
  background: #0e1020;
  padding: 6px;
}

/* ===== Map toggle ===== */
.map-toggle { margin-top: 18px; }

.map-toggle label,
.map-toggle .cap {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 8px;
}

.toggle-buttons {
  display: flex;
  gap: 8px;
}

.toggle-btn {
  flex: 1;
  background: rgba(6, 8, 18, 0.6);
  border: 1px solid rgba(124, 156, 255, 0.2);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 8px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s;
}

.toggle-btn.active {
  background: rgba(124, 156, 255, 0.22);
  color: var(--text);
  border-color: var(--accent);
}

/* ===== Settings section (collapsible) ===== */
.settings {
  margin-top: 18px;
}

.settings > summary,
.reference summary {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.settings > summary {
  font-size: 12px;
  font-weight: 600;
}

.settings > summary::-webkit-details-marker {
  display: none;
}

.settings > summary::before {
  content: "▸";
  font-size: 10px;
  transition: transform 0.15s;
}

.settings[open] > summary::before {
  transform: rotate(90deg);
}

.settings > summary:hover {
  color: var(--text);
}

.settings-body .map-toggle:first-child {
  margin-top: 12px;
}

.reference {
  margin-top: 18px;
}

.reference summary {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.reference summary::-webkit-details-marker {
  display: none;
}

.reference summary::before {
  content: "▸";
  font-size: 10px;
  transition: transform 0.15s;
}

.reference[open] summary::before {
  transform: rotate(90deg);
}

.reference summary:hover {
  color: var(--text);
}

.reference-links {
  margin-top: 8px;
}

.reference a {
  display: block;
  font-size: 12px;
  line-height: 1.5;
  color: var(--accent);
  text-decoration: none;
  padding: 9px 12px;
  background: rgba(124, 156, 255, 0.1);
  border: 1px solid rgba(124, 156, 255, 0.2);
  border-radius: 10px;
  transition: background 0.15s;
}

.reference a + a {
  margin-top: 7px;
}

.reference a:hover {
  background: rgba(124, 156, 255, 0.22);
}

.footer-note {
  margin-top: 18px;
  font-size: 10.5px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
}

.credit {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(124, 156, 255, 0.14);
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--accent);
}

/* ===== Minimize / expand ===== */
#panel {
  transform-origin: top left;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#panel.collapsed {
  opacity: 0;
  transform: scale(0.92);
  pointer-events: none;
}

#expand-btn {
  position: absolute;
  top: 22px;
  left: 22px;
  z-index: 10;
  display: none;
  align-items: center;
  gap: 9px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
  transition: filter 0.15s, transform 0.15s;
}

#expand-btn .logo {
  font-size: 22px;
  filter: drop-shadow(0 0 8px rgba(255, 212, 121, 0.5));
}

#expand-btn:hover { filter: brightness(1.12); }
#expand-btn:active { transform: scale(0.96); }
#expand-btn.show { display: flex; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  #panel {
    top: 12px;
    left: 12px;
    right: 12px;
    width: auto;
    padding: 16px;
  }

  #sat-view { display: none; }
}

/* ===== Sun / Earth / time controls ===== */
.datetime-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

input[type="datetime-local"] {
  flex: 1;
  min-width: 0;
  background: rgba(6, 8, 18, 0.7);
  border: 1px solid rgba(124, 156, 255, 0.3);
  border-radius: 10px;
  color: var(--text);
  font-size: 12.5px;
  padding: 8px 10px;
  outline: none;
  font-family: inherit;
}

input[type="datetime-local"]:focus {
  border-color: var(--accent);
}

/* make the native calendar picker icon visible on dark backgrounds */
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(0.8);
  cursor: pointer;
}

.mini-btn {
  flex-shrink: 0;
  background: rgba(124, 156, 255, 0.18);
  border: 1px solid rgba(124, 156, 255, 0.35);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.mini-btn:hover { background: rgba(124, 156, 255, 0.34); }

.phase-line {
  margin-top: 9px;
  font-size: 12px;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}

.period-line {
  margin-top: 10px;
  font-size: 12px;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}

.period-line .period-note {
  color: var(--text-dim);
  font-size: 11px;
}

.l2-note {
  margin-top: 12px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-dim);
  background: rgba(255, 159, 90, 0.08);
  border: 1px solid rgba(255, 159, 90, 0.25);
  border-radius: 10px;
  padding: 9px 11px;
}
