:root {
  --bg: #080b17;
  --panel: rgba(17, 22, 41, 0.94);
  --panel-2: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.09);
  --text: #f3f5ff;
  --muted: #98a1c0;
  --accent: #ffc83d;      /* one meaning: you can buy / act on this */
  --accent-ink: #231a00;
  --layer: #c9a27a;       /* current layer colour, set from JS */
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --radius: 14px;
  --shop-w: 368px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body { user-select: none; -webkit-user-select: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
[hidden] { display: none !important; }

.stars { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }
.halo { position: fixed; z-index: 0; left: 0; top: 0; width: 10px; height: 10px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--layer) 38%, transparent), transparent); opacity: .55; transition: background 400ms var(--ease); }
#game { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1; touch-action: none; display: block; cursor: crosshair; }

/* ---------- HUD ---------- */
.hud {
  position: fixed; z-index: 3; top: 16px; left: 16px; right: calc(var(--shop-w) + 32px);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 12px; pointer-events: none;
}
.hud > * { pointer-events: auto; }
.depth {
  justify-self: start; width: 220px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line);
}
.depth-row { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--layer); flex: none; }
.depth-row b { font-size: 17px; font-weight: 800; letter-spacing: 0.01em; }
.meters { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); }
.bar { height: 8px; margin: 9px 0 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--layer); transition: width 160ms var(--ease); }
.next { font-size: 13px; color: var(--muted); white-space: nowrap; }
.next b { color: var(--text); font-weight: 700; }

.money { text-align: center; }
.credits { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 46px; font-weight: 900; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; -webkit-text-stroke: 7px #0a0d22; paint-order: stroke fill; }
.coin { width: 34px; height: 34px; flex: none; }
.coin circle { fill: var(--accent); }
.coin path { fill: #8a5a00; }
.rate { margin-top: 6px; font-size: 16px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.credits.bump { animation: bump 140ms var(--ease); }
@keyframes bump { from { transform: scale(1.06); } to { transform: scale(1); } }

.hud-actions { justify-self: end; display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line); transition: transform 120ms var(--ease);
}
.icon-btn:active { transform: scale(0.97); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .spk { fill: var(--text); }
.icon-btn .x { display: none; }
.icon-btn[aria-pressed="true"] .wave { display: none; }
.icon-btn[aria-pressed="true"] .x { display: inline; }
.boost-on {
  height: 44px; padding: 0 14px; border-radius: 12px; display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--accent); font-weight: 700; font-variant-numeric: tabular-nums;
}
.boost-on b { color: var(--accent); font-weight: 900; }

/* ---------- play area overlays ---------- */
.toast {
  position: fixed; z-index: 4; left: calc((100% - var(--shop-w) - 32px) / 2); top: 132px;
  transform: translate(-50%, -8px); opacity: 0; pointer-events: none; text-align: center;
  padding: 12px 22px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line);
  transition: opacity 200ms var(--ease), transform 200ms var(--ease); white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast .t1 { font-size: 22px; font-weight: 900; color: var(--layer); text-transform: uppercase; letter-spacing: 0.04em; }
.toast .t2 { margin-top: 2px; font-size: 14px; color: var(--muted); }
.toast .t2 b { color: var(--text); }

.play-foot {
  position: fixed; z-index: 3; left: 0; right: calc(var(--shop-w) + 32px); bottom: 32px;
  display: grid; justify-items: center; align-items: end; pointer-events: none;
}
.play-foot > * { grid-area: 1 / 1; }
.hint { margin: 0; padding: 10px 18px; border-radius: 999px; background: rgba(8, 11, 23, 0.6); color: var(--text); font-weight: 700; font-size: 16px; transition: opacity 300ms var(--ease); }
.hint.gone { opacity: 0; }
.core-btn {
  pointer-events: auto; padding: 16px 30px; border: 0; border-radius: 999px; font-size: 20px; font-weight: 900;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 0 #b8860b; transition: transform 120ms var(--ease);
  animation: pulse 1.4s ease-in-out infinite;
}
.core-btn:active { transform: translateY(3px) scale(0.97); box-shadow: 0 3px 0 #b8860b; animation: none; }
@keyframes pulse { 50% { transform: scale(1.05); } }

/* ---------- shop ---------- */
.shop {
  position: fixed; z-index: 3; top: 16px; right: 16px; bottom: 16px; width: var(--shop-w);
  display: flex; flex-direction: column; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); overflow: hidden;
}
.tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); flex: none; }
.tabs button {
  flex: 1; height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  font-size: 16px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.tabs button[aria-selected="true"] { background: var(--panel-2); color: var(--text); }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 900; display: inline-grid; place-items: center; letter-spacing: 0; }
.lists { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; -webkit-overflow-scrolling: touch; }
.list { display: flex; flex-direction: column; gap: 6px; }
.sec { margin: 6px 4px 10px; font-size: 13px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.list + .sec { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
@media (min-width: 900px) {
  .tabs { display: none; }
  .list[hidden] { display: flex !important; }
}

.row { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; background: var(--panel-2); min-height: 68px; }
.row .ico { width: 44px; height: 44px; flex: none; border-radius: 11px; display: grid; place-items: center; background: rgba(255,255,255,.06); }
.row .ico svg { width: 26px; height: 26px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.row .txt { flex: 1; min-width: 0; }
.row .name { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.row .name b { font-size: 16px; font-weight: 800; }
.row .name span { font-size: 13px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .fx { margin-top: 3px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.row .fx b { color: var(--text); font-weight: 700; }
.row .fx i { font-style: normal; opacity: .7; }
.buy {
  flex: none; min-width: 92px; height: 44px; padding: 0 12px; border: 0; border-radius: 11px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 16px; font-weight: 900; font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.07); color: var(--muted); transition: transform 100ms var(--ease);
}
.buy .coin { width: 16px; height: 16px; }
.buy.ok { background: var(--accent); color: var(--accent-ink); box-shadow: 0 3px 0 #b8860b; }
.buy.ok .coin circle { fill: #fff3c4; }
.buy:active { transform: scale(0.97); }
.buy.can { background: rgba(255, 255, 255, 0.12); color: var(--text); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; }
.buy.ok:active { transform: translateY(2px) scale(0.97); box-shadow: 0 1px 0 #b8860b; }
.buy[disabled] { cursor: default; }
.row.locked { background: transparent; border: 1px dashed var(--line); }
.row.locked .ico svg { stroke: var(--muted); }
.row.locked .name b { color: var(--muted); }
.row .ico svg.drone-ico { width: 30px; height: 30px; stroke: none; }
.drone-ico ellipse { fill: none; stroke: #e8ebf5; stroke-width: 1.6; }
.drone-ico .body { fill: var(--c); }
.drone-ico .bit { fill: #7d8399; }

.rewards { flex: none; display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.reward {
  flex: 1; min-width: 0; height: 44px; padding: 0 10px; border-radius: 11px; border: 1px solid rgba(255,255,255,.14); background: #222a4a;
  display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden;
  transition: transform 100ms var(--ease);
}
.reward:active { transform: scale(0.97); }
.reward svg.ad { width: 18px; height: 18px; flex: none; }
.ad circle { fill: var(--text); }
.ad path { fill: #1a2140; }
.reward span { overflow: hidden; text-overflow: ellipsis; }
.reward[disabled] { opacity: 0.45; cursor: default; }

/* ---------- dialogs ---------- */
.scrim { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 20px; background: rgba(4, 6, 14, 0.62); animation: fade 200ms var(--ease); }
.dialog {
  width: min(420px, 100%); padding: 26px; border-radius: 20px; background: #141a31; border: 1px solid var(--line); text-align: center;
  animation: pop 220ms var(--ease);
}
.dialog h2 { margin: 0 0 12px; font-size: 24px; font-weight: 900; }
.dialog p { margin: 0 0 10px; font-size: 16px; line-height: 1.45; color: var(--muted); }
.dialog p b { color: var(--text); }
.dialog .big { display: block; margin: 8px 0; font-size: 40px; font-weight: 900; color: var(--accent); font-variant-numeric: tabular-nums; }
.dialog .big.shard { color: #3dff9a; }
.dialog .fine { font-size: 14px; }
.dlg-actions { display: flex; gap: 10px; margin-top: 20px; }
.btn {
  flex: 1; height: 52px; border-radius: 13px; border: 1px solid var(--line); background: rgba(255,255,255,.06);
  font-size: 17px; font-weight: 800; display: flex; align-items: center; justify-content: center; gap: 8px; transition: transform 120ms var(--ease);
}
.btn svg.ad { width: 18px; height: 18px; }
.btn.primary .ad circle { fill: var(--accent-ink); }
.btn.primary .ad path { fill: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: 0 4px 0 #b8860b; }
.btn:active { transform: scale(0.97); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(0.95); } }

.fake-ad { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0,0,0,.85); font-size: 18px; font-weight: 700; color: var(--muted); }

/* ---------- pop-ups ---------- */
#pops { position: fixed; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
.pop {
  position: absolute; left: 0; top: 0; font-weight: 900; font-size: 22px; color: #fff; white-space: nowrap;
  -webkit-text-stroke: 5px #0a0d22; paint-order: stroke fill; letter-spacing: -0.01em; will-change: transform, opacity;
  animation: rise 650ms var(--ease) forwards;
}
.pop.crit { font-size: 38px; color: #ff7a45; -webkit-text-stroke-width: 7px; }
.pop.drone { font-size: 15px; color: #c9d6ff; -webkit-text-stroke-width: 4px; }
@keyframes rise {
  from { transform: translate(var(--x), var(--y)) translate(-50%, -50%) scale(0.95); opacity: 1; }
  70% { opacity: 1; }
  to { transform: translate(var(--x), calc(var(--y) - 70px)) translate(-50%, -50%) scale(1); opacity: 0; }
}

/* ---------- phone ---------- */
@media (max-width: 899px) {
  :root { --sheet-h: min(48vh, 356px); }
  .sec { display: none; }
  .lists { padding: 6px 8px; }
  .hud { top: calc(10px + env(safe-area-inset-top)); left: 10px; right: 10px; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; }
  .money { text-align: right; }
  .credits { justify-content: flex-end; }
  .depth { width: 128px; padding: 9px 10px; border-radius: 12px; }
  .depth-row { gap: 6px; }
  .depth-row b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
  .meters { font-size: 13px; }
  .depth { width: 100%; max-width: 200px; }
  .bar { height: 6px; margin: 7px 0 5px; }
  .next { font-size: 12px; }
  .next .at { display: none; }
  .depth-row b { flex: 1; min-width: 0; }
  .credits { font-size: 28px; gap: 6px; -webkit-text-stroke-width: 6px; }
  .coin { width: 22px; height: 22px; }
  .rate { font-size: 14px; margin-top: 4px; }
  .icon-btn { width: 40px; height: 40px; }
  .boost-on { position: fixed; top: calc(96px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); height: 32px; font-size: 14px; }
  .toast { left: 50%; top: calc(98px + env(safe-area-inset-top)); }
  .play-foot { right: 0; bottom: calc(var(--sheet-h) + 14px); }
  .shop { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: auto; max-height: var(--sheet-h); border-radius: 20px 20px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
  .tabs { padding: 6px 8px; }
  .tabs button { height: 40px; font-size: 15px; }
  .row { min-height: 52px; padding: 5px 8px; gap: 10px; }
  .list { gap: 5px; }
  .row .ico { width: 36px; height: 36px; }
  .row .ico svg { width: 22px; height: 22px; }
  .row .name b { font-size: 15px; }
  .buy { min-width: 84px; height: 40px; font-size: 15px; }
  .rewards { padding: 6px 8px; }
  .reward { height: 40px; }
  .reward { font-size: 13px; padding: 0 8px; }
  .dialog { padding: 22px 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
