:root {
  --bg: #1b1a17; --panel: #2a2824; --panel2: #34312c; --line: #4a463f;
  --text: #ece6da; --muted: #a39c8f; --accent: #f29b24; --accent2: #ffc35a;
  --good: #7cc56b; --bad: #e0573f;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none; overscroll-behavior: none;
  background-image: repeating-linear-gradient(45deg, #1f1d1a 0 12px, #1b1a17 12px 24px);
  min-height: 100vh;
}
h2 { font-size: 16px; margin: 14px 0 8px; color: var(--accent2); text-transform: uppercase; letter-spacing: .05em; }
small { color: var(--muted); }

.top {
  position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px;
  padding: 8px 12px; background: #141311ee; border-bottom: 2px solid var(--accent);
}
.chip { display: flex; align-items: center; gap: 3px; font-weight: 700; font-size: 13px; white-space: nowrap; min-width: 0; }
.top .chip { justify-content: center; }

main { max-width: 520px; margin: 0 auto; padding: 8px 16px calc(120px + var(--ores-h, 0px) + var(--safe-b)); }
.tab { display: none; }
.tab.active { display: block; }

.lvl { font-size: 12px; color: var(--accent); font-weight: 700; white-space: nowrap; }

.bar { height: 8px; background: #191816; border-radius: 4px; overflow: hidden; margin-top: 3px; }
.bar > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .2s; }

/* buttons */
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
.buy {
  background: var(--accent); color: #1b1a17; font-weight: 800; border-radius: 8px; padding: 9px 10px;
  box-shadow: 0 3px 0 #9c5e0e;
}
.buy:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #9c5e0e; }
.buy:disabled { background: #57524a; color: #8f887c; box-shadow: 0 3px 0 #3a3732; cursor: default; }
.buy.big { width: 100%; padding: 14px; font-size: 16px; margin-top: 10px; }
.link { background: none; color: var(--muted); text-decoration: underline; margin-top: 24px; }

/* ore buttons */
.ores {   /* fixed above the tab bar, in thumb reach */
  position: fixed; left: 0; right: 0; bottom: calc(58px + var(--safe-b)); z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  padding: 8px max(12px, calc(50% - 248px)); background: #141311ee; border-top: 2px solid var(--line);
}
.ore {
  padding: 10px 2px; border-radius: 12px; background: radial-gradient(circle at 30% 30%, #6b5a3a, #3d3324);
  border: 2px solid var(--accent); display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0;
}
.ore .oi { font-size: 28px; }
.ore b { font-size: 12px; }
.ore { touch-action: none; }   /* holding must not scroll or zoom */
.ore .bar { width: 80%; height: 5px; }
.ore .bar > div { transition: none; }
.ore:active { transform: scale(.95); filter: brightness(1.25); }
.buy.sm { padding: 7px 10px; font-size: 13px; white-space: nowrap; }
.hint { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; }

/* production rows */
.row {
  background: var(--panel); border: 2px solid var(--line); border-radius: 10px; padding: 6px 8px;
  display: flex; align-items: center; gap: 8px;
}
.row.starved { border-color: var(--bad); }
.row .big { font-size: 24px; }
.row .info { flex: 1; min-width: 0; font-size: 14px; }
.row .own { color: var(--accent2); font-size: 12px; }
.acts { display: flex; flex-direction: column; align-items: stretch; gap: 4px; }
.ctl { display: flex; align-items: center; gap: 4px; }
.pm { width: 30px; height: 30px; border-radius: 6px; background: var(--panel2); border: 1px solid var(--line); font-weight: 900; font-size: 18px; }
.pm:disabled { opacity: .35; }
.cnt { min-width: 38px; text-align: center; font-weight: 700; font-size: 13px; }
.inv { display: flex; flex-wrap: wrap; gap: 6px 12px; background: var(--panel); border-radius: 10px; padding: 8px 10px; }
.note { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.current { background: var(--panel); border: 2px solid var(--accent); border-radius: 10px; padding: 10px; margin: 10px 0; }
.card.done { opacity: .55; }
.row.col { flex-direction: column; align-items: stretch; gap: 6px; }
.rh { display: flex; align-items: center; gap: 8px; }
.rh .info small { display: block; }
.rc { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.fuel { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.fuel[hidden] { display: none; }
.fuel .bar { flex: 1; margin: 0; }
.fuel.empty .bar { outline: 1px solid var(--bad); }
.fuel .buy.sm { padding: 5px 8px; }
.bar.low > div { background: var(--bad); }
.queue {
  position: fixed; left: 0; right: 0; bottom: calc(58px + var(--ores-h, 0px) + var(--safe-b)); z-index: 6; padding: 8px 12px;
  font-size: 13px; font-weight: 700; text-align: left; border-top: 2px solid var(--accent); color: var(--text);
}
.queue[hidden] { display: none; }

/* research */
.list { display: flex; flex-direction: column; gap: 8px; }
.card {
  background: var(--panel); border: 2px solid var(--line); border-radius: 10px; padding: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.card .buy { min-width: 96px; }

/* rocket */
.silo { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 14px; text-align: center; }
.rocket { font-size: 64px; animation: hover 2s ease-in-out infinite; }
@keyframes hover { 50% { transform: translateY(-6px); } }
.version { color: var(--muted); font-size: 12px; text-align: center; }

/* bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex;
  background: #141311; border-top: 2px solid var(--line); padding-bottom: var(--safe-b);
}
.tabs button { flex: 1; background: none; padding: 8px 0; font-size: 22px; display: flex; flex-direction: column; align-items: center; color: var(--muted); }
.tabs button span { font-size: 12px; }
.tabs button.active { color: var(--accent2); box-shadow: inset 0 3px 0 var(--accent); }

/* effects */
.float {
  position: fixed; z-index: 20; transform: translateX(-50%); pointer-events: none;
  font-weight: 900; color: var(--accent2); text-shadow: 0 2px 3px #000; animation: rise .9s ease-out forwards;
}
@keyframes rise { to { transform: translate(-50%, -50px); opacity: 0; } }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(110px + var(--ores-h, 0px) + var(--safe-b)); z-index: 15; max-width: 488px; margin: 0 auto;
  background: #000d; border: 2px solid var(--accent); border-radius: 10px; padding: 10px 12px; text-align: center;
}
.fbar { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.fbar .bar { flex: 1; margin: 0; }
.bar.coal > div { background: linear-gradient(90deg, #555, #aaa); }
.good { color: var(--good); }
.infob { background: none; color: var(--accent2); font-size: 15px; padding: 0 4px; line-height: 1; }
.modal { position: fixed; inset: 0; z-index: 30; background: #000a; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.sheet { background: var(--panel); border: 2px solid var(--accent); border-radius: 12px; padding: 14px; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 6px; }
.sheet h3 { margin: 0 0 4px; color: var(--accent2); }
.sheet p { margin: 0 0 6px; }
.sheet ul { margin: 2px 0 6px; padding-left: 20px; }

.crash {
  position: fixed; inset: 0; z-index: 50; background: var(--bg); padding: 40px 16px;
  display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center;
}
.crash[hidden] { display: none; }
