:root {
  --ink: #1d211f;
  --stone: #ece5d8;
  --wall: #2f3731;
  --gold: #d9a441;
  --red: #b64032;
  --green: #5f8f65;
  --blue: #557f9f;
  --gray: #8b8d8a;
  --paper: #fffaf0;
  --shadow: 0 18px 44px rgba(20, 22, 20, .22);
}

* {
  box-sizing: border-box;
}

body {
  height: 100vh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
  background:
    linear-gradient(rgba(12, 14, 12, .2), rgba(12, 14, 12, .42)),
    url("assets/pokemon-gym-bg.png") center / cover fixed;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: #fff;
  font: inherit;
  font-weight: 800;
  background: var(--red);
  cursor: pointer;
  box-shadow: 0 5px 0 #77281f;
}

button:active {
  transform: translateY(2px);
  box-shadow: 0 3px 0 #77281f;
}

button.secondary {
  color: var(--ink);
  background: #ead8b6;
  box-shadow: 0 5px 0 #a78b5e;
}

.game-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, 500px);
  gap: 10px;
  height: 100vh;
  padding: 8px;
  overflow: hidden;
}

.dungeon,
.codex-board {
  border: 3px solid #111;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.dungeon {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  background:
    linear-gradient(rgba(13, 18, 16, .12), rgba(13, 18, 16, .44)),
    url("assets/pokemon-gym-bg.png") center / cover;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 14px;
  color: #f7edd8;
  background: linear-gradient(90deg, rgba(25, 31, 26, .9), rgba(83, 48, 38, .82));
  backdrop-filter: blur(3px);
}

.home-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-top: 0;
  padding: 0 14px;
  justify-content: center;
  color: var(--ink);
  background: #ead8b6;
  border: 1px solid rgba(255, 255, 255, .32);
  border-radius: 8px;
  box-shadow: 0 5px 0 #a78b5e;
  font-size: .86rem;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.home-link:hover {
  background: #f2dfbf;
}

.home-link:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

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

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 3vw, 2.65rem);
  line-height: 1;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  align-content: start;
  justify-content: flex-end;
  gap: 8px;
}

.stats span {
  border: 1px solid rgba(255,255,255,.32);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(0,0,0,.24);
  white-space: nowrap;
}

.stage {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 10px;
  flex: 1;
  min-height: 0;
  padding: 10px;
}

.map {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 0;
}

.room {
  display: grid;
  place-items: center;
  min-height: 48px;
  border: 3px solid #111;
  border-radius: 8px;
  padding: 4px;
  font-size: 1rem;
  font-weight: 900;
  text-align: center;
  background: rgba(200, 192, 173, .9);
}

button.room {
  width: 100%;
  color: var(--ink);
  box-shadow: none;
}

.region-room {
  align-content: center;
  gap: 2px;
  min-height: 56px;
}

.region-room:disabled {
  cursor: not-allowed;
  opacity: .55;
  filter: grayscale(.65);
}

.region-name,
.region-label {
  display: block;
  line-height: 1.15;
}

.region-name {
  font-size: .95rem;
}

.region-label {
  font-size: .68rem;
}

.room.active {
  color: #fff;
  background: var(--red);
}

.room.cleared {
  color: #fff;
  background: var(--green);
}

.encounter {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  align-content: end;
  gap: 12px;
  min-height: 0;
  padding: 12px;
  border: 3px solid #111;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 199, 89, .22), transparent 30%),
    linear-gradient(rgba(11, 14, 12, .08), rgba(11, 14, 12, .42));
  box-shadow: inset 0 0 0 999px rgba(0,0,0,.08);
}

.monster-card {
  display: grid;
  grid-template-columns: minmax(330px, 1fr) minmax(300px, 420px);
  align-items: end;
  gap: 18px;
}

.monster-arena {
  position: relative;
  display: grid;
  place-items: end center;
  min-height: clamp(440px, 62vh, 650px);
  overflow: visible;
}

.battle-message {
  position: absolute;
  z-index: 6;
  top: 6px;
  left: 50%;
  min-width: min(520px, 88%);
  border: 3px solid #120f0b;
  border-radius: 8px;
  padding: 10px 16px;
  color: #fff7d6;
  font-size: 1.25rem;
  font-weight: 900;
  text-align: center;
  background:
    linear-gradient(90deg, rgba(58, 25, 23, .94), rgba(24, 34, 30, .94)),
    radial-gradient(circle at 20% 30%, rgba(255, 210, 84, .32), transparent 38%);
  box-shadow:
    0 0 0 3px rgba(255, 205, 86, .25),
    0 12px 30px rgba(0,0,0,.45);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -10px) scale(.96);
  transition: opacity .18s ease, transform .18s ease;
}

.battle-message.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.battle-message::before,
.battle-message::after {
  position: absolute;
  top: 50%;
  width: 26px;
  height: 3px;
  background: #ffd66b;
  content: "";
}

.battle-message::before {
  left: 10px;
}

.battle-message::after {
  right: 10px;
}

.monster-arena::after {
  position: absolute;
  z-index: 3;
  inset: 18% 18%;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  content: "";
}

.monster-arena.hit::after {
  background:
    linear-gradient(115deg, transparent 36%, #fff7b3 37% 43%, #ffbf34 44% 50%, transparent 51%),
    radial-gradient(circle, rgba(255, 207, 72, .42), transparent 58%);
  animation: slash .52s ease-out;
}

.monster-arena.capturing::after {
  background:
    radial-gradient(circle, rgba(255,255,255,.8) 0 10%, rgba(255, 207, 72, .64) 11% 28%, transparent 48%);
  animation: captureBurst .88s ease-out;
}

.monster-arena.capturing .monster-image {
  animation: captureSink .88s ease-in-out;
}

.monster-arena.miss .monster-image {
  animation: missShake .26s ease-in-out 2;
}

.monster-arena.miss::after {
  border: 5px solid rgba(184, 50, 40, .86);
  box-shadow: 0 0 30px rgba(184, 50, 40, .6);
  animation: missPulse .5s ease-out;
}

.monster-shadow {
  position: absolute;
  bottom: 18px;
  width: min(420px, 72%);
  height: 54px;
  border-radius: 50%;
  background: rgba(0,0,0,.48);
  filter: blur(8px);
}

.monster-image {
  position: relative;
  z-index: 1;
  width: min(560px, 92%);
  max-height: min(560px, 72vh);
  object-fit: contain;
  cursor: pointer;
  filter: drop-shadow(0 24px 26px rgba(0,0,0,.48));
  animation: breathe 2.8s ease-in-out infinite;
}

.monster-arena.tapped-hop .monster-image {
  animation: monsterTapHop .72s ease-in-out;
}

.monster-arena.tapped-shrink .monster-image {
  animation: monsterTapShrink .72s ease-in-out;
}

.monster-arena.tapped-vanish .monster-image {
  animation: monsterTapVanish .72s ease-in-out;
}

.monster-arena.tapped-wiggle .monster-image {
  animation: monsterTapWiggle .82s ease-in-out;
}

.monster-arena.tapped-spin .monster-image {
  animation: monsterTapSpin .88s ease-in-out;
}

.monster-arena.tapped-dash .monster-image {
  animation: monsterTapDash .9s ease-in-out;
}

.monster-arena.tapped-bounce .monster-image {
  animation: monsterTapBounce .9s ease-in-out;
}

.monster-arena.tapped-sway .monster-image {
  animation: monsterTapSway 1.05s ease-in-out;
}

.monster-arena.tapped-pop .monster-image {
  animation: monsterTapPop 1s cubic-bezier(.2, .78, .28, 1);
}

.capture-orb {
  position: absolute;
  z-index: 5;
  right: 12%;
  bottom: 8%;
  width: 48px;
  height: 48px;
  border: 4px solid #101010;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, #fff 0 12%, transparent 13%),
    linear-gradient(#e74435 0 48%, #111 49% 55%, #f8f3e6 56% 100%);
  box-shadow: 0 8px 18px rgba(0,0,0,.45);
  opacity: 0;
  pointer-events: none;
}

.monster-arena.throwing .capture-orb {
  animation: throwOrb .72s cubic-bezier(.2, .7, .25, 1) forwards;
}

.challenge-card {
  align-self: center;
  border: 3px solid rgba(8, 10, 9, .92);
  border-radius: 8px;
  padding: 14px;
  color: #fff8df;
  background: rgba(20, 24, 21, .82);
  backdrop-filter: blur(4px);
}

.monster-label {
  margin-bottom: 6px;
  color: #ffcf6c;
  font-weight: 900;
}

.word-row {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 12px;
}

#targetWord {
  margin-bottom: 0;
  color: #fff8df;
  font-size: clamp(3.6rem, 9vw, 7.2rem);
  line-height: .9;
  text-shadow:
    4px 4px 0 #0c1110,
    7px 7px 0 rgba(0,0,0,.42);
}

.target-glyph {
  display: inline-block;
  color: inherit;
}

.code-reveal {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  min-height: 48px;
}

.code-reveal:empty {
  display: none;
}

.revealed-code {
  display: grid;
  grid-template-columns: auto auto;
  align-items: end;
  gap: 5px;
  border: 2px solid #111;
  border-radius: 8px;
  padding: 6px 9px;
  color: #111814;
  background: #fff8e8;
  box-shadow:
    0 0 0 3px rgba(255, 218, 98, .26),
    0 5px 0 rgba(0,0,0,.34);
}

.revealed-root {
  color: #d71920;
  font-size: 1.9rem;
  font-weight: 900;
  line-height: 1;
}

.revealed-letter {
  color: #0c2138;
  font-size: .78rem;
  font-weight: 900;
}

.breakdown {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.break-root {
  display: grid;
  grid-template-columns: auto auto;
  align-items: end;
  gap: 6px;
  border: 3px solid #0c1110;
  border-radius: 8px;
  padding: 8px 10px;
  color: #101412;
  background: var(--root-color);
  box-shadow: 0 5px 0 rgba(0,0,0,.34);
}

.break-symbol {
  color: #d71920;
  font-size: 2.4rem;
  font-weight: 900;
  line-height: 1;
}

.break-code {
  color: #0c2138;
  font-size: .95rem;
  font-weight: 900;
}

.break-plus {
  color: #fff8df;
  font-size: 1.7rem;
  font-weight: 900;
}

.needed-categories {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.category-chip {
  border: 2px solid #0c1110;
  border-radius: 999px;
  padding: 5px 9px;
  color: #121512;
  font-size: .9rem;
  font-weight: 900;
  background: var(--category-color);
}

.capture-info {
  margin-bottom: 0;
  color: #ffd77b;
  font-size: .92rem;
  font-weight: 900;
}

#hint {
  display: none;
  margin-bottom: 0;
  color: #f3e8c9;
  font-size: .98rem;
  font-weight: 800;
}

.answer-panel {
  border: 3px solid #111;
  border-radius: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  color: #111814;
  background: #fff8e8;
}

.answer-line {
  min-height: 32px;
  color: #111814;
  font-size: 1.35rem;
  font-weight: 900;
  text-shadow: none;
}

.letter-line {
  color: #49381f;
  font-weight: 800;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  margin-top: 10px;
  gap: 10px;
}

.codex-board {
  overflow: hidden;
  max-height: calc(100vh - 16px);
  background: rgba(255, 250, 240, .9);
}

.board-head {
  padding: 8px 10px;
  color: #fff8df;
  background: #222823;
}

.board-head h2 {
  margin-bottom: 2px;
  font-size: 1.05rem;
}

.board-head p {
  margin-bottom: 0;
  color: #dbc99d;
  font-size: .82rem;
  font-weight: 700;
}

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

.category {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-left: 2px solid #111;
  border-bottom: 2px solid #111;
}

.category:first-child {
  border-left: 0;
}

.category-title {
  display: grid;
  grid-column: 1 / -1;
  place-items: center;
  min-height: 32px;
  border-bottom: 3px solid #111;
  padding: 5px 7px;
  font-size: .88rem;
  font-weight: 900;
  text-align: center;
}

.root-button {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: start;
  gap: 5px;
  min-height: 46px;
  border: 0;
  border-bottom: 2px solid #111;
  border-radius: 0;
  padding: 5px 6px;
  color: var(--ink);
  background: #fff;
  box-shadow: none;
}

.root-button:hover,
.root-button.selected {
  outline: 4px solid var(--gold);
  outline-offset: -4px;
  background: #fff1bf;
}

.root-button.needed {
  position: relative;
  z-index: 1;
  outline: 4px solid #ffe36b;
  outline-offset: -3px;
  background: #fff1a8;
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,.9),
    0 0 16px rgba(255, 220, 76, .9);
  animation: neededGlow 1.45s ease-in-out infinite;
}

.root-button.needed::before {
  content: "";
  position: absolute;
  inset: 6px auto 6px 3px;
  width: 5px;
  border-radius: 999px;
  background: #f04438;
  box-shadow: 0 0 10px rgba(240, 68, 56, .72);
}

.root-button.needed:hover,
.root-button.needed.selected {
  outline-color: #ffb13b;
  background: #ffeaa1;
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,.95),
    0 0 22px rgba(255, 178, 59, .95);
}

.root-grid.hinting .root-button.needed {
  animation: hintFlash .42s ease-in-out 3;
}

.root-symbol {
  color: #d71920;
  font-size: 1.12rem;
  font-weight: 900;
  line-height: 1.15;
}

.root-meta {
  display: grid;
  gap: 1px;
  min-width: 0;
  text-align: left;
}

.root-letter {
  color: #0c2138;
  font-size: .66rem;
  font-weight: 900;
}

.root-shapes {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 3px;
  overflow: visible;
  color: #222;
  font-size: .76rem;
  font-weight: 800;
  line-height: 1.15;
  overflow-wrap: anywhere;
  white-space: normal;
}

.root-shape {
  display: inline-grid;
  place-items: center;
  min-width: 1.22em;
  min-height: 1.22em;
  border-radius: 4px;
  padding: 1px 2px;
  background: rgba(255,255,255,.42);
}

.toast {
  display: none;
}

.toast.show {
  display: none;
}

.pokedex-overlay {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(7, 10, 8, .68);
  backdrop-filter: blur(4px);
}

.pokedex-overlay[hidden] {
  display: none;
}

.pokedex-panel {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1180px, 100%);
  height: calc(100vh - 48px);
  max-height: 920px;
  border: 3px solid #111;
  border-radius: 8px;
  color: #fff8df;
  background: rgba(24, 30, 26, .96);
  box-shadow: 0 24px 60px rgba(0,0,0,.52);
  overflow: hidden;
}

.pokedex-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 3px solid #111;
  background: linear-gradient(90deg, #2b382f, #4b2d27);
}

.pokedex-head h2 {
  margin-bottom: 0;
}

.pokedex-grid {
  display: block;
  min-height: 0;
  max-height: none;
  padding: 14px;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.pokedex-grid.has-detail {
  display: block;
}

.pokedex-grid::-webkit-scrollbar {
  width: 12px;
}

.pokedex-grid::-webkit-scrollbar-track {
  background: rgba(255,255,255,.08);
  border-radius: 999px;
}

.pokedex-grid::-webkit-scrollbar-thumb {
  border: 2px solid rgba(22, 29, 24, .96);
  border-radius: 999px;
  background: #ffcf6c;
}

.pokedex-tabs {
  position: sticky;
  top: -14px;
  z-index: 8;
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  padding: 0 0 8px;
  overflow-x: auto;
  background: rgba(18, 27, 22, .98);
}

.pokedex-tab {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  display: grid;
  gap: 2px;
  min-width: 96px;
  border: 2px solid rgba(255, 207, 108, .34);
  border-bottom-color: #111;
  border-radius: 8px 8px 0 0;
  padding: 8px 10px;
  color: #fff8df;
  background: rgba(255, 250, 240, .1);
  font-weight: 900;
  text-align: left;
  cursor: pointer;
  pointer-events: auto;
}

.pokedex-tab strong {
  color: #ffcf6c;
  font-size: .88rem;
}

.pokedex-tab.active {
  color: #111;
  background: #ffcf6c;
  border-color: #111;
  box-shadow: 0 -2px 0 rgba(255,255,255,.32) inset;
}

.pokedex-tab.active strong {
  color: #8a1f17;
}

.pokedex-detail {
  position: sticky;
  top: 62px;
  z-index: 7;
  display: grid;
  grid-template-columns: minmax(170px, 240px) minmax(150px, 240px) minmax(260px, 1fr) auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
  border: 2px solid rgba(255, 207, 108, .46);
  border-radius: 8px;
  padding: 12px;
  background:
    radial-gradient(circle at 18% 50%, rgba(255, 207, 108, .22), transparent 58%),
    linear-gradient(90deg, #353827, #18231d 62%, #142019);
  box-shadow: 0 12px 22px rgba(0,0,0,.34);
}

.pokedex-detail-image {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 8px;
  background: radial-gradient(circle at 50% 45%, rgba(255, 217, 118, .28), rgba(255,255,255,.06) 68%);
}

.pokedex-detail-image img {
  width: 92%;
  height: 92%;
  object-fit: contain;
  filter: drop-shadow(0 16px 18px rgba(0,0,0,.45));
}

.pokedex-detail-meta {
  display: grid;
  gap: 6px;
}

.pokedex-detail-meta h3 {
  margin: 0;
  color: #ffcf6c;
  font-size: clamp(1.45rem, 3vw, 2.2rem);
}

.pokedex-detail-meta p {
  margin: 0;
  color: #fff8df;
  font-weight: 900;
}

.pokedex-profile {
  display: grid;
  align-self: stretch;
  align-content: start;
  gap: 6px;
  max-height: 190px;
  overflow-y: auto;
  border-left: 2px solid rgba(255, 207, 108, .28);
  padding: 6px 12px;
  color: #fff8df;
  background: rgba(8, 15, 11, .34);
}

.pokedex-profile h4 {
  margin: 0;
  color: #ffcf6c;
  font-size: .95rem;
}

.pokedex-profile p {
  margin: 0;
  line-height: 1.5;
  font-size: .92rem;
  font-weight: 800;
}

.pokedex-detail-close {
  align-self: start;
  min-height: 38px;
  padding: 0 12px;
}

.pokedex-region {
  display: block;
  min-height: 0;
  overflow: visible;
}

.pokedex-region-head {
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  border: 2px solid rgba(255, 207, 108, .35);
  border-radius: 8px;
  padding: 10px 12px;
  color: #fff8df;
  background: #14231a;
  box-shadow: 0 8px 16px rgba(0,0,0,.28);
}

.pokedex-region-head h3 {
  margin: 0;
  font-size: 1.12rem;
}

.pokedex-region-head span {
  color: #ffcf6c;
  font-weight: 900;
}

.pokedex-region-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
  align-content: start;
  gap: 10px;
  max-height: none;
  min-height: 0;
  height: auto;
  overflow: visible;
  padding: 0 4px 18px 0;
}

.pokedex-entry {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 178px;
  border: 2px solid rgba(255,255,255,.18);
  border-radius: 8px;
  padding: 0;
  color: inherit;
  text-align: left;
  overflow: hidden;
  background: rgba(255, 250, 240, .1);
  box-shadow: none;
}

.pokedex-entry.captured {
  cursor: pointer;
}

.pokedex-entry.captured:hover {
  border-color: #ffcf6c;
  background: rgba(255, 207, 108, .16);
}

.pokedex-entry:disabled {
  cursor: default;
}

.pokedex-image-wrap {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 128px;
  flex: 0 0 auto;
  aspect-ratio: 1;
  background: radial-gradient(circle at 50% 45%, rgba(255, 217, 118, .24), rgba(255,255,255,.06) 62%);
}

.pokedex-entry img {
  display: block;
  width: 84%;
  height: 84%;
  object-fit: contain;
}

.pokedex-entry.unknown img {
  filter: grayscale(1) brightness(.08);
  opacity: .72;
}

.pokedex-entry-meta {
  display: grid;
  gap: 2px;
  padding: 8px 10px 10px;
  color: #fff8df;
  font-weight: 900;
}

.pokedex-entry-meta span {
  color: #ffcf6c;
}

@keyframes breathe {
  0%,
  100% {
    transform: translateY(6px) scale(1);
  }

  50% {
    transform: translateY(-2px) scale(1.025);
  }
}

@keyframes slash {
  0% {
    opacity: 0;
    transform: scale(.72) rotate(-10deg);
  }

  35% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: scale(1.18) rotate(6deg);
  }
}

@keyframes missShake {
  0%,
  100% {
    transform: translateX(0);
  }

  35% {
    transform: translateX(-10px);
  }

  70% {
    transform: translateX(10px);
  }
}

@keyframes missPulse {
  0% {
    opacity: 0;
    transform: scale(.82);
  }

  45% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: scale(1.1);
  }
}

@keyframes throwOrb {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(.72) rotate(0deg);
  }

  45% {
    transform: translate(-130px, -160px) scale(1) rotate(320deg);
  }

  82% {
    opacity: 1;
    transform: translate(-260px, -105px) scale(1.08) rotate(620deg);
  }

  100% {
    opacity: 0;
    transform: translate(-285px, -112px) scale(.35) rotate(700deg);
  }
}

@keyframes captureBurst {
  0% {
    opacity: 0;
    transform: scale(.45);
  }

  38% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: scale(1.35);
  }
}

@keyframes captureSink {
  0% {
    opacity: 1;
    transform: translateY(6px) scale(1);
  }

  72% {
    opacity: .35;
    transform: translateY(18px) scale(.72);
  }

  100% {
    opacity: 1;
    transform: translateY(6px) scale(1);
  }
}

@keyframes monsterTapHop {
  0% {
    opacity: 1;
    transform: translate(0, 6px) scale(1);
  }

  34% {
    opacity: .82;
    transform: translate(-24px, -18px) scale(.86);
  }

  62% {
    opacity: 0;
    transform: translate(32px, 20px) scale(.42);
  }

  100% {
    opacity: 1;
    transform: translate(0, 6px) scale(1);
  }
}

@keyframes monsterTapShrink {
  0% {
    opacity: 1;
    transform: translateY(6px) scale(1);
  }

  45% {
    opacity: .78;
    transform: translateY(18px) scale(.58);
  }

  100% {
    opacity: 1;
    transform: translateY(6px) scale(1);
  }
}

@keyframes monsterTapVanish {
  0% {
    opacity: 1;
    transform: translateY(6px) scale(1);
  }

  38% {
    opacity: 0;
    transform: translate(28px, -12px) scale(.36);
  }

  64% {
    opacity: 0;
    transform: translate(-18px, 16px) scale(.64);
  }

  100% {
    opacity: 1;
    transform: translateY(6px) scale(1);
  }
}

@keyframes monsterTapWiggle {
  0%,
  100% {
    transform: translateY(6px) rotate(0deg) scale(1);
  }

  18% {
    transform: translate(-10px, 2px) rotate(-7deg) scale(1.04);
  }

  38% {
    transform: translate(12px, 4px) rotate(7deg) scale(.98);
  }

  62% {
    transform: translate(-7px, 0) rotate(-4deg) scale(1.02);
  }

  82% {
    transform: translate(5px, 5px) rotate(3deg) scale(1);
  }
}

@keyframes monsterTapSpin {
  0% {
    transform: translateY(6px) rotate(0deg) scale(1);
  }

  45% {
    transform: translateY(-10px) rotate(12deg) scale(1.08);
  }

  72% {
    transform: translateY(4px) rotate(-8deg) scale(.98);
  }

  100% {
    transform: translateY(6px) rotate(0deg) scale(1);
  }
}

@keyframes monsterTapDash {
  0% {
    opacity: 1;
    transform: translateY(6px) scale(1);
  }

  32% {
    opacity: .96;
    transform: translate(52px, 2px) scale(.98);
  }

  34% {
    opacity: 0;
    transform: translate(72px, 2px) scale(.94);
  }

  58% {
    opacity: 0;
    transform: translate(-58px, 2px) scale(.94);
  }

  72% {
    opacity: 1;
    transform: translate(-18px, 0) scale(1.03);
  }

  100% {
    opacity: 1;
    transform: translateY(6px) scale(1);
  }
}

@keyframes monsterTapBounce {
  0%,
  100% {
    transform: translateY(6px) scale(1);
  }

  24% {
    transform: translateY(-28px) scale(1.06, .94);
  }

  48% {
    transform: translateY(12px) scale(.94, 1.08);
  }

  70% {
    transform: translateY(-12px) scale(1.02, .98);
  }
}

@keyframes monsterTapSway {
  0%,
  100% {
    transform: translateY(6px) rotate(0deg) scale(1);
  }

  22% {
    transform: translate(-18px, -4px) rotate(-5deg) scale(1.04);
  }

  48% {
    transform: translate(22px, -8px) rotate(6deg) scale(1.02);
  }

  74% {
    transform: translate(-8px, 2px) rotate(-3deg) scale(.99);
  }
}

@keyframes monsterTapPop {
  0% {
    opacity: .72;
    transform: translateY(16px) scale(.72);
  }

  30% {
    opacity: 1;
    transform: translateY(-24px) scale(1.16);
  }

  58% {
    transform: translateY(10px) scale(.96, 1.06);
  }

  100% {
    opacity: 1;
    transform: translateY(6px) scale(1);
  }
}

@keyframes neededGlow {
  0%,
  100% {
    filter: brightness(1);
    box-shadow:
      inset 0 0 0 2px rgba(255,255,255,.9),
      0 0 10px rgba(255, 220, 76, .72);
  }

  50% {
    filter: brightness(1.08);
    box-shadow:
      inset 0 0 0 2px rgba(255,255,255,.95),
      0 0 24px rgba(255, 220, 76, 1);
  }
}

@keyframes hintFlash {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.06);
  }
}

@media (max-width: 980px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .game-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .codex-board {
    order: 2;
  }

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

  .root-button {
    min-height: 64px;
  }

  .pokedex-detail {
    grid-template-columns: minmax(140px, 190px) minmax(0, 1fr) auto;
  }

  .pokedex-profile {
    grid-column: 1 / -1;
    max-height: 140px;
    border-top: 2px solid rgba(255, 207, 108, .28);
    border-left: 0;
  }
}

@media (max-width: 640px) {
  .game-shell {
    gap: 8px;
    padding: 8px;
  }

  .top-bar,
  .stage,
  .monster-card {
    grid-template-columns: 1fr;
  }

  .top-bar {
    display: grid;
    gap: 8px;
    padding: 10px 12px;
  }

  .top-bar h1 {
    font-size: 1.25rem;
  }

  .top-bar .eyebrow {
    margin-bottom: 2px;
    font-size: .72rem;
  }

  .stats {
    justify-content: start;
    font-size: .86rem;
  }

  .stage {
    gap: 8px;
    padding: 8px;
  }

  .map {
    display: flex;
    gap: 6px;
    margin: -2px -2px 2px;
    padding: 2px 2px 8px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
  }

  .room {
    min-height: 42px;
    font-size: .86rem;
  }

  .region-room {
    flex: 0 0 86px;
    scroll-snap-align: start;
    padding: 5px 4px;
  }

  .region-name {
    font-size: .9rem;
  }

  .region-label {
    font-size: .68rem;
    line-height: 1.15;
  }

  .encounter {
    min-height: auto;
    padding: 8px;
  }

  .monster-arena {
    min-height: 170px;
  }

  .battle-message {
    min-width: 92%;
    font-size: 1rem;
  }

  .monster-image {
    width: min(230px, 70%);
  }

  .challenge-card {
    position: sticky;
    top: 6px;
    z-index: 18;
    padding: 10px;
    background: rgba(20, 24, 21, .92);
  }

  .word-row {
    gap: 8px;
  }

  .word-row h2 {
    font-size: clamp(2.8rem, 18vw, 5rem);
  }

  .capture-info,
  .answer-line,
  .letter-line {
    font-size: .9rem;
  }

  .actions {
    position: sticky;
    bottom: 0;
    z-index: 19;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin: 8px -4px -4px;
    padding: 6px 4px 4px;
    background: rgba(20, 24, 21, .95);
  }

  .actions button {
    min-height: 42px;
    padding: 0 6px;
    font-size: .88rem;
  }

  .break-symbol {
    font-size: 2rem;
  }

  .codex-board {
    order: 2;
    max-height: none;
    overflow: visible;
  }

  .board-head {
    position: sticky;
    top: 0;
    z-index: 16;
    padding: 9px 10px;
  }

  .board-head h2 {
    font-size: 1rem;
  }

  .board-head p {
    display: none;
  }

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

  .category {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .category-title {
    writing-mode: vertical-rl;
    min-height: auto;
    min-width: 54px;
    font-size: 1rem;
  }

  .root-button {
    grid-template-columns: 30px minmax(0, 1fr);
    min-height: 58px;
    padding: 6px;
  }

  .root-symbol {
    font-size: 1.15rem;
  }

  .root-shapes {
    font-size: .76rem;
  }

  .pokedex-overlay {
    padding: 8px;
  }

  .pokedex-panel {
    max-height: calc(100vh - 16px);
  }

  .pokedex-region-grid {
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  }

  .pokedex-detail {
    grid-template-columns: 96px minmax(0, 1fr) auto;
    gap: 10px;
  }

  .pokedex-profile {
    max-height: 120px;
    padding: 8px 0 0;
  }

  .pokedex-entry {
    min-height: 148px;
  }

  .pokedex-image-wrap {
    min-height: 102px;
  }
}

@media (max-width: 420px) {
  .monster-arena {
    min-height: 140px;
  }

  .monster-image {
    width: min(190px, 66%);
  }

  .challenge-card {
    padding: 8px;
  }

  .answer-panel {
    padding: 7px 9px;
  }

  .actions button {
    font-size: .82rem;
  }

  .region-room {
    flex-basis: 78px;
  }

  .category {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .category-title {
    min-width: 48px;
  }
}
