:root {
  --bg: #0a0a0c;
  --bg-soft: #15151a;
  --bg-row: #15151a;
  --line: #232329;
  --text: #f5f5f7;
  --muted: #86868b;
  --accent: #ff5a4d;
  --accent-soft: #ff8c82;
  --gold: #ffcf3f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #050507;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#game {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  background:
    radial-gradient(120% 80% at 50% 0%, #1a0808 0%, var(--bg) 55%);
  overflow: hidden;
}

/* ---------- HUD ---------- */
#hud {
  flex: 0 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 12px;
  background: linear-gradient(#160707, transparent);
}
.hud-top { display: flex; justify-content: space-between; align-items: center; }
#host-label { font-size: 12px; font-weight: 700; letter-spacing: 1px; color: var(--accent-soft); text-transform: uppercase; }
#stage-label { font-size: 11px; color: var(--muted); }
.hud-right { display: flex; align-items: center; gap: 10px; }
.icon-btn { background: none; border: none; font-size: 15px; cursor: pointer; padding: 2px 4px; line-height: 1; opacity: 0.85; }
.icon-btn:active { transform: scale(0.9); }
.hud-count { margin-top: 8px; display: flex; align-items: baseline; gap: 10px; }
#balance { font-size: 34px; font-weight: 800; letter-spacing: -0.5px; }
#rate { font-size: 13px; font-weight: 700; color: var(--accent); }
.hud-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ---------- TICKER ---------- */
#ticker { flex: 0 0 auto; padding: 5px 14px; background: #120606; border-bottom: 1px solid #1f1f24; font-size: 11px; color: var(--accent-soft); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 24px; line-height: 14px; }
#ticker:empty { display: none; }
#ticker::before { content: '🔴 LIVE  '; color: var(--accent); font-weight: 700; }
#ticker.flash { animation: tickerIn 0.5s ease; }
@keyframes tickerIn { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- STAGE ---------- */
#stage {
  position: relative;
  flex: 1 1 0;
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#stage-bg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.host-svg { width: 74%; max-width: 360px; height: auto; opacity: 0.9; filter: drop-shadow(0 0 22px rgba(226, 59, 46, 0.22)); }

#strains {
  position: relative; z-index: 2;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 10px 14px; max-width: 94%;
}
.strain {
  position: relative; width: 80px; height: 80px;
  border: none; background: none; padding: 0; cursor: pointer;
  color: var(--c, #ff5a4d);
  transition: transform 0.08s ease;
  filter: drop-shadow(0 0 12px var(--c, #ff5a4d));
}
.strain svg { width: 100%; height: 100%; display: block; }
.strain:active { transform: scale(0.9); }
.strain.tap { animation: pulse 0.18s ease; }
.strain-lv {
  position: absolute; bottom: -2px; right: -2px;
  background: rgba(0, 0, 0, 0.72); color: #fff; font-size: 9px; font-weight: 700;
  padding: 1px 5px; border-radius: 8px; border: 1px solid var(--c, #ff5a4d);
}
@keyframes pulse { 0% { transform: scale(0.88); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }

#tap-hint { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--muted); z-index: 1; pointer-events: none; }
/* Onboarding hint only — hide it once a 2nd strain exists, so it can't overlap
   the strain rows when they wrap to two lines. */
#strains:has(.strain:nth-child(2)) ~ #tap-hint { display: none; }

#floats { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.float {
  position: absolute; font-weight: 800; font-size: 18px; color: var(--accent);
  text-shadow: 0 0 8px rgba(255, 90, 77, 0.6);
  animation: floatUp 0.8s ease-out forwards;
}
@keyframes floatUp {
  0% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60px) scale(1.2); }
}

/* zoom transition on tier advance */
.zoom-anim #stage-bg, .zoom-anim #strains { animation: zoomOutIn 0.62s ease; }
@keyframes zoomOutIn {
  0% { transform: scale(1); opacity: 1; }
  42% { transform: scale(2.6); opacity: 0; }
  44% { transform: scale(0.35); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* golden virus pickup */
#golden { position: absolute; width: 72px; height: 72px; border: none; background: none; padding: 0; cursor: pointer; z-index: 18; animation: goldenBob 1.8s ease-in-out infinite; filter: drop-shadow(0 0 14px rgba(255, 207, 63, 0.85)); }
#golden svg { width: 100%; height: 100%; display: block; }
@keyframes goldenBob { 0%, 100% { transform: translateY(0) rotate(-7deg); } 50% { transform: translateY(-7px) rotate(7deg); } }

/* ---------- PROGRESS ---------- */
#progress {
  flex: 0 0 auto;
  padding: 11px 18px;
  background: #0d0d10;
  border-top: 1px solid #1f1f24;
  border-bottom: 1px solid #1f1f24;
}
.progress-row { display: flex; justify-content: space-between; font-size: 11px; color: #aeaeb2; margin-bottom: 6px; }
#prog-next { color: var(--accent-soft); }
.bar { height: 9px; background: #26262a; border-radius: 5px; overflow: hidden; }
#prog-fill { height: 100%; width: 0%; border-radius: 5px; background: linear-gradient(90deg, #7a201b, #ff5a4d); transition: width 0.2s ease; }

/* ---------- OUTBREAK ---------- */
#outbreak { flex: 0 0 auto; padding: 10px 18px 4px; }
#outbreak-btn {
  position: relative; width: 100%; height: 46px; border: 1px solid #3a1d1a;
  border-radius: 12px; background: #15101a; color: var(--text);
  font-size: 13px; font-weight: 700; overflow: hidden; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#outbreak-btn:disabled { cursor: default; color: var(--muted); }
#outbreak-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  background: linear-gradient(90deg, rgba(255,90,77,0.25), rgba(255,90,77,0.4)); transition: width 0.15s ease;
}
#outbreak-label { position: relative; z-index: 1; }
#outbreak-btn.ready { border-color: var(--accent); color: #fff; animation: obpulse 0.9s ease-in-out infinite; }
#outbreak-btn.ready #outbreak-fill { background: linear-gradient(90deg, #b3261e, #ff5a4d); width: 100% !important; }
#outbreak-btn.active { border-color: var(--gold); color: #fff; }
#outbreak-btn.active #outbreak-fill { background: linear-gradient(90deg, #ff9f0a, #ff5a4d); }
@keyframes obpulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,90,77,0.0); } 50% { box-shadow: 0 0 14px 2px rgba(255,90,77,0.5); } }

/* ---------- PRESTIGE (mutation / NG+) ---------- */
#prestige { flex: 0 0 auto; padding: 4px 18px 2px; }
#prestige-btn { width: 100%; height: 40px; border: 1px solid #2c1f44; border-radius: 12px; background: #140f1e; color: #b89cff; font-size: 13px; font-weight: 700; cursor: pointer; }
#prestige-btn:disabled { color: var(--muted); cursor: default; opacity: 0.75; }
#prestige-btn.ready { border-color: #9a6bff; color: #e4d6ff; animation: prpulse 1s ease-in-out infinite; }
#prestige-info { text-align: center; font-size: 10.5px; color: #9a8bbf; margin-top: 4px; }
@keyframes prpulse { 0%,100% { box-shadow: 0 0 0 0 rgba(154,107,255,0); } 50% { box-shadow: 0 0 14px 2px rgba(154,107,255,0.5); } }

/* ---------- UPGRADES ---------- */
#upgrades {
  flex: 0 1 auto; max-height: 40vh; overflow-y: auto;
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 14px);
  -webkit-overflow-scrolling: touch;
}
.section-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin: 2px 4px 9px; }
.upg {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: var(--bg-row); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; margin-bottom: 8px; cursor: pointer; text-align: left;
  color: var(--text); transition: border-color 0.12s ease, opacity 0.12s ease;
}
.upg-icon { width: 34px; height: 34px; border-radius: 8px; background: #2a1210; display: flex; align-items: center; justify-content: center; font-size: 17px; flex-shrink: 0; }
.upg-mid { flex: 1; min-width: 0; }
.upg-name { font-size: 13px; font-weight: 600; }
.upg-lvl { color: var(--accent-soft); font-weight: 700; }
.upg-desc { font-size: 11px; color: var(--muted); }
.upg-cost { font-size: 13px; font-weight: 800; color: var(--gold); white-space: nowrap; flex-shrink: 0; }
.upg.affordable { border-color: #4a2a14; }
.upg.affordable:active { border-color: var(--gold); }
.upg:disabled { cursor: default; opacity: 0.45; }
.upg.locked { opacity: 0.4; }
.upg.locked .upg-cost { color: var(--muted); }

#reset-btn {
  display: block; margin: 6px auto 2px; padding: 6px 14px;
  background: none; border: 1px solid var(--line); border-radius: 8px;
  color: var(--muted); font-size: 11px; cursor: pointer;
}

/* ---------- overlays ---------- */
.hidden { display: none !important; }
#toast {
  position: absolute; left: 50%; top: 84px; transform: translateX(-50%);
  background: rgba(20,8,8,0.95); border: 1px solid #4a1d18; color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 20;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5); max-width: 90%; text-align: center;
  animation: toastIn 0.3s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

#clear-overlay {
  position: absolute; inset: 0; z-index: 30;
  background: radial-gradient(circle at 50% 40%, rgba(60,8,8,0.96), rgba(5,5,7,0.98));
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.clear-card { text-align: center; max-width: 360px; max-height: 90vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.clear-emoji { font-size: 56px; margin-bottom: 10px; }
.clear-card h1 { font-size: 28px; color: var(--accent); margin-bottom: 10px; letter-spacing: 1px; }
#clear-stats { font-size: 14px; color: var(--muted); line-height: 1.7; margin-bottom: 22px; }
#clear-continue {
  padding: 12px 22px; background: var(--accent); color: #fff; border: none;
  border-radius: 10px; font-size: 14px; font-weight: 700; cursor: pointer;
}

/* ---------- ACHIEVEMENTS ---------- */
#ach-count { font-size: 10px; color: var(--muted); margin-left: 1px; vertical-align: middle; }
#ach-overlay, #lab-overlay, #dnalab-overlay, #settings-overlay { position: absolute; inset: 0; z-index: 25; background: rgba(5,5,7,0.96); display: flex; align-items: center; justify-content: center; padding: 20px; }
.ach-card { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 14px; width: 100%; max-width: 400px; max-height: 80vh; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; padding: 16px; }
.ach-card h2 { font-size: 18px; margin-bottom: 12px; }
#ach-list { overflow-y: auto; min-height: 0; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 8px; }
.ach-row { display: flex; align-items: center; gap: 11px; background: #101013; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
.ach-row.locked { opacity: 0.4; }
.ach-row.unlocked { border-color: #4a3a14; }
.ach-ic { font-size: 20px; width: 28px; text-align: center; flex-shrink: 0; }
.ach-name { font-size: 13px; font-weight: 700; }
.ach-desc { font-size: 11px; color: var(--muted); }
/* Close buttons stay reachable even when the card scrolls (sticky pins them to
   the card's bottom; a no-op for overlays whose inner list scrolls instead). */
#ach-close, #lab-close, #dnalab-close, #set-close { flex: 0 0 auto; position: sticky; bottom: 0; display: block; width: 100%; margin-top: 12px; padding: 10px; background: #26262a; border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-size: 13px; cursor: pointer; }

/* ---------- ADS ---------- */
#ads { flex: 0 0 auto; padding: 2px 18px 4px; }
#ad-btn { width: 100%; height: 38px; border: 1px solid #1f3a2a; border-radius: 12px; background: #0f1a14; color: #7fe0a8; font-size: 12.5px; font-weight: 700; cursor: pointer; }
#ad-btn:disabled { color: var(--muted); cursor: default; opacity: 0.7; }
#ad-banner { flex: 0 0 auto; height: 44px; display: flex; align-items: center; justify-content: center; background: #0c0c0e; border-top: 1px solid var(--line); color: #6a6a70; font-size: 11px; letter-spacing: 2px; }
#ad-overlay { position: absolute; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.93); display: flex; align-items: center; justify-content: center; }
.ad-card { text-align: center; }
.ad-fake { font-size: 46px; }
.ad-sub { color: var(--muted); font-size: 12px; margin-top: 6px; letter-spacing: 1px; }
#ad-countdown { font-size: 46px; font-weight: 800; color: var(--accent-soft); margin: 16px 0 10px; }
.ad-note { font-size: 11px; color: var(--muted); }

/* ---------- LAB (strains) ---------- */
#lab-list { overflow-y: auto; min-height: 0; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 8px; }
.lab-row { display: flex; align-items: center; gap: 10px; background: #101013; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
.lab-row.locked { opacity: 0.4; }
.lab-ic { font-size: 20px; width: 30px; text-align: center; flex-shrink: 0; }
.lab-mid { flex: 1; min-width: 0; }
.lab-name { font-size: 13px; font-weight: 700; }
.lab-sub { font-size: 10.5px; color: var(--muted); }
.lab-act { border: 1px solid var(--line); border-radius: 8px; background: #15151a; color: var(--text); font-size: 11px; font-weight: 700; padding: 7px 11px; cursor: pointer; white-space: nowrap; }
.lab-act:disabled { opacity: 0.45; cursor: default; }
.lab-act.synth { border-color: #2c1f44; color: #b89cff; }

/* ---------- SETTINGS ---------- */
.set-label { font-size: 12px; font-weight: 700; color: var(--accent-soft); margin-bottom: 4px; }
.set-hint { font-size: 11px; color: var(--muted); margin-bottom: 10px; line-height: 1.5; }
#set-code { display: block; width: 100%; height: 70px; resize: vertical; box-sizing: border-box; background: #0a0a0c; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 11px; font-family: monospace; margin: 8px 0; }
#set-export, #set-import { display: block; width: 100%; margin-bottom: 8px; }
#set-msg { font-size: 11px; color: #7fe0a8; min-height: 16px; margin-top: 6px; }
#set-stats { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.stat-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); padding: 3px 2px; border-bottom: 1px solid #16161a; }
.stat-v { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
#set-close { display: block; width: 100%; margin-top: 10px; padding: 10px; background: #26262a; border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-size: 13px; cursor: pointer; }

/* ---------- DNA LAB (prestige perks) ---------- */
#dnalab-btn { display: block; width: 100%; margin-top: 6px; height: 34px; border: 1px solid #2c1f44; border-radius: 10px; background: #140f1e; color: #b89cff; font-size: 12px; font-weight: 700; cursor: pointer; }
#dnalab-list { overflow-y: auto; min-height: 0; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 8px; }
#dnalab-dna { color: #b89cff; }
#dnalab-close { display: block; width: 100%; margin-top: 10px; padding: 10px; background: #26262a; border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-size: 13px; cursor: pointer; }
