:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #334155;
  --border: #334155;
  --text: #e2e8f0;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --good: #4ade80;
  --bad: #f87171;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  background: var(--panel);
  padding: 16px 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
header h1 { margin: 0 0 8px; font-size: 1.6rem; }

#money { margin: 6px 0 12px; font-size: 22px; font-weight: 600; }

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.header-buttons { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

#collect-egg {
  padding: 10px 22px;
  font-size: 18px;
  font-weight: 600;
  background: var(--accent);
}

main { padding: 16px 20px; }

#structures {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.item {
  background: var(--panel);
  padding: 14px;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  border: 1px solid var(--border);
}
.item-head { display: flex; justify-content: space-between; align-items: baseline; }
.item-head .qty { color: #94a3b8; font-weight: 600; }
.item .rate { margin: 8px 0 6px; font-size: 14px; color: #cbd5e1; min-height: 1.2em; }
.item .milestone {
  margin: 0 0 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: #fbbf24;
}
.item .milestone .ms-next { color: #94a3b8; font-weight: 500; }
.item-actions { display: flex; gap: 8px; }
.item-actions button { flex: 1; }

/* Buttons */
button {
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.95rem;
  transition: background 0.15s, opacity 0.15s;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.on { background: var(--good); color: #06210f; }

/* Equipped section */
#equipped-section {
  padding: 16px 20px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
#equipped-section h2 { margin: 0 0 12px; font-size: 1.2rem; }
.equipped-slots { display: flex; gap: 24px; flex-wrap: wrap; }
.slot { text-align: center; min-width: 90px; }
.slot-label { font-size: 13px; color: #94a3b8; margin-bottom: 4px; }
.slot img { display: block; margin: 0 auto 4px; border-radius: 8px; background: var(--panel-2); }
.equip-icon { display: flex; align-items: center; justify-content: center; margin: 0 auto 4px; min-height: 64px; }
.equip-icon img { margin: 0; }
.item-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  border-radius: 6px;
  flex-shrink: 0;
  line-height: 1;
}
.reset-btn { margin-top: 16px; background: #475569; font-size: 0.85rem; }
.reset-btn:hover:not(:disabled) { background: var(--bad); color: #1a0606; }

/* Side panels (shop + inventory) */
.side-panel {
  position: fixed;
  right: 0;
  top: 60px;
  width: 340px;
  max-width: 90vw;
  height: calc(100% - 60px);
  background: var(--panel);
  border-left: 2px solid var(--accent);
  padding: 16px;
  overflow-y: auto;
  box-shadow: -2px 0 12px rgba(0,0,0,0.5);
  transform: translateX(110%);
  transition: transform 0.25s ease;
  z-index: 900;
}
.side-panel.open { transform: translateX(0); }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel-head h2, .panel-head h3 { margin: 0; }
.panel-hint { color: #94a3b8; font-size: 13px; margin: 6px 0 14px; }

/* Shop items */
.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 10px;
}
.shop-item.owned { opacity: 0.55; }
.shop-item img, .inventory-item img { border-radius: 6px; flex-shrink: 0; }
.shop-info, .inv-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.shop-type { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.5px; }
.shop-item button { flex-shrink: 0; white-space: nowrap; }
.bonus { color: var(--good); font-size: 12px; }
.penalty { color: var(--bad); font-size: 12px; }
.rare-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.5);
  border-radius: 4px;
  padding: 0 5px;
}

/* Inventory items */
.inventory-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 10px;
}
.inventory-item.equipped { border: 1px solid var(--good); }
.inventory-item button { flex-shrink: 0; }
#inventory .empty { color: #94a3b8; font-size: 14px; }

/* Achievements popup */
#achievements-popup {
  position: fixed;
  top: 10%;
  left: 50%;
  transform: translateX(-50%) scale(0.96);
  width: 90%;
  max-width: 420px;
  max-height: 75%;
  overflow-y: auto;
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#achievements-popup.open { opacity: 1; transform: translateX(-50%) scale(1); pointer-events: auto; }
#achievements-list { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.achievement {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 10px;
  background: var(--panel-2);
  border-radius: 8px;
  opacity: 0.45;
  transition: opacity 0.3s ease;
}
.achievement { cursor: pointer; }
.achievement:hover { background: #3d4d63; }
.achievement.unlocked { opacity: 1; border: 1px solid var(--good); }
.badge-img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.badge-emoji {
  width: 56px; height: 56px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; border-radius: 6px; background: var(--bg);
}
.badge-img-big { width: 160px; height: 160px; object-fit: cover; border-radius: 12px; }
.badge-emoji-big {
  width: 160px; height: 160px; margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 90px; border-radius: 12px; background: var(--bg);
}

/* Badge detail modal */
#badge-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 1300;
  padding: 20px;
}
#badge-modal.open { opacity: 1; pointer-events: auto; }
.badge-modal-content {
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 14px;
  padding: 24px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  transform: scale(0.92);
  transition: transform 0.2s;
}
#badge-modal.open .badge-modal-content { transform: scale(1); }
#badge-modal.is-locked .badge-modal-content .badge-img-big,
#badge-modal.is-locked .badge-modal-content .badge-emoji-big { opacity: 0.4; }
.badge-modal-content h3 { margin: 16px 0 6px; font-size: 1.3rem; }
.badge-modal-content p { margin: 6px 0; color: #cbd5e1; }
.badge-modal-progress { font-size: 0.9rem; color: #94a3b8 !important; }
.badge-status { display: inline-block; margin: 10px 0 16px; font-weight: 600; }
.badge-status.unlocked { color: var(--good); }
.badge-status.locked { color: #94a3b8; }

/* Achievement unlocked banner — slides up across the bottom */
#achievement-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 24px;
  background: linear-gradient(90deg, #14532d, var(--panel));
  border-top: 3px solid var(--good);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
  transform: translateY(110%);
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 1250;
}
#achievement-banner.show { transform: translateY(0); }
#achievement-banner .badge-img-big,
#achievement-banner .badge-emoji-big { width: 72px; height: 72px; font-size: 40px; border-radius: 10px; }
#achievement-banner .ab-label { font-size: 0.85rem; color: var(--good); letter-spacing: 0.5px; }
#achievement-banner #achievement-banner-name { font-size: 1.4rem; font-weight: 700; margin-top: 2px; }

/* Offline popup */
.popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--panel-2);
  border: 2px solid var(--accent);
  padding: 20px 30px;
  border-radius: 12px;
  box-shadow: 0 0 20px rgba(0,0,0,0.6);
  font-size: 18px;
  text-align: center;
  z-index: 1100;
}

/* Toast */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-2);
  border: 1px solid var(--good);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 10px;
  font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 1200;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Active effects strip (weather + boosts) */
#active-effects { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 20px 0; }
#active-effects:empty { padding: 0; }
.fx { font-size: 13px; font-weight: 600; padding: 4px 11px; border-radius: 999px; }
.fx.good { background: rgba(74,222,128,0.15); color: var(--good); border: 1px solid rgba(74,222,128,0.5); }
.fx.bad { background: rgba(248,113,113,0.15); color: var(--bad); border: 1px solid rgba(248,113,113,0.5); }
.fx.boost { background: rgba(251,191,36,0.15); color: #fbbf24; border: 1px solid rgba(251,191,36,0.5); }
.fx.calm { background: rgba(148,163,184,0.12); color: #94a3b8; border: 1px solid rgba(148,163,184,0.4); }

/* Golden egg */
.golden-egg {
  position: fixed;
  z-index: 1150;
  font-size: 34px;
  width: 60px; height: 60px;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 30%, #fef3c7, #f59e0b);
  border: 2px solid #fde68a;
  border-radius: 50%;
  box-shadow: 0 0 18px 5px rgba(251, 191, 36, 0.85);
  cursor: pointer;
  animation: eggPulse 1s ease-in-out infinite;
}
.golden-egg:hover { background: radial-gradient(circle at 30% 30%, #fffbeb, #fbbf24); }
.golden-egg[hidden] { display: none; }
@keyframes eggPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.14); } }

/* Event modals (minigame + merchant) */
.game-modal {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,0.75);
  z-index: 1300; padding: 20px;
}
.game-modal.open { display: flex; }
.mg-content {
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 14px;
  padding: 24px;
  text-align: center;
  max-width: 360px; width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}
.mg-content h3 { margin: 0 0 8px; font-size: 1.3rem; }
.mg-content p { color: #cbd5e1; margin: 6px 0; }
.nests { display: flex; gap: 14px; justify-content: center; margin: 18px 0; }
.nest { font-size: 42px; width: 84px; height: 84px; background: var(--panel-2); border: 2px solid var(--border); border-radius: 12px; }
.nest:hover:not(:disabled) { border-color: var(--accent); }
.merchant-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.mg-win { color: var(--good); font-size: 1.2rem; font-weight: 700; margin-top: 14px; }
.mg-lose { color: var(--bad); font-weight: 700; margin-top: 10px; }
#mg-result { margin-top: 10px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.timing-track { position: relative; height: 28px; background: var(--panel-2); border-radius: 8px; margin: 20px 0; overflow: hidden; }
.timing-green { position: absolute; left: 40%; width: 20%; top: 0; bottom: 0; background: rgba(74,222,128,0.4); border-left: 2px solid var(--good); border-right: 2px solid var(--good); }
.timing-marker { position: absolute; top: -2px; width: 6px; height: 32px; background: #fde68a; border-radius: 3px; left: 0; }

/* Per-structure multiplier tooltip */
.mult-tooltip {
  position: fixed;
  z-index: 1250;
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  max-width: 250px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.55);
}
.mult-tooltip[hidden] { display: none; }
.mt-title { font-weight: 700; margin-bottom: 4px; }
.mt-row { display: flex; justify-content: space-between; gap: 16px; padding: 1px 0; color: #cbd5e1; }
.mt-row .pos { color: var(--good); font-weight: 600; }
.mt-row .neg { color: var(--bad); font-weight: 600; }
.mt-net { margin-top: 5px; padding-top: 5px; border-top: 1px solid var(--border); font-weight: 700; text-align: right; }

/* Active Boosts panel rows */
.bp-h { font-size: 0.9rem; color: #94a3b8; margin: 16px 0 8px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.bp-row { display: flex; align-items: center; gap: 10px; background: var(--panel-2); padding: 8px 10px; border-radius: 8px; margin-bottom: 8px; }
.bp-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.bp-time { font-size: 12px; color: #94a3b8; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.empty { color: #94a3b8; font-size: 14px; }

/* How to Play modal content */
#info-modal .info-content.howto {
  text-align: left;
  max-width: 480px;
  max-height: 82vh;
  overflow-y: auto;
  border: 2px solid var(--accent);
}
#info-modal h2 { margin: 0 0 14px; text-align: center; font-size: 1.4rem; }
#info-modal h3 { margin: 16px 0 4px; font-size: 1rem; color: #93c5fd; }
#info-modal p { margin: 4px 0; line-height: 1.5; color: #cbd5e1; font-size: 0.95rem; }
#info-modal p strong { color: #e2e8f0; }
.howto-close { margin-top: 18px; width: 100%; }

/* Prestige */
#prestige-btn.ready {
  background: linear-gradient(135deg, #f59e0b, #ec4899);
  color: #fff;
  animation: prestige-pulse 1.6s ease-in-out infinite;
}
@keyframes prestige-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(236, 72, 153, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(236, 72, 153, 0); }
}
.prestige-summary {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
}
.prestige-summary > div {
  flex: 1;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.prestige-summary small { color: #94a3b8; font-size: 12px; }
.ribbon-count { font-size: 1.4rem; font-weight: 700; color: #f9a8d4; }
.upg-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 8px;
}
.upg-row.maxed { opacity: 0.7; }
.upg-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.upg-desc { font-size: 12.5px; color: #cbd5e1; }
.upg-level { font-size: 12px; color: #94a3b8; font-variant-numeric: tabular-nums; }
.upg-row button { flex-shrink: 0; min-width: 64px; }
.prestige-go {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 700;
  background: linear-gradient(135deg, #f59e0b, #ec4899);
}
.prestige-go:disabled {
  background: var(--panel-2);
  color: #94a3b8;
  cursor: not-allowed;
}

/* Processing (Stage 2) */
#processors-section { padding: 0 20px 8px; }
#processors-section h2 { margin: 8px 0 4px; font-size: 1.2rem; }
#processors-section .panel-hint { margin: 0 0 12px; }
#processors {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.item.locked { opacity: 0.6; border-style: dashed; }
.item.locked .rate { color: #f59e0b; }

/* Managers */
.item [data-manager].on { background: #16a34a; }
.item [data-collect] { background: var(--accent); }

/* Packaging (Stage 3) */
#packaging-section { padding: 0 20px 8px; }
#packaging-section h2 { margin: 8px 0 4px; font-size: 1.2rem; }
#packaging-section .panel-hint { margin: 0 0 12px; }
#packaging {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

/* Shipping (Stage 4) */
#shipping-section { padding: 0 20px 8px; }
#shipping-section h2 { margin: 8px 0 4px; font-size: 1.2rem; }
#shipping-section .panel-hint { margin: 0 0 12px; }
#shipping {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.prestige-reqs { margin: 6px 0 12px; padding-left: 20px; color: #cbd5e1; font-size: 13px; }
.prestige-reqs li { margin: 4px 0; }

/* Space (Stage 5) */
#space-section { padding: 0 20px 8px; }
#space-section h2 { margin: 8px 0 4px; font-size: 1.2rem; }
#space-section .panel-hint { margin: 0 0 12px; }
#space {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

/* Cargo Rockets HUD */
#cargo-hud { margin: -6px 0 12px; font-size: 15px; font-weight: 600; color: #c4b5fd; }
#cargo-hud #cargo-count { color: #e2e8f0; }

/* ---- Mission Control (Space market) ------------------------------------ */
#mission-orders {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.mission-empty {
  color: #94a3b8;
  font-style: italic;
  margin: 4px 0;
}
.order-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 220px;
  flex: 1 1 220px;
  max-width: 340px;
}
.order-card.short { opacity: 0.75; }
.order-planet { margin-bottom: 4px; }
.order-reward { font-size: 0.9em; color: var(--good); margin-bottom: 8px; }
.order-card.short .order-reward { color: var(--text); }
.order-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.order-timer { font-size: 0.85em; color: #94a3b8; }
