:root {
  --bg: #0a0a12;
  --panel: rgba(22, 20, 38, 0.72);
  --panel-line: rgba(140, 110, 255, 0.16);
  --violet: #a970ff;
  --violet-soft: #7c5cff;
  --aqua: #46f0d0;
  --gold: #ffd66b;
  --text: #e7e5f5;
  --dim: #8b88a8;
  --dimmer: #605d7a;
  --good: #3dff9e;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: "Cascadia Code", Consolas, ui-monospace, monospace;
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 20% -10%, rgba(124, 92, 255, 0.22), transparent 60%),
    radial-gradient(900px 650px at 90% 110%, rgba(70, 240, 208, 0.12), transparent 60%),
    var(--bg);
  overflow-x: hidden;
}

/* Starfield -------------------------------------------------------------- */
.stars {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    radial-gradient(1.4px 1.4px at 12% 24%, rgba(255,255,255,.7), transparent),
    radial-gradient(1.2px 1.2px at 42% 68%, rgba(255,255,255,.5), transparent),
    radial-gradient(1.6px 1.6px at 68% 18%, rgba(200,180,255,.7), transparent),
    radial-gradient(1.1px 1.1px at 82% 52%, rgba(255,255,255,.55), transparent),
    radial-gradient(1.3px 1.3px at 28% 84%, rgba(180,240,255,.6), transparent),
    radial-gradient(1.2px 1.2px at 58% 40%, rgba(255,255,255,.45), transparent),
    radial-gradient(1.5px 1.5px at 92% 82%, rgba(255,230,180,.6), transparent);
  background-repeat: no-repeat;
  animation: twinkle 6s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .55; } to { opacity: 1; } }

/* Top bar ---------------------------------------------------------------- */
.topbar {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  color: var(--violet); font-size: 22px;
  text-shadow: 0 0 14px rgba(169, 112, 255, .8);
  animation: spin 9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.brand-name {
  font-weight: 700; letter-spacing: 4px; font-size: 18px;
  background: linear-gradient(90deg, #fff, var(--violet));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.prestige-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px; border-radius: 20px;
  border: 1px solid rgba(255, 214, 107, .4);
  background: rgba(255, 214, 107, .08);
  color: var(--gold); font-size: 12.5px; letter-spacing: .5px;
}
.core-icon { text-shadow: 0 0 10px var(--gold); }
.core-mult { color: var(--aqua); font-size: 11.5px; }

/* Layout ----------------------------------------------------------------- */
.layout {
  position: relative; z-index: 2;
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(340px, 1.15fr);
  gap: 22px;
  max-width: 1080px;
  margin: 6px auto 20px;
  padding: 0 22px;
  align-items: start;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 18px;
  backdrop-filter: blur(10px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255,255,255,.04);
}

/* Forge panel ------------------------------------------------------------ */
.forge-panel {
  padding: 26px 22px 30px;
  display: flex; flex-direction: column; align-items: center;
  position: sticky; top: 14px;
}
.resource { text-align: center; margin-bottom: 8px; }
.resource-amount {
  font-size: clamp(34px, 6vw, 52px); font-weight: 700; line-height: 1;
  color: #fff; letter-spacing: 1px;
  text-shadow: 0 0 22px rgba(124, 92, 255, .55);
}
.resource-label {
  margin-top: 6px; font-size: 13px; letter-spacing: 4px;
  color: var(--violet); text-transform: uppercase;
}
.resource-rate { margin-top: 4px; font-size: 13px; color: var(--aqua); }

.core {
  position: relative;
  width: min(230px, 60vw); height: min(230px, 60vw);
  margin: 22px 0 10px;
  border: none; background: transparent; cursor: pointer;
  border-radius: 50%;
  display: grid; place-items: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease;
}
.core:active { transform: scale(.95); }
.core-canvas {
  position: absolute; inset: -12%;
  width: 124%; height: 124%;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0; transition: opacity .5s ease;
  touch-action: none;
}
.core.has-3d .core-canvas { opacity: 1; }
/* When the 3D core renders, retire the CSS stand-in but keep the label. */
.core.has-3d .core-glow,
.core.has-3d .core-ring,
.core.has-3d .core-heart { opacity: 0; }
.core.has-3d .core-hint { text-shadow: 0 0 8px rgba(0,0,0,.6); }
.core-glow, .core-ring, .core-heart { transition: opacity .5s ease; }
.core.hit { animation: coreHit .28s ease; }
@keyframes coreHit {
  0% { transform: scale(.92); }
  55% { transform: scale(1.04); }
  100% { transform: scale(1); }
}
.core-glow {
  position: absolute; inset: 8%;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, #d7c4ff, #8a5cff 42%, #5b2fd6 68%, #2a0f66 100%);
  box-shadow: 0 0 55px rgba(138, 92, 255, .75), inset 0 0 40px rgba(255,255,255,.25);
  animation: breathe 3.4s ease-in-out infinite;
}
@keyframes breathe {
  50% { box-shadow: 0 0 80px rgba(138, 92, 255, .95), inset 0 0 55px rgba(255,255,255,.35); }
}
.core-ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2px dashed rgba(180, 150, 255, .5);
  animation: spin 14s linear infinite;
}
.core-ring::after {
  content: ""; position: absolute; inset: 14px;
  border-radius: 50%;
  border: 1px solid rgba(70, 240, 208, .35);
  animation: spin 9s linear infinite reverse;
}
.core-heart {
  position: relative; z-index: 2;
  font-size: 46px; color: #fff;
  text-shadow: 0 0 18px #fff, 0 0 34px var(--violet);
  animation: floaty 3.4s ease-in-out infinite;
}
@keyframes floaty { 50% { transform: translateY(-6px); } }
.core-hint {
  position: absolute; bottom: 24%; z-index: 2;
  font-size: 11px; letter-spacing: 3px; text-transform: uppercase;
  color: rgba(255,255,255,.75);
}
/* Speech bubble that pops above the core on a strike. */
.core-quip {
  position: relative; z-index: 3;
  max-width: 220px; margin: 0 auto -6px;
  padding: 7px 14px; border-radius: 14px;
  background: rgba(30, 26, 50, .95);
  border: 1px solid rgba(140, 110, 255, .35);
  color: #fff; font-size: 12.5px; line-height: 1.4; text-align: center;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .45);
  opacity: 0; transform: translateY(8px) scale(.9);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.core-quip::after {
  content: ""; position: absolute; left: 50%; bottom: -6px;
  width: 12px; height: 12px; transform: translateX(-50%) rotate(45deg);
  background: rgba(30, 26, 50, .95);
  border-right: 1px solid rgba(140, 110, 255, .35);
  border-bottom: 1px solid rgba(140, 110, 255, .35);
}
.core-quip.show {
  opacity: 1; transform: translateY(0) scale(1);
  animation: quipBob 1.6s ease-in-out;
}
@keyframes quipBob { 40% { transform: translateY(-3px); } }

.click-info { margin-top: 8px; font-size: 13px; color: var(--dim); }
.click-info #click-power { color: var(--good); font-weight: 700; }

/* Shop ------------------------------------------------------------------- */
.shop-panel { padding: 0; overflow: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--panel-line); }
.tab {
  flex: 1; padding: 14px 8px;
  background: transparent; border: none; cursor: pointer;
  color: var(--dim); font-family: inherit; font-size: 13px; letter-spacing: 1px;
  position: relative;
  transition: color .15s ease, background .15s ease;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,.03); }
.tab.active { color: #fff; }
.tab.active::after {
  content: ""; position: absolute; left: 20%; right: 20%; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--violet), transparent);
}
.tab-badge {
  display: inline-block; min-width: 17px; padding: 1px 5px; margin-left: 4px;
  border-radius: 10px; background: var(--good); color: #062; font-size: 10px;
  font-weight: 700; vertical-align: middle;
}
.tab-body { padding: 16px; max-height: 70vh; overflow-y: auto; }
.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* Buy modes -------------------------------------------------------------- */
.buy-modes { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.buy-modes-label { font-size: 12px; color: var(--dimmer); margin-right: 2px; }
.buy-mode {
  padding: 5px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--panel-line); background: rgba(255,255,255,.02);
  color: var(--dim); font-family: inherit; font-size: 12px;
  transition: all .15s ease;
}
.buy-mode:hover { color: var(--text); border-color: rgba(140,110,255,.4); }
.buy-mode.active { color: #fff; background: rgba(124,92,255,.22); border-color: var(--violet-soft); }

/* Generator cards -------------------------------------------------------- */
.gen-list { display: flex; flex-direction: column; gap: 9px; }
.gen-card {
  display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  padding: 11px 13px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--panel-line);
  background: rgba(255,255,255,.02);
  color: var(--text); font-family: inherit;
  transition: transform .12s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.gen-card:hover { border-color: rgba(140,110,255,.45); background: rgba(124,92,255,.07); }
.gen-card.affordable { border-color: rgba(70,240,208,.4); box-shadow: 0 0 0 1px rgba(70,240,208,.14); }
.gen-card:disabled { cursor: not-allowed; opacity: .82; }
.gen-card.locked { opacity: .42; filter: grayscale(.5); }
.gen-card.locked .gen-blurb, .gen-card.locked .gen-out { visibility: hidden; }
.gen-card.pop { animation: cardPop .3s ease; }
@keyframes cardPop { 40% { transform: scale(1.015); } }

.gen-icon {
  display: grid; place-items: center;
  width: 46px; height: 46px; border-radius: 10px;
  font-size: 22px; color: var(--violet);
  background: radial-gradient(circle at 40% 35%, rgba(124,92,255,.28), rgba(124,92,255,.06));
  border: 1px solid rgba(140,110,255,.25);
  text-shadow: 0 0 10px rgba(169,112,255,.6);
}
.gen-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.gen-name { font-size: 14px; font-weight: 600; color: #fff; }
.gen-blurb { font-size: 11px; color: var(--dimmer); }
.gen-out { font-size: 11.5px; color: var(--aqua); margin-top: 2px; }
.gen-buy { text-align: right; display: flex; flex-direction: column; gap: 3px; }
.gen-count { font-size: 18px; font-weight: 700; color: #fff; }
.gen-cost { font-size: 12px; color: var(--gold); white-space: nowrap; }
.gen-card.affordable .gen-cost { color: var(--good); }

/* Upgrades --------------------------------------------------------------- */
.upg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.upg-card {
  display: flex; flex-direction: column; gap: 5px; text-align: left;
  padding: 12px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--panel-line); background: rgba(255,255,255,.02);
  color: var(--text); font-family: inherit;
  transition: transform .12s ease, border-color .15s ease, background .15s ease;
}
.upg-card:hover { border-color: rgba(255,214,107,.45); background: rgba(255,214,107,.06); transform: translateY(-2px); }
.upg-card.affordable { border-color: rgba(70,240,208,.4); box-shadow: 0 0 0 1px rgba(70,240,208,.14); }
.upg-card:disabled { cursor: not-allowed; opacity: .6; }
.upg-name { font-size: 13px; font-weight: 700; color: #fff; }
.upg-desc { font-size: 11px; color: var(--dim); line-height: 1.5; flex: 1; }
.upg-cost { font-size: 12.5px; color: var(--gold); font-weight: 600; }
.upg-card.affordable .upg-cost { color: var(--good); }
.empty { color: var(--dimmer); font-size: 13px; text-align: center; padding: 24px 8px; line-height: 1.6; }

/* Prestige --------------------------------------------------------------- */
.ascend-box { text-align: center; padding: 6px 4px; }
.ascend-icon {
  font-size: 44px; color: var(--gold);
  text-shadow: 0 0 24px rgba(255,214,107,.8);
  animation: floaty 3s ease-in-out infinite;
}
.ascend-box h3 { margin: 8px 0 10px; color: #fff; letter-spacing: 1px; }
.ascend-copy { font-size: 12.5px; color: var(--dim); line-height: 1.7; max-width: 340px; margin: 0 auto 16px; }
.ascend-copy strong { color: var(--gold); }
.ascend-gain { font-size: 15px; color: var(--text); margin-bottom: 14px; }
.ascend-gain span { color: var(--gold); font-weight: 700; font-size: 20px; }
.ascend-btn {
  padding: 11px 30px; border-radius: 12px; cursor: pointer;
  border: 1px solid rgba(255,214,107,.5);
  background: linear-gradient(180deg, rgba(255,214,107,.22), rgba(255,214,107,.08));
  color: var(--gold); font-family: inherit; font-size: 14px; letter-spacing: 2px;
  transition: all .15s ease;
}
.ascend-btn:hover:not(:disabled) { background: rgba(255,214,107,.3); transform: translateY(-2px); box-shadow: 0 8px 22px rgba(255,214,107,.2); }
.ascend-btn:disabled { opacity: .4; cursor: not-allowed; }
.ascend-note { font-size: 11px; color: var(--dimmer); margin-top: 12px; }

/* Floating gain + toasts ------------------------------------------------- */
.float-gain {
  position: fixed; z-index: 20; pointer-events: none;
  transform: translate(-50%, -50%);
  color: var(--good); font-weight: 700; font-size: 18px;
  text-shadow: 0 0 12px rgba(61,255,158,.7);
  animation: floatUp .9s ease-out forwards;
}
@keyframes floatUp {
  0% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -180%) scale(1.1); }
}
.toast-stack {
  position: fixed; z-index: 30; left: 50%; bottom: 26px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.toast {
  padding: 10px 18px; border-radius: 12px; font-size: 13px;
  background: rgba(30, 26, 50, .95); border: 1px solid var(--panel-line);
  color: var(--text); box-shadow: 0 12px 30px rgba(0,0,0,.5);
  opacity: 0; transform: translateY(12px); transition: opacity .3s ease, transform .3s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.good { border-color: rgba(61,255,158,.4); color: var(--good); }
.toast.core { border-color: rgba(255,214,107,.4); color: var(--gold); }

/* Welcome-back popup ----------------------------------------------------- */
.welcome-overlay {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(6, 5, 14, 0);
  backdrop-filter: blur(0px);
  opacity: 0; pointer-events: none;
  transition: opacity .32s ease, background .32s ease, backdrop-filter .32s ease;
}
.welcome-overlay.show {
  opacity: 1; pointer-events: auto;
  background: rgba(6, 5, 14, .62);
  backdrop-filter: blur(4px);
}
.welcome-card {
  position: relative; overflow: hidden;
  width: min(340px, 92vw);
  padding: 30px 26px 26px;
  text-align: center;
  border-radius: 22px;
  border: 1px solid rgba(255, 214, 107, .3);
  background:
    radial-gradient(120% 90% at 50% -20%, rgba(124, 92, 255, .35), transparent 60%),
    rgba(20, 17, 34, .96);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255,255,255,.06);
  transform: translateY(22px) scale(.94);
  transition: transform .38s cubic-bezier(.2, .9, .3, 1.2);
}
.welcome-overlay.show .welcome-card { transform: translateY(0) scale(1); }
.welcome-glow {
  position: absolute; left: 50%; top: -30%;
  width: 220px; height: 220px; transform: translateX(-50%);
  background: radial-gradient(circle, rgba(255,214,107,.28), transparent 68%);
  pointer-events: none;
  animation: breathe 3.6s ease-in-out infinite;
}
.welcome-icon {
  position: relative; z-index: 1;
  font-size: 40px; color: var(--gold);
  text-shadow: 0 0 22px rgba(255,214,107,.85);
  animation: floaty 3s ease-in-out infinite;
}
.welcome-title {
  position: relative; z-index: 1;
  margin: 8px 0 4px; font-size: 22px; letter-spacing: 2px; color: #fff;
}
.welcome-sub {
  position: relative; z-index: 1;
  margin: 0; font-size: 12.5px; color: var(--dim); letter-spacing: .5px;
}
.welcome-time {
  position: relative; z-index: 1;
  margin: 6px 0 18px; font-size: 26px; font-weight: 700; color: var(--aqua);
  text-shadow: 0 0 18px rgba(70,240,208,.4);
}
.welcome-earned {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; gap: 3px;
  padding: 14px; margin-bottom: 20px;
  border-radius: 14px;
  border: 1px solid rgba(70,240,208,.25);
  background: rgba(70,240,208,.06);
}
.welcome-earned-num {
  font-size: 24px; font-weight: 700; color: var(--good);
  text-shadow: 0 0 16px rgba(61,255,158,.4);
}
.welcome-earned-label { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--dim); }
.welcome-btn {
  position: relative; z-index: 1;
  width: 100%; padding: 12px; cursor: pointer;
  border-radius: 12px; border: 1px solid rgba(255,214,107,.5);
  background: linear-gradient(180deg, rgba(255,214,107,.24), rgba(255,214,107,.09));
  color: var(--gold); font-family: inherit; font-size: 14px; letter-spacing: 3px;
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}
.welcome-btn:hover {
  background: rgba(255,214,107,.32); transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(255,214,107,.22);
}

/* Responsive ------------------------------------------------------------- */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .forge-panel { position: static; }
  .tab-body { max-height: none; }
}
