:root {
  --bg-1: #28431f;
  --bg-2: #7abb4f;
  --panel: #2d4d24;
  --panel-2: #3f6631;
  --ink: #f7ffe9;
  --ink-muted: #d0e6b6;
  --accent: #f4b732;
  --danger: #ff5e57;
  --ok: #2bc48a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: "Baloo 2", "Trebuchet MS", sans-serif;
  background: radial-gradient(circle at top, #95d95a 0%, var(--bg-1) 58%);
  color: var(--ink);
}

body.game-page {
  background: radial-gradient(circle at top, #255b7e 0%, #0b1623 64%);
}

a {
  color: inherit;
  text-decoration: none;
}

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 16px 36px;
}

.game-page .wrap {
  max-width: 460px;
  padding: 14px 12px 112px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.logo {
  font-family: "Press Start 2P", monospace;
  font-size: 0.88rem;
  line-height: 1.3;
}

.btn {
  display: inline-block;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #1f1a0e;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn.alt {
  background: var(--panel-2);
  color: var(--ink);
}

.hero,
.card,
.grid-panel {
  background: linear-gradient(160deg, #112940 0%, #0f2235 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
}

.hero {
  padding: 18px;
  margin-bottom: 18px;
}

.title {
  margin: 0 0 10px;
  font-size: clamp(1.4rem, 4.2vw, 2.3rem);
}

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

.card {
  padding: 16px;
}

.stack {
  display: grid;
  gap: 12px;
}

.input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  padding: 12px;
}

.flash {
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.flash.error {
  background: rgba(255, 94, 87, 0.2);
  border: 1px solid rgba(255, 94, 87, 0.55);
}

.flash.ok {
  background: rgba(43, 196, 138, 0.2);
  border: 1px solid rgba(43, 196, 138, 0.55);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 10px 0 16px;
}

.kpi {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  padding: 10px;
}

.kpi strong {
  display: block;
  font-size: 1.3rem;
  margin-bottom: 4px;
}

.grid-panel {
  padding: 12px;
}

.lane-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  margin-top: 10px;
}

.slot {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  text-align: center;
  padding: 4px;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.slot.active {
  background: rgba(243, 176, 58, 0.26);
  transform: translateY(-2px);
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--ink);
  padding: 6px 10px;
  font-size: 0.85rem;
}

.chip[data-wave] {
  cursor: pointer;
}

.chip.active {
  background: rgba(243, 176, 58, 0.32);
}

.wave-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.wave-row .chip {
  min-height: 46px;
  font-weight: 700;
}

.chip.warn {
  background: rgba(255, 94, 87, 0.25);
}

#battle-canvas {
  width: 100%;
  max-width: 360px;
  height: 440px;
  border-radius: 14px;
  overflow: hidden;
  margin: 10px auto 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.action-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  display: flex;
  justify-content: center;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(11, 22, 35, 0) 0%, rgba(11, 22, 35, 0.9) 34%, rgba(11, 22, 35, 0.98) 100%);
}

.action-dock .btn {
  width: min(440px, calc(100% - 8px));
  text-align: center;
  padding: 14px 16px;
  border-radius: 14px;
}

@media (min-width: 760px) {
  .split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }

  .game-page .wrap {
    max-width: 760px;
    padding-bottom: 120px;
  }

  .game-stack {
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    gap: 12px;
  }

  .game-stack .card:first-of-type {
    grid-row: span 2;
  }
}

.game-page {
  width: 100vw;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

.game-page .game-app {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0;
  padding: 0;
  overflow: hidden;
}

.game-page .game-hud {
  background: linear-gradient(160deg, rgba(17, 41, 64, 0.95) 0%, rgba(15, 34, 53, 0.95) 100%);
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  display: grid;
  gap: 8px;
}

.game-page .game-hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.game-page .game-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.game-page .game-stats .kpi {
  padding: 8px;
}

.game-page .game-stats .kpi strong {
  font-size: 1.1rem;
}

.game-page .game-stage {
  min-height: 0;
  background: #0d1b28;
  border: 0;
  border-radius: 0;
  padding: 0;
}

.game-page #battle-canvas {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  border-radius: 0;
  overflow: hidden;
  border: 0;
}

.game-page .game-controls {
  background: linear-gradient(160deg, rgba(17, 41, 64, 0.95) 0%, rgba(15, 34, 53, 0.95) 100%);
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  display: grid;
  gap: 10px;
}

.game-page .wave-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.game-page .wave-row .chip {
  min-height: 48px;
  text-align: center;
  font-size: 0.95rem;
}

.game-page .action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.game-page .action-row .btn {
  padding: 12px 16px;
}

.game-page .game-toast {
  position: fixed;
  left: 8px;
  right: 8px;
  top: 10px;
  z-index: 30;
  margin: 0;
}
