/* ==================== GENESIS — Idle Universe ==================== */
/* Mobile-first dark cosmic theme. 5-tab layout.                     */
/* ================================================================= */

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

:root {
  --bg:          #0a0a1a;
  --bg-card:     rgba(15, 15, 40, 0.85);
  --bg-card-hover: rgba(25, 25, 60, 0.9);
  --border:      rgba(100, 100, 255, 0.15);
  --text:        #e0e0f0;
  --text-dim:    #8888aa;
  --text-bright: #ffffff;
  --accent:      #66ccff;
  --accent-glow: rgba(102, 204, 255, 0.3);
  --gold:        #ffcc44;
  --gold-glow:   rgba(255, 204, 68, 0.3);
  --danger:      #ff4466;
  --success:     #44ff88;
  --purple:      #aa66ff;
  --purple-glow: rgba(170, 102, 255, 0.3);
  --nav-height: 56px;
  --header-height: 210px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* --- Stars --- */
#stars { position: fixed; inset: 0; z-index: 0; pointer-events: none; }

/* --- Popups --- */
.popup {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}
.popup.hidden { display: none; }
.popup-inner {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px;
  max-width: 320px; width: 90%; text-align: center;
}
.popup-wide { max-width: 360px; }
.popup-inner h3 { color: var(--accent); margin-bottom: 12px; font-size: 1.2rem; }
.popup-inner p { color: var(--text); margin-bottom: 16px; line-height: 1.5; }
.popup-buttons { display: flex; gap: 12px; justify-content: center; }
.choice-subtitle { font-size: 0.8rem; color: var(--text-dim); }

/* --- Choice options --- */
.choice-option {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 12px; padding: 12px;
  margin-bottom: 8px; display: flex;
  align-items: center; gap: 12px;
  cursor: pointer; transition: all 0.15s;
  text-align: left;
}
.choice-option:active { transform: scale(0.97); }
.choice-option:hover { border-color: var(--accent); background: rgba(102, 204, 255, 0.08); }
.choice-icon { font-size: 1.5rem; width: 36px; text-align: center; flex-shrink: 0; }
.choice-info { flex: 1; }
.choice-name { font-weight: 600; font-size: 0.95rem; color: var(--text-bright); }
.choice-desc { font-size: 0.75rem; color: var(--text-dim); margin-top: 2px; }

/* --- Buttons --- */
.btn-primary, .btn-secondary, .btn-danger, .btn-prestige {
  border: none; border-radius: 8px; padding: 10px 20px;
  font-size: 0.95rem; font-family: var(--font);
  cursor: pointer; transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: linear-gradient(135deg, #3366ff, #6633ff); color: white; }
.btn-primary:active { transform: scale(0.95); }
.btn-secondary { background: rgba(255, 255, 255, 0.1); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:active { transform: scale(0.95); }
.btn-danger { background: rgba(255, 68, 102, 0.2); color: var(--danger); border: 1px solid rgba(255, 68, 102, 0.3); }
.btn-prestige {
  background: linear-gradient(135deg, #aa66ff, #6633cc); color: white;
  font-size: 1.1rem; padding: 14px 28px; margin: 16px 0; width: 100%; max-width: 280px;
}
.btn-prestige:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-prestige:not(:disabled):active { transform: scale(0.95); }

/* --- Header --- */
#header {
  position: relative; z-index: 2;
  height: var(--header-height);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding-top: env(safe-area-inset-top, 0);
  user-select: none; -webkit-user-select: none;
}
#energy-display { text-align: center; margin-bottom: 4px; }
#energy-amount {
  font-family: var(--font-mono); font-size: 1.8rem; font-weight: 700;
  color: var(--accent); text-shadow: 0 0 20px var(--accent-glow);
  transition: text-shadow 0.1s; min-width: 200px;
}
#energy-amount.flash { text-shadow: 0 0 40px var(--accent); }
#energy-label { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 2px; }
#eps-display { font-family: var(--font-mono); font-size: 0.8rem; color: var(--text-dim); margin-top: 1px; }

/* Insight display in header */
#insight-display {
  font-size: 0.75rem; color: var(--gold); margin-top: 2px;
  display: flex; align-items: center; justify-content: center; gap: 4px;
}
#insight-icon { font-size: 0.85rem; }
#insight-amount { font-family: var(--font-mono); font-weight: 600; }
#insight-rate { font-family: var(--font-mono); font-size: 0.65rem; color: var(--text-dim); }

/* --- Click Orb --- */
#click-area { position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent; }

#orb {
  --orb-h: 200; --orb-s: 80%; --orb-l: 60%;
  --orb-glow: 20; --orb-spin: 12; --orb-ring: 0;
  width: 72px; height: 72px; border-radius: 50%;
  position: relative; transition: transform 0.1s ease;
  background: radial-gradient(circle at 35% 35%,
    hsla(var(--orb-h), var(--orb-s), calc(var(--orb-l) + 20%), 0.9),
    hsla(var(--orb-h), var(--orb-s), var(--orb-l), 0.7) 40%,
    hsla(var(--orb-h), 60%, 20%, 0.9) 70%,
    hsla(var(--orb-h), 40%, 8%, 1));
  box-shadow:
    0 0 calc(var(--orb-glow) * 1px) hsla(var(--orb-h), var(--orb-s), var(--orb-l), 0.4),
    0 0 calc(var(--orb-glow) * 3px) hsla(var(--orb-h), var(--orb-s), var(--orb-l), 0.15),
    inset 0 0 20px hsla(var(--orb-h), var(--orb-s), var(--orb-l), 0.25);
  animation: orbPulse 3s ease-in-out infinite;
}
#orb-inner {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 0deg,
    transparent 0%, hsla(var(--orb-h), var(--orb-s), 80%, 0.15) 15%,
    transparent 30%, hsla(var(--orb-h), var(--orb-s), 90%, 0.1) 50%,
    transparent 65%, hsla(var(--orb-h), var(--orb-s), 80%, 0.12) 80%,
    transparent 100%);
  animation: orbSpin calc(var(--orb-spin) * 1s) linear infinite;
}
#orb::before {
  content: ''; position: absolute; inset: 15%; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.35), transparent 55%);
  z-index: 2; pointer-events: none;
}
#orb::after {
  content: ''; position: absolute; inset: -12px; border-radius: 50%;
  border: 2px solid hsla(var(--orb-h), var(--orb-s), var(--orb-l), calc(var(--orb-ring) * 0.5));
  box-shadow: 0 0 8px hsla(var(--orb-h), var(--orb-s), var(--orb-l), calc(var(--orb-ring) * 0.3));
  animation: orbRing calc(var(--orb-spin) * 0.8s) linear infinite reverse;
  pointer-events: none; transform: rotateX(60deg);
}
#orb:active { transform: scale(0.9); }

/* Burst active: orb goes supernova */
#orb.burst-active {
  filter: brightness(1.5) saturate(1.3);
  animation: orbBurst 0.3s ease infinite alternate;
}
/* Combo active: green flash */
#orb.combo-active { filter: hue-rotate(90deg) brightness(1.2); }

#click-value {
  position: absolute; bottom: -3px; left: 50%; transform: translateX(-50%);
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-dim);
}

/* --- Burst bar --- */
#burst-bar {
  position: relative; width: 120px; height: 28px;
  margin-top: 6px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border); overflow: hidden;
}
#burst-fill {
  position: absolute; top: 0; left: 0; height: 100%; width: 0%;
  background: linear-gradient(90deg, rgba(102, 204, 255, 0.3), rgba(102, 204, 255, 0.5));
  transition: width 0.3s ease;
  border-radius: 14px;
}
#burst-btn {
  position: absolute; inset: 0; background: none; border: none;
  color: var(--text-dim); font-family: var(--font-mono);
  font-size: 0.7rem; font-weight: 700; cursor: pointer;
  z-index: 1; letter-spacing: 1px;
}
#burst-btn.ready { color: var(--accent); text-shadow: 0 0 10px var(--accent-glow); }
#burst-btn.active { color: var(--gold); text-shadow: 0 0 10px var(--gold-glow); animation: burstPulse 0.4s ease infinite alternate; }

/* --- Floating click text --- */
.click-float {
  position: fixed; font-family: var(--font-mono);
  font-size: 1rem; font-weight: 700; color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
  pointer-events: none; z-index: 100;
  animation: floatUp 0.8s ease-out forwards;
}
/* Critical click: gold, larger, slower fade */
.click-float.crit {
  font-size: 1.4rem; color: var(--gold);
  text-shadow: 0 0 15px var(--gold-glow);
  animation: floatUp 1.2s ease-out forwards;
}

/* --- Keyframes --- */
@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-60px) scale(0.7); }
}
@keyframes orbPulse {
  0%, 100% {
    box-shadow: 0 0 calc(var(--orb-glow)*1px) hsla(var(--orb-h),var(--orb-s),var(--orb-l),0.4),
                0 0 calc(var(--orb-glow)*3px) hsla(var(--orb-h),var(--orb-s),var(--orb-l),0.15),
                inset 0 0 20px hsla(var(--orb-h),var(--orb-s),var(--orb-l),0.25);
  }
  50% {
    box-shadow: 0 0 calc(var(--orb-glow)*1.5px) hsla(var(--orb-h),var(--orb-s),var(--orb-l),0.5),
                0 0 calc(var(--orb-glow)*4px) hsla(var(--orb-h),var(--orb-s),var(--orb-l),0.25),
                inset 0 0 25px hsla(var(--orb-h),var(--orb-s),var(--orb-l),0.3);
  }
}
@keyframes orbSpin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes orbRing { from { transform: rotateX(60deg) rotate(0deg); } to { transform: rotateX(60deg) rotate(360deg); } }
@keyframes orbBurst { from { transform: scale(1); } to { transform: scale(1.08); } }
@keyframes burstPulse { from { opacity: 1; } to { opacity: 0.6; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* --- Buy amount bar --- */
#buy-bar {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 5px 16px; background: rgba(10, 10, 30, 0.9);
  border-bottom: 1px solid var(--border);
}
.buy-label { font-size: 0.8rem; color: var(--text-dim); margin-right: 4px; }
.buy-amt {
  background: rgba(255,255,255,0.06); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 10px; font-size: 0.75rem;
  font-family: var(--font-mono); color: var(--text-dim);
  cursor: pointer; transition: all 0.15s;
}
.buy-amt.active { background: rgba(102,204,255,0.15); border-color: var(--accent); color: var(--accent); }
/* Auto-buy toggle: green when on, dim when off */
.buy-amt.autobuy { margin-left: 4px; border-color: rgba(68,255,136,0.3); color: var(--text-dim); }
.buy-amt.autobuy.active { background: rgba(68,255,136,0.15); border-color: var(--success); color: var(--success); }

/* --- Main content --- */
#main {
  position: relative; z-index: 2;
  height: calc(100vh - var(--header-height) - var(--nav-height) - 35px);
  overflow-y: auto; overflow-x: hidden;
  padding: 10px 10px calc(8px + env(safe-area-inset-bottom, 0));
  -webkit-overflow-scrolling: touch;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* --- Producer cards --- */
.producer-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px;
  margin-bottom: 6px; display: flex; align-items: center; gap: 10px;
  cursor: pointer; transition: all 0.15s;
  opacity: 0; max-height: 0; overflow: hidden;
  margin-bottom: 0; padding: 0 10px; border-width: 0;
  transition: all 0.4s ease;
}
.producer-card.unlocked {
  opacity: 1; max-height: 120px; margin-bottom: 6px; padding: 10px; border-width: 1px;
}
.producer-card.affordable { border-color: rgba(102,204,255,0.3); background: var(--bg-card-hover); }
.producer-card:active { transform: scale(0.98); }
.producer-card.locked {
  opacity: 0.35; max-height: 70px; margin-bottom: 6px;
  padding: 8px 10px; border-width: 1px; cursor: default;
}
.producer-emoji { font-size: 1.6rem; width: 36px; text-align: center; flex-shrink: 0; }
.producer-info { flex: 1; min-width: 0; }
.producer-name { font-weight: 600; font-size: 0.9rem; color: var(--text-bright); }
.producer-desc { font-size: 0.65rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.producer-synergy { font-size: 0.65rem; color: var(--gold); margin-top: 1px; }
.producer-eps { font-family: var(--font-mono); font-size: 0.7rem; color: var(--accent); margin-top: 1px; }
.producer-right { text-align: right; flex-shrink: 0; }
.producer-count { font-family: var(--font-mono); font-size: 1rem; font-weight: 700; color: var(--text-bright); }
.producer-cost { font-family: var(--font-mono); font-size: 0.75rem; color: var(--gold); white-space: nowrap; }
.producer-cost.too-expensive { color: var(--text-dim); }

/* --- Upgrades (choice display) --- */
.empty-msg { text-align: center; color: var(--text-dim); padding: 40px 20px; font-style: italic; }
.upgrade-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 6px;
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; transition: all 0.15s;
}
.upgrade-card.affordable { border-color: rgba(102,204,255,0.3); background: var(--bg-card-hover); }
.upgrade-card.purchased { opacity: 0.5; cursor: default; border-color: rgba(68,255,136,0.2); }
.upgrade-card:active:not(.purchased) { transform: scale(0.98); }
.upgrade-emoji { font-size: 1.3rem; width: 32px; text-align: center; flex-shrink: 0; }
.upgrade-info { flex: 1; min-width: 0; }
.upgrade-name { font-weight: 600; font-size: 0.85rem; color: var(--text-bright); }
.upgrade-desc { font-size: 0.7rem; color: var(--text-dim); margin-top: 1px; }
.upgrade-cost { font-family: var(--font-mono); font-size: 0.8rem; color: var(--gold); flex-shrink: 0; }
.upgrade-cost.too-expensive { color: var(--text-dim); }

/* --- Research tree --- */
#research-header {
  text-align: center; padding: 12px 0 8px;
  font-size: 1.2rem; color: var(--gold);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
#research-insight-val { font-family: var(--font-mono); font-weight: 700; }
#research-branches { display: flex; flex-direction: column; gap: 16px; }

.research-branch {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px; overflow: hidden;
}
.branch-header {
  font-weight: 700; font-size: 0.95rem; margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px;
}
.branch-icon { font-size: 1.1rem; }
.branch-desc { font-size: 0.7rem; color: var(--text-dim); font-weight: 400; margin-left: auto; }

.research-node {
  position: relative; padding: 8px 10px; margin-bottom: 4px;
  border-radius: 8px; cursor: pointer;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  transition: all 0.15s; opacity: 0.5;
}
.research-node.affordable {
  opacity: 1; border-color: var(--accent);
  background: rgba(102,204,255,0.08);
}
.research-node.purchased {
  opacity: 1; border-color: rgba(68,255,136,0.3);
  background: rgba(68,255,136,0.06);
}
.research-node.purchased .node-cost { color: var(--success); }
.research-node.locked { opacity: 0.3; cursor: not-allowed; }
.research-node:active:not(.purchased):not(.locked) { transform: scale(0.98); }

.node-connector {
  position: absolute; left: 18px; top: -6px;
  width: 2px; height: 6px; background: rgba(255,255,255,0.1);
}
.research-node:first-of-type .node-connector { display: none; }

.node-body { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.node-name { font-weight: 600; font-size: 0.85rem; color: var(--text-bright); }
.node-desc { font-size: 0.7rem; color: var(--text-dim); width: 100%; }
.node-cost { font-family: var(--font-mono); font-size: 0.75rem; color: var(--gold); margin-left: auto; }

/* --- Prestige tab --- */
#prestige-info { text-align: center; padding: 16px 0; }
#dust-display { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 10px; }
#dust-icon { font-size: 1.4rem; color: var(--purple); text-shadow: 0 0 10px var(--purple-glow); }
#dust-amount { font-family: var(--font-mono); font-size: 1.6rem; font-weight: 700; color: var(--purple); text-shadow: 0 0 15px var(--purple-glow); }
.dust-label { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
#dust-bonus, #prestige-preview { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 6px; }
#prestige-preview { color: var(--purple); }

.prestige-upgrade-card {
  background: var(--bg-card); border: 1px solid rgba(170,102,255,0.2);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 6px;
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; transition: all 0.15s;
}
.prestige-upgrade-card.affordable { border-color: rgba(170,102,255,0.5); background: rgba(170,102,255,0.08); }
.prestige-upgrade-card.purchased { opacity: 0.5; cursor: default; border-color: rgba(68,255,136,0.2); }
.prestige-upgrade-card:active:not(.purchased) { transform: scale(0.98); }
.prestige-cost { font-family: var(--font-mono); font-size: 0.8rem; color: var(--purple); flex-shrink: 0; }

/* --- Section titles --- */
.section-title {
  font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 2px; margin: 16px 0 10px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}

/* --- Achievements --- */
.achievement {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; margin-bottom: 5px;
  display: flex; align-items: center; gap: 8px;
  opacity: 0.35; transition: opacity 0.3s;
}
.achievement.unlocked { opacity: 1; border-color: rgba(255,204,68,0.3); }
.achievement-emoji { font-size: 1.2rem; width: 28px; text-align: center; }
.achievement-info { flex: 1; }
.achievement-name { font-weight: 600; font-size: 0.8rem; color: var(--text-bright); }
.achievement-desc { font-size: 0.65rem; color: var(--text-dim); }

.achievement-toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(15,15,40,0.95); border: 1px solid rgba(255,204,68,0.4);
  border-radius: 12px; padding: 10px 18px;
  display: flex; align-items: center; gap: 8px;
  z-index: 500; animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  box-shadow: 0 0 20px var(--gold-glow);
}
.toast-emoji { font-size: 1.3rem; }
.toast-text { font-size: 0.8rem; color: var(--gold); font-weight: 600; }
@keyframes toastIn { from { opacity:0; transform: translateX(-50%) translateY(-20px); } to { opacity:1; transform: translateX(-50%) translateY(0); } }
@keyframes toastOut { from { opacity:1; } to { opacity:0; } }

/* --- Stats --- */
.stat-row {
  display: flex; justify-content: space-between;
  padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.8rem;
}
.stat-label { color: var(--text-dim); }
.stat-value { color: var(--text-bright); font-family: var(--font-mono); }

#save-controls {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; justify-content: center;
}
#save-controls button { flex: 1; min-width: 65px; }

/* --- Bottom navigation (5 tabs) --- */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  height: var(--nav-height);
  display: flex; background: rgba(8,8,24,0.95);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; color: var(--text-dim);
  font-family: var(--font); cursor: pointer; transition: color 0.15s;
  position: relative; -webkit-tap-highlight-color: transparent;
}
.nav-btn.active { color: var(--accent); }
.nav-icon { font-size: 1.1rem; }
.nav-label { font-size: 0.55rem; text-transform: uppercase; letter-spacing: 0.5px; }
.badge {
  position: absolute; top: 4px; right: calc(50% - 18px);
  background: var(--danger); color: white;
  font-size: 0.55rem; font-weight: 700; padding: 1px 4px;
  border-radius: 8px; min-width: 14px; text-align: center;
}
.badge.hidden { display: none; }

/* --- Scrollbar --- */
#main::-webkit-scrollbar { width: 3px; }
#main::-webkit-scrollbar-track { background: transparent; }
#main::-webkit-scrollbar-thumb { background: rgba(102,204,255,0.2); border-radius: 2px; }

.hidden { display: none !important; }

/* --- Responsive --- */
@media (min-width: 600px) {
  :root { --header-height: 180px; }
  #main { max-width: 500px; margin: 0 auto; }
  #orb { width: 65px; height: 65px; }
  #energy-amount { font-size: 2.2rem; }
  #research-branches { flex-direction: row; gap: 10px; }
  .research-branch { flex: 1; }
}
@media (max-height: 600px) {
  :root { --header-height: 155px; }
  #orb { width: 55px; height: 55px; }
  #energy-amount { font-size: 1.5rem; }
}
