/* style.css - Pokemon Roguelike Retro Theme */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }

html, body {
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  font-family: var(--font-ui);
}

button,
select,
textarea {
  font: inherit;
}

input[type="text"],
input[type="search"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="tel"],
input[type="number"],
input:not([type]) {
  font: inherit;
  box-sizing: border-box;
  height: var(--control-md-height);
  padding: 0 var(--input-px);
  font-size: var(--input-font);
  line-height: calc(var(--control-md-height) - 4px);
  background: var(--input-bg);
  border: 2px solid var(--outline);
  box-shadow: var(--input-edge) var(--input-edge) 0 0 var(--outline);
  color: var(--text-main);
  user-select: text;
  -webkit-user-select: text;
  appearance: none;
  -webkit-appearance: none;
  text-transform: none;
}
input[type="text"]::placeholder,
input[type="search"]::placeholder,
input[type="password"]::placeholder,
input[type="email"]::placeholder,
input[type="url"]::placeholder,
input[type="tel"]::placeholder,
input[type="number"]::placeholder,
input:not([type])::placeholder {
  color: var(--input-placeholder);
}
input[type="text"]:focus,
input[type="search"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="url"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
input:not([type]):focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: var(--input-edge) var(--input-edge) 0 0 var(--input-focus);
}

img,
.pixel-art,
#map-container foreignObject img,
#map-container svg image {
  /* crisp-edges first as the fallback; pixelated (strict nearest-neighbor)
     wins where supported — the reverse order let Safari pick crisp-edges,
     which it renders smoothed. */
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

.map-node-sprite {
  object-fit: contain;
}

:root {
  --ink: #181410;
  --black: #2a2a2a;
  --black-edge: #454545;
  /* Retro pixel border + shadow: light uses --black, dark uses --black-edge */
  --outline: var(--black);
  --bg: #0e0e0e;
  --bg2: var(--black);
  --bg3: #242424;
  --border: var(--outline);
  --accent: #d49a10;
  --accent2: #e83418;
  --text: #f0ece0;
  --text-dim: #909080;
  --green: #3cc24a;
  --orange: #f08c10;
  --red: #e22a18;
  --gold: #ffd700;
  --modal-backdrop: rgba(0, 0, 0, 0.5);
  --scrollbar-track: rgba(0, 0, 0, 0.1);
  --scrollbar-thumb: rgba(0, 0, 0, 0.28);
  --scrollbar-thumb-hover: rgba(0, 0, 0, 0.42);
  /* Panel variables (used by patch notes / hall of fame modals) */
  --bg-main: #e8e4d8;
  --bg-card: #e0dcd0;
  --text-main: var(--ink);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --run-menu-height: 60px;
  --run-menu-width: 172px;
  --run-menu-pad: 13px;
  --run-menu-gap: 10px;
  --pick-cards-gap: 12px;
  --run-menu-offset: 0px;
  --run-menu-sidebar-bg: var(--black);
  --run-menu-toggle-inset: 14px;
  --title-legal-height: 48px;
  --btn-transition-duration: 0.15s;
  --btn-transition-ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --btn-transition: transform var(--btn-transition-duration) var(--btn-transition-ease);
  --btn-lift: -1px;
  --btn-push: 2px;
  /* Button sizes: sm = pokedex gen filters, md = sidebar, lg = title resume */
  --btn-font-sm: var(--text-xs);
  --btn-py-sm: 5px;
  --btn-px-sm: 8px;
  --btn-edge-sm: 2px;
  --btn-font-md: var(--text-sm);
  --btn-py-md: 10px;
  --btn-px-md: 14px;
  --btn-edge-md: 3px;
  --control-md-height: 30px;
  --btn-font-lg: var(--text-base);
  --btn-px-lg: 22px;
  --btn-edge-lg: 4px;
  --control-lg-height: 42px;
  --input-font: var(--btn-font-md);
  --input-px: var(--btn-px-md);
  --input-edge: var(--btn-edge-md);
  --input-bg: #e8e4d8;
  --input-placeholder: #908c7c;
  --input-focus: #cc2222;
  --checkbox-accent: #2e6eb5;
  --font-ui: 'Press Start 2P', monospace;

  /* Type scale (Tailwind ratios, base = 0.5rem) — https://tailwindcss.com/docs/font-size */
  --text-base: 0.5rem;
  --text-xs: calc(var(--text-base) * 0.75);
  --text-sm: calc(var(--text-base) * 0.875);
  --text-lg: calc(var(--text-base) * 1.125);
  --text-xl: calc(var(--text-base) * 1.25);
  --text-2xl: calc(var(--text-base) * 1.5);
  --text-3xl: calc(var(--text-base) * 1.875);
  --text-4xl: calc(var(--text-base) * 2.25);
  --text-5xl: calc(var(--text-base) * 3);
  --text-6xl: calc(var(--text-base) * 3.75);
  --text-7xl: calc(var(--text-base) * 4.5);
  --text-8xl: calc(var(--text-base) * 6);

  /* Text colors (semantic aliases) */
  --text-panel-muted: #504c3c;
  --text-on-gold: #6a4f10;
  --text-inverse: #fff;
}

body.dark-mode {
  --bg-main: #252118;
  --bg-card: #1e1c14;
  --text-main: #e0dcd0;
  --text-panel-muted: #908878;
  --input-bg: #252118;
  --input-placeholder: #706858;
  --outline: var(--black-edge);
  --border: #4a4438;
  --checkbox-accent: #5090d5;
  /* Light thumbs so the scrollbar is visible against dark surfaces (the
     Pokédex and other dark-mode panels) — black-on-dark was invisible. */
  --scrollbar-track: rgba(255, 255, 255, 0.08);
  --scrollbar-thumb: rgba(255, 255, 255, 0.32);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.5);
}

html {
  background: var(--bg) url('../img/background.png') center / cover no-repeat;
  background-color: var(--bg);
  image-rendering: pixelated;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  min-height: 100dvh;
  min-height: 100lvh;
}

html:has(body.dark-mode) {
  background-image: url('../img/backgroundDarkMode.png');
}

body::before {
  content: '';
  position: fixed;
  top: calc(-1 * var(--safe-top));
  right: calc(-1 * var(--safe-right));
  bottom: calc(-1 * var(--safe-bottom));
  left: calc(-1 * var(--safe-left));
  z-index: -1;
  background: var(--bg) url('../img/background.png') center / cover no-repeat;
  image-rendering: pixelated;
}

body {
  background: transparent;
  color: var(--text);
  font-size: var(--text-base);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  min-height: 100dvh;
  min-height: 100lvh;
  overflow-x: hidden;
}

/* ---- Typography (design system) ---- */
h1, h2, h3, h4, h5, h6, p {
  margin: 0;
}

h1, h2, h3, h4, h5, h6, .pixel-font {
  line-height: 1.6;
}

h1, .text-display {
  font-size: var(--text-5xl);
  color: var(--gold);
  line-height: 1.35;
}

h2, .text-screen-title {
  font-size: var(--text-2xl);
  line-height: 1.55;
}

h3, .game-modal-title {
  font-size: var(--text-xl);
  line-height: 1.5;
}

h4,
.settings-section-title,
.dex-detail-section-title,
.patch-note-section-heading {
  font-size: var(--text-lg);
  line-height: 1.5;
}

h1.history-header-title {
  font-size: var(--text-2xl);
  color: #1a66e0;
  line-height: 1.5;
  text-shadow: none;
}

h5 {
  font-size: var(--text-base);
  line-height: 1.5;
}

h6 {
  font-size: var(--text-sm);
  line-height: 1.5;
}

p, .text-body {
  line-height: 1.7;
  color: var(--text);
}

.text-muted { color: var(--text-dim); }
.text-panel { color: var(--text-panel-muted); }
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }
.text-4xl { font-size: var(--text-4xl); }
.text-5xl { font-size: var(--text-5xl); }
.text-6xl { font-size: var(--text-6xl); }
.text-7xl { font-size: var(--text-7xl); }
.text-8xl { font-size: var(--text-8xl); }

/* ---- Screens ---- */
.screen {
  display: none;
  flex-direction: column;
  /* --ad-reserve (default 0) is the height of the in-game sticky-header ad strip;
     subtracting it here keeps every screen within the viewport when ads push the
     page down, so nothing scrolls. It's 0 unless body.show-ads sets it. */
  min-height: calc(100vh - var(--ad-reserve, 0px));
  min-height: -webkit-fill-available;
  min-height: calc(100dvh - var(--ad-reserve, 0px));
  min-height: calc(100lvh - var(--ad-reserve, 0px));
  padding:
    calc(16px + var(--safe-top))
    calc(16px + var(--safe-right))
    calc(16px + var(--safe-bottom))
    calc(16px + var(--safe-left));
  max-width: 900px;
  margin: 0 auto;
}
.screen.active { display: flex; }

/* ---- Screen intro (h2 + desc) ---- */
.screen-intro {
  width: 100%;
  max-width: 520px;
  margin: 0 auto 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
/* Pre-merge style: simple centered colored title + dim caption, no boxed chrome. */
.screen-intro h2 {
  --screen-title-color: var(--gold);
  margin: 0;
  max-width: 100%;
  line-height: 1.6;
  font-size: clamp(10px, 2.5vw, 16px);
  text-align: center;
  text-transform: none;
  color: var(--screen-title-color);
  text-shadow: none;
}
.screen-desc {
  margin: 0;
  max-width: 100%;
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
  color: var(--text-dim);
  text-shadow: none;
}
.screen-desc:empty {
  display: none;
}
/* Event-announcement titles are always the same color across every screen. */

/* ---- Title Screen ---- */
#title-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 20px;
}
#title-screen .title-mode-cards {
  margin-top: 16px;
  margin-bottom: 16px;
}
#title-screen h1,
#title-screen .game-logo {
  font-size: var(--text-8xl);
  letter-spacing: 0.12em;
}
.run-menu-logo {
  font-size: var(--text-lg);
}
.run-menu-brand > .run-menu-logo {
  font-size: var(--text-2xl);
}
.title-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 560px;
}
.game-logo {
  text-shadow:
    2px 2px 0 #6a5010,
    3px 3px 0 var(--outline),
    0 0 18px rgba(255, 215, 0, 0.45);
}
.game-subtitle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  margin: 0;
  padding: 0 8px;
  font-size: var(--text-xl);
  line-height: 1.6;
  text-transform: uppercase;
  color: var(--text-on-gold);
}
.game-subtitle-inner {
  display: flex;
  align-items: baseline;
  flex-shrink: 0;
  gap: 10px;
}
.game-subtitle-sep {
  opacity: 0.55;
}
.game-subtitle-text {
  flex-shrink: 0;
}
.title-version {
  flex-shrink: 0;
  font-size: inherit;
  line-height: inherit;
  text-transform: none;
  color: var(--text-on-gold);
  cursor: pointer;
}
.title-version:hover {
  color: var(--gold);
}
.lang-select {
  font-family: inherit;
  font-size: 11px;
  color: var(--text-on-gold, #eee);
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid var(--gold, #c9a85a);
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.lang-select:hover { color: var(--gold, #c9a85a); }
.lang-select:focus { outline: none; border-color: var(--gold, #c9a85a); }
.settings-lang-select { background: rgba(0, 0, 0, 0.25); }
.game-subtitle::before,
.game-subtitle::after {
  content: '';
  flex: 1;
  max-width: 72px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--text-on-gold));
  opacity: 0.65;
}
.game-subtitle::after {
  background: linear-gradient(90deg, var(--text-on-gold), transparent);
}
@media (max-width: 600px) {
  .title-hero { gap: 10px; }
  #title-screen h1,
  #title-screen .game-logo {
    font-size: var(--text-7xl);
    letter-spacing: 0.08em;
  }
  .game-subtitle::before,
  .game-subtitle::after { max-width: 40px; }
}
body.dark-mode .game-subtitle {
  color: rgba(224, 220, 208, 0.92);
}
body.dark-mode .title-version {
  color: rgba(224, 220, 208, 0.92);
}
body.dark-mode .title-version:hover {
  color: #fff;
}
body.dark-mode .game-subtitle::before {
  background: linear-gradient(90deg, transparent, rgba(224, 220, 208, 0.45));
}
body.dark-mode .game-subtitle::after {
  background: linear-gradient(90deg, rgba(224, 220, 208, 0.45), transparent);
}

/* ---- Buttons: sizes + retro visuals in block near file end ---- */

/* Generation toggle (title screen) — color-themed Roman numerals */
.gen-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.gen-toggle-label {
  font-size: var(--text-sm);
  color: #aaa;
}
.gen-toggle {
  display: flex;
  gap: 12px;
}
.gen-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--black);
  color: #555;
  border: 2px solid var(--black-edge);
  cursor: pointer;
  padding: 0;
}
.gen-btn:hover { color: #bbb; border-color: #666; }
.gen-btn[data-gen="1"].gen-btn--active { color: #c46a6a; border-color: #c46a6a; }
.gen-btn[data-gen="2"].gen-btn--active { color: #c9a85a; border-color: #c9a85a; }



/* ---- Starter Screen ---- */
#starter-screen {
  justify-content: center;
  align-items: center;
  gap: 16px;
}
#starter-layout {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
}
#starter-choices {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  width: 100%;
  gap: var(--pick-cards-gap);
}
#starter-choices:not(:has(.pc-box)) {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 180px));
  justify-content: center;
  gap: var(--pick-cards-gap);
}
#starter-choices:not(:has(.pc-box)) .poke-card,
.starter-card-row .poke-card {
  width: 100%;
  max-width: 180px;
}
@media (max-width: 768px) {
  #starter-choices:not(:has(.pc-box)) {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
    justify-content: center;
    gap: var(--pick-cards-gap);
    width: 100%;
    max-width: 580px;
  }
}

/* PC Box */
.pc-box {
  background: #111e3a;
  border: 2px solid #7090d0;
  border-radius: 10px;
  box-shadow: 3px 3px 0 #000;
  overflow: hidden;
  width: min(580px, 92vw);
  display: flex;
  flex-direction: column;
  height: 540px;
  max-height: min(540px, calc(100dvh - 140px));
}
/* On the HoF-PC starter screen, hide the title and let the PC fill the height.
   (The plain 3-starter pick keeps its 'Choose Your Starter!' header.) */
#starter-screen:has(.pc-box) .screen-intro { display: none; }
#starter-screen:has(.pc-box) { justify-content: flex-start; }
#starter-screen:has(.pc-box) #starter-layout {
  flex: 1;
  min-height: 0;
  width: 100%;
  align-items: stretch;
}
#starter-layout:has(.pc-box) > #starter-region-panel { align-self: flex-start; }
#starter-choices:has(.pc-box) {
  flex: 1;
  min-height: 0;
}
#starter-choices:has(.pc-box) .pc-box {
  flex: 1;
  min-height: 0;
  height: auto;
  max-height: none;
}
.pc-box > .game-modal-header {
  border-bottom: 1px solid #5577dd;
}
.pc-box .game-modal-title {
  color: #fff;
}
.pc-box .game-modal-desc {
  color: #aaccff;
}
.hof-sort-btns {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.hof-sort-btn {
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(180,210,255,0.55);
  box-shadow: var(--btn-edge-sm) var(--btn-edge-sm) 0 0 #5577dd;
  color: #aaccff;
  cursor: pointer;
  flex-shrink: 0;
}
@media (hover: hover) {
  .hof-sort-btn:hover:not(:disabled):not(:active) {
    background: rgba(255,255,255,0.18);
    border-color: rgba(180,210,255,0.85);
    transform: translate(var(--btn-lift), var(--btn-lift));
  }
}
.hof-sort-btn:active:not(:disabled) {
  box-shadow: 1px 1px 0 0 #5577dd;
  transform: translate(1px, 1px);
}
.hof-sort-btn.active {
  background: rgba(100,150,255,0.3);
  border-color: #7090d0;
  box-shadow: 2px 2px 0 0 #7090d0;
  color: #fff;
}
@media (hover: hover) {
  .hof-sort-btn.active:hover:not(:disabled):not(:active) {
    box-shadow: 3px 3px 0 0 #7090d0;
  }
}
.hof-sort-btn.hof-filter-shiny.active {
  background: rgba(0,170,255,0.2);
  border-color: #4af;
  box-shadow: 2px 2px 0 0 #4af;
  color: #4af;
}
@media (hover: hover) {
  .hof-sort-btn.hof-filter-shiny.active:hover:not(:disabled):not(:active) {
    box-shadow: 3px 3px 0 0 #4af;
  }
}
.hof-sort-sep {
  width: 2px;
  background: rgba(180,210,255,0.25);
  margin: 0 2px;
  align-self: stretch;
  flex-shrink: 0;
}
.pc-box-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.pc-box .dex-grid {
  background: #0a1428;
  flex: 1;
  min-height: 0;
  /* Fixed column count that fills the width (no sideways scroll). */
  grid-template-columns: repeat(6, 1fr);
  overflow-x: hidden;
}
@media (max-width: 768px) {
  .pc-box .dex-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
.pc-box .dex-card {
  background: #1B2B52;
  border-color: #31487F;
  position: relative;
  cursor: pointer;
  outline: none;
}
.pc-box .dex-card:hover,
.pc-box .dex-card:focus {
  background: #334875;
  border-color: #94B0DD;
  box-shadow: 2px 2px 0 0 #94B0DD;
}
.pc-box .dex-name { color: #ccdeff; }
/* Missing-starter silhouette (not selectable) — a Pokédex-style "you don't have
   this yet" marker, shown for the active gen filter. */
/* "Missing" filter cards: the starter shown completely grayed out, with its
   name, and not selectable. */
.pc-missing-card { cursor: default; }
.pc-box .pc-missing-card:hover,
.pc-box .pc-missing-card:focus {
  background: #1B2B52;
  border-color: #31487F;
  box-shadow: none;
}
.pc-missing-sprite { filter: grayscale(1) brightness(0.7); }
.pc-box .pc-missing-card .pc-missing-name { color: #6c7689; }
.pc-shiny-star {
  position: absolute;
  top: 0;
  left: 4px;
  font-size: var(--text-lg);
  color: #4af;
  line-height: 1;
}
.pc-buff-stars {
  position: absolute;
  top: 0;
  right: 4px;
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 112px;
}
.pc-buff-stars span {
  font-size: var(--text-lg);
  color: gold;
  line-height: 1;
}
.pc-buff-star-half {
  display: inline-block;
  width: 0.5em;
  overflow: hidden;
}
.pc-box .dex-empty {
  color: rgba(170, 204, 255, 0.55);
}
.pc-box-toolbar {
  background: #0a1428;
  border-bottom: 1px solid #5577dd;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.pc-toolbar-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.pc-toolbar-sep {
  border-top: 2px solid #5577dd;
  margin: 2px 0;
  flex-shrink: 0;
}
.pc-toolbar-top input[type="search"] {
  flex: 1;
  min-width: min(148px, 42vw);
  height: var(--control-md-height);
  min-height: var(--control-md-height);
  font-size: var(--input-font);
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(180, 210, 255, 0.55);
  box-shadow: var(--btn-edge-sm) var(--btn-edge-sm) 0 0 #5577dd;
  color: #e8f0ff;
}
.pc-toolbar-top input[type="search"]::placeholder {
  color: rgba(170, 204, 255, 0.45);
}
.pc-toolbar-top input[type="search"]:focus {
  border-color: rgba(180, 210, 255, 0.85);
  box-shadow: var(--btn-edge-sm) var(--btn-edge-sm) 0 0 #7090d0;
}
.pc-gen-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}
.starter-card-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 180px));
  justify-content: center;
  gap: var(--pick-cards-gap);
  margin-bottom: 0;
  width: 100%;
}
@media (max-width: 768px) {
  /* Pokemon choices sit side-by-side as vertical compact cards. */
  #catch-choices,
  .starter-card-row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
    justify-content: center;
    gap: var(--pick-cards-gap);
    width: 100%;
    max-width: 580px;
  }
  .poke-choice-wrap {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex: 1 1 0;
    min-width: 0;
    max-width: 220px;
  }
  .starter-card-row .poke-card,
  #starter-choices:not(:has(.pc-box)) .poke-card {
    flex: 1 1 0;
    min-width: 0;
    max-width: 180px;
  }
  #catch-choices .poke-card { width: 100%; }
  #starter-choices:not(:has(.pc-box)) .poke-card,
  .starter-card-row .poke-card,
  #catch-choices .poke-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 0;
    padding: 7px 3px;
    text-align: center;
    box-sizing: border-box;
    position: relative;
  }
  #starter-choices:not(:has(.pc-box)) .poke-card[role="button"]:hover,
  #starter-choices:not(:has(.pc-box)) .poke-card[tabindex]:hover,
  .starter-card-row .poke-card[role="button"]:hover,
  .starter-card-row .poke-card[tabindex]:hover,
  #catch-choices .poke-card[role="button"]:hover,
  #catch-choices .poke-card[tabindex]:hover {
    transform: none;
    box-shadow: 0 4px 16px rgba(200, 152, 32, 0.35);
  }
  #starter-choices:not(:has(.pc-box)) .poke-sprite-wrap,
  .starter-card-row .poke-sprite-wrap,
  #catch-choices .poke-sprite-wrap {
    grid-column: 1;
    grid-row: 2;
    width: 68px;
    height: 68px;
    justify-self: center;
    align-self: center;
    position: static;
  }
  #starter-choices:not(:has(.pc-box)) .dex-caught-badge,
  .starter-card-row .dex-caught-badge,
  #catch-choices .dex-caught-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 18px;
    height: 18px;
    z-index: 2;
  }
  #starter-choices:not(:has(.pc-box)) .poke-sprite,
  .starter-card-row .poke-sprite,
  #catch-choices .poke-sprite {
    width: 68px;
    height: 68px;
  }
  #starter-choices:not(:has(.pc-box)) .poke-name,
  .starter-card-row .poke-name,
  #catch-choices .poke-name {
    grid-column: 1;
    grid-row: 3;
    justify-self: center;
    align-self: center;
    text-align: center;
    font-size: var(--text-sm);
    line-height: 1.4;
    width: 100%;
  }
  #starter-choices:not(:has(.pc-box)) .poke-level,
  .starter-card-row .poke-level,
  #catch-choices .poke-level {
    grid-column: 1;
    grid-row: 4;
    justify-self: center;
    align-self: center;
    text-align: center;
    font-size: var(--text-sm);
    width: 100%;
  }
  #starter-choices:not(:has(.pc-box)) .poke-types,
  .starter-card-row .poke-types,
  #catch-choices .poke-types {
    display: none;
  }
  #starter-choices:not(:has(.pc-box)) .poke-card-col-stats,
  .starter-card-row .poke-card-col-stats,
  #catch-choices .poke-card-col-stats {
    grid-column: 2;
    grid-row: 1 / -1;
    display: flex;
    flex-direction: column-reverse;
    align-items: stretch;
    justify-content: center;
    gap: 4px;
    width: 100%;
    min-width: 0;
    padding: 0 2px;
    box-sizing: border-box;
    align-self: stretch;
    justify-self: stretch;
  }
  #starter-choices:not(:has(.pc-box)) .poke-card-col-stats .poke-hp,
  .starter-card-row .poke-card-col-stats .poke-hp,
  #catch-choices .poke-card-col-stats .poke-hp {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 0;
  }
  #starter-choices:not(:has(.pc-box)) .poke-card-col-stats .poke-hp .hp-bar-bg,
  .starter-card-row .poke-card-col-stats .poke-hp .hp-bar-bg,
  #catch-choices .poke-card-col-stats .poke-hp .hp-bar-bg {
    width: 100%;
    max-width: 100%;
  }
  #starter-choices:not(:has(.pc-box)) .poke-card-col-stats .poke-stats-bars,
  .starter-card-row .poke-card-col-stats .poke-stats-bars,
  #catch-choices .poke-card-col-stats .poke-stats-bars {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: 100%;
    padding: 0;
  }
  #starter-choices:not(:has(.pc-box)) .stat-row,
  .starter-card-row .stat-row,
  #catch-choices .stat-row {
    justify-content: flex-start;
    width: 100%;
    min-width: 0;
  }
  #starter-choices:not(:has(.pc-box)) .stat-row .stat-bar-bg,
  .starter-card-row .stat-row .stat-bar-bg,
  #catch-choices .stat-row .stat-bar-bg {
    flex: 1;
    min-width: 36px;
  }
  #starter-choices:not(:has(.pc-box)) .poke-move,
  .starter-card-row .poke-move,
  #catch-choices .poke-move {
    grid-column: 3;
    grid-row: 2 / 5;
    margin-top: 0;
    justify-self: stretch;
    align-self: center;
    width: auto;
    max-width: 100%;
    min-width: 0;
    padding: 6px 4px;
  }
  #starter-choices:not(:has(.pc-box)) .stat-lbl,
  .starter-card-row .stat-lbl,
  #catch-choices .stat-lbl {
    width: 20px;
    font-size: var(--text-xs);
    text-align: center;
  }
  #starter-choices:not(:has(.pc-box)) .stat-val,
  .starter-card-row .stat-val,
  #catch-choices .stat-val {
    width: 18px;
    font-size: var(--text-xs);
    text-align: center;
  }
}

#starter-region-panel {
  width: 100%;
  max-width: 580px;
  background: #111e3a;
  border: 2px solid #7090d0;
  border-radius: 6px;
  padding: 10px 12px;
  box-shadow: 2px 2px 0 0 #000;
  color: #ccdeff;
}
.starter-region-label {
  font-size: var(--text-xs);
  line-height: 1.6;
  color: rgba(204, 222, 255, 0.55);
  text-transform: uppercase;
  text-align: center;
  width: 100%;
  margin-bottom: 6px;
}
.starter-region-name {
  font-size: var(--text-sm);
  line-height: 1.5;
  color: #fff;
  text-align: center;
  width: 100%;
}
.starter-region-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  align-items: stretch;
}
@media (max-width: 400px) {
  /* Four columns drop below ~75px each on very narrow phones — go 2×2 so the
     trainer names and type badges stay legible. */
  .starter-region-grid { grid-template-columns: repeat(2, 1fr); }
}
.starter-region-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  min-width: 0;
  text-align: center;
}
.starter-region-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 4px;
  text-align: center;
  min-width: 0;
}
.starter-region-col .type-badge {
  font-size: var(--text-sm);
  padding: 2px 5px;
}
.starter-region-col .region-stage-name {
  flex: none;
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  word-break: break-word;
  width: 100%;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: #fff;
}
.starter-region-col .region-stage-level {
  font-size: var(--text-sm);
  line-height: 1.5;
  color: rgba(204, 222, 255, 0.85);
}

/* ---- Pokemon Cards ---- */
.poke-card {
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  width: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  position: relative;
}
.poke-card[role="button"], .poke-card[tabindex] {
  cursor: pointer;
}
.poke-card[role="button"]:hover, .poke-card[tabindex]:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(200,152,32,0.35);
}
.poke-card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 16px rgba(255,215,0,0.4);
}

.poke-sprite-wrap { position: relative; width: 96px; height: 96px; }
.poke-sprite {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  filter: drop-shadow(0 2px 8px rgba(200,152,32,0.3));
}
.poke-sprite.shiny { filter: drop-shadow(0 0 12px gold); }
.shiny-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--gold);
  color: #000;
  font-size: var(--text-sm);
  padding: 2px 4px;
  border-radius: 3px;
  font-weight: bold;
}
.dex-caught-badge {
  position: absolute;
  top: -4px;
  left: -4px;
  width: 20px;
  height: 20px;
  filter: drop-shadow(0 0 2px rgba(0,0,0,0.8));
}

.poke-name {
  font-size: var(--text-sm);
  color: var(--text);
  text-align: center;
}
.poke-level { color: var(--text-dim); }
.poke-types { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.poke-card-col-stats { display: contents; }
.poke-stats-bars { display: flex; flex-direction: column; gap: 3px; width: 100%; }
.stat-row { display: flex; align-items: center; gap: 5px; position: relative; cursor: default; }
.stat-row[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  transform: translateX(-50%);
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--text-xs);
  padding: 3px 6px;
  white-space: nowrap;
  box-shadow: 2px 2px 0 0 #000;
  pointer-events: none;
  z-index: 10;
}
.stat-lbl {font-size: var(--text-xs); color: var(--text-dim); width: 22px; text-align: left; flex-shrink: 0; }
.stat-val {font-size: var(--text-xs); color: var(--text-dim); width: 20px; flex-shrink: 0; }
.stat-bar-bg { flex: 1; height: 5px; background: var(--bg3); position: relative; }
.stat-bar-fill { height: 100%; }
.stat-hp, .stat-atk, .stat-def, .stat-spe, .stat-spa, .stat-spd { background: #888; }
.stat-buff-overlay { position: absolute; top: 0; left: 0; height: 100%; background: #4488ff; pointer-events: none; }

/* ---- Stat Buff Screen ---- */
#stat-buff-screen { align-items: center; justify-content: center; gap: 0; }
#stat-buff-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; margin-top: 8px; }
.stat-buff-poke-wrap .poke-card:hover { border-color: var(--accent); transform: translateY(-4px); }
.stat-buff-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 5px;
  padding: 8px 12px; cursor: pointer; width: 280px;
  box-shadow: 2px 2px 0 0 #000;
}
.stat-buff-row:hover:not(.maxed) { border-color: #4488ff; }
.stat-buff-row.maxed { opacity: 0.4; cursor: default; }
.stat-buff-lbl {font-size: var(--text-xs); color: var(--text-dim); width: 26px; text-align: left; flex-shrink: 0; }
.stat-buff-bar-wrap { flex: 1; }
.stat-buff-bar-wrap .stat-bar-bg { height: 7px; }
.stat-buff-count {font-size: var(--text-xs); color: var(--text-dim); white-space: nowrap; }
/* Move / ability window — fixed height and a steady 3-slot meta row so the card
   keeps the same footprint no matter the move's name length, type, or power. */
.poke-move {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 6px;
  width: 100%;
  max-width: 100%;
  min-height: 56px;
  box-sizing: border-box;
}
.move-meta {
  /* Icon, type and power sit right next to each other, same height, centered. */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.move-meta .move-cat-icon,
.move-meta .move-type-badge,
.move-meta .move-power-badge {
  flex: 0 0 auto;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  white-space: nowrap;
}
.move-meta .move-cat-icon { width: auto; object-fit: contain; }
.move-meta .move-type-badge { font-size: 8px; padding: 0 5px; }
.move-meta .move-power-badge { padding: 0 5px; }
/* Mobile: stack the move info — type on its own line (centered, not stretched),
   then physical/special and power on the next line. */
@media (max-width: 768px) {
  .move-meta {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-areas:
      "type type"
      "cat  power";
    justify-content: center;
    align-items: center;
    gap: 3px 4px;
  }
  .move-meta .move-type-badge  { grid-area: type; justify-self: center; }
  .move-meta .move-cat-icon    { grid-area: cat;  justify-self: end; }
  .move-meta .move-power-badge { grid-area: power; justify-self: start; }
}
.move-name {
  font-size: var(--text-sm);
  color: var(--text);
  -webkit-text-stroke: 1.5px #000;
  paint-order: stroke fill;
  text-align: center;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.move-power-badge {
  font-family: monospace, 'Courier New';
  font-size: 9px;
  padding: 2px 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.08);
  color: var(--text-dim);
  font-weight: bold;
}
.move-cat-badge {
  font-family: monospace, 'Courier New';
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: bold;
  text-transform: uppercase;
}
.move-cat-physical { background: #c03028; color: #fff; }
.move-cat-special  { background: #7038f8; color: #fff; }
.move-desc {
  font-size: var(--text-sm);
  color: var(--text-dim);
  text-align: center;
  line-height: 1.6;
}

/* Type badges */
.type-badge {
  font-family: monospace, 'Courier New';
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  /* Punch up the otherwise-muted standard type palette. */
  filter: saturate(1.3);
}
.type-normal   { background:#a8a878; color:#000; }
.type-fire     { background:#f08030; color:#000; }
.type-water    { background:#6890f0; color:#000; }
.type-electric { background:#f8d030; color:#000; }
.type-grass    { background:#78c850; color:#000; }
.type-ice      { background:#98d8d8; color:#000; }
.type-fighting { background:#c03028; color:#fff; }
.type-poison   { background:#a040a0; color:#fff; }
.type-ground   { background:#e0c068; color:#000; }
.type-flying   { background:#a890f0; color:#000; }
.type-psychic  { background:#f85888; color:#fff; }
.type-bug      { background:#a8b820; color:#000; }
.type-rock     { background:#b8a038; color:#000; }
.type-ghost    { background:#705898; color:#fff; }
.type-dragon   { background:#7038f8; color:#fff; }
.type-dark     { background:#705848; color:#fff; }
.type-steel    { background:#b8b8d0; color:#000; }
.type-fairy    { background:#ee99ac; color:#000; }

/* HP Bars */
.hp-bar-bg {
  width: 100%;
  height: 8px;
  background: #111;
  border-radius: 0;
  overflow: hidden;
  /* While an ancestor .battle-pokemon is mid-transform (hit/level-up shakes),
     mobile browsers can rasterize the fill slightly out of step with the
     overflow clip, leaking a subpixel sliver of color past the bar's edges.
     Promoting the bar to its own layer keeps the clip and fill aligned.
     (No clip-path here — it would also clip the outline + pixel shadow.) */
  transform: translateZ(0);
  isolation: isolate;
  image-rendering: pixelated;
  position: relative;
  box-sizing: border-box;
  outline: 2px solid #000;
  box-shadow: 2px 2px 0 0 #000;
}
.hp-bar-bg::after { display: none; }
.hp-bar-bg.sm { height: 5px; }
.hp-bar-fill { height: 100%; border-radius: 0; transition: width 0.3s; display: block; position: relative; }
.hp-bar-shadow { position: absolute; bottom: 0; left: 0; width: 100%; height: 50%; background: rgba(0,0,0,0.23); pointer-events: none; }
.hp-text { font-size: var(--text-base); color: var(--text-dim); }
.poke-hp { width: 100%; display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }

/* ---- Team / Item Bars ---- */
.hud-bars,
.map-panels {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}
.hud-box {
  flex: 1;
  padding: 8px;
}
.map-panel-left  { flex: 2; }
.map-panel-right { flex: 1; }
.hud-label {
  font-size: var(--text-sm);
  color: var(--text-dim);
  margin-bottom: 4px;
}

/* Map HUD — team / items / badges (run screen) */
#map-screen .hud-label,
#map-screen .map-badges-label {
  font-size: var(--text-base);
  margin-bottom: 6px;
}
#map-screen .team-slot-name {
  font-size: var(--text-xs);
  max-width: 64px;
}
#map-screen .team-slot-lv {
  font-size: var(--text-xs);
}
#map-screen .team-slot-item {
  font-size: var(--text-xs);
}
#map-screen .item-badge {
  font-size: var(--text-sm);
  line-height: 1.5;
}
#map-screen .item-bar-empty {
  font-size: var(--text-xs);
  color: var(--text-dim);
}
#map-screen #badge-count {
  gap: 2px;
}
#map-screen #badge-count-panel {
  gap: 2px;
  margin-top: 4px;
}
#map-screen .map-badges-label {
  margin-top: 8px;
  margin-bottom: 4px;
}
#map-screen #badge-count .badge-icon-img,
#map-screen #badge-count .badge-icon-empty,
#map-screen #badge-count-panel .badge-icon-img,
#map-screen #badge-count-panel .badge-icon-empty {
  width: 20px;
  height: 20px;
}

/* Desktop-only — hidden on mobile */
.map-badges-label,
#badge-count-panel { display: none; }
/* From tablet width up the badges live in the right HUD panel (this used to
   be ≥900px only, leaving the 769–899px window with no badge display). */
@media (min-width: 769px) {
  .map-badges-label { display: block; }
  #badge-count-panel {
    display: grid;
    grid-template-columns: repeat(4, auto);
  }
}
#team-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
#team-bar .poke-card { width: 100%; }
.screen-team-bar {
  display: flex; gap: 20px; flex-wrap: wrap; justify-content: center;
  margin-top: 16px; padding-top: 12px;
  border-top: 1px solid var(--border);
}
.team-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 64px;
}
/* Reorderable slots: the whole slot (and every child — sprite, name, level, HP)
   must swallow touch gestures, otherwise a drag started on the sprite/text is
   treated as a scroll and only the empty area grabs. Centring keeps the grab box
   filling the slot's full height. */
.team-slot-reorder { justify-content: center; }
.team-slot-reorder,
.team-slot-reorder * { touch-action: none; }
.team-sprite { width: 40px; height: 40px; image-rendering: pixelated; }
.team-slot-name { font-size: var(--text-sm); color: var(--text-dim); text-align: center; overflow: hidden; max-width: 64px; white-space: nowrap; text-overflow: ellipsis; }
.team-slot-lv { font-size: var(--text-xs); color: var(--accent); }
.team-slot-item {
  font-size: var(--text-sm);
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  padding: 1px 3px;
  background: rgba(255,215,0,0.12);
  border: 1px solid rgba(255,215,0,0.3);
  transition: background 0.15s;
}
.team-slot-item:hover { background: rgba(255,215,0,0.28); }

/* Icon-only item badges in a wrapping row — same presentation as the passive
   badges below them; names show in the hover/tap tooltip. */
#item-bar,
#elite-prep-items { display: grid; grid-template-columns: repeat(5, max-content); gap: 4px; align-items: center; justify-content: start; }
#item-bar .item-badge,
#elite-prep-items .item-badge { font-size: 0; line-height: 0; padding: 3px; }
.item-badge {
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: var(--text-base);
  cursor: help;
}
.item-sprite-icon {
  /* crisp-edges first as the fallback; pixelated (strict nearest-neighbor)
     wins where supported — the reverse order let Safari pick crisp-edges,
     which it renders smoothed. */
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  flex-shrink: 0;
}
#item-tooltip {
  position: fixed;
  pointer-events: none;
  background: #0e0b06;
  border: 2px solid #c8b070;
  box-shadow: 0 0 0 1px #000, 3px 3px 0 0 #000;
  color: var(--text);
  font-size: var(--text-sm);
  line-height: 1.9;
  padding: 8px 12px;
  white-space: normal;
  max-width: 200px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.1s;
  transform: translate(-50%, calc(-100% - 12px));
}
#item-tooltip.visible { opacity: 1; }

#trait-tooltip {
  position: fixed;
  pointer-events: none;
  background: #0e0b06;
  border: 2px solid #c8b070;
  box-shadow: 0 0 0 1px #000, 3px 3px 0 0 #000;
  color: var(--text);
  font-size: var(--text-sm);
  line-height: 1.9;
  padding: 8px 12px;
  white-space: normal;
  max-width: 200px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.1s;
}
#trait-tooltip.visible { opacity: 1; }

/* No text/image selection or long-press menu on the map */
#map-container,
#map-container svg,
#map-container svg * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#map-container svg {
  shape-rendering: crispEdges;
}
/* Map nodes: the CSS transform re-states the per-node translate (set as
   --node-tx/--node-ty by map.js) so clickable nodes can grow + glow on hover.
   The attribute transform stays in the markup as a fallback. */
#map-container svg g.map-node {
  transform: translate(var(--node-tx, 0px), var(--node-ty, 0px));
  transform-origin: 0 0;
}
#map-container svg g.map-node--clickable {
  transition: transform 0.12s ease, filter 0.12s ease;
}
@media (hover: hover) {
  #map-container svg g.map-node--clickable:hover {
    transform: translate(var(--node-tx, 0px), var(--node-ty, 0px)) scale(1.15);
    filter: drop-shadow(0 0 6px rgba(255, 215, 0, 0.85)) brightness(1.12);
  }
}
#map-container foreignObject img {
  -webkit-user-drag: none;
  user-drag: none;
  pointer-events: none;
}

/* ---- Map Node Tooltip ---- */
#map-node-tooltip {
  position: fixed;
  pointer-events: none;
  background: #0e0b06;
  border: 2px solid #c8b070;
  box-shadow: 0 0 0 1px #000, 3px 3px 0 0 #000;
  color: var(--text);
  font-size: var(--text-sm);
  line-height: 1.9;
  padding: 8px 12px;
  white-space: normal;
  max-width: 200px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.1s;
  transform: translate(-50%, calc(-100% - 12px));
}
#map-node-tooltip.visible { opacity: 1; }

/* ---- Tutorial overlay ---- */
#tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 600;
  cursor: pointer;
}
.tutorial-callout {
  position: absolute;
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: var(--text-sm);
  line-height: 1.7;
  padding: 8px 12px;
  border-radius: 6px;
  max-width: 180px;
  pointer-events: none;
}
.tutorial-callout::after {
  content: '';
  position: absolute;
  border: 6px solid transparent;
}
.tutorial-callout.arrow-right::after {
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  border-left-color: var(--accent);
}
.tutorial-callout.arrow-up::after {
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  border-bottom-color: var(--accent);
}
.tutorial-dismiss {
  position: absolute;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  color: var(--text-dim);
  font-size: var(--text-xs);
  pointer-events: none;
}

#team-hover-card {
  position: fixed;
  z-index: 500;
  pointer-events: none;
  display: none;
  width: 200px;
}
#team-hover-card .poke-card {
  margin: 0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}

/* ---- Map Screen ---- */
#map-screen { gap: 12px; }
/* Legacy top bar — only ever rendered in the 769–899px window (mobile and the
   ≥900px sidebar layout both hide it) where it sat empty in Battle Tower.
   Hidden everywhere; badges show in the right HUD panel from 769px up instead. */
.map-header {
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
#map-info { display: none; }
#badge-count { display: grid; grid-template-columns: repeat(8, auto); gap: 3px; }
.badge-icon-img { width: 22px; height: 22px; image-rendering: pixelated; }
.badge-icon-empty { display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 1px dashed var(--border); opacity: 0.3; }

#map-container {
  --map-frame-color: var(--text-main);
  flex: 1;
  min-height: 320px;
  aspect-ratio: 1600 / 2668;
  width: auto;
  align-self: center;
  position: relative;
  overflow: hidden;
  background: center / cover no-repeat;
  image-rendering: pixelated;
  border: 2px solid var(--map-frame-color);
  box-shadow: 3px 3px 0 0 var(--map-frame-color);
}
#map-container::after {
  content: 'pokelike.xyz';
  position: absolute;
  bottom: -2px;
  right: -2px;
  font-size: var(--text-xs);
  line-height: 1.45;
  text-transform: uppercase;
  color: var(--gold);
  background: var(--map-frame-color);
  padding: 4px 6px;
  text-shadow:
    1px 1px 0 #6a5010,
    2px 2px 0 var(--map-frame-color),
    0 0 12px rgba(255, 215, 0, 0.45);
  pointer-events: none;
}


/* ---- Battle Screen ---- */
#battle-screen { gap: 12px; }
.overtime-banner { background: #c00; color: #fff;font-size: var(--text-sm); text-align: center; padding: 5px; }
.battle-header { text-align: center; }

/* Battle screen: keep the title, drop the subtitle. The header carries the
   screen-intro 40px bottom margin, which leaves a huge gap above the field once
   the subtitle is gone — collapse it. The field keeps its original,
   non-responsive layout — Pokémon stack at their natural size/spacing and a full
   team of 6 simply scrolls if it doesn't fit. */
#battle-screen #battle-subtitle { display: none; }
#battle-screen .battle-header { margin-bottom: 0; }

/* Passives sit in a vertical strip to the LEFT of the fighting field. */
.battle-stage {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 10px;
}
.battle-stage .battle-field { flex: 1 1 auto; min-width: 0; }
#battle-passives-row {
  flex: 0 0 auto;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
}

.battle-field {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.battle-side {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.battle-side-label {
  font-size: var(--text-sm);
  color: var(--text-dim);
  text-transform: uppercase;
}

.battle-pokemon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 8px 72px;
  position: relative;
}
.battle-base {
  width: 128px;
  height: auto;
  image-rendering: pixelated;
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
}
.battle-pokemon { background: url('../img/battle-bg.png') center bottom / cover no-repeat !important; background-clip: padding-box !important; }
.battle-pokemon.fainted { opacity: 0.3; }
.battle-sprite { width: 84px; height: 84px; image-rendering: pixelated; position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%); z-index: 3; }
#player-side .battle-sprite { transform: translateX(-50%) scaleX(-1); }
.battle-poke-name { font-size: var(--text-xs);color: #fff; -webkit-text-stroke: 2px #000; paint-order: stroke fill; margin-bottom: 8px; }
.battle-stages { position: absolute; bottom: 4px; left: 4px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; z-index: 4; }
.battle-stage-badge {font-size: var(--text-xs); padding: 1px 3px; border-radius: 2px; box-shadow: 1px 1px 0 0 #000; }
.stage-up   { background: #1a3a1a; color: #5af055; border: 1px solid #5af055; }
.stage-down { background: #3a1a1a; color: #f05545; border: 1px solid #f05545; }

.battle-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  padding: 4px 8px;
}

#btn-auto-battle:disabled { opacity: 0.35; }

/* Post-loss Continue — big, red, gently pulsing so it can't be missed.
   (Specificity includes the id so the dark-mode #btn-continue-battle
   background override doesn't win.) */
#btn-continue-battle.battle-continue-loss,
body.dark-mode #btn-continue-battle.battle-continue-loss {
  font-size: var(--btn-font-lg);
  height: var(--control-lg-height);
  min-height: var(--control-lg-height);
  padding: 0 var(--btn-px-lg);
  background: var(--red);
  color: #fff;
  border-color: var(--outline);
  box-shadow: var(--btn-edge-lg) var(--btn-edge-lg) 0 0 var(--outline);
  animation: continue-loss-pulse 1.4s ease-in-out infinite;
}
@keyframes continue-loss-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.05); }
}

/* Mobile: progression buttons (FIGHT on the prep screen, post-loss Continue)
   pin to the bottom center where the thumb already rests. Centered with
   left/right + margin auto (not translateX) so their scale animations don't
   fight the centering transform. */
@media (max-width: 768px) {
  .elite-prep-fight-btn,
  #btn-continue-battle.battle-continue-loss {
    position: fixed;
    left: 16px;
    right: 16px;
    margin-left: auto;
    margin-right: auto;
    width: min(360px, calc(100vw - 32px));
    bottom: calc(14px + var(--safe-bottom));
    z-index: 60;
    box-sizing: border-box;
  }
  /* The pinned FIGHT button leaves the flow — keep the prep content
     scrollable above it. */
  #elite-prep-screen.active {
    padding-bottom: calc(86px + var(--safe-bottom));
  }
}


/* ---- Catch Screen ---- */
#catch-screen { gap: 16px; justify-content: center; align-items: center; }
#catch-choices {
  display: flex;
  gap: var(--pick-cards-gap);
  justify-content: center;
  flex-wrap: wrap;
}

/* ---- Trait preview under pick options ---- */
.poke-choice-wrap {
  display: flex;
  flex-direction: column;
  width: 180px;
}
/* Equal-height cards across a pokemon choice row: the row stretches every item
   to the tallest, and each card grows to fill its slot, so move/ability wrapping
   (1 vs 2 lines) no longer makes cards different heights. */
#catch-choices,
.starter-card-row,
#starter-choices:not(:has(.pc-box)) { align-items: stretch; }
.poke-choice-wrap > .poke-card { flex: 1 1 auto; height: auto; }
.starter-card-row > .poke-card,
#starter-choices:not(:has(.pc-box)) > .poke-card { height: 100%; }
@media (max-width: 600px) {
  #shiny-screen .poke-choice-wrap { width: 150px; max-width: 100%; }
}
/* Battle Tower / endless catch: each wrap also carries a trait preview below the
   card. Equalize the base CARDS with subgrid so a taller trait box on one option
   no longer stretches another option's card (the empty-space look reported in the
   tower). The trait preview keeps its natural content height. Desktop only — the
   mobile catch screen has its own compact layout. */
@media (min-width: 769px) {
  #catch-choices:has(.poke-trait-preview) {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 190px);
    grid-template-rows: auto auto auto; /* card | trait preview | reroll button */
    justify-content: center;
    align-items: start;
    gap: 16px;
  }
  #catch-choices:has(.poke-trait-preview) .poke-choice-wrap {
    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 3;
    width: auto;
  }
  /* Card and trait box both fill the column so the trait box is never wider
     than the card above it. */
  #catch-choices:has(.poke-trait-preview) > .poke-choice-wrap > .poke-card { width: 100%; }
  /* Trait rows keep their natural size — a single-type mon shows one normal-sized
     box (no enlarged box to fill a dual-type's height). */
  #catch-choices:has(.poke-trait-preview) .poke-trait-preview { align-self: start; }
}
/* Same equalization on the mobile tower catch screen — a taller trait box no
   longer stretches the other cards, and the trait box matches its card's width.
   Columns share the row width here instead of a fixed 190px. */
@media (max-width: 768px) {
  #catch-choices:has(.poke-trait-preview) {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto; /* card | trait preview | reroll button */
    justify-content: center;
    align-items: start;
    gap: var(--pick-cards-gap);
    width: 100%;
    max-width: 580px;
  }
  #catch-choices:has(.poke-trait-preview) .poke-choice-wrap {
    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 3;
    width: auto;
    max-width: none;
  }
  #catch-choices:has(.poke-trait-preview) .poke-card { width: 100%; max-width: none; }
  #catch-choices:has(.poke-trait-preview) .poke-trait-preview { align-self: start; }
}
.poke-trait-preview {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 4px 4px;
}
/* Holds the row-3 space after a reroll so the layout doesn't jump. */
.reroll-placeholder {
  height: var(--control-md-height);
}
.trait-preview-row {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 7px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  box-shadow: 2px 2px 0 0 #000;
  min-width: 0;
  overflow: hidden;
}
.trait-preview-row-up {
  border-color: #ffd700;
  box-shadow: 0 0 0 1px #ffd700, 2px 2px 0 0 #000;
}
.trait-preview-row-header {
  display: flex;
  align-items: center;
  gap: 5px;
}
.trait-preview-count {
  font-size: var(--text-xs);
  color: var(--text-dim);
  white-space: nowrap;
}
.trait-preview-new-tag {
  font-size: var(--text-xs);
  color: #ffd700;
}
.trait-preview-desc {
  color: var(--text-dim);
  line-height: 1.5;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}

/* ---- Item Screen ---- */
#item-screen { gap: 16px; justify-content: center; align-items: center; }
#item-choices {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}
.item-card {
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  width: 220px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
}
.item-card:hover { border-color: var(--accent); transform: translateY(-4px); box-shadow: 0 8px 24px rgba(200,152,32,0.35); }
/* Locked starting-item card (Challenge picker): no hover lift + lock overlay. */
.item-card.locked,
.item-card.locked:hover { transform: none; border-color: var(--border); box-shadow: 3px 3px 0 0 var(--outline); cursor: not-allowed; position: relative; }
.starting-item-lock {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  cursor: not-allowed;
}
.starting-item-lock img { height: 40px; width: auto; image-rendering: pixelated; }
.item-icon { font-size: 36px; margin-bottom: 8px; }
.item-name {
  font-size: var(--text-lg);
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.5;
}
.item-desc { color: var(--text-dim); line-height: 1.6; }
/* Tags (PASSIVE / USABLE ITEM / NEW / REPLACE) sit at the bottom of the card,
   not directly under the description, so they line up across cards. */
.item-tag { margin-top: auto; padding-top: 6px; }
.item-tag--usable { font-size: 9px; color: #4af; }

/* ---- Swap Screen ---- */
#swap-screen { gap: 16px; }
.swap-prompt { text-align: center; color: var(--text-dim); margin: 0; }
#swap-choices { display: grid; grid-template-columns: repeat(3, auto); gap: 12px; justify-content: center; }
@media (max-width: 768px) {
  /* A full 6-mon team can't fit 3-up on a phone (3 × 150px cards overflow the
     viewport sideways) — wrap full-size cards instead, 2-up on most phones. */
  #swap-choices {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
  }
  #swap-choices .poke-card { width: 150px; max-width: 100%; }
}

/* ---- Trade Screen ---- */
#trade-screen { gap: 10px; }
#trade-desc { text-align: center; color: var(--text-dim); margin: 0; }
#trade-team-list { list-style: none; padding: 0; margin: 0; width: 100%; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; max-height: 55vh; }
.trade-member-row {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.trade-member-row:hover { border-color: var(--accent); background: rgba(255,255,255,0.04); }
.trade-member-sprite { width: 48px; height: 48px; image-rendering: pixelated; flex-shrink: 0; }
.trade-member-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.trade-member-name {
  font-size: var(--text-base);
  color: var(--text);
  line-height: 1.35;
}
.trade-member-level {
  font-size: var(--text-sm);
  color: var(--text-dim);
  line-height: 1.35;
}
.trade-member-types { display: flex; gap: 4px; }
.trade-member-arrow { font-size: 16px; color: var(--text-dim); flex-shrink: 0; }
.trade-footer { text-align: center; padding-top: 4px; }

/* ---- Shiny Screen ---- */
#shiny-screen { align-items: center; justify-content: center; gap: 20px; text-align: center; }
.shiny-title {
  font-size: var(--text-2xl);
  color: var(--gold);
  text-shadow: 0 0 20px var(--gold);
  animation: shimmer 1s ease-in-out infinite alternate;
}
@keyframes shimmer { from { text-shadow: 0 0 10px gold; } to { text-shadow: 0 0 30px gold, 0 0 60px orange; } }
#shiny-content { display: flex; flex-direction: column; align-items: center; gap: 16px; }

/* ---- Badge Screen ---- */
#badge-screen { gap: 16px; justify-content: center; align-items: center; text-align: center; }
.badge-earn-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.badge-earn-icon-wrap {
  background: var(--bg2);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 24px 28px;
  box-shadow: 3px 3px 0 0 #000;
}
.badge-earn-icon {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  display: block;
  animation: badge-earn-bounce 0.5s ease-in-out infinite alternate;
}
@keyframes badge-earn-bounce { from { transform: scale(1); } to { transform: scale(1.1); } }
.badge-earn-count {
  margin: 0;
  font-size: var(--text-xs);
  line-height: 1.6;
  color: var(--text-dim);
}
.badge-earn-footer { text-align: center; margin-top: 4px; }

/* ---- Item Equip Modal ---- */
.item-equip-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding:
    calc(16px + var(--safe-top))
    calc(16px + var(--safe-right))
    calc(16px + var(--safe-bottom))
    calc(16px + var(--safe-left));
  box-sizing: border-box;
}
.item-equip-box {
  background: #e8e4d8;
  border: 2px solid var(--outline);
  box-shadow: 3px 3px 0 0 var(--outline);
  color: var(--text-main);
  padding: 18px;
  max-width: 360px;
  width: 92%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 90dvh; /* dynamic vh so bottom buttons stay on-screen on mobile */
  overflow-y: auto;
}
.equip-item-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 12px;
  margin: -18px -18px 0;
  background: #d8d4c8;
  border-bottom: 2px solid var(--outline);
}
.equip-item-icon { font-size: 28px; flex-shrink: 0; }
.equip-item-header > div:not(:first-child) {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.item-equip-box .equip-item-name {
  font-size: var(--text-lg);
  color: var(--text-main);
  line-height: 1.5;
}
.equip-item-desc {
  color: var(--text-dim);
  line-height: 1.6;
}
.equip-pokemon-list { display: flex; flex-direction: column; gap: 6px; }
.equip-pokemon-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #dedad0;
  border: 2px solid #BFBCB0;
  box-shadow: none;
  padding: 7px 8px;
}
.equip-poke-sprite { width: 36px; height: 36px; image-rendering: pixelated; flex-shrink: 0; }
.equip-poke-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 60px;
}
.equip-poke-name {
  font-size: var(--text-base);
  color: var(--text);
  line-height: 1.35;
}
.equip-poke-lv {
  font-size: var(--text-sm);
  color: var(--text-dim);
  line-height: 1.35;
}
.item-equip-box .equip-held-slot {
  flex: 1;
  font-size: var(--text-lg);
  color: var(--text-main);
  text-align: right;
  padding-right: 6px;
}
.item-equip-box .equip-held-item {
  font-size: var(--text-lg);
  color: var(--text-main);
}
.equip-empty-slot { color: var(--text-dim); font-style: italic; }
.equip-btn-group { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }

.equip-pokemon-row .btn-primary.btn-sm:not(.equip-btn-unequip) {
  background: #C89821;
  border: 2px solid #C89821;
  box-shadow: var(--btn-edge-sm) var(--btn-edge-sm) 0 0 #9a7818;
  color: #fff;
}
.equip-pokemon-row .btn-primary.btn-sm.equip-btn-unequip {
  background: #d84848;
  border: 2px solid #e06060;
  box-shadow: var(--btn-edge-sm) var(--btn-edge-sm) 0 0 #b83838;
  color: #fff;
}
@media (hover: hover) {
  .equip-pokemon-row .btn-primary.btn-sm:hover:not(:disabled):not(:active) {
    transform: translate(var(--btn-lift), var(--btn-lift));
  }
  .equip-pokemon-row .btn-primary.btn-sm:not(.equip-btn-unequip):hover:not(:disabled):not(:active) {
    background: #d4ac28;
    border-color: #d4ac28;
    box-shadow: 3px 3px 0 0 #9a7818;
    color: #fff;
  }
  .equip-pokemon-row .btn-primary.btn-sm.equip-btn-unequip:hover:not(:disabled):not(:active) {
    background: #e85858;
    border-color: #f07070;
    box-shadow: 3px 3px 0 0 #b83838;
    color: #fff;
  }
}
.equip-pokemon-row .btn-primary.btn-sm:active:not(:disabled) {
  transform: translate(var(--btn-push), var(--btn-push));
}
.equip-pokemon-row .btn-primary.btn-sm:not(.equip-btn-unequip):active:not(:disabled) {
  background: #C89821;
  border-color: #C89821;
  box-shadow: 1px 1px 0 0 #9a7818;
  color: #fff;
}
.equip-pokemon-row .btn-primary.btn-sm.equip-btn-unequip:active:not(:disabled) {
  background: #d84848;
  border-color: #e06060;
  box-shadow: 1px 1px 0 0 #b83838;
  color: #fff;
}
.equip-self-tag { font-size: var(--text-sm); color: var(--text-dim); font-style: italic; flex-shrink: 0; }

/* ---- Transition Screen ---- */
#transition-screen {
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  background: radial-gradient(circle, var(--bg3) 0%, var(--bg) 70%);
}
#transition-msg { font-size: var(--text-2xl); color: var(--green); }
#transition-sub { color: var(--text-dim); }

/* ---- Elite Prep Screen ---- */
#elite-prep-screen {
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding:
    calc(16px + var(--safe-top))
    calc(16px + var(--safe-right))
    calc(16px + var(--safe-bottom))
    calc(16px + var(--safe-left));
  /* No screen background — let the shared body backdrop show through, matching the
     other pick/prep screens (catch / item / passive). */
  overflow-y: auto;
}
/* Pre-fight prep reuses the battle field verbatim (.battle-field / .battle-side /
   .battle-pokemon / .battle-trait-bar) so it reads exactly like the fight. Extras:
   a "Choose Your Order" banner, an external Bag window floated on the left, a big
   red FIGHT button centred over the field, and prep-only hover/drag affordances. */
#elite-prep-screen { position: relative; }
#elite-prep-screen .screen-intro { margin-bottom: 0; }

.elite-prep-order-banner {
  font-size: var(--text-xl); color: var(--gold); text-align: center;
  text-shadow: 2px 2px 0 #000;
}
.elite-prep-hint { color: var(--text-dim); font-size: var(--text-sm); text-align: center; }

/* Your Pokémon face the foe; the enemy trainer faces inward — same as battle. */
#elite-prep-player-side .battle-sprite { transform: translateX(-50%) scaleX(-1); }
.elite-prep-trainer-enemy img { transform: scaleX(-1); }

/* Bag │ both-team field │ FIGHT button, laid out in one centered row. The teams
   top-align so your lead and the enemy lead sit on the same line. */
.elite-prep-stage {
  display: flex; align-items: flex-start; justify-content: center;
  gap: 12px; width: 100%;
}
.elite-prep-field {
  position: relative; flex: 0 1 520px; margin-inline: 0;
  align-items: start; /* grid: top-align the two team columns */
}
/* Reserve equal trait-bar height on both sides so the Pokémon below them line up. */
.elite-prep-field .battle-trait-bar { min-height: 24px; align-content: flex-start; }

/* Bag window — sits next to your team (left of the field), vertically centered. */
.elite-prep-bag {
  flex: 0 0 auto; align-self: center; width: 156px;
  border: 2px solid var(--border); border-radius: 8px; background: var(--bg3);
  box-shadow: 4px 4px 0 0 var(--outline);
  padding: 8px; display: flex; flex-direction: column; gap: 8px;
}
.elite-prep-bag-title {
  font-size: var(--text-sm); color: var(--gold); text-transform: uppercase; text-align: center;
  border-bottom: 2px solid var(--border); padding-bottom: 6px;
}
/* Layout (grid) is shared with #item-bar above so the prep bag matches the
   regular run bag; only the min-height floor is prep-specific. */
#elite-prep-items { min-height: 22px; }

/* Big red FIGHT button — sits beside the enemy team (right of the field). */
.elite-prep-fight-btn {
  flex: 0 0 auto; align-self: center; white-space: nowrap;
  font-family: var(--font-ui); font-size: var(--text-2xl); color: #fff;
  background: var(--red); border: 3px solid var(--outline);
  box-shadow: 5px 5px 0 0 var(--outline);
  padding: 16px 22px; cursor: pointer; letter-spacing: 1px;
  text-shadow: 2px 2px 0 #000;
  transition: var(--btn-transition);
}
.elite-prep-fight-btn:hover  { transform: scale(1.05); box-shadow: 6px 6px 0 0 var(--outline); }
.elite-prep-fight-btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 0 var(--outline); }

/* Held-item badge shown on each prep Pokémon (the live battle hides held items). */
.elite-prep-mon-item {
  position: absolute; top: 4px; right: 6px; z-index: 5; line-height: 0;
  background: rgba(0,0,0,0.55); border: 1px solid var(--border); border-radius: 4px;
  padding: 2px;
}

/* Drag-to-reorder affordance on your battle Pokémon. */
#elite-prep-player-side .battle-pokemon { cursor: grab; }
.battle-pokemon.prep-dragover { outline: 2px dashed var(--gold); outline-offset: -2px; }

@media (max-width: 720px) {
  /* Not enough width for Bag │ field │ FIGHT side by side — stack them:
     Bag on top, both teams in the middle, FIGHT full-width at the bottom. */
  .elite-prep-stage { flex-wrap: wrap; gap: 10px; }
  .elite-prep-bag {
    order: -1; width: 100%; max-width: 360px; align-self: center; margin: 0 auto;
  }
  .elite-prep-field { flex: 1 1 100%; max-width: 520px; margin-inline: auto; }
  .elite-prep-fight-btn {
    order: 1; width: 100%; max-width: 360px; align-self: center;
    font-size: var(--text-xl); padding: 14px 18px;
  }
}

/* ---- Game Over Screen ---- */
#gameover-screen {
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  background: radial-gradient(circle, #2a0000 0%, var(--bg) 70%);
}
.gameover-title {
  font-size: var(--text-5xl);
  color: var(--red);
  text-shadow: 0 0 20px var(--red);
}
#gameover-badges { color: var(--text-dim); }
#gameover-team {
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  max-width: 600px;
}

/* ---- Win Screen ---- */
#win-screen {
  align-items: center;
  gap: 20px;
  text-align: center;
  padding-bottom: calc(40px + var(--safe-bottom));
}
.win-title {
  font-size: var(--text-4xl);
  color: var(--gold);
  text-shadow: 0 0 30px var(--gold);
  animation: shimmer 1.5s ease-in-out infinite alternate;
}
#win-team { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ---- Loading ---- */
.loading {
  color: var(--text-dim);
  padding: 20px;
  text-align: center;
  animation: pulse 1s ease-in-out infinite alternate;
}
@keyframes pulse { from { opacity: 0.5; } to { opacity: 1; } }

/* Cloud-save "contacting server" state. Bright cyan distinguishes it from
   amber (offline) and the default (online), pulse + spinning ⟳ supply
   continuous motion so the indicator never looks frozen even if the load
   takes the full timeout to respond. */
[data-menu="account"].cloud-loading {
  color: #5fb8ff !important;
  animation: cloud-loading-pulse 1.2s ease-in-out infinite;
}
@keyframes cloud-loading-pulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}
[data-menu="account"].cloud-loading .run-menu-account-label::before {
  content: '⟳ ';
  display: inline;
  animation: cloud-spin 0.9s linear infinite;
}
@keyframes cloud-spin {
  to { transform: rotate(360deg); }
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
  .battle-field { grid-template-columns: 1fr 1fr; }
  .poke-card { width: 150px; }
  #catch-choices .poke-card,
  #starter-choices:not(:has(.pc-box)) .poke-card,
  .starter-card-row .poke-card {
    width: 100%;
    max-width: 100%;
  }
  #catch-choices .poke-choice-wrap {
    width: 100%;
    max-width: 580px;
  }

  /* Tighter mobile spacing: less air to the screen edges and between tiles,
     and trim the roomy gaps on the battle / pick screens. */
  .screen {
    padding:
      calc(10px + var(--safe-top))
      calc(8px + var(--safe-right))
      calc(10px + var(--safe-bottom))
      calc(8px + var(--safe-left));
  }
  .screen-intro { margin-bottom: 16px; }
  #battle-screen { gap: 8px; }
  .battle-field { gap: 8px; }
  .battle-side { padding: 8px 6px; gap: 12px; }
  .battle-pokemon { padding-bottom: 60px; }
}


/* Scrollbar — track + thumb rectangles darken the container behind them */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 0;
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 0;
  min-height: 24px;
}
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }
::-webkit-scrollbar-corner { background: var(--scrollbar-track); }

/* ---- Desktop sidebar layout (900px+) ---- */
@media (min-width: 900px) {
  #map-screen {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    height: calc(100vh - var(--ad-reserve, 0px));
    min-height: unset;
    overflow: hidden;
    gap: clamp(8px, 1vw, 20px);
    padding:
      calc(clamp(10px, 1.2vw, 20px) + var(--safe-top))
      calc(clamp(10px, 1.2vw, 20px) + var(--safe-right))
      calc(clamp(10px, 1.2vw, 20px) + var(--safe-bottom))
      calc(clamp(10px, 1.2vw, 20px) + var(--safe-left));
    position: relative;
  }

  body.run-menu-active #map-screen {
    padding-top: calc(clamp(10px, 1.2vw, 20px) + var(--safe-top));
    padding-bottom: calc(clamp(10px, 1.2vw, 20px) + var(--safe-bottom));
    padding-left: calc(clamp(10px, 1.2vw, 20px) + var(--safe-left));
  }

  .map-panels  { display: contents; }

  /* Layout: items | team | map | traits (the region/stage panel is gone). */
  .map-panel-left {
    order: 2;
    flex: 0 0 auto;
    width: fit-content;
    align-self: start;
    max-height: calc(100dvh - 32px - var(--run-menu-offset) - var(--ad-reserve, 0px));
    overflow-y: auto;
    padding-bottom: 16px;
    scroll-padding-bottom: 16px;
  }

  .map-panel-right {
    order: 1;
    flex: 0 0 auto;
    width: fit-content;
    align-self: start;
    max-height: calc(100dvh - 32px - var(--run-menu-offset) - var(--ad-reserve, 0px));
    overflow-y: auto;
    padding-bottom: 16px;
    scroll-padding-bottom: 16px;
  }

  /* Story mode: items sit to the right of the map (team | map | items)
     instead of the default items | team | map. */
  body.map-mode-story .map-panel-right { order: 4; }

  #map-container {
    order: 3;
    flex: 0 0 auto;
    min-height: 0;
    height: calc(100vh - 32px - var(--run-menu-offset) - var(--ad-reserve, 0px));
    width: auto;
    align-self: center;
  }

  #endless-trait-panel {
    order: 4;
    flex: 0 0 auto;
    width: fit-content;
    align-self: start;
    max-height: calc(100vh - 32px - var(--run-menu-offset) - var(--ad-reserve, 0px));
    overflow-y: auto;
  }

  #endless-region-panel {
    order: 4;
    flex: 0 0 auto;
    width: fit-content;
    align-self: start;
    max-height: calc(100vh - 32px - var(--run-menu-offset) - var(--ad-reserve, 0px));
    overflow-y: auto;
  }

  #team-bar { display: flex; flex-direction: column; gap: 8px; }
  #team-bar .poke-card { width: auto; }
}

/* Zoomed breakpoints scale the side panels up. `zoom` also multiplies their
   max-height, so the calc(... ) cap must be divided by the zoom factor or the
   panel renders taller than the viewport and its bottom is clipped instead of
   scrolling. Each panel keeps overflow-y:auto so long teams / trait lists scroll
   within the visible height. */
@media (min-width: 1200px) {
  .map-panel-left, .map-panel-right,
  #endless-trait-panel, #endless-region-panel {
    zoom: 1.25;
    max-height: calc((100dvh - 32px - var(--run-menu-offset) - var(--ad-reserve, 0px)) / 1.25);
    overflow-y: auto;
  }
}

@media (min-width: 1600px) {
  .map-panel-left, .map-panel-right,
  #endless-trait-panel, #endless-region-panel {
    zoom: 1.5;
    max-height: calc((100dvh - 32px - var(--run-menu-offset) - var(--ad-reserve, 0px)) / 1.5);
    overflow-y: auto;
  }
}

@media (min-width: 2100px) {
  .map-panel-left, .map-panel-right,
  #endless-trait-panel, #endless-region-panel {
    zoom: 1.8;
    max-height: calc((100dvh - 32px - var(--run-menu-offset) - var(--ad-reserve, 0px)) / 1.8);
    overflow-y: auto;
  }
}

/* ---- Battle Animations ---- */

/* Attacker highlight pulse */
.battle-pokemon.attacking {
  animation: attacker-pulse 0.3s ease-in-out;
}
@keyframes attacker-pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.08); filter: brightness(1.2); }
  100% { transform: scale(1); }
}

/* ---- Per-type hit animations ---- */

/* Crit — gold burst flash */
.battle-pokemon.crit-flash { animation: crit-flash 0.5s ease-out; }
@keyframes crit-flash {
  0%   { filter: brightness(1); }
  20%  { filter: brightness(1.9) sepia(1) saturate(5) hue-rotate(10deg); transform: scale(1.12); }
  60%  { filter: brightness(1.3) sepia(1) saturate(3); transform: scale(0.95); }
  100% { filter: brightness(1); transform: scale(1); }
}
.crit-popup {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  color: var(--gold);
  font-size: var(--text-sm);
  font-weight: bold;
  white-space: nowrap;
  pointer-events: none;
  animation: crit-popup 0.8s ease-out forwards;
  z-index: 10;
}
@keyframes crit-popup {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0);    }
  100% { opacity: 0; transform: translateX(-50%) translateY(-32px); }
}

/* Normal — simple white flash */
.battle-pokemon.hit-normal { animation: hit-normal 0.35s ease-out; }
@keyframes hit-normal {
  0%   { filter: brightness(1); }
  25%  { filter: brightness(1.4) saturate(0); }
  100% { filter: brightness(1); }
}

/* ======================== FIRE ======================== */
.battle-pokemon.hit-fire { animation: hit-fire 0.75s ease-out; }
@keyframes hit-fire {
  0%   { filter: brightness(1) saturate(1); transform: scale(1); }
  7%   { filter: brightness(1.9) saturate(2) hue-rotate(-15deg) drop-shadow(0 0 22px #ff4400); transform: scale(1.1); }
  26%  { filter: brightness(1.5) saturate(6) hue-rotate(-18deg) drop-shadow(0 -10px 18px #ff8800); transform: scale(1.07) translateX(2px); }
  55%  { filter: brightness(1.25) saturate(3) hue-rotate(-10deg) drop-shadow(0 -6px 10px #ffcc00); transform: scale(1.02); }
  100% { filter: brightness(1) saturate(1); transform: scale(1); }
}
/* ======================== WATER ======================== */
.battle-pokemon.hit-water { animation: hit-water 0.5s ease-out; }
@keyframes hit-water {
  0%   { filter: brightness(1); transform: scale(1); }
  20%  { filter: brightness(1.3) drop-shadow(0 0 14px #4488ff); transform: scaleX(0.88) scaleY(1.08); }
  50%  { filter: brightness(1.2) drop-shadow(0 0 8px #6699ff); transform: scaleX(1.04) scaleY(0.97); }
  100% { filter: brightness(1); transform: scale(1); }
}
/* ======================== ELECTRIC ======================== */
.battle-pokemon.hit-electric { animation: hit-electric 0.45s ease-out; }
@keyframes hit-electric {
  0%   { filter: brightness(1); transform: translateX(0); }
  8%   { filter: brightness(1.9) drop-shadow(0 0 18px #ffff00); transform: translateX(5px); }
  16%  { filter: brightness(1); transform: translateX(-5px); }
  24%  { filter: brightness(1.7) drop-shadow(0 0 14px #ffee00); transform: translateX(4px); }
  32%  { filter: brightness(1); transform: translateX(-3px); }
  50%  { filter: brightness(1.3) drop-shadow(0 0 8px #ffcc00); transform: translateX(0); }
  100% { filter: brightness(1); transform: translateX(0); }
}
/* ======================== GRASS ======================== */
.battle-pokemon.hit-grass { animation: hit-grass 0.55s ease-out; }
@keyframes hit-grass {
  0%   { filter: brightness(1); transform: rotate(0deg); }
  20%  { filter: brightness(1.4) drop-shadow(0 0 12px #44cc44); transform: rotate(-4deg) scale(1.04); }
  50%  { filter: brightness(1.2) drop-shadow(0 0 8px #66dd44); transform: rotate(3deg) scale(1.01); }
  100% { filter: brightness(1); transform: rotate(0deg) scale(1); }
}
/* ======================== ICE ======================== */
.battle-pokemon.hit-ice { animation: hit-ice 0.5s ease-out; }
@keyframes hit-ice {
  0%   { filter: brightness(1); transform: scale(1); }
  15%  { filter: brightness(1.5) drop-shadow(0 0 14px #aaeeff) saturate(0.3); transform: scale(1.06); }
  50%  { filter: brightness(1.3) drop-shadow(0 0 10px #88ddff) saturate(0.6); transform: scale(1.02); }
  100% { filter: brightness(1) saturate(1); transform: scale(1); }
}
/* ======================== FIGHTING ======================== */
.battle-pokemon.hit-fighting { animation: hit-fighting 0.4s ease-out; }
@keyframes hit-fighting {
  0%   { filter: brightness(1); transform: translate(0, 0); }
  12%  { filter: brightness(1.6) drop-shadow(0 0 12px #cc2222); transform: translate(-6px, 4px); }
  28%  { filter: brightness(1.4) drop-shadow(0 0 8px #dd3333); transform: translate(5px, -3px); }
  50%  { filter: brightness(1.2); transform: translate(-2px, 1px); }
  100% { filter: brightness(1); transform: translate(0, 0); }
}
/* ======================== POISON ======================== */
.battle-pokemon.hit-poison { animation: hit-poison 0.6s ease-out; }
@keyframes hit-poison {
  0%   { filter: brightness(1); transform: scale(1); }
  20%  { filter: brightness(1.35) drop-shadow(0 0 14px #aa44cc); transform: scale(0.94); }
  50%  { filter: brightness(1.2) drop-shadow(0 0 10px #993dbb); transform: scale(1.03); }
  100% { filter: brightness(1); transform: scale(1); }
}
/* ======================== GROUND ======================== */
.battle-pokemon.hit-ground { animation: hit-ground 0.5s ease-out; }
@keyframes hit-ground {
  0%   { filter: brightness(1); transform: translate(0, 0); }
  10%  { transform: translate(0, -4px); }
  22%  { filter: brightness(1.4) drop-shadow(0 6px 12px #cc8833); transform: translate(0, 8px); }
  45%  { filter: brightness(1.2) drop-shadow(0 3px 8px #dd9944); transform: translate(0, -2px); }
  100% { filter: brightness(1); transform: translate(0, 0); }
}

/* ======================== FLYING ======================== */
.battle-pokemon.hit-flying { animation: hit-flying 0.5s ease-out; }
@keyframes hit-flying {
  0%   { filter: brightness(1); transform: translateY(0); }
  25%  { filter: brightness(1.4) drop-shadow(0 -8px 14px #aabbff); transform: translateY(-8px); }
  55%  { filter: brightness(1.2) drop-shadow(0 -4px 8px #99aaee); transform: translateY(-3px); }
  100% { filter: brightness(1); transform: translateY(0); }
}

/* ======================== PSYCHIC ======================== */
.battle-pokemon.hit-psychic { animation: hit-psychic 0.6s ease-out; }
@keyframes hit-psychic {
  0%   { filter: brightness(1); transform: scale(1) rotate(0deg); }
  20%  { filter: brightness(1.5) drop-shadow(0 0 16px #ff44aa); transform: scale(1.05) rotate(8deg); }
  50%  { filter: brightness(1.3) drop-shadow(0 0 10px #ee3399); transform: scale(0.97) rotate(-4deg); }
  100% { filter: brightness(1); transform: scale(1) rotate(0deg); }
}
/* ======================== BUG ======================== */
.battle-pokemon.hit-bug { animation: hit-bug 0.4s ease-out; }
@keyframes hit-bug {
  0%   { filter: brightness(1); }
  20%  { filter: brightness(1.5) drop-shadow(0 0 12px #88bb00); transform: scale(1.04); }
  55%  { filter: brightness(1.2) drop-shadow(0 0 6px #99cc11); transform: scale(1.01); }
  100% { filter: brightness(1); transform: scale(1); }
}

/* ======================== ROCK ======================== */
.battle-pokemon.hit-rock { animation: hit-rock 0.5s ease-out; }
@keyframes hit-rock {
  0%   { filter: brightness(1); transform: translate(0, 0); }
  20%  { filter: brightness(1.4) saturate(0.6); transform: translate(-4px, -2px); }
  40%  { filter: brightness(1.2) saturate(0.7); transform: translate(3px, 2px); }
  65%  { filter: brightness(1.1); transform: translate(-1px, 0); }
  100% { filter: brightness(1) saturate(1); transform: translate(0, 0); }
}
/* ======================== GHOST ======================== */
.battle-pokemon.hit-ghost { animation: hit-ghost 0.6s ease-out; }
@keyframes hit-ghost {
  0%   { filter: brightness(1) opacity(1); }
  20%  { filter: brightness(0.4) drop-shadow(0 0 18px #7755aa) opacity(0.55); transform: scale(1.06); }
  40%  { filter: brightness(1.25) drop-shadow(0 0 12px #9966bb) opacity(0.9); transform: scale(0.96); }
  60%  { filter: brightness(0.7) drop-shadow(0 0 8px #8855aa) opacity(0.75); transform: scale(1.02); }
  100% { filter: brightness(1) opacity(1); transform: scale(1); }
}

/* ======================== DRAGON ======================== */
.battle-pokemon.hit-dragon { animation: hit-dragon 0.55s ease-out; }
@keyframes hit-dragon {
  0%   { filter: brightness(1) hue-rotate(0deg); transform: scale(1); }
  20%  { filter: brightness(1.5) drop-shadow(0 0 16px #7722ee) hue-rotate(30deg); transform: scale(1.07); }
  50%  { filter: brightness(1.3) drop-shadow(0 0 10px #9944ff) hue-rotate(-12deg); transform: scale(1.02); }
  100% { filter: brightness(1) hue-rotate(0deg); transform: scale(1); }
}

/* ======================== DARK ======================== */
.battle-pokemon.hit-dark { animation: hit-dark 0.45s ease-out; }
@keyframes hit-dark {
  0%   { filter: brightness(1); }
  20%  { filter: brightness(0.2) drop-shadow(0 0 16px #330022) invert(0.4); transform: scale(1.04); }
  45%  { filter: brightness(0.5) drop-shadow(0 0 10px #553344); transform: scale(0.97); }
  100% { filter: brightness(1); transform: scale(1); }
}

/* ======================== STEEL ======================== */
.battle-pokemon.hit-steel { animation: hit-steel 0.4s ease-out; }
@keyframes hit-steel {
  0%   { filter: brightness(1); }
  20%  { filter: brightness(1.5) saturate(0) drop-shadow(0 0 14px #ccddee); transform: scale(1.05); }
  55%  { filter: brightness(1.2) saturate(0.3) drop-shadow(0 0 7px #aabbcc); transform: scale(1.01); }
  100% { filter: brightness(1) saturate(1); transform: scale(1); }
}

/* ======================== FAIRY ======================== */
.battle-pokemon.hit-fairy { animation: hit-fairy 0.55s ease-out; }
@keyframes hit-fairy {
  0%   { filter: brightness(1); transform: scale(1); }
  20%  { filter: brightness(1.5) drop-shadow(0 0 14px #ff88cc); transform: scale(1.06) rotate(3deg); }
  45%  { filter: brightness(1.3) drop-shadow(0 0 10px #ff66bb); transform: scale(0.97) rotate(-2deg); }
  100% { filter: brightness(1); transform: scale(1) rotate(0deg); }
}

/* ---- Trainer Select Screen ---- */
#trainer-screen {
  align-items: center;
  justify-content: center;
  gap: 32px;
}
#trainer-choices {
  display: flex;
  gap: 40px;
  justify-content: center;
}
.trainer-card {
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 28px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.trainer-card:hover, .trainer-card:focus {
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(200,152,32,0.35);
  outline: none;
}
.trainer-icon-wrap img {
  display: block;
  width: 80px;
  height: 80px;
  image-rendering: pixelated;
}
.trainer-label {
  font-size: var(--text-base);
}
@media (max-width: 600px) {
  /* Two cards at 28px/36px padding + a 40px gap overflow a 320–360px viewport
     — tighten so BOY and GIRL always sit side by side without clipping. */
  #trainer-choices { gap: 16px; }
  .trainer-card { padding: 20px 22px; }
}

/* ---- Battle Trainer Icons ---- */
.battle-trainer {
  display: flex;
  justify-content: center;
  margin-bottom: 6px;
}
.trainer-sprite-img { image-rendering: pixelated; }
.battle-trainer img {
  width: 56px;
  height: 56px;
  image-rendering: pixelated;
  opacity: 0.9;
}

/* Active pokemon highlight (1v1 current fighter) */
.battle-pokemon.active-pokemon .battle-base {
  filter: drop-shadow(0 0 6px rgba(200,152,32,0.7));
}

/* ---- Map Notification Banner ---- */
.map-notification {
  position: fixed;
  top: calc(60px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: var(--text-sm);
  padding: 12px 24px;
  border-radius: 6px;
  border: 2px solid #00aaaa;
  box-shadow: 0 4px 20px rgba(0,170,170,0.4);
  z-index: 100;
  transition: opacity 0.5s;
  pointer-events: none;
}

/* ---- Level-Up Animation ---- */
.battle-pokemon {
  position: relative;
}

.battle-pokemon.level-up .battle-sprite {
  animation: level-up-bounce var(--levelup-dur, 0.7s) cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: 50% 100%;
}
/* Player-side sprites are mirrored (scaleX(-1)). Use a dedicated keyframe
   so the bounce preserves the mirror instead of flipping the sprite mid-animation. */
#player-side .battle-pokemon.level-up .battle-sprite {
  animation-name: level-up-bounce-mirrored;
}
.battle-pokemon.level-up::after {
  content: '';
  position: absolute;
  inset: -8px;
  pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 224, 102, 0.28) 0%, rgba(255, 215, 0, 0.0) 65%);
  animation: level-up-burst var(--levelup-dur, 0.7s) ease-out forwards;
  z-index: 5;
}
.battle-pokemon.level-up {
  animation: level-up-flash var(--levelup-dur, 0.7s) ease-out;
}

@keyframes level-up-flash {
  0%   { filter: brightness(1)    drop-shadow(0 0 0 transparent); }
  25%  { filter: brightness(1.18) drop-shadow(0 0 6px #ffe066); }
  60%  { filter: brightness(1.08) drop-shadow(0 0 4px #ffd700); }
  100% { filter: brightness(1)    drop-shadow(0 0 0 transparent); }
}

@keyframes level-up-bounce {
  0%   { transform: translateX(-50%) translateY(0)     scale(1); }
  35%  { transform: translateX(-50%) translateY(-10px) scale(1.05); }
  65%  { transform: translateX(-50%) translateY(0)     scale(1.0); }
  85%  { transform: translateX(-50%) translateY(-3px)  scale(1.02); }
  100% { transform: translateX(-50%) translateY(0)     scale(1); }
}

/* Mirrored variant — player-side sprites carry scaleX(-1) on the base rule */
@keyframes level-up-bounce-mirrored {
  0%   { transform: translateX(-50%) translateY(0)     scale(1)    scaleX(-1); }
  35%  { transform: translateX(-50%) translateY(-10px) scale(1.05) scaleX(-1); }
  65%  { transform: translateX(-50%) translateY(0)     scale(1.0)  scaleX(-1); }
  85%  { transform: translateX(-50%) translateY(-3px)  scale(1.02) scaleX(-1); }
  100% { transform: translateX(-50%) translateY(0)     scale(1)    scaleX(-1); }
}

@keyframes level-up-burst {
  0%   { transform: scale(0.6); opacity: 0; }
  30%  { transform: scale(1.0); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}

.level-up-text {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  color: #ffd700;
  font-size: var(--text-sm);
  font-weight: bold;
  white-space: nowrap;
  pointer-events: none;
  animation: level-up-float var(--levelup-text-dur, 0.9s) ease-out forwards;
  text-shadow: 0 0 8px #ffd700, 0 0 4px #fff, 1px 1px 0 #000;
  z-index: 10;
}

@keyframes level-up-float {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-28px); }
}

/* ---- Team bar reordering ---- */
.team-slot-reorder,
.team-drag-ghost {
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}
.team-slot-reorder .team-sprite,
.team-drag-ghost .team-sprite,
.team-drag-ghost img {
  -webkit-user-drag: none;
  user-drag: none;
  pointer-events: none;
}
.team-slot-dragging {
  opacity: 0.4;
}
.team-slot-dragover {
  outline: 2px solid #ffd700;
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
  background: rgba(255, 215, 0, 0.08);
}

/* ---- Achievement Toast ---- */
/* Event toasts — understated, low-contrast fade-in (was a large bright slide). */
.achievement-toast {
  position: fixed;
  bottom: calc(18px + var(--safe-bottom));
  right: calc(16px + var(--safe-right));
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #6a5e28;
  border-radius: 6px;
  padding: 7px 10px;
  z-index: 500;
  max-width: 230px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.achievement-toast.visible { opacity: 1; transform: none; }
.item-found-toast {
  position: fixed;
  bottom: calc(18px + var(--safe-bottom));
  left: calc(16px + var(--safe-left));
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #6a4452;
  border-radius: 6px;
  padding: 7px 10px;
  z-index: 500;
  max-width: 230px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.item-found-toast.visible { opacity: 1; transform: none; }
.item-toast-icon { font-size: 18px; opacity: 0.9; }
.item-toast-label {
  font-size: var(--text-xs);
  color: var(--text-dim);
  margin-bottom: 2px;
}
.item-found-toast .item-toast-name {
  font-size: var(--text-sm);
  line-height: 1.4;
  color: var(--text);
}
.ach-toast-icon { font-size: 18px; opacity: 0.9; }
.ach-toast-label {
  font-size: var(--text-xs);
  color: var(--text-dim);
  margin-bottom: 2px;
}
.ach-toast-name {
  font-size: var(--text-xs);
  color: var(--text);
}

/* ---- Shared game modal shell ---- */
.game-modal {
  position: fixed;
  inset: 0;
  background: var(--modal-backdrop);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(16px + var(--safe-top))
    calc(16px + var(--safe-right))
    calc(16px + var(--safe-bottom))
    calc(16px + var(--safe-left));
  box-sizing: border-box;
}
.game-modal--menu { z-index: 350; }
.game-modal--stacked { z-index: 301; }

.game-modal-box {
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #e8e4d8;
  border: 2px solid var(--outline);
  box-shadow: 3px 3px 0 0 var(--outline);
  color: var(--text-main);
}
.game-modal-box--menu     { max-width: 340px; }
.game-modal-box--settings { max-width: 400px; }
.game-modal-box--md      { max-width: 500px; }
.game-modal-box--lg      { max-width: 520px; }
.game-modal-box--detail  { max-width: 520px; max-height: 88vh; }
.game-modal-box--dex {
  max-width: 580px;
  height: 82vh;
  max-height: calc(100dvh - 32px - var(--safe-top) - var(--safe-bottom));
}

.game-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 2px solid var(--outline);
  flex-shrink: 0;
}
.game-modal-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.game-modal-title {
  color: var(--text-main);
  text-transform: uppercase;
}
.game-modal-desc {
  margin: 0;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-panel-muted);
}
.game-modal-body {
  overflow-y: auto;
  background: #e0dcd0;
  flex: 1;
  min-height: 0;
}
.game-modal-body--padded {
  padding: 14px 16px 16px;
}

.game-modal-header--ach { background: #389838; }
.game-modal-header--ach .game-modal-title { color: #fff; }
.game-modal-header--ach .game-modal-desc { color: #c8f0c8; }
.game-modal-header--menu { background: #2a2820; }
.game-modal-header--menu .game-modal-title { color: #fff; }
.game-modal-header--dex { background: #cc2222; }
.game-modal-header--dex .game-modal-title { color: #fff; }
.game-modal-header--dex .game-modal-desc { color: #ffc8c8; }
.game-modal-header--settings { background: #2e6eb5; }
.game-modal-header--settings .game-modal-title { color: #fff; }
.game-modal-header--hof { background: #C89821; }
.game-modal-header--hof .game-modal-title {
  color: #fff;
}
.game-modal-header--hof .game-modal-desc { color: rgba(255, 255, 255, 0.88); }
.game-modal-header--patch,
.game-modal-header--detail { background: #e8e4d8; }
.game-modal-header--cloud { background: #2898c8; }
.game-modal-header--cloud .game-modal-title { color: #fff; }
.game-modal-header--cloud .game-modal-desc { color: #c8e8f8; }
.game-modal-header--pc {
  background: linear-gradient(180deg, #3a5ccc 0%, #1e3a99 100%);
}
.game-modal-header--pc .game-modal-title {
  color: #fff;
  line-height: 1.5;
  text-transform: uppercase;
}
.game-modal-header--pc .game-modal-desc {
  color: #aaccff;
}

/* ---- Achievements Modal ---- */
.ach-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 6px;
  font-size: var(--text-sm);
  color: #7a6400;
  text-transform: uppercase;
  border-bottom: 2px solid var(--outline);
  background: #d8d4c8;
  position: sticky;
  top: 0;
  z-index: 1;
}
.ach-category-count {
  font-size: var(--text-xs);
  color: #806040;
  text-transform: none;
}
.ach-modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  padding: 12px 14px 14px;
  background: #e0dcd0;
}
.ach-card {
  background: #e0f0e0;
  border: 2px solid #58a858;
  padding: 10px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.ach-card.unlocked {
  border-color: #389838;
  background: #c8e8c8;
  box-shadow: inset 0 0 0 1px #389838;
}
.ach-card.locked { opacity: 0.45; }
.ach-icon {
  font-size: 22px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* PokeAPI sprite used as an achievement icon */
.ach-sprite {
  width: 48px;
  height: 48px;
  object-fit: contain;
  image-rendering: pixelated;
  vertical-align: middle;
}
.ach-card.locked .ach-sprite { opacity: 0.45; }
.ach-toast-icon .ach-sprite { width: 34px; height: 34px; }
.ach-name {
  font-size: var(--text-xs);
  color: var(--text-main);
  line-height: 1.5;
}
.ach-desc {
  font-size: var(--text-xs);
  color: var(--text-panel-muted);
  line-height: 1.4;
}
.ach-card.unlocked .ach-desc { color: var(--text-panel-muted); }

/* Small icon button for map header */
.btn-icon-sm {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.75;
  transition: opacity 0.1s, transform 0.1s;
}
.btn-icon-sm img {
  width: auto;
  /* The menu sprites are 22×22 — render 1:1. Any non-integer scale (the old
     24px here / 19px in the map bar) blurs them on iOS. */
  height: 22px;
  image-rendering: pixelated;
  display: block;
}
.btn-icon-sm.btn-icon-glyph {
  width: 28px;
  height: 28px;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
}
@media (hover: hover) {
  .btn-icon-sm:hover {
    opacity: 1;
    transform: scale(1.2);
  }
}

/* ---- Run menu sidebar ---- */
.run-menu-toggle {
  display: none;
  position: fixed;
  top: calc(var(--run-menu-toggle-inset) + var(--safe-top));
  left: calc(var(--run-menu-toggle-inset) + var(--safe-left));
  z-index: 35;
}
.run-menu-toggle-bars {
  display: block;
  width: 12px;
  height: 2px;
  background: currentColor;
  box-shadow: 0 -4px 0 currentColor, 0 4px 0 currentColor;
  flex-shrink: 0;
}
.run-menu-toggle.visible { display: none; }
@media (min-width: 769px) {
  .run-menu-toggle.visible {
    display: inline-flex;
    transition: left 0.2s ease, transform var(--btn-transition-duration) var(--btn-transition-ease);
  }
  body.run-menu-sidebar-open .run-menu-toggle.visible {
    left: calc(var(--run-menu-toggle-inset) + var(--safe-left) + var(--run-menu-width));
  }
  body.run-menu-active {
    transition: padding-left 0.2s ease;
  }
  body.run-menu-active.run-menu-sidebar-open {
    padding-left: var(--run-menu-width);
  }
  #run-menu-bar.visible {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    pointer-events: none;
  }
  body.run-menu-sidebar-open #run-menu-bar.visible {
    transform: translateX(0);
    pointer-events: auto;
  }
}

#run-menu-bar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: auto;
  z-index: 25;
  width: var(--run-menu-width);
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  background: var(--run-menu-sidebar-bg);
  border: none;
  box-shadow: none;
  padding:
    calc(var(--run-menu-pad) + var(--safe-top))
    var(--run-menu-pad)
    calc(var(--run-menu-pad) + var(--safe-bottom))
    calc(var(--run-menu-pad) + var(--safe-left));
  overflow: visible;
}
#run-menu-bar.visible { display: flex; }

.run-menu-sidebar {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
}
.run-menu-mobile-bar {
  display: none;
}

.run-menu-brand {
  flex-shrink: 0;
  margin: 0 0 var(--run-menu-gap);
  padding: 12px 8px;
  background: transparent;
  text-align: center;
}
.run-menu-logo {
  margin: 0;
  letter-spacing: 0.1em;
  line-height: 1.45;
  color: #ffd700;
  text-shadow: 1px 1px 0 #6a5010;
}

/* logo.png wordmark — replaces the "POKELIKE" text in the three brand spots.
   Pixel-art source (113×30), so render crisp and size per context by height. */
.game-logo img,
.history-select-logo img,
.run-menu-brand .run-menu-logo img {
  display: block;
  width: auto;
  image-rendering: pixelated;
}
.game-logo img { height: clamp(64px, 15vw, 128px); margin: 0 auto; }
.history-select-logo img { height: 18px; }
/* Sidebar wordmark — scale to the 172px rail width (minus padding). */
.run-menu-brand .run-menu-logo img { width: 100%; max-width: 140px; height: auto; margin: 0 auto; }

.run-menu-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--run-menu-gap);
  min-height: 0;
  padding: 0;
  overflow: visible;
}
.run-menu-group {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--run-menu-gap);
  flex-shrink: 0;
  padding: 0 0 2px;
}
.run-menu-group--main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 2px 2px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
.run-menu-group--main::-webkit-scrollbar {
  width: 5px;
}
.run-menu-group--main::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}
.run-menu-group--main::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 0;
}
.run-menu-group--main::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}
.run-menu-group--run {
  display: none;
  padding: 0 0 2px;
}
body.run-menu-in-run .run-menu-group--run {
  display: flex;
}
.run-menu-group--bottom {
  margin-top: auto;
  padding: var(--run-menu-gap) 0 2px;
  border-top: 1px solid var(--black-edge);
}

/* Credits modal — opened from the "Credits" menu entry (sidebar + mobile menu). */
.credits-modal-body { padding: 16px 18px 18px; }
.credits-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.credits-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}
.credits-role {
  font-size: var(--text-xs);
  color: var(--text-panel-muted);
  text-transform: uppercase;
}
.credits-name {
  font-size: var(--text-sm);
  color: var(--text-main);
}
.credits-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.credits-link:hover { color: var(--accent); }

/* Passive-item description window (opened by tapping a passive badge). */
.passive-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 18px;
  text-align: center;
}
.passive-info-icon img { width: 48px; height: 48px; image-rendering: pixelated; }
.passive-info-desc { font-size: var(--text-sm); line-height: 1.7; color: var(--text-main); }

.run-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 100%;
  max-width: none;
  min-width: 0;
  min-height: auto;
  margin: 0;
  white-space: normal;
  word-break: break-word;
  -webkit-tap-highlight-color: transparent;
}
#run-menu-bar .run-menu-btn.btn-primary:not([data-menu="discord"]),
#run-menu-bar a.run-menu-btn.btn-primary:not([data-menu="discord"]),
.run-menu-mobile-bar .run-menu-btn.btn-primary,
.history-select-back.run-menu-btn.btn-primary,
.history-select-logo.run-menu-btn.btn-primary,
.btn-run-panel.btn-primary,
.btn-run-panel.btn-secondary {
  --run-menu-btn-edge: var(--black-edge);
  background: var(--black);
  color: #fff;
  border: 2px solid var(--run-menu-btn-edge);
  box-shadow: 3px 3px 0 0 var(--run-menu-btn-edge);
}
@media (hover: hover) {
  #run-menu-bar .run-menu-btn.btn-primary:not([data-menu="discord"]):hover,
  #run-menu-bar a.run-menu-btn.btn-primary:not([data-menu="discord"]):hover,
  .run-menu-mobile-bar .run-menu-btn.btn-primary:hover,
  .history-select-back.run-menu-btn.btn-primary:hover,
  .btn-run-panel.btn-primary:hover:not(:disabled):not(:active),
  .btn-run-panel.btn-secondary:hover:not(:disabled):not(:active) {
    background: var(--black);
    color: #fff;
    border-color: var(--run-menu-btn-edge);
    box-shadow: 4px 4px 0 0 var(--run-menu-btn-edge);
    transform: translate(var(--btn-lift), var(--btn-lift));
  }
}
#run-menu-bar .run-menu-btn.btn-primary:not([data-menu="discord"]):active,
#run-menu-bar a.run-menu-btn.btn-primary:not([data-menu="discord"]):active,
.run-menu-mobile-bar .run-menu-btn.btn-primary:active,
.history-select-back.run-menu-btn.btn-primary:active,
.btn-run-panel.btn-primary:active:not(:disabled),
.btn-run-panel.btn-secondary:active:not(:disabled) {
  background: var(--black);
  color: #fff;
  border-color: var(--run-menu-btn-edge);
  box-shadow: 1px 1px 0 0 var(--run-menu-btn-edge);
  transform: translate(2px, 2px);
}
.run-menu-btn:focus {
  outline: none;
}
.run-menu-btn:focus-visible {
  outline: 2px solid #8a8070;
  outline-offset: 2px;
}
.run-menu-link {
  text-decoration: none;
  display: inline-flex;
}
#run-menu-bar [data-menu="discord"] {
  color: #fff;
  background: #5865f2;
  border-color: #4752c4;
  box-shadow: 3px 3px 0 0 #3c45a8;
}
@media (hover: hover) {
  #run-menu-bar [data-menu="discord"]:hover {
    color: #fff;
    background: #5865f2;
    border-color: #5865f2;
    box-shadow: 4px 4px 0 0 #3c45a8;
  }
}
#run-menu-bar [data-menu="discord"]:active {
  background: #5865f2;
  border-color: #3c45a8;
  box-shadow: 1px 1px 0 0 #3c45a8;
  transform: translate(2px, 2px);
}
#run-menu-bar .run-menu-btn--warn,
.run-menu-mobile-bar .run-menu-btn--warn,
[data-menu="account"].run-menu-btn--warn {
  --run-menu-btn-edge: #a07838;
  color: #fff !important;
  border-color: var(--run-menu-btn-edge) !important;
  box-shadow: 3px 3px 0 0 var(--run-menu-btn-edge) !important;
}
@media (hover: hover) {
  #run-menu-bar .run-menu-btn--warn:hover,
  .run-menu-mobile-bar .run-menu-btn--warn:hover {
    box-shadow: 4px 4px 0 0 var(--run-menu-btn-edge) !important;
  }
}
#run-menu-bar .run-menu-btn--warn:active,
.run-menu-mobile-bar .run-menu-btn--warn:active {
  box-shadow: 1px 1px 0 0 var(--run-menu-btn-edge) !important;
  transform: translate(var(--btn-push), var(--btn-push));
}

body.run-menu-active {
  --run-menu-offset: 0px;
}
body.run-menu-active .screen.active {
  padding-top: calc(16px + var(--safe-top));
  padding-right: calc(16px + var(--safe-right));
  padding-bottom: calc(16px + var(--safe-bottom));
  padding-left: calc(16px + var(--safe-left));
}
body.run-menu-active #title-screen.active {
  padding-bottom: calc(16px + var(--safe-bottom) + var(--run-menu-offset) + var(--title-legal-height) + 8px);
}

@media (max-width: 768px) {
  :root {
    --run-menu-width: 0px;
    --run-menu-height: 64px;
    --run-menu-pad: 11px;
    --run-menu-gap: 8px;
  }
  .run-menu-toggle,
  .run-menu-toggle.visible {
    display: none !important;
  }
  #run-menu-bar {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    flex-direction: column;
    padding: 0;
    border-top: 1px solid var(--black-edge);
  }
  .run-menu-sidebar {
    display: none !important;
  }
  .run-menu-mobile-bar {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    align-items: stretch;
    gap: var(--run-menu-gap);
    width: 100%;
    padding:
      8px
      calc(20px + var(--safe-right))
      calc(8px + var(--safe-bottom))
      calc(20px + var(--safe-left));
  }
  .run-menu-mobile-bar [data-menu="menu"] {
    grid-column: 1;
    justify-self: start;
    width: auto;
    max-width: 100%;
  }
  .run-menu-mobile-bar [data-menu="reset"] {
    grid-column: 2;
    justify-self: center;
    width: auto;
    max-width: 100%;
  }
  .run-menu-mobile-bar [data-menu="account"] {
    grid-column: 3;
    justify-self: end;
    width: auto;
    max-width: 100%;
  }
  .run-menu-mobile-bar .run-menu-btn {
    font-size: var(--text-xs);
    padding: 9px 8px;
    min-width: 0;
  }
  .run-menu-mobile-bar .run-menu-btn--account .run-menu-account-label {
    display: block;
    max-width: 108px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .run-menu-mobile-bar [data-menu="account"].cloud-loading .run-menu-account-label::before {
    content: none;
    animation: none;
  }
  body.run-menu-active {
    --run-menu-offset: var(--run-menu-height);
  }
  body.run-menu-active .screen.active {
    padding-left: calc(16px + var(--safe-left));
    padding-bottom: calc(16px + var(--safe-bottom) + var(--run-menu-height));
  }
  body.run-menu-active #title-screen.active {
    padding-bottom: calc(16px + var(--safe-bottom) + var(--run-menu-offset) + 8px);
  }
  body.run-menu-active #map-screen {
    padding-left: calc(6px + var(--safe-left));
    padding-bottom: calc(6px + var(--safe-bottom) + var(--run-menu-height));
  }
}

body.dark-mode #run-menu-bar {
  background: var(--run-menu-sidebar-bg);
}
body.dark-mode .run-menu-group--bottom {
  border-top-color: #141414;
}

/* ---- App menu modal ---- */
.app-menu-modal-list {
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  gap: 8px;
}
#app-menu-modal .app-menu-modal-item {
  width: 100%;
  max-width: none;
  text-align: center;
  font-size: var(--text-sm);
  padding: 10px 12px;
}
#app-menu-modal .run-menu-btn.btn-primary:not([data-menu="discord"]),
#app-menu-modal a.run-menu-btn.btn-primary:not([data-menu="discord"]) {
  background: #e8e4d8;
  color: var(--text-main);
  border: 2px solid var(--outline);
  box-shadow: 3px 3px 0 0 var(--outline);
}
@media (hover: hover) {
  #app-menu-modal .run-menu-btn.btn-primary:not([data-menu="discord"]):hover,
  #app-menu-modal a.run-menu-btn.btn-primary:not([data-menu="discord"]):hover {
    background: #e8e4d8;
    color: var(--text-main);
    border-color: var(--outline);
    box-shadow: 4px 4px 0 0 var(--outline);
  }
}
#app-menu-modal .run-menu-btn.btn-primary:not([data-menu="discord"]):active,
#app-menu-modal a.run-menu-btn.btn-primary:not([data-menu="discord"]):active {
  background: #e8e4d8;
  color: var(--text-main);
  border-color: var(--outline);
  box-shadow: 1px 1px 0 0 var(--outline);
  transform: translate(2px, 2px);
}
#app-menu-modal [data-menu="discord"] {
  color: #fff;
  background: #5865f2;
  border-color: #4752c4;
  box-shadow: 3px 3px 0 0 #3c45a8;
}
@media (hover: hover) {
  #app-menu-modal [data-menu="discord"]:hover {
    color: #fff;
    background: #5865f2;
    border-color: #5865f2;
    box-shadow: 4px 4px 0 0 #3c45a8;
  }
}
#app-menu-modal [data-menu="discord"]:active {
  background: #5865f2;
  border-color: #3c45a8;
  box-shadow: 1px 1px 0 0 #3c45a8;
  transform: translate(2px, 2px);
}
.app-menu-modal-legal {
  margin: 0;
  padding: 10px 14px 14px;
  border-top: 2px solid var(--outline);
  font-size: var(--text-xs);
  line-height: 1.6;
  text-align: center;
  color: var(--text-panel-muted);
}
body.dark-mode .game-modal-header--menu {
  background: var(--ink);
  border-bottom-color: var(--outline);
}
body.dark-mode .game-modal-header--menu .game-modal-title { color: #e0dcd0; }
body.dark-mode .app-menu-modal-body { background: #1e1c14; }
body.dark-mode #app-menu-modal .run-menu-btn.btn-primary:not([data-menu="discord"]),
body.dark-mode #app-menu-modal a.run-menu-btn.btn-primary:not([data-menu="discord"]) {
  background: #252118;
  color: #e0dcd0;
}
@media (hover: hover) {
  body.dark-mode #app-menu-modal .run-menu-btn.btn-primary:not([data-menu="discord"]):hover,
  body.dark-mode #app-menu-modal a.run-menu-btn.btn-primary:not([data-menu="discord"]):hover {
    background: #2e2820;
    color: #e0dcd0;
  }
}
body.dark-mode .app-menu-modal-legal {
  color: #706858;
}

@media (max-width: 768px) {
  .game-modal {
    padding:
      calc(8px + var(--safe-top))
      calc(8px + var(--safe-right))
      calc(8px + var(--safe-bottom))
      calc(8px + var(--safe-left));
  }
  .game-modal-box--dex,
  .game-modal-box--lg,
  .game-modal-box--md,
  .game-modal-box--settings {
    height: 70vh;
    max-height: calc(100dvh - 16px - var(--safe-top) - var(--safe-bottom));
  }
  #save-auth-modal .game-modal-box--settings {
    height: auto;
  }
  body.run-menu-active .game-modal-box--dex,
  body.run-menu-active .game-modal-box--lg,
  body.run-menu-active .game-modal-box--md,
  body.run-menu-active .game-modal-box--settings {
    max-height: calc(100dvh - 16px - var(--safe-top) - var(--safe-bottom) - var(--run-menu-height));
  }
  body.run-menu-active #save-auth-modal .game-modal-box--settings {
    height: auto;
  }
}
.dex-modal-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 2px solid var(--outline);
  background: #e0dcd0;
  flex-shrink: 0;
}
.dex-filter-bar {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  background: #dedad0;
  border-bottom: 2px solid var(--outline);
}
.dex-filter-btn {
  background: #e8e4d8;
  border: 2px solid var(--outline);
  box-shadow: var(--btn-edge-sm) var(--btn-edge-sm) 0 0 var(--outline);
  color: var(--text-panel-muted);
  cursor: pointer;
}
.dex-filter-btn:hover { border-color: #cc2222; color: var(--text-main); }
.dex-filter-btn.active {
  background: #f8e8e8;
  border-color: #cc2222;
  box-shadow: 2px 2px 0 0 #cc2222;
  color: #cc2222;
}
.dex-progress-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}
.dex-progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dex-progress-track {
  flex: 1;
  height: 26px;
  overflow: hidden;
  position: relative;
  border: 2px solid var(--outline);
  background: #d8d4c8;
}
.dex-progress-track--all {
  height: 26px;
}
.dex-progress-fill {
  height: 100%;
  width: 0;
  transition: width 0.3s;
}
.dex-progress-fill--gen1 {
  background: repeating-linear-gradient(60deg, #cc1111 0px, #cc1111 16px, #ee3333 16px, #ee3333 32px);
}
.dex-progress-fill--all {
  background: repeating-linear-gradient(60deg, #3344aa 0px, #3344aa 16px, #4455cc 16px, #4455cc 32px);
}
.dex-progress-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: bold;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}
.dex-charm-icon {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--outline);
  background: #e8e4d8;
  flex-shrink: 0;
  box-sizing: border-box;
}
.dex-charm-icon--active {
  border-color: #c8a800;
  box-shadow: 0 0 6px gold;
}
.dex-charm-icon-img {
  width: 20px;
  height: 20px;
  image-rendering: pixelated;
}
.dex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  align-content: start;
  gap: 6px;
  padding: 12px 14px 14px;
  overflow-y: auto;
  background: #e0dcd0;
  flex: 1 1 0;
  min-height: 0;
}
.dex-gen-header {
  grid-column: 1 / -1;
  font-size: var(--text-sm);
  color: #a01818;
  text-transform: uppercase;
  padding: 6px 4px 2px;
  border-bottom: 2px solid var(--outline);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.gen-count {
  color: #806040;
  font-size: var(--text-xs);
  text-transform: none;
}
.dex-card {
  background: #e8e4d8;
  border: 2px solid var(--outline);
  padding: 7px 5px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  box-sizing: border-box;
}
.dex-card.dex-caught {
  border-color: #cc2222;
  background: #f8e8e8;
}
.dex-num { font-size: var(--text-sm); color: #908c7c;}
.dex-sprite { width: 54px; height: 54px; image-rendering: pixelated; }
.dex-name {font-size: var(--text-xs); color: var(--text-main); }
.dex-types { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; margin-top: 2px; }
.dex-types .type-badge { font-size: var(--text-xs); padding: 1px 4px; }
.dex-caught-badge { font-size: var(--text-sm); color: #cc2222; margin-top: 2px; }
.dex-empty { color: #908c7c; font-size: var(--text-xs); text-align: center; padding: 40px; grid-column: 1/-1; }
.dex-silhouette { filter: brightness(0); }
.dex-unknown-name { color: #b0aca0; }
.dex-unknown { opacity: 0.6; }
.dex-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.dex-tab-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.dex-tab-row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
}
#dex-search-input {
  width: min(148px, 42vw);
  min-width: 0;
}
.dex-hide-caught-btn {
  white-space: nowrap;
}
.dex-tab-row .dex-hide-caught-btn:hover { color: var(--text-main); }
.dex-tab-row .dex-hide-caught-btn.active {
  background: #f8e8e8;
  border-color: #cc2222;
  box-shadow: 2px 2px 0 0 #cc2222;
  color: #cc2222;
}
.shiny-dex-box .dex-tab-row .dex-hide-caught-btn.active {
  background: #fff8d0;
  border-color: #c8a800;
  box-shadow: 2px 2px 0 0 #c8a800;
  color: #8a6000;
}
.dex-toolbar-sep {
  border-top: 2px solid var(--outline);
  margin: 2px 0;
}
.dex-gen-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}
.dex-gen-filter-btn {
  color: var(--text-panel-muted);
  flex-shrink: 0;
}
.dex-gen-filter-btn:hover { border-color: #cc2222; color: var(--text-main); }
.dex-gen-filter-btn.active {
  background: #f8e8e8;
  border-color: #cc2222;
  box-shadow: 2px 2px 0 0 #cc2222;
  color: #cc2222;
}
.shiny-dex-box .dex-gen-filter-btn.active {
  background: #fff8d0;
  border-color: #c8a800;
  box-shadow: 2px 2px 0 0 #c8a800;
  color: #8a6000;
}
.dex-tab:hover { color: var(--text-main); }
.dex-tab.active {
  background: #f8e8e8;
  border-color: #cc2222;
  box-shadow: 2px 2px 0 0 #cc2222;
  color: #cc2222;
}
.dex-tab[data-tab="shiny"].active {
  background: #fff8d0;
  border-color: #c8a800;
  box-shadow: 2px 2px 0 0 #c8a800;
  color: #8a6000;
}
.shiny-dex-box .dex-gen-header { color: #8a6000; }
.shiny-dex-card {
  border-color: #c8a800;
  background: #fff8d0;
  position: relative;
}

/* ---- Pokédex Detail Modal ---- */
.dex-detail-body {
  overflow-y: auto;
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #e0dcd0;
  flex: 1;
  min-height: 0;
}
.dex-detail-top {
  display: flex;
  gap: 18px;
  align-items: flex-start;
}
.dex-detail-sprite-wrap {
  position: relative;
  flex-shrink: 0;
}
.dex-detail-sprite {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  display: block;
}
.dex-detail-shiny-btn {
  position: absolute;
  bottom: 2px;
  right: 2px;
  color: var(--text-panel-muted);
}
.dex-detail-shiny-btn--active {
  color: #c89820;
  text-shadow: 0 0 6px gold;
  border-color: #c8a800;
  background: #fff8d0;
}
.dex-detail-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
.dex-detail-name {
  font-size: var(--text-sm);
  color: var(--text-main);
}
.dex-detail-num {
  font-size: var(--text-xs);
  color: #908c7c;
}
.dex-detail-types {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.dex-detail-flavor {
  font-size: var(--text-xs);
  color: var(--text-panel-muted);
  font-style: italic;
  line-height: 1.5;
  margin-top: 4px;
}
.dex-detail-section-title {
  color: #a01818;
  text-transform: uppercase;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--outline);
}
.dex-detail-evo {
  overflow-x: auto;
  padding: 4px;
}
.dex-evo-forward {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
}
.dex-evo-node {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.dex-evo-sprite {
  width: 54px;
  height: 54px;
  image-rendering: pixelated;
}
.dex-evo-node--current > .dex-evo-sprite {
  outline: 2px solid #c89820;
  outline-offset: 1px;
}
.dex-evo-name {
  font-size: var(--text-xs);
  color: var(--text-panel-muted);
  text-align: center;
  max-width: 60px;
  word-break: break-word;
}
.dex-evo-node--current > .dex-evo-name {
  color: #c89820;
}
.dex-evo-arrow-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.dex-evo-arrow {
  color: #a01818;
  font-size: var(--text-xs);
  line-height: 1;
}
.dex-evo-level {
  font-size: var(--text-xs);
  color: #908c7c;
  white-space: nowrap;
}
.dex-evo-children {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dex-evo-branch {
  flex-wrap: wrap;
  flex-direction: row;
  align-items: flex-start;
}
.dex-detail-locations {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dex-detail-loc-group {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  flex-wrap: wrap;
}
.dex-detail-loc-label {
  font-size: var(--text-xs);
  color: var(--text-panel-muted);
  flex-shrink: 0;
  padding-top: 3px;
}
.dex-detail-loc-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.dex-detail-loc-tag {
  background: #f8e8e8;
  border: 1px solid #cc2222;
  color: #a01818;
  font-size: var(--text-xs);
  padding: 2px 6px;
}
.dex-detail-loc-tag--tower {
  background: #e8ecf8;
  border-color: #3344aa;
  color: #223388;
}
.dex-detail-loc-none {
  font-size: var(--text-xs);
  color: #908c7c;
  /* No italic: it shifted the baseline and made "Not available" / "Not found"
     jump up out of line with regular location text. Match the label's top
     padding so it sits on the same line. */
  padding-top: 3px;
}
.dex-card.dex-caught:hover,
.dex-card.shiny-dex-card:hover,
.dex-card.dex-unknown:hover {
  cursor: pointer;
  border-color: var(--outline);
  box-shadow: 2px 2px 0 0 var(--outline);
}
.pc-box .dex-card.pc-dex-card--shiny:hover,
.pc-box .dex-card.pc-dex-card--shiny:focus {
  background: #334875;
  border-color: #94B0DD;
  box-shadow: 2px 2px 0 0 #94B0DD;
}

/* ---- Patch Notes Modal ---- */
.patch-note-block {
  margin-bottom: 20px;
}
.patch-note-block:last-child {
  margin-bottom: 0;
}
.patch-note-version-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--outline);
}
.patch-note-version {
  font-size: var(--text-lg);
  color: #c89820;
}
.patch-note-title {
  font-size: var(--text-xl);
  color: var(--text-main);
  flex: 1;
  min-width: 0;
}
.patch-note-date {
  font-size: var(--text-xs);
  color: #908c7c;
  margin-left: auto;
}
.patch-note-section {
  margin-bottom: 12px;
}
.patch-note-section:last-child {
  margin-bottom: 0;
}
.patch-note-section-heading {
  color: #7a6400;
  margin-bottom: 6px;
  text-transform: uppercase;
}
.patch-note-list {
  margin: 0;
  padding-left: 16px;
  list-style: disc;
}
.patch-note-entry {
  font-size: var(--text-base);
  color: var(--text-panel-muted);
  margin-bottom: 4px;
  line-height: 1.6;
}
.patch-note-entry:last-child {
  margin-bottom: 0;
}

/* ---- Hall of Fame Modal ---- */
.hof-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 2px solid var(--outline);
  background: #e0dcd0;
  flex-shrink: 0;
}
.hof-filter-chip {
  color: var(--text-panel-muted);
}
.hof-filter-chip.active {
  background: #f0e8c0;
  border-color: #c89820;
  box-shadow: 2px 2px 0 0 #c89820;
  color: var(--text-main);
}
/* Second-level (sub) filter rows: visually subordinate to the main tabs. Each
   facet (e.g. Story difficulty, region) is its own single-select row. */
.hof-subfilter-bar {
  flex-direction: column;
  align-items: flex-start;
  padding: 8px 14px;
  background: #ece8dc;
  border-bottom-width: 1px;
}
.hof-subfilter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.hof-subfilter-chip {
  color: var(--text-panel-muted);
}
.hof-subfilter-chip.active {
  background: #f0e8c0;
  border-color: #c89820;
  box-shadow: 2px 2px 0 0 #c89820;
  color: var(--text-main);
}
.hof-empty {
  margin: 0;
  text-align: center;
  padding: 24px 8px;
  font-size: var(--text-xs);
  line-height: 1.8;
  color: var(--text-panel-muted);
}
.hof-entry-card {
  background: #e8e4d8;
  border: 2px solid var(--outline);
  padding: 12px;
  margin-bottom: 10px;
}
.hof-entry-card:last-child {
  margin-bottom: 0;
}
.hof-entry-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--outline);
}
.hof-entry-title {
  font-size: var(--text-sm);
  color: #c89820;
  line-height: 1.5;
}
.hof-entry-date {
  font-size: var(--text-xs);
  color: #908c7c;
  flex-shrink: 0;
}
.hof-entry-team {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.hof-pokemon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.hof-pokemon-sprite {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
}
.hof-pokemon--shiny .hof-pokemon-sprite {
  filter: drop-shadow(0 0 4px gold);
}
.hof-pokemon-name {
  font-size: var(--text-xs);
  color: var(--text-panel-muted);
  text-align: center;
  line-height: 1.4;
}
.hof-pokemon--shiny .hof-pokemon-name {
  color: #c89820;
}
.hof-pokemon-lv {
  font-size: var(--text-xs);
  color: #908c7c;
}
.hof-pokemon-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.settings-section-title {
  color: #2e6eb5;
  padding: 10px 14px 6px;
  text-transform: uppercase;
  background: #d8d4c8;
  border-bottom: 2px solid var(--outline);
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 2px solid var(--outline);
  cursor: pointer;
  transition: background 0.12s;
  background: #e8e4d8;
}
.settings-row:last-child { border-bottom: none; }
.settings-row:hover { background: #dedad0; }
.settings-row-disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }
.settings-label {
  font-size: var(--text-sm);
  color: var(--text-main);
  line-height: 1.5;
}
.settings-volume {
  flex: 1;
  max-width: 120px;
  accent-color: var(--checkbox-accent);
  cursor: pointer;
}
.pixel-checkbox,
.settings-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  flex-shrink: 0;
  cursor: pointer;
  box-sizing: border-box;
  background: #e8e4d8;
  border: 2px solid var(--outline);
  box-shadow: 2px 2px 0 0 var(--outline);
  transition: var(--btn-transition);
  backface-visibility: hidden;
  transform: translate(0, 0);
}
@media (hover: hover) {
  .settings-row:not(.settings-row-disabled) .settings-checkbox:hover,
  .pixel-checkbox:hover:not(:disabled) {
    box-shadow: 3px 3px 0 0 var(--outline);
  }
}
.pixel-checkbox:active:not(:disabled),
.settings-checkbox:active:not(:disabled) {
  box-shadow: 1px 1px 0 0 var(--outline);
  transform: translate(1px, 1px);
}
.pixel-checkbox:checked,
.settings-checkbox:checked {
  background: var(--checkbox-accent);
}
.pixel-checkbox:checked:active:not(:disabled),
.settings-checkbox:checked:active:not(:disabled) {
  box-shadow: 1px 1px 0 0 var(--outline);
}
.pixel-checkbox:focus-visible,
.settings-checkbox:focus-visible {
  outline: 2px solid #8a8070;
  outline-offset: 2px;
}
.pixel-checkbox:disabled,
.settings-checkbox:disabled {
  cursor: not-allowed;
}

#save-auth-modal .game-modal-box {
  height: auto;
}
#save-auth-modal .game-modal-body {
  flex: 0 0 auto;
}
.cloud-auth-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#save-auth-modal input[type="text"],
#save-auth-modal input[type="password"] {
  width: 100%;
}
.cloud-auth-error {
  font-size: var(--text-xs);
  line-height: 1.6;
  color: #cc2222;
  display: none;
}
.cloud-auth-actions {
  display: flex;
  gap: 8px;
}
.cloud-auth-actions .btn-primary { flex: 1; }
#save-auth-modal .btn-primary {
  border-color: var(--outline);
  box-shadow: 3px 3px 0 0 var(--outline);
}
@media (hover: hover) {
  #save-auth-modal .btn-primary:hover { box-shadow: 4px 4px 0 0 var(--outline); }
}
#save-auth-modal .btn-primary:active { box-shadow: 1px 1px 0 0 var(--outline); }
#save-auth-modal .btn-primary:disabled { box-shadow: 3px 3px 0 0 var(--outline); }
.cloud-auth-status {
  font-size: var(--text-xs);
  line-height: 1.6;
  color: var(--text-panel-muted);
  margin: 0;
}
.cloud-auth-status--warn { color: #906818; }

/* =================================================
   RETRO PIXEL STYLE — pure CSS, no 9-slice
   ================================================= */

/* Strip ALL border-radius site-wide */
* { border-radius: 0 !important; }

/* Exception: elements that must stay circular */
.badge-icon-empty,
.legend-dot { border-radius: 99px !important; }

/* ---- Button sizes (sm = pokedex gen, md = sidebar) ---- */
button,
a.run-menu-btn,
.btn-primary,
.btn-secondary {
  text-transform: uppercase;
}

.title-mode-card-body,
.title-mode-card-title,
.title-mode-card-desc {
  text-transform: none;
}

.btn-sm {
  font-size: var(--btn-font-sm);
  line-height: 1.45;
  padding: var(--btn-py-sm) var(--btn-px-sm);
  box-sizing: border-box;
}

.btn-md.hof-sort-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-sm.dex-detail-shiny-btn {
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  padding: 0;
  line-height: 1;
}

.btn-md {
  font-size: var(--btn-font-md);
  line-height: calc(var(--control-md-height) - 4px);
  height: var(--control-md-height);
  min-height: var(--control-md-height);
  padding: 0 var(--btn-px-md);
  box-sizing: border-box;
}

.btn-lg {
  font-size: var(--btn-font-lg);
  line-height: calc(var(--control-lg-height) - 4px);
  height: var(--control-lg-height);
  min-height: var(--control-lg-height);
  padding: 0 var(--btn-px-lg);
  box-sizing: border-box;
}

.btn-icon {
  width: var(--control-md-height);
  min-width: var(--control-md-height);
  padding: 0;
  font-size: var(--text-lg);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-icon-close {
  font-size: 0;
}

.btn-close-glyph {
  position: relative;
  width: 11px;
  height: 11px;
  flex-shrink: 0;
}

.btn-close-glyph::before,
.btn-close-glyph::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 13px;
  height: 2px;
  background: currentColor;
  transform-origin: center;
}

.btn-close-glyph::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.btn-close-glyph::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

/* ---- Buttons (variants) ---- */
.btn-primary {
  background: #e8e4d8;
  border: 2px solid var(--outline);
  box-shadow: var(--btn-edge-md) var(--btn-edge-md) 0 0 var(--outline);
  color: var(--text-main);
  cursor: pointer;
}
@media (hover: hover) {
  .btn-primary:hover  { box-shadow: 4px 4px 0 0 var(--outline); }
}
.btn-primary:active { box-shadow: 1px 1px 0 0 var(--outline); transform: translate(2px, 2px); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: var(--btn-edge-md) var(--btn-edge-md) 0 0 var(--outline); transform: none; }

.btn-primary.btn-lg {
  box-shadow: var(--btn-edge-lg) var(--btn-edge-lg) 0 0 var(--outline);
}
@media (hover: hover) {
  .btn-primary.btn-lg:hover { box-shadow: 5px 5px 0 0 var(--outline); }
}
.btn-primary.btn-lg:active { box-shadow: 1px 1px 0 0 var(--outline); transform: translate(2px, 2px); }
.btn-primary.btn-lg:disabled { box-shadow: var(--btn-edge-lg) var(--btn-edge-lg) 0 0 var(--outline); }

.btn-secondary {
  background: var(--black);
  border: 2px solid var(--black-edge);
  box-shadow: var(--btn-edge-sm) var(--btn-edge-sm) 0 0 var(--black-edge);
  color: var(--text-dim);
  cursor: pointer;
}
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-secondary:hover {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 3px 3px 0 0 var(--black-edge);
}

.title-mode-card,
.history-region-btn,
.hof-sort-btn,
.btn-primary,
.btn-secondary {
  transition: var(--btn-transition);
  backface-visibility: hidden;
  transform: translate(0, 0);
}

@media (hover: hover) {
  .btn-primary:hover:not(:disabled):not(:active),
  .btn-secondary:hover:not(:disabled):not(:active),
  .run-menu-btn:hover:not(:disabled):not(:active),
  .run-menu-toggle:hover:not(:active),
  .history-mode-btn:hover:not(:disabled):not(:active),
  .history-battle-tower-btn:hover:not(:disabled):not(:active),
  .title-mode-card:hover:not(:disabled):not(:active),
  #btn-auto-battle:hover:not(:disabled):not(:active),
  #btn-continue-battle:hover:not(:disabled):not(:active),
  #app-menu-modal .run-menu-btn:hover:not(:disabled):not(:active),
  #app-menu-modal a.run-menu-btn:hover:not(:disabled):not(:active),
  .hof-sort-btn:hover:not(:disabled):not(:active) {
    transform: translate(var(--btn-lift), var(--btn-lift));
  }
  .history-region-btn--locked:hover,
  .history-more-regions--locked .history-battle-tower-btn:hover {
    transform: none;
  }
}

.btn-secondary:active:not(:disabled) {
  transform: translate(var(--btn-push), var(--btn-push));
  box-shadow: 1px 1px 0 0 var(--black-edge);
}

.btn-block { width: 100%; }
.btn-block--gap { margin-top: 8px; }
.btn-block--gap-sm { margin-top: 6px; }
.btn-block--gap-lg { margin-top: 12px; }
.btn-block--stack { margin-bottom: 10px; }
.item-equip-box > .btn-secondary.btn-block--gap + .btn-secondary.btn-block { margin-top: 4px; }
.btn-secondary--purple { border-color: #c8a0ff; color: #c8a0ff; }
.btn-secondary--gold { border-color: #ffd700; color: #ffd700; }

.title-mode-cards {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 18px;
  width: 100%;
  max-width: 760px;
}
/* Each mode is a column: the card on top, its Resume button below it. */
.title-mode-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
@media (max-width: 600px) {
  /* Story + Battle Tower side by side; Challenges wraps below them, centered
     and at the same card size (not stretched full-width). */
  .title-mode-cards {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 100%;
    padding: 0 12px;
    gap: 12px;
  }
  .title-mode-col {
    flex: 0 0 calc(50% - 6px);
    min-width: 0;
  }
  /* Long single-word titles ("Challenges", longer in DE/FR) can still outgrow
     a half-width column on small phones — scale the font with the viewport. */
  .title-mode-card-title {
    font-size: clamp(9px, 3.4vw, var(--text-2xl));
  }
  .title-mode-card-action {
    padding: 6px 4px;
  }
}
.title-mode-card {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  min-width: 0;
  width: 100%;
  margin: 0;
  padding: 0;
  font: inherit;
  text-align: inherit;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  gap: 6px;
  background: transparent;
  border: none;
  box-shadow: none;
  overflow: visible;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) {
  .title-mode-card:hover:not(:disabled):not(:active) .title-mode-card-figure {
    box-shadow: 4px 4px 0 0 var(--outline);
  }
}
.title-mode-card:active:not(:disabled) .title-mode-card-figure {
  box-shadow: 1px 1px 0 0 var(--outline);
  transform: translate(var(--btn-push), var(--btn-push));
}
.title-mode-card:disabled {
  cursor: not-allowed;
}
.title-mode-card-body {
  display: block;
  flex: 1;
  padding: 12px 10px;
  text-align: center;
}
/* Title sits above a square scene image; the colored action bar is overlaid
   on the bottom of the image as the CTA. */
.title-mode-card-figure {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: #e8e4d8;
  border: 2px solid var(--outline);
  box-shadow: 3px 3px 0 0 var(--outline);
}
.title-mode-card-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  filter: saturate(1.2);
}
.title-mode-card-title {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  /* Reserve two lines and bottom-align the text so a single-line title ("Story")
     sits right above its figure, exactly like a wrapped two-line title
     ("Battle Tower") — keeping both figures, and their action bars, aligned. */
  min-height: 2.9em;
  font-size: var(--text-2xl);
  line-height: 1.3;
  margin: 0;
  padding: 2px 8px 4px;
  text-align: center;
  background: transparent;
  text-shadow: none;
}
.title-mode-card--story .title-mode-card-title {
  color: #1f8f3a;
}
.title-mode-card--tower .title-mode-card-title {
  color: #1a66e0;
}
.title-mode-card--challenge .title-mode-card-title {
  color: #c43a2e;
}
.title-mode-card-desc {
  display: block;
  color: #2a2820;
  line-height: 1.5;
  margin: 0;
}
.title-mode-card-action {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px 14px;
  border-top: 2px solid var(--outline);
  background: var(--ink);
  color: #e8e4d8;
  font-size: var(--text-sm);
  text-align: center;
}
.title-mode-card--story .title-mode-card-action {
  background: #1f8f3a;
  color: #fff;
}
.title-mode-card--story:hover:not(:disabled) .title-mode-card-action {
  background: #25a847;
}
.title-mode-card--story:active:not(:disabled) .title-mode-card-action {
  background: #176e2c;
}
.title-mode-card--tower .title-mode-card-action {
  background: #1a66e0;
  color: #fff;
}
.title-mode-card--tower:hover:not(:disabled) .title-mode-card-action {
  background: #2a72e8;
}
.title-mode-card--tower:active:not(:disabled) .title-mode-card-action {
  background: #104898;
}
.title-mode-card--challenge .title-mode-card-action {
  background: #c43a2e;
  color: #fff;
}
.title-mode-card--challenge:hover:not(:disabled) .title-mode-card-action {
  background: #d4483b;
}
.title-mode-card--challenge:active:not(:disabled) .title-mode-card-action {
  background: #9a2a20;
}
/* Resume button under each mode card — themed to match the mode's action bar. */
.title-mode-resume {
  display: block;
  width: 100%;
  margin: 0;
  padding: 9px 12px;
  font: inherit;
  font-size: var(--text-sm);
  text-transform: uppercase;
  text-align: center;
  color: #fff;
  border: 2px solid var(--outline);
  box-shadow: 3px 3px 0 0 var(--outline);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.title-mode-resume--story { background: #1f8f3a; }
.title-mode-resume--tower { background: #1a66e0; }
.title-mode-resume--challenge { background: #c43a2e; }
@media (hover: hover) {
  .title-mode-resume--story:hover { background: #25a847; box-shadow: 4px 4px 0 0 var(--outline); }
  .title-mode-resume--tower:hover { background: #2a72e8; box-shadow: 4px 4px 0 0 var(--outline); }
  .title-mode-resume--challenge:hover { background: #d4483b; box-shadow: 4px 4px 0 0 var(--outline); }
}
.title-mode-resume:active {
  box-shadow: 1px 1px 0 0 var(--outline);
  transform: translate(2px, 2px);
}
.title-mode-card--locked {
  position: relative;
  opacity: 0.5;
}
.title-mode-card--locked:disabled {
  opacity: 0.5;
}
.title-mode-card-lock {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  cursor: not-allowed;
  pointer-events: auto;
}
.title-mode-card-lock img {
  height: 36px;
  width: auto;
  image-rendering: pixelated;
}

#history-region-select,
#endless-stage-select {
  align-items: center;
}
/* Per-mode header colors (h1-prefixed to beat the base h1.history-header-title). */
h1.history-header-title--story { color: #1f8f3a; }
h1.history-header-title--tower { color: #1a66e0; }
h1.history-header-title--challenge { color: #c43a2e; }
.history-select-panel {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.history-select-topbar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}
.history-select-back {
  flex-shrink: 0;
  width: auto;
}
.history-select-logo {
  flex: 1;
  min-width: 0;
  pointer-events: none;
  cursor: default;
}
.history-header {
  width: 100%;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: #e8e4d8;
  border: 2px solid var(--outline);
  box-shadow: 3px 3px 0 0 var(--outline);
  box-sizing: border-box;
}
.history-header-text {
  min-width: 0;
}
.history-header-title {
  color: #1a66e0;
  line-height: 1.5;
  margin: 0 0 8px;
}
.history-header-intro,
.history-header-lead {
  color: #2a2820;
  line-height: 1.5;
  margin: 0 0 6px;
}
.history-header-text > :last-child {
  margin-bottom: 0;
}
.history-header-desc {
  color: #3a3428;
  line-height: 1.5;
  margin: 0;
}
.history-mode-toggle-wrap {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.history-mode-btn {
  flex: 1;
  opacity: 1;
}
.history-mode-btn:not(.history-mode-btn--selected) {
  background: #d4d0c4;
  border-color: var(--outline);
  box-shadow: 3px 3px 0 0 var(--outline);
  color: #6a6860;
}
.history-mode-btn--selected.history-mode-btn--classic {
  background: #e8e4d8;
  border-color: #1a66e0;
  box-shadow: 3px 3px 0 0 #1a66e0;
  color: #1a66e0;
}
.history-mode-btn--selected.history-mode-btn--classic:hover { box-shadow: 4px 4px 0 0 #1a66e0; }
.history-mode-btn--selected.history-mode-btn--classic:active { box-shadow: 1px 1px 0 0 #1a66e0; transform: translate(2px, 2px); }
.history-mode-btn--selected.history-mode-btn--nuzlocke {
  background: #e8e4d8;
  border-color: #bb1a1a;
  box-shadow: 3px 3px 0 0 #bb1a1a;
  color: #bb1a1a;
}
.history-mode-btn--selected.history-mode-btn--nuzlocke:hover { box-shadow: 4px 4px 0 0 #bb1a1a; }
.history-mode-btn--selected.history-mode-btn--nuzlocke:active { box-shadow: 1px 1px 0 0 #bb1a1a; transform: translate(2px, 2px); }
.history-region-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.history-more-regions {
  position: relative;
  width: 100%;
  margin-top: 12px;
  padding: 12px 14px;
  background: #e8e4d8;
  border: 2px solid var(--outline);
  box-shadow: 3px 3px 0 0 var(--outline);
  text-align: center;
  color: var(--text-main);
  overflow: hidden;
}
.history-more-regions--locked {
  opacity: 0.5;
}
.history-more-regions-lock {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  cursor: not-allowed;
  pointer-events: auto;
}
.history-more-regions-lock img {
  height: 36px;
  width: auto;
  image-rendering: pixelated;
}
.history-more-regions--locked .history-battle-tower-btn:disabled {
  opacity: 1;
  cursor: not-allowed;
}
.history-more-regions--locked .history-battle-tower-btn:hover,
.history-more-regions--locked .history-battle-tower-btn:active {
  box-shadow: 3px 3px 0 0 #7a5ac8;
  transform: none;
}
.history-more-regions-text {
  font-size: var(--text-sm);
  color: #2a2820;
  line-height: 1.45;
  margin: 0 0 10px;
}
.history-battle-tower-btn {
  width: 100%;
  background: #6238bb;
  border-color: #7a5ac8;
  box-shadow: 3px 3px 0 0 #7a5ac8;
  color: #fff;
}
.history-battle-tower-btn:hover { box-shadow: 4px 4px 0 0 #7a5ac8; }
.history-battle-tower-btn:active { box-shadow: 1px 1px 0 0 #7a5ac8; transform: translate(2px, 2px); }
.history-region-btn {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: stretch;
  width: 100%;
  min-height: 88px;
  padding: 0;
  overflow: hidden;
  text-align: left;
  background: #e8e4d8;
  border: 2px solid var(--outline);
  box-shadow: var(--btn-edge-md) var(--btn-edge-md) 0 0 var(--outline);
  cursor: pointer;
  color: var(--text-main);
  text-transform: none;
}
@media (hover: hover) {
  .history-region-btn:not(.history-region-btn--locked):hover {
    box-shadow: 4px 4px 0 0 var(--outline);
    transform: translate(var(--btn-lift), var(--btn-lift));
  }
}
/* Nuzlocke selected — give the region cards a red treatment so the mode reads at
   a glance. */
.history-region-list--nuz .history-region-btn:not(.history-region-btn--locked) {
  border-color: #b32020;
  box-shadow: var(--btn-edge-md) var(--btn-edge-md) 0 0 #7a1414;
}
@media (hover: hover) {
  .history-region-list--nuz .history-region-btn:not(.history-region-btn--locked):hover {
    box-shadow: 4px 4px 0 0 #7a1414;
  }
}
.history-region-btn:not(.history-region-btn--locked):active {
  box-shadow: 1px 1px 0 0 var(--outline);
  transform: translate(var(--btn-push), var(--btn-push));
}
.history-region-btn--locked {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}
.history-region-btn--locked:hover,
.history-region-btn--locked:active {
  box-shadow: var(--btn-edge-md) var(--btn-edge-md) 0 0 var(--outline);
  transform: none;
}
.history-region-btn:focus-visible {
  outline: 2px solid #8a8070;
  outline-offset: 2px;
}
.history-region-lock {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  cursor: not-allowed;
  pointer-events: auto;
}
.history-region-lock img {
  height: 36px;
  width: auto;
  image-rendering: pixelated;
}
.history-region-visual {
  position: relative;
  overflow: hidden;
  min-height: 88px;
  height: 100%;
}
.history-region-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: saturate(1.2);
}
.history-region-label-drop {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: rgba(0, 0, 0, 0.12);
  padding: 8px 10px;
  box-sizing: border-box;
}
.history-region-name {
  font-size: var(--text-3xl);
  color: #fff;
  line-height: 1.3;
  text-transform: uppercase;
  text-shadow: 0 1px 0 #000, 0 2px 4px #000, 0 0 8px #000;
}
.history-region-gens {
  font-size: var(--text-lg);
  color: #fff;
  opacity: 0.95;
  margin-top: 4px;
  text-transform: uppercase;
  text-shadow: 0 1px 0 #000, 0 1px 3px #000, 0 0 6px #000;
}
.history-region-stats {
  background: #e8e4d8;
  border-left: 2px solid var(--outline);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  color: var(--text-main);
  min-height: 88px;
}
.history-region-stat-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: var(--text-sm);
  line-height: 1.3;
}
.history-region-stat-row span:first-child {
  color: #3a3428;
}
.history-region-stat-row span:last-child {
  color: #100e0c;
  font-weight: bold;
  flex-shrink: 0;
}
/* ---- Light panel base colour ---- */
/* Warm off-white, like a GBA LCD menu box */

/* ---- Cards ---- */
.poke-card,
.trainer-card,
.item-card {
  background: #e8e4d8;
  border: 2px solid var(--outline);
  box-shadow: 3px 3px 0 0 var(--outline);
  color: var(--text-main);
}
/* Dark text inside cards */
.poke-name,
.trainer-label,
.item-name            { font-size: var(--text-lg); color: var(--text-main); }
.poke-level,
.poke-stats,
.item-desc            { color: var(--text-panel-muted); }
.move-name            { color: var(--text-main); -webkit-text-stroke: 1px rgba(0,0,0,0.15); }
.move-power-badge     { background: rgba(0,0,0,0.07); color: var(--text-panel-muted); }
.move-desc            { color: var(--text-panel-muted); }
.poke-move            { border-color: var(--outline); }
.poke-card[role="button"]:hover,
.poke-card[tabindex]:hover { border-color: var(--outline); box-shadow: 4px 4px 0 0 var(--outline); }
.poke-card.selected   { border-color: #c8a000; box-shadow: 3px 3px 0 0 var(--outline); }
.item-card:hover      { border-color: var(--outline); box-shadow: 4px 4px 0 0 var(--outline); }
.trainer-card:hover,
.trainer-card:focus   { border-color: var(--outline); box-shadow: 4px 4px 0 0 var(--outline); }

/* ---- HUD panels ---- */
.hud-box,
.map-header {
  background: #e8e4d8;
  border: 2px solid var(--outline);
  box-shadow: 3px 3px 0 0 var(--outline);
  color: var(--text-main);
}
.hud-label            { color: var(--text-panel-muted); }
.team-slot-name       { color: var(--text-panel-muted); }
.team-slot-lv         { color: #8a6000; }
#map-info             { color: #8a6000 !important; }
.badge-icon-empty     { border-color: var(--outline); }

/* Item badges in HUD */
.item-badge {
  background: #d8d4c8;
  border: 1px solid var(--outline);
  color: var(--text-main);
}

/* Run mode: lighter HUD text only */
body.run-menu-in-run #map-screen .hud-label,
body.run-menu-in-run #map-screen .map-badges-label,
body.run-menu-in-run #map-screen .team-slot-name,
body.run-menu-in-run #map-screen .trait-count,
body.run-menu-in-run #map-screen .trait-desc,
body.run-menu-in-run #map-screen .region-stage-name,
body.run-menu-in-run #map-screen .region-stage-level,
body.run-menu-in-run #catch-screen .team-slot-name {
  color: #8a8070;
}
body.run-menu-in-run #map-screen .team-slot-lv,
body.run-menu-in-run #map-screen #map-info,
body.run-menu-in-run #catch-screen .team-slot-lv {
  color: #c8a800 !important;
}
body.run-menu-in-run #map-screen .item-badge {
  color: #6a6658;
}

body.dark-mode.run-menu-in-run #map-screen .hud-label,
body.dark-mode.run-menu-in-run #map-screen .map-badges-label,
body.dark-mode.run-menu-in-run #map-screen .team-slot-name,
body.dark-mode.run-menu-in-run #map-screen .trait-count,
body.dark-mode.run-menu-in-run #map-screen .trait-desc,
body.dark-mode.run-menu-in-run #map-screen .region-stage-name,
body.dark-mode.run-menu-in-run #map-screen .region-stage-level,
body.dark-mode.run-menu-in-run #catch-screen .team-slot-name {
  color: rgba(255, 255, 255, 0.85);
}
body.dark-mode.run-menu-in-run #map-screen .item-badge {
  color: #fff;
}

#item-tooltip,
#trait-tooltip {
  background: #e8e4d8;
  border: 2px solid var(--outline);
  color: var(--text-main);
  box-shadow: 2px 2px 0 0 var(--outline);
}

/* ---- Battle side ---- */
.battle-side {
  background: #2e2e2e;
  border: 2px solid var(--outline);
  box-shadow: 4px 4px 0 0 var(--outline);
}
.battle-pokemon {
  border: 2px solid var(--outline);
  box-shadow: 3px 3px 0 0 var(--outline);
}

/* ---- Item equip modal ---- */
.item-equip-box .equip-item-name {
  font-size: var(--text-lg);
  color: var(--text-main);
}
.item-equip-box .equip-held-slot,
.item-equip-box .equip-held-item {
  font-size: var(--text-lg);
  color: var(--text-main);
}
.equip-item-desc  { color: var(--text-panel-muted); }
.equip-poke-name  { color: var(--text-main); }
.equip-poke-lv    { color: var(--text-panel-muted); }
.equip-empty-slot { color: #908c7c; }
.equip-self-tag   { color: #908c7c; }

/* ---- List rows ---- */
.equip-pokemon-row,
.trade-member-row {
  background: #dedad0;
  border: 2px solid var(--outline);
  color: var(--text-main);
}
.item-equip-box .equip-pokemon-row {
  border-color: #BFBCB0;
  box-shadow: none;
}
.trade-member-name  { color: var(--text-main); }
.trade-member-level { color: var(--text-panel-muted); }
.trade-member-arrow { color: var(--text-panel-muted); }
.trade-member-row:hover { background: #d0ccc0; border-color: var(--outline); }

/* ---- Toasts (kept dark for floating visibility, muted borders) ---- */
.achievement-toast {
  background: rgba(17, 17, 17, 0.92);
  border: 1px solid #6a5e28;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}
.item-found-toast {
  background: rgba(17, 17, 17, 0.92);
  border: 1px solid #6a4452;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

/* ---- Map notification banner ---- */
.map-notification {
  background: #e8e4d8;
  border: 2px solid var(--outline);
  box-shadow: 0 0 0 2px var(--outline), 3px 3px 0 0 var(--outline);
  color: var(--text-main);
}

/* ---- Tutorial callout ---- */
.tutorial-callout {
  background: #e8e4d8;
  border: 2px solid var(--outline);
  box-shadow: 2px 2px 0 0 var(--outline);
  color: var(--text-main);
}

/* ---- Endless mode: trait preview rows (catch screen) ---- */
.trait-preview-row {
  background: #d8d4c8;
  border-color: var(--outline);
  box-shadow: 2px 2px 0 0 var(--outline);
}
.trait-preview-row-up {
  border-color: #c8a000;
  box-shadow: 0 0 0 1px #c8a000, 2px 2px 0 0 var(--outline);
}
.trait-preview-count,
.trait-preview-desc { color: var(--text-panel-muted); }
.trait-preview-new-tag { color: #8a6000; }

/* ---- Endless mode: map trait panel + region panel ---- */
.trait-count, .trait-desc { color: var(--text-panel-muted); }
.region-stage-level { color: var(--text-panel-muted); }

/* ---- Settings Modal overrides (light body tokens) ---- */

/* Semi-transparent overlays so background.jpg shows through */
#gameover-screen   { background: rgba(10, 0, 0, 0.75); }
#transition-screen { background: rgba(0, 0, 0, 0.55); }

/* ---- Discord Link ---- */
.discord-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #fff;
  text-decoration: none;
  font-size: var(--text-sm);
  opacity: 0.85;
  margin-top: 10px;
  transition: opacity 0.15s;
  background: #5865F2;
  padding: 6px 10px;
  border-radius: 4px;
}
.discord-link:hover { opacity: 1; }
.discord-link svg { width: 16px; height: 16px; fill: #fff; flex-shrink: 0; }

@media (min-width: 769px) {
  .title-legal-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: flex;
    justify-content: center;
    padding: 6px calc(16px + var(--safe-right)) calc(6px + var(--safe-bottom)) calc(16px + var(--safe-left));
    pointer-events: none;
  }
  body.run-menu-active .title-legal-footer {
    left: var(--safe-left);
    right: var(--safe-right);
    padding-left: 16px;
    padding-right: 16px;
    bottom: calc(var(--safe-bottom) + var(--run-menu-offset) + 4px);
    transition: left 0.2s ease;
  }
  body.run-menu-active.run-menu-sidebar-open .title-legal-footer {
    left: calc(var(--safe-left) + var(--run-menu-width));
  }
  .title-legal-footer-inner {
    max-width: min(520px, 100%);
    text-align: center;
    pointer-events: auto;
  }
  .title-footer-link {
    display: inline-block;
    margin-bottom: 12px;
    font-size: var(--text-sm);
    color: rgba(32, 30, 26, 0.92);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
  }
  @media (hover: hover) {
    .title-footer-link:hover { color: var(--gold); }
  }
  .title-footer-link:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 3px;
  }
  .title-footer-legal {
    margin: 0;
    font-size: var(--text-sm);
    line-height: 1.5;
    color: rgba(32, 30, 26, 0.92);
  }
  body.dark-mode .title-footer-link { color: rgba(224, 220, 208, 0.92); }
  body.dark-mode .title-footer-legal { color: rgba(176, 172, 160, 0.92); }
}
@media (max-width: 768px) {
  .title-legal-footer {
    display: none !important;
  }
}

/* ======================================================
   DARK MODE
   ====================================================== */
body.dark-mode::before {
  background-image: url('../img/backgroundDarkMode.png');
}

body.dark-mode .poke-card,
body.dark-mode .trainer-card,
body.dark-mode .item-card,
body.dark-mode .badge-earn-icon-wrap {
  background: #252118;
  color: #e0dcd0;
}
body.dark-mode .poke-name,
body.dark-mode .trainer-label,
body.dark-mode .item-name            { color: #e0dcd0; }
body.dark-mode .poke-level,
body.dark-mode .poke-stats,
body.dark-mode .item-desc            { color: #908878; }
body.dark-mode .move-name            { color: #e0dcd0; -webkit-text-stroke: none; }
body.dark-mode .move-power-badge     { background: rgba(255,255,255,0.1); color: #908878; }
body.dark-mode .move-desc            { color: #908878; }
body.dark-mode .poke-move            { border-color: var(--outline); }
body.dark-mode .poke-card[role="button"]:hover,
body.dark-mode .poke-card[tabindex]:hover { border-color: #e0dcd0; }
body.dark-mode .poke-card.selected   { border-color: #c8a000; }
body.dark-mode .item-card:hover      { border-color: #e0dcd0; }
body.dark-mode .trainer-card:hover,
body.dark-mode .trainer-card:focus   { border-color: #e0dcd0; }

body.dark-mode .hud-box,
body.dark-mode .map-header {
  background: #252118;
  color: #e0dcd0;
}
body.dark-mode #map-container {
  --map-frame-color: var(--outline);
}
body.dark-mode .hud-label            { color: #908878; }
body.dark-mode .trait-count,
body.dark-mode .trait-desc,
body.dark-mode .trait-preview-count,
body.dark-mode .trait-preview-desc,
body.dark-mode .region-stage-level   { color: #909080; }
body.dark-mode .trait-preview-new-tag { color: #ffd700; }
body.dark-mode .trait-preview-row {
  background: #252118;
}
body.dark-mode .trait-preview-row-up {
  border-color: #ffd700;
  box-shadow: 0 0 0 1px #ffd700, 2px 2px 0 0 var(--outline);
}

body.dark-mode .item-badge {
  background: #1e1c14;
  color: #e0dcd0;
}
body.dark-mode #item-tooltip,
body.dark-mode #trait-tooltip {
  background: #252118;
  color: #e0dcd0;
}

body.dark-mode #btn-auto-battle,
body.dark-mode #btn-continue-battle {
  background: #252118;
  color: #e0dcd0;
}

body.dark-mode .item-equip-box {
  background: #252118;
  color: #e0dcd0;
}
body.dark-mode .equip-item-header {
  background: #1e1c14;
  border-bottom-color: var(--outline);
}
body.dark-mode .equip-item-name,
body.dark-mode .equip-poke-name      { color: #e0dcd0; }
body.dark-mode .equip-item-desc,
body.dark-mode .equip-poke-lv        { color: #908878; }
body.dark-mode .item-equip-box .equip-held-slot,
body.dark-mode .item-equip-box .equip-held-item {
  color: #e0dcd0;
}
body.dark-mode .equip-pokemon-row,
body.dark-mode .trade-member-row {
  background: #2e2820;
  color: #e0dcd0;
}
body.dark-mode .trade-member-name    { color: #e0dcd0; }
body.dark-mode .trade-member-level,
body.dark-mode .trade-member-arrow   { color: #908878; }
body.dark-mode .equip-pokemon-row:hover,
body.dark-mode .trade-member-row:hover { background: #3a3228; }

body.dark-mode .map-notification {
  background: #252118;
  color: #e0dcd0;
}
body.dark-mode .tutorial-callout {
  background: #252118;
  color: #e0dcd0;
}
body.dark-mode #starter-region-panel {
  background: #111e3a;
  border-color: #7090d0;
  color: #ccdeff;
}
body.dark-mode .game-modal-box {
  background: #252118;
  color: #e0dcd0;
}
body.dark-mode .game-modal-header--ach {
  background: #286828;
  border-bottom-color: var(--text-main);
}
body.dark-mode .game-modal-header--ach .game-modal-title { color: #fff; }
body.dark-mode .game-modal-header--ach .game-modal-desc { color: #a8d8a8; }
body.dark-mode .game-modal-title { color: #e0dcd0; }
body.dark-mode .game-modal-desc { color: #908878; }
body.dark-mode .game-modal-body,
body.dark-mode .game-modal-body--padded { background: #1e1c14; }
body.dark-mode .ach-category-header {
  background: #1a1810;
  color: #c8a800;
  border-bottom-color: #3a3428;
}
body.dark-mode .ach-category-count { color: #706858; }
body.dark-mode .ach-modal-grid { background: #1e1c14; }
body.dark-mode .ach-card {
  background: #1a2818;
  border-color: #389838;
}
body.dark-mode .ach-card.unlocked {
  border-color: #58a858;
  background: #243824;
  box-shadow: inset 0 0 0 1px #58a858;
}
body.dark-mode .ach-name { color: #e0dcd0; }
body.dark-mode .ach-desc { color: #908878; }
body.dark-mode .ach-card.unlocked .ach-desc { color: #908878; }

body.dark-mode .game-modal-header--patch,
body.dark-mode .game-modal-header--detail {
  background: #252118;
  border-bottom-color: #4a4438;
}
body.dark-mode .patch-note-version-header { border-bottom-color: #3a3428; }
body.dark-mode .patch-note-version { color: #c8a800; }
body.dark-mode .patch-note-title { color: #e0dcd0; }
body.dark-mode .patch-note-date { color: #706858; }
body.dark-mode .patch-note-section-heading { color: #c8a800; }
body.dark-mode .patch-note-entry { color: #908878; }

body.dark-mode .game-modal-header--hof {
  background: #8a7018;
  border-bottom-color: var(--outline);
}
body.dark-mode .game-modal-header--hof .game-modal-title { color: #fff; }
body.dark-mode .game-modal-header--hof .game-modal-desc { color: rgba(255, 255, 255, 0.88); }
body.dark-mode .hof-filter-bar {
  background: #1e1c14;
  border-bottom-color: #3a3428;
}
body.dark-mode .hof-filter-chip {
  background: #252118;
  color: #908878;
}
body.dark-mode .hof-filter-chip.active {
  background: #2a2618;
  border-color: #c8a800;
  box-shadow: 2px 2px 0 0 #c8a800;
  color: #c8a800;
}
body.dark-mode .hof-subfilter-bar {
  background: #161410;
  border-bottom-color: #3a3428;
}
body.dark-mode .hof-subfilter-chip {
  background: #252118;
  color: #908878;
}
body.dark-mode .hof-subfilter-chip.active {
  background: #2a2618;
  border-color: #c8a800;
  box-shadow: 2px 2px 0 0 #c8a800;
  color: #c8a800;
}
body.dark-mode .hof-empty { color: #908878; }
body.dark-mode .hof-entry-card {
  background: #252118;
}
body.dark-mode .hof-entry-header { border-bottom-color: #3a3428; }
body.dark-mode .hof-entry-title { color: #c8a800; }
body.dark-mode .hof-entry-date { color: #706858; }
body.dark-mode .hof-pokemon-name { color: #908878; }
body.dark-mode .hof-pokemon--shiny .hof-pokemon-name { color: #c8a800; }
body.dark-mode .hof-pokemon-lv { color: #706858; }

body.dark-mode .game-modal-header--dex {
  background: #881818;
  border-bottom-color: var(--text-main);
}
body.dark-mode .game-modal-header--dex .game-modal-title { color: #fff; }
body.dark-mode .game-modal-header--dex .game-modal-desc { color: #e8a8a8; }
body.dark-mode .dex-modal-toolbar {
  background: #1e1c14;
  border-bottom-color: #3a3428;
}
body.dark-mode .dex-progress-track {
  background: #1a1810;
  border-color: #4a4438;
}
body.dark-mode .dex-charm-icon {
  background: #252118;
  border-color: #4a4438;
}
body.dark-mode .dex-filter-bar {
  background: #1e1c14;
  border-bottom-color: #3a3428;
}
body.dark-mode .dex-filter-btn {
  background: #252118;
  color: #908878;
}
body.dark-mode .dex-filter-btn:hover { border-color: #cc2222; color: #e0dcd0; }
body.dark-mode .dex-filter-btn.active {
  border-color: #cc2222;
  color: #cc2222;
  background: #2e1818;
  box-shadow: 2px 2px 0 0 #cc2222;
}
body.dark-mode .dex-grid { background: #1e1c14; }
body.dark-mode .dex-gen-header { color: #ff6666; border-bottom-color: #3a3428; }
body.dark-mode .gen-count { color: #706858; }
body.dark-mode .dex-card {
  background: #252118;
  border-color: #3a3428;
}
body.dark-mode .dex-card.dex-caught {
  border-color: #cc2222;
  background: #2e1818;
}
body.dark-mode .dex-num { color: #706858; }
body.dark-mode .dex-name { color: #e0dcd0; }
body.dark-mode .dex-unknown-name { color: #706858; }
body.dark-mode .dex-tab {
  background: #252118;
  color: #908878;
}
body.dark-mode .dex-tab:hover { color: #e0dcd0; }
body.dark-mode .dex-tab.active {
  background: #2e1818;
  border-color: #cc2222;
  box-shadow: 2px 2px 0 0 #cc2222;
  color: #cc2222;
}
body.dark-mode .dex-tab[data-tab="shiny"].active {
  background: #2a2618;
  border-color: #c8a800;
  box-shadow: 2px 2px 0 0 #c8a800;
  color: #c8a800;
}
body.dark-mode .dex-toolbar-sep { border-top-color: #3a3428; }
body.dark-mode .dex-gen-filter-btn {
  background: #252118;
  color: #908878;
}
body.dark-mode .dex-gen-filter-btn:hover { border-color: #cc2222; color: #e0dcd0; }
body.dark-mode .dex-gen-filter-btn.active {
  background: #2e1818;
  border-color: #cc2222;
  box-shadow: 2px 2px 0 0 #cc2222;
  color: #cc2222;
}
body.dark-mode .shiny-dex-box .dex-gen-filter-btn.active {
  background: #2a2618;
  border-color: #c8a800;
  box-shadow: 2px 2px 0 0 #c8a800;
  color: #c8a800;
}
body.dark-mode .dex-hide-caught-btn {
  background: #252118;
  color: #908878;
}
body.dark-mode .dex-tab-row .dex-hide-caught-btn:hover { color: #e0dcd0; }
body.dark-mode .dex-tab-row .dex-hide-caught-btn.active {
  background: #2e1818;
  border-color: #cc2222;
  box-shadow: 2px 2px 0 0 #cc2222;
  color: #cc2222;
}
body.dark-mode .shiny-dex-box .dex-tab-row .dex-hide-caught-btn.active {
  background: #2a2618;
  border-color: #c8a800;
  box-shadow: 2px 2px 0 0 #c8a800;
  color: #c8a800;
}
body.dark-mode .shiny-dex-box .dex-gen-header { color: #c8a800; }
body.dark-mode .shiny-dex-card {
  border-color: #c8a800;
  background: #2a2618;
}
body.dark-mode .dex-detail-body { background: #1e1c14; }
body.dark-mode .dex-detail-name { color: #e0dcd0; }
body.dark-mode .dex-detail-num { color: #706858; }
body.dark-mode .dex-detail-flavor { color: #908878; }
body.dark-mode .dex-detail-section-title {
  color: #ff6666;
  border-bottom-color: #3a3428;
}
body.dark-mode .dex-detail-shiny-btn {
  background: #252118;
  color: #908878;
}
body.dark-mode .dex-detail-shiny-btn--active {
  background: #2a2618;
  border-color: #c8a800;
  color: #c8a800;
}
body.dark-mode .dex-evo-name { color: #908878; }
body.dark-mode .dex-evo-node--current > .dex-evo-name { color: #c8a800; }
body.dark-mode .dex-evo-arrow { color: #ff6666; }
body.dark-mode .dex-evo-level { color: #706858; }
body.dark-mode .dex-detail-loc-label { color: #908878; }
body.dark-mode .dex-detail-loc-none { color: #706858; }
body.dark-mode .dex-detail-loc-tag {
  background: #2e1818;
  border-color: #cc2222;
  color: #ff8888;
}
body.dark-mode .dex-detail-loc-tag--tower {
  background: #181828;
  border-color: #3344aa;
  color: #88aacc;
}

body.dark-mode .game-modal-header--settings {
  background: #1a5090;
  border-bottom-color: var(--text-main);
}
body.dark-mode .game-modal-header--settings .game-modal-title { color: #fff; }
body.dark-mode .settings-section-title {
  background: #1a1810;
  color: #5090d5;
  border-bottom-color: #3a3428;
}
body.dark-mode .settings-row {
  background: #252118;
  border-bottom-color: #3a3428;
  color: #e0dcd0;
}
body.dark-mode .settings-row:hover { background: #2e2820; }
body.dark-mode .settings-label { color: #e0dcd0; }
body.dark-mode .settings-checkbox:checked,
body.dark-mode .pixel-checkbox:checked {
  background: var(--checkbox-accent);
}
body.dark-mode .game-modal-header--cloud {
  background: #1a6898;
  border-bottom-color: var(--text-main);
}
body.dark-mode .game-modal-header--cloud .game-modal-title { color: #fff; }
body.dark-mode .game-modal-header--cloud .game-modal-desc { color: #a8d8f0; }
body.dark-mode .game-modal-header--pc {
  background: linear-gradient(180deg, #3a5ccc 0%, #1e3a99 100%);
}
body.dark-mode .pc-box .game-modal-title,
body.dark-mode .game-modal-header--pc .game-modal-title { color: #fff; }
body.dark-mode .pc-box .game-modal-desc,
body.dark-mode .game-modal-header--pc .game-modal-desc { color: #aaccff; }
body.dark-mode .cloud-auth-status { color: #908878; }
body.dark-mode .cloud-auth-status--warn { color: #d0a040; }
body.dark-mode #save-auth-modal .btn-primary {
  background: #252118;
  color: #e0dcd0;
}

body.dark-mode .btn-primary {
  background: #252118;
  color: #e0dcd0;
}
body.dark-mode .title-mode-card {
  /* No slab background on the whole button — only the inner figure tile is
     meant to have a background, matching light mode. */
  background: transparent;
}
body.dark-mode .title-mode-card--story .title-mode-card-title {
  color: #5fd07a;
}
body.dark-mode .title-mode-card--tower .title-mode-card-title {
  color: #6699ff;
}
body.dark-mode .title-mode-card--challenge .title-mode-card-title {
  color: #ff7a6e;
}
body.dark-mode .title-mode-card-desc {
  color: #e0dcd0;
}
body.dark-mode .title-mode-card-action {
  background: #100e0c;
  border-top-color: var(--outline);
  color: #f0ece4;
}
body.dark-mode .title-mode-card--story .title-mode-card-action {
  background: #1e8a3a;
  color: #fff;
}
body.dark-mode .title-mode-card--story:hover:not(:disabled) .title-mode-card-action {
  background: #24a24a;
  color: #fff;
}
body.dark-mode .title-mode-card--tower .title-mode-card-action {
  background: #2266dd;
  color: #fff;
}
body.dark-mode .title-mode-card--tower:hover:not(:disabled) .title-mode-card-action {
  background: #3377ee;
  color: #fff;
}
body.dark-mode .title-mode-card--challenge .title-mode-card-action {
  background: #b8362b;
  color: #fff;
}
body.dark-mode .title-mode-card--challenge:hover:not(:disabled) .title-mode-card-action {
  background: #cc4538;
  color: #fff;
}
body.dark-mode .history-mode-btn--selected.history-mode-btn--classic { border-color: #2266dd; box-shadow: 3px 3px 0 0 #2266dd; color: #6699ff; }
body.dark-mode .history-mode-btn--selected.history-mode-btn--classic:hover { box-shadow: 4px 4px 0 0 #2266dd; }
body.dark-mode .history-mode-btn--selected.history-mode-btn--nuzlocke { border-color: #cc2222; box-shadow: 3px 3px 0 0 #cc2222; color: #ff6666; }
body.dark-mode .history-mode-btn--selected.history-mode-btn--nuzlocke:hover { box-shadow: 4px 4px 0 0 #cc2222; }
body.dark-mode .history-header {
  background: #2a2620;
}
body.dark-mode .history-header-title {
  color: #6699ff;
}
body.dark-mode h1.history-header-title--story { color: #5fd07a; }
body.dark-mode h1.history-header-title--tower { color: #6699ff; }
body.dark-mode h1.history-header-title--challenge { color: #ff7a6e; }
body.dark-mode .history-header-intro,
body.dark-mode .history-header-lead,
body.dark-mode .history-header-desc {
  color: #e0dcd0;
}
body.dark-mode .history-mode-btn:not(.history-mode-btn--selected) {
  background: #1a1814;
  color: #706858;
}
body.dark-mode .history-mode-btn--selected.history-mode-btn--classic,
body.dark-mode .history-mode-btn--selected.history-mode-btn--nuzlocke {
  background: #252118;
}
body.dark-mode .history-region-stats {
  background: #2a2620;
  border-left-color: var(--outline);
  color: #f0ece4;
}
body.dark-mode .history-region-stat-row span:first-child {
  color: #c8c4b8;
}
body.dark-mode .history-region-stat-row span:last-child {
  color: #fff;
}
body.dark-mode .history-more-regions {
  background: #2a2620;
  color: #f0ece4;
}
body.dark-mode .history-region-btn {
  background: #252118;
}
body.dark-mode .history-select-back.run-menu-btn.btn-primary,
body.dark-mode .history-select-logo.run-menu-btn.btn-primary,
body.dark-mode .btn-run-panel.btn-primary,
body.dark-mode .btn-run-panel.btn-secondary {
  --run-menu-btn-edge: var(--outline);
  background: #252118;
  color: #e0dcd0;
}
@media (hover: hover) {
  body.dark-mode .history-select-back.run-menu-btn.btn-primary:hover,
  body.dark-mode .btn-run-panel.btn-primary:hover:not(:disabled):not(:active),
  body.dark-mode .btn-run-panel.btn-secondary:hover:not(:disabled):not(:active) {
    background: #2e2820;
    color: #e0dcd0;
  }
}
body.dark-mode .history-select-back.run-menu-btn.btn-primary:active,
body.dark-mode .btn-run-panel.btn-primary:active:not(:disabled),
body.dark-mode .btn-run-panel.btn-secondary:active:not(:disabled) {
  background: #252118;
  color: #e0dcd0;
}
body.dark-mode .equip-pokemon-row .btn-primary.btn-sm:not(.equip-btn-unequip) {
  background: #C89821;
  border-color: #C89821;
  box-shadow: var(--btn-edge-sm) var(--btn-edge-sm) 0 0 #9a7818;
  color: #fff;
}
body.dark-mode .equip-pokemon-row .btn-primary.btn-sm.equip-btn-unequip {
  background: #d84848;
  border-color: #e06060;
  box-shadow: var(--btn-edge-sm) var(--btn-edge-sm) 0 0 #b83838;
  color: #fff;
}
body.dark-mode .history-more-regions-text {
  color: #e0dcd0;
}
body.dark-mode .history-battle-tower-btn {
  background: #6848b0;
  border-color: #9a7ae8;
  box-shadow: 3px 3px 0 0 #9a7ae8;
  color: #fff;
}
body.dark-mode .history-battle-tower-btn:hover { box-shadow: 4px 4px 0 0 #9a7ae8; }

/* ── Endless Trait Panel (map screen) ──────────────────────────────────────── */

.map-panel-traits {
  flex: 0 0 auto;
  min-width: 140px;
  max-width: 180px;
}
.trait-row {
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.trait-row:last-child { border-bottom: none; margin-bottom: 0; }
.trait-row-inactive { opacity: 0.4; }
.trait-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 3px;
}
.trait-count {
  font-size: var(--text-xs);
  color: var(--text-dim);
  white-space: nowrap;
}
.trait-progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 3px;
}
.trait-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}
/* Use type badge colors for the fill */
.trait-progress-fill.type-fire     { background: #f08030; }
.trait-progress-fill.type-water    { background: #6890f0; }
.trait-progress-fill.type-grass    { background: #78c850; }
.trait-progress-fill.type-electric { background: #f8d030; }
.trait-progress-fill.type-ice      { background: #98d8d8; }
.trait-progress-fill.type-poison   { background: #a040a0; }
.trait-progress-fill.type-ground   { background: #e0c068; }
.trait-progress-fill.type-flying   { background: #a890f0; }
.trait-progress-fill.type-psychic  { background: #f85888; }
.trait-progress-fill.type-bug      { background: #a8b820; }
.trait-progress-fill.type-rock     { background: #b8a038; }
.trait-progress-fill.type-ghost    { background: #705898; }
.trait-progress-fill.type-dragon   { background: #7038f8; }
.trait-progress-fill.type-dark     { background: #705848; }
.trait-progress-fill.type-steel    { background: #b8b8d0; }
.trait-progress-fill.type-normal   { background: #a8a878; }
.trait-desc {
  font-size: var(--text-xs);
  color: var(--text-dim);
  line-height: 1.6;
}

/* On desktop, trait panel goes after team + items (right side) */
@media (min-width: 769px) {
  .map-panel-traits {
    order: 4;
    align-self: start;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
  }
}

/* ── Endless Region Panel (map screen, right of items) ─────────────────────── */

.map-panel-region {
  flex: 0 0 auto;
  min-width: 130px;
}
.region-stage-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}
.region-stage-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px;
  border-radius: 3px;
  border: 1px solid transparent;
  font-size: var(--text-xs);
  opacity: 0.6;
}
.region-stage-row.done {
  opacity: 0.35;
}
.region-stage-row.current {
  opacity: 1;
  border-color: var(--gold);
  background: rgba(255, 200, 0, 0.08);
}
.region-stage-row.boss {
  border-color: var(--border);
  opacity: 0.6;
}
.region-stage-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--text-xs);
}
.region-stage-level {
  font-size: var(--text-xs);
  color: var(--text-dim);
  white-space: nowrap;
}

@media (min-width: 769px) {
  .map-panel-region {
    order: 4;
    align-self: start;
  }
}

/* ── Mobile item screen: 3-in-a-row ───────────────────────────────────────── */
@media (max-width: 768px) {
  #item-choices {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .item-card { width: auto; padding: 12px 8px; }

  /* Passive pick screen: same 3-in-a-row grid so every passive card shares one
     width (as a flex row the width:auto cards each sized to their own text). */
  #passive-choices:not(.is-replace-grid) {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
  }
  #passive-choices .choice-skip-row { grid-column: 1 / -1; }
}

/* ── Mobile map screen layout ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* 100dvh gives the true visible viewport on iOS Safari (excludes address bar).
     Do NOT add 100lvh after this — lvh is the address-bar-HIDDEN height, which
     pushes the map's bottom off-screen (with overflow:hidden it can't scroll). */
  #map-screen {
    position: relative;
    height: -webkit-fill-available;
    /* Subtract --ad-reserve (the in-game sticky-header strip; 0 when no ad) so
       the fixed-height, overflow:hidden map fits under the reserved top strip
       instead of pushing the page 90px past the viewport and scrolling. */
    height: calc(100dvh - var(--ad-reserve, 0px));
    min-height: 0;
    padding:
      calc(6px + var(--safe-top))
      calc(6px + var(--safe-right))
      calc(6px + var(--safe-bottom))
      calc(6px + var(--safe-left));
    gap: 6px;
    overflow: hidden;
  }
  /* The bottom run-menu bar never shows during a run on mobile — the floating
     top-right quick-nav covers every run screen now — so reclaim its reserved
     bottom padding on every run screen. */
  body.run-menu-in-run #run-menu-bar { display: none; }
  body.run-menu-active.run-menu-in-run .screen.active {
    padding-bottom: calc(16px + var(--safe-bottom));
  }
  body.run-menu-active:has(#map-screen.active) #map-screen {
    padding-bottom: calc(6px + var(--safe-bottom));
  }

  /* Remove the top bar; badges live in the panel strip on mobile */
  .map-header { display: none; }

  /* Quick-menu icons overlay the top-right (over the team) instead of taking a
     row; team + items sit above the map. */
  .map-menu-icons {
    position: fixed;
    top: calc(var(--safe-top) + 5px);
    right: calc(var(--safe-right) + 5px);
    z-index: 250;
    /* Vertical column on mobile (horizontal row on desktop). */
    flex-direction: column;
    flex-wrap: nowrap;
    margin: 0;
    gap: 5px;
    padding: 3px 5px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 6px;
  }
  .map-panels {
    order: 2;
    flex: 0 0 auto;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 6px;
    width: var(--map-render-width, 100%);
    max-width: 100%;
    margin-inline: auto;
  }
  #map-container {
    order: 3;
    flex: 1;
    min-height: 0;
    width: auto;
    max-width: 100%;
  }

  /* Trait panel: slim horizontal scrollable strip */
  .map-panel-traits {
    flex: 1 1 100%;
    max-width: none;
    min-width: 0;
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    gap: 0;
    align-items: flex-start;
    padding: 2px;
  }
  .map-panel-traits .hud-label { display: none; }
  .trait-row {
    flex-shrink: 0;
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
    padding-right: 8px;
    margin-right: 8px;
    border-right: 1px solid var(--border);
  }
  .trait-row:last-child { border-right: none; padding-right: 0; margin-right: 0; }
  .trait-desc { display: none; }

  /* Team panel: single row, slots shrink evenly so all 6 always fit */
  .map-panel-left { flex: 1 1 100%; padding: 4px; }
  .map-panel-left .hud-label { display: none; }
  #team-bar {
    display: flex !important;
    flex-direction: row;
    gap: 3px;
    overflow: visible;
    padding-bottom: 0;
  }
  #map-screen #team-bar .team-slot { flex: 1; width: auto; min-width: 0; }
  #map-screen #team-bar .team-slot-name {
    max-width: 100%;
    font-size: var(--text-xs);
  }
  #map-screen #team-bar .team-slot-lv { font-size: var(--text-sm); }
  #map-screen #team-bar .team-sprite {
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
  }

  /* Items: icon-only horizontal strip; region panel: hidden on mobile */
  .map-panel-right { flex: 1 1 100%; padding: 2px 4px; min-width: 0; }
  .map-panel-right .hud-label { display: none; }
  #item-bar { display: grid; grid-template-columns: repeat(5, max-content); gap: 4px; padding: 2px 0; justify-content: start; }
  #item-bar .item-badge { font-size: 0; padding: 3px; line-height: 0; }
  /* Labels are hidden here, so the passive items need their own gap from the items. */
  #passive-badges { margin-top: 14px; }
  .map-panel-region { display: none; }
}

/* ── Endless Mode ───────────────────────────────────────────────────────────── */

/* Floating stat-change arrow popup */
.stat-change-popup {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--text-sm);
  font-weight: bold;
  pointer-events: none;
  z-index: 20;
  text-shadow: 0 1px 3px #000;
  white-space: nowrap;
  animation: stat-float 0.7s ease-out forwards;
}
@keyframes stat-float {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-28px); }
}

/* Status badge (poison ☠ / freeze ❄) pinned to pokemon sprite corner */
.status-badge {
  position: absolute;
  bottom: 2px;
  right: 2px;
  font-size: var(--text-base);
  padding: 1px 3px;
  border-radius: 3px;
  z-index: 10;
  pointer-events: none;
}
.frozen-flash {
  animation: frozen-pulse 0.3s ease-in-out;
}
@keyframes frozen-pulse {
  0%, 100% { filter: brightness(1); }
  50%       { filter: brightness(2) saturate(0); }
}

/* Trait bars shown inside each battle side during endless boss fights */
.battle-trait-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 0 0 4px;
  min-height: 0;
  /* When one side's bar is given extra minHeight to match the taller side,
     keep the badges packed at the top instead of stretching them apart. */
  align-content: flex-start;
}
.battle-trait-bar:empty { visibility: hidden; }
.battle-trait-bar-right { justify-content: flex-end; }
.trait-badge {
  font-size: var(--text-sm);
  padding: 2px 5px;
  border-radius: 3px;
}


/* ============================================================================
   World Tournament / Challenge Mode / Gen2 — ported from the worldTournament
   branch onto the fork's refactored stylesheet. Covers: battle damage/crit
   popups, type-chart modal, SHIFT-hover advanced stats, status-effect
   animations (freeze/poison/ice), Publift ad slots, WT types modal, passive
   item badges/screen, Challenge Runs + Monotype select UI.
   ============================================================================ */

.crit-popup, .dmg-popup {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  color: var(--gold);
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  font-weight: bold;
  white-space: nowrap;
  pointer-events: none;
  animation: crit-popup 0.8s ease-out forwards;
  z-index: 10;
}
@keyframes crit-popup {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0);    }
  100% { opacity: 0; transform: translateX(-50%) translateY(-32px); }
}

/* Damage number popup — Battle Tower only. Smaller + softer than crit so it
   reads as supplementary info, not a screen-eating banner. */
.dmg-popup {
  top: 8px;
  color: #ff9a9a;
  font-size: 8px;
  font-weight: normal;
  opacity: 0.85;
  text-shadow: 1px 1px 0 #000;
}
.dmg-popup.dmg-crit   { color: #ffd766; font-size: 10px; }
.dmg-popup.dmg-nve    { color: #bbbbbb; }
.dmg-popup.dmg-se     { color: #ff6868; }
.dmg-popup.dmg-poison { color: #c977e0; }
.dmg-popup.dmg-heal   { color: #88f0a0; }

/* ---- Type chart icon + modal (Elite prep & WT prep) ---- */
.typechart-btn {
  background: transparent;
  border: 1px solid #d4af37;
  color: #ffe27a;
  border-radius: 4px;
  padding: 2px 5px;
  margin-left: 8px;
  font-size: 11px;
  cursor: pointer;
  line-height: 1;
}
.typechart-btn:hover { background: rgba(212,175,55,0.15); }

.typechart-overlay {
  position: fixed; inset: 0; z-index: 230;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
}
.typechart-box {
  background: #1a1230;
  border: 2px solid #d4af37;
  border-radius: 8px;
  padding: 12px;
  max-width: min(96vw, 720px);
  max-height: 90vh;
  display: flex; flex-direction: column;
  font-family: 'Press Start 2P', monospace;
}
.typechart-title {
  font-size: 9px; color: #d4af37; text-align: center; margin-bottom: 6px;
}
.typechart-scroll {
  overflow: auto;
  flex: 1;
  border: 1px solid #333;
}
table.typechart {
  border-collapse: collapse;
  font-size: 6px;
}
table.typechart th, table.typechart td {
  width: 22px; height: 22px;
  text-align: center;
  border: 1px solid #2a2040;
  padding: 0;
  background: #0a0418;
  color: #ddd;
}
table.typechart th.tc-h {
  color: #fff;
  font-size: 5px;
  letter-spacing: 0;
  text-transform: uppercase;
}
table.typechart td.tc-se   { background: #6e1a1a; color: #ffd5d5; font-weight: bold; }
table.typechart td.tc-nve  { background: #1a3a6e; color: #cfe5ff; }
table.typechart td.tc-zero { background: #444;    color: #888; }
.typechart-legend {
  font-size: 6px;
  text-align: center;
  margin-top: 6px;
  color: #aaa;
}
.typechart-legend .tc-se,
.typechart-legend .tc-nve,
.typechart-legend .tc-zero {
  display: inline-block;
  padding: 1px 3px;
  border-radius: 2px;
  color: #fff;
}
.typechart-legend .tc-se   { background: #6e1a1a; }
.typechart-legend .tc-nve  { background: #1a3a6e; }
.typechart-legend .tc-zero { background: #444; color: #aaa; }

/* SHIFT+hover advanced stats — appended below the standard pokemon card in
   the team hover popup. Compact two-column rows. */
.adv-stats {
  margin-top: 6px;
  padding: 5px 6px;
  border: 1px dashed #d4af37;
  border-radius: 4px;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  background: rgba(212,175,55,0.06);
  display: flex; flex-direction: column; gap: 3px;
}
.adv-stat-row {
  display: flex; justify-content: space-between;
  gap: 8px;
  line-height: 1.3;
}
.adv-stat-row span { color: #aaa; }
.adv-stat-row b { color: #ffe27a; }
.hover-shift-hint {
  margin-top: 6px;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #888;
  text-align: center;
  opacity: 0.7;
}

/* Trait labels reuse the existing .crit-popup style (same float-up motion
   as the dodge/struggle popup) — no extra class needed. */

.status-badge-pulse {
  animation: status-badge-pulse 0.45s ease-out;
}
@keyframes status-badge-pulse {
  0%   { transform: scale(1);   filter: brightness(1); }
  35%  { transform: scale(1.4); filter: brightness(1.8); }
  100% { transform: scale(1);   filter: brightness(1); }
}
.frozen-flash {
  animation: frozen-pulse 0.3s ease-in-out;
}
@keyframes frozen-pulse {
  0%, 100% { filter: brightness(1); }
  50%       { filter: brightness(2) saturate(0); }
}

/* freeze-apply: plays once when a Pokemon gets frozen.
   Phases: brief blue glow → desaturate + ice-blue tint + small shrink-wrap,
   then settles on a faint cyan halo so the badge "owns" the state visually. */
.freeze-apply {
  animation: freeze-apply 0.9s cubic-bezier(0.22, 0.61, 0.36, 1);
}
@keyframes freeze-apply {
  0%   { filter: brightness(1) saturate(1)   drop-shadow(0 0 0 #7ecff0)  hue-rotate(0deg); transform: scale(1); }
  20%  { filter: brightness(1.6) saturate(1.3) drop-shadow(0 0 10px #d6f0ff) hue-rotate(-10deg); transform: scale(1.08); }
  45%  { filter: brightness(1.3) saturate(0.4) drop-shadow(0 0 16px #aee0ff) hue-rotate(-20deg); transform: scale(0.96); }
  70%  { filter: brightness(1.1) saturate(0.2) drop-shadow(0 0 12px #7ecff0) hue-rotate(-15deg); transform: scale(1.01); }
  100% { filter: brightness(0.95) saturate(0.55) drop-shadow(0 0 6px #7ecff0) hue-rotate(-8deg); transform: scale(1); }
}
/* Ice overlay drawn on top of the sprite while freeze-apply runs — sells the
   "ice crystallizing over the sprite" idea without needing a sprite swap. */
.freeze-apply::after {
  content: '';
  position: absolute; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 25% 30%, rgba(220,245,255,0.85) 0 6%, transparent 14%),
    radial-gradient(circle at 70% 65%, rgba(200,235,255,0.75) 0 5%, transparent 12%),
    radial-gradient(circle at 50% 20%, rgba(230,248,255,0.7)  0 4%, transparent 10%),
    radial-gradient(circle at 35% 80%, rgba(210,240,255,0.7)  0 4%, transparent 11%),
    linear-gradient(180deg, rgba(180,225,255,0) 0%, rgba(180,225,255,0.35) 100%);
  mix-blend-mode: screen;
  animation: freeze-overlay 0.9s ease-out forwards;
  z-index: 5;
}
@keyframes freeze-overlay {
  0%   { opacity: 0; transform: scale(0.7); }
  35%  { opacity: 1; transform: scale(1.05); }
  100% { opacity: 0.6; transform: scale(1); }
}

/* freeze-break: plays once when the Ice trait shatters a freeze.
   Hard white flash, sharper shake than the apply, plus a brief de-tint. */
.freeze-break {
  animation: freeze-break 0.7s ease-out;
}
@keyframes freeze-break {
  0%   { filter: brightness(0.95) saturate(0.55) drop-shadow(0 0 6px #7ecff0); transform: translate(0, 0) rotate(0); }
  12%  { filter: brightness(2.6) saturate(1.4) drop-shadow(0 0 14px #ffffff); transform: translate(-5px, 2px) rotate(-2deg); }
  24%  { filter: brightness(2.0) saturate(1.2) drop-shadow(0 0 12px #d6f0ff); transform: translate(5px, -2px) rotate(2deg); }
  38%  { filter: brightness(1.6) saturate(1.1) drop-shadow(0 0 10px #b0e0ff); transform: translate(-3px, 1px) rotate(-1deg); }
  55%  { filter: brightness(1.3) saturate(1)   drop-shadow(0 0 6px  #b0e0ff); transform: translate(2px, 0)   rotate(0); }
  100% { filter: brightness(1) saturate(1)     drop-shadow(0 0 0   #7ecff0); transform: translate(0, 0)    rotate(0); }
}
/* Ice shards spawned by ui.js when freeze breaks. Each shard is a small
   div pushed outward + downward, fading out — sells the crystal shattering. */
.ice-shard {
  position: absolute;
  width: 4px; height: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #b0e0ff 60%, #7ecff0 100%);
  box-shadow: 0 0 4px #d6f0ff;
  border-radius: 1px;
  pointer-events: none;
  z-index: 11;
  animation: ice-shard 0.7s ease-out forwards;
}
@keyframes ice-shard {
  0%   { opacity: 1; transform: translate(0, 0) rotate(var(--shard-rot, 0deg)) scale(1.2); }
  100% { opacity: 0; transform: translate(var(--shard-dx, 0), var(--shard-dy, 24px)) rotate(calc(var(--shard-rot, 0deg) + 180deg)) scale(0.7); }
}

/* poison-apply: one-shot purple bubble glow when poison stacks first land
   on a Pokemon. Distinct from hit-poison (which plays on each tick). */
.poison-apply {
  animation: poison-apply 0.8s ease-out;
}
@keyframes poison-apply {
  0%   { filter: brightness(1) drop-shadow(0 0 0 #a040a0); transform: scale(1); }
  25%  { filter: brightness(1.4) drop-shadow(0 0 14px #c977e0) hue-rotate(15deg); transform: scale(1.06); }
  55%  { filter: brightness(1.2) drop-shadow(0 0 10px #aa44cc) hue-rotate(8deg); transform: scale(0.98); }
  100% { filter: brightness(1) drop-shadow(0 0 0 #a040a0); transform: scale(1); }
}
.poison-apply::after {
  content: '';
  position: absolute; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 30% 70%, rgba(201,119,224,0.85) 0 5%, transparent 12%),
    radial-gradient(circle at 65% 40%, rgba(180,90,200,0.8)  0 4%, transparent 11%),
    radial-gradient(circle at 50% 85%, rgba(170,68,204,0.75) 0 4%, transparent 10%),
    radial-gradient(circle at 80% 75%, rgba(190,100,210,0.7) 0 3%, transparent 9%);
  mix-blend-mode: screen;
  animation: poison-overlay 0.8s ease-out forwards;
  z-index: 5;
}
@keyframes poison-overlay {
  0%   { opacity: 0; transform: translateY(6px) scale(0.85); }
  40%  { opacity: 1; transform: translateY(-2px) scale(1.05); }
  100% { opacity: 0; transform: translateY(-10px) scale(1); }
}

/* Trait bars shown inside each battle side during endless boss fights */
.battle-trait-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 0 0 4px;
  min-height: 0;
  /* When one side's bar is given extra minHeight to match the taller side,
     keep the badges packed at the top instead of stretching them apart. */
  align-content: flex-start;
}
.battle-trait-bar:empty { visibility: hidden; }
.battle-trait-bar-right { justify-content: flex-end; }
.trait-badge {
  font-size: 8px;
  padding: 2px 5px;
  border-radius: 3px;
  font-family: 'Press Start 2P', monospace;
  letter-spacing: 0;
}

/* === Publift Fuse ad slots ===
   Ads show only IN-GAME: ui.js adds body.show-ads on active-run gameplay screens
   (map + in-run choice/event screens) and removes it on the title / menus /
   setup / battle / game-over screens. Layout split at 1024px:
     • Desktop (>=1024px): narrow skyscraper VRECs (160×600) on the side rails.
     • Mobile  (<=1023px): the Sticky_header top bar only — no side rails.
   The sticky footer / interstitial Fuse injects itself are positioned by Fuse. */

/* Hidden by default; the body.show-ads rules below opt each slot back in. */
#fuse-sticky-header,
#fuse-left-vrec,
#fuse-right-vrec { display: none; }

/* An empty (unfilled) ad slot must never intercept gameplay clicks — when shown
   in-game but not yet filled it's a transparent box over the map. Only a slot
   Fuse actually filled (body.fuse-has-*) re-enables pointer events for its ad. */
#fuse-sticky-header,
#fuse-left-vrec,
#fuse-right-vrec { pointer-events: none; }
body.fuse-has-sticky #fuse-sticky-header { pointer-events: auto; }
body.fuse-has-left   #fuse-left-vrec     { pointer-events: auto; }
body.fuse-has-right  #fuse-right-vrec    { pointer-events: auto; }

#fuse-left-vrec,
#fuse-right-vrec {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 160px;
  height: 600px;
  max-height: calc(100vh - 24px);
  /* Below the run-menu toggle (z 35) and sidebar (z 25) so the ad can never sit
     over the top-left menu button and block it — the reported unclickable-button
     bug, which showed up on shorter / zoomed viewports where the 600px column
     reached the top-left corner. */
  z-index: 20;
}
/* Flank the centered content column instead of pinning to the viewport edge, so
   each VREC sits beside the game rather than over the corner chrome. Clamp to a
   12px edge gutter on narrower screens (the body's 184px padding keeps the
   content clear of the clamped ad). 172 = 160px ad + 12px gap. */
#fuse-left-vrec  { left:  max(12px, calc(50% - 460px - 172px)); }
#fuse-right-vrec { right: max(12px, calc(50% - 460px - 172px)); }

/* Sticky header (MOBILE ONLY): a fixed top strip while in-game. We pin it
   ourselves so it reliably occupies the reserved strip. Its height is
   --ad-reserve, which is 0 until a creative actually fills the slot
   (body.fuse-has-sticky from the MutationObserver in index.html) — so when no ad
   loads there is NO empty gap and NO layout shift. When it IS filled,
   --ad-reserve becomes the strip height, body gets a matching padding-top, and
   every screen subtracts it from its height (see .screen / #map-screen), so the
   strip pushes the game down WITHOUT scrolling and WITHOUT overlapping it. */
body.show-ads { padding-top: var(--ad-reserve, 0px); }

body.show-ads #fuse-sticky-header {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 320px;
  max-width: 100vw;
  height: var(--ad-reserve, 0px);
  /* Above in-game chrome (floating quick-nav is z 250); below modals (z 300+). */
  z-index: 260;
}
/* Push the fixed top-right quick-nav below the ad strip (no-op until filled,
   since --ad-reserve is then 0). */
body.show-ads .map-menu-icons {
  top: calc(var(--safe-top) + 8px + var(--ad-reserve, 0px));
}

/* Mobile (<=1023px): the sticky top bar; reserve its strip only when filled. */
@media (max-width: 1023px) {
  body.show-ads #fuse-sticky-header { display: block; }
  body.show-ads.fuse-has-sticky { --ad-reserve: 90px; }
}

/* Desktop (>=1024px): the side VRECs; reserve rail space ONLY when a creative
   actually fills the slot. 184 = 160px ad + 24px gutter. (No top bar here.) */
@media (min-width: 1024px) {
  body.show-ads #fuse-left-vrec,
  body.show-ads #fuse-right-vrec { display: block; }
  body.show-ads.fuse-has-left  { padding-left: 184px; }
  body.show-ads.fuse-has-right { padding-right: 184px; }
}

/* --- Local preview placeholders (activate by appending ?adpreview=1) ---
   The script injects a .ad-preview-stub child into each side VREC so the
   MutationObserver fires (driving the body padding push) and so the slot is
   non-empty just like with a real Fuse iframe. The stub fills its slot
   and renders the dashed "AD" tile. */
.ad-preview-stub {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', monospace;
  color: #fff;
  text-align: center;
  white-space: pre-line;
  pointer-events: none;
  background: repeating-linear-gradient(
    45deg,
    rgba(80, 110, 170, 0.55),
    rgba(80, 110, 170, 0.55) 10px,
    rgba(120, 150, 210, 0.55) 10px,
    rgba(120, 150, 210, 0.55) 20px
  );
  border: 2px dashed rgba(255, 255, 255, 0.55);
  box-sizing: border-box;
  text-shadow: 1px 1px 0 #000;
  font-size: 9px;
  line-height: 1.8;
}
#fuse-left-vrec  .ad-preview-stub::before { content: "AD\ALeft VREC\A160 × 600"; }
#fuse-right-vrec .ad-preview-stub::before { content: "AD\ARight VREC\A160 × 600"; }

/* The sticky-header slot is positioned and sized by the body.show-ads rules
   above (the same path production uses); ?adpreview=1 just drops a stub inside
   it, which both fills the strip visually and trips the fuse-has-sticky
   fill-detection that turns --ad-reserve on. */
#fuse-sticky-header .ad-preview-stub { font-size: 8px; }
#fuse-sticky-header .ad-preview-stub::before { content: "AD — Sticky header"; }

/* ---- WT types modal ---- */
.wt-types-overlay {
  position: fixed; inset: 0; z-index: 220;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
}
.wt-types-box {
  background: #1a1230;
  border: 2px solid #d4af37;
  border-radius: 8px;
  padding: 14px 16px;
  max-width: min(90vw, 460px);
  font-family: 'Press Start 2P', monospace;
}
.wt-region-row { margin-bottom: 8px; }
.wt-types-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 3px 0 0;
}
.wt-types-pill {
  display: flex; gap: 4px; align-items: center; justify-content: space-between;
  padding: 4px 5px; border-radius: 4px;
  font-size: 7px; color: #fff; text-align: left;
  border: 1px solid rgba(255,255,255,0.2);
}
.wt-types-pill.defeated { opacity: 0.35; text-decoration: line-through; }
.wt-types-row-label { font-size: 8px; color: #d4af37; margin: 0; }

/* Map overview modal rows (story = gyms + Champion; tower = region bosses).
   Standard light game-modal styling, with done/current states. */
.league-modal-list { display: flex; flex-direction: column; }
.league-modal-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 2px solid var(--outline);
  background: #e8e4d8;
}
.league-modal-row:last-child { border-bottom: none; }
.league-modal-loc {
  flex: 1;
  min-width: 0;
  font-size: var(--text-xs);
  line-height: 1.5;
  color: var(--text-panel-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.league-modal-name {
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-main);
  white-space: nowrap;
}
.league-modal-check {
  width: 14px;
  text-align: center;
  font-size: var(--text-sm);
  color: #389838;
  flex-shrink: 0;
}
.league-modal-row.done { opacity: 0.55; }
.league-modal-row.done .league-modal-name { text-decoration: line-through; }
.league-modal-row.current { background: #f0e8c0; }
.league-modal-row.current .league-modal-check { color: #c89820; }
body.dark-mode .league-modal-row { background: #252118; border-bottom-color: #3a3428; }
body.dark-mode .league-modal-row.current { background: #2a2618; }
body.dark-mode .league-modal-name { color: #e0dcd0; }
body.dark-mode .league-modal-loc { color: #908878; }
body.dark-mode .league-modal-row.current .league-modal-check { color: #c8a800; }

/* ---- Passive items badge row ----
   Used in #passive-badges (map HUD) and #wt-passives-row (tournament view).
   Selectors are scoped on .passive-badge so both containers share styling. */
#wt-passives-row {
  display: flex; flex-wrap: wrap; gap: 3px;
  padding: 2px 4px;
}
/* #passive-badges mirrors #item-bar's grid + badge size so the items row and the
   passive-items row line up column-for-column. The two groups are separated by a
   top margin on the "PASSIVE ITEMS" label (desktop); on mobile that label is
   hidden, so #passive-badges itself takes the gap (see the mobile map block). */
.map-passives-label { margin-top: 12px; }
#passive-badges {
  display: grid; grid-template-columns: repeat(5, max-content);
  gap: 4px; align-items: center; justify-content: start;
}
.passive-badge {
  font-size: 12px; line-height: 1;
  padding: 2px 3px; border: 1px solid #d4af37;
  border-radius: 3px; background: rgba(212,175,55,0.15);
  position: relative; display: inline-block;
}
#passive-badges .passive-badge { font-size: 0; line-height: 0; padding: 3px; }
/* Disabled passive: muted icon + red diagonal strike + "OFF" tag so it's
   obvious at a glance which items the player has turned off. */
.passive-badge.disabled {
  border-color: #5a2424;
  background: rgba(90,36,36,0.25);
}
.passive-badge.disabled .item-sprite-icon {
  opacity: 0.35; filter: grayscale(1);
}
.passive-badge.disabled::after {
  content: ''; position: absolute; left: 0; right: 0; top: 50%;
  height: 2px; background: #ff5555; box-shadow: 0 0 3px #ff5555;
  transform: rotate(-22deg); pointer-events: none;
}
.passive-badge .off-tag {
  position: absolute; bottom: -4px; right: -4px;
  font-size: 7px; font-weight: bold; color: #ff7777;
  background: #1a0a0a; border: 1px solid #ff5555;
  padding: 0 2px; border-radius: 2px; line-height: 1.2;
  pointer-events: none;
}
#passive-screen { gap: 16px; justify-content: center; align-items: center; }
#passive-screen h2 { font-size: clamp(10px, 2.5vw, 14px); text-align: center; }
#passive-choices {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}
/* Passive-flavored item card — same shape as .item-card but gold-themed. */
.item-card.passive-card { border-color: #d4af37; }
.item-card.passive-card:hover { border-color: #ffe27a; box-shadow: 0 8px 24px rgba(212,175,55,0.45); }
.item-card.passive-card .item-name { color: #d4af37; }
.item-card.passive-card .item-tag  { font-size: 9px; color: #d4af37; }

/* Compact, centered Skip button shared by the item / passive choice screens.
   Sits on its own full-width row so it never stretches to card height or width
   at odd zoom levels. */
.choice-skip-row {
  flex-basis: 100%;
  display: flex;
  justify-content: center;
  margin-top: 4px;
}
.choice-skip-btn {
  width: auto;
  min-width: 130px;
  max-width: 260px;
  padding: 10px 28px;
  margin: 0;
  white-space: normal;
}

/* Passive bag-full replace screen: a clean 3×2 grid — four owned passives, the
   incoming item, then a Skip cell beside it. */
#passive-choices.is-replace-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
}
#passive-choices.is-replace-grid .item-card { width: auto; }
/* 5 owned passives + incoming + skip = 7 cells, so the skip would otherwise sit
   alone at the start of a third row. Span it across the full grid and centre it
   so it reads as a centred action below the cards. */
#passive-choices.is-replace-grid .choice-skip-cell {
  grid-column: 1 / -1;
  justify-self: center;
  width: auto;
  min-width: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
  font-weight: bold;
}
@media (max-width: 600px) {
  #passive-choices.is-replace-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ====== Challenge Runs interface ====== */
#challenge-select { align-items: center; padding-bottom: 28px; }
.chal-header {
  font-family: 'Press Start 2P', monospace;
  font-size: 15px; color: var(--gold);
  text-align: center; letter-spacing: 1px;
  text-shadow: 2px 2px 0 #000; margin-bottom: 6px;
}
.chal-sub { font-size: 9px; color: var(--text-dim); text-align: center; margin-bottom: 16px; }

/* Intro / Trial banner — the gateway run */
.chal-intro {
  width: min(560px, 92vw);
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; margin-bottom: 18px;
  border: 2px solid var(--gold); border-radius: 10px;
  background: linear-gradient(135deg, #2a1d05, #14110a);
  box-shadow: 0 0 14px rgba(212,175,55,0.22), inset 0 0 0 1px #000;
  cursor: pointer; transition: transform .15s, box-shadow .15s; text-align: left;
}
@media (hover: hover) { .chal-intro:hover { transform: translateY(-2px); box-shadow: 0 0 22px rgba(212,175,55,0.4); } }
.chal-intro.done { border-color: var(--green); box-shadow: 0 0 14px rgba(76,175,80,0.25); }
.chal-intro-icon { font-size: 34px; filter: drop-shadow(2px 2px 0 #000); }
.chal-intro-sprite {
  width: 96px; height: 96px; object-fit: contain;
  image-rendering: pixelated; flex: 0 0 auto;
  filter: drop-shadow(2px 2px 0 #000);
}
.chal-intro-body { flex: 1; }
.chal-intro-title { font-family: 'Press Start 2P', monospace; font-size: 11px; color: #fff; margin-bottom: 6px; }
.chal-intro-desc { font-size: 8px; color: var(--text-dim); line-height: 1.6; }
.chal-intro-cta {
  font-family: 'Press Start 2P', monospace; font-size: 9px;
  color: var(--gold); white-space: nowrap; align-self: center;
}
.chal-intro.done .chal-intro-cta { color: var(--green); }
.chal-intro--launch { margin-bottom: 16px; }

/* ---- Hall of Records (Challenge landing screen) ---- */
.chal-records {
  width: 100%; box-sizing: border-box;
  border: 2px solid var(--border); border-radius: 10px;
  background: linear-gradient(135deg, #1b1710, #121212);
  padding: 14px 16px;
}
.chal-records-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px; flex-wrap: wrap; margin-bottom: 12px;
  border-bottom: 1px solid var(--border); padding-bottom: 10px;
}
.chal-records-title { font-family: 'Press Start 2P', monospace; font-size: 10px; color: var(--gold); }
.chal-records-tally { font-size: 8px; color: var(--text-dim); }
.chal-rec-mvp {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin-bottom: 12px;
  border: 1px solid var(--gold); border-radius: 8px;
  background: linear-gradient(135deg, #2a1d05, #14110a);
}
.chal-rec-mvp-sprite {
  width: 56px; height: 56px; object-fit: contain;
  image-rendering: pixelated; flex: 0 0 auto;
  filter: drop-shadow(1px 1px 0 #000);
}
.chal-rec-mvp-label { font-family: 'Press Start 2P', monospace; font-size: 9px; color: var(--gold); margin-bottom: 5px; }
.chal-rec-mvp-sub { font-size: 8px; color: var(--text-dim); }
.chal-rec-list { display: flex; flex-direction: column; gap: 2px; }
.chal-rec-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 4px; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.chal-rec-row:last-child { border-bottom: none; }
.chal-rec-icon { font-size: 14px; flex: 0 0 auto; width: 18px; text-align: center; }
.chal-rec-label { flex: 1; font-size: 9px; color: var(--text-dim); }
.chal-rec-val {
  display: flex; flex-direction: column; align-items: flex-end;
  font-family: 'Press Start 2P', monospace; font-size: 9px; color: #fff; text-align: right;
}
.chal-rec-sub { font-family: inherit; font-size: 7px; color: var(--text-dim); margin-top: 3px; }

/* ---- Post-run recap (stage-complete + game-over screens) ---- */
.run-stats-summary {
  width: min(520px, 92vw); margin: 12px auto;
  border: 2px solid var(--gold); border-radius: 10px;
  background: linear-gradient(135deg, #1b1710, #121212);
  padding: 14px 16px; box-sizing: border-box;
}
.run-stats-head {
  font-family: 'Press Start 2P', monospace; font-size: 10px; color: var(--gold);
  text-align: center; margin-bottom: 12px;
}
.run-score {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 12px; margin-bottom: 12px;
  border: 2px solid var(--border); border-radius: 8px;
  background: linear-gradient(135deg, #15202e, #101319);
}
.run-score.is-record { border-color: var(--gold); box-shadow: 0 0 14px rgba(212,175,55,0.35); }
.run-score-label { font-family: 'Press Start 2P', monospace; font-size: 8px; color: var(--text-dim); letter-spacing: 1px; }
.run-score-value { font-family: 'Press Start 2P', monospace; font-size: 22px; color: #fff; text-shadow: 0 0 10px rgba(212,175,55,0.5); }
.run-score-value--help { cursor: help; }
.run-score-earned { font-size: var(--text-sm); color: var(--gold); font-weight: 700; }
.run-score-breakdown {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px;
  font-size: 8px; color: var(--text-dim); margin-top: 2px;
}
.run-score-breakdown b { color: #fff; font-weight: normal; }
.run-mvp {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 12px; margin-bottom: 12px;
  border: 1px solid var(--gold); border-radius: 8px;
  background: linear-gradient(135deg, #2a1d05, #14110a);
}
.run-mvp-crown { font-family: 'Press Start 2P', monospace; font-size: 10px; color: var(--gold); }
.run-mvp-sprite {
  width: 88px; height: 88px; object-fit: contain;
  image-rendering: pixelated; filter: drop-shadow(2px 2px 0 #000);
}
.run-mvp-name { font-family: 'Press Start 2P', monospace; font-size: 10px; color: #fff; }
.run-mvp-line { font-size: 8px; color: var(--text-dim); }
.run-stat-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px;
}
@media (max-width: 480px) { .run-stat-grid { grid-template-columns: repeat(2, 1fr); } }
.run-stat-cell {
  position: relative; display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 10px 6px;
  border: 1px solid var(--border); border-radius: 8px;
  background: linear-gradient(135deg, #1d1d1d, #121212); text-align: center;
}
.run-stat-cell.is-record { border-color: var(--gold); box-shadow: 0 0 10px rgba(212,175,55,0.3); }
.run-stat-icon { font-size: 16px; }
.run-stat-value { font-family: 'Press Start 2P', monospace; font-size: 11px; color: #fff; }
.run-stat-label { font-size: 7px; color: var(--text-dim); }
.run-stat-sub { font-size: 7px; color: var(--text-dim); line-height: 1.4; }
.run-stat-record {
  margin-top: 2px; font-size: 6px; color: #14110a; font-weight: bold;
  background: var(--gold); border-radius: 3px; padding: 2px 4px; letter-spacing: .5px;
}
.run-passives {
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border);
}
.run-passives-head {
  font-size: 8px; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 1px; text-align: center; margin-bottom: 8px;
}
.run-passives-list {
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
}
.run-passive {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--border); border-radius: 6px;
  background: linear-gradient(135deg, #1d1d1d, #121212);
  padding: 4px 8px;
}
.run-passive img { image-rendering: pixelated; }
.run-passive-name { font-size: 8px; color: #fff; }

/* ---- Mobile: run recap + Hall of Records ---- */
@media (max-width: 600px) {
  .run-stats-summary { width: 94vw; padding: 12px 10px; margin: 10px auto; }
  .run-stats-head { font-size: 9px; margin-bottom: 10px; }
  .run-score { padding: 12px 8px; }
  .run-score-value { font-size: 18px; }
  .run-score-breakdown { font-size: 7px; gap: 4px 10px; }
  .run-stat-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .run-stat-cell { padding: 8px 5px; }
  .run-stat-value { font-size: 10px; }
  .run-mvp { padding: 10px; }
  .run-mvp-sprite { width: 72px; height: 72px; }
  .run-mvp-crown, .run-mvp-name { font-size: 9px; }
  .run-passive { padding: 3px 6px; gap: 3px; }
  .run-passive-name { font-size: 7px; }

  .chal-records { padding: 12px 10px; }
  .chal-records-head { margin-bottom: 10px; padding-bottom: 8px; }
  .chal-records-title { font-size: 9px; }
  .chal-records-tally { font-size: 7px; }
  .chal-rec-mvp { padding: 8px 10px; gap: 10px; }
  .chal-rec-mvp-sprite { width: 46px; height: 46px; }
  .chal-rec-mvp-label { font-size: 8px; }
  .chal-rec-label { font-size: 8px; }
  .chal-rec-val { font-size: 8px; }

  /* The recap makes these end screens taller than the viewport on phones —
     let them scroll from the top instead of clipping centered content. */
  #endless-stage-complete, #gameover-screen {
    justify-content: flex-start; overflow-y: auto;
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: calc(24px + var(--safe-bottom));
  }
}

/* Challenge card grid — the whole screen scrolls, so the grid itself never
   clips a card row (an inner max-height would cut text at the boundary). */
.chal-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px; width: min(560px, 92vw); padding: 4px;
}
@media (max-width: 520px) { .chal-grid { grid-template-columns: 1fr; } }
/* Challenge screen reuses the Battle Tower / Story select panel + top bar, just
   a touch wider so its two-column grid fits. */
.chal-panel { max-width: 580px; }
.chal-panel .chal-intro,
.chal-panel .chal-grid {
  width: 100%;
  margin-left: 0;
  margin-right: 0;
}
.chal-card {
  position: relative; display: flex; flex-direction: column; gap: 6px;
  padding: 12px; text-align: left;
  border: 2px solid var(--border); border-radius: 10px;
  background: linear-gradient(135deg, #1d1d1d, #121212);
  cursor: pointer; transition: transform .15s, border-color .15s, box-shadow .15s;
  overflow: hidden;
}
@media (hover: hover) { .chal-card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 0 12px rgba(200,152,32,0.25); } }
.chal-card.done { border-color: var(--green); }
.chal-card.locked { cursor: not-allowed; opacity: .55; }
.chal-card.locked:hover { transform: none; border-color: var(--border); box-shadow: none; }
.chal-card-top { display: flex; align-items: center; gap: 8px; }
.chal-card-icon { font-size: 22px; filter: drop-shadow(1px 1px 0 #000); }
.chal-card-sprite {
  width: 80px; height: 80px; object-fit: contain;
  image-rendering: pixelated; flex: 0 0 auto;
  filter: drop-shadow(1px 1px 0 #000);
}
.chal-card-name { flex: 1; font-family: 'Press Start 2P', monospace; font-size: 9px; color: #fff; line-height: 1.4; }
.chal-card-desc { font-size: 8px; color: var(--text-dim); line-height: 1.55; }
.chal-card-badge { font-size: 8px; margin-top: 2px; }
.chal-card-badge.done { color: var(--green); }
.chal-card-badge.todo { color: var(--text-dim); }
.chal-card-badge.mono { color: var(--accent); }
.chal-lock-overlay {
  position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center;
  font-size: 24px; background: rgba(0,0,0,0.5); backdrop-filter: blur(1px);
}

/* Monotype sub-menu — grid of type tiles (page scrolls, no inner clip) */
#monotype-select { align-items: center; padding-bottom: 28px; }
.mono-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px; width: min(470px, 92vw); padding: 4px;
}
@media (max-width: 400px) { .mono-grid { grid-template-columns: repeat(2, 1fr); } }
.mono-tile {
  position: relative; display: flex; flex-direction: column;
  align-items: center; gap: 7px; padding: 13px 8px;
  border: 2px solid var(--border); border-radius: 10px;
  background: linear-gradient(135deg, #1d1d1d, #121212);
  cursor: pointer; transition: transform .15s, border-color .15s, box-shadow .15s;
}
@media (hover: hover) { .mono-tile:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 0 12px rgba(200,152,32,0.25); } }
.mono-tile.done { border-color: var(--green); }
.mono-tile .type-badge { font-size: 9px; padding: 3px 10px; }
.mono-tile-status { font-size: 8px; color: var(--text-dim); }
.mono-tile.done .mono-tile-status { color: var(--green); }
.mono-tile-check { position: absolute; top: 5px; right: 7px; font-size: 10px; color: var(--green); }

/* ---- Reset-run loading gate (2s spinner before the run is wiped) ---- */
#reset-loading-overlay {
  position: fixed; inset: 0; z-index: 400;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; background: rgba(0, 0, 0, 0.82);
}
#reset-loading-overlay .reset-spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--gold);
  animation: spin 0.8s linear infinite;
}
#reset-loading-overlay .reset-loading-text {
  font-family: 'Press Start 2P', monospace; font-size: 11px;
  color: var(--gold); letter-spacing: 1px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Floating quick-nav overlay, pinned top-right on every run screen. It's a
   top-level element (not inside #map-screen), so it's hidden by default and
   shown only during a run — and never over the full-screen battle. */
.map-menu-icons {
  position: fixed;
  top: calc(var(--safe-top) + 8px);
  right: calc(var(--safe-right) + 8px);
  z-index: 250;
  display: none;
  /* Vertical column on every breakpoint. */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 6px;
  margin: 0;
  padding: 4px 6px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 8px;
}
/* Always visible except during the full-screen battle. */
body:not(.in-battle) .map-menu-icons { display: flex; }
/* Context buttons: Map/Reset/Exit only in a run; Poké Mart only outside one. */
body:not(.run-menu-in-run) .map-menu-icons .nav-in-run { display: none; }
body.run-menu-in-run .map-menu-icons .nav-out-of-run { display: none; }
.map-menu-icons .btn-icon-sm img { height: 22px; } /* native size — no scaling blur */
/* Fullscreen button: inline SVG (no PNG asset) sized to match the icon row.
   The compress icon shows only while fullscreen is active (body.is-fullscreen). */
.map-menu-fs-icon { display: block; width: 22px; height: 22px; color: #f3f3f7; }
.fs-icon-compress { display: none; }
body.is-fullscreen .map-menu-icons .fs-icon-expand { display: none; }
body.is-fullscreen .map-menu-icons .fs-icon-compress { display: block; }
/* Hover label beside each menu icon — retro tooltip look (same palette as the
   item/map tooltips). data-tip is filled per-language via data-i18n-attr.
   The bar is a vertical column on the right edge, so the label sits to the LEFT
   of each icon (vertically centred) — clear of the icons above and below. */
.map-menu-icons .btn-icon-sm { position: relative; }
@media (hover: hover) {
  .map-menu-icons .btn-icon-sm:hover::after {
    content: attr(data-tip);
    position: absolute;
    top: 50%;
    right: calc(100% + 7px);
    transform: translateY(-50%);
    background: #0e0b06;
    border: 1px solid #c8b070;
    color: var(--text);
    font-size: var(--text-xs);
    line-height: 1.4;
    padding: 4px 6px;
    white-space: nowrap;
    box-shadow: 2px 2px 0 0 #000;
    pointer-events: none;
    z-index: 300;
  }
}
.run-menu-btn-icon { height: 1.1em; width: auto; vertical-align: -0.15em; margin-right: 4px; image-rendering: pixelated; }

/* ── Poké Mart (Pokédollar shop) ─────────────────────────────────────────── */
/* Pokédollar symbol — a bold "P" with a horizontal bar, drawn in CSS so it
   inherits whatever colour the surrounding text uses. Swap for an <img> later
   if a dedicated sprite is supplied. */
.pdollar {
  display: inline-block;
  position: relative;
  font-weight: 800;
  font-style: normal;
  margin-right: 0.18em;
}
.pdollar::before { content: "P"; }
.pdollar::after {
  content: "";
  position: absolute;
  left: -0.04em;
  right: 0.30em;
  top: 0.46em;
  border-top: 0.13em solid currentColor;
}

.game-modal-header--shop { background: #2a1d05; }
.game-modal-header--shop .game-modal-title { color: #ffe27a; }
.game-modal-header--shop .game-modal-desc { color: #d4af37; }

/* Wallet banner */
.mart-wallet {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 14px 16px 6px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #3a2d08, #1a1408);
  border: 2px solid var(--gold);
  box-shadow: 3px 3px 0 0 var(--outline);
}
.mart-wallet-label {
  font-size: var(--text-xs);
  color: #d4af37;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.mart-wallet-amount { font-size: var(--text-lg); color: var(--gold); font-weight: 800; }

/* Egg cards */
.mart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 8px 16px 16px;
}
.mart-egg {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 14px 12px;
  border: 2px solid var(--outline);
  background: #e8e4d8;
  box-shadow: 3px 3px 0 0 var(--outline);
}
.mart-egg--shiny  { border-color: #4aa3ff; }
.mart-egg--legend { border-color: var(--gold); }
.mart-egg-art {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 84px;
  height: 84px;
}
.mart-egg-icon { width: 76px; height: 76px; image-rendering: pixelated; }
.mart-egg-name { font-size: var(--text-sm); color: var(--text-main); font-weight: 700; }
.mart-egg-desc { font-size: var(--text-xs); color: var(--text-panel-muted); line-height: 1.5; flex: 1; }
.mart-egg-refund { font-size: var(--text-xs); color: var(--text-panel-muted); opacity: 0.85; }
.mart-buy {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  white-space: nowrap;
}
/* Readable on the cream button (light) and the dark button (dark mode). */
.mart-buy-price { color: #8a6a12; font-weight: 800; }

body.dark-mode .mart-egg { background: #252118; }
body.dark-mode .mart-egg-name { color: #e0dcd0; }
body.dark-mode .mart-egg-desc,
body.dark-mode .mart-egg-refund { color: #908878; }
body.dark-mode .mart-buy-price { color: var(--gold); }

/* Vitamins */
.mart-section-title {
  font-size: var(--text-sm);
  font-weight: 800;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 4px 16px 0;
}
.mart-section-desc {
  font-size: var(--text-xs);
  color: var(--text-panel-muted);
  line-height: 1.5;
  margin: 2px 16px 8px;
}
.mart-vitamin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  padding: 0 16px 16px;
}
.mart-vitamin {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border: 2px solid var(--outline);
  background: #e8e4d8;
  box-shadow: 3px 3px 0 0 var(--outline);
  cursor: pointer;
}
.mart-vitamin:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 0 var(--outline); }
.mart-vitamin:active { transform: translate(1px, 1px); box-shadow: 2px 2px 0 0 var(--outline); }
.mart-vitamin-art {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
}
.mart-vitamin-icon { width: 32px; height: 32px; image-rendering: pixelated; }
.mart-vitamin-name { font-size: var(--text-sm); color: var(--text-main); font-weight: 700; }
.mart-vitamin-stat { font-size: var(--text-xs); color: var(--text-panel-muted); }
.mart-vitamin-price { font-size: var(--text-xs); color: #8a6a12; font-weight: 800; }
body.dark-mode .mart-vitamin { background: #252118; }
body.dark-mode .mart-vitamin-name { color: #e0dcd0; }
body.dark-mode .mart-vitamin-price { color: var(--gold); }

/* Vitamin (EV) apply modal — Hall of Fame PC grid */
.vitamin-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 16px 4px;
  padding: 8px 14px;
  background: linear-gradient(135deg, #3a2d08, #1a1408);
  border: 2px solid var(--gold);
  box-shadow: 3px 3px 0 0 var(--outline);
}
.vitamin-bar-info { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); color: #d4af37; font-weight: 700; }
.vitamin-bar-icon { width: 22px; height: 22px; image-rendering: pixelated; vertical-align: middle; }
.vitamin-bar-wallet { font-size: var(--text-xs); color: #d4af37; }
.vitamin-bar-wallet b { color: var(--gold); }
.vitamin-bar--poor { animation: vitamin-bar-shake 0.4s; border-color: #e05050; }
@keyframes vitamin-bar-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}
.vitamin-cap-note {
  font-size: var(--text-xs);
  color: var(--text-panel-muted);
  margin: 0 16px 6px;
}
/* Reuse the Hall of Fame PC chrome, but let it fit inside the modal box. */
.pc-box.vitamin-modal-pc {
  width: auto;
  height: min(56vh, 440px);
  max-height: none;
  margin: 0 16px 16px;
}
/* The vitamin "apply" PC is a narrower (md) modal than the starter PC, so the
   default 6 fixed columns squeeze the cards (and their EV badges) too tight.
   Fit as many ~100px cards as the modal width allows instead. */
.pc-box.vitamin-modal-pc .dex-grid {
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}
.vitamin-card { cursor: pointer; }
.vitamin-ev-badge {
  font-size: var(--text-xs);
  color: #9fb3d9;
  line-height: 1.3;
  margin-top: 2px;
}
.vitamin-ev-badge b { color: #8fd0ff; }
.pc-box .vitamin-card--done { opacity: 0.5; cursor: default; }
.pc-box .vitamin-card--done:hover { background: #1B2B52; border-color: #31487F; box-shadow: none; }
.vitamin-card--done .vitamin-ev-badge b { color: gold; }

@media (max-width: 480px) {
  .mart-grid { grid-template-columns: 1fr; }
  .mart-vitamin-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Egg-cracking reveal overlay ────────────────────────────────────────── */
.egg-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: rgba(8, 6, 14, 0.92);
  cursor: pointer;
}
.egg-stage {
  position: relative;
  width: 210px;
  height: 210px;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Real PokeAPI egg sprite. */
.egg-shape {
  width: 172px;
  height: 172px;
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5));
}
.egg-shaking { animation: egg-wobble 0.5s ease-in-out 3; }
@keyframes egg-wobble {
  0%, 100% { transform: rotate(0deg) translateY(0); }
  20% { transform: rotate(-9deg) translateY(-2px); }
  60% { transform: rotate(9deg) translateY(-2px); }
}
/* Crack/burst: a quick scale-up flash before the sprite reveal. */
.egg-cracked { animation: egg-burst 0.45s ease-out forwards; }
@keyframes egg-burst {
  0%   { transform: scale(1); filter: brightness(1); }
  40%  { transform: scale(1.25) rotate(4deg); filter: brightness(1.8); }
  100% { transform: scale(1.6); filter: brightness(3); opacity: 0; }
}
.egg-reveal-sprite {
  position: absolute;
  width: 170px;
  height: 170px;
  image-rendering: pixelated;
  opacity: 0;
  transform: scale(0.4);
}
.egg-reveal-sprite.egg-revealed {
  animation: egg-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.egg-reveal-sprite.shiny { filter: drop-shadow(0 0 14px gold); }
@keyframes egg-pop {
  0%   { opacity: 0; transform: scale(0.4); }
  100% { opacity: 1; transform: scale(1); }
}
.egg-result { text-align: center; min-height: 40px; }
.egg-name { font-size: var(--text-lg); color: #fff; line-height: 1.5; }
.egg-new  { font-size: var(--text-xl); color: var(--gold); margin-top: 4px; animation: shimmer 1s ease-in-out infinite alternate; }
.egg-dup  { font-size: var(--text-sm); color: #8fd0ff; margin-top: 4px; }
.egg-hint { font-size: var(--text-xs); color: var(--text-dim); transition: opacity 0.3s; }
