:root {
  --bg: #05070d;
  --panel: rgba(12, 18, 30, 0.78);
  --panel-strong: rgba(8, 14, 25, 0.94);
  --border: rgba(110, 170, 230, 0.25);
  --accent: #5fd4ff;
  --accent-dim: #2a7e9a;
  --warn: #ffb347;
  --bad: #ff4f5e;
  --good: #6fffa1;
  --text: #d8e6f5;
  --text-dim: #93a6bd;
  --fuel: #3fc0ff;
  --ox: #6fe7ff;
  --mono: #ffd56b;
  --elec: #c1ff5e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: "SF Pro Display", "Helvetica Neue", "Hiragino Sans", "Yu Gothic", sans-serif;
  background: #000;
  color: var(--text);
  user-select: none;
}

canvas#viewport {
  position: fixed;
  inset: 0;
  width: 100%; height: 100%;
  display: block;
}

.hidden { display: none !important; }

/* ===== Splash ===== */
#splash {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at center, #07101e 0%, #000 70%);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 999;
  transition: opacity 0.6s ease;
}
#splash h1 {
  font-size: 56px;
  letter-spacing: 8px;
  background: linear-gradient(90deg, #5fd4ff 0%, #b8e7ff 50%, #5fd4ff 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  margin: 0;
}
#splash .tagline { color: var(--text-dim); letter-spacing: 4px; margin-top: 8px; }
#splash .loading { margin-top: 60px; color: var(--accent); letter-spacing: 4px; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }

/* ===== Top bar ===== */
#topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--panel-strong);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px;
  gap: 24px;
  z-index: 100;
  backdrop-filter: blur(12px);
}
#topbar .brand {
  font-weight: 700; letter-spacing: 3px;
  color: var(--accent);
}
#topbar .modes { display: flex; gap: 4px; }
#topbar .modes button {
  background: transparent; color: var(--text-dim);
  border: 1px solid transparent;
  padding: 6px 14px; border-radius: 4px;
  cursor: pointer; font-size: 13px;
}
#topbar .modes button.active {
  background: rgba(95, 212, 255, 0.12);
  border-color: var(--accent-dim);
  color: var(--accent);
}
#topbar .modes button:hover { color: var(--text); }
#topbar .time {
  display: flex; align-items: center; gap: 6px;
  margin-left: auto;
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 13px;
}
#topbar .time button {
  background: rgba(95, 212, 255, 0.1);
  border: 1px solid var(--border);
  color: var(--accent);
  cursor: pointer; padding: 2px 8px;
  border-radius: 3px;
}
#topbar .info {
  display: flex; gap: 14px;
  font-size: 12px; color: var(--text-dim);
  font-family: "SF Mono", "Menlo", monospace;
}
#topbar .info span { padding: 4px 8px; background: rgba(255,255,255,0.04); border-radius: 3px; }

/* ===== VAB UI ===== */
#part-catalog {
  position: fixed; top: 60px; left: 12px;
  width: 250px; max-height: calc(100vh - 80px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex; flex-direction: column;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.catalog-header {
  padding: 10px 14px;
  font-weight: 600;
  letter-spacing: 2px;
  border-bottom: 1px solid var(--border);
  color: var(--accent);
}
.catalog-tabs {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  border-bottom: 1px solid var(--border);
}
.catalog-tabs button {
  background: transparent; color: var(--text-dim);
  border: none; border-bottom: 2px solid transparent;
  padding: 8px 4px; cursor: pointer;
  font-size: 11px;
}
.catalog-tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(95, 212, 255, 0.08);
}
#part-list {
  overflow-y: auto;
  padding: 8px;
  display: flex; flex-direction: column; gap: 6px;
  flex: 1;
}
.part-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 4px;
  padding: 8px;
  cursor: grab;
  transition: all 0.15s;
}
.part-card:hover {
  background: rgba(95, 212, 255, 0.1);
  border-color: var(--accent-dim);
  transform: translateX(2px);
}
.part-card.dragging { opacity: 0.5; cursor: grabbing; }
.part-card .name { font-size: 12px; font-weight: 600; color: var(--text); }
.part-card .stats { font-size: 10px; color: var(--text-dim); margin-top: 4px; font-family: "SF Mono", monospace; }
.part-card .icon {
  display: inline-block;
  width: 28px; height: 28px;
  background: linear-gradient(135deg, #2a4055, #1a2535);
  border-radius: 3px;
  margin-right: 8px;
  vertical-align: middle;
}

#stage-panel {
  position: fixed; top: 60px; right: 12px;
  width: 220px; max-height: calc(100vh - 80px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.stage-header {
  padding: 10px 14px;
  font-weight: 600;
  letter-spacing: 2px;
  border-bottom: 1px solid var(--border);
  color: var(--accent);
}
#stage-list { padding: 8px; max-height: 60vh; overflow-y: auto; }
.stage-entry {
  background: rgba(255,255,255,0.04);
  border-left: 3px solid var(--accent);
  padding: 6px 10px;
  margin-bottom: 4px;
  font-size: 11px;
  font-family: "SF Mono", monospace;
  border-radius: 3px;
  cursor: grab;
}
.stage-entry .stage-num { color: var(--accent); font-weight: 700; }
.stage-entry .parts { color: var(--text-dim); }

#build-toolbar {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  display: flex; gap: 6px;
  z-index: 50;
  backdrop-filter: blur(8px);
}
#build-toolbar button {
  background: rgba(95, 212, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
#build-toolbar button:hover { background: rgba(95, 212, 255, 0.2); }

.info-panel {
  position: fixed;
  top: 60px; left: 280px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px;
  width: 320px;
  max-height: 70vh;
  overflow-y: auto;
  font-size: 12px;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.info-panel h3 { margin: 0 0 8px 0; color: var(--accent); font-size: 14px; }
.info-panel .row { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed rgba(255,255,255,0.05); }
.info-panel .row label { color: var(--text-dim); }
.info-panel .row span { font-family: "SF Mono", monospace; }
.info-panel .warn { color: var(--warn); }
.info-panel .bad { color: var(--bad); }
.info-panel .good { color: var(--good); }

/* ===== Flight HUD ===== */
#throttle-panel {
  position: fixed; bottom: 16px; left: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  width: 90px;
  z-index: 50;
  backdrop-filter: blur(8px);
}
#throttle-panel .label { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; letter-spacing: 1px; }
.throttle-track {
  width: 100%; height: 180px;
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--border);
  position: relative;
  border-radius: 3px;
}
#throttle-fill {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(180deg, var(--bad), var(--warn), var(--good));
  height: 0%;
  transition: height 0.1s linear;
}
#throttle-percent {
  text-align: center;
  font-family: "SF Mono", monospace;
  margin-top: 8px;
  color: var(--accent);
  font-weight: 700;
}

#navball-container {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  width: 240px; height: 240px;
  background: var(--panel-strong);
  border: 2px solid var(--border);
  border-radius: 50%;
  z-index: 50;
  overflow: hidden;
}
#navball { width: 100%; height: 100%; }
.navball-label {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  padding: 2px 8px;
  border-radius: 3px;
  font-family: "SF Mono", monospace;
  font-size: 12px;
  color: var(--accent);
}

#resource-panel {
  position: fixed; top: 64px; right: 12px;
  width: 220px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.resource { margin-bottom: 8px; }
.resource span { font-size: 11px; color: var(--text-dim); display: block; margin-bottom: 3px; }
.resource .bar {
  width: 100%; height: 8px;
  background: rgba(0,0,0,0.5);
  border-radius: 4px;
  overflow: hidden;
}
.resource .fill {
  height: 100%; width: 100%;
  background: var(--fuel);
  transition: width 0.2s;
}
#fuel-bar { background: var(--fuel); }
#ox-bar { background: var(--ox); }
#mono-bar { background: var(--mono); }
#elec-bar { background: var(--elec); }

#telemetry {
  position: fixed; top: 64px; left: 12px;
  width: 200px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  z-index: 50;
  backdrop-filter: blur(8px);
  font-size: 11px;
}
#telemetry div { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed rgba(255,255,255,0.05); }
#telemetry label { color: var(--text-dim); }
#telemetry span { font-family: "SF Mono", monospace; color: var(--accent); }

#stage-readout {
  position: fixed; bottom: 16px; right: 16px;
  width: 220px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  z-index: 50;
  backdrop-filter: blur(8px);
}
#stage-readout .next-stage { font-size: 11px; color: var(--text-dim); letter-spacing: 1px; }
#next-stage-content { font-size: 12px; color: var(--text); margin: 6px 0; font-family: "SF Mono", monospace; }
#stage-btn {
  width: 100%; background: rgba(255, 79, 94, 0.2);
  color: var(--bad); border: 1px solid var(--bad);
  padding: 8px; border-radius: 4px; cursor: pointer;
  font-weight: 700;
  margin-top: 6px;
}
#stage-btn:hover { background: rgba(255, 79, 94, 0.4); }

#control-help {
  position: fixed; bottom: 280px; right: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-size: 10px;
  color: var(--text-dim);
  z-index: 50;
  backdrop-filter: blur(8px);
}
#control-help div { padding: 2px 0; }
kbd {
  background: rgba(255,255,255,0.1);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: "SF Mono", monospace;
  font-size: 10px;
  color: var(--accent);
  margin-right: 2px;
}

#map-view {
  position: fixed; inset: 60px 12px 12px 12px;
  background: rgba(0,5,15,0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  z-index: 60;
  backdrop-filter: blur(20px);
}
#map-view canvas { width: 100%; height: 100%; }
.map-legend {
  position: absolute; top: 10px; left: 10px;
  color: var(--accent); font-size: 12px; letter-spacing: 2px;
}

#event-log {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%);
  width: 400px;
  z-index: 50;
  pointer-events: none;
}
.event-message {
  background: var(--panel-strong);
  border-left: 4px solid var(--accent);
  padding: 8px 14px;
  margin-bottom: 4px;
  font-size: 12px;
  border-radius: 3px;
  animation: slideIn 0.3s ease, fadeOut 0.5s ease 4s forwards;
  backdrop-filter: blur(8px);
}
.event-message.warn { border-left-color: var(--warn); color: var(--warn); }
.event-message.bad { border-left-color: var(--bad); color: var(--bad); }
.event-message.good { border-left-color: var(--good); color: var(--good); }
@keyframes slideIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(-10px); } }

/* Modal */
#modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(8px);
}
.modal-inner {
  background: var(--panel-strong);
  border: 1px solid var(--accent-dim);
  border-radius: 8px;
  padding: 30px;
  max-width: 480px;
}
.modal-inner h2 { color: var(--accent); margin-top: 0; }
.modal-inner button {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 8px 24px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 700;
  margin-top: 16px;
}
