:root {
  color-scheme: dark;
  --bg: #151719;
  --panel: #202428;
  --panel-soft: #2a3035;
  --text: #f2f0e8;
  --muted: #b8b5aa;
  --gold: #f2c14e;
  --danger: #f45b69;
  --good: #6ee7a8;
  --line: rgba(255, 255, 255, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #263238 0, #151719 38rem);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

.game-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  max-width: 680px;
  font-size: clamp(1.3rem, 2vw, 2rem);
  line-height: 1.08;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 10px;
}

.stat,
.shop,
.tip {
  background: rgba(32, 36, 40, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stat {
  min-width: 104px;
  padding: 10px 12px;
}

.stat span,
.upgrade-meta,
.tip {
  color: var(--muted);
  font-size: 0.86rem;
}

.stat strong {
  display: block;
  margin-top: 3px;
  color: var(--text);
  font-size: 1.25rem;
}

.play-area {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}

.shop {
  padding: 14px;
}

.shop h2 {
  font-size: 1.05rem;
  margin-bottom: 10px;
}

.shop-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.control-button {
  width: 100%;
  padding: 10px 11px;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.control-button:hover,
.control-button:focus-visible {
  border-color: var(--gold);
  outline: none;
}

.control-button.active {
  color: #151719;
  background: var(--good);
  border-color: var(--good);
}

.danger-button:hover,
.danger-button:focus-visible {
  border-color: var(--danger);
}

.upgrade-list {
  display: grid;
  gap: 10px;
}

.upgrade {
  width: 100%;
  display: grid;
  gap: 4px;
  padding: 11px;
  text-align: left;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.upgrade:hover:not(:disabled),
.upgrade:focus-visible:not(:disabled) {
  border-color: var(--gold);
  outline: none;
}

.upgrade:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.upgrade.current {
  border-color: var(--good);
  background: rgba(110, 231, 168, 0.16);
}

.upgrade-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 800;
}

.upgrade-price {
  color: var(--gold);
}

.tip {
  margin-top: 12px;
  padding: 10px;
  line-height: 1.35;
}

.stage-wrap {
  position: relative;
  min-height: 640px;
  overflow: hidden;
  background: #1d2426;
  border: 1px solid var(--line);
  border-radius: 8px;
}

canvas {
  display: block;
  width: 100%;
  height: 640px;
  min-height: 640px;
  cursor: pointer;
  touch-action: none;
}

.help-strip {
  position: absolute;
  left: 14px;
  top: 14px;
  max-width: calc(100% - 28px);
  padding: 9px 12px;
  color: var(--text);
  background: rgba(21, 23, 25, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 800;
  pointer-events: none;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(8px);
  max-width: min(460px, calc(100% - 28px));
  padding: 10px 14px;
  color: #151719;
  background: var(--gold);
  border-radius: 8px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.bad {
  color: white;
  background: var(--danger);
}

@media (max-width: 900px) {
  .topbar,
  .play-area {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

  .stage-wrap {
    order: 1;
  }

  .shop {
    order: 2;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 580px) {
  .game-shell {
    padding: 10px;
  }

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

  .stage-wrap,
  canvas {
    height: 500px;
    min-height: 500px;
  }
}
