:root {
  --bg: #0b0d12;
  --fg: #e6e8ee;
  --muted: #8a91a3;
  --red: #ff4d5e;
  --blue: #3d9bff;
  --amber: #ffb547;
  --gold: #ffd84d;
  --goo: #b6ff3b;
  --panel: rgba(14, 17, 25, 0.86);
  --border: rgba(255, 255, 255, 0.1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: "Space Grotesk", system-ui, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
          user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  top: 12px;
  left: 16px;
  right: 16px;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  pointer-events: none;
}
.hud > div { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.hud .lbl { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.hud b { font-size: 20px; font-variant-numeric: tabular-nums; margin-right: 8px; }
.chain {
  color: var(--gold);
  font-weight: 600;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.15s, transform 0.25s cubic-bezier(0.3, 1.8, 0.5, 1);
}
.chain.on { opacity: 1; transform: scale(1); }

/* ---------- Zone / pickup banner ---------- */
.banner {
  position: fixed;
  top: 22%;
  left: 50%;
  z-index: 4;
  text-align: center;
  pointer-events: none;
  opacity: 0;
}
.banner span {
  display: block;
  color: var(--muted);
  font: 600 13px "JetBrains Mono", ui-monospace, monospace;
  text-transform: uppercase;
  letter-spacing: 0.2em;
}
.banner b {
  display: block;
  font-size: clamp(28px, 7vw, 52px);
  letter-spacing: -0.02em;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.6);
}
.banner.show { animation: banner 2.4s cubic-bezier(0.2, 1.4, 0.4, 1) forwards; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  12%, 75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 6, 10, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
  cursor: pointer;
}
.overlay.show { opacity: 1; visibility: visible; }

.card {
  width: min(440px, 100%);
  padding: 28px 28px 22px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  text-align: center;
  transform: translateY(12px) scale(0.97);
  transition: transform 0.35s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.overlay.show .card { transform: none; }

h1, h2 { margin: 0 0 8px; letter-spacing: -0.03em; line-height: 1; }
h1 { font-size: clamp(34px, 9vw, 48px); }
h1 em { font-style: normal; color: var(--goo); }
h2 { font-size: 40px; color: var(--goo); }

.tag { margin: 0 0 18px; color: var(--muted); font-size: 15px; }

.how {
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
  text-align: left;
  font-size: 14px;
  line-height: 1.4;
}
.how li { display: flex; align-items: center; gap: 12px; padding: 5px 0; }
.how li > span:first-child { flex: 0 0 74px; display: flex; gap: 4px; justify-content: flex-end; }

.ico { display: inline-block; width: 18px; height: 18px; border-radius: 50%; }
.ico.gear { background: radial-gradient(circle, var(--bg) 25%, var(--red) 27%); box-shadow: 0 0 0 3px var(--red) inset; }
.ico.wall { border-radius: 2px; width: 8px; background: repeating-linear-gradient(var(--muted) 0 3px, transparent 3px 6px); }
.ico.goo { border-radius: 9px 9px 4px 4px; background: var(--goo); }

kbd {
  display: inline-block;
  min-width: 24px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 3px;
  border-radius: 6px;
  background: #1a1f2b;
  color: var(--fg);
  font: 600 12px "JetBrains Mono", ui-monospace, monospace;
  text-align: center;
}

.go { margin: 0; color: var(--fg); font-size: 15px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 0 0 14px;
}
.stats div { padding: 10px 4px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); }
.stats dt { color: var(--muted); font: 11px "JetBrains Mono", ui-monospace, monospace; text-transform: uppercase; }
.stats dd { margin: 4px 0 0; font: 600 20px "JetBrains Mono", ui-monospace, monospace; }
.newbest { display: none; margin: 0 0 12px; color: var(--gold); font-weight: 700; letter-spacing: 0.1em; }
.newbest.on { display: block; animation: pulse 0.8s ease-in-out infinite; }

/* ---------- Seeds ---------- */
.hud b.seed { font-size: 13px; color: var(--muted); letter-spacing: 0.08em; }

.seed-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 0 18px;
  cursor: default;
}
.seed-row label { color: var(--muted); font: 11px "JetBrains Mono", ui-monospace, monospace; text-transform: uppercase; letter-spacing: 0.08em; }
.seed-row input {
  width: 13ch;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #1a1f2b;
  color: var(--gold);
  font: 600 15px "JetBrains Mono", ui-monospace, monospace;
  letter-spacing: 0.12em;
  text-align: center;
  -webkit-user-select: text;
          user-select: text;
}
.seed-row input:focus { outline: none; border-color: var(--gold); }
.seed-row button, .actions button {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #1a1f2b;
  color: var(--fg);
  font: 600 13px "JetBrains Mono", ui-monospace, monospace;
  cursor: pointer;
}
.seed-row button { width: 34px; height: 33px; font-size: 16px; }
.seed-row button:hover, .actions button:hover { border-color: var(--muted); }

.seed-line { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.seed-line code { color: var(--gold); font: 600 14px "JetBrains Mono", ui-monospace, monospace; letter-spacing: 0.1em; }
.seed-line b { color: var(--fg); }

.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.actions button { padding: 8px 12px; }
.actions kbd { margin-right: 4px; padding: 0 5px; font-size: 11px; }

/* ---------- Campaign ---------- */
.powers {
  position: fixed;
  top: 46px;
  left: 16px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}
.pw {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  font-size: 12px;
  overflow: hidden;
  animation: pw-in 0.3s cubic-bezier(0.3, 1.6, 0.5, 1);
}
@keyframes pw-in { from { transform: translateX(-20px); opacity: 0; } }
.pw b { color: var(--fg); }
.pw span { color: var(--muted); }
.pw u { position: absolute; left: 0; bottom: 0; height: 2px; background: currentColor; text-decoration: none; }
.pw i { display: inline-block; width: 12px; height: 12px; }
.pw.oil { color: var(--gold); }
.pw.oil i { border-radius: 3px; background: var(--gold); }
.pw.magnet { color: var(--red); }
.pw.magnet i { border: 3px solid var(--red); border-top: 0; border-radius: 0 0 8px 8px; }
.pw.overclock { color: #ff4dd2; }
.pw.overclock b { animation: rainbow 0.6s linear infinite; }
.pw.overclock i { border-radius: 2px; animation: rainbow-bg 0.6s linear infinite; }
.pw.gun { color: #cfd3dc; }
.pw.gun i { width: 14px; height: 8px; border-radius: 2px 4px 4px 2px; background: #cfd3dc; box-shadow: 4px 0 0 -1px var(--gold); }
@keyframes rainbow { 0% { color: #ff4d5e; } 33% { color: #ffd84d; } 66% { color: #3d9bff; } 100% { color: #ff4d5e; } }
@keyframes rainbow-bg { 0% { background: #ff4d5e; } 33% { background: #ffd84d; } 66% { background: #3d9bff; } 100% { background: #ff4d5e; } }
.hud b.low { color: var(--red); animation: pulse 0.5s ease-in-out infinite; }

.tag.small { margin-top: -8px; font-size: 13px; }
.assist { display: flex; align-items: center; justify-content: center; gap: 8px; margin: -6px 0 16px; color: var(--fg); font-size: 14px; cursor: pointer; }
.assist input { width: 16px; height: 16px; accent-color: var(--goo); }
.assist small { color: var(--muted); font-size: 12px; }
.ico.crate { border-radius: 3px; background: #c98a2b; box-shadow: 0 0 0 2px #7a4f12 inset; }
.ico.bot { border-radius: 5px; background: radial-gradient(circle at 50% 45%, var(--red) 22%, #454c5c 25%); }

.overlay.passive { cursor: default; pointer-events: none; }
h2.win { color: var(--gold); }
.tally { display: grid; gap: 6px; margin: 14px 0 0; font-family: "JetBrains Mono", ui-monospace, monospace; }
.tally div { display: flex; justify-content: space-between; padding: 8px 12px; border-radius: 8px; background: rgba(255, 255, 255, 0.04); }
.tally dt { color: var(--muted); }
.tally dd { margin: 0; font-weight: 600; }

/* ---------- Workshop ---------- */
.overlay#shop { cursor: default; }
.card.shop { width: min(520px, 100%); }
.budget { margin: 0 0 14px; color: var(--muted); font: 13px "JetBrains Mono", ui-monospace, monospace; text-transform: uppercase; letter-spacing: 0.08em; }
.budget b { color: var(--gold); font-size: 22px; letter-spacing: 0; }
.items { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 0 0 16px; }
.item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #1a1f2b;
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.item:hover:not(.off) { border-color: var(--gold); transform: translateY(-1px); }
.item b { font-size: 14px; }
.item small { grid-column: 1; color: var(--muted); font-size: 12px; }
.item em { grid-row: 1 / span 2; grid-column: 2; align-self: center; color: var(--gold); font: 600 13px "JetBrains Mono", ui-monospace, monospace; font-style: normal; }
.item kbd { position: absolute; top: -7px; left: -7px; min-width: 20px; padding: 0 4px; font-size: 10px; }
.item.off { opacity: 0.45; cursor: not-allowed; }
.item.bought { animation: bought 0.4s; }
@keyframes bought { 40% { transform: scale(1.04); border-color: var(--goo); } }
.seed-row .daily { width: auto; padding: 0 10px; font-size: 12px; color: var(--gold); }

/* ---------- Corner links ---------- */
.corner {
  position: fixed;
  left: 50%;
  bottom: 12px;
  z-index: 6;
  display: flex;
  gap: 8px;
  transform: translateX(-50%);
  font: 12px "JetBrains Mono", ui-monospace, monospace;
}
.corner a, .corner button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.corner a:hover, .corner button:hover, .corner button[aria-pressed="true"] { color: var(--fg); border-color: var(--muted); }

/* ---------- Touch controls ---------- */
.touch { display: none; }
.taps { display: none !important; }

@media (pointer: coarse) {
  .touch {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    z-index: 4;
    display: flex;
    gap: 10px;
  }
  .touch button {
    width: 72px;
    height: 72px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: rgba(20, 24, 34, 0.6);
    color: var(--fg);
    font: 600 22px "Space Grotesk", system-ui, sans-serif;
    touch-action: none;
  }
  .touch button:active { background: rgba(255, 255, 255, 0.16); }
  .touch .jump { margin-left: auto; width: 96px; color: var(--goo); font-size: 18px; }
  .touch .fire { display: none; color: var(--gold); font-size: 16px; }
  body.has-gun .touch .fire { display: block; }
  .corner { top: 44px; bottom: auto; }
  body .powers { top: 84px; }
  .keys { display: none !important; }
  .taps { display: flex !important; }
}

@media (max-width: 560px) {
  .hud { left: 10px; right: 10px; gap: 6px; }
  .hud > div { gap: 5px; }
  .hud b { font-size: 15px; margin-right: 2px; }
  .hud .seed, .hud .seed-lbl { display: none; }
  .powers { top: 66px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .items { grid-template-columns: 1fr; }
  .item kbd { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .go, .newbest.on { animation: none; }
}
