:root {
  --mint: #37f0a0;
  --sky: #7fd4ff;
  --warn: #ffb84d;
  --bad: #ff5468;
  --ink: #eaf2f6;
  --ink-dim: #93a7b4;
  --panel: rgba(6, 14, 22, 0.66);
  --panel-line: rgba(127, 212, 255, 0.28);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #010409;
  font-family: "Space Grotesk", system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font-family: inherit; border: none; cursor: pointer; user-select: none; -webkit-user-select: none; }

/* ---------- HUD ---------- */

#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#hud[hidden] { display: none; }
#hud button, .stick { pointer-events: auto; }

#topbar {
  position: absolute;
  top: calc(var(--safe-t) + 10px);
  left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 10px;
}
.datum {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  padding: 6px 13px;
  text-align: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-width: 86px;
}
.datum label { display: block; font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-dim); }
.datum span { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.datum span.good { color: var(--mint); }
.datum span.warn { color: var(--warn); }
.datum span.bad { color: var(--bad); }

/* docking reticle */
#reticle {
  position: absolute;
  left: 50%; top: 50%;
  width: 130px; height: 130px;
  transform: translate(-50%, -50%);
}
.ret-ring {
  position: absolute; inset: 0;
  border: 1.5px solid rgba(127, 212, 255, 0.5);
  border-radius: 50%;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#reticle.locked .ret-ring {
  border-color: var(--mint);
  box-shadow: 0 0 22px rgba(55, 240, 160, 0.4), inset 0 0 16px rgba(55, 240, 160, 0.12);
  animation: lock-pulse 1.1s ease-in-out infinite;
}
@keyframes lock-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.045); } }
.ret-cross {
  position: absolute; inset: 0;
}
.ret-cross::before, .ret-cross::after {
  content: "";
  position: absolute;
  background: rgba(127, 212, 255, 0.4);
}
.ret-cross::before { left: 50%; top: -8px; bottom: -8px; width: 1px; }
.ret-cross::after { top: 50%; left: -8px; right: -8px; height: 1px; }
#retDot {
  position: absolute;
  left: 50%; top: 50%;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 12px rgba(255, 184, 77, 0.8);
  transition: background 0.15s ease;
}
#retDot.good { background: var(--mint); box-shadow: 0 0 12px rgba(55, 240, 160, 0.9); }

#callout {
  position: absolute;
  top: calc(var(--safe-t) + 66px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 14px; font-weight: 600;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: callout-in 0.25s ease;
}
#callout[hidden] { display: none; }
@keyframes callout-in { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* sticks */
.stick {
  position: absolute;
  bottom: calc(var(--safe-b) + 26px);
  width: 118px; height: 118px;
  border-radius: 50%;
  background: rgba(8, 18, 28, 0.45);
  border: 1.5px solid rgba(127, 212, 255, 0.22);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  touch-action: none;
}
.stick label {
  position: absolute;
  bottom: -18px; left: 0; right: 0;
  text-align: center;
  font-size: 9px; letter-spacing: 0.22em;
  color: var(--ink-dim);
}
#leftStick { left: calc(var(--safe-l) + 20px); }
#rightStick { right: calc(var(--safe-r) + 20px); }
.stick-nub {
  position: absolute;
  left: 50%; top: 50%;
  width: 48px; height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(190,230,255,0.55), rgba(127,212,255,0.18));
  border: 1px solid rgba(190, 230, 255, 0.4);
}

#thrustCol {
  position: absolute;
  right: calc(var(--safe-r) + 152px);
  bottom: calc(var(--safe-b) + 34px);
  display: flex; flex-direction: column; gap: 8px;
}
.thrust-btn {
  width: 56px; height: 52px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  color: var(--sky);
  font-size: 18px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  touch-action: none;
}
.thrust-btn:active { background: rgba(127, 212, 255, 0.2); }

#leftCol {
  position: absolute;
  left: calc(var(--safe-l) + 152px);
  bottom: calc(var(--safe-b) + 34px);
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.mini-btn {
  width: 52px; height: 44px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--ink);
  font-size: 14px; font-weight: 700;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  touch-action: none;
}
.mini-btn.on { border-color: var(--mint); color: var(--mint); }

#fuelWrap {
  position: absolute;
  top: calc(var(--safe-t) + 66px);
  right: calc(var(--safe-r) + 14px);
  display: flex; align-items: center; gap: 7px;
}
#fuelWrap label { font-size: 10px; letter-spacing: 0.16em; color: var(--ink-dim); }
#fuelBar {
  width: 74px; height: 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.1);
  overflow: hidden;
}
#fuelFill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--sky), var(--mint)); border-radius: 999px; }

/* ---------- overlays ---------- */

#menu, #over {
  position: fixed; inset: 0;
  z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 20px calc(var(--safe-r) + 20px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 20px);
  background: radial-gradient(90% 70% at 50% 30%, rgba(4, 10, 18, 0.12), rgba(1, 4, 9, 0.78));
}
#menu[hidden], #over[hidden] { display: none; }

.menu-card {
  width: min(92vw, 400px);
  background: rgba(5, 12, 20, 0.8);
  border: 1px solid var(--panel-line);
  border-radius: 26px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: 30px 26px 22px;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
}

.menu-badge { filter: drop-shadow(0 6px 20px rgba(127, 212, 255, 0.35)); }

.menu-title {
  font-size: 48px; font-weight: 700;
  letter-spacing: 0.04em;
  margin-top: 8px;
  background: linear-gradient(165deg, #d8f2ff 5%, var(--sky) 50%, #3a86c8 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.menu-sub { font-size: 15px; color: var(--ink-dim); margin-top: 6px; font-weight: 400; }

.seg {
  display: flex;
  margin-top: 18px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}
.seg-btn {
  border-radius: 999px;
  padding: 9px 15px;
  background: transparent;
  color: var(--ink-dim);
  font-size: 13px; font-weight: 700;
}
.seg-btn.on { background: var(--sky); color: #04121e; }

.primary {
  margin-top: 18px;
  width: 100%;
  padding: 16px;
  border-radius: 18px;
  background: linear-gradient(160deg, #b8e6ff, var(--sky) 50%, #2f7cb8);
  color: #04121e;
  font-size: 20px; font-weight: 700;
  letter-spacing: 0.08em;
  box-shadow: 0 10px 28px rgba(127, 212, 255, 0.3);
  transition: transform 0.12s ease;
}
.primary:active { transform: scale(0.97); }

.ghost {
  margin-top: 10px;
  width: 100%;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--ink);
  font-size: 15px; font-weight: 600;
}

#stars { margin-top: 10px; font-size: 26px; color: var(--warn); letter-spacing: 0.2em; }

.menu-hints {
  margin-top: 16px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12.5px; color: var(--ink-dim);
}
.credit { margin-top: 14px; font-size: 10.5px; color: rgba(147, 167, 180, 0.65); }

/* ---------- loader ---------- */

#loader {
  position: fixed; inset: 0;
  z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(130% 100% at 50% 115%, #103a66 0%, #061426 44%, #010409 100%);
  transition: opacity 0.45s ease;
}
#loader.done { opacity: 0; pointer-events: none; }
.loader-inner { display: flex; flex-direction: column; align-items: center; gap: 13px; }
.loader-badge { animation: rise 2.2s ease-in-out infinite; }
@keyframes rise { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
.loader-title {
  font-size: 38px; font-weight: 700;
  letter-spacing: 0.08em;
  background: linear-gradient(165deg, #d8f2ff 5%, var(--sky) 50%, #3a86c8 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.loader-bar {
  width: min(60vw, 250px); height: 5px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
}
.loader-fill {
  height: 100%; width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--sky), var(--mint));
  transition: width 0.25s ease;
  box-shadow: 0 0 10px rgba(127, 212, 255, 0.7);
}
.loader-sub { font-size: 13px; color: var(--ink-dim); }

@media (max-width: 700px) {
  .menu-title { font-size: 42px; }
  #thrustCol { right: calc(var(--safe-r) + 146px); }
  #leftCol { left: calc(var(--safe-l) + 146px); }
}
