: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;
}

.topbar-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
}

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,
.login-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,
.login-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 {
  color: #ffffff;
  background: var(--blue);
  box-shadow: 0 10px 22px rgba(42, 111, 210, 0.18);
}

.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: #c93636;
  box-shadow: 0 10px 22px rgba(201, 54, 54, 0.2);
}

.stage-utility-actions {
  position: absolute;
  left: 24px;
  bottom: 24px;
  z-index: 2;
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 8px;
}

.settings-icon-button {
  position: absolute;
  top: 18px;
  left: 22px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 44px;
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: var(--control-bg);
  cursor: pointer;
  font-size: 2.00rem;
  line-height: 1;
  box-shadow: 0 10px 22px rgba(32, 42, 68, 0.1);
}

.settings-icon-button:hover {
  filter: brightness(0.96);
}

.box-preview-wrap {
  position: absolute;
  right: 24px;
  bottom: 24px;
  z-index: 2;
  display: grid;
  justify-items: end;
}

.box-preview-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: var(--ink);
  background: var(--control-bg);
  box-shadow: none;
  cursor: pointer;
  font-weight: 900;
}

.box-preview-button:disabled,
.box-preview-button.is-empty {
  color: var(--muted);
  background: #d8dde7;
  cursor: not-allowed;
  opacity: 0.62;
}

body.is-dark .box-preview-button:disabled,
body.is-dark .box-preview-button.is-empty {
  background: #2b3546;
}

.box-preview-grid {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  display: grid;
  grid-template-columns: repeat(3, 34px);
  gap: 6px;
  max-height: 194px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 14px 32px rgba(23, 32, 51, 0.18);
  overflow-y: auto;
}

.box-preview-slot {
  display: grid;
  place-items: center;
  width: 34px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--control-bg);
  cursor: pointer;
  overflow: hidden;
}

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

.daily-challenge-button,
.tutorial-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: var(--ink);
  background: var(--control-bg);
  box-shadow: none;
  cursor: pointer;
  font-weight: 900;
}

.daily-challenge-button {
  grid-column: 1 / -1;
  color: #ffffff;
  background: var(--blue);
  box-shadow: 0 10px 22px rgba(42, 111, 210, 0.18);
}

.leaderboard-icon-button {
  position: relative;
  width: 44px;
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  color: transparent;
  background: var(--control-bg);
  cursor: pointer;
}

.leaderboard-icon-button::before {
  content: "";
  position: absolute;
  inset: 11px 8px 12px;
  background: #d8a21b;
  clip-path: polygon(0 35%, 22% 58%, 36% 20%, 50% 54%, 64% 20%, 78% 58%, 100% 35%, 88% 100%, 12% 100%);
}

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

.auth-window {
  position: relative;
  width: min(430px, 100%);
  max-height: 100%;
  border: 1px solid rgba(217, 223, 235, 0.9);
  border-radius: 8px;
  padding: 24px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  overflow-y: auto;
  touch-action: pan-y;
}

.auth-close-button {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: var(--control-bg);
  cursor: pointer;
  font-size: 1.2rem;
}

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

.auth-panel h2 {
  margin: 0 42px 6px 0;
  font-size: 1.6rem;
  line-height: 1;
}

.auth-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 800;
}

.auth-panel input {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--control-bg);
  font: inherit;
}

.google-login-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: #172033;
  background: #ffffff;
  cursor: pointer;
  font-weight: 900;
}

.google-logo {
  display: grid;
  place-items: center;
  width: 22px;
  aspect-ratio: 1;
  border-radius: 50%;
  color: #ffffff;
  background:
    conic-gradient(
      from -45deg,
      #4285f4 0 25%,
      #34a853 25% 50%,
      #fbbc05 50% 75%,
      #ea4335 75% 100%
    );
  font-size: 0.82rem;
  font-weight: 900;
}

.auth-divider {
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.auth-submit-button {
  width: 100%;
}

.auth-link-button {
  border: 0;
  padding: 4px 0;
  color: var(--blue);
  background: transparent;
  cursor: pointer;
  font-weight: 900;
}

.auth-message {
  min-height: 1.3em;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  text-align: center;
}

.profile-actions {
  display: grid;
  gap: 6px;
}

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

.leaderboard-window {
  position: relative;
  display: grid;
  gap: 12px;
  width: min(860px, 100%);
  max-height: 100%;
  border: 1px solid rgba(217, 223, 235, 0.9);
  border-radius: 8px;
  padding: 22px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.leaderboard-close-button {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: var(--control-bg);
  cursor: pointer;
  font-size: 1.2rem;
}

.leaderboard-window h2 {
  margin: 0 42px 4px;
  font-size: clamp(1.7rem, 4vw, 2.8rem);
  line-height: 1;
  text-align: center;
  overflow-wrap: anywhere;
}

.leaderboard-header-row,
.leaderboard-rows {
  display: grid;
  gap: 8px;
}

.leaderboard-header-row {
  grid-template-columns: 58px minmax(110px, 1.1fr) minmax(88px, auto) minmax(180px, 2fr);
  align-items: center;
  padding: 0 18px 0 24px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.leaderboard-rows {
  max-height: min(420px, 46vh);
  overflow-y: auto;
  padding-right: 4px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 58px minmax(110px, 1.1fr) minmax(88px, auto) minmax(180px, 2fr);
  gap: 10px;
  align-items: center;
  border-radius: 8px;
  padding: 10px 18px 10px 24px;
  background: var(--control-bg);
  font-weight: 800;
  min-width: 0;
}

.leaderboard-row span,
.leaderboard-header-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.leaderboard-row:has(.trash-favorite-button) {
  grid-template-columns: 58px minmax(110px, 1.1fr) minmax(88px, auto) minmax(180px, 2fr) 40px;
}

.leaderboard-row.rank-1 {
  color: #b88700;
}

.leaderboard-row.rank-2 {
  color: #8f96a3;
}

.leaderboard-row.rank-3 {
  color: #a8662b;
}

.leaderboard-row.current-row {
  outline: 2px solid var(--blue);
}

.leaderboard-team {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.leaderboard-team img {
  width: 28px;
  aspect-ratio: 1;
  object-fit: contain;
}

.leaderboard-user-rank {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

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

.leaderboard-actions .primary-button {
  flex: 1 1 180px;
}

.leaderboard-actions .primary-button.is-unavailable {
  background: #8f96a3;
  box-shadow: none;
}

.leaderboard-actions .primary-button.is-validating {
  background: #d6a51d;
  color: #1f1700;
  box-shadow: none;
}

.leaderboard-actions .primary-button:disabled {
  opacity: 1;
}

.trash-favorite-button {
  justify-self: end;
  width: 34px;
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  color: transparent;
  background: #c93636;
  cursor: pointer;
  position: relative;
}

.trash-favorite-button::before {
  content: "";
  position: absolute;
  inset: 9px 10px 8px;
  border: 2px solid #ffffff;
  border-top: 0;
}

.trash-favorite-button::after {
  content: "";
  position: absolute;
  top: 7px;
  left: 9px;
  width: 16px;
  height: 2px;
  background: #ffffff;
  box-shadow: 4px -3px 0 -1px #ffffff;
}

.leaderboard-message {
  min-height: 1.3em;
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.success-toast {
  position: absolute;
  top: 22px;
  left: 50%;
  z-index: 8;
  transform: translateX(-50%);
  border-radius: 8px;
  padding: 10px 14px;
  color: #ffffff;
  background: var(--green);
  font-weight: 900;
  box-shadow: 0 14px 28px rgba(69, 179, 107, 0.28);
  opacity: 0;
  animation: toast-fade 1800ms ease forwards;
}

.primary-button:hover,
.danger-button:hover,
.reset-button:hover,
.box-preview-button:hover,
.tutorial-button:hover,
.leaderboard-icon-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: auto;
  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);
}

.settings-modal,
.daily-challenge-modal,
.daily-stats-modal,
.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);
}

.settings-window {
  display: grid;
  gap: 12px;
  width: min(380px, 100%);
  border: 1px solid rgba(217, 223, 235, 0.9);
  border-radius: 8px;
  padding: 22px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.settings-window h2 {
  margin: 0 0 4px;
  font-size: 1.35rem;
}

.settings-window label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  min-height: 36px;
  color: var(--ink);
  font-weight: 800;
}

.settings-window input {
  width: 20px;
  aspect-ratio: 1;
  accent-color: var(--blue);
}

.settings-window .primary-button {
  width: 100%;
  margin-top: 4px;
}

.daily-challenge-window,
.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: 0px 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;
}

.daily-challenge-window {
  grid-template-rows: auto auto auto auto 1fr auto;
  width: min(760px, 100%);
  height: auto;
  max-height: min(680px, 100%);
}

.daily-challenge-window h2,
.daily-challenge-window h3 {
  margin: 0;
  text-align: center;
}

.daily-challenge-intro {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 400;
  text-align: center;
}

.daily-challenge-requirements,
.daily-stats-list {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.daily-challenge-requirements p,
.daily-stats-list p {
  margin: 0;
  color: var(--ink);
  font-weight: 800;
}

.daily-challenge-met-message {
  margin: 0;
  color: var(--green);
  font-size: 1rem;
  font-weight: 900;
  text-align: center;
}

.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;
}

.daily-challenge-close-button,
.close-tutorial-button {
  position: absolute;
  right: 18px;
  bottom: 18px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: var(--ink);
  background: var(--control-bg);
  box-shadow: none;
  cursor: pointer;
}

.daily-challenge-close-button {
  top: 12px;
  bottom: auto;
  width: 38px;
  min-height: 38px;
  padding: 0;
}

.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 {
  --slider-item-width: clamp(150px, 24vw, 250px);
  --slider-gap: clamp(18px, 5vw, 44px);
  --slider-step: calc(var(--slider-item-width) + var(--slider-gap));
  display: block;
  width: min(720px, 100%);
  overflow: hidden;
  touch-action: auto;
}

.slider-track {
  display: flex;
  align-items: center;
  gap: var(--slider-gap);
  width: max-content;
  transition: transform 320ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

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

.ball-choice.is-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 {
  --slider-item-width: clamp(128px, 22vw, 172px);
  --slider-gap: clamp(16px, 4vw, 34px);
  --slider-step: calc(var(--slider-item-width) + var(--slider-gap));
  display: block;
  width: 100%;
  overflow: hidden;
  touch-action: auto;
}

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

.charm-choice.is-center {
  transform: scale(1);
}

.charm-choice[data-slot="side"] {
  opacity: 0.48;
  transform: translateY(-10px) scale(0.78);
  filter: saturate(0.8);
}

.charm-choice[data-slot="side"]:not(.is-locked):not(.is-disabled):hover {
  opacity: 0.72;
  transform: translateY(-12px) scale(0.82);
}

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

.charm-choice.is-center.is-locked,
.charm-choice.is-center.is-disabled {
  cursor: not-allowed;
}

.charm-choice.is-locked::after,
.charm-choice.is-disabled::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,
.charm-choice.is-disabled::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-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;
}

.charm-token.charm-shiny,
.mini-charm.charm-shiny {
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 30%, #ffffff 0 8%, transparent 9%),
    radial-gradient(circle at 64% 62%, #ffffff 0 7%, transparent 8%),
    linear-gradient(145deg, #ffe156, #70d6ff 52%, #b388eb);
}

.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;
}

#addToBoxButton,
#confirmFinalTeamButton,
#continueButton {
  background: var(--blue);
  box-shadow: 0 10px 22px rgba(47, 128, 237, 0.24);
}

#continueButton.is-unavailable,
#continueButton:disabled {
  background: #8f96a3;
  box-shadow: none;
}

.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 {
  position: relative;
  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);
}

.shiny-symbol {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 42px;
  height: 36px;
  pointer-events: none;
}

.shiny-symbol i {
  position: absolute;
  display: block;
  width: 14px;
  aspect-ratio: 1;
  background: #ffd34f;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  filter: drop-shadow(0 2px 3px rgba(23, 32, 51, 0.18));
}

.shiny-symbol i:nth-child(1) {
  left: 14px;
  top: 0;
}

.shiny-symbol i:nth-child(2) {
  left: 0;
  bottom: 0;
}

.shiny-symbol i:nth-child(3) {
  right: 0;
  bottom: 0;
}

.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: auto;
}

.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;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.box-coin-warning {
  flex: 1 0 100%;
  margin: 0;
  color: #c93636;
  font-size: 0.88rem;
  font-weight: 900;
  text-align: right;
}

.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-leaderboard-link {
  display: block;
  width: fit-content;
  margin-top: 4px;
  margin-inline: auto;
  color: #d8a21b;
  font-size: clamp(1.2rem, 2.5vw, 1.75rem);
  text-align: center;
  overflow-wrap: anywhere;
}

.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;
  }
}

@keyframes toast-fade {
  0% {
    opacity: 0;
    transform: translate(-50%, -6px);
  }

  14%,
  72% {
    opacity: 1;
    transform: translate(-50%, 0);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -6px);
  }
}

@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;
  }

  .topbar-actions {
    flex-direction: column;
    gap: 6px;
  }

  h1 {
    font-size: clamp(2rem, 13vw, 3.4rem);
  }

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

  .theme-toggle-button,
  .login-button {
    min-height: 32px;
    padding: 0 8px;
    font-size: 0.72rem;
    border-radius: 7px;
  }

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

  .stage-utility-actions {
    left: 14px;
    bottom: 14px;
    grid-template-columns: auto auto;
  }

  .settings-icon-button {
    top: 10px;
    left: 10px;
    width: 40px;
    font-size: 1.2rem;
  }

  .box-preview-wrap {
    right: 14px;
    bottom: 14px;
  }

  .box-preview-button {
    min-height: 40px;
    padding: 0 14px;
  }

  .box-preview-grid {
    grid-template-columns: repeat(3, 30px);
    gap: 5px;
    max-height: 174px;
    padding: 7px;
  }

  .box-preview-slot {
    width: 30px;
  }

  .daily-challenge-button,
  .tutorial-button {
    min-height: 40px;
    padding: 0 14px;
  }

  .leaderboard-icon-button {
    width: 40px;
  }

  .game-stage {
    min-height: clamp(660px, calc(100dvh - 132px), 760px);
    padding: 76px 12px 136px;
  }

  .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 {
    --slider-item-width: clamp(108px, 38vw, 170px);
    --slider-gap: 18px;
    width: min(100% - 20px, 520px);
  }

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

  .charm-carousel {
    --slider-item-width: clamp(112px, 34vw, 142px);
    --slider-gap: 14px;
  }

  .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 124px;
  }

  .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 124px;
  }

  .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: 112px;
    width: min(520px, calc(100% - 24px));
    font-size: 0.84rem;
  }

  .tutorial-modal {
    padding: 10px;
  }

  .auth-modal {
    padding: 10px;
  }

  .settings-modal {
    padding: 10px;
  }

  .settings-window {
    width: min(100%, 360px);
    padding: 18px 14px;
  }

  .auth-window {
    width: 100%;
    padding: 18px 14px;
  }

  .leaderboard-modal {
    padding: 10px;
  }

  .leaderboard-window {
    width: 100%;
    padding: 48px 12px 18px;
  }

  .leaderboard-window h2 {
    margin: 0 34px 4px;
    font-size: clamp(1.35rem, 8vw, 2rem);
  }

  .leaderboard-header-row {
    grid-template-columns: 34px minmax(58px, 1fr) minmax(48px, 0.72fr) minmax(92px, 1.3fr);
    gap: 6px;
    padding: 0 8px;
    font-size: 0.68rem;
  }

  .leaderboard-row {
    grid-template-columns: 34px minmax(58px, 1fr) minmax(48px, 0.72fr) minmax(92px, 1.3fr);
    gap: 6px;
    padding: 8px;
    font-size: 0.72rem;
  }

  .leaderboard-row:has(.trash-favorite-button) {
    grid-template-columns: 34px minmax(54px, 1fr) minmax(48px, 0.72fr) minmax(72px, 1.15fr) 32px;
  }

  .leaderboard-team img {
    width: 22px;
  }

  .leaderboard-actions .primary-button {
    flex-basis: 100%;
    min-height: 40px;
    font-size: 0.82rem;
  }

  .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;
  }

  .ball-choice.is-locked::before {
    height: clamp(18px, 4vw, 28px);
    top: calc(34.5% - clamp(28px, 5vw, 45px));
  }

  .charm-choice.is-locked::before {
    height: clamp(16px, 3.5vw, 12px);
    top: calc(27.5% - clamp(20px, 3.8vw, 30px));
  }

  .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,
  .login-button {
    min-height: 30px;
    padding: 0 7px;
    font-size: 0.68rem;
  }

  .game-stage {
    min-height: clamp(650px, calc(100dvh - 118px), 750px);
    padding: 72px 10px 134px;
  }

  .ball-carousel {
    --slider-item-width: clamp(104px, 42vw, 150px);
    --slider-gap: 12px;
    width: 100%;
  }

  .charm-carousel {
    --slider-item-width: clamp(104px, 38vw, 132px);
    --slider-gap: 10px;
  }

  .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;
  }

  .final-leaderboard-link {
    display: block;
    justify-self: center;
    width: fit-content;
    margin-inline: auto;
    text-align: center;
  }

  .leaderboard-window {
    padding-inline: 10px;
  }

  .leaderboard-window h2 {
    margin-inline: 28px;
    font-size: clamp(1.2rem, 7vw, 1.65rem);
  }

  .leaderboard-header-row {
    grid-template-columns: 30px minmax(48px, 1fr) minmax(44px, 0.72fr) minmax(76px, 1.25fr);
    gap: 5px;
    font-size: 0.62rem;
  }

  .leaderboard-row {
    grid-template-columns: 30px minmax(48px, 1fr) minmax(44px, 0.72fr) minmax(76px, 1.25fr);
    gap: 5px;
    font-size: 0.66rem;
  }

  .leaderboard-row:has(.trash-favorite-button) {
    grid-template-columns: 28px minmax(44px, 1fr) minmax(40px, 0.7fr) minmax(60px, 1fr) 30px;
  }

  .leaderboard-team img {
    width: 19px;
  }

  .leaderboard-icon-button {
    width: 38px;
  }

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

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