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

html, body {
  width: 100%; height: 100%;
  background: #000;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #fff;
}

#app { position: relative; width: 100vw; height: calc(100vh - 44px); height: calc(100dvh - 44px); }
#canvas { display: block; width: 100%; height: 100%; }

/* ── Header ── */
#header {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  padding: 18px 520px 18px 28px;
  display: flex; align-items: flex-start; justify-content: space-between;
  background: linear-gradient(to bottom, rgba(0,0,10,0.85) 0%, transparent 100%);
  pointer-events: none;
}

#header h1 {
  font-size: 1.1rem; font-weight: 300;
  letter-spacing: 0.45em; text-transform: uppercase;
  color: rgba(255,255,255,0.75);
}

/* ── Header left: title + planet nav + moon nav stacked ── */
#header-left {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  pointer-events: auto;
}

/* ── Header top-right: always pinned to top-right corner ── */
#header-top-right {
  position: absolute; top: 18px; right: 28px;
  display: flex; align-items: center; gap: 8px;
  pointer-events: auto; flex-wrap: nowrap;
}

#help-btn {
  margin-left: 10px;
  padding: 5px 14px; border-radius: 22px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.55);
  cursor: pointer; font-size: 0.78rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  font-family: inherit; flex-shrink: 0; letter-spacing: 0.06em;
}
#help-btn:hover {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.35);
  color: rgba(255,255,255,0.9);
}

/* ── Help Overlay ── */
#help-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: transparent;
  pointer-events: none;
}
#help-overlay.hidden { display: none; }

.help-callout {
  position: absolute;
  background: rgba(4,8,30,0.96);
  border: 1px solid rgba(80,130,255,0.35);
  border-radius: 14px;
  padding: 20px 22px 16px;
  width: 310px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.8);
  pointer-events: none;
}
.help-callout::after {
  content: '';
  position: absolute;
  border: 8px solid transparent;
}
.help-callout[data-arrow="up"]::after {
  top: -16px; left: 22px;
  border-bottom-color: rgba(80,130,255,0.4);
}
.help-callout[data-arrow="down"]::after {
  bottom: -16px; left: 22px;
  border-top-color: rgba(80,130,255,0.4);
}
.help-callout[data-arrow="left"]::after {
  left: -16px; top: 20px;
  border-right-color: rgba(80,130,255,0.4);
}
.help-callout[data-arrow="right"]::after {
  right: -16px; top: 20px;
  border-left-color: rgba(80,130,255,0.4);
}

.help-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(80,130,255,0.18);
  border: 1px solid rgba(80,130,255,0.45);
  color: rgba(140,185,255,0.9);
  font-size: 0.75rem; font-weight: 700;
  margin-bottom: 9px;
}
.help-title {
  font-size: 1.05rem; font-weight: 600;
  color: rgba(255,255,255,0.95);
  letter-spacing: 0.03em; margin-bottom: 8px;
}
.help-body {
  font-size: 0.88rem; line-height: 1.65;
  color: rgba(255,255,255,0.65);
}
.help-close-x {
  position: absolute; top: 10px; right: 10px;
  background: none; border: none;
  color: rgba(255,255,255,0.35);
  font-size: 1.2rem; line-height: 1;
  cursor: pointer; padding: 2px 6px;
  border-radius: 4px;
  pointer-events: auto;
  transition: color 0.15s;
}
.help-close-x:hover { color: rgba(255,255,255,0.8); }

.help-footer {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid rgba(80,130,255,0.12);
  pointer-events: auto;
}
.help-counter {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.28);
  letter-spacing: 0.05em;
}
.help-nav-btn {
  background: none;
  border: 1px solid rgba(80,130,255,0.32);
  color: rgba(140,185,255,0.85);
  padding: 5px 13px; border-radius: 14px;
  cursor: pointer; font-size: 0.72rem;
  font-family: inherit; letter-spacing: 0.04em;
  transition: background 0.15s, border-color 0.15s;
}
.help-nav-btn:hover {
  background: rgba(80,130,255,0.18);
  border-color: rgba(80,130,255,0.55);
}
.help-nav-btn.done {
  background: rgba(80,130,255,0.18);
  border-color: rgba(80,130,255,0.5);
  color: rgba(180,210,255,0.95);
}

#back-btn {
  display: block;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.8);
  padding: 7px 18px; border-radius: 22px;
  cursor: pointer; font-size: 0.78rem;
  letter-spacing: 0.06em;
  margin-bottom: 20px;
  transition: background 0.2s, border-color 0.2s;
  font-family: inherit;
}
#back-btn:hover { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.35); }
#back-btn.hidden { display: none; }

/* ── Planet Nav ── */
#planet-nav {
  display: flex; align-items: center; justify-content: flex-start;
  flex-wrap: nowrap; gap: 4px;
  pointer-events: auto;
  padding: 0; margin-top: 10px;
}
#planet-nav::-webkit-scrollbar { display: none; }

.planet-nav-btn {
  display: flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,0.04);
  border: 1px solid transparent;
  color: rgba(255,255,255,0.55);
  padding: 5px 11px; border-radius: 20px;
  cursor: pointer; font-size: 0.62rem;
  letter-spacing: 0.13em; text-transform: uppercase;
  white-space: nowrap; font-family: inherit;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.planet-nav-btn:hover {
  color: rgba(255,255,255,0.82);
  background: rgba(255,255,255,0.09);
}
.planet-nav-btn.active {
  color: rgba(255,255,255,0.92);
  background: rgba(255,255,255,0.07);
  border-color: var(--accent, rgba(255,255,255,0.3));
}
.planet-nav-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent, #fff);
  flex-shrink: 0;
  opacity: 0.7;
}
.planet-nav-btn.active .planet-nav-dot { opacity: 1; }

/* ── Time Controls ── */
#time-controls {
  position: absolute; bottom: 24px; left: 20px; z-index: 20;
  display: flex; flex-direction: column; gap: 8px;
  background: rgba(4,6,22,0.75);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px; padding: 12px 16px;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  width: min(420px, calc(100vw - 40px));
}

#sim-date {
  font-size: 1rem; font-weight: 300;
  letter-spacing: 0.06em; color: rgba(255,255,255,0.88);
}

#speed-row {
  display: flex; align-items: center; gap: 8px;
}


#speed-label {
  font-size: 0.75rem; color: rgba(255,255,255,0.7);
  letter-spacing: 0.08em; min-width: 72px; text-align: right;
  white-space: nowrap;
}
#days-per-sec {
  font-size: 0.62rem; color: rgba(255,255,255,0.35);
  letter-spacing: 0.06em; white-space: nowrap;
}

#speed-slider {
  flex: 1; height: 3px;
  -webkit-appearance: none; appearance: none;
  background: rgba(255,255,255,0.15); border-radius: 2px; outline: none; cursor: pointer;
}
#speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px;
  border-radius: 50%; background: rgba(255,255,255,0.85); cursor: pointer;
  box-shadow: 0 0 4px rgba(255,255,255,0.3);
}
#speed-slider::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: rgba(255,255,255,0.85); cursor: pointer; border: none;
}


#time-btns { display: flex; align-items: center; gap: 6px; }

#reverse-btn, #reset-btn, #pause-btn {
  padding: 5px 14px; border-radius: 22px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.55);
  cursor: pointer; font-size: 0.78rem; font-weight: 600;
  letter-spacing: 0.06em; font-family: inherit;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  white-space: nowrap;
}
#reverse-btn:hover, #reset-btn:hover, #pause-btn:hover {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.35);
  color: rgba(255,255,255,0.9);
}
#reverse-btn.active {
  background: rgba(100,160,255,0.15);
  border-color: rgba(100,160,255,0.7);
  color: rgba(140,190,255,0.9);
}

/* ── Moon Nav ── */
#moon-nav {
  display: flex; align-items: center; justify-content: flex-start;
  flex-wrap: wrap; gap: 4px; padding: 0;
  pointer-events: none;
  opacity: 0; max-height: 0; overflow: hidden;
  transition: opacity 0.3s, max-height 0.3s;
}
#moon-nav.visible { opacity: 1; pointer-events: auto; max-height: 60px; }

.moon-nav-btn {
  background: rgba(255,255,255,0.03);
  border: 1px solid transparent;
  color: rgba(255,255,255,0.55);
  padding: 3px 10px; border-radius: 14px;
  cursor: pointer; font-size: 0.58rem;
  letter-spacing: 0.13em; text-transform: uppercase;
  white-space: nowrap; font-family: inherit;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.moon-nav-btn:hover {
  color: rgba(255,255,255,0.72);
  background: rgba(255,255,255,0.08);
}
.moon-nav-btn.active {
  color: rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.07);
  border-color: rgba(255,255,255,0.22);
}

/* ── Labels ── */
#labels-container {
  position: absolute; inset: 0; z-index: 10; pointer-events: none;
}
#labels-container.labels-hidden .planet-label {
  pointer-events: none;
}
.planet-label {
  position: absolute; transform: translateX(-50%);
  background: rgba(5,5,20,0.65);
  border: 1px solid rgba(255,255,255,0.13);
  color: rgba(255,255,255,0.85);
  padding: 3px 11px; border-radius: 14px;
  font-size: 0.68rem; letter-spacing: 0.18em;
  text-transform: uppercase; white-space: nowrap;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  pointer-events: auto; cursor: pointer;
  transition: opacity 0.3s, background 0.2s, border-color 0.2s;
  user-select: none;
}
.planet-label:hover {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.35);
}
.moon-label {
  font-size: 0.58rem;
  padding: 2px 8px;
  color: rgba(255,255,255,0.55);
  background: rgba(5,5,20,0.45);
  border-color: rgba(255,255,255,0.08);
  cursor: pointer;
}
.moon-label:hover {
  color: rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.28);
}

/* ── Stats Panel ── */
#stats-panel {
  position: absolute; top: 0; right: 0; z-index: 15;
  width: 320px; height: 100%;
  background: rgba(4,6,22,0.88);
  border-left: 1px solid rgba(255,255,255,0.07);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  overflow-y: auto;
  padding: 110px 26px 36px;
  transform: translateX(100%) translateZ(0);
  transition: transform 0.42s cubic-bezier(0.4, 0, 0.2, 1);
}
#stats-panel.visible { transform: translateX(0) translateZ(0); }

#stats-panel::-webkit-scrollbar { width: 3px; }
#stats-panel::-webkit-scrollbar-track { background: transparent; }
#stats-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }

#planet-name {
  font-size: 1.85rem; font-weight: 200;
  letter-spacing: 0.12em; text-transform: uppercase;
  margin-bottom: 8px; line-height: 1.1;
}

#planet-type-badge {
  display: inline-block;
  padding: 3px 11px; border-radius: 14px;
  font-size: 0.63rem; letter-spacing: 0.18em;
  text-transform: uppercase; margin-bottom: 16px;
}

#planet-description {
  font-size: 0.82rem; line-height: 1.75;
  color: rgba(255,255,255,0.55);
  margin-bottom: 22px; padding-bottom: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

#stats-grid { display: flex; flex-direction: column; gap: 13px; }

.stat-item { display: flex; flex-direction: column; gap: 2px; }

.stat-label {
  font-size: 0.63rem; letter-spacing: 0.2em;
  text-transform: uppercase; color: rgba(255,255,255,0.3);
}
.stat-value {
  font-size: 0.88rem; color: rgba(255,255,255,0.82);
  letter-spacing: 0.03em;
}

.stat-note {
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(80,130,255,0.07);
  border: 1px solid rgba(80,130,255,0.18);
  font-size: 0.72rem; line-height: 1.6;
  color: rgba(255,255,255,0.45);
}

/* ── Top controls (GI + Labels + Music) ── */
#top-controls {
  display: flex; gap: 8px; align-items: center;
}
.btn-icon-only { display: none; }

#gi-btn, #labels-btn, #music-btn {
  padding: 4px 12px; border-radius: 22px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.35);
  cursor: pointer; font-size: 0.7rem; font-weight: 500;
  letter-spacing: 0.08em; font-family: inherit;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
#gi-btn.active {
  background: rgba(255,210,50,0.1);
  border-color: rgba(255,210,50,0.7);
  color: rgba(255,210,50,0.9);
}
#gi-icon {
  filter: grayscale(1) brightness(0.5);
  transition: filter 0.3s;
}
#gi-btn.active #gi-icon {
  filter: grayscale(0) brightness(1.2);
}
#gi-btn:hover, #labels-btn:hover, #music-btn:hover {
  border-color: rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.65);
}
#music-btn.active {
  background: rgba(160,80,255,0.12);
  border-color: rgba(160,80,255,0.7);
  color: rgba(180,100,255,0.9);
}
#volume-slider {
  width: 68px; height: 3px;
  -webkit-appearance: none; appearance: none;
  background: rgba(255,255,255,0.15); border-radius: 2px;
  outline: none; cursor: pointer; flex-shrink: 0;
}
#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 11px; height: 11px;
  border-radius: 50%; background: rgba(180,100,255,0.9); cursor: pointer;
  box-shadow: 0 0 4px rgba(160,80,255,0.5);
}
#volume-slider::-moz-range-thumb {
  width: 11px; height: 11px; border-radius: 50%;
  background: rgba(180,100,255,0.9); cursor: pointer; border: none;
}
#labels-btn.active {
  background: rgba(50,205,100,0.1);
  border-color: rgba(50,205,100,0.7);
  color: rgba(50,205,100,0.9);
}
#labels-btn:not(.active) {
  background: rgba(220,60,60,0.1);
  border-color: rgba(220,60,60,0.6);
  color: rgba(220,60,60,0.9);
}
#demo-btn {
  position: absolute; bottom: 24px; right: 20px; z-index: 20;
  padding: 5px 16px; border-radius: 22px;
  background: rgba(80,130,255,0.1);
  border: 1px solid rgba(80,130,255,0.6);
  color: rgba(80,130,255,0.9);
  cursor: pointer; font-size: 0.7rem; font-weight: 500;
  letter-spacing: 0.08em; font-family: inherit;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
#demo-btn.active {
  background: rgba(50,205,100,0.1);
  border-color: rgba(50,205,100,0.7);
  color: rgba(50,205,100,0.9);
}
#demo-btn:hover {
  border-color: rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.65);
}

/* ── Overview Hint ── */
#overview-hint {
  position: absolute; bottom: 28px; left: 50%; z-index: 5;
  transform: translateX(-50%);
  font-size: 0.72rem; color: rgba(255,255,255,0.6);
  letter-spacing: 0.25em; text-transform: uppercase;
  pointer-events: none;
  transition: opacity 0.4s;
}

/* ── Responsive ── */

/* Tablet (iPad portrait and landscape) */
@media (max-width: 1280px) {
  #stats-panel { width: min(320px, 100%); }

  .planet-nav-btn {
    padding: 4px 8px;
    font-size: 0.58rem;
    letter-spacing: 0.08em;
  }

  #header h1 { font-size: 0.9rem; letter-spacing: 0.3em; }

  #top-controls .btn-label { display: none; }
  #top-controls .btn-icon-only { display: inline; }
  #volume-slider { width: 70px; }
  #header { padding-right: 280px; }
}

/* Mobile */
@media (max-width: 600px) {
  #stats-panel { width: 100%; border-left: none; padding: 80px 20px 30px; }
  #header h1 { display: none; }
}

/* ── Keyboard hint ── */
#key-hint {
  position: absolute; bottom: 56px; left: 50%; z-index: 5;
  transform: translateX(-50%);
  font-size: 0.62rem; color: rgba(255,255,255,0.5);
  letter-spacing: 0.2em; text-transform: uppercase;
  pointer-events: none;
}
