:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #5c667a;
  --paper: #fffdf7;
  --panel: #ffffff;
  --line: #d9dfeb;
  --body-start: #f5fbff;
  --body-end: #fff4f0;
  --stage-wash-start: rgba(255, 255, 255, 0.76);
  --stage-wash-end: rgba(255, 255, 255, 0.92);
  --stage-grid-blue: rgba(47, 128, 237, 0.08);
  --stage-grid-green: rgba(69, 179, 107, 0.08);
  --control-bg: #eef3f9;
  --red: #e53e3e;
  --blue: #2f80ed;
  --yellow: #ffd166;
  --green: #45b36b;
  --shadow: 0 18px 45px rgba(32, 42, 68, 0.16);
}

body.is-dark {
  color-scheme: dark;
  --ink: #f3f7ff;
  --muted: #aeb9ca;
  --paper: #101827;
  --panel: #182235;
  --line: #344257;
  --body-start: #09111f;
  --body-end: #1f2937;
  --stage-wash-start: rgba(13, 20, 33, 0.86);
  --stage-wash-end: rgba(18, 28, 45, 0.94);
  --stage-grid-blue: rgba(96, 165, 250, 0.12);
  --stage-grid-green: rgba(74, 222, 128, 0.1);
  --control-bg: rgba(24, 34, 53, 0.9);
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 209, 102, 0.24), transparent 28rem),
    linear-gradient(135deg, var(--body-start) 0%, var(--paper) 46%, var(--body-end) 100%);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 24px;
}

.topbar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
}

h1 {
  margin: 0;
  font-size: clamp(2.5rem, 7vw, 5.5rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.topbar p {
  max-width: 36rem;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.theme-toggle-button {
  min-height: 42px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--control-bg);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(32, 42, 68, 0.1);
}

.theme-toggle-button:hover {
  filter: brightness(0.97);
}

.primary-button,
.danger-button,
.reset-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: #ffffff;
  cursor: pointer;
}

.primary-button {
  background: var(--blue);
  box-shadow: 0 10px 22px rgba(47, 128, 237, 0.24);
}

.success-button {
  background: var(--green);
  box-shadow: 0 10px 22px rgba(69, 179, 107, 0.22);
}

.danger-button,
.remove-button {
  background: #c93636;
  box-shadow: 0 10px 22px rgba(201, 54, 54, 0.2);
}

.reset-button {
  position: absolute;
  right: 24px;
  bottom: 24px;
  z-index: 2;
  background: var(--blue);
  box-shadow: 0 10px 22px rgba(47, 128, 237, 0.24);
}

.tutorial-button {
  position: absolute;
  left: 24px;
  bottom: 24px;
  z-index: 2;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: var(--ink);
  background: var(--control-bg);
  box-shadow: none;
  cursor: pointer;
}

.primary-button:hover,
.danger-button:hover,
.reset-button:hover,
.tutorial-button:hover {
  filter: brightness(0.96);
}

.primary-button:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.54;
}

.game-stage {
  position: relative;
  display: grid;
  place-items: center;
  padding: 92px 24px 88px;
  min-height: clamp(640px, calc(100vh - 190px), 760px);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: clip;
  touch-action: pan-y;
  background:
    linear-gradient(var(--stage-wash-start), var(--stage-wash-end)),
    repeating-linear-gradient(
      0deg,
      transparent 0 42px,
      var(--stage-grid-blue) 42px 44px
    ),
    repeating-linear-gradient(
      90deg,
      transparent 0 42px,
      var(--stage-grid-green) 42px 44px
    );
  box-shadow: var(--shadow);
}

.tutorial-modal {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: clamp(14px, 3vw, 32px);
  background: rgba(23, 32, 51, 0.72);
}

.tutorial-window {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
  width: min(960px, 100%);
  height: min(680px, 100%);
  max-height: 100%;
  border: 1px solid rgba(217, 223, 235, 0.9);
  border-radius: 8px;
  padding: clamp(14px, 2vw, 22px);
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.tutorial-window h2 {
  margin: 0;
  text-align: center;
  font-size: 1.25rem;
}

.tutorial-viewer {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  align-items: center;
  gap: clamp(10px, 2vw, 18px);
  min-height: 0;
  overflow: hidden;
}

.tutorial-viewer img {
  display: block;
  width: 100%;
  max-height: min(510px, 62vh);
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
  background: var(--control-bg);
}

.tutorial-arrow {
  display: grid;
  place-items: center;
  width: clamp(42px, 8vw, 58px);
  aspect-ratio: 1;
  border: 0;
  color: transparent;
  background: transparent;
  cursor: pointer;
}

.tutorial-arrow::before {
  content: "";
  width: 100%;
  aspect-ratio: 1;
  clip-path: polygon(18% 8%, 18% 92%, 92% 50%);
  background: var(--ink);
  filter: drop-shadow(0 10px 14px rgba(32, 42, 68, 0.16));
}

#previousTutorialButton::before {
  transform: rotate(180deg);
}

.tutorial-arrow:hover::before {
  opacity: 0.86;
}

.tutorial-counter {
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.close-tutorial-button {
  position: absolute;
  right: 18px;
  bottom: 18px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: #ffffff;
  background: var(--blue);
  box-shadow: 0 10px 22px rgba(47, 128, 237, 0.24);
  cursor: pointer;
}

.hud {
  position: absolute;
  top: 18px;
  right: 22px;
  z-index: 1;
  display: grid;
  gap: 8px;
  justify-items: end;
}

.round-counter,
.coin-counter {
  margin: 0;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--ink);
  background: var(--control-bg);
  font-weight: 800;
}

.spawn-selection {
  display: grid;
  justify-items: center;
  gap: clamp(22px, 4vh, 34px);
  width: min(820px, calc(100% - 32px));
}

.spawn-selection[hidden],
.active-charm-badge[hidden] {
  display: none;
}

.ball-carousel {
  display: grid;
  grid-template-columns: minmax(72px, 0.55fr) minmax(160px, 1fr) minmax(72px, 0.55fr);
  align-items: center;
  justify-items: center;
  gap: clamp(12px, 4vw, 34px);
  width: min(720px, 100%);
  touch-action: pan-y;
}

.ball-choice {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 12px;
  border: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    filter 180ms ease;
}

.ball-choice[data-slot="center"] {
  transform: scale(1);
}

.ball-choice[data-slot="side"] {
  opacity: 0.42;
  transform: scale(0.66);
  filter: saturate(0.72);
}

.ball-choice[data-slot="side"]:hover {
  opacity: 0.72;
  transform: scale(0.72);
}

.ball-choice.is-locked {
  opacity: 0.34;
  filter: grayscale(0.85) saturate(0.35);
}

.ball-choice.is-locked::after {
  content: "";
  position: absolute;
  top: 38%;
  left: 50%;
  width: clamp(34px, 6vw, 58px);
  height: clamp(28px, 5vw, 46px);
  border: clamp(4px, 0.7vw, 7px) solid #172033;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 50%, #172033 0 24%, transparent 15%),
    conic-gradient(from 0deg at 50% 48%, transparent 0 159deg, #172033 160deg 200deg, transparent 201deg 360deg),
    rgba(255, 255, 255, 0.82);
  transform: translate(-50%, -50%);
}

.ball-choice.is-locked::before {
  content: "";
  position: absolute;
  top: calc(38% - clamp(30px, 5.4vw, 62px));
  left: 50%;
  width: clamp(22px, 4vw, 38px);
  height: clamp(28px, 5vw, 5px);
  border: clamp(4px, 0.7vw, 7px) solid #172033;
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  transform: translateX(-50%);
  z-index: 1;
}

.ball-label {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  background: var(--control-bg);
  font-weight: 800;
  text-align: center;
}

.ball-carousel.is-splitting {
  opacity: 0;
}

.spawn-selection.is-splitting {
  pointer-events: none;
}

.spawn-selection.is-splitting .charm-section {
  opacity: 0;
}

.charm-section {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(640px, 100%);
}

.charm-section h2 {
  margin: 0;
  font-size: clamp(1rem, 2vw, 1.35rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.charm-carousel {
  display: grid;
  grid-template-columns: minmax(82px, 0.6fr) minmax(128px, 1fr) minmax(82px, 0.6fr);
  align-items: center;
  justify-items: center;
  gap: clamp(10px, 3vw, 24px);
  width: 100%;
  touch-action: pan-y;
}

.charm-choice {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 8px;
  border: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    filter 180ms ease;
}

.charm-choice[data-slot="center"] {
  transform: scale(1);
}

.charm-choice[data-slot="side"] {
  opacity: 1;
  transform: translateY(-25px) scale(1);
}

.charm-choice[data-slot="side"]:hover {
  transform: translateY(-27px);
}

.charm-choice.is-locked,
.charm-choice.is-disabled {
  cursor: not-allowed;
  opacity: 0.36;
  filter: grayscale(0.8) saturate(0.45);
}

.charm-choice.is-locked::after {
  content: "";
  position: absolute;
  top: 34.5%;
  left: 50%;
  width: clamp(26px, 5vw, 37px);
  height: clamp(22px, 4.4vw, 34px);
  border: clamp(3px, 0.6vw, 5px) solid #172033;
  border-radius: 7px;
  background:
    radial-gradient(circle at 50% 48%, #172033 0 20%, transparent 21%),
    conic-gradient(from 0deg at 50% 50%, transparent 0 158deg, #172033 159deg 201deg, transparent 202deg 360deg),
    rgba(255, 255, 255, 0.9);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.charm-choice.is-locked::before {
  content: "";
  position: absolute;
  top: calc(34.5% - clamp(22px, 4.2vw, 42px));
  left: 50%;
  width: clamp(18px, 3.6vw, 20px);
  height: clamp(20px, 4vw, 1px);
  border: clamp(3px, 0.6vw, 5px) solid #172033;
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 1;
}

.charm-choice.is-selected .charm-token {
  box-shadow:
    0 0 0 4px rgba(69, 179, 107, 0.26),
    0 16px 28px rgba(32, 42, 68, 0.16);
}

.charm-arrow {
  display: grid;
  place-items: center;
  width: clamp(42px, 8vw, 58px);
  aspect-ratio: 1;
  clip-path: polygon(18% 8%, 18% 92%, 92% 50%);
  color: transparent;
  background: #172033;
  filter: drop-shadow(0 10px 14px rgba(32, 42, 68, 0.16));
}

body.is-dark .charm-arrow {
  background: #ffffff;
}

.charm-choice[data-slot="side"]:first-child .charm-arrow {
  transform: rotate(180deg);
}

.charm-token {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(62px, 11vw, 96px);
  aspect-ratio: 1;
  border: 4px solid #172033;
  color: #172033;
  font-size: clamp(1.05rem, 2.4vw, 1.65rem);
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 14px 24px rgba(32, 42, 68, 0.12);
}

.charm-label {
  max-width: 136px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 9px;
  background: var(--control-bg);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

.charm-cost {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.charm-description {
  max-width: min(560px, 100%);
  min-height: 2.6em;
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
  line-height: 1.3;
}

.charm-token.charm-gen-a,
.mini-charm.charm-gen-a {
  border-radius: 50%;
  background: linear-gradient(145deg, #ffcf59, #f45d48);
}

.charm-token.charm-gen-b,
.mini-charm.charm-gen-b {
  border-radius: 18px;
  background: linear-gradient(145deg, #70d6ff, #5f7cff);
  transform: rotate(45deg);
}

.charm-token.charm-gen-b span {
  transform: rotate(-45deg);
}

.charm-token.charm-gen-c,
.mini-charm.charm-gen-c {
  clip-path: polygon(50% 0, 96% 26%, 96% 74%, 50% 100%, 4% 74%, 4% 26%);
  background: linear-gradient(145deg, #b9fbc0, #00a878);
}

.charm-token.charm-fire,
.mini-charm.charm-fire {
  border-radius: 52% 48% 52% 48% / 64% 64% 36% 36%;
  background: linear-gradient(145deg, #ff6b35, #ffe156);
}

.charm-token.charm-water,
.mini-charm.charm-water {
  border-radius: 50% 50% 50% 8px;
  background: linear-gradient(145deg, #48cae4, #4361ee);
  transform: rotate(-45deg);
}

.charm-token.charm-water span {
  transform: rotate(45deg);
}

.charm-token.charm-mind,
.mini-charm.charm-mind {
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #ffffff 0 18%, transparent 19%),
    conic-gradient(#ff8fab, #b388eb, #ffd166, #ff8fab);
}

.charm-token.charm-nature,
.mini-charm.charm-nature {
  border-radius: 72% 28% 72% 28%;
  background: linear-gradient(145deg, #99d98c, #f4a261);
}

.charm-token.charm-stone,
.mini-charm.charm-stone {
  clip-path: polygon(18% 6%, 82% 6%, 100% 44%, 72% 96%, 28% 96%, 0 44%);
  background: linear-gradient(145deg, #b8c0c2, #8d99ae);
}

.charm-token.charm-shadow,
.mini-charm.charm-shadow {
  border-radius: 20px 50% 20px 50%;
  background: linear-gradient(145deg, #8e44ad, #2d3142);
  color: #ffffff;
}

.active-charm-badge {
  position: absolute;
  top: 18px;
  left: 22px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--control-bg);
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(32, 42, 68, 0.12);
}

.active-charm-badge .mini-charm {
  width: 22px;
  aspect-ratio: 1;
  border: 2px solid #172033;
}

.split-ball-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.split-ball-copy {
  position: absolute;
  width: clamp(150px, 24vw, 250px);
  aspect-ratio: 1;
}

.split-ball-copy:first-child {
  animation: split-left 720ms ease-in-out both;
}

.split-ball-copy:last-child {
  animation: split-right 720ms ease-in-out both;
}

.pokeball-button {
  width: clamp(150px, 24vw, 250px);
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transition:
    transform 180ms ease,
    filter 180ms ease;
}

.pokeball-button:hover {
  transform: translateY(-4px) scale(1.02);
  filter: drop-shadow(0 16px 22px rgba(23, 32, 51, 0.2));
}

.pokeball-button:disabled {
  cursor: wait;
}

.pokeball {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border: 8px solid #172033;
  border-radius: 50%;
  overflow: hidden;
  background:
    linear-gradient(to bottom, var(--red) 0 48%, #172033 48% 53%, #ffffff 53% 100%);
  box-shadow:
    inset 0 -16px 26px rgba(23, 32, 51, 0.16),
    0 24px 60px rgba(23, 32, 51, 0.2);
}

.pokeball.great-ball {
  background:
    radial-gradient(circle at 22% 18%, var(--red) 0 12%, transparent 13%),
    radial-gradient(circle at 78% 18%, var(--red) 0 12%, transparent 13%),
    linear-gradient(to bottom, var(--blue) 0 48%, #172033 48% 53%, #ffffff 53% 100%);
}

.pokeball.ultra-ball {
  background:
    linear-gradient(90deg, transparent 0 32%, var(--yellow) 32% 42%, transparent 42% 58%, var(--yellow) 58% 68%, transparent 68% 100%) top / 100% 48% no-repeat,
    linear-gradient(to bottom, #252b35 0 48%, #172033 48% 53%, #ffffff 53% 100%);
}

.pokeball.master-ball {
  background:
    radial-gradient(circle at 22% 18%, #d914ab 0 12%, transparent 13%),
    radial-gradient(circle at 78% 18%, #d914ab 0 12%, transparent 13%),
    linear-gradient(to bottom, #a33ab8 0 48%, #172033 48% 53%, #ffffff 53% 100%);
}

.pokeball.master-ball::before {
  content: "M";
  position: absolute;
  left: 50%;
  top: 21%;
  color: #ffffff;
  font-size: clamp(1.5rem, 6vw, 3.8rem);
  font-weight: 900;
  line-height: 1;
  transform: translateX(-50%);
}

.pokeball-band {
  position: absolute;
  inset: 46% 0 auto;
  height: 9%;
  background: #172033;
}

.pokeball-button-dot {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 31%;
  aspect-ratio: 1;
  border: 8px solid #172033;
  border-radius: 50%;
  background: #ffffff;
  transform: translate(-50%, -50%);
}

.encounter-panel {
  width: min(820px, calc(100% - 32px));
  display: grid;
  gap: 18px;
  justify-items: center;
  padding-bottom: 72px;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: auto;
}

.pokemon-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.pokemon-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--panel);
  box-shadow: 0 16px 32px rgba(32, 42, 68, 0.12);
  text-align: center;
}

.sprite-wrap {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1.12;
  border-radius: 8px;
  background:
    radial-gradient(circle, rgba(255, 209, 102, 0.42), transparent 42%),
    linear-gradient(145deg, #f7fbff, #fff8eb);
}

.pokemon-card.is-shiny .sprite-wrap {
  background:
    radial-gradient(circle, rgba(255, 209, 102, 0.64), transparent 40%),
    linear-gradient(145deg, #fff8cf, #eef9ff);
}

.pokemon-card img {
  width: min(82%, 260px);
  aspect-ratio: 1;
  object-fit: contain;
  image-rendering: auto;
}

.pokemon-card h2 {
  margin: 16px 0 0;
  font-size: clamp(1.25rem, 3vw, 2rem);
  line-height: 1.1;
  letter-spacing: 0;
  text-transform: capitalize;
  overflow-wrap: anywhere;
  hyphens: auto;
}

.pokemon-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

.encounter-description {
  max-width: min(520px, 100%);
  margin: -6px 0 0;
  color: var(--muted);
  text-align: center;
}

.box-panel {
  position: absolute;
  inset: 32px;
  z-index: 4;
  width: auto;
  min-height: 0;
  padding: 64px 36px 96px;
  display: grid;
  grid-template-columns: 52px minmax(0, 420px) 52px;
  grid-template-areas:
    "previous card next";
  justify-content: center;
  align-items: center;
  gap: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(var(--stage-wash-start), var(--stage-wash-end)),
    repeating-linear-gradient(
      0deg,
      transparent 0 42px,
      var(--stage-grid-blue) 42px 44px
    ),
    repeating-linear-gradient(
      90deg,
      transparent 0 42px,
      var(--stage-grid-green) 42px 44px
    );
  box-shadow: 0 24px 70px rgba(23, 32, 51, 0.28);
  overflow-y: auto;
  overscroll-behavior: auto;
}

.box-card {
  grid-area: card;
  width: min(100%, 420px);
  max-height: calc(100vh - 360px);
  padding: 16px;
  align-self: center;
  justify-self: center;
  touch-action: pan-y;
}

.box-card .sprite-wrap {
  aspect-ratio: 1.25;
}

.box-card img {
  width: min(72%, 220px);
}

.box-card h2 {
  margin-top: 12px;
  font-size: clamp(1.15rem, 2.4vw, 1.65rem);
}

.box-card.is-team-selectable {
  cursor: pointer;
}

.box-card.is-team-selectable:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 36px rgba(32, 42, 68, 0.18);
}

.box-meta {
  position: absolute;
  top: 18px;
  left: 24px;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.team-strip {
  position: absolute;
  top: 46px;
  left: 24px;
  display: grid;
  grid-template-columns: repeat(6, 34px);
  gap: 6px;
}

.team-slot {
  display: grid;
  place-items: center;
  width: 34px;
  aspect-ratio: 1;
  border: 1px dashed #b8c1d1;
  border-radius: 8px;
  background: var(--control-bg);
  overflow: hidden;
}

.team-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.box-full-notice {
  position: absolute;
  top: 54px;
  right: 24px;
  margin: 0;
  border-radius: 8px;
  padding: 8px 12px;
  color: #ffffff;
  background: #c93636;
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(201, 54, 54, 0.2);
}

.carousel-button {
  width: 48px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background: var(--control-bg);
  box-shadow: 0 10px 22px rgba(32, 42, 68, 0.12);
  cursor: pointer;
  font-size: 2rem;
  line-height: 1;
}

.carousel-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

#previousBoxButton {
  grid-area: previous;
}

#nextBoxButton {
  grid-area: next;
}

.box-actions {
  position: absolute;
  right: 24px;
  bottom: 24px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.final-team-panel {
  width: min(1080px, calc(100% - 32px));
  padding: 18px 0 80px;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: auto;
}

.final-team-panel h2 {
  margin: 0 0 18px;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.95;
  text-align: center;
}

.score-breakdown {
  max-width: 960px;
  margin: -8px auto 18px;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1.45;
  font-weight: 800;
  text-align: center;
}

.final-score {
  max-width: 960px;
  margin: 24px auto 0;
  color: var(--ink);
  font-size: clamp(1.35rem, 2.6vw, 2rem);
  line-height: 1.25;
  font-weight: 900;
  text-align: center;
}

.final-team-grid {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.final-team-grid .pokemon-card {
  width: min(160px, calc(50vw - 32px));
  padding: 10px;
}

.final-team-grid .sprite-wrap {
  aspect-ratio: 1.2;
}

.final-team-grid img {
  width: min(72%, 120px);
}

.final-team-grid h2 {
  margin-top: 10px;
  font-size: clamp(0.95rem, 1.8vw, 1.25rem);
  max-width: 100%;
  overflow-wrap: anywhere;
}

.final-team-grid p {
  font-size: 0.85rem;
}

.status-text {
  position: absolute;
  left: 50%;
  bottom: 28px;
  width: min(420px, calc(100% - 220px));
  margin: 0;
  transform: translateX(-50%);
  color: var(--muted);
  text-align: center;
}

.site-footer {
  width: min(1180px, calc(100% - 32px));
  margin: -8px auto 28px;
  color: var(--muted);
}

.site-footer p {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.5;
  text-align: center;
}

.is-loading .pokeball {
  animation: wobble 680ms ease-in-out infinite;
}

@keyframes wobble {
  0%,
  100% {
    transform: rotate(0deg);
  }

  25% {
    transform: rotate(-7deg);
  }

  75% {
    transform: rotate(7deg);
  }
}

@keyframes split-left {
  0% {
    transform: translateX(0) scale(1) rotate(0deg);
    opacity: 1;
  }

  100% {
    transform: translateX(clamp(-250px, -24vw, -150px)) scale(0.82) rotate(-18deg);
    opacity: 0.9;
  }
}

@keyframes split-right {
  0% {
    transform: translateX(0) scale(1) rotate(0deg);
    opacity: 1;
  }

  100% {
    transform: translateX(clamp(150px, 24vw, 250px)) scale(0.82) rotate(18deg);
    opacity: 0.9;
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    min-height: auto;
    padding: 14px 0 18px;
    gap: 12px;
  }

  .topbar {
    align-items: start;
    gap: 10px;
  }

  h1 {
    font-size: clamp(2.1rem, 14vw, 3.6rem);
  }

  .topbar p {
    margin-top: 8px;
    font-size: 0.92rem;
  }

  .theme-toggle-button {
    min-height: 38px;
    padding: 0 10px;
    font-size: 0.82rem;
  }

  .reset-button {
    right: 14px;
    bottom: 14px;
    min-height: 40px;
    padding: 0 14px;
  }

  .tutorial-button {
    left: 14px;
    bottom: 14px;
    min-height: 40px;
    padding: 0 14px;
  }

  .game-stage {
    min-height: clamp(620px, calc(100dvh - 132px), 720px);
    padding: 76px 12px 92px;
  }

  .hud {
    top: 10px;
    right: 10px;
    gap: 6px;
  }

  .round-counter,
  .coin-counter {
    padding: 7px 10px;
    font-size: 0.82rem;
  }

  .pokemon-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .ball-carousel {
    grid-template-columns: 64px minmax(130px, 1fr) 64px;
    gap: 8px;
    width: min(100% - 20px, 520px);
  }

  .spawn-selection {
    gap: 16px;
    width: min(100% - 20px, 520px);
  }

  .charm-carousel {
    grid-template-columns: 66px minmax(112px, 1fr) 66px;
    gap: 8px;
  }

  .charm-token {
    width: clamp(54px, 17vw, 78px);
    font-size: 0.9rem;
  }

  .charm-label {
    max-width: 106px;
    padding: 5px 7px;
    font-size: 0.74rem;
  }

  .charm-cost {
    font-size: 0.72rem;
  }

  .charm-description {
    min-height: 3.4em;
    font-size: 0.86rem;
  }

  .active-charm-badge {
    top: 12px;
    left: 12px;
    max-width: calc(100% - 170px);
    font-size: 0.74rem;
  }

  .pokeball-button {
    width: clamp(108px, 38vw, 170px);
  }

  .split-ball-copy {
    width: clamp(108px, 38vw, 170px);
  }

  .ball-choice[data-slot="side"] {
    transform: scale(0.58);
  }

  .ball-label {
    font-size: 0.78rem;
    padding: 5px 7px;
  }

  .encounter-panel {
    width: calc(100% - 20px);
    max-height: 100%;
    gap: 12px;
    padding: 12px 2px 88px;
  }

  .box-panel {
    inset: 10px;
    padding: 92px 10px 116px;
    grid-template-columns: 36px minmax(0, 1fr) 36px;
    gap: 8px;
  }

  .box-card {
    padding: 10px;
    max-height: none;
  }

  .box-card img {
    width: min(68%, 180px);
  }

  .carousel-button {
    width: 36px;
    font-size: 1.35rem;
  }

  .box-actions {
    right: 10px;
    bottom: 10px;
    left: 10px;
    gap: 8px;
  }

  .box-actions .primary-button,
  .box-actions .danger-button {
    flex: 1 1 132px;
    min-height: 40px;
    padding: 0 10px;
    font-size: 0.86rem;
  }

  .box-meta {
    top: 12px;
    left: 12px;
    right: 12px;
  }

  .team-strip {
    top: 42px;
    left: 12px;
    grid-template-columns: repeat(6, 30px);
  }

  .team-slot {
    width: 30px;
  }

  .box-full-notice {
    top: 78px;
    right: 12px;
  }

  .pokemon-card {
    padding: 12px;
  }

  .pokemon-card img {
    width: min(66%, 176px);
  }

  .pokemon-card h2 {
    margin-top: 10px;
    font-size: clamp(0.92rem, 5vw, 1.32rem);
  }

  .pokemon-card p {
    font-size: 0.82rem;
  }

  .final-team-panel {
    width: calc(100% - 20px);
    padding: 10px 0 80px;
  }

  .final-team-panel h2 {
    margin-bottom: 12px;
    font-size: clamp(1.75rem, 10vw, 2.7rem);
  }

  .score-breakdown {
    margin-bottom: 12px;
    font-size: 0.9rem;
  }

  .final-team-grid {
    justify-content: center;
    gap: 10px;
  }

  .final-team-grid .pokemon-card {
    padding: 10px;
  }

  .final-team-grid h2 {
    font-size: clamp(0.78rem, 4vw, 1rem);
    line-height: 1.05;
  }

  .status-text {
    bottom: 68px;
    width: min(520px, calc(100% - 24px));
    font-size: 0.84rem;
  }

  .tutorial-modal {
    padding: 10px;
  }

  .tutorial-window {
    width: 100%;
    height: 100%;
    padding: 12px;
    gap: 10px;
  }

  .tutorial-window h2 {
    font-size: 1rem;
  }

  .tutorial-viewer {
    grid-template-columns: 34px minmax(0, 1fr) 34px;
    gap: 8px;
  }

  .tutorial-viewer img {
    max-height: calc(100dvh - 260px);
  }

  .tutorial-arrow {
    width: 34px;
    font-size: 1.35rem;
  }

  .close-tutorial-button {
    right: 12px;
    bottom: 12px;
    min-height: 40px;
    padding: 0 14px;
  }

  .site-footer {
    width: min(100% - 24px, 1120px);
  }
}

@media (max-width: 420px) {
  .app-shell {
    width: min(100% - 16px, 1120px);
  }

  .topbar > div {
    min-width: 0;
  }

  .theme-toggle-button {
    padding: 0 8px;
  }

  .game-stage {
    min-height: clamp(610px, calc(100dvh - 118px), 700px);
    padding: 72px 10px 90px;
  }

  .ball-carousel {
    grid-template-columns: 52px minmax(118px, 1fr) 52px;
    width: 100%;
  }

  .charm-carousel {
    grid-template-columns: 52px minmax(104px, 1fr) 52px;
  }

  .charm-arrow {
    width: 38px;
  }

  .box-panel {
    inset: 8px;
    padding: 88px 8px 112px;
    grid-template-columns: 32px minmax(0, 1fr) 32px;
  }

  .carousel-button {
    width: 32px;
  }

  .box-actions .primary-button,
  .box-actions .danger-button {
    flex-basis: 118px;
    font-size: 0.8rem;
  }

  .tutorial-button,
  .reset-button {
    min-height: 38px;
    padding: 0 10px;
    font-size: 0.82rem;
  }

  .tutorial-viewer {
    grid-template-columns: 30px minmax(0, 1fr) 30px;
    gap: 6px;
  }

  .tutorial-arrow {
    width: 30px;
  }
}
