:root {
  color-scheme: dark;
  --bg: #08111f;
  --panel: #101c2f;
  --panel-2: #17243a;
  --text: #f8fafc;
  --muted: #a8b3c7;
  --accent: #facc15;
  --blue: #2563eb;
  --danger: #fb7185;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.22), transparent 34rem),
    linear-gradient(135deg, #08111f 0%, #151a2f 52%, #0b1324 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: #f8fafc;
  color: #0f172a;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

.app {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 28px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
  gap: 18px;
  align-items: start;
}

.game-panel,
.side-panel {
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 8px;
  background: rgba(16, 28, 47, 0.86);
  box-shadow: 0 20px 55px rgba(0, 0, 0, 0.25);
}

.game-panel {
  padding: clamp(12px, 2vw, 18px);
}

.side-panel {
  padding: 16px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 4vw, 2.5rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.hud p,
.message,
.character-card span {
  color: var(--muted);
}

.stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: end;
}

.stats span {
  min-width: 90px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel-2);
  text-align: center;
  color: var(--muted);
}

.stats strong {
  display: block;
  color: var(--accent);
  font-size: 1.25rem;
}

#gameCanvas {
  display: block;
  width: 100%;
  max-width: min(100%, 760px, calc(100vh - 210px));
  aspect-ratio: 19 / 17;
  height: auto;
  margin: 0 auto;
  border: 4px solid var(--blue);
  border-radius: 8px;
  background: #020617;
  touch-action: none;
}

#gameCanvas.win-glow {
  box-shadow: 0 0 0 4px rgba(250, 204, 21, 0.2), 0 0 44px rgba(250, 204, 21, 0.46);
}

#gameCanvas.lose-shake {
  animation: board-shake 0.22s linear infinite;
}

#gameCanvas.lose-glow {
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.18), 0 0 44px rgba(251, 113, 133, 0.42);
}

#gameCanvas.caught-pop {
  animation: caught-pop 0.9s ease-out;
}

@keyframes board-shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-3px);
  }

  75% {
    transform: translateX(3px);
  }
}

@keyframes caught-pop {
  0% {
    filter: saturate(1);
    box-shadow: 0 0 0 0 rgba(251, 113, 133, 0.65);
  }

  35% {
    filter: saturate(1.55) brightness(1.18);
    box-shadow: 0 0 0 8px rgba(251, 113, 133, 0.24), 0 0 32px rgba(250, 204, 21, 0.45);
  }

  100% {
    filter: saturate(1);
    box-shadow: 0 0 0 0 rgba(251, 113, 133, 0);
  }
}

.message {
  min-height: 24px;
  margin-top: 12px;
  text-align: center;
  font-weight: 700;
}

.message.win {
  color: #86efac;
}

.message.lose {
  color: var(--danger);
}

.actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.actions button {
  min-width: 130px;
  padding: 0 14px;
}

.character-list {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}

.character-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
  border-radius: 8px;
  background: var(--panel-2);
}

.character-card img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #0f172a;
}

.character-card strong,
.character-card span {
  display: block;
}

.touch-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(58px, 1fr));
  gap: 8px;
}

.touch-pad button {
  padding: 0 6px;
}

@media (max-width: 820px) {
  .app {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .side-panel {
    display: none;
  }

  .hud {
    display: grid;
  }

  .stats {
    justify-content: stretch;
  }

  .stats span {
    flex: 1;
  }

  #gameCanvas {
    max-width: min(100%, calc(100vh - 250px));
  }
}

@media (max-width: 520px) {
  .app {
    padding: 10px;
    gap: 10px;
  }

  .game-panel,
  .side-panel {
    padding: 10px;
  }

  .stats span {
    min-width: 0;
  }

  #gameCanvas {
    border-width: 3px;
    max-width: 100%;
  }
}
