/* ===================================================================== tokens */
:root {
  --bg: #eef2f8;
  --bg-glow: #dfe8f7;
  --panel: #ffffff;
  --panel-2: #f3f6fb;
  --panel-3: #e8edf5;
  --border: #d9e0ea;
  --text: #18202d;
  --muted: #5f6b7e;
  --accent: #3b74e6;
  --accent-2: #2a5cc4;
  --accent-soft: rgb(59 116 230 / .12);
  --gold: #ffc531;
  --gold-2: #ff9f1c;
  --danger: #d6463b;
  --success: #239a4a;
  --top: #172238;
  --top-2: #111a2c;
  --hp-green: #36c25a;
  --hp-yellow: #f2bd2c;
  --hp-red: #e8463a;
  --shadow: 0 1px 2px rgb(16 30 54 / .05), 0 6px 20px rgb(16 30 54 / .07);
  --shadow-lg: 0 18px 50px rgb(10 20 40 / .25);
  --radius: 14px;
  --radius-sm: 9px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: Fredoka, Inter, system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d121b; --bg-glow: #142036; --panel: #161d29; --panel-2: #1c2433; --panel-3: #232d3f; --border: #273246;
    --text: #e7ecf4; --muted: #94a0b3; --accent: #5b92ff; --accent-2: #7aa7ff; --accent-soft: rgb(91 146 255 / .14);
    --top: #0b111c; --top-2: #080d16; --success: #3ccf6e;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .22);
    --shadow-lg: 0 24px 60px rgb(0 0 0 / .5);
    color-scheme: dark;
  }
}

/* ===================================================================== base */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, var(--bg-glow), transparent 70%), var(--bg);
  background-attachment: fixed;
  color: var(--text); font: 14px/1.5 var(--font);
  display: flex; flex-direction: column; overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-display); }
h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600;
  margin: 0 0 12px; display: flex; align-items: center; gap: 8px;
}
a { color: var(--accent); }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
* { scrollbar-width: thin; scrollbar-color: var(--panel-3) transparent; }

/* ===================================================================== top bar */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 0 16px; height: 56px; flex: none;
  background: linear-gradient(var(--top), var(--top-2)); color: #fff; position: sticky; top: 0; z-index: 20;
  box-shadow: 0 1px 0 rgb(255 255 255 / .06), 0 6px 18px rgb(0 0 0 / .18);
}
.brand { display: flex; align-items: center; gap: 4px; font: 600 19px var(--font-display); letter-spacing: .01em; white-space: nowrap; }
.brand img { width: 46px; height: 46px; image-rendering: pixelated; margin: -4px -2px -4px -10px; }
.brand b { color: var(--gold); font-weight: 700; }
#tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; align-self: stretch; align-items: center; scrollbar-width: none; }
.tab {
  position: relative; border: 0; background: transparent; color: #aab7cc; padding: 7px 14px; border-radius: 99px;
  cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 8px; font-weight: 500; transition: background .15s, color .15s;
}
.tab:hover { background: rgb(255 255 255 / .08); color: #fff; }
.tab.active { background: rgb(255 255 255 / .14); color: #fff; font-weight: 600; }
.tab.attention::after {
  content: ""; position: absolute; top: 5px; right: 6px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 0 0 rgb(255 197 49 / .7); animation: ping 1.4s infinite;
}
@keyframes ping { 70% { box-shadow: 0 0 0 8px rgb(255 197 49 / 0); } 100% { box-shadow: 0 0 0 0 rgb(255 197 49 / 0); } }
.tab-close { opacity: .55; font-size: 16px; line-height: 1; margin-right: -4px; padding: 0 2px; border-radius: 50%; }
.tab-close:hover { opacity: 1; color: #fff; background: rgb(255 255 255 / .15); }
#conn-status { color: var(--gold); font-size: 12px; white-space: nowrap; }
.user-chip {
  background: rgb(255 255 255 / .1); border: 1px solid rgb(255 255 255 / .16); color: #fff; border-radius: 99px;
  padding: 5px 14px; cursor: pointer; white-space: nowrap; font-weight: 600;
}
.user-chip:hover { background: rgb(255 255 255 / .16); }
.search-chip {
  display: flex; align-items: center; gap: 8px; border: 0; cursor: pointer; white-space: nowrap;
  background: linear-gradient(var(--gold), var(--gold-2)); color: #3a2400; font-weight: 700; font-size: 13px;
  padding: 5px 12px; border-radius: 99px;
}
.search-chip .spinner { border-color: rgb(58 36 0 / .25); border-top-color: #3a2400; }
.search-chip-x { opacity: .6; }
.search-chip:hover .search-chip-x { opacity: 1; }

#panels { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tab-panel { flex: 1; min-height: 0; animation: fade-in .2s ease-out; }
@keyframes fade-in { from { opacity: 0; } }

/* ===================================================================== controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--panel); border-radius: var(--radius-sm); padding: 7px 14px;
  cursor: pointer; font-weight: 600; transition: background .15s, border-color .15s, transform .06s, box-shadow .15s;
}
.btn:hover { background: var(--panel-2); border-color: color-mix(in srgb, var(--border) 60%, var(--accent)); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.small { padding: 5px 11px; font-size: 13px; }
.btn.tiny { padding: 2px 9px; font-size: 12px; font-weight: 600; border-radius: 99px; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-align: left; font-weight: 600; }
.link:hover { text-decoration: underline; }
input, select, textarea {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 11px; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
input[type=range] { accent-color: var(--accent); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgb(255 255 255 / .35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
.spinner.dark { border-color: var(--panel-3); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toggle switch. */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { width: 38px; height: 22px; border-radius: 99px; background: var(--panel-3); border: 1px solid var(--border); position: relative; transition: background .2s; flex: none; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3); transition: transform .2s; }
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--accent-soft); }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.field-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.empty, .empty-state { color: var(--muted); font-size: 13px; }
.empty-state { list-style: none; padding: 6px 0; margin: 0; }
.count { background: var(--panel-2); border: 1px solid var(--border); border-radius: 99px; padding: 0 8px; color: var(--text); font-size: 11px; letter-spacing: 0; }

/* ===================================================================== home */
.home {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; padding: 18px;
  height: calc(100vh - 56px); max-width: 1320px; margin: 0 auto; width: 100%;
}
.home-main { display: flex; flex-direction: column; gap: 18px; min-height: 0; }
.play-card { display: flex; flex-direction: column; gap: 16px; padding: 22px; flex: none; }
.play-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.play-head h1 { margin: 0 0 4px; font-size: 28px; font-weight: 600; letter-spacing: -.01em; }
.play-art { width: 96px; height: 96px; border-radius: 16px; image-rendering: pixelated; flex: none; box-shadow: var(--shadow); }
.format-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.format-card {
  position: relative; display: flex; flex-direction: column; gap: 4px; text-align: left; cursor: pointer;
  background: var(--panel-2); border: 2px solid transparent; border-radius: 12px; padding: 12px 14px;
  transition: border-color .15s, background .15s, transform .08s;
}
.format-card:hover { background: var(--panel-3); }
.format-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.format-card:active { transform: scale(.99); }
.format-name { font: 600 15px var(--font-display); }
.format-desc { font-size: 12px; color: var(--muted); line-height: 1.4; }
.format-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 1px 7px; border-radius: 99px; background: var(--panel); border: 1px solid var(--border); color: var(--muted); }
.tag.doubles { color: #8a5cf0; border-color: color-mix(in srgb, #8a5cf0 40%, var(--border)); }
.tag.needs { color: var(--gold-2); border-color: color-mix(in srgb, var(--gold-2) 40%, var(--border)); }
.play-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.play-actions .hint { flex: 1; min-width: 160px; }
.battle-btn {
  min-width: 220px; padding: 14px 28px; font: 600 22px var(--font-display); letter-spacing: .02em; border: 0; border-radius: 14px;
  background: linear-gradient(var(--gold), var(--gold-2)); color: #3a2400;
  box-shadow: 0 4px 0 #c97a00, 0 10px 24px rgb(255 159 28 / .35);
}
.battle-btn:hover { background: linear-gradient(#ffd25a, #ffab35); }
.battle-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #c97a00, 0 4px 12px rgb(255 159 28 / .3); }
.battle-btn.searching { background: var(--panel-3); color: var(--text); box-shadow: none; font-size: 16px; }
.battle-btn.searching .spinner { border-color: var(--border); border-top-color: var(--accent); }

.lobby-card { display: flex; flex-direction: column; min-height: 220px; flex: 1; }
.chat-log { flex: 1; overflow-y: auto; min-height: 0; padding-right: 4px; display: flex; flex-direction: column; }
.chat-log .empty-state { margin: auto; }
.chat-form { display: flex; gap: 6px; margin-top: 10px; }
.chat-form input { flex: 1; }
.time { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chat-name { color: var(--accent); font-weight: 600; }

.side-col { display: flex; flex-direction: column; gap: 14px; overflow-y: auto; min-height: 0; padding-bottom: 4px; }
.side-col .card { padding: 14px 16px; }
.user-list, .room-list { list-style: none; margin: 0; padding: 0; }
.user-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.user-list li:last-child { border-bottom: 0; }
.u-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 7px; }
.u-name small { color: var(--muted); font-weight: 400; }
.u-meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--hp-green); flex: none; box-shadow: 0 0 0 3px rgb(54 194 90 / .15); }
.dot.busy { background: var(--hp-yellow); box-shadow: 0 0 0 3px rgb(242 189 44 / .15); }
.room-list li:not(.empty-state) { padding: 7px 0; border-bottom: 1px solid var(--border); }
.room-list li:last-child { border-bottom: 0; }
.room-list a, .room-list .link { font-weight: 600; text-decoration: none; }
.room-list a:hover { text-decoration: underline; }
.room-list em { color: var(--muted); font-style: normal; font-weight: 400; }
.ladder { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.ladder th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; }
.ladder td, .ladder th { padding: 5px 4px; border-bottom: 1px solid var(--border); }
.ladder tr:last-child td { border-bottom: 0; }
.ladder tbody tr:first-child td:first-child:not(.empty-state) { color: var(--gold-2); font-weight: 700; }

/* ===================================================================== notifications / dialogs */
#notifications { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(380px, calc(100vw - 32px)); }
.challenge-card, .toast-note {
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow-lg); animation: slidein .25s ease-out;
}
.challenge-card { border-left-color: var(--gold-2); }
.challenge-card .row { display: flex; gap: 8px; margin-top: 10px; }
.challenge-card small { color: var(--muted); display: block; }
@keyframes slidein { from { transform: translateY(12px); opacity: 0; } }
dialog { border: 1px solid var(--border); border-radius: 18px; background: var(--panel); color: var(--text); padding: 24px; box-shadow: var(--shadow-lg); }
dialog[open] { animation: pop .18s ease-out; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }
dialog::backdrop { background: rgb(8 14 26 / .6); backdrop-filter: blur(2px); }
#login-form { display: flex; flex-direction: column; gap: 12px; width: min(340px, 80vw); text-align: center; }
#login-form h2 { justify-content: center; font-size: 24px; color: var(--text); text-transform: none; letter-spacing: 0; margin: 0; }
#login-form p { margin: 0; color: var(--muted); }
#login-form input { text-align: center; font-size: 16px; padding: 10px; }
#login-form .btn { padding: 10px; font-size: 15px; }
.login-art { width: 128px; height: 128px; border-radius: 20px; image-rendering: pixelated; margin: 0 auto; box-shadow: var(--shadow); }
.error { color: var(--danger); min-height: 1.2em; font-size: 13px; }

.tooltip {
  position: fixed; z-index: 100; max-width: 320px; background: #0c1220f5; color: #eef3fb; border-radius: 12px;
  padding: 11px 13px; font-size: 13px; pointer-events: none; box-shadow: 0 12px 32px rgb(0 0 0 / .4); border: 1px solid rgb(255 255 255 / .08);
}
.tt-title { font: 600 16px var(--font-display); margin-bottom: 4px; }
.tt-stats { margin-top: 4px; color: #c8d2e2; }
.tt-desc { margin-top: 6px; color: #e9eef6; }
.tt-fusion { color: #9fb0c8; font-size: 12px; margin-top: 2px; }
.cat { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: #555; color: #fff; text-transform: uppercase; letter-spacing: .04em; }
.cat.Physical { background: #d0541c; } .cat.Special { background: #4b6cd6; } .cat.Status { background: #8a8796; }

.type {
  display: inline-block; background: var(--c); color: #fff; font-size: 10px; font-weight: 700; text-transform: uppercase;
  padding: 1px 7px; border-radius: 5px; text-shadow: 0 1px 1px rgb(0 0 0 / .3); letter-spacing: .05em; margin-right: 3px;
}

/* ===================================================================== battle */
.battle-room { display: grid; grid-template-columns: minmax(0, 1fr) 340px; height: calc(100vh - 56px); }
.battle-main { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; padding: 14px 16px; gap: 10px; align-items: center; }
/* The field shrinks on short screens so the controls stay visible without scrolling. */
.battle-main > .battle-topbar, .battle-main > .field, .battle-main > .controls, .battle-main > .draft-board {
  width: min(100%, 820px, calc((100vh - 56px - 320px) * 16 / 9));
  min-width: min(100%, 480px);
}
.battle-topbar { display: flex; align-items: center; gap: 12px; }
.battle-title { font: 600 17px var(--font-display); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.battle-title em { color: var(--muted); font-weight: 500; font-style: normal; font-size: 14px; }
.battle-format { color: var(--muted); font-size: 12px; background: var(--panel-2); border: 1px solid var(--border); padding: 2px 10px; border-radius: 99px; white-space: nowrap; }
.spectating { font-size: 12px; background: var(--accent-soft); color: var(--accent); padding: 2px 10px; border-radius: 99px; font-weight: 600; }

.field {
  position: relative; aspect-ratio: 16 / 9; border-radius: 16px; overflow: hidden;
  box-shadow: var(--shadow), inset 0 0 0 1px rgb(255 255 255 / .06); flex: none; container-type: inline-size;
  /* Arena palette; overridden per background in features.css. */
  --sky1: #8fd0f5; --sky2: #bfe6f7; --ground1: #9fd27c; --ground2: #7fbf5e; --hill: #79b45b;
  --plat1: #c8e6a0; --plat2: #8fbf63; --plat3: #6e9f48; --horizon: 48%;
}
.field-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(120% 60% at 50% 105%, var(--hill) 0 45%, transparent 46%),
    linear-gradient(var(--sky1) 0%, var(--sky2) var(--horizon), var(--ground1) calc(var(--horizon) + .2%), var(--ground2) 100%);
  transition: filter .6s;
}
.field-bg::before, .field-bg::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.field[data-weather="RainDance"] .field-bg { filter: saturate(.6) brightness(.8) hue-rotate(10deg); }
.field[data-weather="SunnyDay"] .field-bg { filter: saturate(1.3) brightness(1.1) sepia(.15); }
.field[data-weather="Sandstorm"] .field-bg { filter: sepia(.6) saturate(1.2); }
.field[data-weather="Snowscape"] .field-bg, .field[data-weather="Snow"] .field-bg { filter: saturate(.3) brightness(1.15); }
.field-info { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; font-size: 12px; z-index: 5; font-weight: 600; }
.field-info span:not(:empty) { background: rgb(10 16 28 / .55); backdrop-filter: blur(4px); color: #fff; border-radius: 99px; padding: 2px 11px; white-space: nowrap; }
.platform { position: absolute; border-radius: 50%; background: radial-gradient(var(--plat1), var(--plat2) 60%, var(--plat3)); box-shadow: inset 0 -4px 0 rgb(0 0 0 / .12), 0 6px 12px rgb(0 0 0 / .1); }
.platform.far { width: 34%; height: 11%; right: 9%; top: 43%; }
.platform.near { width: 44%; height: 14%; left: 2%; bottom: 2%; }
.sprite-wrap { position: absolute; display: flex; align-items: end; justify-content: center; z-index: 2; }
.sprite-wrap.far { width: 28cqw; height: 28cqw; right: 12%; bottom: 50%; } /* bottom edge = platform centre */
.sprite-wrap.near { width: 40cqw; height: 40cqw; left: 4%; bottom: 8%; }
/* Player's mon faces right. `scale`/`translate` are separate properties so the
   ground offset, the flip and the hover bob (which animates `transform`) don't clash. */
.sprite-wrap.near img { scale: -1 1; }
.sprite {
  width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated;
  translate: 0 var(--drop, 0); transition: translate .15s;
  filter: drop-shadow(0 3px 0 rgb(0 0 0 / .15));
}
.sprite.hover { animation: hover-bob 2.4s ease-in-out infinite; }
@keyframes hover-bob { 50% { transform: translateY(-4%); } }
.sprite.shiny { filter: hue-rotate(160deg) drop-shadow(0 3px 0 rgb(0 0 0 / .15)); }
.sprite-wrap.fainted { opacity: 0; }

.hpbox {
  position: absolute; z-index: 4; width: 34%; min-width: 180px; background: rgb(255 255 255 / .94); color: #18202d;
  border-radius: 12px; padding: 7px 11px; box-shadow: 0 4px 14px rgb(0 0 0 / .18); opacity: 0; transition: opacity .3s;
  font-size: clamp(11px, 1.8cqw, 14px); cursor: help; border: 1px solid rgb(255 255 255 / .8);
}
.hpbox.show { opacity: 1; }
.hpbox.far { left: 3%; top: 14%; }
.hpbox.near { right: 3%; bottom: 20%; }
.hp-name { display: flex; align-items: baseline; gap: 6px; font-weight: 700; }
.hp-name span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lvl { font-size: .82em; color: #5f6b7e; font-weight: 600; }
.gender.M { color: #3b74e6; } .gender.F { color: #e0457b; }
.hp-row { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.hpbar { flex: 1; height: 9px; background: #3b4250; border-radius: 99px; overflow: hidden; box-shadow: inset 0 1px 2px rgb(0 0 0 / .4); }
.hpfill { height: 100%; border-radius: 99px; transition: width .6s cubic-bezier(.3,.7,.3,1), background .5s; box-shadow: inset 0 -2px 0 rgb(0 0 0 / .15); }
.hp-text { font-size: .85em; font-variant-numeric: tabular-nums; min-width: 3.5em; text-align: right; color: #3a4556; font-weight: 600; }
.status { background: var(--c); color: #fff; font-size: .72em; font-weight: 800; padding: 0 5px; border-radius: 4px; letter-spacing: .03em; }
.boosts { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.boosts:empty { display: none; }
.boost { font-size: .72em; font-weight: 700; padding: 0 6px; border-radius: 4px; }
.boost.up { background: #d8f1d8; color: #1f7a2c; } .boost.down { background: #f6dada; color: #a3261c; } .boost.vol { background: #e5e2f6; color: #4a3f9e; }

.party { position: absolute; z-index: 3; display: flex; align-items: center; gap: 3px; background: rgb(10 16 28 / .5); backdrop-filter: blur(4px); padding: 3px 9px 3px 4px; border-radius: 99px; }
.party.far { right: 2%; top: 2.5%; }
.party.near { left: 2%; top: 2.5%; }
.party-name { color: #fff; font-size: 12px; font-weight: 600; margin: 0 4px 0 6px; max-width: 14cqw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pball { width: 22px; height: 22px; border-radius: 50%; background: rgb(255 255 255 / .88); display: grid; place-items: center; overflow: hidden; }
.pball img { width: 30px; height: 30px; image-rendering: pixelated; object-fit: contain; }
.pball.unknown { background: radial-gradient(circle at 50% 50%, #fff 0 18%, #333 19% 26%, transparent 27%), linear-gradient(#e6453a 48%, #333 48% 54%, #f4f4f4 54%); }
.pball.fainted { opacity: .35; filter: grayscale(1); }
.pball.statused { box-shadow: 0 0 0 2px #f2bd2c; }

.field-toast {
  position: absolute; z-index: 7; left: 50%; top: 40%; transform: translate(-50%, -50%); pointer-events: none;
  font: 700 clamp(16px, 3.6cqw, 30px) var(--font-display); color: #fff; text-shadow: 0 2px 0 #b8341f, 0 0 14px rgb(0 0 0 / .45); opacity: 0; white-space: nowrap;
}
.field-toast.show { animation: toast 1s ease-out; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.8); } 20% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -70%); } }
/* End-of-battle banner across the field. */
.field-banner {
  position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; pointer-events: none;
  background: radial-gradient(ellipse at center, rgb(8 14 26 / .55), rgb(8 14 26 / .15) 70%);
  animation: fade-in .4s ease-out;
}
.field-banner span {
  font: 700 clamp(28px, 8cqw, 64px) var(--font-display); color: #fff; letter-spacing: .02em;
  text-shadow: 0 4px 0 rgb(0 0 0 / .25), 0 0 30px rgb(0 0 0 / .4); animation: pop .4s cubic-bezier(.2,.9,.3,1.3);
}
.field-banner.won span { color: var(--gold); }

.controls {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px;
  box-shadow: var(--shadow); min-height: 110px; flex: none;
}
.controls-msg { margin-bottom: 10px; display: flex; align-items: center; gap: 10px; font-weight: 500; min-height: 28px; }
.controls-msg b { font-family: var(--font-display); font-weight: 600; font-size: 15px; }
.controls-msg .btn { margin-left: auto; }
.waiting { display: flex; align-items: center; gap: 12px; color: var(--muted); padding: 8px 2px; }
.moves { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.move-btn {
  position: relative; border: 0; border-radius: 12px; padding: 9px 13px; cursor: pointer; color: #fff; text-align: left;
  background: linear-gradient(color-mix(in srgb, var(--c) 85%, white), var(--c));
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / .2), 0 2px 6px rgb(0 0 0 / .12); text-shadow: 0 1px 1px rgb(0 0 0 / .35);
  transition: transform .08s, filter .15s, box-shadow .15s;
}
.move-btn:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); box-shadow: inset 0 -3px 0 rgb(0 0 0 / .2), 0 6px 14px rgb(0 0 0 / .18); }
.move-btn:active:not(:disabled) { transform: translateY(1px); }
.move-btn:disabled { filter: grayscale(.9) opacity(.45); cursor: not-allowed; }
.mv-name { display: block; font: 600 16px var(--font-display); letter-spacing: .01em; padding-right: 44px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mv-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; opacity: .95; font-weight: 500; }
.mv-meta span:last-child { font-variant-numeric: tabular-nums; }
.mv-eff {
  position: absolute; top: 8px; right: 9px; font-size: 11px; font-weight: 800; padding: 1px 6px; border-radius: 99px;
  background: rgb(255 255 255 / .92); color: #18202d; text-shadow: none;
}
.mv-eff.super { background: #fff; color: #c2410c; box-shadow: 0 0 0 2px rgb(255 255 255 / .5); }
.mv-eff.weak { background: rgb(0 0 0 / .35); color: #fff; }
.mv-eff.immune { background: rgb(0 0 0 / .55); color: #fff; }
.switch-label { font-size: 11px; color: var(--muted); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.switch-label:empty { display: none; }
.switches { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.switch-btn {
  display: grid; grid-template-columns: 34px minmax(0, 1fr); grid-template-rows: auto auto; column-gap: 6px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 4px 8px 6px 3px; cursor: pointer; text-align: left;
  transition: border-color .15s, background .15s, transform .08s;
}
.switch-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.switch-btn:disabled { opacity: .55; cursor: not-allowed; }
.switch-btn.fainted { opacity: .3; }
.switch-btn img { grid-row: span 2; width: 34px; height: 34px; object-fit: contain; image-rendering: pixelated; }
.sw-name { font-weight: 600; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-hp { height: 5px; background: var(--panel-3); border-radius: 99px; overflow: hidden; display: block; }
.mini-hp span { display: block; height: 100%; }
.end-panel { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 4px; }
.end-title { font: 600 22px var(--font-display); }
.end-title.won { color: var(--success); }
.end-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.battle-side { display: flex; flex-direction: column; border-left: 1px solid var(--border); background: var(--panel); min-height: 0; }
.battle-side-head { padding: 12px 14px 0; }
.battle-side-head h2 { margin: 0; }
.battle-log { flex: 1; overflow-y: auto; min-height: 0; font-size: 13px; padding: 8px 14px; line-height: 1.55; }
.battle-side .chat-form { margin: 0; padding: 10px 12px; border-top: 1px solid var(--border); }
.log-line { padding: 1px 2px; }
.log-line.turn {
  margin: 12px 0 6px; padding: 4px 10px; background: var(--panel-2); border-radius: 8px; font: 600 13px var(--font-display);
  letter-spacing: .03em; color: var(--muted); position: sticky; top: -8px; border: 1px solid var(--border);
}
.log-line.headline { font-weight: 600; margin: 6px 0; }
.log-line.win { font: 600 16px var(--font-display); color: var(--success); margin-top: 10px; }
.log-line.minor { color: var(--muted); font-size: 12px; }
.log-line.emph { font-weight: 600; }
.log-line.ability { color: #8a5cf0; font-size: 12px; font-weight: 600; }
.log-line.notice { color: var(--muted); font-style: italic; }
.log-line.error { color: var(--danger); font-weight: 600; }
.log-line.chat { margin: 3px 0; padding: 3px 8px; background: var(--panel-2); border-radius: 8px; }
.move-name { color: color-mix(in srgb, var(--c) 75%, var(--text)); }

/* ===================================================================== pokédex */
.dex { padding: 18px; max-width: 1320px; margin: 0 auto; height: calc(100vh - 56px); overflow-y: auto; width: 100%; }
.dex-filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; position: sticky; top: -18px; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); padding: 10px 0;
}
.dex-search { flex: 1; min-width: 220px; }
.dex-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.dex-card {
  position: relative; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; transition: transform .1s, border-color .15s, box-shadow .15s;
}
.dex-card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow); }
.dex-card img { width: 96px; height: 96px; image-rendering: pixelated; object-fit: contain; }
.dex-name { font: 600 14px var(--font-display); text-align: center; }
.dex-parts { font-size: 12px; color: var(--muted); text-align: center; }
.dex-types { display: flex; gap: 2px; margin-top: 3px; flex-wrap: wrap; justify-content: center; }
.dex-alts { font-size: 11px; color: var(--muted); }
.dex-more { text-align: center; color: var(--muted); padding: 18px; }
.dex-detail { width: min(760px, 94vw); }
.dlg-close { position: absolute; right: 14px; top: 10px; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--muted); border-radius: 50%; width: 34px; height: 34px; }
.dlg-close:hover { background: var(--panel-2); color: var(--text); }
.detail-body { display: flex; gap: 22px; flex-wrap: wrap; }
.detail-sprites { display: flex; flex-direction: column; gap: 8px; max-height: 70vh; overflow-y: auto; }
.detail-sprites figure { margin: 0; }
.detail-sprites figcaption { font-size: 12px; color: var(--muted); text-align: center; margin-top: 2px; }
.detail-sprites img { width: 192px; max-width: 100%; image-rendering: pixelated; background: var(--panel-2); border-radius: 12px; }
.detail-info { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 10px; }
.detail-info h2 { font-size: 28px; color: var(--text); text-transform: none; letter-spacing: 0; margin: 0; font-weight: 600; }
.stats { display: flex; flex-direction: column; gap: 5px; }
.stat-row { display: grid; grid-template-columns: 40px 36px 1fr; align-items: center; gap: 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
.stat-row.total { border-top: 1px solid var(--border); padding-top: 5px; }
.stat-bar { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.stat-bar div { height: 100%; border-radius: 99px; }
.abilities, .credit { font-size: 13px; color: var(--muted); }

/* ===================================================================== responsive */
@media (max-width: 1100px) {
  .home { grid-template-columns: 1fr; height: auto; }
  .side-col { flex-direction: row; flex-wrap: wrap; overflow: visible; }
  .side-col .card { flex: 1; min-width: 260px; }
  .lobby-card { min-height: 300px; }
  .battle-room { grid-template-columns: 1fr; height: auto; }
  .battle-main { overflow: visible; }
  .battle-main > .battle-topbar, .battle-main > .field, .battle-main > .controls, .battle-main > .draft-board { width: min(100%, 820px); min-width: 0; }
  .battle-side { border-left: 0; border-top: 1px solid var(--border); height: 380px; }
  .switches { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .topbar { padding: 0 8px; gap: 8px; }
  .brand span { display: none; }
  .search-chip-text { display: none; }
  .home { padding: 12px; gap: 12px; }
  .play-card { padding: 16px; }
  .play-art { display: none; }
  .play-head h1 { font-size: 22px; }
  .battle-btn { width: 100%; }
  .format-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .format-card { padding: 10px 11px; }
  .format-card .format-desc { display: none; }
  .format-name { font-size: 14px; }
  .user-chip { max-width: 96px; overflow: hidden; text-overflow: ellipsis; padding: 5px 10px; }
  .tab { padding: 6px 10px; }
  .battle-topbar { flex-wrap: wrap; row-gap: 4px; }
  .battle-format { display: none; }
  .mv-meta { flex-direction: column; gap: 0; }
  .battle-main { padding: 8px; }
  .switches { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hpbox { min-width: 0; width: 44%; padding: 4px 7px; }
  .party .pball { width: 16px; height: 16px; }
  .party-name { display: none; }
  .mv-name { font-size: 14px; }
  .end-panel { flex-direction: column; align-items: stretch; text-align: center; }
  .end-actions { justify-content: center; }
}
