:root {
  --bg: #ffffff;
  --ink: #111118;
  --muted: #6b6b78;
  --accent: #5b8cff;
  --coin: #e8a317;
  --good: #2ecc71;
  --card: #f4f4f8;
  --shadow: 0 12px 40px rgba(20, 20, 40, 0.12);
  --radius: 18px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body.rainbow {
  animation: hue 8s linear infinite;
}
@keyframes hue {
  to {
    filter: hue-rotate(360deg);
  }
}

#world {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--bg);
  transition: background 0.6s ease;
}

#world.soft-night {
  --bg: #0e0e14;
  --ink: #f2f2f8;
  --muted: #9a9ab0;
  --card: #1a1a24;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  background: var(--bg);
  color: var(--ink);
}

#fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

#dvd-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
}
#dvd-layer.hidden {
  display: none;
}

.dvd {
  position: absolute;
  font-weight: 900;
  font-size: 28px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0.85;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.2));
  user-select: none;
}

#stage {
  position: relative;
  z-index: 5;
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 28px 20px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  overflow-y: auto;
}

#hud {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
#hud.hidden {
  display: none;
}
.stat {
  background: var(--card);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat .label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 2px;
}
.stat span:last-child {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
#coins {
  color: var(--coin);
}

.story {
  min-height: 3.2em;
  text-align: center;
  font-size: 18px;
  line-height: 1.45;
  font-weight: 600;
  max-width: 28ch;
  color: var(--ink);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}
.story.show {
  opacity: 1;
  transform: none;
}
.story .line {
  display: block;
  margin: 0.35em 0;
}
.story .whisper {
  color: var(--muted);
  font-weight: 500;
  font-size: 16px;
}

.main-btn {
  appearance: none;
  border: 3px solid #0040c8;
  cursor: pointer;
  font: inherit;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  padding: 22px 48px;
  border-radius: 999px;
  /* Solid bright blue — never white-on-white */
  background: #0a84ff !important;
  color: #ffffff !important;
  box-shadow: 0 14px 36px rgba(10, 132, 255, 0.55),
    0 2px 0 rgba(255, 255, 255, 0.3) inset;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s;
  opacity: 1;
  transform: scale(1);
  z-index: 20;
  position: relative;
}
.main-btn.hidden {
  display: none !important;
}
.main-btn.visible {
  display: inline-block !important;
  opacity: 1 !important;
  visibility: visible !important;
  animation: btn-in 0.55s cubic-bezier(0.2, 0.9, 0.2, 1);
}
.main-btn:not(:disabled):hover {
  filter: brightness(1.08);
  background: #0070f0 !important;
}
.main-btn:not(:disabled):active {
  transform: scale(0.94);
}
.main-btn.pop {
  animation: pop 0.28s ease;
}
@keyframes btn-in {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

#wait-hint {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  color: #bbb;
  font-size: 14px;
  font-weight: 600;
  z-index: 4;
  letter-spacing: 0.04em;
  transition: opacity 0.4s;
}
#wait-hint.gone {
  opacity: 0;
  pointer-events: none;
}
@keyframes pop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
  }
}

.main-btn.mega {
  background: linear-gradient(145deg, #ff6bcb, #ff9f0a 50%, #5b8cff);
  box-shadow: 0 16px 40px rgba(255, 107, 203, 0.4);
}

.upgrades {
  width: 100%;
  margin-top: 8px;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.upgrades.hidden {
  display: none;
}
.upgrades.show {
  opacity: 1;
  transform: none;
  display: block;
}
.upgrades h2 {
  font-size: 20px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 4px;
}
.upgrades .hint {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 14px;
}

.shop {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  align-items: center;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  transition: border-color 0.2s, transform 0.15s;
}
.card.locked {
  opacity: 0.55;
}
.card.owned {
  border-color: var(--good);
}
.card.affordable:not(.owned):not(.locked) {
  border-color: rgba(91, 140, 255, 0.45);
}
.card h3 {
  font-size: 16px;
  font-weight: 800;
}
.card p {
  grid-column: 1 / -1;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.35;
}
.card .req {
  font-size: 11px;
  color: var(--muted);
  grid-column: 1;
}
.buy {
  appearance: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  white-space: nowrap;
}
.buy:disabled {
  opacity: 0.4;
  cursor: default;
  background: #999;
}
.buy.owned-label {
  background: var(--good);
  cursor: default;
}

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: rgba(20, 20, 30, 0.9);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.hidden {
  display: none;
}

@media (max-width: 420px) {
  .main-btn {
    font-size: 22px;
    padding: 18px 36px;
  }
  #hud {
    grid-template-columns: 1fr;
  }
}
