:root {
  --bg: #07060f;
  --bg-elev: rgba(16, 14, 32, 0.72);
  --bg-card: rgba(24, 20, 48, 0.78);
  --border: rgba(168, 140, 255, 0.16);
  --border-hot: rgba(130, 220, 255, 0.45);
  --text: #f2edff;
  --muted: #9b93b8;
  --accent: #8b7cff;
  --accent-2: #52e0ff;
  --accent-3: #ff6bcb;
  --good: #5dffb1;
  --warn: #ffd166;
  --danger: #ff6b8a;
  --glow: 0 0 40px rgba(139, 124, 255, 0.35);
  --radius: 18px;
  --font: "Outfit", system-ui, sans-serif;
  --display: "Space Grotesk", "Outfit", system-ui, sans-serif;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow-x: hidden;
}

body {
  min-height: 100vh;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(88, 40, 180, 0.28), transparent 60%),
    radial-gradient(900px 500px at 90% 10%, rgba(20, 120, 180, 0.2), transparent 55%),
    radial-gradient(800px 700px at 50% 100%, rgba(180, 40, 120, 0.12), transparent 50%),
    var(--bg);
}

#stars {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.nebula {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.45;
  animation: drift 28s ease-in-out infinite alternate;
}

.n1 {
  width: 420px;
  height: 420px;
  left: -80px;
  top: 20%;
  background: radial-gradient(circle, rgba(120, 90, 255, 0.55), transparent 70%);
}

.n2 {
  width: 360px;
  height: 360px;
  right: -60px;
  top: 40%;
  background: radial-gradient(circle, rgba(50, 200, 255, 0.4), transparent 70%);
  animation-duration: 36s;
  animation-delay: -8s;
}

.n3 {
  width: 500px;
  height: 280px;
  left: 30%;
  bottom: -80px;
  background: radial-gradient(circle, rgba(255, 80, 180, 0.25), transparent 70%);
  animation-duration: 42s;
  animation-delay: -15s;
}

@keyframes drift {
  from {
    transform: translate3d(0, 0, 0) scale(1);
  }
  to {
    transform: translate3d(40px, -30px, 0) scale(1.08);
  }
}

.topbar,
.layout,
.footer {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.4rem 0.4rem;
  max-width: 1200px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  color: var(--accent-2);
  background: linear-gradient(145deg, rgba(139, 124, 255, 0.28), rgba(82, 224, 255, 0.12));
  border: 1px solid var(--border);
  box-shadow: var(--glow);
}

.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
  letter-spacing: 0.02em;
  font-weight: 700;
}

.tagline {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.top-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.icon-btn {
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  transition: 0.18s ease;
}

.icon-btn:hover {
  border-color: var(--border-hot);
  background: rgba(130, 220, 255, 0.08);
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 1.1rem;
  max-width: 1200px;
  margin: 0.6rem auto 2rem;
  padding: 0 1.2rem;
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  backdrop-filter: blur(16px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.spark-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1.2rem 1.4rem;
  position: sticky;
  top: 1rem;
  height: fit-content;
}

.energy-block {
  text-align: center;
  width: 100%;
  margin-bottom: 1.4rem;
}

.energy-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  font-weight: 600;
}

.energy-value {
  font-family: var(--display);
  font-size: clamp(2.2rem, 5vw, 3.1rem);
  font-weight: 700;
  line-height: 1.1;
  margin: 0.25rem 0;
  background: linear-gradient(120deg, #fff 20%, var(--accent-2) 55%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(82, 224, 255, 0.25);
  transition: transform 0.12s ease;
}

.energy-value.bump {
  transform: scale(1.04);
}

.energy-rate {
  color: var(--good);
  font-weight: 600;
  font-size: 0.95rem;
}

.meta-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 0.85rem;
}

.meta-chip {
  font-size: 0.8rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
}

.meta-chip strong {
  color: var(--accent-2);
  font-weight: 600;
  margin-left: 0.25rem;
}

.spark-btn {
  position: relative;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  isolation: isolate;
  transition: transform 0.12s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.spark-btn:active,
.spark-btn.pressed {
  transform: scale(0.94);
}

.spark-core {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.95), transparent 28%),
    radial-gradient(circle at 50% 50%, #b8a8ff 0%, #5a47d8 45%, #1a1240 100%);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.12),
    0 0 30px rgba(139, 124, 255, 0.55),
    0 0 70px rgba(82, 224, 255, 0.28),
    inset 0 -10px 30px rgba(0, 0, 0, 0.35);
  z-index: 2;
  animation: pulse 2.4s ease-in-out infinite;
}

.spark-glyph {
  font-size: 2.2rem;
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.8));
}

.spark-label {
  position: absolute;
  bottom: 10px;
  z-index: 3;
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 600;
}

.spark-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(130, 220, 255, 0.25);
  z-index: 1;
}

.spark-ring.r1 {
  animation: spin 12s linear infinite;
  border-top-color: var(--accent-2);
  border-right-color: transparent;
}

.spark-ring.r2 {
  inset: 12px;
  animation: spin 8s linear infinite reverse;
  border-bottom-color: var(--accent-3);
  border-left-color: transparent;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.12),
      0 0 30px rgba(139, 124, 255, 0.55),
      0 0 70px rgba(82, 224, 255, 0.28),
      inset 0 -10px 30px rgba(0, 0, 0, 0.35);
  }
  50% {
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.18),
      0 0 45px rgba(139, 124, 255, 0.75),
      0 0 90px rgba(82, 224, 255, 0.4),
      inset 0 -10px 30px rgba(0, 0, 0, 0.35);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.click-power {
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.click-power span {
  color: var(--accent-2);
  font-weight: 700;
}

.tabs-panel {
  display: flex;
  flex-direction: column;
  min-height: 640px;
  overflow: hidden;
}

.tabs {
  display: flex;
  gap: 0.35rem;
  padding: 0.85rem 0.9rem 0;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 0.75rem 0.5rem;
  border-radius: 12px 12px 0 0;
  color: var(--muted);
  font-weight: 600;
  transition: 0.15s ease;
  border: 1px solid transparent;
  border-bottom: none;
}

.tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

.tab.active {
  color: var(--text);
  background: rgba(139, 124, 255, 0.12);
  border-color: var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.tab-body {
  display: none;
  padding: 0.9rem;
  overflow: auto;
  flex: 1;
}

.tab-body.active {
  display: block;
}

.buy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.seg {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem;
  gap: 0.15rem;
}

.seg-btn {
  min-width: 44px;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
}

.seg-btn.active {
  background: linear-gradient(135deg, rgba(139, 124, 255, 0.9), rgba(82, 224, 255, 0.55));
  color: #0b0a14;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.85rem;
  align-items: center;
  padding: 0.95rem;
  border-radius: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.card:hover {
  border-color: rgba(168, 140, 255, 0.35);
}

.card.affordable {
  border-color: rgba(93, 255, 177, 0.28);
  box-shadow: 0 0 24px rgba(93, 255, 177, 0.06);
}

.card.locked {
  opacity: 0.55;
}

.card-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
}

.card-body h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 600;
}

.card-body p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.card-meta {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  margin-top: 0.45rem;
  font-size: 0.78rem;
}

.pill {
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  border: 1px solid transparent;
}

.pill.owned {
  color: var(--accent-2);
  border-color: rgba(82, 224, 255, 0.2);
}

.pill.prod {
  color: var(--good);
  border-color: rgba(93, 255, 177, 0.18);
}

.buy-btn {
  min-width: 110px;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(139, 124, 255, 0.25), rgba(82, 224, 255, 0.1));
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.88rem;
  transition: 0.15s ease;
  text-align: center;
}

.buy-btn .cost {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: 0.15rem;
}

.buy-btn:not(:disabled):hover {
  border-color: var(--border-hot);
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(82, 224, 255, 0.12);
}

.buy-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.buy-btn.can {
  background: linear-gradient(135deg, rgba(93, 255, 177, 0.22), rgba(82, 224, 255, 0.14));
  border-color: rgba(93, 255, 177, 0.4);
  color: #d8ffe9;
}

.upgrade.owned {
  border-color: rgba(139, 124, 255, 0.4);
  background: linear-gradient(135deg, rgba(139, 124, 255, 0.12), rgba(24, 20, 48, 0.78));
}

.upgrade.owned .buy-btn {
  background: rgba(255, 255, 255, 0.04);
  color: var(--good);
}

.prestige-card {
  text-align: center;
  padding: 1.5rem 1rem 1.2rem;
  max-width: 520px;
  margin: 1rem auto;
}

.prestige-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 0.8rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2rem;
  color: var(--accent-2);
  background: radial-gradient(circle, rgba(82, 224, 255, 0.2), rgba(139, 124, 255, 0.08));
  border: 1px solid var(--border);
  box-shadow: var(--glow);
}

.prestige-card h2 {
  margin: 0 0 0.5rem;
  font-family: var(--display);
}

.prestige-card > p {
  color: var(--muted);
  line-height: 1.5;
  margin: 0 auto 1.2rem;
  max-width: 34ch;
}

.prestige-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.2rem;
}

.prestige-stats > div {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.85rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.prestige-stats strong {
  font-family: var(--display);
  font-size: 1.15rem;
  color: var(--accent-2);
}

.primary-btn,
.ghost-btn,
.danger-btn {
  border-radius: 12px;
  padding: 0.8rem 1.1rem;
  font-weight: 700;
  transition: 0.15s ease;
}

.primary-btn {
  background: linear-gradient(135deg, #8b7cff, #4ec7ef);
  color: #0b0a14;
  box-shadow: 0 10px 30px rgba(82, 224, 255, 0.18);
}

.primary-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.primary-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

.primary-btn.wide,
.ghost-btn.wide {
  width: 100%;
}

.ghost-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.ghost-btn:hover {
  border-color: var(--border-hot);
}

.danger-btn {
  border: 1px solid rgba(255, 107, 138, 0.4);
  background: rgba(255, 107, 138, 0.12);
  color: #ffc0cd;
}

.danger-btn:hover {
  background: rgba(255, 107, 138, 0.2);
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.75rem 0 0;
}

.footer {
  max-width: 1200px;
  margin: 0 auto 1.5rem;
  padding: 0 1.2rem;
  color: var(--muted);
  font-size: 0.8rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.dot {
  opacity: 0.5;
}

.muted {
  color: var(--muted);
}

/* Floating numbers */
#float-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  overflow: hidden;
}

.float-num {
  position: fixed;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--accent-2);
  text-shadow: 0 0 12px rgba(82, 224, 255, 0.7);
  animation: float-up 0.9s ease-out forwards;
  white-space: nowrap;
}

.float-num.big {
  color: var(--good);
  font-size: 1.25rem;
}

@keyframes float-up {
  0% {
    opacity: 0;
    transform: translate(-50%, 0) scale(0.8);
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -70px) scale(1.05);
  }
}

/* Toasts */
#toast-root {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(320px, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  background: rgba(18, 16, 36, 0.92);
  border: 1px solid var(--border-hot);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), var(--glow);
  animation: toast-in 0.28s ease;
  backdrop-filter: blur(12px);
}

.toast.ach .title {
  color: var(--warn);
}

.toast .title {
  font-weight: 700;
  font-size: 0.88rem;
  margin-bottom: 0.15rem;
}

.toast .body {
  color: var(--muted);
  font-size: 0.82rem;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Dialogs */
dialog {
  border: none;
  padding: 0;
  background: transparent;
  color: var(--text);
  max-width: min(560px, calc(100vw - 2rem));
  width: 100%;
}

dialog::backdrop {
  background: rgba(4, 3, 12, 0.72);
  backdrop-filter: blur(6px);
}

.modal {
  background: rgba(16, 14, 32, 0.96);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.modal header h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.15rem;
}

.modal header .close {
  min-width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
}

.stat-grid,
.settings-list,
.ach-grid,
.offline-msg {
  padding: 1rem 1.1rem 1.2rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.stat {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
}

.stat .k {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 0.25rem;
}

.stat .v {
  font-family: var(--display);
  font-weight: 600;
}

.ach-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
  max-height: min(60vh, 480px);
  overflow: auto;
}

.ach {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
}

.ach.done {
  border-color: rgba(255, 209, 102, 0.35);
  background: linear-gradient(135deg, rgba(255, 209, 102, 0.1), rgba(255, 255, 255, 0.02));
}

.ach .icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.25);
  font-size: 1.15rem;
  filter: grayscale(1);
  opacity: 0.55;
}

.ach.done .icon {
  filter: none;
  opacity: 1;
}

.ach h3 {
  margin: 0;
  font-size: 0.92rem;
}

.ach p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-2);
}

.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-top: 1rem;
}

.settings-actions .danger-btn {
  grid-column: 1 / -1;
}

.import-box {
  width: 100%;
  min-height: 100px;
  margin-top: 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  padding: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  resize: vertical;
}

.offline-msg {
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}

.offline-msg strong {
  color: var(--accent-2);
}

body.shake {
  animation: shake 0.35s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-4px);
  }
  40% {
    transform: translateX(4px);
  }
  60% {
    transform: translateX(-3px);
  }
  80% {
    transform: translateX(2px);
  }
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .spark-panel {
    position: static;
  }

  .prestige-stats {
    grid-template-columns: 1fr;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .settings-actions {
    grid-template-columns: 1fr;
  }

  .card {
    grid-template-columns: auto 1fr;
  }

  .buy-btn {
    grid-column: 1 / -1;
  }
}
