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

html, body {
  height: 100%;
  overflow: hidden;
  background: #05010f;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: #e8ecf8;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#game, #game canvas {
  position: fixed;
  inset: 0;
  touch-action: none;
}

/* ------------------------------------------------------------------ HUD */
#hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}
#hud-left, #hud-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#hud-right { justify-content: flex-end; }

.pill {
  background: rgba(16, 14, 40, 0.72);
  border: 1px solid rgba(120, 140, 255, 0.25);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  backdrop-filter: blur(6px);
  white-space: nowrap;
}

.btn {
  pointer-events: auto;
  cursor: pointer;
  color: #e8ecf8;
  font-size: 15px;
  line-height: 1;
  transition: transform 0.1s, border-color 0.15s;
}
.btn:hover { border-color: rgba(120, 200, 255, 0.7); transform: scale(1.08); }
.btn:active { transform: scale(0.95); }

.level-dot.exp, .set-btn.exp { border-style: dashed; border-color: rgba(255, 209, 102, 0.6); }

#fuel { display: flex; align-items: center; gap: 8px; }
#fuel-track {
  width: 84px;
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
#fuel-track { position: relative; }
#fuel-fill {
  height: 100%;
  width: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, #ff9f43, #ffd166);
  transition: width 0.15s linear;
}
#fuel-cost {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(255, 93, 93, 0.85);
  border-radius: 4px;
}

#stops span { margin: 0 1px; }
.stop-done { opacity: 0.35; filter: grayscale(0.8); }
.stop-active { text-shadow: 0 0 8px rgba(124, 255, 107, 0.9); }
.stop-todo { opacity: 0.7; }

#power { color: #9bd5ff; }

/* ------------------------------------------------------------- hint bar */
#hint {
  position: fixed;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(560px, 92vw);
  text-align: center;
  font-size: 14px;
  color: rgba(210, 222, 255, 0.85);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 10;
}

/* ---------------------------------------------------------- level dots */
#level-label { pointer-events: auto; cursor: pointer; }
#level-label::after { content: ' ▾'; opacity: 0.6; font-size: 10px; }

#levels-bar {
  position: fixed;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 25;
  max-width: 100vw;
  background: rgba(12, 10, 34, 0.92);
  border: 1px solid rgba(120, 140, 255, 0.3);
  border-radius: 16px;
  padding: 10px 14px;
  backdrop-filter: blur(8px);
}
#levels-bar.open { display: flex; }
#set-bar, #dot-bar { display: flex; gap: 8px; }
#set-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(200, 214, 255, 0.75);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}
.set-btn {
  border: 1px solid rgba(255, 209, 102, 0.3);
  background: rgba(16, 14, 40, 0.72);
  color: #ffd166;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: transform 0.1s, border-color 0.15s, background 0.15s;
}
.set-btn:hover:not(:disabled) { transform: scale(1.08); border-color: #ffd166; }
.set-btn.current { background: rgba(255, 209, 102, 0.22); border-color: #ffd166; }
.set-btn.locked { opacity: 0.4; cursor: default; }
#difficulty { color: #ffd166; }

.level-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(120, 140, 255, 0.35);
  background: rgba(16, 14, 40, 0.72);
  color: #cfe1ff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: transform 0.1s, border-color 0.15s, background 0.15s;
}
.level-dot:hover:not(:disabled) { transform: scale(1.12); border-color: #7ad7ff; }
.level-dot.current { background: rgba(60, 130, 255, 0.45); border-color: #7ad7ff; }
.level-dot.locked { opacity: 0.45; cursor: default; font-size: 12px; }

/* ------------------------------------------------ launch telemetry */
#aim-readout {
  position: fixed;
  z-index: 5;
  pointer-events: none;
  /* offset clear of the ship: a short trail lands right below it */
  transform: translate(-50%, 320%);
  background: rgba(8, 6, 24, 0.9);
  border: 1.5px solid rgba(255, 209, 102, 0.75);
  color: #ffe9b0;
  border-radius: 9px;
  padding: 4px 11px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------- fine-aim chip */
#fine-chip {
  position: fixed;
  z-index: 5;
  pointer-events: none;
  transform: translate(-50%, -190%);
  background: rgba(10, 8, 30, 0.88);
  border: 1.5px solid #66e0ff;
  color: #e8f6ff;
  border-radius: 9px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

/* ------------------------------------------------------- install banner */
#install-banner {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 35;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(440px, 92vw);
  padding: 10px 12px 10px 10px;
  background: rgba(14, 12, 38, 0.95);
  border: 1px solid rgba(120, 140, 255, 0.35);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
}
#install-banner[hidden] { display: none; }
#install-banner img { width: 40px; height: 40px; border-radius: 9px; flex: none; }
.ib-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
/* one line each: a wrapping banner grows tall enough to swallow the menu */
.ib-text b { font-size: 14px; color: #e8ecf8; white-space: nowrap; }
.ib-text span { font-size: 12px; color: rgba(200, 214, 255, 0.72); white-space: nowrap; }
#btn-install {
  background: linear-gradient(180deg, #6f7dff, #4a56d8);
  border: none;
  color: #fff;
  font-size: 13.5px;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
#btn-install:hover { filter: brightness(1.12); }
.ib-dismiss {
  background: none;
  border: none;
  color: rgba(200, 214, 255, 0.5);
  font-size: 15px;
  cursor: pointer;
  padding: 4px 2px;
}
.ib-dismiss:hover { color: #e8ecf8; }

/* --------------------------------------------------------------- toast */
#toast {
  position: fixed;
  top: 96px;
  left: 50%;
  transform: translate(-50%, -12px);
  background: rgba(16, 14, 40, 0.85);
  border: 1px solid rgba(255, 160, 120, 0.35);
  border-radius: 12px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 20;
  max-width: 92vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------- overlay */
#overlay {
  position: fixed;
  inset: 0;
  display: none;
  background: rgba(4, 2, 16, 0.55);
  backdrop-filter: blur(4px);
  z-index: 30;
  /* The install banner is fixed to the bottom of the same screen the menu sits
     on. Reserve its height so the panel centres in what is left instead of
     sliding under it — on a short phone it used to bury the Play button. */
  padding-bottom: var(--install-h, 0px);
  transition: padding-bottom 0.2s;
  /* Centring with align-items would clip a panel taller than the screen and
     leave it unreachable; margin:auto on the panel centres it when it fits and
     lets it scroll when it does not. */
  overflow-y: auto;
  overscroll-behavior: contain;
}
#overlay.show { display: flex; }

.panel {
  margin: auto;
  background: rgba(14, 12, 38, 0.92);
  border: 1px solid rgba(120, 140, 255, 0.3);
  border-radius: 20px;
  padding: 36px 44px;
  max-width: min(560px, 92vw);
  text-align: center;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.6), 0 0 60px rgba(80, 60, 220, 0.15);
  animation: pop 0.3s ease-out;
}
@keyframes pop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ------------------------------------------------------ what's new panel */
.panel.wide { max-width: min(680px, 94vw); padding: 28px 30px 24px; }
.news-h1 { font-size: 30px !important; margin-bottom: 14px !important; }
.menu-links {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 4px;
}
.menu-links a {
  color: rgba(190, 205, 255, 0.62);
  font-size: 12.5px;
  text-decoration: none;
  border-bottom: 1px solid rgba(190, 205, 255, 0.25);
}
.menu-links a:hover { color: #ffd166; border-bottom-color: #ffd166; }

.panel button.linkish {
  background: none;
  border: none;
  color: rgba(190, 205, 255, 0.7);
  font-size: 13px;
  padding: 8px 10px;
  margin-top: 10px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.panel button.linkish:hover { background: none; color: #ffd166; transform: none; }
.news-dot {
  background: #ffd166;
  color: #241a00;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-decoration: none;
  margin-left: 4px;
}
.rel-list {
  max-height: min(56vh, 460px);
  overflow-y: auto;
  text-align: left;
  padding-right: 8px;
  margin-bottom: 16px;
}
.rel { padding: 12px 0 4px; border-top: 1px solid rgba(120, 140, 255, 0.16); }
.rel:first-child { border-top: none; }
.rel-head { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.rel-v {
  color: #ffd166;
  font-weight: 800;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.rel-t { color: #dfe6ff; font-weight: 700; font-size: 15px; }
.rel-d { color: rgba(160, 178, 225, 0.65); font-size: 12px; margin-left: auto; }
.rel.latest .rel-v::after {
  content: 'LATEST';
  background: rgba(255, 209, 102, 0.16);
  color: #ffd166;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 10px;
  margin-left: 7px;
  letter-spacing: 0.06em;
}
.promptbox {
  max-height: min(46vh, 380px);
  overflow-y: auto;
  text-align: left;
  background: rgba(4, 3, 16, 0.75);
  border: 1px solid rgba(120, 140, 255, 0.22);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 0 0 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.6;
  color: rgba(206, 219, 255, 0.82);
  white-space: pre-wrap;
  word-break: break-word;
}
.rebuild-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.panel .btnlink {
  display: inline-block;
  background: rgba(40, 44, 90, 0.55);
  border: 1px solid rgba(120, 140, 255, 0.3);
  border-radius: 10px;
  padding: 9px 14px;
  color: #cfd8ff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.panel .btnlink:hover { background: rgba(70, 110, 220, 0.6); color: #fff; }

.rel ul { margin: 7px 0 4px; padding-left: 20px; }
.rel li {
  color: rgba(210, 222, 255, 0.82);
  font-size: 13.5px;
  line-height: 1.62;
  margin-bottom: 5px;
}

.menu-emoji { font-size: 42px; margin-bottom: 4px; }

.panel h1 {
  font-size: 38px;
  background: linear-gradient(90deg, #7ad7ff, #b28bff, #ff7ac8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 6px;
}
.panel h2 { font-size: 28px; margin-bottom: 8px; }
.tagline { color: rgba(200, 214, 255, 0.85); font-size: 15px; margin-bottom: 16px; }
.howto { font-size: 14px; line-height: 1.75; color: rgba(210, 222, 255, 0.8); margin-bottom: 20px; }

.stars { font-size: 40px; color: #ffd166; letter-spacing: 6px; margin: 6px 0 10px; }

.panel button {
  pointer-events: auto;
  cursor: pointer;
  border: 1px solid rgba(120, 200, 255, 0.4);
  background: rgba(40, 60, 140, 0.5);
  color: #eaf3ff;
  font-size: 15px;
  font-weight: 700;
  border-radius: 12px;
  padding: 12px 22px;
  transition: transform 0.1s, background 0.15s;
}
.panel button:hover { background: rgba(70, 110, 220, 0.6); transform: translateY(-1px); }
.panel button.big {
  font-size: 18px;
  padding: 14px 34px;
  background: linear-gradient(90deg, rgba(50, 120, 255, 0.7), rgba(140, 80, 255, 0.7));
  border-color: rgba(160, 200, 255, 0.6);
}
.btn-row { display: flex; gap: 12px; justify-content: center; }

@media (max-width: 640px) {
  #hud { top: 6px; left: 6px; right: 6px; gap: 5px; flex-wrap: wrap; }
  #hud-left, #hud-right { flex-wrap: wrap; gap: 5px; }
  #hud-right { justify-content: flex-end; }
  .pill { font-size: 12px; padding: 6px 10px; }
  /* comfortable thumb targets for every tappable control */
  .btn { font-size: 16px; min-width: 42px; min-height: 38px; }
  #level-label { min-height: 38px; font-size: 13px; }
  #fuel { min-height: 38px; }
  #fuel-track { width: 44px; }
  #hint { font-size: 11px; top: 104px; }
  #toast { top: 150px; font-size: 13px; padding: 8px 14px; }
  #levels-bar { bottom: 6px; gap: 6px; max-width: 98vw; padding: 12px 10px; }
  #set-bar { gap: 6px; flex-wrap: wrap; justify-content: center; }
  .set-btn { padding: 8px 10px; font-size: 9px; min-height: 36px; }
  #set-name { font-size: 10px; }
  #dot-bar { gap: 6px; flex-wrap: wrap; justify-content: center; max-width: 96vw; }
  .level-dot { width: 38px; height: 38px; font-size: 13px; }
  .level-dot.locked { font-size: 11px; }
  .panel { padding: 26px 22px; }
  .panel h1 { font-size: 30px; }
  .howto { font-size: 12px; }
  .panel button { padding: 14px 22px; }
}

/* ------------------------------------------------------------- settings */
.settings { display: flex; flex-direction: column; gap: 8px; margin: 14px 0 4px; }
.setting {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(120, 140, 255, 0.22);
  border-radius: 14px;
  padding: 11px 14px;
  color: #e8ecf8;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.setting:hover { border-color: rgba(120, 200, 255, 0.6); background: rgba(255, 255, 255, 0.07); }
.s-icon { font-size: 19px; line-height: 1; flex: none; }
.s-text { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; flex: 1; }
.s-text b { font-size: 14px; }
.s-text span { font-size: 11.5px; color: rgba(200, 214, 255, 0.65); }
.s-toggle {
  flex: none;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  position: relative;
  transition: background 0.18s;
}
.s-toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #cfd7ee;
  transition: transform 0.18s, background 0.18s;
}
.s-toggle.on { background: linear-gradient(180deg, #6f7dff, #4a56d8); }
.s-toggle.on::after { transform: translateX(18px); background: #fff; }
