/* ============ Gen Arena — mobile battle client ============ */
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #07070f; overscroll-behavior: none; }
body { display: flex; justify-content: center; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }

#app {
  /* default tokens (modern) */
  --font: 'Outfit', system-ui, sans-serif;
  --bg: #0b0b1a; --fg: #eef0ff; --muted: #9aa0c8;
  --panel: rgba(255,255,255,.07); --panel-b: rgba(255,255,255,.14); --panel-fg: #fff;
  --accent: #7c5cff; --accent2: #22d3ee;
  --hp-hi: linear-gradient(90deg,#34d399,#a3f7bf); --hp-mid: linear-gradient(90deg,#fbbf24,#fde68a); --hp-lo: linear-gradient(90deg,#f43f5e,#fb7185);
  --r: 18px; --fs: 15px;
  position: relative; width: 100%; max-width: 480px; height: 100dvh; overflow: hidden;
  font-family: var(--font); font-size: var(--fs); color: var(--fg); background: var(--bg);
  transition: background .4s;
}
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: max(14px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom)); overflow-y: auto; }

/* ---------------- HOME ---------------- */
.home { gap: 10px; }
.home-bg { position: absolute; inset: 0; z-index: -1; overflow: hidden; }
.home-bg::before, .home-bg::after { content: ''; position: absolute; width: 140%; aspect-ratio: 1; border-radius: 50%; filter: blur(60px); opacity: .55; animation: drift 14s ease-in-out infinite alternate; }
.home-bg::before { background: radial-gradient(circle, #6d28d9, transparent 60%); left: -60%; top: -40%; }
.home-bg::after { background: radial-gradient(circle, #0891b2, transparent 60%); right: -70%; bottom: -50%; animation-delay: -7s; }
@keyframes drift { to { transform: translate(18%, 12%) rotate(40deg); } }
.brand { text-align: center; margin-top: 8px; }
.brand h1 { margin: 6px 0 0; font-size: 40px; font-weight: 800; letter-spacing: -1px; background: linear-gradient(120deg,#fff,#c4b5fd 40%,#67e8f9); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; letter-spacing: 2px; text-transform: uppercase; }
.brand-ball { width: 44px; height: 44px; margin: 0 auto; border-radius: 50%; background: linear-gradient(#ff3b5c 0 46%, #111 46% 54%, #f4f4ff 54%); box-shadow: 0 0 0 3px #111, 0 0 30px #ff3b5c88; position: relative; animation: wobble 3s ease-in-out infinite; }
.brand-ball::after { content: ''; position: absolute; inset: 15px; border-radius: 50%; background: #f4f4ff; box-shadow: 0 0 0 3px #111; }
@keyframes wobble { 0%,70%,100% { transform: rotate(0); } 75% { transform: rotate(-14deg); } 85% { transform: rotate(10deg); } }
.hero-mons { height: 110px; display: flex; justify-content: center; align-items: flex-end; gap: 4px; }
.hero-mons img { height: 96px; image-rendering: pixelated; object-fit: contain; max-width: 31%; filter: drop-shadow(0 8px 10px #0008); animation: bob 2.6s ease-in-out infinite; }
.hero-mons img:nth-child(2) { height: 110px; animation-delay: -.8s; }
.hero-mons img:nth-child(3) { animation-delay: -1.6s; }
@keyframes bob { 50% { transform: translateY(-6px); } }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); margin: 8px 2px 0; font-weight: 600; }
.themes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.theme-card { position: relative; border-radius: 14px; padding: 10px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; border: 2px solid transparent; transition: transform .2s, border-color .2s, box-shadow .2s; }
.theme-card b { font-size: 22px; line-height: 1.1; }
.theme-card span { font-size: 11px; font-weight: 600; }
.theme-card i { font-size: 9px; font-style: normal; opacity: .7; }
.theme-card.on { border-color: #fff; transform: translateY(-3px); box-shadow: 0 10px 24px #0007; }
.t-gen1 { background: linear-gradient(160deg,#fff 0 55%,#f3d6d6 55% 70%,#d6e0f3 70%); color: #2b2b33; font-family: 'Press Start 2P'; }
.t-gen1 b { font-size: 16px; }
.t-gen1 span, .t-gen1 i { font-size: 7px; }
.t-gen2 { background: linear-gradient(160deg,#fff 50%,#c8f0ff); color: #222; font-family: 'Press Start 2P'; }
.t-gen2 b { font-size: 16px; } .t-gen2 span, .t-gen2 i { font-size: 7px; }
.t-gen3 { background: linear-gradient(#a8e0a0,#58a858); color: #203020; font-family: 'Pixelify Sans'; }
.t-modern { background: linear-gradient(140deg,#7c5cff,#22d3ee); color: #fff; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--panel); border: 1px solid var(--panel-b); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { padding: 10px 6px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--muted); transition: .2s; }
.seg button.on { background: #fff; color: #111; box-shadow: 0 4px 14px #0005; }
.cta { margin-top: 6px; padding: 16px; border-radius: 16px; font-weight: 800; font-size: 17px; letter-spacing: .3px; color: #fff; background: linear-gradient(120deg,#7c5cff,#c026d3 55%,#f43f5e); box-shadow: 0 10px 30px #7c5cff55, inset 0 1px 0 #fff4; transition: transform .15s; }
.cta:active { transform: scale(.97); }
.cta.ghost { background: var(--panel); border: 1px solid var(--panel-b); box-shadow: none; font-weight: 600; }
.cta[disabled] { opacity: .45; }
.cta small { font-size: 10px; padding: 2px 6px; border-radius: 6px; background: #fff2; margin-left: 6px; vertical-align: middle; }
.credits { font-size: 10px; color: var(--muted); text-align: center; opacity: .7; margin: 8px 0 0; }
.row { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; }
.link { color: var(--muted); padding: 12px; }

/* ---------------- PREVIEW ---------------- */
.preview { gap: 8px; background: radial-gradient(120% 60% at 50% 0%, #2a1b5e, transparent), var(--bg); }
.team-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; }
.team-row .tm { width: 64px; text-align: center; font-size: 10px; color: var(--muted); }
.team-row img { width: 60px; height: 60px; image-rendering: pixelated; }
.vs { text-align: center; font-weight: 800; font-size: 28px; letter-spacing: 4px; background: linear-gradient(90deg,#f43f5e,#fbbf24); -webkit-background-clip: text; background-clip: text; color: transparent; }
.team-list { display: flex; flex-direction: column; gap: 8px; }
.tcard { display: grid; grid-template-columns: 64px 1fr; gap: 10px; align-items: center; padding: 8px 12px 8px 4px; border-radius: 16px; background: var(--panel); border: 1px solid var(--panel-b); animation: rise .45s both; }
.tcard img { width: 64px; height: 64px; image-rendering: pixelated; }
.tcard h3 { margin: 0; font-size: 16px; display: flex; gap: 8px; align-items: center; }
.tcard h3 small { color: var(--muted); font-weight: 400; font-size: 12px; }
.tcard .mv { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { font-size: 10.5px; padding: 3px 7px; border-radius: 999px; background: var(--tc, #555); color: #fff; font-weight: 600; text-shadow: 0 1px 1px #0006; }
.types { display: inline-flex; gap: 3px; }
.types .chip { font-size: 9px; padding: 2px 6px; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* ---------------- BATTLE ---------------- */
.battle { padding: 0; gap: 0; }
.topbar { position: relative; z-index: 20; padding: max(8px, env(safe-area-inset-top)) 10px 8px; display: flex; align-items: center; gap: 6px; flex: none; }
.topbar > * { pointer-events: auto; }
.pill { height: 30px; min-width: 30px; padding: 0 10px; border-radius: 999px; background: #0007; color: #fff; font: 600 12px 'Outfit', sans-serif; display: grid; place-items: center; backdrop-filter: blur(8px); }
.turn { margin-right: auto; }
.skin-switch { display: flex; background: #0007; border-radius: 999px; padding: 3px; backdrop-filter: blur(8px); }
.skin-switch button { font: 700 11px 'Outfit', sans-serif; color: #fffa; width: 30px; height: 24px; border-radius: 999px; }
.skin-switch button.on { background: #fff; color: #111; }

.scene { position: relative; width: 100%; aspect-ratio: var(--aspect, 4/4.2); overflow: hidden; flex: none; background: var(--scene-bg, #111); transition: aspect-ratio .3s; }
.scene .bg { position: absolute; inset: 0; }
.scene .bg i { position: absolute; display: none; }
.fx { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 8; pointer-events: none; image-rendering: pixelated; }
.floaters { position: absolute; inset: 0; z-index: 9; pointer-events: none; }

.mon { position: absolute; z-index: 3; display: flex; flex-direction: column; align-items: center; transform-origin: 50% 100%; }
.mon.foe { right: 7%; bottom: 47%; }
.mon.me { left: 5%; bottom: 0; }
.mon .sprite { display: block; image-rendering: pixelated; transform-origin: 50% 100%; }
.mon .shadow { display: none; }
.mon .subdoll { display: none; position: absolute; bottom: 0; width: 60%; aspect-ratio: 1; }
.mon.has-sub .sprite { opacity: 0; }
.mon.has-sub .subdoll { display: block; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32' shape-rendering='crispEdges'%3E%3Cpath fill='%23e8e0d0' stroke='%23303030' d='M10 6h12v4h2v8h-2v8h-4v-4h-4v4h-4v-8H8v-8h2z'/%3E%3Cpath fill='%23303030' d='M13 11h2v2h-2zM18 11h2v2h-2z'/%3E%3Cpath fill='%23f08080' d='M10 3h3v4h-3zM19 3h3v4h-3z'/%3E%3C/svg%3E") center/contain no-repeat; image-rendering: pixelated; animation: bob 1.4s ease-in-out infinite; }

.platform { position: absolute; z-index: 1; display: none; border-radius: 50%; }

.hud { position: absolute; z-index: 5; width: 50%; transition: opacity .3s, transform .3s; }
.hud.foe { left: 4%; top: 7%; }
.hud.me { right: 3%; bottom: 7%; }
.hud.off { opacity: 0; transform: translateY(-6px); }
.hud-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; white-space: nowrap; }
.hud .nm { overflow: hidden; text-overflow: ellipsis; }
.hp-row { display: flex; align-items: center; gap: 4px; margin-top: 3px; }
.hp-bar { position: relative; flex: 1; height: 8px; overflow: hidden; }
.hp-bar i { position: absolute; inset: 0; width: var(--w, 100%); background: var(--hp-hi); transition: width var(--hp-t, .7s) cubic-bezier(.4,.1,.3,1), background .3s; }
.hp-bar[data-lv="mid"] i { background: var(--hp-mid); }
.hp-bar[data-lv="lo"] i { background: var(--hp-lo); }
.hud-bottom { display: flex; justify-content: space-between; align-items: center; min-height: 1em; margin-top: 3px; }
.st:empty { display: none; }
.st { font-size: .7em; padding: 1px 5px; border-radius: 4px; color: #fff; font-weight: 700; text-transform: uppercase; }
.st[data-s="par"] { background: #c8a800; } .st[data-s="slp"] { background: #8c8c9c; } .st[data-s="brn"] { background: #e04020; }
.st[data-s="psn"], .st[data-s="tox"] { background: #a040a0; } .st[data-s="frz"] { background: #40a0d0; } .st[data-s="fnt"] { background: #333; }
.exp { display: none; }
.pips { display: inline-flex; gap: 3px; }
.pips b { width: 8px; height: 8px; border-radius: 50%; background: #f44; box-shadow: inset 0 -2px #0004; }
.pips b.dead { background: #555; }
.pips b.st { background: #fb4; }
.hud.me > .pips { position: absolute; top: -14px; right: 4px; }

.ball { position: absolute; z-index: 6; width: 18px; height: 18px; border-radius: 50%; display: none; background: linear-gradient(#ff3b5c 0 45%, #111 45% 55%, #fff 55%); box-shadow: 0 0 0 2px #111; }
.ball.throw-me { display: block; animation: throwMe .55s cubic-bezier(.3,.6,.4,1) forwards; }
.ball.throw-foe { display: block; animation: throwFoe .55s cubic-bezier(.3,.6,.4,1) forwards; }
@keyframes throwMe { from { left: -10%; top: 70%; transform: rotate(0); } 50% { top: 42%; } to { left: 22%; top: 78%; transform: rotate(720deg); } }
@keyframes throwFoe { from { left: 110%; top: 10%; transform: rotate(0); } 50% { top: 0%; } to { left: 72%; top: 34%; transform: rotate(-720deg); } }

/* sprite states */
.mon.enter .sprite { animation: enter .5s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes enter { 0% { transform: scale(0); filter: brightness(8); } 60% { filter: brightness(3); } 100% { transform: scale(1); filter: none; } }
.mon.withdraw .sprite { animation: withdraw .35s ease-in forwards; }
@keyframes withdraw { to { transform: scale(0); filter: brightness(3) sepia(1) hue-rotate(-50deg) saturate(6); } }
.mon.hit .sprite { animation: blink .5s steps(1) both; }
@keyframes blink { 0%,40%,80% { opacity: 0; } 20%,60%,100% { opacity: 1; } }
.mon.faint .sprite { animation: faint .6s ease-in forwards; }
@keyframes faint { to { transform: translateY(110%); opacity: 0; } }
.mon.gone { visibility: hidden; }
.mon.lunge.me .sprite { animation: lungeMe .35s ease-in-out; }
.mon.lunge.foe .sprite { animation: lungeFoe .35s ease-in-out; }
@keyframes lungeMe { 40% { transform: translate(18%, -14%); } }
@keyframes lungeFoe { 40% { transform: translate(-18%, 14%); } }
.mon.charge .sprite { animation: charge .6s ease-in-out; }
@keyframes charge { 30%,70% { filter: brightness(2.4) drop-shadow(0 0 10px #fff); transform: scale(1.06); } }
.mon.idle.me .sprite { animation: breathe 2.8s ease-in-out infinite; }
.mon.idle.foe .sprite { animation: breathe 3.2s ease-in-out infinite; animation-delay: -1s; }
@keyframes breathe { 50% { transform: scaleY(1.025) translateY(-1px); } }
.scene.shake { animation: shake var(--shake-t, .4s) linear; }
@keyframes shake { 10%,50%,90% { transform: translate(calc(var(--sx) * -1px), 1px); } 30%,70% { transform: translate(calc(var(--sx) * 1px), -1px); } }
.scene.psy .bg, .scene.psy .mon { animation: psy .9s ease-in-out; }
@keyframes psy { 25% { filter: hue-rotate(90deg) saturate(1.6); transform: skewX(3deg); } 75% { filter: hue-rotate(-60deg); transform: skewX(-3deg); } }

.floater { position: absolute; font-weight: 800; font-size: 22px; color: #fff; text-shadow: 0 2px 0 #000a, 0 0 12px var(--c, #f43f5e); animation: floatUp 1s ease-out forwards; white-space: nowrap; transform: translateX(-50%); }
.floater.crit { font-size: 15px; letter-spacing: 1px; color: #fde047; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, 6px) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -8px) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -46px) scale(1); } }

/* console */
.console { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 10px 12px max(12px, env(safe-area-inset-bottom)); gap: 10px; }
.textbox { position: relative; min-height: 76px; padding: 12px 16px; line-height: 1.45; }
.textbox p { margin: 0; white-space: pre-wrap; }
.textbox .more { position: absolute; right: 12px; bottom: 6px; font-size: 10px; opacity: 0; }
.textbox.wait .more { opacity: 1; animation: nudge .6s steps(2) infinite; }
@keyframes nudge { 50% { transform: translateY(2px); } }
.controls { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.controls.busy .menu { opacity: .35; pointer-events: none; filter: saturate(.3); }
.menu { flex: 1; display: flex; flex-direction: column; gap: 8px; transition: opacity .2s, filter .2s; min-height: 0; }
.menu.main { display: grid; grid-template-columns: 1.4fr 1fr; grid-template-rows: 1fr 1fr; }
.menu.main .a1 { grid-row: span 2; }
.menu button { position: relative; }
.move-grid { flex: 1; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; gap: 8px; }
.mbtn { display: flex; flex-direction: column; justify-content: center; align-items: flex-start; padding: 8px 12px; text-align: left; gap: 2px; min-height: 58px; }
.mbtn .mn { font-weight: 700; font-size: 1em; line-height: 1.1; }
.mbtn .mi { display: flex; gap: 6px; align-items: center; font-size: .72em; width: 100%; justify-content: space-between; }
.mbtn .eff { font-size: .7em; opacity: .9; }
.mbtn[disabled] { opacity: .4; }
.back { padding: 10px; font-weight: 600; }
.party-list { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; overflow-y: auto; align-content: start; }
.pbtn { display: grid; grid-template-columns: 40px 1fr; align-items: center; gap: 4px; padding: 6px 8px 6px 2px; text-align: left; min-height: 56px; }
.pbtn img { width: 40px; height: 30px; object-fit: contain; image-rendering: pixelated; }
.pbtn .pn { font-weight: 700; font-size: .85em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pbtn .hp-bar { height: 5px; margin-top: 4px; }
.pbtn small { font-size: .65em; opacity: .8; }
.pbtn.cur { outline: 2px solid currentColor; outline-offset: -2px; }
.pbtn[disabled] { opacity: .4; }

.result { position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; background: #0009; backdrop-filter: blur(6px); animation: fade .3s both; }
@keyframes fade { from { opacity: 0; } }
.result-card { width: min(88%, 380px); padding: 28px 20px 20px; border-radius: 24px; background: #15152b; border: 1px solid #fff2; text-align: center; animation: rise .45s cubic-bezier(.2,1.4,.4,1) both; }
.result-card h2 { margin: 0; font-size: 34px; font-weight: 800; background: linear-gradient(120deg,#fde047,#f97316); -webkit-background-clip: text; background-clip: text; color: transparent; }
.result-card.lose h2 { background-image: linear-gradient(120deg,#94a3b8,#64748b); }
.result-card p { color: var(--muted); margin: 6px 0 18px; font-size: 13px; }

/* =================================================================
   THEME: GEN I — native 160x144 screen (see gen1.js), SGB colours, DMG-style body
   ================================================================= */
.gb { display: none; }
#app[data-theme="gen1"] {
  --font: 'Press Start 2P', monospace; --fs: 10px;
  --g0: #2b2b33; --g3: #f4f2ec;
  --bg: #d9d7d0; --fg: #2b2b33; --muted: #6b6a72;
  --panel: #f4f2ec; --panel-b: #2b2b33;
  --hp-hi: #3c9c4a; --hp-mid: #d6a400; --hp-lo: #d24a30;
}
#app[data-theme="gen1"] .battle { background: linear-gradient(#dcdad3, #cfcdc5); }
#app[data-theme="gen1"] .topbar { background: none; }
#app[data-theme="gen1"] .scene, #app[data-theme="gen1"] .textbox { display: none; }
#app[data-theme="gen1"] .gb { display: flex; justify-content: center; padding: 4px 0 6px; }
.gb-bezel { position: relative; padding: 14px 18px 20px 24px; background: #5b5a66; border-radius: 10px 10px 34px 10px; box-shadow: inset 0 2px 0 #ffffff22, inset 0 -3px 0 #0003, 0 6px 16px #0003; }
.gb-led { position: absolute; left: 8px; top: 50%; width: 8px; height: 8px; border-radius: 50%; background: #ff3b3b; box-shadow: 0 0 8px #ff3b3b; }
#gb .nat { display: none; background: #fff; }
#gbc, #gbcc { width: 320px; height: 288px; image-rendering: pixelated; image-rendering: crisp-edges; }
#gbaView { width: min(336px, calc(100vw - 48px)); aspect-ratio: 3 / 2; height: auto; image-rendering: auto; }
#app[data-theme="gen1"] #gbc, #app[data-theme="gen2"] #gbcc, #app[data-theme="gen3"] #gbaView { display: block; }
/* era bodies: GBC (Crystal) and GBA */
#app[data-theme="gen2"].native .battle { background: linear-gradient(#5d4a8f, #4a3a78); }
#app[data-theme="gen2"].native .gb-bezel { background: #2e2a3a; border-radius: 12px 12px 30px 12px; }
#app[data-theme="gen3"].native .battle { background: linear-gradient(#4f4fa8, #3c3c8c); }
#app[data-theme="gen3"].native .gb-bezel { background: #22223a; border-radius: 22px; padding: 14px 16px; }
#app[data-theme="gen3"].native .gb-led { left: 5px; }
#app.native[data-theme="gen2"] .scene, #app.native[data-theme="gen2"] .textbox,
#app.native[data-theme="gen3"] .scene, #app.native[data-theme="gen3"] .textbox { display: none; }
#app.native[data-theme="gen2"] .gb, #app.native[data-theme="gen3"] .gb { display: flex; justify-content: center; padding: 4px 0 6px; }
#app.native[data-theme="gen2"] .topbar, #app.native[data-theme="gen3"] .topbar { background: none; }
@media (max-width: 350px) { #gbc { width: 160px; height: 144px; } }
#app[data-theme="gen1"] .console { padding-top: 6px; }
#app[data-theme="gen1"] .menu button { border: 3px solid #2b2b33; border-radius: 8px; background: #f4f2ec; color: #2b2b33; text-transform: uppercase;
  box-shadow: inset 0 0 0 2px #f4f2ec, inset 0 0 0 4px #2b2b33, 0 3px 0 #2b2b3355; font-size: 10px; }
#app[data-theme="gen1"] .menu button:active { transform: translateY(2px); box-shadow: inset 0 0 0 2px #f4f2ec, inset 0 0 0 4px #2b2b33; }
#app[data-theme="gen1"] .menu.main button span::before { content: '▶ '; opacity: 0; }
#app[data-theme="gen1"] .menu.main button:hover span::before, #app[data-theme="gen1"] .menu.main button:active span::before { opacity: 1; }
#app[data-theme="gen1"] .menu.main .a1 { background: #9a2257; color: #fff; box-shadow: inset 0 0 0 2px #9a2257, inset 0 0 0 4px #f4f2ec, 0 3px 0 #2b2b3355; }
#app[data-theme="gen1"] .mbtn { border-left-width: 3px !important; }
#app[data-theme="gen1"] .chip { background: #2b2b33 !important; color: #f4f2ec; border-radius: 0; text-shadow: none; font-size: 7px; }
#app[data-theme="gen1"] .mbtn .mn, #app[data-theme="gen1"] .pbtn .pn { font-size: 9px; font-weight: 400; }
#app[data-theme="gen1"] .mbtn .mi { font-size: 7px; }
#app[data-theme="gen1"] .pbtn img { filter: grayscale(1) contrast(1.4); }
#app[data-theme="gen1"] .topbar .pill, #app[data-theme="gen1"] .skin-switch { background: #2b2b33; color: #f4f2ec; backdrop-filter: none; border-radius: 6px; }
#app[data-theme="gen1"] .skin-switch button.on { background: #f4f2ec; color: #2b2b33; border-radius: 4px; }
#app[data-theme="gen1"] .lv::before, #app[data-theme="gen2"] .lv::before { content: ':L'; }
#app[data-theme="gen1"] .nm, #app[data-theme="gen2"] .nm { text-transform: uppercase; }
#app[data-theme="gen2"] .menu button { border: 3px solid #181818; border-radius: 6px; background: #fff; color: #181818; text-transform: uppercase; font-size: 10px; }
#app[data-theme="gen2"] .menu.main button span::before { content: '▶ '; opacity: 0; }
#app[data-theme="gen2"] .menu.main button:hover span::before, #app[data-theme="gen2"] .menu.main button:active span::before { opacity: 1; }
#app[data-theme="gen2"] .st { background: #222 !important; color: #fff; border-radius: 0; font-size: 7px; }
#app[data-theme="gen2"] .mbtn .mn, #app[data-theme="gen2"] .pbtn .pn { font-size: 9px; font-weight: 400; }
#app[data-theme="gen2"] .mbtn .mi { font-size: 7px; }

/* =================================================================
   THEME: GEN II — Game Boy Color, Crystal
   ================================================================= */
#app[data-theme="gen2"] {
  --font: 'Press Start 2P', monospace; --fs: 11px;
  --g0: #181818; --g3: #f8f8f8;
  --bg: #f8f8f8; --fg: #181818; --muted: #606060; --panel: #fff; --panel-b: #181818;
  --hp-hi: #00b800; --hp-mid: #f8a800; --hp-lo: #f80000;
  --aspect: 10/9; --scene-bg: #f8f8f8;
}
#app[data-theme="gen2"] .battle { background: #f8f8f8; }
#app[data-theme="gen2"] .scene { background: linear-gradient(#f8f8f8 60%, #e8f0f8); }
#app[data-theme="gen2"] .hud { color: #181818; font-size: 10px; }
#app[data-theme="gen2"] .hp-label { font-size: 7px; padding: 1px 2px; background: #181818; color: #f8b800; }
#app[data-theme="gen2"] .hp-bar { height: 6px; border: 2px solid #181818; border-radius: 4px; background: #fff; }
#app[data-theme="gen2"] .hud.foe { padding: 0 0 8px 6px; border-left: 3px solid #181818; border-bottom: 3px solid #181818; }
#app[data-theme="gen2"] .hud.me { padding: 0 6px 8px 0; border-right: 3px solid #181818; border-bottom: 3px solid #181818; }
#app[data-theme="gen2"] .hud.me .exp { display: block; height: 4px; margin-top: 4px; background: #e0e0e0; border: 1px solid #181818; }
#app[data-theme="gen2"] .hud.me .exp i { display: block; height: 100%; width: 62%; background: #3880f8; }
#app[data-theme="gen2"] .pips b { border-radius: 50%; width: 7px; height: 7px; background: #f80000; box-shadow: 0 0 0 1px #181818; }
#app[data-theme="gen2"] .console { background: #f8f8f8; }
#app[data-theme="gen2"] .textbox { background: #fff; color: #181818; border: 3px solid #181818; border-radius: 4px; padding: 14px 16px; line-height: 2; font-size: 10px;
  box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 5px #6890b0, inset 0 0 0 7px #fff, inset 0 0 0 9px #181818; }
#app[data-theme="gen2"] .menu button { box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px #6890b0; }
#app[data-theme="gen2"] .menu button:active { background: #e8f0ff; }
#app[data-theme="gen2"] .mbtn { border-left: 10px solid var(--tc) !important; }
#app[data-theme="gen2"] .chip { border-radius: 2px; text-shadow: none; font-size: 7px; }
#app[data-theme="gen2"] .floater { color: #181818; text-shadow: 2px 2px 0 #fff; font-size: 12px; }
#app[data-theme="gen2"] .topbar .pill, #app[data-theme="gen2"] .skin-switch { background: #181818; border-radius: 4px; backdrop-filter: none; }

/* =================================================================
   THEME: GEN III — Game Boy Advance, Emerald
   ================================================================= */
#app[data-theme="gen3"] {
  --font: 'Pixelify Sans', monospace; --fs: 16px;
  --bg: #283848; --fg: #fff; --muted: #c8d0e0; --panel: #f8f8f8; --panel-b: #686078;
  --hp-hi: linear-gradient(#70f8a8 0 30%, #18c020 30%); --hp-mid: linear-gradient(#f8e038 0 30%, #c8a808 30%); --hp-lo: linear-gradient(#f85838 0 30%, #a82010 30%);
  --aspect: 3/2.2;
}
#app[data-theme="gen3"] .battle { background: #283848; }
#app[data-theme="gen3"] .scene { background:
  linear-gradient(180deg, #f8f8e0 0%, #d8f0c0 30%, #a8d890 46%, #78c070 47%, #88d080 60%, #68b060 100%); }
#app[data-theme="gen3"] .scene .bg i { display: block; border-radius: 50%; background: #a0e0a0; opacity: .5; }
#app[data-theme="gen3"] .scene .bg .b1 { width: 40%; height: 7%; left: -6%; top: 52%; }
#app[data-theme="gen3"] .scene .bg .b2 { width: 30%; height: 5%; right: 4%; top: 72%; }
#app[data-theme="gen3"] .scene .bg .b3 { width: 60%; height: 18%; left: 20%; top: 10%; background: #fff; opacity: .55; filter: blur(10px); }
#app[data-theme="gen3"] .platform { display: block; background: #c8e8a0; box-shadow: inset 0 -4px 0 #88b868, 0 0 0 3px #507840; }
#app[data-theme="gen3"] .platform.foe { width: 46%; height: 11%; right: 2%; bottom: 43%; }
#app[data-theme="gen3"] .platform.me { width: 56%; height: 12%; left: -6%; bottom: -3%; }
#app[data-theme="gen3"] .hud { background: #f8f8d8; color: #383838; border: 3px solid #404040; border-radius: 10px 4px 10px 4px; padding: 5px 10px 6px; box-shadow: 3px 3px 0 #a0a088, inset 0 0 0 2px #e0e0b8; font-size: 15px; text-shadow: 1px 1px 0 #d8d0b0; width: 52%; }
#app[data-theme="gen3"] .hud.foe { top: 6%; left: 3%; }
#app[data-theme="gen3"] .hud.me { bottom: 5%; right: 2%; }
#app[data-theme="gen3"] .lv::before { content: 'Lv'; font-size: .8em; }
#app[data-theme="gen3"] .hp-label { font-size: 10px; font-weight: 600; padding: 0 4px; border-radius: 3px; background: #404040; color: #f8b800; text-shadow: none; }
#app[data-theme="gen3"] .hp-bar { height: 7px; background: #404040; border: 2px solid #404040; border-radius: 3px; }
#app[data-theme="gen3"] .hp-num { font-size: 15px; }
#app[data-theme="gen3"] .hud.me .exp { display: block; height: 4px; margin: 3px 0 0 26px; background: #404040; border-radius: 2px; }
#app[data-theme="gen3"] .hud.me .exp i { display: block; height: 100%; width: 40%; background: #40c8f8; }
#app[data-theme="gen3"] .console { background: #283848; }
#app[data-theme="gen3"] .textbox { background: #284050; color: #fff; border: 4px solid #c84848; outline: 3px solid #283040; border-radius: 8px; box-shadow: inset 0 0 0 3px #d8a050; text-shadow: 2px 2px 0 #686878; font-size: 17px; padding: 12px 18px; }
#app[data-theme="gen3"] .menu button { background: #f8f8f8; color: #484848; border: 3px solid #686078; border-radius: 8px; box-shadow: inset 0 0 0 2px #d0d0e0, 2px 2px 0 #1a2430; text-shadow: 1px 1px 0 #d0d0d8; font-size: 17px; text-transform: uppercase; }
#app[data-theme="gen3"] .menu.main button span::before { content: '▶'; color: #e83838; margin-right: 6px; opacity: 0; }
#app[data-theme="gen3"] .menu.main button:hover span::before, #app[data-theme="gen3"] .menu.main button:active span::before { opacity: 1; }
#app[data-theme="gen3"] .mbtn { text-transform: none !important; }
#app[data-theme="gen3"] .mbtn .mn { font-weight: 600; }
#app[data-theme="gen3"] .mbtn .mi { font-size: 12px; }
#app[data-theme="gen3"] .chip { border-radius: 4px; border: 1px solid #0004; }
#app[data-theme="gen3"] .pips b { width: 9px; height: 9px; }
#app[data-theme="gen3"] .floater { font-family: 'Pixelify Sans'; text-shadow: 2px 2px 0 #404040; }
#app[data-theme="gen3"] .hud.me > .pips { top: -16px; }

/* =================================================================
   THEME: MODERN — HD glass arena
   ================================================================= */
#app[data-theme="modern"] .scene { background: radial-gradient(120% 80% at 50% 110%, #3b1d7a 0%, #140c2e 55%, #07070f 100%); --aspect: 4/4.4; }
#app[data-theme="modern"] .scene .bg i { display: block; border-radius: 50%; filter: blur(40px); opacity: .55; animation: drift 12s ease-in-out infinite alternate; }
#app[data-theme="modern"] .scene .bg .b1 { width: 70%; height: 50%; left: -20%; top: -10%; background: #7c3aed; }
#app[data-theme="modern"] .scene .bg .b2 { width: 60%; height: 40%; right: -20%; top: 20%; background: #0891b2; animation-delay: -6s; }
#app[data-theme="modern"] .scene .bg .b3 { width: 120%; height: 30%; left: -10%; bottom: -12%; background: #db2777; opacity: .35; animation-delay: -3s; }
#app[data-theme="modern"] .scene::after { content: ''; position: absolute; inset: 52% -40% -20%; z-index: 0; background:
  repeating-linear-gradient(90deg, #ffffff10 0 1px, transparent 1px 40px), repeating-linear-gradient(0deg, #ffffff10 0 1px, transparent 1px 40px);
  transform: perspective(300px) rotateX(62deg); transform-origin: 50% 0; mask-image: linear-gradient(transparent, #000 30%, transparent); }
#app[data-theme="modern"] .platform { display: block; z-index: 2; background: radial-gradient(closest-side, #a78bfa66, #a78bfa11 70%, transparent); box-shadow: 0 0 0 2px #c4b5fd55, 0 0 40px #8b5cf655; animation: halo 3s ease-in-out infinite; }
#app[data-theme="modern"] .platform.foe { width: 44%; height: 9%; right: 4%; bottom: 44%; }
#app[data-theme="modern"] .platform.me { width: 58%; height: 12%; left: -2%; bottom: 5%; animation-delay: -1.5s; }
@keyframes halo { 50% { box-shadow: 0 0 0 2px #67e8f977, 0 0 60px #22d3ee55; } }
#app[data-theme="modern"] .mon.foe { bottom: 48%; }
#app[data-theme="modern"] .mon.me { bottom: 9%; left: 6%; }
#app[data-theme="modern"] .mon .sprite { image-rendering: pixelated; filter: drop-shadow(0 6px 10px #0009); }
#app[data-theme="modern"] .hud { background: linear-gradient(135deg, #ffffff1f, #ffffff08); border: 1px solid #ffffff2a; border-radius: 16px; padding: 9px 12px 8px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: 0 8px 30px #0006; font-size: 14px; width: 54%; }
#app[data-theme="modern"] .hud .nm { font-weight: 700; }
#app[data-theme="modern"] .lv { font-size: 11px; color: #c4b5fd; font-weight: 600; }
#app[data-theme="modern"] .lv::before { content: 'Lv. '; }
#app[data-theme="modern"] .hp-label { display: none; }
#app[data-theme="modern"] .hp-bar { height: 8px; border-radius: 99px; background: #ffffff18; }
#app[data-theme="modern"] .hp-bar i { border-radius: 99px; box-shadow: 0 0 12px #34d39988; }
#app[data-theme="modern"] .hp-num { font-size: 12px; font-weight: 600; color: #e9e5ff; font-variant-numeric: tabular-nums; }
#app[data-theme="modern"] .st { border-radius: 99px; font-size: 9.5px; padding: 2px 7px; }
#app[data-theme="modern"] .hud.me > .pips { top: -16px; }
#app[data-theme="modern"] .pips b { box-shadow: 0 0 6px #f44a; }
#app[data-theme="modern"] .battle { background: #07070f; }
#app[data-theme="modern"] .textbox { border-radius: 18px; background: linear-gradient(135deg,#ffffff14,#ffffff06); border: 1px solid #ffffff22; font-size: 16px; font-weight: 500; }
#app[data-theme="modern"] .menu button { border-radius: 18px; background: linear-gradient(135deg,#ffffff16,#ffffff06); border: 1px solid #ffffff1f; font-weight: 700; font-size: 17px; transition: transform .12s, box-shadow .2s; overflow: hidden; }
#app[data-theme="modern"] .menu button:active { transform: scale(.96); }
#app[data-theme="modern"] .menu.main .a1 { background: linear-gradient(140deg,#f43f5e,#c026d3 60%,#7c3aed); box-shadow: 0 10px 30px #c026d355; font-size: 24px; letter-spacing: .5px; }
#app[data-theme="modern"] .menu.main .a1::after { content: ''; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 30%, #fff4 45%, transparent 60%); animation: sheen 3.2s ease-in-out infinite; }
@keyframes sheen { from { transform: translateX(-100%); } 60%,to { transform: translateX(100%); } }
#app[data-theme="modern"] .menu.main .a2 { background: linear-gradient(140deg,#0891b2,#22d3ee); }
#app[data-theme="modern"] .mbtn { background: linear-gradient(135deg, color-mix(in srgb, var(--tc) 70%, #000) 0%, color-mix(in srgb, var(--tc) 30%, #0b0b1a) 100%) !important; border: 1px solid color-mix(in srgb, var(--tc) 60%, #fff) !important; box-shadow: 0 6px 20px color-mix(in srgb, var(--tc) 35%, transparent); }
#app[data-theme="modern"] .mbtn .mn { font-size: 16px; }
#app[data-theme="modern"] .mbtn .chip { background: #0005 !important; }
#app[data-theme="modern"] .pbtn img { image-rendering: auto; }

#app[data-theme="modern"] .topbar { background: #07070f; }
#app[data-theme="gen1"] .topbar { background: var(--g3); }
#app[data-theme="gen2"] .topbar { background: #f8f8f8; }
#app[data-theme="gen3"] .topbar { background: #283848; }

/* =================================================================
   LAYOUT: battle screen + selector + team sides + move explorer
   Phones: tabs under the screen. ≥1100px: your team left, foe + explorer right.
   ================================================================= */
.battle { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto auto auto minmax(0, 1fr);
  grid-template-areas: "top top" "screen screen" "tabs tabs" "ctl ctl"; }
.battle > .topbar { grid-area: top; }
.battle > #gb, .battle > .scene { grid-area: screen; }
.battle > .ptabs { grid-area: tabs; }
.battle > .console { grid-area: ctl; }
.battle > #sideMe { grid-area: me; }
.battle > #sideFoe { grid-area: foe; }
.battle > .explorer { grid-area: ex; }
.side, .explorer { display: none; min-width: 0; overflow-y: auto; padding: 8px 10px 12px; }
.battle[data-pane="teams"] { grid-template-areas: "top top" "screen screen" "tabs tabs" "me foe"; }
.battle[data-pane="teams"] > .console { display: none; }
.battle[data-pane="teams"] > .side { display: block; }
.battle[data-pane="moves"] { grid-template-areas: "top top" "screen screen" "tabs tabs" "ex ex"; }
.battle[data-pane="moves"] > .console { display: none; }
.battle[data-pane="moves"] > .explorer { display: flex; }

.ptabs { display: flex; gap: 4px; padding: 6px 12px 0; }
.ptabs button { flex: 1; min-height: 36px; border-radius: 10px; font: 600 13px 'Outfit', system-ui, sans-serif; color: var(--muted); background: transparent; border: 1px solid transparent; }
.ptabs button[aria-selected="true"] { color: var(--fg); background: var(--panel); border-color: var(--panel-b); }

@media (min-width: 1100px) {
  #app { max-width: 1240px; }
  .battle, .battle[data-pane] { grid-template-columns: 300px minmax(0, 480px) 380px; justify-content: center; column-gap: 12px;
    grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "top top top" "me screen foe" "me ctl ex"; }
  .battle > .ptabs { display: none; }
  .battle > .console, .battle[data-pane] > .console { display: flex; }
  .battle > .side, .battle[data-pane] > .side { display: block; }
  .battle > .explorer, .battle[data-pane] > .explorer { display: flex; }
}

/* team sides */
.side h3 { margin: 4px 2px 8px; font: 700 12px 'Outfit', system-ui, sans-serif; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; }
.side h3 b { color: var(--fg); font-weight: 700; letter-spacing: 0; }
.tmon { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 6px; align-items: center; padding: 6px 8px 6px 4px; border-radius: 12px; border: 1px solid var(--panel-b); background: var(--panel); margin-bottom: 6px; font-family: 'Outfit', system-ui, sans-serif; color: var(--fg); }
.tmon.active { outline: 2px solid var(--accent, #7c5cff); outline-offset: -1px; }
.tmon.fainted { opacity: .45; filter: grayscale(1); }
.tmon .mini { width: 44px; height: 38px; object-fit: contain; image-rendering: pixelated; }
.tmon .mini.smooth { image-rendering: auto; }
.tmon .top { display: flex; justify-content: space-between; gap: 6px; font-size: 13px; font-weight: 700; }
.tmon .top span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tmon .top small { color: var(--muted); font-weight: 600; flex: none; }
.tmon .hp { height: 6px; border-radius: 99px; background: #8883; overflow: hidden; margin: 4px 0 3px; }
.tmon .hp i { display: block; height: 100%; width: var(--w); background: var(--c); }
.tmon .sub { display: flex; gap: 6px; align-items: center; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tmon .st { position: static; }

/* move explorer */
.explorer { flex-direction: column; gap: 8px; }
.ex-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ex-head h3 { margin: 0; font: 700 12px 'Outfit', system-ui, sans-serif; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.seg.mini button { padding: 6px 10px; font-size: 12px; }
.ex-list { display: flex; flex-direction: column; gap: 6px; }
.ex-mon { display: flex; gap: 8px; align-items: center; font: 600 13px 'Outfit', system-ui, sans-serif; color: var(--fg); }
.ex-mon img { width: 40px; height: 34px; object-fit: contain; image-rendering: pixelated; }
.exm { border: 1px solid var(--panel-b); background: var(--panel); border-radius: 12px; padding: 8px 10px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 8px; font-family: 'Outfit', system-ui, sans-serif; color: var(--fg); border-left: 4px solid var(--tc); }
.exm .nm { font-weight: 700; font-size: 14px; display: flex; gap: 6px; align-items: center; min-width: 0; }
.exm .stats { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; font-size: 11px; color: var(--muted); }
.exm .stats b { display: block; color: var(--fg); font-size: 13px; font-variant-numeric: tabular-nums; }
.exm .note { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.exm .note.good { color: #2f9e57; } .exm .note.bad { color: #d0533f; }
.exm button { font: 600 12px 'Outfit', system-ui, sans-serif; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--panel-b); background: var(--bg); color: var(--fg); }
.exm button:disabled { opacity: .4; }

/* canvas-rendered era selectors */
.menu-canvas { flex: 1; display: flex; align-items: flex-start; justify-content: center; min-height: 0; }
#menuView { width: 100%; max-width: 420px; height: auto; max-height: 100%; object-fit: contain; touch-action: manipulation; cursor: pointer; border-radius: 6px; }
.controls.busy .menu-canvas { opacity: .55; filter: saturate(.4); pointer-events: none; }
#app[data-ui="gen1"] .console, #app[data-ui="gen2"] .console, #app[data-ui="gen3"] .console { padding-top: 6px; }

/* modern HTML selector under any battle screen */
#app[data-ui="modern"][data-ui] .menu button { border-radius: 18px; background: linear-gradient(135deg,#ffffff1c,#ffffff08); border: 1px solid #ffffff2a; color: #fff; font: 700 17px 'Outfit', system-ui, sans-serif; text-transform: none; box-shadow: none; overflow: hidden; }
#app[data-ui="modern"][data-ui] .console { background: #0d0d1d; border-radius: 18px 18px 0 0; }
#app[data-ui="modern"][data-ui] .menu.main .a1 { background: linear-gradient(140deg,#f43f5e,#c026d3 60%,#7c3aed); font-size: 24px; }
#app[data-ui="modern"][data-ui] .menu.main .a2 { background: linear-gradient(140deg,#0891b2,#22d3ee); }
#app[data-ui="modern"][data-ui] .menu.main button span::before { content: none; }
#app[data-ui="modern"][data-ui] .mbtn { background: linear-gradient(135deg, color-mix(in srgb, var(--tc) 70%, #000), color-mix(in srgb, var(--tc) 30%, #0b0b1a)) !important; border: 1px solid color-mix(in srgb, var(--tc) 60%, #fff) !important; }
#app[data-ui="modern"][data-ui] .mbtn .mn, #app[data-ui="modern"][data-ui] .pbtn .pn { font: 700 15px 'Outfit', system-ui, sans-serif; }
#app[data-ui="modern"][data-ui] .mbtn .mi { font: 600 11px 'Outfit', system-ui, sans-serif; }
#app[data-ui="modern"][data-ui] .chip { border-radius: 999px; font: 600 10.5px 'Outfit', system-ui, sans-serif; background: #0005 !important; color: #fff; }
#app[data-ui="modern"][data-ui] .pbtn img { image-rendering: auto; filter: none; }
.pbtn img.smooth { image-rendering: auto; }

/* settings sheet */
.sheet { position: absolute; inset: 0; z-index: 60; background: #0008; backdrop-filter: blur(6px); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card { width: min(100%, 520px); max-height: 92%; overflow-y: auto; background: #15152b; color: #eef0ff; border-radius: 22px 22px 0 0; padding: 16px 16px max(18px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; font-family: 'Outfit', system-ui, sans-serif; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet .label { color: #a7acd4; margin-top: 8px; }
.sheet .label small { text-transform: none; letter-spacing: 0; font-weight: 500; }
.sheet .seg { --panel: #ffffff10; --panel-b: #ffffff22; --muted: #a7acd4; }
.sheet .seg.wrap { display: flex; flex-wrap: wrap; }
.sheet .seg.wrap button { flex: 1 1 140px; }
.sheet .check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: #dcdcf5; }
.mini-preview { display: flex; gap: 6px; flex-wrap: wrap; padding: 6px 0; }
.mini-preview img { width: 48px; height: 40px; object-fit: contain; image-rendering: pixelated; background: #ffffff0d; border-radius: 8px; }
.mini-preview img.smooth { image-rendering: auto; }
