:root {
  --space: #0e1322;
  --panel: rgba(18, 24, 40, .82);
  --panel-solid: #151c2e;
  --panel-2: rgba(255, 255, 255, .05);
  --line: rgba(255, 255, 255, .09);
  --ink: #edf0f6;
  --muted: #8a94aa;
  --accent: #ff8a4c;       /* spacesuit orange */
  --accent-ink: #1b1209;
  --tech: #4fd1c5;         /* belts, drones, readouts */
  --warn: #ff6b6b;
  --alien: #7dffb0;
  --r: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--space);
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
html, body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
button { touch-action: manipulation; }
body.building #game { cursor: crosshair; }

.hidden { display: none !important; }

/* Dark visor glass, with a thin bright edge along the top. */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top-color: rgba(255, 255, 255, .16);
  border-radius: var(--r);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .28);
}

/* ---------- left HUD ---------- */
.hud-left {
  position: fixed; top: 16px; left: 16px; z-index: 5;
  display: flex; flex-direction: column; gap: 8px; width: 270px;
}
.hud-main { padding: 14px 16px 12px; }
.credits { display: flex; align-items: baseline; gap: 8px; }
.mb-icon { color: var(--accent); font-size: 16px; transform: translateY(-3px); }
#hud-credits { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.unit { color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .1em; }

.bag { margin-top: 10px; }
.bag-head {
  display: flex; justify-content: space-between;
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600;
}
#hud-bag-text { color: var(--ink); font-variant-numeric: tabular-nums; }
.bagbar {
  position: relative; height: 12px; margin-top: 6px;
  background: rgba(255, 255, 255, .07); border-radius: 3px; overflow: hidden;
}
.bagbar .fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  background: var(--tech); transition: width .15s linear, background .3s;
}
.bagbar .fill.full { background: var(--accent); animation: blink 1s infinite; }
/* Segment cut-outs, like an oxygen gauge. */
.bagbar::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 10px, var(--panel-solid) 10px 12px);
}
@keyframes blink { 50% { opacity: .55; } }

.mini-stats {
  display: flex; gap: 14px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600;
}
.mini-stats b { color: var(--ink); font-weight: 700; margin-left: 3px; }

.mission {
  padding: 10px 14px; text-align: left; font-size: 14px; font-weight: 500;
  display: flex; flex-direction: column; gap: 3px;
}
.mission .count { font-size: 10px; letter-spacing: .16em; color: var(--accent); font-weight: 700; text-transform: uppercase; }
.mission.done { animation: flash .6s ease; }
@keyframes flash { 0% { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 138, 76, .35); } 100% { } }

.broom-chip {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  font-size: 13px; font-weight: 600; text-align: left;
}
.broom-chip #broom-state { flex: 1; }
.broom-chip.up { border-color: rgba(79, 209, 197, .5); color: var(--tech); }
.broom-chip.up .b-ico { transform: rotate(-35deg); }
.b-ico { display: inline-block; transition: transform .2s; }

/* ---------- right HUD ---------- */
/* The buttons in a row, and under them (hud-stack) the top players, the compass and, on phones, the
   radar. Only the panels themselves catch taps, not the gaps between them. */
.hud-right {
  position: fixed; top: 16px; right: 16px; z-index: 5;
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; align-items: stretch; pointer-events: none;
}
.hud-right > * { pointer-events: auto; }
/* Phones only: sound, pause, worlds, help and the account fold into a menu. */
.menu-btn { display: none; }
.sector-chip {
  display: flex; align-items: center; gap: 8px; padding: 0 14px;
  font-size: 12px; letter-spacing: .14em; text-transform: uppercase; font-weight: 600;
}
.sector-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: #ffd27a; box-shadow: 0 0 8px #ffd27a; }
.sector-chip.dark .dot { background: #7f93ff; box-shadow: 0 0 8px #7f93ff; }
.icon-btns { display: flex; padding: 4px; gap: 2px; }
.icon-btns button {
  border: 0; background: transparent; width: 34px; height: 30px; border-radius: 8px;
  font-size: 12px; font-weight: 700; color: var(--muted);
}
.icon-btns button:hover, .icon-btns button.on { background: var(--panel-2); color: var(--ink); }

/* ---------- action button (drive / park / cancel) ---------- */
.action-btn {
  position: fixed; right: 182px; bottom: 16px; z-index: 5;
  display: flex; align-items: center; gap: 10px; padding: 12px 18px;
  font-size: 15px; font-weight: 700; color: var(--accent-ink);
  background: var(--accent); border-color: rgba(255, 255, 255, .25);
}
.action-btn .key { color: rgba(27, 18, 9, .6); border-color: rgba(27, 18, 9, .25); }

/* The thumb-stick: where a finger came down on the ground, and how far it has pushed. */
.stick {
  position: fixed; left: 0; top: 0; width: 112px; height: 112px; margin: -56px 0 0 -56px; z-index: 3;
  border-radius: 50%; pointer-events: none;
  border: 2px solid rgba(255, 255, 255, .35); background: rgba(14, 19, 34, .16);
}
.stick i {
  position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border-radius: 50%; background: rgba(255, 255, 255, .6); box-shadow: 0 2px 10px rgba(0, 0, 0, .3);
}

/* Touch screens: no keyboard hints. */
body.touch .key, body.touch .t-key { display: none; }
body.touch .tool { grid-template-columns: 1fr; }

/* ---------- station panel ---------- */
.station-panel {
  position: fixed; right: 16px; top: 64px; width: 330px; z-index: 6; padding: 14px 16px 16px;
  display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 200px); overflow-y: auto;
}
.sp-head { display: flex; justify-content: space-between; align-items: flex-start; }
.sp-head h3 { margin: 2px 0 0; font-size: 17px; font-weight: 700; }
.station-panel .stats dd.ok { color: var(--tech); }
.station-panel .stats dd.warn { color: #ffb37a; }
.sp-mods { display: flex; flex-direction: column; gap: 8px; }
.sp-mod {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 10px; align-items: center;
  padding: 8px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line);
}
.sp-mod img { width: 48px; height: 48px; object-fit: contain; }
.sp-mod b { display: block; font-size: 13px; }
.sp-mod span { display: block; font-size: 11px; color: var(--muted); line-height: 1.35; }
.sp-mod button {
  border: 0; border-radius: 8px; padding: 8px 10px; font-weight: 700; font-size: 12px;
  background: var(--accent); color: var(--accent-ink); white-space: nowrap;
}
.sp-mod button:disabled { background: rgba(255, 255, 255, .07); color: var(--muted); cursor: not-allowed; }
.sp-full { margin: 0; font-size: 12px; color: var(--tech); }
.lab-parts { font-size: 13px; font-weight: 600; color: var(--alien); }
/* The book: every find as a card, a ghost until found; a pink dot means a scanner marked it. */
.book-panel { width: 360px; }
.book-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.find {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px 7px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line);
}
.find img { width: 52px; height: 52px; }
.find span { font-size: 10.5px; line-height: 1.2; text-align: center; color: var(--muted); min-height: 2.4em; }
.find.got { border-color: rgba(255, 143, 216, .35); }
.find.got span { color: var(--ink); font-weight: 600; }
.find em { display: block; font-style: normal; font-size: 10px; color: var(--muted); }
.region-map { grid-column: 1 / -1; width: 100%; aspect-ratio: 1; }
.region-next { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--muted); text-align: center; }
.region-next b { color: var(--ink); }
.book-tabs { display: flex; gap: 6px; }
.book-tabs button {
  flex: 1; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: transparent;
  color: var(--muted); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer;
}
.book-tabs button.on { background: var(--panel-2); color: var(--ink); border-color: rgba(255, 143, 216, .35); }
.find i { position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: #ff8fd8; box-shadow: 0 0 8px #ff8fd8; }
.lab-list { display: flex; flex-direction: column; gap: 8px; }
.lab-item {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  padding: 9px 10px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line);
}
.lab-item b { display: block; font-size: 13px; }
.lab-item span { display: block; font-size: 11px; color: var(--muted); line-height: 1.35; margin-top: 2px; }
.lab-item .tier-bar { margin-top: 6px; }
.lab-item.done { opacity: .7; }
.lab-item button {
  border: 0; border-radius: 8px; padding: 8px 10px; font-weight: 700; font-size: 12px; white-space: nowrap;
  background: var(--alien); color: #0b1a12;
}
.lab-item button:disabled { background: rgba(255, 255, 255, .07); color: var(--muted); cursor: not-allowed; }
.lab-done { font-size: 12px; font-weight: 700; color: var(--alien); }

/* ---------- account ---------- */
.account-chip {
  display: flex; align-items: center; gap: 8px; padding: 0 14px; border: 1px solid var(--line);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.account-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.account-chip.signed .dot { background: var(--tech); box-shadow: 0 0 8px var(--tech); }
.account-chip.error .dot { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.account-chip:hover { border-color: rgba(79, 209, 197, .5); }
.auth-card label { display: block; margin-top: 12px; font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.auth-card input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 9px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .05); color: var(--ink);
  font: 500 16px "Space Grotesk", sans-serif; outline: none;
}
.auth-card input:focus { border-color: var(--tech); }
.auth-tabs { display: flex; gap: 4px; margin-top: 14px; padding: 3px; background: var(--panel-2); border-radius: 9px; }
.auth-tabs button { flex: 1; border: 0; background: transparent; padding: 7px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); }
.auth-tabs button.on { background: rgba(255, 255, 255, .09); color: var(--ink); }
.auth-error { min-height: 18px; margin-top: 10px; font-size: 13px; color: var(--warn); }
.auth-note { font-size: 12px; line-height: 1.5; color: var(--muted); margin: 4px 0 16px; }
.auth-actions { display: flex; justify-content: flex-end; gap: 8px; }
.acct-display { display: flex; gap: 6px; margin-top: 6px; }
.acct-display input { margin-top: 0; flex: 1; }
.acct-display button { white-space: nowrap; border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 9px; padding: 0 14px; font-weight: 600; }
.auth-actions .primary { float: none; }
.auth-actions .ghost { border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 9px; padding: 11px 16px; font-weight: 600; }
.auth-actions button:disabled { opacity: .5; cursor: wait; }
.auth-newgame {
  display: block; margin: 14px auto 0; border: 0; background: none; padding: 4px 8px;
  font-size: 12px; font-weight: 600; color: var(--muted); text-decoration: underline; text-underline-offset: 3px;
}
.auth-newgame:hover { color: var(--ink); }
.auth-newgame.confirm { color: var(--warn); text-decoration: none; }

/* ---------- toasts / prompt ---------- */
#toasts {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 6; pointer-events: none;
}
.toast {
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(10px);
  border-radius: 8px; padding: 8px 14px 8px 12px; font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
  animation: toast-in .25s ease;
}
.toast::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }
.toast.alien { color: var(--alien); border-color: rgba(125, 255, 176, .3); }
.toast.find { color: #ff8fd8; border-color: rgba(255, 143, 216, .3); }
.toast.badge { color: #ffd27a; border-color: rgba(255, 210, 122, .3); }
.toast.badge::before { background: #ffd27a; box-shadow: 0 0 8px #ffd27a; }
.toast.find::before { background: #ff8fd8; box-shadow: 0 0 8px #ff8fd8; }
.toast.alien::before { background: var(--alien); box-shadow: 0 0 8px var(--alien); }
.toast.out { opacity: 0; transform: translateY(-6px); transition: all .4s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.prompt {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%);
  background: rgba(255, 138, 76, .95); color: var(--accent-ink); border-radius: 6px;
  padding: 7px 14px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; z-index: 4;
  pointer-events: none;
}

/* ---------- bottom controls ---------- */
.dock-row { position: fixed; left: 16px; bottom: 16px; z-index: 4; display: flex; gap: 8px; }
.dock-btn {
  position: relative; display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  font-size: 15px; font-weight: 600;
}
.dock-btn:hover { border-color: rgba(255, 138, 76, .5); }
.dock-btn .ico { color: var(--accent); font-size: 18px; }
.key, .t-key {
  font-size: 10px; font-weight: 700; color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px;
}
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 7px; }

.buildbar {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 4;
  display: flex; gap: 4px; padding: 5px;
}
.tool {
  border: 1px solid transparent; background: transparent; border-radius: 9px;
  padding: 7px 12px; display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center;
  min-width: 140px; text-align: left;
}
.tool .t-key { grid-row: span 2; }
.tool:hover { background: var(--panel-2); }
.tool.on { background: rgba(79, 209, 197, .14); border-color: rgba(79, 209, 197, .5); }
.tool:disabled { opacity: .35; cursor: not-allowed; }
.t-name { font-size: 13px; font-weight: 600; white-space: nowrap; }
.t-cost { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* Round radar, drawn at the same angle as the view. */
.radar {
  position: fixed; right: 16px; bottom: 16px; width: 150px; height: 150px; z-index: 4;
  border-radius: 50%; overflow: hidden; background: #0b1020;
  border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
#minimap { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .9; }

.eyebrow { font-size: 10px; letter-spacing: .18em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.modal h2 { margin: 2px 0 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }

/* ---------- tier progress (HUD + store) ---------- */
.tier-badge {
  display: inline-grid; place-items: center; min-width: 26px; height: 20px; padding: 0 6px;
  border-radius: 5px; background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 700; letter-spacing: .04em; white-space: nowrap;
}
.tier-badge.locked { background: rgba(255, 255, 255, .1); color: var(--muted); }
.tier-bar { position: relative; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.tier-bar .fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--accent), #ffd27a); transition: width .3s; }
.tier-mini { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.tier-mini .tier-bar { flex: 1; }
.tier-text { margin-top: 5px; font-size: 11px; color: var(--muted); }
.tier-text b { color: var(--ink); font-weight: 600; }

/* ---------- store ---------- */
.store {
  position: fixed; inset: 0; z-index: 8; display: grid; place-items: center;
  background: rgba(5, 8, 16, .55); backdrop-filter: blur(3px);
}
.store-card {
  width: min(1060px, calc(100vw - 32px)); height: min(720px, calc(100vh - 32px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--panel-solid); border: 1px solid var(--line); border-top: 3px solid var(--accent);
  border-radius: 16px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.store-head { display: flex; align-items: center; gap: 22px; padding: 18px 22px 12px; }
/* Close button pinned to the card's top-right corner, whatever the header holds. */
.store-card { position: relative; }
.store-head { padding-right: 64px; }
#store-close { position: absolute; top: 14px; right: 14px; }
.store-title h2 { margin: 2px 0 0; font-size: 24px; font-weight: 700; }
.tier-box { flex: 1; max-width: 360px; margin-left: auto; }
.tier-row { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.tier-sub { font-size: 11px; color: var(--muted); margin-top: 5px; }
.store-credits { display: flex; align-items: baseline; gap: 6px; }
.store-credits #store-credits { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.close { border: 0; background: var(--panel-2); width: 32px; height: 32px; border-radius: 8px; font-size: 18px; line-height: 1; flex: none; }

.tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab {
  border: 0; background: transparent; padding: 10px 14px; font-size: 14px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.on { color: var(--ink); border-bottom-color: var(--accent); }
.tab .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

.store-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 330px; }
.grid {
  overflow-y: auto; padding: 16px 18px; display: grid; gap: 10px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.item {
  position: relative; border: 1px solid var(--line); background: var(--panel-2); border-radius: 12px;
  padding: 10px 10px 12px; text-align: left; display: flex; flex-direction: column; gap: 6px;
}
.item:hover { border-color: rgba(255, 255, 255, .22); }
.item.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.item img {
  width: 100%; aspect-ratio: 1.35; object-fit: contain; border-radius: 8px;
  background: radial-gradient(circle at 50% 60%, rgba(255, 255, 255, .09), rgba(255, 255, 255, .02) 70%);
}
.item.locked img { filter: grayscale(1) brightness(.55); }
.item .i-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.item .i-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 11px; color: var(--muted); }
.item .i-meta .ok { color: var(--tech); font-weight: 600; }
.item .i-meta .price { color: var(--ink); font-weight: 600; }
.item .i-meta .price.short { color: var(--warn); }
.item .lock { position: absolute; top: 14px; right: 14px; font-size: 13px; }
/* Station upgrades are add-ons to a station, not buildings of their own. */
.item .upg {
  position: absolute; top: 10px; left: 10px; padding: 2px 7px; border-radius: 999px;
  font-size: 9px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  background: rgba(79, 209, 197, .16); color: var(--tech); border: 1px solid rgba(79, 209, 197, .35);
}
.preview .kicker { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--tech); }
.item .pips { display: flex; gap: 3px; }
.pip { width: 8px; height: 8px; border-radius: 2px; background: rgba(255, 255, 255, .12); transform: rotate(45deg) scale(.75); }
.pip.on { background: var(--accent); }

.preview { border-left: 1px solid var(--line); padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.preview .big {
  width: 100%; aspect-ratio: 1.3; object-fit: contain; border-radius: 12px;
  background: radial-gradient(circle at 50% 62%, rgba(255, 138, 76, .12), rgba(255, 255, 255, .02) 70%);
}
.preview.locked .big { filter: grayscale(1) brightness(.6); }
.preview h3 { margin: 0; font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.preview .desc { margin: 0; font-size: 13px; color: #c9cfdb; line-height: 1.5; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 12px; }
.stats dt { color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 10px; font-weight: 600; align-self: center; }
.stats dd { margin: 0; font-weight: 600; }
.stats .up { color: var(--tech); }
.actions { display: flex; gap: 8px; margin-top: auto; }
.actions button {
  flex: 1; border: 0; border-radius: 10px; padding: 12px 14px; font-weight: 700; font-size: 14px;
  background: var(--accent); color: var(--accent-ink);
}
.actions button.ghost { background: transparent; color: var(--tech); border: 1px solid rgba(79, 209, 197, .5); }
.actions button:disabled { background: rgba(255, 255, 255, .07); color: var(--muted); border-color: transparent; cursor: not-allowed; }
.why { font-size: 12px; color: var(--muted); line-height: 1.4; }
.why b { color: var(--accent); }
.dock-note { margin: 0; padding: 8px 22px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.dock-note.ok { color: var(--tech); font-weight: 600; }
.dock-note.away { background: rgba(255, 138, 76, .14); color: #ffb37a; font-weight: 600; }

/* ---------- debug console (` key) ---------- */
.debug {
  position: fixed; top: 0; left: 16px; right: 16px; height: min(46vh, 420px); z-index: 10;
  display: flex; flex-direction: column;
  background: rgba(8, 11, 20, .94); border: 1px solid var(--line); border-top: 0;
  border-radius: 0 0 12px 12px; box-shadow: 0 20px 50px rgba(0, 0, 0, .45);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  animation: drop .15s ease-out;
}
@keyframes drop { from { transform: translateY(-30px); opacity: 0; } }
.debug-head { display: flex; align-items: center; gap: 14px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.debug-title { color: var(--accent); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: 11px; }
.debug-stats { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.debug .close { width: 26px; height: 26px; font-size: 15px; }
.debug-actions { display: flex; flex-wrap: wrap; gap: 5px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.debug-actions button {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); border-radius: 6px;
  padding: 3px 9px; font: inherit; font-size: 11px;
}
.debug-actions button:hover { border-color: var(--tech); color: var(--tech); }
.debug-log { flex: 1; overflow-y: auto; padding: 8px 12px; }
.debug-log div { white-space: pre-wrap; word-break: break-word; }
.debug-log .cmd { color: var(--ink); }
.debug-log .cmd::before { content: "› "; color: var(--accent); }
.debug-log .ok { color: var(--tech); }
.debug-log .err { color: var(--warn); }
.debug-log .info { color: var(--muted); }
.debug-input { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); }
.debug-input span { color: var(--accent); font-weight: 700; }
.debug-input input { flex: 1; background: transparent; border: 0; outline: 0; color: var(--ink); font: inherit; font-size: 13px; }
.debug-overlay {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 6; pointer-events: none;
  background: rgba(8, 11, 20, .8); color: var(--tech); border-radius: 6px; padding: 4px 10px;
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(5, 8, 16, .55); z-index: 9;
  display: grid; place-items: center; backdrop-filter: blur(3px);
}
.modal-card {
  width: min(460px, calc(100vw - 32px)); background: var(--panel-solid); border: 1px solid var(--line);
  border-top: 3px solid var(--accent); border-radius: 14px;
  padding: 24px 26px 20px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.modal.alien .modal-card { border-top-color: var(--alien); background: #0f1a1c; color: #d6f5e4; }
.modal.alien .eyebrow { color: var(--alien); }
.modal.alien .primary { background: var(--alien); color: #0b1a12; }
#modal-body { font-size: 15px; line-height: 1.55; margin: 12px 0 18px; color: #c9cfdb; }
#modal-body p { margin: 0 0 10px; }
#modal-body a { color: var(--tech); }
#modal-body kbd {
  display: inline-block; min-width: 22px; text-align: center; padding: 1px 6px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
  background: var(--panel-2); color: var(--ink); font: 700 11px "Space Grotesk", sans-serif;
}
.primary {
  border: 0; border-radius: 9px; padding: 11px 18px; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 14px; float: right;
}
.modal-card::after { content: ""; display: block; clear: both; }

@media (max-width: 900px) {
  .hud-left { width: 220px; }
  .sector-chip { display: none; }
  .store-body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .preview {
    border-left: 0; border-top: 1px solid var(--line); max-height: 300px;
    display: grid; grid-template-columns: 120px 1fr; column-gap: 14px; align-content: start;
  }
  .preview .big { grid-row: span 3; width: 120px; }
  .preview > :not(.big) { grid-column: 2; }
  .tier-box { display: none; }
  .radar { display: none; }
  .tool { min-width: 0; }
  /* Stack the build bar above the upgrades button instead of overlapping it. */
  .buildbar { bottom: 78px; left: 16px; transform: none; }
  .prompt { bottom: 150px; }
}

/* ---------- phones: a small HUD that keeps the ground visible ----------
   Top left, one slim card (money, bag, tier) over the mission; tapping the card folds the mission,
   the radar and the region away (body.hud-min). Top right, a menu button (sound, pause, worlds, help,
   account) over the radar, with the region you are in as its caption. Thumbs work the bottom
   corners: the store and the book on the left, the broom and the action button as round buttons on
   the right. Panels and pop-ups come up from the bottom as sheets, and the store fills the screen. */
@media (max-width: 700px), (max-height: 520px) {
  :root {
    --safe-t: max(8px, env(safe-area-inset-top)); --safe-l: max(8px, env(safe-area-inset-left));
    --safe-r: max(12px, env(safe-area-inset-right)); --safe-b: max(12px, env(safe-area-inset-bottom));
    --thumb: 58px; --radar: 96px;
  }
  .hud-left { top: var(--safe-t); left: var(--safe-l); width: 186px; gap: 5px; }
  .hud-main {
    display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; column-gap: 8px;
    padding: 6px 8px 6px 10px; cursor: pointer;
  }
  .credits { gap: 4px; line-height: 1; }
  #hud-credits { font-size: 17px; }
  .credits .mb-icon { font-size: 12px; transform: translateY(-1px); }
  .credits .unit { display: none; }
  /* Money, bag count, tier and the fold arrow on one row; the bag bar in a thin line under them. */
  .credits { grid-area: 1 / 1; }
  .bag { display: contents; }
  #bag-label { display: none; }
  .bag-head { grid-area: 1 / 2; justify-self: end; font-size: 10px; letter-spacing: 0; }
  .bagbar { grid-area: 2 / 1 / 3 / -1; height: 6px; margin-top: 5px; }
  .tier-mini { grid-area: 1 / 3; margin: 0; }
  .tier-mini .tier-bar, .tier-text, .mini-stats { display: none; }
  .tier-mini .tier-badge { min-width: 22px; height: 17px; padding: 0 4px; font-size: 10px; }
  /* Which way a tap on the card goes: fold away, or open up again. */
  .hud-main::after { content: "▴"; grid-area: 1 / 4; font-size: 10px; color: var(--muted); }
  body.hud-min .hud-main::after { content: "▾"; }
  .mission { padding: 6px 10px; font-size: 12px; line-height: 1.3; }
  .mission .count { display: none; }
  .mission span:last-child { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  body.hud-min .mission, body.hud-min .hud-stack, body.hud-min .sector-chip { display: none !important; }

  /* Round thumb buttons, bottom right: the broom, and above it whatever E does just now. */
  .broom-chip {
    position: fixed; right: var(--safe-r); bottom: var(--safe-b); z-index: 5;
    width: var(--thumb); height: var(--thumb); padding: 0; border-radius: 50%; justify-content: center;
  }
  .broom-chip #broom-state { display: none; }
  .broom-chip .b-ico { font-size: 25px; }
  .broom-chip.up { background: rgba(79, 209, 197, .22); }
  .action-btn {
    right: var(--safe-r); bottom: calc(var(--safe-b) + var(--thumb) + 10px);
    width: var(--thumb); height: var(--thumb); padding: 0; border-radius: 50%; justify-content: center;
    font-size: 12px; line-height: 1.1; text-align: center;
  }

  .hud-right { top: var(--safe-t); right: var(--safe-l); gap: 6px; flex-direction: column; align-items: flex-end; flex-wrap: nowrap; }
  .menu-btn { display: grid; place-items: center; order: -1; width: 38px; height: 38px; padding: 0; font-size: 20px; line-height: 1; }
  body.menu-open .menu-btn { border-color: var(--accent); color: var(--accent); }
  /* The menu drops down over the radar. */
  .icon-btns, .account-chip { display: none; }
  body.menu-open .icon-btns, body.menu-open .account-chip { display: flex; position: absolute; right: 0; z-index: 2; }
  body.menu-open .icon-btns { top: 44px; }
  body.menu-open .account-chip { top: 92px; height: 38px; }
  body.menu-open .hud-stack, body.menu-open .sector-chip { visibility: hidden; }
  .icon-btns button { width: 38px; height: 36px; font-size: 14px; }
  .account-chip { padding: 0 12px; max-width: 170px; overflow: hidden; text-overflow: ellipsis; }
  .hud-right > .hud-stack { order: 1; flex-basis: auto; }
  .hud-stack .leaders, .hud-stack .compass { display: none; }
  .radar { display: block; position: relative; right: auto; bottom: auto; width: var(--radar); height: var(--radar); }
  /* The region you are in, as the radar's caption. */
  .sector-chip {
    display: flex; order: 2; width: var(--radar); justify-content: center; text-align: center;
    padding: 4px 6px; border-radius: 8px; font-size: 9px; letter-spacing: .06em; line-height: 1.25;
  }
  .sector-chip .dot { display: none; }

  .dock-row { left: var(--safe-l); bottom: var(--safe-b); gap: 6px; }
  .dock-btn { gap: 7px; padding: 9px 12px; font-size: 13px; }
  .dock-btn .ico { font-size: 15px; }
  .buildbar { left: var(--safe-l); right: calc(var(--safe-r) + var(--thumb) + 8px); bottom: calc(var(--safe-b) + 56px); transform: none; }
  .tool { flex: 1; min-width: 0; padding: 6px 8px; }
  .t-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
  .t-cost { font-size: 10px; }
  .prompt {
    bottom: calc(var(--safe-b) + 58px); max-width: calc(100vw - 2 * var(--thumb) - 48px);
    white-space: normal; text-align: center; font-size: 11px;
  }
  .buildbar:not(.hidden) ~ .prompt { bottom: calc(var(--safe-b) + 112px); }
  /* Messages come up above the thumbs, not over the HUD. */
  #toasts { top: auto; bottom: calc(var(--safe-b) + 150px); width: calc(100vw - 2 * var(--thumb) - 48px); }
  .toast { font-size: 12px; }

  .close { width: 40px; height: 40px; }
  .station-panel {
    left: 0; right: 0; top: auto; bottom: 0; width: auto; z-index: 7;
    max-height: 72vh; max-height: 72dvh; border-radius: 18px 18px 0 0; border-bottom: 0;
    padding: 16px max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  .modal { place-items: end stretch; }
  .modal-card {
    width: auto; max-height: 90vh; max-height: 90dvh; overflow-y: auto; border-radius: 18px 18px 0 0;
    padding: 20px max(20px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  }
  #modal-ok { float: none; display: block; width: 100%; padding: 14px; font-size: 15px; }
  .auth-actions button { flex: 1; padding: 13px 10px; }
  /* Signing in stays at the top, clear of the keyboard. */
  #auth { place-items: start stretch; }
  #auth .modal-card { border-radius: 0 0 18px 18px; padding-top: calc(18px + env(safe-area-inset-top)); }

  .store { place-items: stretch; }
  .store-card {
    width: auto; height: 100vh; height: 100dvh; border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  #store-close { top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); }
  .store-head { padding: 12px 60px 8px 14px; gap: 12px; }
  .store-title h2 { font-size: 18px; }
  .preview { max-height: 45vh; max-height: 45dvh; }
  .actions button { padding: 14px; font-size: 15px; }
}
/* Phone held sideways: little height. The left column stays short, panels open at the side and the
   store keeps its item details beside the list. */
@media (max-height: 520px) {
  :root { --thumb: 54px; --radar: 80px; }
  #toasts { bottom: calc(var(--safe-b) + 128px); }
  .station-panel {
    left: auto; top: 0; width: min(380px, 60vw); max-height: none; border-radius: 18px 0 0 18px; border-bottom: 1px solid var(--line);
    padding-top: calc(14px + env(safe-area-inset-top)); padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .modal { place-items: center; }
  .modal-card { width: min(460px, calc(100vw - 32px)); border-radius: 14px; max-height: calc(100dvh - 16px); padding: 18px 22px 16px; }
  #auth { place-items: start center; }
  #auth .modal-card { border-radius: 0 0 14px 14px; padding-top: calc(14px + env(safe-area-inset-top)); }
  .store-body { grid-template-columns: 1fr minmax(240px, 38%); grid-template-rows: 1fr; }
  .preview { display: flex; flex-direction: column; max-height: none; border-top: 0; border-left: 1px solid var(--line); padding: 12px 14px; }
  .preview .big { width: 100%; max-height: 90px; }
}

/* ---------- world picker ---------- */
.worlds {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 50% 20%, #1c2540, #0a0e1a 70%);
}
.worlds-card { position: relative; width: min(980px, 100%); max-height: 100%; overflow: auto; padding: 8px 4px; }
.worlds-card .close { position: absolute; top: 4px; right: 4px; }
.worlds-head { text-align: center; margin: 4px 0 22px; }
.worlds-logo { font-size: 46px; font-weight: 700; letter-spacing: -.03em; }
.worlds-logo::first-letter { color: var(--accent); }
.worlds-head p { margin: 4px 0 0; color: var(--muted); }
.worlds-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.world {
  display: flex; flex-direction: column; text-align: left; padding: 0; overflow: hidden; cursor: pointer;
  border-radius: 18px; border: 1px solid var(--line); background: var(--panel-solid); color: inherit; font: inherit;
  transition: transform .15s, border-color .15s;
}
.world:hover { transform: translateY(-3px); border-color: rgba(255, 255, 255, .25); }
.world.here { border-color: var(--accent); }
.world-art { position: relative; display: block; height: 150px; overflow: hidden; }
.world-text { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px 6px; }
.world-name { font-size: 20px; font-weight: 700; }
.world-blurb { font-size: 13px; color: var(--muted); line-height: 1.4; }
.world-status { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; color: var(--tech); }
.world-go { margin: 8px 16px 16px; align-self: flex-start; padding: 9px 14px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 13px; }

/* Little dioramas of each world, in CSS. */
.world.moon .world-art {
  background:
    radial-gradient(circle at 72% 34%, #e8e5dc 0 15%, transparent 15.5%),
    radial-gradient(circle at 66% 30%, rgba(0,0,0,.08) 0 4%, transparent 4.5%),
    radial-gradient(1px 1px at 20% 30%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 40% 15%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 85% 70%, #fff 50%, transparent 51%), radial-gradient(1.5px 1.5px at 12% 65%, #fff 50%, transparent 51%),
    linear-gradient(#0a0f1e, #26304f);
}
.world.moon .world-art::after {
  content: ''; position: absolute; left: -10%; right: -10%; bottom: -40px; height: 90px; border-radius: 50%;
  background: linear-gradient(#cfccc2, #9d9a91);
}
.world.desert .world-art { background: radial-gradient(circle at 80% 26%, #fff6d8 0 9%, rgba(255,240,200,.5) 10%, transparent 24%), linear-gradient(#78aee0, #f3dcae 85%); }
.world.desert .world-art::before {
  content: ''; position: absolute; left: 22%; bottom: 34px; width: 120px; height: 84px;
  background: linear-gradient(90deg, #e8b974 50%, #c48c4a 50%); clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.world.desert .world-art::after {
  content: ''; position: absolute; left: -10%; right: -10%; bottom: -46px; height: 96px; border-radius: 50% 50% 0 0;
  background: linear-gradient(#e2b56c, #c98f48);
}
.world.sea .world-art {
  background:
    repeating-linear-gradient(105deg, rgba(160,240,255,.10) 0 14px, transparent 14px 48px),
    radial-gradient(3px 3px at 30% 40%, rgba(255,255,255,.5) 50%, transparent 51%), radial-gradient(2px 2px at 34% 26%, rgba(255,255,255,.4) 50%, transparent 51%),
    linear-gradient(#1b7f99, #062638);
}
.world.sea .world-art::before {
  content: ''; position: absolute; left: 50%; bottom: 30px; width: 110px; height: 55px; transform: translateX(-50%);
  border-radius: 110px 110px 0 0; background: radial-gradient(circle at 50% 100%, rgba(111,231,255,.9), rgba(90,225,255,.15) 70%);
  box-shadow: 0 0 40px rgba(90,225,255,.5);
}
.world.sea .world-art::after {
  content: ''; position: absolute; left: -10%; right: -10%; bottom: -46px; height: 90px; border-radius: 50% 50% 0 0;
  background: linear-gradient(#a7a586, #6f7a72);
}
@media (max-width: 760px) {
  .worlds { place-items: start center; }
  .worlds-list { grid-template-columns: 1fr; }
  .world { flex-direction: row; align-items: stretch; }
  .world-art { width: 110px; height: auto; flex: none; }
  .world-go { display: none; }
  .worlds-logo { font-size: 36px; }
  .world.desert .world-art::before { left: 10px; width: 80px; height: 56px; }
  .world.sea .world-art::before { width: 80px; height: 40px; }
}

.modal .small { font-size: 12px; opacity: .7; }

/* Under the buttons: the top players, then the compass (north is up on screen). */
.hud-right > .hud-stack {
  flex-basis: 100%; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none;
}
.hud-stack > * { pointer-events: auto; }
.compass { width: 70px; height: 70px; padding: 0; border-radius: 50%; display: grid; place-items: center; }
.compass canvas { width: 70px; height: 70px; }
.leaders { width: 200px; padding: 10px 12px 8px; }
.leaders ol { list-style: none; margin: 6px 0 0; padding: 0; }
.leaders li { display: grid; grid-template-columns: 16px 1fr auto; gap: 6px; align-items: baseline; padding: 3px 0; font-size: 12px; }
.leaders li span { color: var(--muted); font-weight: 700; font-size: 11px; }
.leaders li b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaders li em { font-style: normal; font-variant-numeric: tabular-nums; color: var(--muted); }
.leaders li.me b, .leaders li.me em { color: var(--accent); }
.leaders li.sep { margin-top: 4px; padding-top: 6px; border-top: 1px solid var(--line); }
.leaders li.empty { display: block; color: var(--muted); }

/* A white flash while stepping through a portal. */
#flash { position: fixed; inset: 0; z-index: 20; pointer-events: none; background: #fff; opacity: 0; }
#flash.on { animation: flash .7s ease-out; }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }
