:root {
  --bg: #15110e;
  --panel: #231c16;
  --panel-2: #2e251d;
  --line: #43372b;
  --text: #f3eadf;
  --muted: #b5a797;
  --accent: #ffb547;
  --good: #5fd35f;
  --bad: #e8483a;
  --fuel: #f0a830;
  --hull: #4fb3e8;
  --radius: 10px;
  --header-h: 48px;
  --hud-h: 44px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}


.page {
  padding: 8px 8px 40px;
}

.game-root {
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: 1100px;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

.hud {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--hud-h);
  padding: 0 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.hud-cell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.1;
}

.hud-cell .lbl {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.hud-cell.cash span:last-child {
  color: var(--accent);
}

.hud-cell.meter {
  width: 110px;
}

.bar {
  height: 10px;
  background: #0d0a08;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 3px;
}

.bar.thin {
  height: 6px;
}

.bar-fill {
  height: 100%;
  width: 0;
  transition: width 0.15s linear;
}

.bar-fill.fuel {
  background: linear-gradient(90deg, #d97b1c, var(--fuel));
}

.bar-fill.hull {
  background: linear-gradient(90deg, #2a78b8, var(--hull));
}

.bar-fill.low {
  background: var(--bad);
  animation: blink 0.6s steps(2) infinite;
}

.bar-fill.goal-fill {
  background: linear-gradient(90deg, #5fd35f, #b8f56a);
}

@keyframes blink {
  50% {
    opacity: 0.35;
  }
}

.hud-spacer {
  flex: 1;
}

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 700;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  color: #1b1108;
  border-color: var(--accent);
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
}

/* ---------- Stage ---------- */

.stage {
  position: relative;
  width: 100%;
  height: clamp(360px, calc(100vh - var(--header-h) - var(--hud-h) - 28px), 820px);
  height: clamp(360px, calc(100dvh - var(--header-h) - var(--hud-h) - 28px), 820px);
  background: #17110d;
  touch-action: none;
}

.stage #game {
  display: block;
  width: 100%;
  height: 100%;
}

.goal {
  position: absolute;
  top: 8px;
  left: 8px;
  width: min(300px, 60%);
  padding: 6px 8px;
  background: rgba(20, 15, 11, 0.78);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  pointer-events: none;
}

.goal-text b {
  color: var(--accent);
}

.contract-chip {
  position: absolute;
  top: 8px;
  right: 8px;
  max-width: 45%;
  padding: 6px 8px;
  background: rgba(20, 15, 11, 0.78);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  pointer-events: none;
  text-align: right;
}

.contract-chip b {
  color: #8ef58e;
}

.enter-btn {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  padding: 10px 18px;
  font-weight: 800;
  font-size: 16px;
  background: var(--accent);
  color: #1b1108;
  border: 0;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  animation: glow 1.2s ease-in-out infinite;
}

@keyframes glow {
  50% {
    box-shadow: 0 0 0 6px rgba(255, 181, 71, 0.35), 0 4px 16px rgba(0, 0, 0, 0.5);
  }
}

.items {
  position: absolute;
  left: 8px;
  top: 64px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-btn {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(35, 28, 22, 0.85);
  font-size: 20px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.item-btn:disabled {
  opacity: 0.35;
}

.item-btn .count {
  position: absolute;
  right: 2px;
  bottom: 1px;
  font-size: 11px;
  font-weight: 800;
}

.item-btn .key {
  position: absolute;
  left: 3px;
  top: 1px;
  font-size: 9px;
  color: var(--muted);
}

/* ---------- Touch controls ---------- */

.touch {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-between;
  padding: 10px;
  pointer-events: none;
}

.touch-left,
.touch-right {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.tbtn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(20, 15, 11, 0.45);
  font-size: 24px;
  color: #fff;
  touch-action: none;
}

.tbtn.active {
  background: rgba(255, 181, 71, 0.55);
}

.tbtn-up {
  width: 76px;
  height: 76px;
}

/* ---------- Toasts ---------- */

.toasts {
  position: absolute;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  width: min(90%, 420px);
}

.toast {
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(20, 15, 11, 0.9);
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  animation: toast-in 0.25s ease-out;
}

.toast.good {
  border-color: var(--good);
}

.toast.bad {
  border-color: var(--bad);
}

.toast.gold {
  border-color: var(--accent);
  color: var(--accent);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

/* ---------- Overlays and shops ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(8, 6, 4, 0.72);
  z-index: 5;
}

.overlay.show {
  display: flex;
}

.panel {
  width: min(560px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.panel .sub {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.panel .row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.panel .row canvas {
  flex: none;
  width: 28px;
  height: 28px;
}

.panel .row .grow {
  flex: 1;
  min-width: 0;
}

.panel .row .name {
  font-weight: 700;
}

.panel .row .desc {
  font-size: 12px;
  color: var(--muted);
}

.panel .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

.tiers {
  display: flex;
  gap: 3px;
  margin-top: 4px;
}

.tiers i {
  width: 14px;
  height: 5px;
  border-radius: 2px;
  background: #3b3128;
}

.tiers i.on {
  background: var(--accent);
}

.price {
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
}

.hot {
  color: #ff9a5a;
  font-weight: 800;
  font-size: 11px;
  margin-left: 6px;
}

.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.shelf div {
  font-size: 12px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
}

.shelf div.found {
  color: #ffd76a;
  border-color: #6d5a26;
}

.title-screen {
  text-align: center;
}

.logo {
  font-size: clamp(40px, 9vw, 72px);
  font-weight: 900;
  letter-spacing: 4px;
  margin: 0;
  background: linear-gradient(180deg, #ffe08a, #d9822b 60%, #8c3b16);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-screen .tag {
  color: var(--muted);
  margin: 4px 0 16px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 280px;
  margin: 0 auto;
}

.menu-buttons .btn {
  padding: 12px;
  font-size: 16px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  font-size: 14px;
  margin: 10px 0;
}

.stats span:nth-child(even) {
  font-weight: 700;
  text-align: right;
}

.ach {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}

.ach.locked {
  color: var(--muted);
}

.ad-below {
  max-width: 1100px;
  margin: 12px auto 0;
}

.about {
  max-width: 820px;
  margin: 24px auto 0;
  padding: 0 8px;
  line-height: 1.55;
  color: #ddd2c4;
}

.about h1,
.about h2 {
  color: var(--text);
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel);
  font-size: 12px;
}

@media (max-width: 640px) {
  .hud {
    gap: 6px;
    padding: 0 6px;
  }
  .hud-cell {
    font-size: 13px;
  }
  .hud-cell.meter {
    width: 54px;
  }
  .hud-cell.depth {
    display: none;
  }
  .page {
    padding: 4px 0 30px;
  }
  .game-root {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  .goal {
    font-size: 11px;
    width: 56%;
  }
  .contract-chip {
    font-size: 11px;
    max-width: 40%;
  }
}
