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

:root {
  --bg: #0a0c10;
  --panel: #14181e;
  --ink: #e8ecef;
  --muted: #7a8490;
  --rr-body: #2a2e32;
  --rr-hi: #4a5058;
  --nest: #c9a66b;
  --nest-dk: #8a6b3f;
  --amber: #ffb000;
  --green: #40d878;
  --red: #ff4040;
  --sky: #1a2744;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Press Start 2P", monospace;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  padding: calc(8px + var(--safe-t)) calc(8px + var(--safe-r))
    calc(8px + var(--safe-b)) calc(8px + var(--safe-l));
  gap: 8px;
}

.top {
  text-align: center;
  flex: 0 0 auto;
}

.top h1 {
  margin: 0;
  font-size: clamp(10px, 2.8vw, 16px);
  letter-spacing: 0.08em;
  color: var(--ink);
}

.top .sub {
  margin: 6px 0 0;
  font-size: clamp(6px, 1.6vw, 8px);
  color: var(--muted);
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #05070a;
  border: 3px solid var(--rr-hi);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px #000, 0 0 0 1px #000;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--sky);
}

.hud {
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  font-size: clamp(6px, 1.5vw, 8px);
  text-shadow: 1px 1px 0 #000;
  z-index: 2;
}

.hud-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: baseline;
}

.hud .label {
  color: var(--muted);
  margin-right: 4px;
}

.fuel-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fuel-bar {
  flex: 1 1 auto;
  height: 10px;
  background: #1a1e24;
  border: 2px solid var(--rr-hi);
  image-rendering: pixelated;
}

#fuel-fill {
  height: 100%;
  width: 100%;
  background: var(--green);
  transform-origin: left center;
  transform: scaleX(1);
}

#fuel-fill.warn {
  background: var(--amber);
}

#fuel-fill.crit {
  background: var(--red);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 10, 0.78);
  z-index: 5;
  padding: 12px;
}

.overlay[hidden] {
  display: none;
}

.card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 3px solid var(--nest);
  padding: 18px 14px;
  text-align: center;
  box-shadow: 4px 4px 0 #000;
}

.card h2 {
  margin: 0 0 10px;
  font-size: clamp(10px, 3vw, 14px);
  color: var(--nest);
  line-height: 1.4;
}

.card p {
  margin: 0 0 10px;
  font-size: clamp(7px, 2vw, 9px);
  line-height: 1.7;
  color: var(--ink);
}

.card .extra {
  color: var(--amber);
  min-height: 1.4em;
}

.btns {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 14px 0 8px;
}

.btn {
  font-family: inherit;
  font-size: clamp(8px, 2.2vw, 10px);
  padding: 12px 16px;
  min-width: 110px;
  min-height: 44px;
  color: #0a0c10;
  background: var(--nest);
  border: 3px solid var(--nest-dk);
  box-shadow: 3px 3px 0 #000;
  cursor: pointer;
}

.btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #000;
}

.btn-expert {
  background: var(--amber);
  border-color: #a07000;
}

.btn-ghost {
  background: var(--rr-hi);
  border-color: #2a2e32;
  color: var(--ink);
}

.hint {
  margin-top: 8px;
  font-size: clamp(5px, 1.4vw, 7px);
  color: var(--muted);
  line-height: 1.6;
}

.mobile-hint {
  display: none;
}

.touch {
  display: none;
  flex: 0 0 auto;
  gap: 10px;
  padding: 4px 0 0;
  justify-content: space-between;
}

.tbtn {
  flex: 1 1 0;
  min-height: 56px;
  font-family: inherit;
  font-size: 18px;
  color: var(--ink);
  background: var(--rr-body);
  border: 3px solid var(--rr-hi);
  box-shadow: 2px 2px 0 #000;
  cursor: pointer;
  touch-action: none;
}

.tbtn:active,
.tbtn.held {
  background: var(--rr-hi);
  color: var(--amber);
}

.t-thrust {
  flex: 1.4 1 0;
  background: #243028;
  border-color: #3a6050;
}

.foot {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: clamp(5px, 1.3vw, 7px);
  color: var(--muted);
  line-height: 1.4;
}

@media (max-width: 720px), (pointer: coarse) {
  .desktop-hint {
    display: none;
  }
  .mobile-hint {
    display: block;
  }
  .touch {
    display: flex;
  }
  .top .sub {
    display: none;
  }
}

@media (max-height: 520px) {
  .top {
    display: none;
  }
  .foot {
    display: none;
  }
}
