/* ====================================
   PokéTower - Pokemon tower defense
   ==================================== */

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

:root {
  --bg: #121928;
  --bg-2: #172238;
  --panel: #f7f0d6;
  --panel-2: #ede1b8;
  --ink: #222733;
  --text: #eef2ff;
  --muted: #8fa1bd;
  --frame: #263447;
  --frame-light: #3f5d7d;
  --red: #e04040;
  --red-dark: #8c1818;
  --blue: #2a6db0;
  --yellow: #f8d030;
  --green: #49a65a;
  --cream: #f8f2d8;
  --pxfont: "Press Start 2P", monospace;
  --uifont: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--text);
  font-family: var(--uifont);
  background:
    linear-gradient(135deg, rgba(255,255,255,.03) 25%, transparent 25%) 0 0 / 22px 22px,
    linear-gradient(225deg, rgba(255,255,255,.025) 25%, transparent 25%) 0 0 / 22px 22px,
    linear-gradient(180deg, #0f1726 0%, var(--bg) 48%, #0d1421 100%);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
}

button,
.btn {
  -webkit-tap-highlight-color: transparent;
}

#app,
#app * {
  touch-action: manipulation;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}

.topbar {
  width: min(100%, 1320px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto minmax(320px, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 3px solid #111822;
  border-radius: 8px;
  background: linear-gradient(180deg, #22334b 0%, #182338 100%);
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,.07),
    0 8px 0 rgba(0,0,0,.26);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #ffcc00;
  text-decoration: none;
  font-family: var(--pxfont);
  font-size: .86rem;
  letter-spacing: 1px;
  text-shadow:
    2px 2px 0 #0066cc,
    3px 3px 0 rgba(0,0,0,.7);
  white-space: nowrap;
}

.brand span span {
  color: #ff6060;
}

.brand-ball {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 3px solid #10131a;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #fff 0 5px, #10131a 6px 8px, transparent 9px),
    linear-gradient(180deg, var(--red) 0 49%, #10131a 50% 54%, #f8f8f8 55% 100%);
  box-shadow: inset -3px -4px 0 rgba(0,0,0,.18);
}

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

.hud-chip {
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  padding: 8px 10px;
  color: var(--ink);
  background: linear-gradient(180deg, var(--cream), #efe3bd);
  border: 2px solid #121821;
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.55);
}

.hud-chip strong {
  font-family: var(--pxfont);
  font-size: .64rem;
  line-height: 1;
  color: #1f2937;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-chip small {
  color: #536070;
  font-weight: 800;
  font-size: .64rem;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.btn,
.icon-btn {
  border: 3px solid #111822;
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  box-shadow: 0 4px 0 rgba(0,0,0,.32), inset 0 0 0 2px rgba(255,255,255,.45);
  transition: transform .08s ease, box-shadow .08s ease, filter .12s ease;
}

.btn {
  min-height: 42px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #ffeab8 0%, #f0d080 100%);
  font-family: var(--pxfont);
  font-size: .58rem;
  line-height: 1.3;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(180deg, #ff7373 0%, #d83030 100%);
  text-shadow: 1px 1px 0 rgba(0,0,0,.35);
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  background: linear-gradient(180deg, #f8f2d8 0%, #e8d99f 100%);
  font-family: var(--pxfont);
  font-size: .58rem;
}

.icon-btn.danger {
  color: #fff;
  background: linear-gradient(180deg, #6d7788 0%, #3b4658 100%);
}

.btn:disabled,
.icon-btn:disabled {
  cursor: default;
  opacity: .58;
  filter: grayscale(.4);
}

.btn:not(:disabled):hover,
.icon-btn:not(:disabled):hover {
  filter: brightness(1.07);
  transform: translateY(-1px);
  box-shadow: 0 5px 0 rgba(0,0,0,.36), inset 0 0 0 2px rgba(255,255,255,.55);
}

.btn:not(:disabled):active,
.icon-btn:not(:disabled):active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0,0,0,.34), inset 0 0 0 2px rgba(255,255,255,.45);
}

.game-shell {
  width: min(100%, 1320px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 346px;
  gap: 12px;
  align-items: start;
}

.playfield {
  position: relative;
  min-width: 0;
  border: 4px solid #111822;
  border-radius: 8px;
  background: #000;
  overflow: hidden;
  box-shadow:
    inset 0 0 0 2px #3b5572,
    0 10px 0 rgba(0,0,0,.28);
}

#game-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 12 / 7;
  background: #8ccf6b;
  image-rendering: pixelated;
}

.match-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(9, 14, 23, .72);
  backdrop-filter: blur(4px);
}

.match-overlay.hidden {
  display: none;
}

.modal-panel {
  width: min(100%, 420px);
  color: var(--ink);
  text-align: center;
  padding: 22px;
  border: 4px solid #111822;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--cream), #eadcad);
  box-shadow:
    inset 0 0 0 3px #2a6db0,
    6px 8px 0 rgba(0,0,0,.35);
}

.modal-panel h1 {
  margin: 0 0 12px;
  color: #b02828;
  font-family: var(--pxfont);
  font-size: .85rem;
  line-height: 1.6;
}

.modal-panel p {
  margin: 0 0 18px;
  color: #3e4857;
  font-family: var(--pxfont);
  font-size: .52rem;
  line-height: 1.8;
}

.side-panel {
  display: grid;
  gap: 12px;
}

.panel-section {
  color: var(--ink);
  border: 3px solid #111822;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,.55),
    0 7px 0 rgba(0,0,0,.25);
  overflow: hidden;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 0;
}

.panel-section h2 {
  margin: 0;
  padding: 12px 12px 0;
  color: #283243;
  font-family: var(--pxfont);
  font-size: .58rem;
  line-height: 1.5;
}

.panel-heading h2 {
  padding: 0;
}

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

.field-control {
  display: grid;
  gap: 5px;
}

.field-control span {
  color: #5b687a;
  font-size: .62rem;
  font-weight: 900;
  text-transform: uppercase;
}

.field-control select {
  width: 100%;
  min-height: 38px;
  padding: 8px;
  color: #293241;
  border: 2px solid #1d2634;
  border-radius: 7px;
  background: rgba(255,255,255,.64);
  font-weight: 900;
}

.btn-mode {
  grid-column: 1 / -1;
  min-height: 38px;
  color: #f8f2d8;
  background: linear-gradient(180deg, #3f5d7d 0%, #263447 100%);
}

.mission-summary {
  display: grid;
  gap: 6px;
  padding: 0 12px 12px;
  color: #4c5868;
  font-size: .72rem;
  font-weight: 800;
  line-height: 1.45;
}

.mission-summary strong {
  color: #293241;
}

.best-run {
  color: #687489;
  font-family: var(--pxfont);
  font-size: .38rem;
  line-height: 1.5;
  text-align: right;
}

.tower-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.tower-card {
  width: 100%;
  min-height: 72px;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  color: var(--ink);
  text-align: left;
  border: 2px solid #1d2634;
  border-left-width: 7px;
  border-left-color: var(--tower-color, #2a6db0);
  border-radius: 8px;
  background: rgba(255,255,255,.45);
  cursor: pointer;
  transition: background .12s ease, transform .12s ease, box-shadow .12s ease;
}

.tower-card:hover,
.tower-card.selected {
  background: rgba(255,255,255,.76);
  transform: translateY(-1px);
  box-shadow: 0 4px 0 rgba(0,0,0,.16);
}

.tower-card.selected {
  outline: 3px solid rgba(224,64,64,.38);
}

.tower-card img {
  width: 50px;
  height: 50px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(2px 3px 0 rgba(0,0,0,.2));
}

.tower-main {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.tower-name {
  color: #222733;
  font-family: var(--pxfont);
  font-size: .5rem;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tower-role {
  color: #526070;
  font-size: .72rem;
  font-weight: 800;
  line-height: 1.2;
}

.tower-cost {
  justify-self: end;
  color: #9a6812;
  font-family: var(--pxfont);
  font-size: .48rem;
  white-space: nowrap;
}

.type-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  padding: 4px 7px;
  border: 1px solid rgba(0,0,0,.24);
  border-radius: 5px;
  color: #fff;
  background: var(--type-color, #888);
  font-size: .62rem;
  font-weight: 800;
  text-shadow: 0 1px 1px rgba(0,0,0,.32);
  text-transform: uppercase;
}

.inspector {
  padding: 12px;
}

.inspect-card {
  display: grid;
  gap: 10px;
}

.inspect-head {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.inspect-head img {
  width: 58px;
  height: 58px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(2px 3px 0 rgba(0,0,0,.2));
}

.inspect-title {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.inspect-title strong {
  font-family: var(--pxfont);
  font-size: .56rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.inspect-title span {
  color: #5b687a;
  font-size: .74rem;
  font-weight: 800;
}

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

.mini-stat {
  padding: 8px;
  border: 1px solid rgba(32,38,52,.22);
  border-radius: 7px;
  background: rgba(255,255,255,.45);
}

.mini-stat small {
  display: block;
  margin-bottom: 5px;
  color: #677386;
  font-weight: 800;
  font-size: .62rem;
  text-transform: uppercase;
}

.mini-stat strong {
  color: #293241;
  font-family: var(--pxfont);
  font-size: .48rem;
  line-height: 1.35;
}

.inspect-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.inspect-actions .btn {
  min-height: 40px;
  padding: 9px 10px;
  font-size: .5rem;
}

.btn-evolve {
  color: #242414;
  background: linear-gradient(180deg, #fff0a8 0%, #f8d030 100%);
}

.btn-ability {
  color: #f8f2d8;
  background: linear-gradient(180deg, #6d5ad5 0%, #3f347e 100%);
}

.target-row,
.specialization-row {
  display: grid;
  gap: 7px;
  padding: 9px;
  border: 1px solid rgba(32,38,52,.22);
  border-radius: 7px;
  background: rgba(255,255,255,.48);
}

.target-row strong,
.specialization-row strong {
  color: #293241;
  font-family: var(--pxfont);
  font-size: .46rem;
  line-height: 1.35;
}

.target-row .btn,
.specialization-row .btn {
  min-height: 36px;
  padding: 8px;
  font-size: .46rem;
}

.specialization-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.xp-progress,
.evo-note {
  padding: 9px;
  color: #3d4858;
  border: 1px solid rgba(32,38,52,.22);
  border-radius: 7px;
  background: rgba(255,255,255,.48);
}

.evo-note {
  margin: 0;
  font-size: .72rem;
  font-weight: 800;
  line-height: 1.45;
}

.xp-progress {
  display: grid;
  gap: 7px;
}

.xp-progress div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.xp-progress strong {
  color: #293241;
  font-family: var(--pxfont);
  font-size: .46rem;
  line-height: 1.35;
}

.xp-progress span {
  color: #677386;
  font-size: .68rem;
  font-weight: 800;
}

.xp-track {
  height: 8px;
  overflow: hidden;
  border: 2px solid #1b2230;
  border-radius: 999px;
  background: #263447;
}

.xp-track span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #98d8d8 0%, #f8d030 100%);
}

.wave-intel {
  padding: 12px;
}

.wave-intel-card {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 2px solid rgba(32,38,52,.28);
  border-left: 7px solid #2a6db0;
  border-radius: 8px;
  background: rgba(255,255,255,.5);
}

.wave-intel-card.boss-wave {
  border-left-color: var(--red);
  background:
    linear-gradient(180deg, rgba(255,240,168,.7), rgba(255,255,255,.45));
}

.wave-intel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.wave-intel-top span,
.wave-status {
  color: #677386;
  font-size: .68rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.wave-intel-top strong {
  color: #293241;
  font-family: var(--pxfont);
  font-size: .48rem;
}

.wave-intel h3 {
  margin: 0;
  color: #293241;
  font-family: var(--pxfont);
  font-size: .56rem;
  line-height: 1.5;
}

.wave-intel p {
  margin: 0;
  color: #4c5868;
  font-size: .75rem;
  font-weight: 800;
  line-height: 1.45;
}

.wave-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.wave-tags span {
  padding: 4px 7px;
  color: #f8f2d8;
  border: 1px solid rgba(0,0,0,.26);
  border-radius: 5px;
  background: #293241;
  font-size: .62rem;
  font-weight: 900;
  text-transform: uppercase;
}

.wave-enemies {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.enemy-chip {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 7px 5px 6px;
  border: 1px solid rgba(32,38,52,.22);
  border-top: 5px solid var(--type-color, #888);
  border-radius: 7px;
  background: rgba(255,255,255,.55);
}

.enemy-chip.boss-chip {
  box-shadow: 0 0 0 2px rgba(224,64,64,.28);
}

.enemy-chip img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  image-rendering: pixelated;
}

.enemy-chip span {
  max-width: 100%;
  color: #293241;
  font-size: .58rem;
  font-weight: 900;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wave-status {
  text-align: right;
}

.inspect-empty {
  color: #536070;
  font-family: var(--pxfont);
  font-size: .48rem;
  line-height: 1.8;
}

.event-log {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 12px;
  list-style: none;
}

.event-log li {
  padding: 8px;
  color: #314052;
  border-left: 5px solid #2a6db0;
  border-radius: 7px;
  background: rgba(255,255,255,.5);
  font-size: .72rem;
  line-height: 1.35;
  font-weight: 700;
}

.event-log li.good {
  border-left-color: var(--green);
}

.event-log li.warn {
  border-left-color: var(--red);
}

.pokedex {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.dex-group {
  display: grid;
  gap: 7px;
}

.dex-group h3 {
  margin: 0;
  color: #293241;
  font-family: var(--pxfont);
  font-size: .48rem;
  line-height: 1.5;
}

.dex-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.dex-chip {
  min-width: 0;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  padding: 6px;
  border: 1px solid rgba(32,38,52,.2);
  border-left: 5px solid var(--type-color, #888);
  border-radius: 7px;
  background: rgba(255,255,255,.5);
}

.dex-chip img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  image-rendering: pixelated;
}

.dex-chip span {
  min-width: 0;
  color: #293241;
  font-size: .58rem;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legal {
  width: min(100%, 1320px);
  margin: 0 auto;
  color: rgba(238,242,255,.56);
  font-size: .72rem;
  line-height: 1.5;
  text-align: center;
}

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

  .brand,
  .controls {
    justify-content: center;
  }

  .game-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .log-panel,
  .pokedex-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  #app {
    padding: 8px;
  }

  .topbar {
    gap: 10px;
    padding: 8px;
  }

  .brand {
    font-size: .72rem;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hud-chip {
    padding: 7px 8px;
  }

  .hud-chip strong {
    font-size: .52rem;
  }

  .hud-chip small {
    font-size: .56rem;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr repeat(3, 42px);
    width: 100%;
  }

  .btn {
    font-size: .5rem;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .tower-list {
    grid-template-columns: 1fr;
  }

  .tower-card {
    min-height: 68px;
    grid-template-columns: 48px minmax(0, 1fr) auto;
  }

  .tower-card img {
    width: 44px;
    height: 44px;
  }

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

  .setup-grid,
  .specialization-options,
  .dex-list {
    grid-template-columns: 1fr;
  }
}
