@font-face {
  font-family: 'PokemonGBA';
  src: url('/assets/fonts/pokemon.ttf') format('truetype');
  font-display: block;
}
@font-face {
  font-family: 'PokemonGBA Small';
  src: url('/assets/fonts/pokemon-small.ttf') format('truetype');
  font-display: block;
}

:root {
  --ink: #303848;
  --ink-soft: #5c6478;
  --shadow: #d0d0c8;
  --paper: #f8f8f2;
  --paper-2: #e8ecf0;
  --line: #4a5470;
  --line-2: #8898b8;
  --accent: #e04040;
  --accent-2: #f87858;
  --blue: #3870c8;
  --green: #38b060;
  --yellow: #f0c030;
  --night: #0c1428;
  --font: 'PokemonGBA', 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  --px: 2px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0e1320; color: var(--ink); font-family: var(--font); font-size: 16px; overflow: hidden; }
/* Phones: no double-tap zoom, no rubber-band scrolling of the page, no
   font boosting. Pinch zoom stays possible on the login screens. */
html { touch-action: manipulation; overscroll-behavior: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* The game: never panned, zoomed or text-selected by a finger (panels that
   scroll say so themselves: touch-action pan-y); inputs and the chat log
   stay selectable. */
#app { position: fixed; inset: 0; overflow: hidden; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#app input, #app textarea, #app [contenteditable] { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
#app img { -webkit-user-drag: none; }
/* field.js places the world canvas (left / top on the device pixel grid). */
#world { position: absolute; left: 0; top: 0; image-rendering: pixelated; image-rendering: crisp-edges; }
#overlay { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 2; }
#night { position: absolute; inset: 0; pointer-events: none; transition: background 2s; }
#fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 50; }
#fade.on { opacity: 1; }
#fade.white { background: #fff; }

/* ------------------------------------------------------------------ windows */
.win {
  background: var(--paper);
  border: calc(var(--px) * 2) solid var(--line);
  border-radius: 10px;
  box-shadow: inset 0 0 0 var(--px) #fff, inset 0 0 0 calc(var(--px) * 2) var(--line-2), 0 6px 0 rgba(0, 0, 0, .25);
  color: var(--ink);
  text-shadow: 1px 1px 0 var(--shadow);
}
.btn {
  appearance: none; cursor: pointer; border: 2px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 14px;
  box-shadow: inset 0 -3px 0 var(--paper-2); text-shadow: 1px 1px 0 var(--shadow);
}
.btn:hover, .btn:focus-visible { background: #fff7e6; outline: none; border-color: var(--accent); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn.primary { background: var(--accent); color: #fff; border-color: #a02828; text-shadow: 1px 1px 0 #802020; box-shadow: inset 0 -3px 0 #b83030; }
.btn.primary:hover { background: #f05050; }
.btn.small { padding: 2px 8px; font-size: 14px; }
.btn[disabled] { opacity: .5; cursor: default; }
.muted { color: var(--ink-soft); }
.error { color: var(--accent); min-height: 1.2em; margin: 6px 0 0; }

/* ------------------------------------------------------------------ auth */
/* Login and new trainer: centred, scrolling (not clipped) when a phone on its
   side or its keyboard leaves less room than the box needs. */
.screen { position: fixed; inset: 0; display: flex; z-index: 100; overflow: auto; overscroll-behavior: contain; padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: radial-gradient(ellipse at 50% 30%, #3a5a9a 0%, #1c2a4c 55%, #0e1320 100%); }
/* The sign-in scene (tools/extract-field-title.js, 832x700): at the smallest
   whole-number zoom that fills the screen (ui/title.js sets --title-size and
   --title-x), panning from the town down to the harbour; darker at the top
   and bottom so the logo and the window read well. */
.title-art { position: fixed; inset: 0; background: url('/assets/title/olivine.png') no-repeat; background-size: var(--title-size, cover); background-position: var(--title-x, 72%) 0%;
  image-rendering: pixelated; image-rendering: crisp-edges; pointer-events: none; animation: title-pan 70s ease-in-out infinite alternate; }
.title-art::after { content: ''; position: absolute; inset: 0; background:
  linear-gradient(180deg, rgba(8, 12, 26, .55) 0%, rgba(8, 12, 26, 0) 26%, rgba(8, 12, 26, 0) 62%, rgba(8, 12, 26, .6) 100%),
  radial-gradient(ellipse at 50% 50%, rgba(6, 10, 22, 0) 55%, rgba(6, 10, 22, .45) 100%); }
@keyframes title-pan { from { background-position: var(--title-x, 72%) 0%; } to { background-position: var(--title-x, 72%) 100%; } }
@media (prefers-reduced-motion: reduce) { .title-art { animation: none; background-position: var(--title-x, 72%) 35%; } }
.screen > .win { margin: auto; }
/* An upright phone: the logo on the scene at the top, the sign-in window at
   the bottom (thumb reach); a computer: both together in the middle; a phone
   on its side: side by side. */
.auth-stage { position: relative; flex: 1; display: grid; grid-template-rows: auto 1fr auto; justify-items: center; gap: 16px; }
.auth-brand { text-align: center; margin-top: 4vh; }
.auth-box { position: relative; align-self: end; width: min(400px, 100%); padding: 18px 20px 14px; text-align: center; display: grid; gap: 12px; }
.auth-box > p { margin: 0; }
#auth-error:empty, #auth-status:empty { display: none; }
#auth .logo { font-size: clamp(34px, 13vw, 52px); }
@media (min-width: 720px) and (min-height: 560px) {
  .auth-stage { grid-template-rows: 1fr auto auto 1fr; gap: 18px; }
  .auth-brand { grid-row: 2; margin: 0; padding: 22px 56px 18px; border-radius: 50%; background: radial-gradient(ellipse at 50% 50%, rgba(8, 12, 26, .72) 0%, rgba(8, 12, 26, .5) 45%, rgba(8, 12, 26, 0) 72%); }
  .auth-box { grid-row: 3; align-self: start; }
  #auth .logo { font-size: 64px; }
}
@media (max-height: 520px) and (min-width: 560px) {
  .auth-stage { grid-template-rows: auto; grid-template-columns: minmax(0, 1fr) minmax(0, 400px); align-items: center; column-gap: 24px; }
  .auth-brand { margin: 0; }
  .auth-box { align-self: center; }
  #auth .logo { font-size: 40px; }
}
@media (max-height: 460px) { .auth-box { padding: 12px 18px 8px; gap: 8px; } .logo { font-size: 30px; } .tagline { margin-bottom: 8px; } #auth-form label, .name-field { margin-bottom: 6px; } .gender-pick { margin: 6px 0; } .gender canvas { width: 32px; height: 64px; } }
.jo-touch .gender, .jo-touch .auth-actions .btn, .jo-touch .screen input { min-height: 44px; }
.logo { margin: 0; font-size: 40px; letter-spacing: 1px; color: var(--accent); text-shadow: 2px 2px 0 #f8c0a8, 4px 4px 0 var(--line); }
.logo span { color: var(--blue); text-shadow: 2px 2px 0 #b8d0f8, 4px 4px 0 var(--line); }
.tagline { margin: 4px 0 18px; color: var(--ink-soft); }
/* on the scene: outlined in night blue */
#auth .logo { line-height: 1; font-weight: normal;
  text-shadow: 3px 3px 0 #f8c0a8, -2px -2px 0 var(--night), 2px -2px 0 var(--night), -2px 2px 0 var(--night), 2px 2px 0 var(--night), 5px 5px 0 var(--night); }
#auth .logo span { color: #5890e8; text-shadow: 3px 3px 0 #b8d0f8, -2px -2px 0 var(--night), 2px -2px 0 var(--night), -2px 2px 0 var(--night), 2px 2px 0 var(--night), 5px 5px 0 var(--night); }
#auth .tagline { margin: 10px 0 0; color: #fff; font-size: 17px; text-shadow: 2px 2px 0 var(--night); }
.auth-online { display: inline-flex; align-items: center; gap: 8px; margin: 12px 0 0; padding: 4px 12px; border-radius: 999px; background: rgba(8, 12, 26, .62); color: #fff; font-size: 15px; text-shadow: 1px 1px 0 var(--night); }
.auth-online i { width: 10px; height: 10px; border-radius: 50%; background: #58d878; box-shadow: 0 0 0 2px rgba(88, 216, 120, .3); }
/* loading: an HP-bar style meter where the button will be */
.auth-load { display: grid; gap: 8px; font-size: 15px; color: var(--ink-soft); }
.auth-bar { height: 16px; border: 3px solid var(--line); border-radius: 8px; background: #505868; padding: 2px; }
.auth-bar i { display: block; height: 100%; width: 0; border-radius: 3px; background: linear-gradient(#70f8a8 0 45%, #58d080 45%); transition: width .2s; }
.auth-fine { font-size: 12px; line-height: 1.4; color: var(--ink-soft); text-shadow: none; }
#auth-form label, .name-field { display: grid; text-align: left; gap: 4px; margin-bottom: 12px; }
input { border: 2px solid var(--line-2); border-radius: 6px; padding: 7px 9px; background: #fff; outline: none; }
input:focus { border-color: var(--blue); }
.auth-actions { display: flex; gap: 10px; justify-content: center; margin-top: 6px; flex-wrap: wrap; }
/* Sign in with Google, the primary way in, and the username form under it
   when the server allows it (docs/auth.md). Touch targets are 44px. */
#auth .google-btn { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; min-height: 54px; box-sizing: border-box; text-decoration: none; font-weight: bold; font-size: 18px; border-radius: 10px; }
#auth .google-btn .g-mark { width: 28px; height: 28px; flex: none; padding: 4px; background: #fff; border-radius: 50%; }
.auth-or { display: flex; align-items: center; gap: 8px; margin: 2px 0 0; font-size: 14px; }
.auth-or::before, .auth-or::after { content: ''; flex: 1; border-top: 2px solid var(--line-2); }
.auth-actions .btn { min-height: 44px; }
.account-win .body { display: grid; gap: 8px; }
.account-win p { margin: 0; }
.account-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.account-actions .btn { min-height: 44px; }
.account-actions .btn.sel { border-color: var(--accent); }

.create-box { width: min(620px, 100%); padding: 22px; text-align: center; }
.create-box h2 { margin: 0 0 4px; }
.gender-pick { display: flex; justify-content: center; gap: 12px; margin: 14px 0; }
.gender { display: grid; justify-items: center; gap: 4px; cursor: pointer; border: 2px solid var(--line-2); background: #fff; border-radius: 10px; padding: 8px 18px; }
.gender canvas { width: 48px; height: 96px; image-rendering: pixelated; }
.gender.active { border-color: var(--accent); background: #fff2ea; }
.name-field { max-width: 280px; margin: 0 auto 12px; }
.starters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.starter { cursor: pointer; border: 2px solid var(--line-2); border-radius: 10px; background: #fff; padding: 6px 4px; display: grid; justify-items: center; }
.starter img { width: 64px; height: 64px; image-rendering: pixelated; object-fit: none; object-position: 0 0; }
.starter.active { border-color: var(--accent); background: #fff2ea; }
.starter .types { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; }

/* ------------------------------------------------------------------ HUD */
/* The game bar, chat, party cards and pads are the social layer
   (client/css/social-ui.css + social-layout.css); --bar-bottom is the bar's bottom edge. */
.alpha-mark { color: #d03030; font-weight: bold; }
.banner { position: absolute; left: calc(14px + env(safe-area-inset-left, 0px)); top: calc(var(--bar-bottom, 46px) + 8px); z-index: 11; padding: 6px 16px; animation: bannerIn 2.6s ease forwards; pointer-events: none; }
@keyframes bannerIn { 0% { transform: translateY(-80px); } 12%, 82% { transform: translateY(0); } 100% { transform: translateY(-80px); } }

#party-strip { position: absolute; right: calc(10px + env(safe-area-inset-right, 0px)); top: calc(var(--bar-bottom, 46px) + 8px); display: grid; gap: 3px; z-index: 9; pointer-events: none; }
.ps-mon { display: grid; grid-template-columns: 32px 1fr; align-items: center; width: 150px; background: rgba(248, 248, 242, .88); border: 2px solid var(--line); border-radius: 8px; padding: 0 6px 2px 0; font-size: 14px; }
.ps-mon.fainted { opacity: .6; }
.ps-mon .ico { width: 32px; height: 32px; }
.ps-name { display: flex; justify-content: space-between; gap: 4px; }

/* ------------------------------------------------------------------ dialog */
/* The message box: at the bottom of the room the pads leave (--free-*,
   ui/layout.js); ui.js moves it beside or above the chat when that is in
   the way. A tap or click anywhere on it is A. */
.dialog { position: absolute; left: calc(var(--free-l, 0px) + (100% - var(--free-l, 0px) - var(--free-r, 0px)) / 2); bottom: calc(var(--free-b, 0px) + 14px); transform: translateX(-50%); width: min(700px, calc(100% - var(--free-l, 0px) - var(--free-r, 0px) - 24px)); min-height: 94px; padding: 14px 20px 14px; z-index: 30; font-size: 20px; line-height: 30px; cursor: pointer; touch-action: manipulation; }
.dialog.placed { transform: none; }
/* A box drawn on a black screen shows over the black (#fade, z 50): the
   source's box loads its palette unfaded (ui.js msgbox, overBlack). */
.dialog.over-fade { z-index: 51; }
.dialog-text { white-space: pre-wrap; min-height: 60px; }
.dialog-arrow { position: absolute; right: 16px; bottom: 6px; color: var(--accent); font-size: 14px; animation: bob .6s steps(2) infinite; }
.dialog-speaker { position: absolute; top: -16px; left: 16px; background: var(--blue); color: #fff; border-radius: 6px; padding: 0 8px; font-size: 16px; line-height: 24px; text-shadow: 1px 1px 0 #204080; }
.dialog-choices { position: absolute; right: 0; bottom: calc(100% + 8px); z-index: 1; padding: 8px 12px; min-width: 110px; display: grid; gap: 2px; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; cursor: default; }
.choice { cursor: pointer; padding: 1px 4px 1px 20px; position: relative; }
.jo-touch .choice { display: flex; align-items: center; min-height: 44px; padding-right: 12px; }
.jo-touch .choice.sel::before { top: 50%; transform: translateY(-50%); }
.choice.sel::before, .menu-item.sel::before { content: '▶'; position: absolute; left: 3px; color: var(--ink); font-size: 12px; }
@keyframes bob { 50% { transform: translateY(3px); } }

/* ------------------------------------------------------------------ generic windows */
/* Windows open in the room the pads, the notch and the keyboard leave
   (--free-*, --kb: ui/layout.js), never wider or taller than it. */
#windows { position: absolute; top: max(var(--free-t, 0px), calc(var(--bar-cover, 0px) + 4px)); left: var(--free-l, 0px); right: var(--free-r, 0px); bottom: max(var(--free-b, 0px), var(--kb, 0px)); pointer-events: none; z-index: 20; }
.window { position: absolute; pointer-events: auto; padding: 12px 14px; max-height: calc(100% - 16px); max-width: calc(100% - 12px); display: flex; flex-direction: column; }
.window.center { left: 50%; top: 50%; transform: translate(-50%, -50%); }
.window h3 { margin: 0 0 8px; font-size: 20px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.window .body, .window .list { overflow: auto; min-height: 0; overscroll-behavior: contain; touch-action: pan-y; }
.close-x { cursor: pointer; border: 0; background: transparent; font-size: 18px; color: var(--ink-soft); }
/* Touch: 44px targets. */
.jo-touch .close-x { min-width: 44px; min-height: 44px; margin: -8px -8px -8px 0; }
.jo-touch .btn { min-height: 44px; }
.jo-touch .menu-item, .jo-touch .window .row { min-height: 44px; }
.jo-touch .menu-item { display: flex; align-items: center; }
.jo-touch .menu-item .key { margin-left: auto; }
.jo-touch .menu-item.sel::before { top: 50%; transform: translateY(-50%); }
.jo-touch .tabs button { min-height: 44px; }
.jo-touch .window input:not([type=checkbox]):not([type=radio]):not([type=range]) { min-height: 44px; font-size: 16px; }
.jo-touch .window input[type=range] { min-height: 44px; }
.jo-touch .window input[type=checkbox] { width: 24px; height: 24px; vertical-align: middle; }
.close-x:hover { color: var(--accent); }

.start-menu { right: 12px; top: 8px; width: 190px; padding: 10px 8px; max-height: calc(100% - 16px); overflow-y: auto; }
.menu-item { cursor: pointer; padding: 4px 8px 4px 22px; position: relative; border-radius: 6px; font-size: 19px; }
.menu-item:hover { background: #eef2fa; }
.menu-item .key { float: right; color: var(--ink-soft); font-size: 13px; }

.list { display: grid; gap: 4px; }
.row { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; }
.row:hover, .row.sel { background: #eef4ff; border-color: var(--line-2); }
.row .grow { flex: 1; min-width: 0; }
.row img.icon { width: 24px; height: 24px; image-rendering: pixelated; }

.type { display: inline-block; min-width: 54px; text-align: center; font-size: 12px; line-height: 16px; border-radius: 4px; padding: 0 5px; color: #fff; text-shadow: 1px 1px 0 rgba(0, 0, 0, .35); text-transform: uppercase; letter-spacing: .5px; }
.t-NORMAL { background: #a8a878; } .t-FIRE { background: #f08030; } .t-WATER { background: #6890f0; } .t-GRASS { background: #78c850; }
.t-ELECTRIC { background: #e0c020; } .t-ICE { background: #78c8c8; } .t-FIGHTING { background: #c03028; } .t-POISON { background: #a040a0; }
.t-GROUND { background: #d8b050; } .t-FLYING { background: #a890f0; } .t-PSYCHIC { background: #f85888; } .t-BUG { background: #a8b820; }
.t-ROCK { background: #b8a038; } .t-GHOST { background: #705898; } .t-DRAGON { background: #7038f8; } .t-DARK { background: #705848; }
.t-STEEL { background: #b8b8d0; } .t-FAIRY { background: #ee99ac; } .t-MYSTERY { background: #68a090; }

.hpbar { position: relative; height: 8px; background: #505860; border: 2px solid #404850; border-radius: 4px; overflow: hidden; }
.hpbar > i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--green); transition: width .6s linear; }
.hpbar.mid > i { background: var(--yellow); }
.hpbar.low > i { background: var(--accent); }
.expbar { height: 5px; background: #505860; border-radius: 3px; overflow: hidden; }
.expbar > i { display: block; height: 100%; background: #48a8f8; transition: width .6s linear; }
.status { font-size: 11px; border-radius: 4px; padding: 0 4px; color: #fff; line-height: 14px; }
.st-PAR { background: #c8a818; } .st-BRN { background: #e05830; } .st-PSN, .st-TOX { background: #a040a0; } .st-SLP { background: #8c8c8c; } .st-FRZ { background: #58a8d8; } .st-FNT { background: #c03030; }

/* party */
.party-win { width: min(560px, calc(100% - 20px)); }
.party-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pcard { border: 2px solid var(--line-2); border-radius: 10px; padding: 6px 8px; background: linear-gradient(#fff, #eef3fb); cursor: pointer; display: grid; grid-template-columns: 40px 1fr; gap: 2px 6px; align-items: center; position: relative; }
.pcard:hover, .pcard.sel { border-color: var(--accent); }
.pcard.lead { background: linear-gradient(#fff6ee, #fde6d8); }
.pcard.fainted { filter: grayscale(.7); }
.pcard .ico { grid-row: span 2; width: 40px; height: 40px; }
.pcard .nm { display: flex; justify-content: space-between; font-size: 17px; }
.pcard .held { position: absolute; right: 6px; bottom: 4px; width: 16px; height: 16px; image-rendering: pixelated; }
.ico { image-rendering: pixelated; background-repeat: no-repeat; }
.party-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.summary { width: min(600px, calc(100% - 20px)); }
.sum-top { display: grid; grid-template-columns: 136px 1fr; gap: 12px; }
.sum-art { width: 128px; height: 128px; image-rendering: pixelated; background-color: #eef4ff; background-repeat: no-repeat; background-size: 128px 256px; background-position: 0 0; border-radius: 10px; border: 2px solid var(--line-2); }
.sum-table { width: 100%; border-collapse: collapse; font-size: 16px; }
.sum-table td { padding: 1px 6px; }
.sum-table td:first-child { color: var(--ink-soft); }
.stat-bar { height: 6px; background: #dde3ee; border-radius: 3px; overflow: hidden; }
.stat-bar > i { display: block; height: 100%; background: var(--blue); }
.moves-list { display: grid; gap: 4px; margin-top: 8px; }
.move-row { display: grid; grid-template-columns: 70px 1fr auto auto; gap: 8px; align-items: center; border: 2px solid var(--line-2); border-radius: 8px; padding: 3px 8px; background: #fff; }

/* bag */
.bag-win { width: min(560px, calc(100% - 20px)); height: min(560px, calc(100% - 20px)); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.tabs button { cursor: pointer; border: 2px solid var(--line-2); background: #fff; border-radius: 8px; padding: 2px 10px; font-size: 15px; }
.tabs button.active { background: var(--blue); color: #fff; border-color: #204890; text-shadow: none; }
.item-desc { min-height: 54px; border-top: 2px dashed var(--line-2); margin-top: 8px; padding-top: 6px; white-space: pre-line; color: var(--ink-soft); font-size: 15px; }
.qty { color: var(--ink-soft); }

/* pc */
.pc-win { width: min(840px, calc(100% - 20px)); height: min(620px, calc(100% - 20px)); }
.pc-layout { display: grid; grid-template-columns: 1fr 220px; gap: 10px; min-height: 0; flex: 1; }
.pc-box { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; background: #d8e8d0; border: 2px solid var(--line-2); border-radius: 10px; padding: 8px; align-content: start; }
.pc-slot { aspect-ratio: 1; border-radius: 8px; background: rgba(255, 255, 255, .45); cursor: pointer; display: grid; place-items: center; border: 2px solid transparent; }
.pc-slot:hover, .pc-slot.sel { border-color: var(--accent); background: #fff; }
.pc-side { display: grid; gap: 6px; align-content: start; }
.pc-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }

/* mart */
.mart-win { width: min(520px, calc(100% - 20px)); max-height: min(600px, calc(100% - 20px)); }
.price { color: var(--blue); }

/* trade */
.trade-win { width: min(760px, calc(100% - 20px)); }
.trade-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.offer { border: 2px dashed var(--line-2); border-radius: 10px; min-height: 150px; padding: 8px; display: grid; justify-items: center; align-content: center; gap: 4px; text-align: center; }
.offer.ready { border-style: solid; border-color: var(--green); background: #eefaf0; }

/* dex */
.dex-win { width: min(760px, calc(100% - 20px)); height: min(640px, calc(100% - 20px)); }
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.dex-cell { border: 2px solid var(--line-2); border-radius: 8px; background: #fff; display: grid; justify-items: center; padding: 2px; font-size: 12px; cursor: pointer; }
.dex-cell.unseen { opacity: .35; }
.dex-cell.caught { border-color: var(--accent); }
.dex-cell .ico { width: 32px; height: 32px; }

/* players (the trainer card is client/css/card.css) */
.who-win { width: min(460px, calc(100% - 20px)); max-height: min(560px, calc(100% - 20px)); }
.ctx-menu { position: absolute; padding: 6px; min-width: 150px; z-index: 40; }

/* evolution / learn prompt */
.evo-win { width: min(420px, calc(100% - 20px)); text-align: center; }
.evo-stage { height: 150px; display: grid; place-items: center; }
.evo-art { width: 128px; height: 128px; image-rendering: pixelated; background-repeat: no-repeat; background-size: 128px 256px; background-position: 0 0; }
.evo-art.flash { animation: evoFlash 0.35s steps(2) infinite; }
@keyframes evoFlash { 50% { filter: brightness(8) saturate(0); } }

/* toasts */
#toasts { position: absolute; left: 50%; top: calc(var(--bar-bottom, 46px) + 8px); transform: translateX(-50%); display: grid; justify-items: center; gap: 6px; z-index: 60; pointer-events: none; width: max-content; max-width: calc(100% - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)); }
.toast { padding: 6px 14px; font-size: 16px; animation: toast 3.6s ease forwards; text-align: center; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ------------------------------------------------------------------ battle */
/* The 240x160 picture (#battle-stage) is where viewport.js placePicture puts
   it (battle/stage.js: left / top / size inline, --bs its pixel scale): the
   largest area the touch pads and the notch leave free. The rest is black. */
#battle { position: absolute; inset: 0; z-index: 25; background: #000; overflow: hidden; }
#battle-stage { position: absolute; left: 0; top: 0; width: 240px; height: 160px; --bs: 1; }
/* The game's windows opened from a battle (the horde's bag, the fallback
   party / move / summary windows) go over it. */
#app.battle-on > #windows { z-index: 26; }
#battle-canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
/* hordes: the source's windows and healthboxes, drawn over the 320x160 scene (battle/horde/view.js) */
#battle-hud-canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; image-rendering: pixelated; pointer-events: none; }
#battle-hud { position: absolute; inset: 0; font-size: calc(var(--bs) * 10px); }
.hb { position: absolute; width: calc(var(--bs) * 104px); padding: calc(var(--bs) * 3px) calc(var(--bs) * 6px); background: #f8f8e8; border: calc(var(--bs) * 1.5px) solid #405048; border-radius: calc(var(--bs) * 5px) calc(var(--bs) * 2px); box-shadow: calc(var(--bs) * 2px) calc(var(--bs) * 2px) 0 rgba(0,0,0,.3); text-shadow: 1px 1px 0 var(--shadow); line-height: 1.2; transition: opacity .3s; }
.hb.foe { left: calc(var(--bs) * 10px); top: calc(var(--bs) * 12px); }
.hb.me { right: calc(var(--bs) * 8px); top: calc(var(--bs) * 74px); }
.hb .nm { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; }
.hb .nm b { font-weight: normal; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hb .hpline { display: grid; grid-template-columns: auto 1fr; gap: calc(var(--bs) * 3px); align-items: center; margin-top: calc(var(--bs) * 1px); }
.hb .hpline span { font-size: .75em; color: #f0a020; text-shadow: none; font-weight: bold; }
.hb .hpbar { height: calc(var(--bs) * 4px); border-width: 1px; }
.hb .hpnum { text-align: right; font-size: .9em; }
.hb .expbar { margin-top: calc(var(--bs) * 2px); height: calc(var(--bs) * 2px); }
.hb .caught { display: inline-block; width: calc(var(--bs) * 6px); height: calc(var(--bs) * 6px); border-radius: 50%; background: linear-gradient(#e04040 50%, #fff 50%); border: 1px solid #333; margin-right: 2px; }
.btext { position: absolute; left: calc(var(--bs) * 2px); right: calc(var(--bs) * 2px); bottom: calc(var(--bs) * 2px); height: calc(var(--bs) * 44px); padding: calc(var(--bs) * 6px) calc(var(--bs) * 10px);
  background: #283850; border: calc(var(--bs) * 2px) solid #c8a860; border-radius: calc(var(--bs) * 4px); color: #fff; text-shadow: 1px 1px 0 #506078; font-size: calc(var(--bs) * 11px); line-height: 1.45; white-space: pre-wrap; }
.bmenu { position: absolute; right: calc(var(--bs) * 2px); bottom: calc(var(--bs) * 2px); width: calc(var(--bs) * 116px); height: calc(var(--bs) * 44px); display: grid; grid-template-columns: 1fr 1fr; gap: calc(var(--bs) * 2px); padding: calc(var(--bs) * 3px); background: #f8f8f0; border: calc(var(--bs) * 2px) solid #405060; border-radius: calc(var(--bs) * 4px); }
.bbtn { cursor: pointer; border: calc(var(--bs) * 1px) solid rgba(0,0,0,.25); border-radius: calc(var(--bs) * 3px); font-size: calc(var(--bs) * 10px); color: #fff; text-shadow: 1px 1px 0 rgba(0,0,0,.35); position: relative; }
.bbtn.sel { outline: calc(var(--bs) * 1.5px) solid #303848; outline-offset: -1px; }
.bbtn.fight { background: #e05050; } .bbtn.bag { background: #e0a030; } .bbtn.pkmn { background: #48a858; } .bbtn.run { background: #4878d0; }
.bbtn:hover { filter: brightness(1.1); }
.bmoves { position: absolute; left: calc(var(--bs) * 2px); right: calc(var(--bs) * 2px); bottom: calc(var(--bs) * 2px); height: calc(var(--bs) * 44px); display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: calc(var(--bs) * 2px); padding: calc(var(--bs) * 2px); background: #f8f8f0; border: calc(var(--bs) * 2px) solid #405060; border-radius: calc(var(--bs) * 4px); }
.mbtn { cursor: pointer; border-radius: calc(var(--bs) * 3px); border: calc(var(--bs) * 1px) solid rgba(0,0,0,.25); color: #fff; text-shadow: 1px 1px 0 rgba(0,0,0,.4); display: grid; align-content: center; justify-items: center; font-size: calc(var(--bs) * 9px); line-height: 1.25; padding: 0 calc(var(--bs) * 1px); }
.mbtn small { font-size: .8em; opacity: .9; }
.mbtn.sel { outline: calc(var(--bs) * 1.5px) solid #303848; outline-offset: -1px; }
.mbtn[disabled] { filter: grayscale(1); opacity: .6; cursor: default; }
.mbtn.back, .bbtn.back { background: #8a94a8; }
.bpanel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: calc(var(--bs) * 200px); max-height: calc(var(--bs) * 150px); overflow: auto; font-size: calc(var(--bs) * 9px); padding: calc(var(--bs) * 6px); }
.bpanel .row { padding: calc(var(--bs) * 1.5px) calc(var(--bs) * 3px); }
.bpanel { touch-action: pan-y; overscroll-behavior: contain; }
/* Touch: the DOM menus' buttons and rows are 44 px targets at least; the
   menus grow upwards over the field when the picture is small (phones). */
.jo-touch .bmenu, .jo-touch .bmoves { height: auto; min-height: calc(var(--bs) * 44px); grid-auto-rows: minmax(44px, auto); }
.jo-touch .bbtn, .jo-touch .mbtn { min-height: 44px; }
.jo-touch .bpanel .row { min-height: 44px; display: flex; align-items: center; gap: 6px; }
.jo-touch .bpanel .btn { min-height: 44px; }
.bwait { position: absolute; right: calc(var(--bs) * 6px); bottom: calc(var(--bs) * 50px); color: #fff; font-size: calc(var(--bs) * 8px); text-shadow: 1px 1px 0 #000; }
.btimer { position: absolute; left: calc(var(--bs) * 6px); top: calc(var(--bs) * 4px); color: #fff; font-size: calc(var(--bs) * 8px); text-shadow: 1px 1px 0 #000; }

/* ------------------------------------------------------------------ touch */
/* The pixel pads: #touch.jo-pads in social-layout.css. */

@media (max-width: 700px) {
  .dialog { font-size: 17px; line-height: 26px; }
  .party-grid { grid-template-columns: 1fr; }
  .pc-layout { grid-template-columns: 1fr; }
  #party-strip { display: none; }
}
/* A short screen (a phone on its side, a small window): a smaller message
   box, and the old party strip gives the room to the pads. */
@media (max-height: 520px) {
  .dialog { font-size: 17px; line-height: 24px; min-height: 76px; padding: 10px 16px; }
  .dialog-text { min-height: 48px; }
  .dialog-speaker { font-size: 14px; line-height: 20px; top: -14px; }
  .window { padding: 8px 10px; }
  .window h3 { font-size: 17px; margin-bottom: 4px; }
  #party-strip { display: none; }
}
.jo-touch #party-strip { display: none; }

/* ---- story scripts: mugshots, sign boxes, mon pics, money box, starter case ---- */
.dialog .mugshot { position: absolute; right: 10px; bottom: calc(100% + 4px); width: clamp(64px, 22vh, 128px); height: clamp(64px, 22vh, 128px); image-rendering: pixelated; pointer-events: none; }
.dialog.sign { border-style: dashed; }
.dialog.call { background: #1d2940; color: #eaf2ff; }
/* showmonpic: centred in the free room, under the bar; the front picture's
   first frame (the sheet is 64 x 128). */
.monpic { position: absolute; left: calc(var(--free-l, 0px) + (100% - var(--free-l, 0px) - var(--free-r, 0px)) / 2); top: max(calc(var(--bar-bottom, 46px) + 8px), 14%); transform: translateX(-50%); padding: 8px; z-index: 29; pointer-events: none; }
.monpic img { width: clamp(96px, 28vh, 192px); height: clamp(96px, 28vh, 192px); object-fit: cover; object-position: 50% 0; image-rendering: pixelated; display: block; }
/* The money / coin box: top left, under the bar. */
.moneybox { position: absolute; left: calc(var(--free-l, 0px) + 12px); top: calc(var(--bar-bottom, 46px) + 8px); padding: 6px 12px; z-index: 29; font-size: 18px; pointer-events: none; }
/* Item description header (showitemdescription): icon + text across the top, under the bar. */
.itemdesc { position: absolute; left: calc(var(--free-l, 0px) + (100% - var(--free-l, 0px) - var(--free-r, 0px)) / 2); top: calc(var(--bar-bottom, 46px) + 8px); transform: translateX(-50%); width: min(700px, calc(100% - var(--free-l, 0px) - var(--free-r, 0px) - 24px)); display: flex; align-items: center; gap: 12px; padding: 8px 14px; z-index: 29; pointer-events: none; }
@media (max-height: 520px) { .itemdesc { padding: 4px 10px; } .itemdesc img { width: 32px; height: 32px; } .itemdesc-text { font-size: 15px; } .moneybox { font-size: 15px; padding: 4px 10px; } }
/* Field status boxes: the DexNav search (bottom left) and dowsing (top right). */
.field-status { position: absolute; z-index: 25; padding: 6px 10px; font-size: 14px; pointer-events: none; }
.field-status.dexnav { left: calc(var(--free-l, 0px) + 8px); bottom: calc(var(--free-b, 0px) + 8px); min-width: min(220px, calc(100% - 16px)); }
.field-status.dowse { right: calc(var(--free-r, 0px) + 8px + env(safe-area-inset-right, 0px)); top: calc(var(--bar-bottom, 46px) + 8px); padding: 4px 8px; }
.itemdesc img { width: 48px; height: 48px; image-rendering: pixelated; flex: none; }
.itemdesc-text { font-family: 'PokemonGBA Small', 'PokemonGBA', sans-serif; font-size: 18px; line-height: 1.25; }
.starter-case { width: min(760px, calc(100% - 20px)); }
.starter-case .balls { overflow-y: auto; touch-action: pan-y; min-height: 0; }
.starter-case .balls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.starter-case .ball { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; }
.starter-case .ball.sel { border-color: var(--accent); background: rgba(255, 255, 255, .08); }
.starter-case .ball img { width: clamp(64px, 16vh, 96px); height: clamp(64px, 16vh, 96px); image-rendering: pixelated; object-fit: cover; object-position: 0 0; }
.starter-case .info { min-height: 26px; text-align: center; }
.script-fade { position: absolute; inset: 0; pointer-events: none; z-index: 49; transition: opacity .3s; opacity: 0; }

/* ------------------------------------------------------------------ battery saver */
/* Hub → Settings → Game's battery saver (client/js/game-settings.js; main.js
   puts html.jo-battery on while it's on): fewer UI animations, as the OS's
   reduced motion does for the social layer (social-ui.css), and the title's
   pan, the message box's arrow and Hub's spinner. What ends by its own
   animation (a toast, the map banner) keeps it. */
html.jo-battery .pxui *, html.jo-battery .pxui *::before, html.jo-battery .pxui *::after, html.jo-battery .title-art, html.jo-battery .dialog-arrow, html.jo-battery .hub-spin { animation: none !important; transition: none !important; }
/* (the title's pan stops where reduced motion rests it, 35% down, not at the top) */
html.jo-battery .title-art { background-position: var(--title-x, 72%) 35%; }
