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

:root {
  --bg-deep: #060618;
  --bg-panel: rgba(8, 12, 42, 0.85);
  --cyan: #00e5ff;
  --cyan-dim: #007a8a;
  --orange: #ff6b35;
  --orange-glow: #ff8c00;
  --red: #ff2d55;
  --green: #39ff14;
  --text: #e0e8f0;
  --text-dim: #6a7a8a;
  --border: rgba(0, 229, 255, 0.2);
  --panel-radius: 8px;
}

body {
  background: var(--bg-deep);
  color: var(--text);
  font-family: 'Exo 2', sans-serif;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

#scene-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

#scene-container canvas {
  display: block;
}

/* HEADER */
#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: linear-gradient(180deg, rgba(6,6,24,0.95) 0%, rgba(6,6,24,0.7) 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}

#header-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rocket-icon {
  font-size: 22px;
  animation: rocketBob 2s ease-in-out infinite;
}

@keyframes rocketBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.title-text {
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--orange));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#mission-clock {
  font-family: 'Share Tech Mono', monospace;
  font-size: 16px;
  color: var(--cyan);
  letter-spacing: 2px;
}

/* PANELS */
.panel-title {
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--cyan);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
}

/* PARTS PANEL */
#parts-panel {
  position: fixed;
  left: 8px;
  top: 56px;
  bottom: 80px;
  width: 180px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  z-index: 50;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(10px);
}

#parts-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

#parts-list::-webkit-scrollbar {
  width: 4px;
}

#parts-list::-webkit-scrollbar-thumb {
  background: var(--cyan-dim);
  border-radius: 2px;
}

.part-card {
  background: rgba(0, 229, 255, 0.05);
  border: 1px solid rgba(0, 229, 255, 0.1);
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.part-card:hover {
  background: rgba(0, 229, 255, 0.15);
  border-color: var(--cyan);
  transform: translateX(3px);
}

.part-card.selected {
  background: rgba(255, 107, 53, 0.2);
  border-color: var(--orange);
  box-shadow: 0 0 12px rgba(255, 107, 53, 0.3);
}

.part-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.part-info {
  flex: 1;
}

.part-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
}

.part-detail {
  font-family: 'Share Tech Mono', monospace;
  font-size: 9px;
  color: var(--text-dim);
}

.part-category {
  font-family: 'Share Tech Mono', monospace;
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--orange);
  padding: 10px 8px 4px;
  text-transform: uppercase;
}

/* STAGING PANEL */
#staging-panel {
  position: fixed;
  right: 8px;
  top: 56px;
  width: 160px;
  max-height: 300px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  z-index: 50;
  backdrop-filter: blur(10px);
  overflow-y: auto;
}

.stage-group {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

.stage-header {
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  color: var(--orange);
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.stage-part {
  font-size: 10px;
  color: var(--text-dim);
  padding: 2px 0;
}

/* STATS BAR */
#stats-bar {
  position: fixed;
  bottom: 52px;
  left: 196px;
  right: 176px;
  height: 44px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 50;
  backdrop-filter: blur(10px);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  font-family: 'Share Tech Mono', monospace;
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 2px;
}

.stat-value {
  font-family: 'Share Tech Mono', monospace;
  font-size: 14px;
  color: var(--cyan);
  font-weight: 700;
}

.stat-value.warning {
  color: var(--red);
}

.stat-value.good {
  color: var(--green);
}

/* BUILD ACTIONS */
#build-actions {
  position: fixed;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 50;
}

/* BUTTONS */
.btn-action {
  font-family: 'Exo 2', sans-serif;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1px;
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
}

.btn-launch {
  background: linear-gradient(135deg, var(--orange), #ff3d00);
  color: white;
  box-shadow: 0 0 20px rgba(255, 107, 53, 0.4);
  animation: launchPulse 2s ease-in-out infinite;
}

.btn-launch:hover {
  box-shadow: 0 0 30px rgba(255, 107, 53, 0.7);
  transform: scale(1.05);
}

@keyframes launchPulse {
  0%, 100% { box-shadow: 0 0 20px rgba(255, 107, 53, 0.4); }
  50% { box-shadow: 0 0 35px rgba(255, 107, 53, 0.7); }
}

.btn-secondary {
  background: rgba(0, 229, 255, 0.1);
  color: var(--cyan);
  border: 1px solid var(--cyan-dim);
}

.btn-secondary:hover {
  background: rgba(0, 229, 255, 0.25);
  border-color: var(--cyan);
}

.btn-stage {
  background: linear-gradient(135deg, #ff6b35, #ff3d00);
  color: white;
  font-size: 14px;
  padding: 12px 28px;
  box-shadow: 0 0 15px rgba(255, 107, 53, 0.3);
}

.btn-stage:hover {
  box-shadow: 0 0 25px rgba(255, 107, 53, 0.6);
}

.btn-abort {
  background: linear-gradient(135deg, var(--red), #cc0033);
  color: white;
}

.btn-abort:hover {
  box-shadow: 0 0 20px rgba(255, 45, 85, 0.5);
}

/* FLIGHT UI */
#throttle-container {
  position: fixed;
  left: 12px;
  bottom: 80px;
  width: 50px;
  height: 220px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  z-index: 50;
  backdrop-filter: blur(10px);
}

#throttle-track {
  flex: 1;
  width: 20px;
  position: relative;
  background: rgba(0,0,0,0.4);
  border-radius: 4px;
  margin: 8px 0;
  overflow: hidden;
}

#throttle-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0%;
  background: linear-gradient(0deg, var(--orange), var(--green));
  border-radius: 4px;
  transition: height 0.1s;
}

#throttle-slider {
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  writing-mode: bt-lr;
  -webkit-appearance: slider-vertical;
}

#throttle-value {
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  color: var(--orange);
}

/* FLIGHT INSTRUMENTS */
#flight-instruments {
  position: fixed;
  right: 8px;
  top: 56px;
  width: 160px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  z-index: 50;
  backdrop-filter: blur(10px);
  padding: 4px 0;
}

.instrument {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid rgba(0,229,255,0.08);
}

.inst-label {
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.inst-value {
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  color: var(--cyan);
  font-weight: 700;
}

#fuel-bar-container {
  width: 80px;
  height: 10px;
  background: rgba(0,0,0,0.5);
  border-radius: 3px;
  overflow: hidden;
}

#fuel-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--red), var(--orange), var(--green));
  border-radius: 3px;
  transition: width 0.3s;
}

/* FLIGHT CONTROLS BOTTOM */
#flight-controls-bottom {
  position: fixed;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 50;
}

#control-hints {
  position: fixed;
  bottom: 52px;
  left: 70px;
  display: flex;
  gap: 16px;
  z-index: 50;
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  color: var(--text-dim);
}

/* MAP VIEW */
#map-view {
  position: fixed;
  right: 180px;
  top: 56px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  z-index: 60;
  padding: 8px;
  backdrop-filter: blur(10px);
}

.map-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 0;
  font-size: 9px;
  color: var(--text-dim);
  font-family: 'Share Tech Mono', monospace;
}

.legend-line {
  width: 20px;
  height: 2px;
}

.legend-line.karman {
  background: var(--orange);
}

/* MISSION MODAL */
#mission-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.8);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#modal-content {
  background: linear-gradient(135deg, rgba(8,12,42,0.97), rgba(20,10,40,0.97));
  border: 1px solid var(--cyan-dim);
  border-radius: 12px;
  padding: 32px 40px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 60px rgba(0,229,255,0.15);
}

#modal-title {
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: 24px;
  letter-spacing: 3px;
  margin-bottom: 20px;
  background: linear-gradient(90deg, var(--cyan), var(--orange));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#modal-stats {
  text-align: left;
  margin-bottom: 16px;
}

.modal-stat-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
}

.modal-stat-label {
  color: var(--text-dim);
}

.modal-stat-val {
  color: var(--cyan);
  font-weight: 700;
}

#modal-stars {
  font-size: 28px;
  margin: 12px 0;
  letter-spacing: 4px;
}

#modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

/* SAVE/LOAD MODAL */
#save-load-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.8);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#save-load-content {
  background: linear-gradient(135deg, rgba(8,12,42,0.97), rgba(20,10,40,0.97));
  border: 1px solid var(--cyan-dim);
  border-radius: 12px;
  padding: 24px 32px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 60px rgba(0,229,255,0.15);
}

#save-load-content h2 {
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 3px;
  margin-bottom: 16px;
  color: var(--cyan);
}

#sl-input-area {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

#rocket-name-input {
  flex: 1;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--cyan-dim);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text);
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  outline: none;
}

#rocket-name-input:focus {
  border-color: var(--cyan);
}

#sl-list {
  max-height: 250px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.saved-rocket-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: rgba(0,229,255,0.05);
  border: 1px solid rgba(0,229,255,0.1);
  border-radius: 6px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.saved-rocket-item:hover {
  background: rgba(0,229,255,0.15);
  border-color: var(--cyan);
}

.saved-rocket-name {
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  color: var(--text);
}

.saved-rocket-parts {
  font-size: 10px;
  color: var(--text-dim);
}

.btn-delete-rocket {
  background: rgba(255,45,85,0.2);
  border: 1px solid rgba(255,45,85,0.3);
  color: var(--red);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 10px;
}

.btn-delete-rocket:hover {
  background: rgba(255,45,85,0.4);
}

/* LEADERBOARD */
#leaderboard-section {
  position: fixed;
  right: 8px;
  bottom: 8px;
  width: 160px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  z-index: 50;
  backdrop-filter: blur(10px);
  max-height: 300px;
  overflow-y: auto;
}

#lb-toggle {
  cursor: pointer;
  user-select: none;
}

.lb-entry {
  display: flex;
  justify-content: space-between;
  padding: 4px 10px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.lb-rank { color: var(--orange); }
.lb-alt { color: var(--cyan); }

/* FOOTER */
#footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 24px;
  background: rgba(6,6,24,0.9);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 40;
  font-size: 10px;
  color: var(--text-dim);
}

#footer a {
  color: var(--cyan-dim);
  text-decoration: none;
}

#footer a:hover {
  color: var(--cyan);
}

/* SPACE REACHED CELEBRATION */
.space-reached {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: 36px;
  color: var(--orange);
  text-shadow: 0 0 30px rgba(255,107,53,0.6);
  z-index: 150;
  animation: spaceFadeIn 0.5s ease-out, spaceFadeOut 1s ease-in 3s forwards;
  pointer-events: none;
  text-align: center;
}

@keyframes spaceFadeIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes spaceFadeOut {
  to { opacity: 0; }
}

/* Mobile adjustments */
@media (max-width: 768px) {
  #parts-panel { width: 140px; }
  #staging-panel { width: 120px; }
  #stats-bar { left: 148px; right: 128px; }
  .title-text { font-size: 12px; letter-spacing: 1px; }
  #flight-instruments { width: 130px; }
  #control-hints { display: none; }
}