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

/* ─── TOKENS ─────────────────────────────────────────────── */
:root {
  --black:      #0f0f0f;
  --darkgray:   #2d2d2d;
  --gray:       #4a4a4a;
  --lightgray:  #8a8a8a;
  --white:      #e8e8e8;
  --cream:      #f0e8c8;
  --dark-bg:    #1a1a2e;
  --red:        #c8003a;
  --red-hover:  #e0004a;
  --blue:       #0050a0;
  --blue-hover: #0068c8;
  --green:      #008a1e;
  --green-hover:#00b026;
  --yellow:     #f8c030;
  --dialog-bg:  #f0e8c8;
  --dialog-bd:  #202040;
  --hp-green:   #50c020;
  --hp-yellow:  #c8b000;
  --font:       'Press Start 2P', monospace;
  --app-w:      420px;
  --app-h:      680px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* GBA controller palette */
  --gba-body:   #6a5acd;
  --gba-dark:   #3d2f99;
  --gba-ab-a:   #e83030;
  --gba-ab-b:   #2060d0;
  --gba-dpad:   #1a1a2e;
}

/* ─── RESET ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Prevent text selection and touch callouts everywhere in the game */
html, body, #app {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ─── BODY ───────────────────────────────────────────────── */
html, body {
  height: 100%;
  overflow: hidden;
  background: #12082a;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(80,0,120,.35) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 50%, rgba(0,40,120,.35) 0%, transparent 55%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
}

/* ─── APP SHELL ──────────────────────────────────────────── */
#app {
  position: relative;
  width: min(var(--app-w), 100vw);
  height: min(var(--app-h), 100dvh);
  background: var(--dark-bg);
  overflow: hidden;
  border: 5px solid #111;
  border-radius: 6px;
  box-shadow: 0 0 0 2px #333, 0 0 40px rgba(100,80,200,.55), 0 0 90px rgba(80,60,180,.25);
}
#app::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0px, transparent 2px, rgba(0,0,0,.045) 2px, rgba(0,0,0,.045) 4px);
  pointer-events: none;
  z-index: 900;
}

/* ─── MOBILE FULL-SCREEN ─────────────────────────────────── */
@media (max-width: 480px), (max-height: 720px) {
  html, body { align-items: flex-start; }
  #app { width: 100vw; height: 100dvh; border: none; border-radius: 0; box-shadow: none; }
}

/* ─── SCREENS ────────────────────────────────────────────── */
.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ─── ANIMATIONS ─────────────────────────────────────────── */
@keyframes blink        { 0%,100%{opacity:1}50%{opacity:0} }
@keyframes fadeIn       { from{opacity:0}to{opacity:1} }
@keyframes slideUp      { from{transform:translateY(16px);opacity:0}to{transform:translateY(0);opacity:1} }
@keyframes bounce       { 0%,100%{transform:translateY(0)}50%{transform:translateY(-7px)} }
@keyframes pop          { 0%{transform:scale(.5);opacity:0}65%{transform:scale(1.08)}100%{transform:scale(1);opacity:1} }
@keyframes goldShimmer  { 0%,100%{color:#f8c030;text-shadow:0 0 8px #f8c030}50%{color:#ffe878;text-shadow:0 0 18px #ffe878,0 0 36px #f8c030} }
@keyframes blueShimmer  { 0%,100%{color:#60c8ff;text-shadow:4px 4px 0 #003d70,0 0 12px #60c8ff}50%{color:#a0e0ff;text-shadow:4px 4px 0 #003d70,0 0 24px #a0e0ff,0 0 48px #60c8ff} }
@keyframes correctPulse { 0%,100%{background:#c8ffc8;border-color:var(--green)}50%{background:#e0ffe0} }
@keyframes wrongShake   { 0%,100%{transform:translateX(0)}25%{transform:translateX(-5px)}75%{transform:translateX(5px)} }
@keyframes npcFloat     { 0%,100%{transform:translateY(0)}50%{transform:translateY(-8px)} }
@keyframes treeSway     { 0%,100%{transform:rotate(-2deg)}50%{transform:rotate(2deg)} }
/* Sprite walk — player.png 384x32px, 24 frames at 16x32px each
   Layout: 0-2=down  3-5=up  6-8=left  9-11=right */
@keyframes walkDown  { from{background-position-x:   0px} to{background-position-x:  -96px} }
@keyframes walkLeft  { from{background-position-x: -96px} to{background-position-x: -192px} }
@keyframes walkUp    { from{background-position-x:-192px} to{background-position-x: -288px} }
@keyframes walkRight { from{background-position-x:-288px} to{background-position-x: -384px} }
@keyframes dpadPress    { 0%{transform:scale(1)}50%{transform:scale(.88)}100%{transform:scale(1)} }
@keyframes abPress      { 0%{transform:scale(1)}40%{transform:scale(.82)}100%{transform:scale(1)} }
@keyframes choiceCursor { 0%,100%{box-shadow:0 0 0 3px var(--yellow), 2px 2px 0 var(--darkgray)}50%{box-shadow:0 0 0 3px #ffe878, 2px 2px 0 var(--darkgray)} }
@keyframes talkBubble   { 0%{transform:translateY(0)}50%{transform:translateY(-3px)} }
@keyframes arrowPulse   { 0%,100%{transform:scale(1) translateX(0)} 50%{transform:scale(1.25) translateX(4px)} }

.blink { animation: blink 1s step-end infinite; }

/* ─── DIALOG BOX ─────────────────────────────────────────── */
.dialog-box {
  background: var(--dialog-bg);
  border: 4px solid var(--dialog-bd);
  position: relative;
  padding: 16px 14px 12px;
  flex-shrink: 0;
}
.dialog-box::before {
  content: '';
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(255,255,255,.45);
  pointer-events: none;
}
.dialog-speaker {
  font-size: 7px;
  color: var(--black);
  background: var(--dialog-bg);
  border: 3px solid var(--dialog-bd);
  padding: 3px 8px;
  position: absolute;
  top: -16px;
  left: 10px;
  white-space: nowrap;
  letter-spacing: .5px;
}
.dialog-text {
  font-size: clamp(6.5px, 1.8vw, 8px);
  line-height: 2;
  color: var(--black);
  padding-top: 2px;
  min-height: 52px;
}
.dialog-arrow { font-size: 10px; color: var(--black); text-align: right; margin-top: 4px; }

/* ─── PIXEL BUTTONS ──────────────────────────────────────── */
.btn-pixel {
  display: inline-block;
  font-family: var(--font);
  font-size: clamp(7px, 2vw, 9px);
  padding: 10px 16px;
  border: 3px solid var(--black);
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--black);
  transition: transform .05s, box-shadow .05s;
  letter-spacing: .5px;
  color: var(--white);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn-pixel:active { transform: translate(3px,3px); box-shadow: none; }
.btn-blue  { background: var(--blue);  } .btn-blue:hover  { background: var(--blue-hover); }
.btn-green { background: var(--green); } .btn-green:hover { background: var(--green-hover); }
.btn-red   { background: var(--red);   } .btn-red:hover   { background: var(--red-hover); }
.btn-full  { width: 100%; text-align: center; }

/* ─── OVERWORLD BG ───────────────────────────────────────── */
.overworld-bg {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    repeating-linear-gradient(0deg,   transparent 0,transparent 31px, rgba(0,80,0,.12) 31px, rgba(0,80,0,.12) 32px),
    repeating-linear-gradient(90deg,  transparent 0,transparent 31px, rgba(0,80,0,.12) 31px, rgba(0,80,0,.12) 32px),
    linear-gradient(180deg, #6cb84e 0%, #58a83e 100%);
  background-position: 16px 16px, 16px 16px, 0 0;
}

/* ═══════════════════════════════════════════════════════════
   GBA CONTROLLER OVERLAY
   Sits outside #app, fixed to viewport bottom.
   Shown only when screen === 'map' or 'battle'.
   ═══════════════════════════════════════════════════════════ */
.gba-controller {
  display: flex;
  align-items: center;
  background: linear-gradient(180deg, rgba(26,10,62,.82) 0%, rgba(14,6,36,.95) 100%);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 800;
  user-select: none;
  touch-action: none;
  pointer-events: auto;
}
.gba-controller.hidden { display: none; }

/* ── PORTRAIT: two panels fixed at bottom ── */
@media (orientation: portrait) {
  #gba-left, #gba-right {
    position: fixed;
    bottom: 0;
    height: clamp(110px, 22vw, 148px);
    flex-direction: row;
    border-top: 2px solid rgba(120,80,255,.35);
  }

  #gba-left {
    left: 0;
    width: 65%;
    justify-content: space-evenly;
    align-items: center;
    padding: 0 8px max(8px,var(--safe-bottom)) clamp(8px,3vw,20px);
  }

  #gba-right {
    right: 0;
    width: 35%;
    justify-content: center;
    padding: 0 clamp(8px,3vw,20px) max(8px,var(--safe-bottom)) 8px;
  }

  #gba-left .gba-mid-btns {
    flex-direction: row;
    gap: 6px;
    margin-top: 0;
    width: auto;
    justify-content: center;
  }
}

@media (min-width: 900px) {
  .gba-controller { display: none !important; }
}

/* ── D-PAD ───────────────────────────────────────────────── */
.dpad {
  position: relative;
  width:  clamp(90px, 21vw, 120px);
  height: clamp(90px, 21vw, 120px);
  flex-shrink: 0;
}
.dpad-btn {
  position: absolute;
  background: var(--gba-dpad);
  border: 2px solid rgba(255,255,255,.18);
  color: rgba(255,255,255,.75);
  font-size: clamp(8px, 2.2vw, 11px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  transition: background .08s;
}
.dpad-btn:active, .dpad-btn.pressed {
  background: #3a3a6e;
  animation: dpadPress .15s ease;
}

/* Cross layout: 3×3 grid conceptually */
.dpad-up    { top:0;         left:33.3%;  width:33.4%; height:33.4%; border-radius:4px 4px 0 0; }
.dpad-down  { bottom:0;      left:33.3%;  width:33.4%; height:33.4%; border-radius:0 0 4px 4px; }
.dpad-left  { top:33.3%;     left:0;      width:33.4%; height:33.4%; border-radius:4px 0 0 4px; }
.dpad-right { top:33.3%;     right:0;     width:33.4%; height:33.4%; border-radius:0 4px 4px 0; }
.dpad-center{ top:33.3%;     left:33.3%;  width:33.4%; height:33.4%; background:#111; border:none; cursor:default; }

/* ── SELECT / START (center strip) ─────────────────────────  */
.gba-mid-btns {
  display: flex;
  flex-direction: row;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 12px;
  width: 100%;
}
.gba-mid-btn {
  background: #2a1a5e;
  border: 2px solid rgba(255,255,255,.2);
  border-radius: 30px;
  color: rgba(255,255,255,.6);
  font-family: var(--font);
  font-size: clamp(4.5px, 1.2vw, 6px);
  padding: clamp(8px, 2vw, 11px) clamp(6px, 1.5vw, 10px);
  cursor: pointer;
  letter-spacing: .5px;
  -webkit-tap-highlight-color: transparent;
  transition: background .08s;
  min-width: 56px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gba-mid-btn:active { background: #3d2f99; }

/* ── A / B BUTTONS ───────────────────────────────────────── */
.ab-cluster {
  position: relative;
  width:  clamp(90px, 21vw, 120px);
  height: clamp(90px, 21vw, 120px);
  flex-shrink: 0;
}
.ab-btn {
  position: absolute;
  width:  clamp(36px, 9vw, 48px);
  height: clamp(36px, 9vw, 48px);
  border-radius: 50%;
  border: 3px solid rgba(0,0,0,.5);
  font-family: var(--font);
  font-size: clamp(9px, 2.5vw, 13px);
  font-weight: bold;
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 0 rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.3);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  transition: transform .06s, box-shadow .06s;
}
.ab-btn:active, .ab-btn.pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.2);
  animation: abPress .18s ease;
}
/* B = left, A = right (classic GBA layout) */
.ab-b { background: radial-gradient(circle at 35% 35%, #4080ff, var(--gba-ab-b)); bottom: 14%; left: 5%; }
.ab-a { background: radial-gradient(circle at 35% 35%, #ff5555, var(--gba-ab-a)); top: 14%;    right: 5%; }

/* label under each button */
.ab-btn::after {
  content: attr(id) == 'btn-a' ? 'A' : 'B';
  position: absolute;
  bottom: -14px;
  font-size: 5px;
  color: rgba(255,255,255,.4);
  letter-spacing: 1px;
}

/* ─── BOOT ───────────────────────────────────────────────── */
#screen-boot { background: #f8f0ff; align-items: center; justify-content: center; animation: fadeIn .4s ease; }
.boot-logo { text-align: center; display:flex; flex-direction:column; align-items:center; gap:12px; }
.boot-gameboy { font-size: clamp(22px,7vw,36px); font-weight:bold; color: #4a0e8f; letter-spacing: 3px; text-shadow: 2px 2px 0 rgba(0,0,0,.1); }
.boot-gameboy sup { font-size:50%; vertical-align:super; }
.boot-ding    { font-size: 28px; animation: goldShimmer 1.5s ease-in-out infinite; }

/* ─── TITLE ──────────────────────────────────────────────── */
#screen-title { background: linear-gradient(180deg,#08031a 0%,#180a44 45%,#240e6a 75%,#120538 100%); overflow: hidden; }
.title-bg { position:relative; width:100%; height:100%; display:flex; flex-direction:column; align-items:center; justify-content:center; }
.title-stars {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1px 1px at 8%  12%, #fff 100%,transparent),
    radial-gradient(1px 1px at 22% 38%, #fff 100%,transparent),
    radial-gradient(1px 1px at 43% 8%,  #fff 100%,transparent),
    radial-gradient(1px 1px at 58% 28%, #fff 100%,transparent),
    radial-gradient(1px 1px at 73% 14%, #fff 100%,transparent),
    radial-gradient(1px 1px at 87% 42%, #fff 100%,transparent),
    radial-gradient(1px 1px at 33% 62%, rgba(255,255,255,.5) 100%,transparent),
    radial-gradient(1px 1px at 52% 72%, rgba(255,255,255,.5) 100%,transparent),
    radial-gradient(2px 2px at 18% 82%, rgba(255,220,100,.8) 100%,transparent),
    radial-gradient(2px 2px at 78% 78%, rgba(255,220,100,.8) 100%,transparent);
}
.title-main { text-align:center; z-index:1; padding:24px 16px; }
.title-logo { margin-bottom:16px; line-height:1; }
.title-poke { font-size:clamp(22px,7.5vw,38px); color:var(--yellow); text-shadow:4px 4px 0 #7a5800,0 0 24px rgba(248,192,48,.5); animation:goldShimmer 3s ease-in-out infinite; display:inline-block; }
.title-game  { font-size:clamp(22px,7.5vw,38px); color:#60c8ff; text-shadow:4px 4px 0 #003d70,0 0 24px rgba(96,200,255,.5); display:inline-block; animation:blueShimmer 3s ease-in-out infinite; }
.title-sub  { font-size:clamp(6px,1.8vw,8px); color:rgba(255,255,255,.75); letter-spacing:1px; margin:10px 0 6px; }
.title-edition { font-size:clamp(5.5px,1.6vw,7px); color:var(--yellow); margin-bottom:24px; animation:goldShimmer 3s ease-in-out infinite; }
.title-deco { font-size:clamp(22px,6vw,32px); margin-bottom:28px; display:flex; gap:16px; justify-content:center; }
.title-deco span:nth-child(1){animation:npcFloat 2.0s ease-in-out infinite;}
.title-deco span:nth-child(2){animation:npcFloat 2.4s ease-in-out infinite;}
.title-deco span:nth-child(3){animation:npcFloat 2.8s ease-in-out infinite;}
.title-tap  { font-size:clamp(7px,2vw,9px); color:var(--white); letter-spacing:1px; }
.title-footer { position:absolute; bottom:max(12px,var(--safe-bottom)); font-size:6px; color:rgba(255,255,255,.3); letter-spacing:.5px; }

/* ─── CONTINUE ───────────────────────────────────────────── */
#screen-continue { background:linear-gradient(180deg,#08031a 0%,#180a44 100%); align-items:center; justify-content:center; }
.continue-bg { width:90%; max-width:340px; display:flex; flex-direction:column; align-items:center; gap:16px; animation:fadeIn .5s ease; }
.continue-logo { font-size:clamp(16px,5vw,22px); color:var(--yellow); text-shadow:3px 3px 0 #7a5800; animation:goldShimmer 3s ease-in-out infinite; }
.continue-logo span { color:#60c8ff; text-shadow:3px 3px 0 #003d70; }
.continue-card { width:100%; background:var(--dialog-bg); border:4px solid var(--dialog-bd); padding:16px; display:flex; flex-direction:column; gap:10px; box-shadow:4px 4px 0 rgba(0,0,0,.5); }
.continue-card-header { font-size:8px; color:var(--black); margin-bottom:4px; letter-spacing:1px; }
.save-row { display:flex; justify-content:space-between; align-items:center; font-size:clamp(6.5px,1.8vw,8px); }
.save-lbl { color:var(--gray); } .save-val { color:var(--black); }
.continue-or  { font-size:7px; color:rgba(255,255,255,.4); letter-spacing:1px; }
.continue-warn{ font-size:6px; color:rgba(255,80,80,.7); text-align:center; line-height:1.8; min-height:14px; }

/* ─── NAME ENTRY ─────────────────────────────────────────── */
#screen-name { background:#c8b88a; padding:14px 10px 10px; gap:10px; }
.name-dialog { flex-shrink:0; }
.name-entry-area { display:flex; flex-direction:column; align-items:center; gap:8px; flex:1; }
.name-display-box { background:var(--white); border:3px solid var(--black); padding:8px 20px; font-size:clamp(14px,4.5vw,20px); color:var(--black); min-width:180px; text-align:center; letter-spacing:4px; box-shadow:inset 2px 2px 0 rgba(0,0,0,.2); }
.keyboard-grid { display:grid; grid-template-columns:repeat(10,1fr); gap:3px; width:100%; }
.key-btn { background:var(--white); border:2px solid var(--black); color:var(--black); font-family:var(--font); font-size:clamp(6px,1.8vw,8px); padding:clamp(5px,1.5vw,8px) 2px; cursor:pointer; text-align:center; box-shadow:2px 2px 0 var(--darkgray); user-select:none; -webkit-tap-highlight-color:transparent; transition:transform .05s,box-shadow .05s; }
.key-btn:active { transform:translate(2px,2px); box-shadow:none; }
.name-controls { display:flex; gap:12px; margin-top:4px; }
.btn-del { background:var(--red); } .btn-del:hover { background:var(--red-hover); }
.btn-ok  { background:var(--green); } .btn-ok:hover { background:var(--green-hover); }

/* ─── INTRO ──────────────────────────────────────────────── */
#screen-intro { flex-direction:column-reverse; }
.intro-dialog { margin:10px; min-height:90px; }
.intro-npc    { position:absolute; right:22%; bottom:30%; font-size:clamp(44px,13vw,64px); animation:npcFloat 2s ease-in-out infinite; filter:drop-shadow(2px 3px 0 rgba(0,0,0,.4)); }
.intro-npc.intro-npc-centered {
  right:auto !important;
  left:50% !important;
  bottom:20% !important;
  transform:translate(-50%, 50%);
  font-size:clamp(80px,25vw,120px);
  text-align:center;
}
.intro-npc.intro-npc-centered img {
  height:clamp(120px,35vw,180px) !important;
  margin:0 auto;
  display:block;
}
.intro-oak-bg {
  display:flex; align-items:center; justify-content:center;
}
.intro-player {
  position: absolute;
  left: 22%;
  bottom: 28%;
  width: 32px;
  height: 64px;
  background-image: url('./player.png');
  background-repeat: no-repeat;
  background-size: 768px 64px;
  background-position-x: -32px;
  background-position-y: 0;
  image-rendering: pixelated;
  animation: bounce 1s ease-in-out infinite;
  filter: drop-shadow(2px 3px 0 rgba(0,0,0,.4));
}
.tap-hint     { font-size:6px; color:var(--black); background:rgba(255,255,255,.6); text-align:center; padding:4px; letter-spacing:1px; flex-shrink:0; }

/* ─── MAP ────────────────────────────────────────────────── */
.map-header { background:var(--dark-bg); padding:8px 12px; display:flex; align-items:center; justify-content:space-between; gap:8px; border-bottom:3px solid var(--black); flex-shrink:0; }
.map-left   { display:flex; align-items:center; gap:6px; flex:1; }
.map-center { display:flex; align-items:center; gap:6px; flex:1; justify-content:center; }
.map-right  { display:flex; align-items:center; gap:6px; flex:1; justify-content:flex-end; }
.map-pin    { font-size:12px; }
.map-town-name { font-size:clamp(5.5px,1.6vw,7px); color:var(--yellow); letter-spacing:.5px; word-spacing:-1px; }
.prog-bar-outer { width:80px; height:9px; background:var(--black); border:2px solid var(--lightgray); overflow:hidden; }
.prog-bar-inner { height:100%; width:0%; background:var(--hp-green); transition:width .5s ease; }
.prog-text  { font-size:6px; color:var(--white); }
.save-dot     { font-size:12px; animation:blink 3s ease-in-out infinite; }
.music-toggle {
  font-size: 14px;
  cursor: pointer;
  opacity: 1;
  transition: opacity .2s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  padding: 2px 4px;
}
.music-toggle.muted { opacity: .35; }

.map-world  {
  position: relative;
  overflow: hidden;
}
/* Wide scrolling inner world — JS translates this to pan the camera */
.map-inner {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 400%;
  height: 400%;
  will-change: transform;
  z-index: 25;
}
.map-trees {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.tree {
  position: absolute;
  display: inline-block;
  filter: drop-shadow(1px 2px 0 rgba(0,0,0,.3));
  line-height: 1;
  z-index: 80;
}
.tree:nth-child(even) { }
.tall-grass {
  position: absolute;
  display: inline-block;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,.2));
  line-height: 1;
  z-index: 5;
  opacity: .85;
  animation: grassSway 2s ease-in-out infinite alternate;
}
@keyframes grassSway {
  0%   { transform: rotate(-3deg) scaleY(1); }
  50%  { transform: rotate(2deg) scaleY(1.05); }
  100% { transform: rotate(-3deg) scaleY(1); }
}
.tall-grass-flip {
  animation: grassSwayFlip 2s ease-in-out infinite alternate;
}
@keyframes grassSwayFlip {
  0%   { transform: scaleX(-1) rotate(-3deg) scaleY(1); }
  50%  { transform: scaleX(-1) rotate(2deg) scaleY(1.05); }
  100% { transform: scaleX(-1) rotate(-3deg) scaleY(1); }
}
/* Directional nudge arrow */
.map-dir-arrow {
  position: absolute;
  font-size: clamp(24px, 7vw, 34px);
  color: var(--yellow);
  text-shadow: 0 0 6px rgba(248,192,48,.8), 2px 2px 0 rgba(0,0,0,.5);
  pointer-events: none;
  z-index: 50;
  filter: drop-shadow(0 0 4px rgba(248,192,48,.6));
  transition: opacity .5s ease;
  display: none;
  bottom: -9999px;
}
/* NPC lives inside .map-inner, positioned in world-px via JS */
.map-npc-wrap { position:absolute; text-align:center; z-index: 70; }
.npc-bubble   { font-size:14px; font-family:var(--font); color:var(--black); background:var(--yellow); border:2px solid var(--black); width:20px; height:20px; display:flex; align-items:center; justify-content:center; margin:0 auto 2px; animation:bounce .7s ease-in-out infinite; }
.map-npc      { font-size:clamp(36px,10vw,52px); filter:drop-shadow(2px 3px 0 rgba(0,0,0,.35)); cursor:pointer; animation:npcFloat 2s ease-in-out infinite; }
.intro-npc img { height:clamp(56px,16vw,80px); width:auto; image-rendering:pixelated; display:block; }
.intro-npc.intro-npc-centered img { height:clamp(120px,35vw,180px) !important; }
.map-npc img   { height:clamp(56px,16vw,80px); width:auto; image-rendering:pixelated; display:block; }
/* Player is fixed to the viewport centre horizontally; only Y moves */
/* "..." bubble above player when pressing talk away from NPC */
.player-bubble {
  font-size: 11px;
  font-family: var(--font);
  color: var(--black);
  background: #fff;
  border: 2px solid var(--black);
  padding: 0 5px;
  height: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  white-space: nowrap;
  position: absolute;
  z-index: 100;
  box-shadow: 1px 1px 0 rgba(0,0,0,.3);
  left: -9999px;
}
.player-bubble::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border: 3px solid transparent;
  border-top-color: var(--black);
}
.player-bubble.visible {
  display: flex;
  animation: bounce .5s ease-in-out 3;
}

.map-player {
  position: absolute;
  width:  32px;
  height: 64px;
  background-image: url('./player.png');
  background-repeat: no-repeat;
  background-size: 768px 64px;
  image-rendering: pixelated;
  filter: drop-shadow(2px 3px 0 rgba(0,0,0,.4));
  z-index: 70;
  font-size: 0;
  color: transparent;
  left: -9999px;
}
.map-player.walk-down  { animation: walkDown  .32s steps(3) infinite; }
.map-player.walk-up    { animation: walkUp    .32s steps(3) infinite; }
.map-player.walk-left  { animation: walkLeft  .32s steps(3) infinite; }
.map-player.walk-right { animation: walkRight .32s steps(3) infinite; }
.map-player.idle       { animation: none; }

/* Talk hint that floats above player when near NPC */
.map-talk-hint {
  position: absolute;
  font-family: var(--font);
  font-size: 6px;
  background: var(--yellow);
  color: var(--black);
  border: 2px solid var(--black);
  padding: 3px 6px;
  white-space: nowrap;
  z-index: 50;
  animation: talkBubble .6s ease-in-out infinite;
  pointer-events: none;
}
/* Desktop: show "Press E", hide "Press A" */
.hint-touch { display: none; }
.hint-pc    { display: inline; }
/* Touch/mobile: show "Press A", hide "Press E" */
@media (pointer: coarse) {
  .hint-touch { display: inline; }
  .hint-pc    { display: none; }
}

/* HUD below map */
.map-hud { background:var(--dialog-bg); border-top:4px solid var(--dialog-bd); padding:8px 10px; display:flex; gap:0; flex-shrink:0; }
.hud-cell { flex:1; text-align:center; border-right:2px solid rgba(0,0,0,.15); padding:0 4px; }
.hud-cell:last-child { border-right:none; }
.hud-lbl  { font-size:5.5px; color:var(--gray); margin-bottom:3px; }
.hud-val  { font-size:clamp(7px,2vw,9px); color:var(--black); }

/* ─── BATTLE ─────────────────────────────────────────────── */
#screen-battle { flex-direction:column; }
.battle-scene {
  display:flex; justify-content:space-between; align-items:flex-end;
  padding:10px 16px 6px;
  background:linear-gradient(180deg,#90c8f0 0%,#70b0e0 55%,#c8b880 55%,#b09860 100%);
  flex-shrink:0; min-height:clamp(100px,22vh,150px); position:relative;
}
.battle-scene::after { content:''; position:absolute; top:55%; left:0; right:0; height:2px; background:rgba(0,0,0,.18); }
.battle-npc-side, .battle-player-side { display:flex; flex-direction:column; align-items:center; gap:4px; }
.battle-npc-row, .battle-player-row { display:flex; align-items:flex-end; gap:2px; }
.battle-npc-trainer, .battle-player-trainer {
  font-size:clamp(38px,11vw,56px);
  filter:drop-shadow(2px 3px 0 rgba(0,0,0,.3));
  align-self:flex-end;
  line-height:1;
}
.battle-npc-trainer img, .battle-player-trainer img {
  height:clamp(56px,16vw,80px);
  width:auto;
  image-rendering:pixelated;
  display:block;
}
.battle-player-trainer {
  width:32px;
  height:64px;
  background-image:url('./player.png');
  background-repeat:no-repeat;
  background-size:768px 64px;
  background-position:-32px 0;
  image-rendering:pixelated;
  filter:drop-shadow(2px 3px 0 rgba(0,0,0,.3));
}
.battle-sprite { font-size:clamp(14px,4vw,20px); filter:drop-shadow(1px 2px 0 rgba(0,0,0,.3)); animation:npcFloat 2s ease-in-out infinite; }
.battle-sprite img { height:clamp(18px,5vw,24px); width:auto; image-rendering:pixelated; display:block; }
.battle-player-side .battle-sprite { animation:bounce 1s ease-in-out infinite; }
/* Player sprite on battle screen — use sprite sheet facing down-idle */
.battle-player-sprite {
  width: 48px;
  height: 96px;
  background-image: url('./player.png');
  background-repeat: no-repeat;
  background-size: 1152px 96px;  /* 3× scale */
  background-position-x: -48px; /* idle down frame */
  background-position-y: 0;
  image-rendering: pixelated;
  filter: drop-shadow(2px 3px 0 rgba(0,0,0,.3));
  animation: bounce 1s ease-in-out infinite;
}
.battle-name-tag { font-size:clamp(5.5px,1.6vw,7px); background:rgba(255,255,255,.8); border:2px solid var(--black); padding:2px 6px; color:var(--black); }
.battle-dialog { margin:8px; min-height:72px; }
.battle-choices { display:grid; grid-template-columns:1fr 1fr; gap:5px; padding:5px 8px; flex-shrink:0; }

/* choice button */
.choice-btn {
  background:var(--dialog-bg);
  border:3px solid var(--dialog-bd);
  color:var(--black);
  font-family:var(--font);
  font-size:clamp(6px,1.7vw,7.5px);
  padding:clamp(7px,2vw,10px) clamp(6px,2vw,10px);
  cursor:pointer;
  text-align:left;
  line-height:1.8;
  box-shadow:2px 2px 0 var(--darkgray);
  word-break:break-word;
  hyphens:auto;
  transition:transform .06s, box-shadow .06s, border-color .08s;
  -webkit-tap-highlight-color:transparent;
  position:relative;
}
.choice-btn::before { content:attr(data-letter) ' '; color:var(--blue); }
.choice-btn:hover   { background:#fffae0; border-color:var(--blue); transform:translate(-1px,-1px); box-shadow:3px 3px 0 var(--darkgray); }
.choice-btn:active  { transform:translate(2px,2px); box-shadow:none; }

/* D-pad / keyboard cursor highlight */
.choice-btn.cursor:not(.confirm-btn)  { animation:choiceCursor .7s ease-in-out infinite; border-color:var(--yellow) !important; background:#fffae0 !important; }
.choice-btn.confirm-btn.cursor { border-color:var(--yellow) !important; box-shadow:0 0 0 3px var(--yellow); }
.choice-btn.correct { background:#c8ffc8; border-color:var(--green); animation:correctPulse .5s ease 3; pointer-events:none; }
.choice-btn.wrong   { background:#ffc8c8; border-color:var(--red);   animation:wrongShake .35s ease;   pointer-events:none; }
.choice-btn.disabled{ opacity:.5; pointer-events:none; }
.choice-btn.selected{ background:#c0e0ff; border-color:var(--blue); border-width:4px; box-shadow:3px 3px 0 var(--blue); color:var(--black); }
.choice-btn.selected::after { content:' ✔'; color:var(--blue); font-size:1.6em; vertical-align:middle; }
.choice-btn.confirm-btn { background:var(--blue); color:#fff; border-color:#003080; text-align:center; grid-column: 1 / -1; }
.choice-btn.confirm-btn:hover:not(:disabled) { background:#0050d0; }
.choice-btn.confirm-inactive { opacity:.4; pointer-events:none; }
.choice-btn.confirm-btn::before { content:''; }

.battle-footer { background:var(--dark-bg); border-top:3px solid var(--black); padding:clamp(4px,1.2vw,6px) 12px max(4px,var(--safe-bottom)); display:flex; justify-content:space-between; align-items:center; font-size:clamp(5.5px,1.5vw,7px); color:var(--yellow); flex-shrink:0; }
.kbd-hint { font-size:5px; color:rgba(255,255,255,.3); }
@media (max-width:480px) { .kbd-hint { display:none; } }

/* ─── RESULT ─────────────────────────────────────────────── */
#screen-result { background:var(--dark-bg); align-items:center; justify-content:center; }
.result-box { background:var(--dialog-bg); border:4px solid var(--dialog-bd); padding:clamp(16px,4.5vw,26px) clamp(12px,3.5vw,20px); width:clamp(270px,88vw,390px); text-align:center; box-shadow:6px 6px 0 rgba(0,0,0,.5); animation:pop .4s cubic-bezier(.175,.885,.32,1.275); display:flex; flex-direction:column; gap:9px; }
.result-icon  { font-size:clamp(26px,8vw,40px); }
.result-label { font-size:clamp(11px,3.5vw,15px); }
.result-label.correct { color:var(--green); text-shadow:2px 2px 0 #003010; }
.result-label.wrong   { color:var(--red);   text-shadow:2px 2px 0 #400010; }
.result-correct-ans   { font-size:clamp(6px,1.8vw,7.5px); color:var(--green); background:rgba(0,160,30,.1); border:2px solid rgba(0,160,30,.3); padding:6px; text-align:left; line-height:1.8; display:none; }
.result-correct-ans.visible { display:block; }
.result-explanation   { font-size:clamp(6px,1.8vw,7.5px); color:var(--black); line-height:2; text-align:left; padding:8px; background:rgba(255,255,255,.5); border:2px solid rgba(0,0,0,.15); }
.result-pts { font-size:clamp(9px,2.8vw,12px); color:var(--yellow); text-shadow:2px 2px 0 #604000; animation:goldShimmer 2s ease-in-out infinite; }

/* ─── LEVEL UP ───────────────────────────────────────────── */
#screen-levelup { background:linear-gradient(135deg,#0f0630,#220e5e,#0a0a34); align-items:center; justify-content:center; }
.levelup-box { text-align:center; padding:clamp(16px,4vw,28px) clamp(14px,3.5vw,22px); width:90%; max-width:360px; display:flex; flex-direction:column; gap:12px; animation:fadeIn .5s ease; }
.lu-stars    { font-size:clamp(7px,2vw,9px); color:var(--yellow); text-shadow:0 0 8px var(--yellow); letter-spacing:1px; }
.lu-sprite   { animation:bounce 1s ease-in-out infinite; display:flex; justify-content:center; }
.lu-player-sprite {
  width: 32px;
  height: 64px;
  background-image: url('./player.png');
  background-repeat: no-repeat;
  background-size: 768px 64px;
  background-position: -32px 0;
  image-rendering: pixelated;
  filter: drop-shadow(2px 3px 0 rgba(0,0,0,.4));
  transform: scale(1.5);
  transform-origin: center bottom;
}
.lu-text     { font-size:clamp(7.5px,2.2vw,9px); color:var(--white); line-height:2; }
.lu-badge    { font-size:clamp(7px,2vw,9px); color:var(--yellow); background:rgba(255,255,255,.08); border:2px solid var(--yellow); padding:clamp(8px,2.5vw,12px); }
.lu-prog-wrap{ display:flex; flex-direction:column; gap:5px; align-items:center; }
.lu-prog-outer{ width:80%; height:12px; background:var(--black); border:2px solid var(--lightgray); overflow:hidden; }
.lu-prog-inner{ height:100%; background:var(--hp-green); transition:width .8s ease; }
.lu-prog-label{ font-size:7px; color:var(--white); }

/* ─── COMPLETE ───────────────────────────────────────────── */
#screen-complete { background:linear-gradient(180deg,#08031a 0%,#180a44 100%); overflow:hidden; }
.complete-scroll { overflow-y:auto; height:100%; -webkit-overflow-scrolling:touch; }
.complete-area   { text-align:center; padding:clamp(18px,4.5vw,28px) clamp(12px,3.5vw,18px) max(22px,var(--safe-bottom)); display:flex; flex-direction:column; gap:12px; align-items:center; animation:fadeIn .7s ease; }
.complete-trophy { font-size:clamp(44px,13vw,64px); animation:goldShimmer 2s ease-in-out infinite; }
.complete-title  { font-size:clamp(16px,5.5vw,24px); color:var(--yellow); text-shadow:3px 3px 0 #604000; animation:goldShimmer 2s ease-in-out infinite; }
.complete-name   { font-size:clamp(9px,2.8vw,13px); color:var(--white); }
.complete-msg    { font-size:clamp(6px,1.7vw,7.5px); color:rgba(255,255,255,.8); line-height:2.2; max-width:360px; text-align:left; }
.complete-stats  { font-size:clamp(7px,2vw,8.5px); color:var(--yellow); background:rgba(255,255,255,.08); border:2px solid rgba(255,255,255,.15); padding:clamp(10px,3vw,16px); line-height:2.6; width:100%; max-width:340px; text-align:left; white-space:pre-line; }
.complete-badges { width:100%; max-width:340px; display:flex; flex-direction:column; gap:6px; }
.badge-row { font-size:clamp(6.5px,1.8vw,8px); color:var(--white); padding:8px 10px; border:2px solid rgba(248,192,48,.35); background:rgba(255,255,255,.04); text-align:left; }

/* ─── TOAST ──────────────────────────────────────────────── */
.toast { position:absolute; bottom:max(20px,var(--safe-bottom)); left:50%; transform:translateX(-50%); background:var(--dark-bg); border:3px solid var(--yellow); color:var(--yellow); font-family:var(--font); font-size:clamp(6.5px,1.8vw,8px); padding:10px 18px; z-index:950; animation:slideUp .3s ease; white-space:nowrap; max-width:90%; overflow:hidden; text-overflow:ellipsis; }
.hidden { display:none !important; }

/* ─── LANDSCAPE CONTROLLER LAYOUT ───────────────────────── */
@media (orientation: landscape) and (max-height: 600px) {
  html, body { align-items: flex-start; justify-content: flex-start; }

  #app {
    width: 100vw; height: 100dvh;
    border: none; border-radius: 0; box-shadow: none;
    display: flex; flex-direction: row; align-items: stretch;
  }

  .screen { position: relative; flex: 1; inset: auto; height: 100dvh; overflow: hidden; min-width: 0; }

  #gba-left, #gba-right {
    position: relative !important;
    bottom: auto !important; left: auto !important; right: auto !important;
    height: 100dvh; width: clamp(150px, 22vw, 180px);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-top: none;
    gap: 8px;
    flex-shrink: 0;
    background: linear-gradient(180deg, rgba(26,10,62,.82) 0%, rgba(14,6,36,.95) 100%);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  }

  #gba-left  {
    order: -1;
    border-right: 2px solid rgba(120,80,255,.35);
    border-left: none; border-top: none;
    padding: 8px 8px 8px max(8px, env(safe-area-inset-left, 0px));
  }
  #gba-right {
    order: 1;
    border-left: 2px solid rgba(120,80,255,.35);
    border-right: none; border-top: none;
    padding: 8px max(8px, env(safe-area-inset-right, 0px)) 8px 8px;
  }

  .gba-controller.hidden { display: none; }

  .dpad { width: clamp(90px, 20vh, 120px); height: clamp(90px, 20vh, 120px); }
  .gba-mid-btns { margin-top: 16px; }
  .ab-cluster { position: relative; width: clamp(90px, 21vw, 120px); height: clamp(90px, 21vw, 120px); flex: none; }
  #gba-right .ab-btn { position: absolute; }
  #gba-right .ab-b { bottom: 14%; left: 5%; top: auto; transform: none; }
  #gba-right .ab-a { top: 14%; right: 5%; transform: none; }
  .gba-mid-btns { flex-direction: column; gap: 5px; }
  .gba-mid-btn  { min-width: 44px; width: 44px; font-size: 5px; padding: 6px 4px; }

  .intro-npc-centered img { height: clamp(60px, 20vh, 100px) !important; }
  .intro-npc-centered { font-size: clamp(40px, 14vh, 70px); bottom: 30% !important; }
  .starter-choices { gap: 6px; padding: 4px 6px; }
  .starter-btn { padding: 6px 4px; }
  .starter-btn .starter-emoji { font-size: clamp(24px, 8vh, 36px); }
  .catch-wild-pokemon { font-size: clamp(40px, 14vh, 60px); }
  .catch-scene { padding: 8px 12px 4px; }
  .battle-anim-npc-sprite, .battle-anim-player-sprite { font-size: clamp(32px, 10vh, 48px); }
  .battle-scene { min-height: clamp(70px, 18vh, 110px); }
}

/* ─── STARTER SELECTION ──────────────────────────────────── */
#screen-starter {
  background:linear-gradient(180deg, #6cb84e 0%, #58a83e 100%);
  flex-direction:column;
  justify-content:flex-start;
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
}
#screen-starter .overworld-bg {
  flex:0 0 auto;
  min-height:30%;
  max-height:38%;
}
.starter-dialog {
  margin:0 8px;
  min-height:60px;
  flex-shrink:0;
}
.starter-choices {
  display:flex;
  justify-content:center;
  gap:clamp(6px,2vw,12px);
  padding:8px 10px;
  padding-bottom:max(16px, calc(var(--safe-bottom) + 160px));
  flex-shrink:0;
}
.starter-btn {
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:6px;
  padding:clamp(10px,3vw,16px) clamp(8px,2.5vw,14px);
  background:var(--dialog-bg);
  border:4px solid var(--dialog-bd);
  cursor:pointer;
  font-family:var(--font);
  transition:transform .15s, box-shadow .15s;
  box-shadow:4px 4px 0 rgba(0,0,0,.4);
  flex:1;
  max-width:130px;
}
.starter-btn:hover,
.starter-btn:active {
  transform:translateY(-3px);
  box-shadow:4px 7px 0 rgba(0,0,0,.4);
  background:#fff8e0;
}
.starter-btn .starter-emoji {
  font-size:clamp(32px,10vw,48px);
  animation:npcFloat 2s ease-in-out infinite;
  filter:drop-shadow(2px 3px 0 rgba(0,0,0,.3));
}
.starter-btn .starter-name {
  font-size:clamp(5.5px,1.6vw,7px);
  color:var(--black);
}
.starter-btn .starter-type {
  font-size:clamp(5px,1.3vw,6px);
  color:var(--lightgray);
}

/* ─── STARTER CONFIRM ────────────────────────────────────── */
#screen-starter-confirm {
  background:linear-gradient(180deg,#90c8f0 0%,#70b0e0 55%,#c8b880 55%,#b09860 100%);
  align-items:center;
  justify-content:center;
}
.starter-confirm-bg {
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:10px;
  padding:16px;
  width:100%;
}
.starter-chosen-emoji {
  font-size:clamp(56px,18vw,80px);
  animation:bounce 1s ease-in-out infinite;
  filter:drop-shadow(3px 4px 0 rgba(0,0,0,.35));
}
.starter-chosen-name {
  font-size:clamp(11px,3.5vw,15px);
  color:var(--black);
  font-family:var(--font);
  text-shadow:1px 1px 0 rgba(255,255,255,.6);
}
.starter-chosen-level {
  font-size:clamp(7px,2vw,9px);
  color:var(--gray);
  font-family:var(--font);
}
.starter-confirm-dialog {
  margin:0 12px;
  width:calc(100% - 24px);
}
.starter-flee-text {
  font-family:var(--font);
  font-size:clamp(6px,1.7vw,7.5px);
  color:var(--gray);
  text-align:center;
  line-height:2;
  padding:0 16px;
  animation:fadeIn .8s ease;
}

/* ─── CATCH SCREEN ───────────────────────────────────────── */
#screen-catch {
  background:linear-gradient(180deg,#90c8f0 0%,#70b0e0 55%,#60a840 55%,#408830 100%);
  flex-direction:column;
  justify-content:flex-start;
}
.catch-scene {
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:6px;
  padding:clamp(16px,5vw,28px) 16px 10px;
  flex-shrink:0;
}
.catch-wild-pokemon {
  font-size:clamp(56px,18vw,80px);
  animation:npcFloat 2s ease-in-out infinite;
  filter:drop-shadow(3px 4px 0 rgba(0,0,0,.35));
}
.catch-wild-name {
  font-family:var(--font);
  font-size:clamp(9px,2.8vw,12px);
  color:var(--black);
  text-shadow:1px 1px 0 rgba(255,255,255,.6);
}
.catch-wild-level {
  font-family:var(--font);
  font-size:clamp(6.5px,1.8vw,8px);
  color:var(--gray);
}
.catch-dialog {
  margin:8px;
  min-height:50px;
  flex-shrink:0;
}
.catch-actions {
  display:flex;
  gap:8px;
  padding:6px 12px;
  padding-bottom:max(16px, calc(var(--safe-bottom) + 160px));
  justify-content:center;
  flex-shrink:0;
}
.catch-action-btn {
  flex:1;
  max-width:160px;
}

/* ─── CATCH RESULT ───────────────────────────────────────── */
#screen-catch-result {
  background:linear-gradient(180deg,#90c8f0 0%,#70b0e0 55%,#60a840 55%,#408830 100%);
  align-items:center;
  justify-content:center;
}
.catch-result-bg {
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:14px;
  padding:20px;
  width:100%;
}
.catch-result-emoji {
  font-size:clamp(48px,15vw,72px);
  filter:drop-shadow(3px 4px 0 rgba(0,0,0,.35));
}
.catch-result-msg {
  font-family:var(--font);
  font-size:clamp(8px,2.5vw,11px);
  color:var(--black);
  text-align:center;
  line-height:2;
  text-shadow:1px 1px 0 rgba(255,255,255,.6);
  padding:0 16px;
}
.catch-result-msg.success { color:var(--green); }
.catch-result-msg.fail { color:var(--red); }

/* ─── BATTLE POKEMON LABELS ──────────────────────────────── */
.battle-npc-pokemon-name,
.battle-player-pokemon-name {
  font-family:var(--font);
  font-size:clamp(5px,1.4vw,6.5px);
  color:var(--black);
  background:rgba(255,255,255,.7);
  border:2px solid rgba(0,0,0,.2);
  padding:1px 5px;
  text-align:center;
}
.battle-npc-pokemon-level,
.battle-player-pokemon-level {
  font-family:var(--font);
  font-size:clamp(4.5px,1.2vw,5.5px);
  color:var(--gray);
  text-align:center;
}

/* ─── BATTLE ANIMATION SCREEN ────────────────────────────── */
#screen-battle-anim {
  background:linear-gradient(180deg,#90c8f0 0%,#70b0e0 55%,#c8b880 55%,#b09860 100%);
  flex-direction:column;
  justify-content:center;
  align-items:center;
}
.battle-anim-scene {
  display:flex;
  justify-content:space-around;
  align-items:center;
  width:100%;
  padding:10px 16px;
  gap:8px;
}
.battle-anim-npc,
.battle-anim-player {
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:6px;
  flex:1;
}
.battle-anim-npc-name,
.battle-anim-player-name {
  font-family:var(--font);
  font-size:clamp(6px,1.8vw,8px);
  color:var(--black);
  text-shadow:1px 1px 0 rgba(255,255,255,.5);
}
.battle-anim-npc-sprite,
.battle-anim-player-sprite {
  font-size:clamp(42px,13vw,64px);
  filter:drop-shadow(2px 3px 0 rgba(0,0,0,.3));
  transition:opacity .6s ease, transform .6s ease;
}
.battle-anim-vs {
  font-size:clamp(20px,6vw,32px);
  animation:bounce .8s ease-in-out infinite;
  filter:drop-shadow(2px 2px 0 rgba(0,0,0,.3));
}
.battle-anim-hp-bar {
  width:clamp(60px,20vw,100px);
  height:10px;
  background:var(--black);
  border:2px solid var(--lightgray);
  overflow:hidden;
}
.battle-anim-hp-fill {
  height:100%;
  width:100%;
  background:var(--hp-green);
  transition:width 1s ease;
}
.battle-anim-msg {
  font-family:var(--font);
  font-size:clamp(8px,2.5vw,11px);
  color:var(--black);
  text-align:center;
  padding:12px 16px;
  line-height:2;
  text-shadow:1px 1px 0 rgba(255,255,255,.5);
  min-height:40px;
}

/* ─── WILD POKEMON ON MAP ────────────────────────────────── */
.map-wild-wrap {
  position:absolute;
  text-align:center;
  z-index:70;
  cursor:pointer;
}
.wild-bubble {
  font-size:12px;
  font-family:var(--font);
  color:var(--black);
  background:var(--green);
  border:2px solid var(--black);
  width:18px;
  height:18px;
  display:flex;
  align-items:center;
  justify-content:center;
  margin:0 auto 2px;
  animation:bounce .7s ease-in-out infinite;
  color:#fff;
}
.map-wild {
  font-size:clamp(28px,8vw,40px);
  filter:drop-shadow(2px 3px 0 rgba(0,0,0,.3));
  animation:npcFloat 2s ease-in-out infinite;
}

/* ─── POKEBALL COUNT IN MAP HEADER ───────────────────────── */
.pokeball-count {
  font-size:clamp(6px,1.6vw,7.5px);
  color:var(--white);
  text-shadow:1px 1px 0 rgba(0,0,0,.5);
  white-space:nowrap;
}

/* ─── RESULT POKEBALLS REWARD ────────────────────────────── */
.result-pokeballs {
  font-size:clamp(7px,2vw,9px);
  color:var(--blue);
  text-shadow:1px 1px 0 rgba(0,0,0,.15);
  animation:blueShimmer 2s ease-in-out infinite;
}

/* ─── COMPLETE SCREEN PARTY ──────────────────────────────── */
.complete-party-title {
  font-size:clamp(9px,2.8vw,12px);
  color:var(--yellow);
  text-shadow:2px 2px 0 #604000;
  margin-top:8px;
}
.complete-party-grid {
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(80px, 1fr));
  gap:6px;
  width:100%;
  max-width:340px;
}
.complete-party-entry {
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:2px;
  background:rgba(255,255,255,.06);
  border:2px solid rgba(248,192,48,.25);
  padding:6px 4px;
  font-family:var(--font);
}
.complete-party-entry .party-emoji {
  font-size:clamp(20px,6vw,28px);
}
.complete-party-entry .party-name {
  font-size:clamp(4.5px,1.2vw,5.5px);
  color:var(--white);
}
.complete-party-entry .party-level {
  font-size:clamp(4px,1vw,5px);
  color:var(--lightgray);
}

/* ─── POKEBALL SHAKE ANIMATION ───────────────────────────── */
@keyframes pokeballShake {
  0%,100% { transform:rotate(0deg); }
  20%     { transform:rotate(-15deg); }
  40%     { transform:rotate(15deg); }
  60%     { transform:rotate(-10deg); }
  80%     { transform:rotate(10deg); }
}
.pokeball-shaking {
  animation:pokeballShake .6s ease-in-out;
  display:inline-block;
}

/* ─── CATCH SUCCESS FLASH ────────────────────────────────── */
@keyframes catchFlash {
  0%   { background:rgba(255,255,255,0); }
  50%  { background:rgba(255,255,255,.6); }
  100% { background:rgba(255,255,255,0); }
}
.catch-flash {
  animation:catchFlash .4s ease;
}

/* ─── CATCH RESULT TEXT SUB-STYLES ───────────────────────── */
.catch-success-title {
  font-size:clamp(12px,4vw,16px);
  color:var(--green);
  text-shadow:2px 2px 0 #003010;
  margin-bottom:4px;
}
.catch-fail-title {
  font-size:clamp(12px,4vw,16px);
  color:var(--red);
  text-shadow:2px 2px 0 #400010;
  margin-bottom:4px;
}
.catch-success-detail,
.catch-fail-detail {
  font-size:clamp(7px,2vw,9px);
  line-height:2;
}
.catch-success-sub {
  font-size:clamp(6px,1.6vw,7.5px);
  color:var(--green);
  margin-top:4px;
}
.catch-fail-sub {
  font-size:clamp(6px,1.6vw,7.5px);
  color:var(--lightgray);
  margin-top:4px;
}

/* ─── STARTER / CATCH CURSOR SELECTION ───────────────────── */
.starter-btn-selected {
  outline:3px solid var(--yellow);
  outline-offset:-2px;
  background:#fff8e0;
  transform:translateY(-3px);
  box-shadow:4px 7px 0 rgba(0,0,0,.4);
}
.catch-btn-selected {
  outline:3px solid var(--yellow);
  outline-offset:-2px;
}

/* ─── MAP ROCKS ──────────────────────────────────────────── */
.map-rock {
  position: absolute;
  display: inline-block;
  filter: drop-shadow(2px 2px 0 rgba(0,0,0,.4));
  line-height: 1;
  z-index: 15;
}

/* ─── BATTLE POKEMON FLOAT (name+level above sprite) ───── */
.battle-pokemon-float {
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:1px;
}

/* ─── POKEBALL ICON ──────────────────────────────────────── */
.pokeball-icon {
  width:14px;
  height:14px;
  vertical-align:middle;
  image-rendering:pixelated;
  display:inline-block;
  margin-right:2px;
}

/* ─── POKEBALL THROW ANIMATION ───────────────────────────── */
.pokeball-throw {
  position:absolute;
  width:32px;
  height:32px;
  bottom:15%;
  right:8%;
  z-index:200;
  image-rendering:pixelated;
  offset-path:path('M 0 0 C -80 -180, -140 -340, -160 -460');
  animation:pokeThrow .7s cubic-bezier(.2,.8,.3,1) forwards;
}
@keyframes pokeThrow {
  0%   { offset-distance:0%; transform:rotate(0deg) scale(1); opacity:1; }
  100% { offset-distance:100%; transform:rotate(-540deg) scale(0.7); opacity:1; }
}

.pokeball-burst {
  position:absolute;
  width:64px;
  height:64px;
  margin-left:-32px;
  margin-top:-32px;
  z-index:200;
  border-radius:50%;
  background:radial-gradient(circle, rgba(255,255,255,1) 0%, rgba(255,255,200,.8) 30%, rgba(255,200,100,.4) 60%, transparent 80%);
  animation:burstAnim .6s ease-out forwards;
  pointer-events:none;
}
@keyframes burstAnim {
  0%   { transform:scale(0.3); opacity:1; }
  40%  { transform:scale(2.5); opacity:.9; }
  100% { transform:scale(4); opacity:0; }
}

/* ─── BATTLE ANIM TRAINER PEEK ───────────────────────────── */
.battle-anim-trainer-npc,
.battle-anim-trainer-player {
  position:absolute;
  top:50%;
  transform:translateY(-50%);
  z-index:5;
  opacity:.7;
  font-size:clamp(50px,15vw,72px);
}
.battle-anim-trainer-npc {
  left:4px;
}
.battle-anim-trainer-npc img {
  height:clamp(72px,20vw,100px);
  width:auto;
  image-rendering:pixelated;
  display:block;
}
.battle-anim-trainer-player {
  right:4px;
}
.anim-player-sprite-sheet {
  width:48px;
  height:96px;
  background-image:url('./player.png');
  background-repeat:no-repeat;
  background-size:1152px 96px;
  background-position:-48px 0;
  image-rendering:pixelated;
}

/* ─── PARTY SELECT SCREEN ────────────────────────────────── */
#screen-party-select {
  background:linear-gradient(180deg,#1a1a2e 0%,#16213e 100%);
  flex-direction:column;
  align-items:center;
  padding:12px 10px;
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
}
.party-select-header {
  font-family:var(--font);
  font-size:clamp(10px,3vw,14px);
  color:var(--yellow);
  text-shadow:2px 2px 0 #604000;
  text-align:center;
  padding:8px 0 12px;
  flex-shrink:0;
}
.party-select-list {
  display:flex;
  flex-direction:column;
  gap:6px;
  width:100%;
  max-width:380px;
  padding-bottom:max(16px, calc(var(--safe-bottom) + 160px));
}
.party-select-entry {
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 12px;
  background:var(--dialog-bg);
  border:3px solid var(--dialog-bd);
  cursor:pointer;
  font-family:var(--font);
  transition:transform .1s, box-shadow .1s;
  box-shadow:3px 3px 0 rgba(0,0,0,.4);
  position:relative;
}
.party-select-entry:hover,
.party-select-entry.party-selected {
  transform:translateX(6px);
  box-shadow:3px 3px 0 rgba(0,0,0,.4);
  border-color:var(--yellow);
  background:#fff8e0;
}
.party-select-entry.fainted {
  opacity:.5;
  cursor:not-allowed;
}
.party-select-entry.fainted:hover {
  transform:none;
  border-color:var(--dialog-bd);
  background:var(--dialog-bg);
}
.party-select-emoji {
  font-size:clamp(28px,8vw,40px);
  position:relative;
  flex-shrink:0;
}
.party-select-zzz {
  position:absolute;
  top:-8px;
  right:-8px;
  font-family:var(--font);
  font-size:clamp(6px,1.8vw,8px);
  color:var(--lightgray);
  animation:bounce 1.5s ease-in-out infinite;
}
.party-select-info {
  display:flex;
  flex-direction:column;
  gap:2px;
}
.party-select-name {
  font-size:clamp(8px,2.5vw,11px);
  color:var(--black);
}
.party-select-detail {
  font-size:clamp(5.5px,1.5vw,7px);
  color:var(--gray);
}
.party-select-badge {
  margin-left:auto;
  font-size:clamp(5px,1.3vw,6.5px);
  color:var(--green);
  font-family:var(--font);
}
.party-select-badge.badge-fainted {
  color:var(--red);
}

/* ─── POKEBALL REST + BOUNCE ─────────────────────────────── */
.pokeball-rest {
  position:absolute;
  width:40px;
  height:40px;
  z-index:200;
  image-rendering:pixelated;
}
.pokeball-bounce-anim {
  animation:pokeballBounce .5s ease-out;
}
@keyframes pokeballBounce {
  0%   { transform:translateY(0); }
  20%  { transform:translateY(-24px) rotate(-10deg); }
  40%  { transform:translateY(0) rotate(0deg); }
  55%  { transform:translateY(-12px) rotate(8deg); }
  70%  { transform:translateY(0) rotate(0deg); }
  82%  { transform:translateY(-5px) rotate(-4deg); }
  100% { transform:translateY(0) rotate(0deg); }
}
