/* Idle Space Mining — dark sci-fi theme */
:root {
  --bg: #05060e;
  --panel: rgba(15, 18, 34, 0.82);
  --panel-solid: #10131f;
  --border: rgba(255, 255, 255, 0.08);
  --text: #dfe6f2;
  --dim: #8b94a8;
  --accent: #37e0ff;
  --purple: #a56bff;
  --gold: #ffd54a;
  --good: #54ffb0;
  --bad: #ff5a6e;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation; /* no double-tap zoom while rapid-clicking the planet */
}

button, .tab-btn, .buy-row, canvas, #topbar, .res-row, .planet-card, .ach-cell {
  user-select: none;
  -webkit-user-select: none;
}

button { font-family: inherit; cursor: pointer; }

#app { display: flex; flex-direction: column; height: 100vh; }

/* ------------------------------------------------ topbar */
#topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 16px;
  background: linear-gradient(180deg, rgba(20, 24, 44, 0.95), rgba(12, 14, 26, 0.95));
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-icon { font-size: 22px; }
.brand-name {
  font-weight: 800;
  letter-spacing: 2.5px;
  font-size: 13px;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.top-stats { display: flex; gap: 14px; flex: 1; flex-wrap: wrap; }
.top-stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.ts-icon { font-size: 14px; }
.ts-val { font-weight: 700; font-size: 15px; }
.ts-sub { color: var(--good); font-size: 11px; }
.buy-amount { display: flex; gap: 4px; }
.amt-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--dim);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.15s;
}
.amt-btn:hover { color: var(--text); border-color: var(--accent); }
.amt-btn.active {
  color: #061018;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(55, 224, 255, 0.4);
}

/* ------------------------------------------------ layout */
#layout {
  display: grid;
  grid-template-columns: minmax(340px, 42%) 1fr;
  flex: 1;
  min-height: 0;
}
#left {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-height: 0;
  min-width: 0; /* never let content force the grid track wider than the viewport */
  position: relative;
}
#scene-wrap { flex: 1 1 45%; min-height: 240px; position: relative; overflow: hidden; }
#scene { display: block; cursor: crosshair; }
#scene:active { cursor: grabbing; }
#right { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

/* ------------------------------------------------ event banner */
.event-banner {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  backdrop-filter: blur(6px);
  animation: slideDown 0.3s ease;
}
.ev-good { background: rgba(84, 255, 176, 0.12); border: 1px solid rgba(84, 255, 176, 0.4); }
.ev-bad { background: rgba(255, 90, 110, 0.12); border: 1px solid rgba(255, 90, 110, 0.4); }
.ev-timer { font-weight: 700; font-variant-numeric: tabular-nums; }
@keyframes slideDown { from { transform: translateY(-16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ------------------------------------------------ planet info + resources */
#planet-info {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.pi-name { font-weight: 700; font-size: 15px; }
.pi-mult { color: var(--accent); font-size: 12px; font-weight: 600; margin-left: 6px; }
.pi-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.pi-rates { display: flex; gap: 16px; color: var(--dim); font-size: 12px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 11px;
  color: var(--dim);
}
.chip.sm { padding: 1px 7px; font-size: 10px; }
.res-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

#resources-panel {
  flex: 0 1 auto;
  overflow-y: auto;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  max-height: 34%;
}
.res-empty { color: var(--dim); font-size: 12px; padding: 8px 0; }
.res-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 13px;
}
.res-name { color: var(--dim); flex: 1; }
.res-amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.badge-auto, .badge-online {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 2px 7px;
  border-radius: 20px;
  background: rgba(84, 255, 176, 0.15);
  color: var(--good);
  border: 1px solid rgba(84, 255, 176, 0.4);
  vertical-align: middle;
}

/* ------------------------------------------------ tabs */
#tabs {
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  background: rgba(10, 12, 24, 0.9);
}
#tabs::-webkit-scrollbar { height: 0; }
.tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--dim);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.tab-btn.active {
  color: var(--accent);
  background: rgba(55, 224, 255, 0.1);
  border-color: rgba(55, 224, 255, 0.35);
  box-shadow: 0 0 14px rgba(55, 224, 255, 0.15);
}

/* ------------------------------------------------ panel content */
#panel { flex: 1; overflow-y: auto; padding: 14px 16px 40px; }
#panel::-webkit-scrollbar, #resources-panel::-webkit-scrollbar { width: 8px; }
#panel::-webkit-scrollbar-thumb, #resources-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}
.panel-section { margin-bottom: 20px; }
.panel-title {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}
.panel-sub { color: var(--dim); font-size: 12px; margin: 6px 0 10px; line-height: 1.5; }

.buy-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  margin-bottom: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: border-color 0.15s, transform 0.1s;
}
.buy-row:hover { border-color: rgba(55, 224, 255, 0.3); }
.br-icon { font-size: 22px; width: 30px; text-align: center; flex-shrink: 0; }
.br-body { flex: 1; min-width: 0; }
.br-name { font-weight: 700; font-size: 13.5px; }
.br-count { color: var(--accent); font-size: 11.5px; font-weight: 600; margin-left: 4px; }
.br-desc { color: var(--dim); font-size: 11.5px; margin-top: 2px; line-height: 1.4; }
.buy-row.owned { opacity: 0.75; border-color: rgba(84, 255, 176, 0.25); }
.buy-row.locked { opacity: 0.45; }

.btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn:hover:not(:disabled) { border-color: var(--accent); box-shadow: 0 0 10px rgba(55, 224, 255, 0.25); }
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-buy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 86px;
  background: linear-gradient(180deg, rgba(55, 224, 255, 0.16), rgba(55, 224, 255, 0.06));
  border-color: rgba(55, 224, 255, 0.3);
}
.bb-label { font-size: 10px; letter-spacing: 0.5px; color: var(--dim); }
.bb-cost { font-size: 12px; color: var(--accent); }
.btn-buy:disabled .bb-cost { color: var(--bad); }
.btn-sell {
  width: 100%;
  margin-top: 8px;
  background: linear-gradient(180deg, rgba(255, 213, 74, 0.18), rgba(255, 213, 74, 0.06));
  border-color: rgba(255, 213, 74, 0.35);
  color: var(--gold);
}
.btn-sell:hover:not(:disabled) { border-color: var(--gold); box-shadow: 0 0 12px rgba(255, 213, 74, 0.3); }
.btn-danger { border-color: rgba(255, 90, 110, 0.4); color: var(--bad); }
.btn-danger:hover:not(:disabled) { border-color: var(--bad); box-shadow: 0 0 10px rgba(255, 90, 110, 0.3); }
.btn-prestige {
  background: linear-gradient(90deg, rgba(165, 107, 255, 0.25), rgba(55, 224, 255, 0.2));
  border-color: var(--purple);
  color: #fff;
  font-size: 14px;
  padding: 12px 24px;
  letter-spacing: 1px;
}
.btn-prestige:hover:not(:disabled) { box-shadow: 0 0 20px rgba(165, 107, 255, 0.5); }

/* ------------------------------------------------ energy */
.energy-box { padding: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 12px; }
.energy-nums { font-size: 12.5px; color: var(--dim); margin-bottom: 8px; }
.energy-bar { height: 8px; background: rgba(255, 255, 255, 0.07); border-radius: 4px; overflow: hidden; }
.energy-fill { height: 100%; width: 0; background: var(--good); border-radius: 4px; transition: width 0.3s, background 0.3s; }

/* ------------------------------------------------ planets */
.planet-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  transition: border-color 0.2s;
}
.planet-card.current { border-color: rgba(55, 224, 255, 0.5); box-shadow: 0 0 16px rgba(55, 224, 255, 0.12); }
.planet-card.locked-card { opacity: 0.65; }
.pc-orb { width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0; }
.pc-body { flex: 1; min-width: 0; }
.pc-name { font-weight: 700; }
.pc-desc { color: var(--dim); font-size: 11.5px; margin: 3px 0 6px; }
.pc-dist { display: flex; gap: 4px; flex-wrap: wrap; }
.pc-action { flex-shrink: 0; }

/* ------------------------------------------------ prestige */
.prestige-box {
  padding: 18px;
  background: linear-gradient(135deg, rgba(165, 107, 255, 0.08), rgba(55, 224, 255, 0.05));
  border: 1px solid rgba(165, 107, 255, 0.3);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pr-stat { font-size: 14px; }

/* ------------------------------------------------ achievements */
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.ach-cell {
  padding: 10px 8px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  opacity: 0.35;
  filter: grayscale(1);
  transition: all 0.3s;
}
.ach-cell.unlocked {
  opacity: 1;
  filter: none;
  border-color: rgba(255, 213, 74, 0.45);
  box-shadow: 0 0 12px rgba(255, 213, 74, 0.12);
}
.ach-icon { font-size: 20px; }
.ach-name { font-size: 10.5px; font-weight: 600; margin-top: 4px; color: var(--dim); }
.ach-cell.unlocked .ach-name { color: var(--gold); }

/* ------------------------------------------------ stats & settings */
.stats-list { display: flex; flex-direction: column; }
.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 13px;
}
.stat-row span { color: var(--dim); }
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.setting-row input[type=range] { width: 160px; accent-color: var(--accent); }
.setting-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.settings-btns { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.save-area {
  user-select: text;
  -webkit-user-select: text;
  width: 100%;
  height: 110px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: monospace;
  font-size: 11px;
  padding: 8px;
  resize: vertical;
  margin: 8px 0;
}

/* ------------------------------------------------ mission */
.mission-active { padding: 14px; background: var(--panel); border: 1px solid rgba(55, 224, 255, 0.3); border-radius: 12px; display: flex; flex-direction: column; gap: 8px; }

/* ------------------------------------------------ toasts */
#toasts {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  max-width: 360px;
  pointer-events: none;
}
.toast {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.45;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateX(24px);
  transition: all 0.35s cubic-bezier(0.2, 0.8, 0.3, 1.1);
}
.toast.show { opacity: 1; transform: none; }
.toast.good { border-color: rgba(84, 255, 176, 0.45); }
.toast.bad { border-color: rgba(255, 90, 110, 0.5); }
.toast.gold { border-color: rgba(255, 213, 74, 0.55); box-shadow: 0 0 18px rgba(255, 213, 74, 0.15), 0 6px 24px rgba(0,0,0,.5); }
.toast.info { border-color: rgba(55, 224, 255, 0.35); }

/* ------------------------------------------------ modal */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(3, 4, 10, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--panel-solid);
  border: 1px solid rgba(55, 224, 255, 0.25);
  border-radius: 16px;
  padding: 24px;
  max-width: 480px;
  width: calc(100% - 32px);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), 0 0 40px rgba(55, 224, 255, 0.08);
  animation: popIn 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes popIn { from { transform: scale(0.9); opacity: 0; } }
.modal h2 { font-size: 17px; margin-bottom: 12px; }
.modal p { color: var(--dim); font-size: 13px; line-height: 1.6; margin-bottom: 10px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; }
.offline-gains {
  padding: 12px 16px;
  background: rgba(55, 224, 255, 0.06);
  border: 1px solid rgba(55, 224, 255, 0.2);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13.5px;
}

/* ------------------------------------------------ tutorial & help */
#tutorial-card {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 90;
  width: 300px;
  max-width: calc(100vw - 32px);
  background: var(--panel-solid);
  border: 1px solid rgba(55, 224, 255, 0.4);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.6), 0 0 22px rgba(55, 224, 255, 0.12);
  animation: slideDown 0.3s ease;
}
.tut-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tut-tag {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--accent);
  background: rgba(55, 224, 255, 0.1);
  border: 1px solid rgba(55, 224, 255, 0.3);
  padding: 2px 8px;
  border-radius: 20px;
}
.tut-skip {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 11px;
  padding: 2px 4px;
}
.tut-skip:hover { color: var(--text); }
.tut-body { display: flex; gap: 10px; align-items: flex-start; }
.tut-icon { font-size: 24px; animation: tutBounce 1.6s ease-in-out infinite; }
@keyframes tutBounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.tut-title { font-weight: 700; font-size: 13.5px; margin-bottom: 3px; }
.tut-text { color: var(--dim); font-size: 12px; line-height: 1.5; }
.tut-text b { color: var(--accent); }

.tab-btn.tab-pulse {
  border-color: rgba(55, 224, 255, 0.6);
  animation: tabPulse 1.2s ease-in-out infinite;
}
@keyframes tabPulse {
  0%, 100% { box-shadow: 0 0 4px rgba(55, 224, 255, 0.2); }
  50% { box-shadow: 0 0 16px rgba(55, 224, 255, 0.55); }
}

.help-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  transition: all 0.15s;
}
.help-btn:hover { border-color: var(--accent); box-shadow: 0 0 10px rgba(55, 224, 255, 0.25); }

.help-guide h3 { font-size: 13px; color: var(--accent); margin: 14px 0 4px; }
.help-guide h3:first-child { margin-top: 0; }
.help-guide p { color: var(--dim); font-size: 12.5px; line-height: 1.6; margin-bottom: 4px; }
.help-guide b { color: var(--text); }

@media (max-width: 900px) {
  #tutorial-card {
    bottom: calc(12px + env(safe-area-inset-bottom));
    left: 12px;
    width: 260px;
  }
}

/* ------------------------------------------------ tooltip */
#tooltip {
  position: fixed;
  display: none;
  z-index: 300;
  background: var(--panel-solid);
  border: 1px solid rgba(55, 224, 255, 0.3);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  max-width: 280px;
  pointer-events: none;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}

/* ------------------------------------------------ responsive */
@media (max-width: 900px) {
  html, body { overflow: auto; }
  #app { height: auto; min-height: 100vh; }
  #layout { grid-template-columns: 1fr; }
  #left { border-right: none; border-bottom: 1px solid var(--border); }
  #scene-wrap { min-height: 260px; height: 38vh; }
  #resources-panel { max-height: 200px; }
  #panel { padding: 12px 10px calc(90px + env(safe-area-inset-bottom)); }

  /* Compact sticky topbar */
  #topbar {
    position: sticky;
    top: 0;
    padding: 6px 10px;
    padding-top: calc(6px + env(safe-area-inset-top));
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  #topbar::-webkit-scrollbar { display: none; }
  .brand { gap: 0; }
  .brand-name { display: none; }
  .brand-icon { font-size: 20px; }
  .top-stats { gap: 6px; flex-wrap: nowrap; }
  .top-stat { padding: 4px 8px; border-radius: 8px; white-space: nowrap; }
  .ts-val { font-size: 13px; }
  .ts-sub { display: none; }
  .amt-btn { padding: 5px 8px; font-size: 11px; }
  .help-btn { padding: 4px 9px; }

  /* Sticky tab bar with bigger touch targets */
  #tabs {
    position: sticky;
    top: 46px;
    z-index: 4;
    padding: 6px 8px;
  }
  .tab-name { display: none; }
  .tab-btn { padding: 10px 13px; font-size: 17px; }

  /* Bigger touch targets */
  .btn { padding: 10px 14px; }
  .btn-buy { min-width: 92px; }
  .buy-row { padding: 10px 12px; }

  /* Toasts on top so they never cover the tutorial card or buy buttons */
  #toasts {
    top: calc(env(safe-area-inset-top) + 56px);
    bottom: auto;
    right: 8px;
    left: 8px;
    max-width: none;
    align-items: flex-end;
  }
  .toast { max-width: 320px; }

  .modal { padding: 18px; max-height: 85vh; }
  .settings-btns .btn { flex: 1 1 40%; }
}
