:root {
  --bg: #0f131a; --panel: #171c26; --panel-2: #1e2430; --line: #2a3140; --text: #eef0f4; --muted: #9aa4b5;
  --dim: #6c7686; --accent: #5aa2ff; --good: #3fbf6a; --warn: #e8b830; --bad: #e25050; --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; }
button { font: inherit; color: inherit; }
.top { position: sticky; top: 0; z-index: 5; background: rgba(15, 19, 26, .94); backdrop-filter: blur(6px);
       border-bottom: 1px solid var(--line); padding: 10px 16px 0; }
.brand { font-weight: 700; letter-spacing: .3px; margin-bottom: 8px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: 0; padding: 8px 12px 10px; color: var(--muted); cursor: pointer;
               border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
main { padding: 16px; max-width: 980px; margin: 0 auto; }
.center { display: grid; place-items: center; min-height: 50vh; text-align: center; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.grid { display: grid; gap: 10px; }
.stats4 { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.stat .k { color: var(--muted); font-size: 13px; }
.stat .v { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; margin: 22px 0 10px; }
.party { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.mon { display: flex; gap: 12px; align-items: center; cursor: pointer; text-align: left; width: 100%; }
.mon:hover { border-color: #3a4456; }
.mon img { width: 72px; height: 72px; image-rendering: pixelated; flex: none; }
.mon .info { min-width: 0; flex: 1; }
.mon .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 5px; color: #fff; text-transform: uppercase; }
.tag { font-size: 12px; padding: 1px 7px; border-radius: 5px; background: var(--panel-2); color: var(--muted); }
.box { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.cell { text-align: center; padding: 8px 4px; cursor: pointer; }
.cell img { width: 64px; height: 64px; image-rendering: pixelated; }
.cell .n { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 180px; background: var(--panel); border: 1px solid var(--line); color: var(--text);
                 border-radius: 8px; padding: 9px 12px; font: inherit; }
.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.btn:disabled { opacity: .4; cursor: default; }
.pager { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 14px; }
.badges { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.badge { display: flex; gap: 10px; align-items: center; }
.badge .dot { width: 30px; height: 30px; border-radius: 50%; flex: none; border: 2px solid var(--line); }
.badge.off { opacity: .45; }
.sheet { position: fixed; inset: 0; background: rgba(5, 8, 12, .7); display: grid; place-items: end center; z-index: 10; }
.sheet.hidden { display: none; }
.sheet-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px 14px 0 0; width: 100%;
              max-width: 620px; max-height: 88vh; overflow: auto; padding: 18px 18px 26px; }
@media (min-width: 700px) { .sheet { place-items: center; } .sheet-card { border-radius: 14px; } }
.detail-head { display: flex; gap: 14px; align-items: center; }
.detail-head img { width: 112px; height: 112px; image-rendering: pixelated; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin-top: 12px; font-size: 14px; }
.kv .k { color: var(--muted); }
.bars { display: grid; grid-template-columns: 54px 38px 1fr 64px; gap: 5px 8px; align-items: center; font-size: 13px; margin-top: 8px; }
.bar { height: 7px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; }
.moves { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.move { border-radius: 8px; padding: 8px 10px; background: var(--panel-2); border-left: 4px solid var(--line); }
.move .m { font-weight: 700; font-size: 14px; }
.move .d { font-size: 12px; color: var(--muted); }
.close { float: right; background: none; border: 0; font-size: 22px; color: var(--muted); cursor: pointer; line-height: 1; }
@media (max-width: 480px) { main { padding: 12px; } .moves { grid-template-columns: 1fr; } }

.btn.primary { background: #2d5fb0; border-color: #3a70c8; }
.btn.primary:disabled { background: var(--panel-2); border-color: var(--line); }
.pill { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; cursor: pointer;
        color: var(--muted); font-size: 13px; }
.pill.on { color: var(--text); border-color: var(--accent); }
.list { grid-template-columns: 1fr; }
.item { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.item.pick { text-align: left; cursor: pointer; width: 100%; }
.item-main { min-width: 0; }
.item .m { font-weight: 700; }
.item .d { font-size: 13px; color: var(--muted); }
.item-buy { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; }
.price { font-weight: 700; }
.qty { width: 58px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 8px;
       padding: 7px 8px; font: inherit; }
.actions { display: grid; gap: 10px; }
.field { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field label { color: var(--muted); font-size: 13px; min-width: 120px; }
.field input { flex: 1; min-width: 90px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
               border-radius: 8px; padding: 7px 10px; font: inherit; }
code { background: var(--panel-2); border-radius: 4px; padding: 0 4px; font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
         background: #222a38; border: 1px solid #36425a; border-radius: 10px; padding: 10px 14px; max-width: min(560px, 92vw);
         z-index: 20; transition: opacity .2s, transform .2s; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.toast.on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast div + div { margin-top: 4px; }
.toast a { color: var(--accent); word-break: break-all; }
@media (max-width: 480px) { .item { flex-direction: column; align-items: stretch; } .item-buy { align-items: stretch; } }

.fight { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.fight .m { font-weight: 700; }
.fight .d { font-size: 13px; color: var(--muted); }
select { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 7px 10px;
         font: inherit; max-width: 100%; }
.play { padding: 12px; }
.play .scene { width: 100%; height: auto; border-radius: 8px; display: block; margin: 8px 0; image-rendering: auto; }
.eauthor { color: var(--muted); font-size: 13px; }
.hunt { margin-top: 10px; color: var(--muted); font-size: 13px; }
.hunt.next { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px;
             border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); font-size: 14px; }
.etitle { font-weight: 700; font-size: 17px; }
.edesc, .content { margin: 6px 0; }
.efield { margin-top: 8px; }
.ename { color: var(--muted); font-size: 13px; margin-bottom: 2px; }
.efoot { color: var(--dim); font-size: 12px; margin-top: 8px; }
pre.log { margin: 0; white-space: pre-wrap; background: #0c1016; border: 1px solid var(--line); border-radius: 8px;
          padding: 8px 10px; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; max-height: 220px; overflow: auto; }
.comps { display: grid; gap: 8px; margin-top: 10px; }
.crow { display: flex; gap: 8px; flex-wrap: wrap; }
.crow .btn { flex: 1 1 140px; padding: 11px 12px; font-weight: 600; }
.crow select { flex: 1 1 100%; padding: 10px; }
.ds-primary { background: #2d5fb0; border-color: #3a70c8; }
.ds-success { background: #237a45; border-color: #2e9255; }
.ds-danger { background: #a33737; border-color: #bd4646; }
.ds-blurple { background: #4f5bd5; border-color: #5d69e0; }
.ds-green { background: #237a45; border-color: #2e9255; }
.ds-red { background: #a33737; border-color: #bd4646; }
.ds-grey, .ds-gray, .ds-secondary { background: var(--panel-2); }
.btn:disabled { opacity: .45; }

/* training */
table.train { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; }
table.train th { color: var(--muted); font-weight: 500; font-size: 12px; text-align: left; padding: 4px 6px; }
table.train td { padding: 6px; border-top: 1px solid var(--line); vertical-align: middle; }
table.train .num { text-align: right; width: 64px; font-variant-numeric: tabular-nums; }
table.train td.acts { text-align: right; white-space: nowrap; }
.evbar { display: block; height: 3px; margin-top: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
.evbar i { display: block; height: 100%; background: var(--accent); }
.btn.small { padding: 4px 10px; font-size: 13px; }
@media (max-width: 480px) { table.train td.acts .btn { display: block; width: 100%; margin: 2px 0; } }

/* phase 4 */
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.starters { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.center-card { max-width: 420px; margin: 40px auto; text-align: center; display: grid; gap: 12px; padding: 24px; }
label.toggle { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; cursor: pointer; }
label.toggle input { margin-top: 4px; width: 18px; height: 18px; }
ol.lb { margin: 6px 0 0; padding-left: 22px; font-size: 14px; }
ol.lb li { padding: 4px 0; border-top: 1px solid var(--line); }
ol.lb li > span:first-child { display: inline-block; min-width: 40%; }
ol.lb li.me { color: var(--accent); }
.moves.learn { max-height: 46vh; overflow-y: auto; }
button.move.pick { width: 100%; text-align: left; background: var(--panel-2); color: var(--text); cursor: pointer; font: inherit;
                   border: 1px solid transparent; border-left: 4px solid var(--line); }
button.move.pick:disabled { cursor: default; opacity: 1; }
button.move.pick:not(:disabled):hover { border-color: var(--accent); }
input.search { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 8px;
               padding: 8px 10px; font: inherit; }
input.search:focus { outline: none; border-color: var(--accent); }
.card.mon.starter { flex-direction: column; align-items: center; text-align: center; gap: 4px; }
.card.mon.starter .info { align-items: center; }
.card.mon.starter .row { justify-content: center; }
.card.mon.starter .name { white-space: normal; overflow: visible; }
.bars.wide { grid-template-columns: 84px 38px 1fr 0; }

/* phase 5 */
.vs-player { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.vs-banner { position: fixed; bottom: 72px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; gap: 12px; align-items: center;
             padding: 10px 14px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--accent); box-shadow: 0 6px 24px rgba(0,0,0,.4);
             max-width: calc(100% - 32px); }

/* battle layout: moves right next to (wide) or right under (phone) the picture, the log after them */
main:has(.play .pbody) { max-width: 1240px; }
.play .pbody { display: grid; gap: 12px; margin-top: 8px; }
.play .pbody .scene { margin: 0; }
.play .pright .comps { margin-top: 0; }
@media (min-width: 860px) {
  .play .pbody { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); align-items: start; }
  .play .pleft { position: sticky; top: 8px; }
}
.play .scene { aspect-ratio: 16 / 9; object-fit: contain; }    /* its space is kept while a new picture loads: no jump */
@media (max-width: 859px) {
  .play .crow .btn { padding: 8px 6px; font-size: 13px; line-height: 1.25; min-height: 0; }
  .play .comps { gap: 6px; }
  .play .crow { gap: 6px; }
}

/* held items: a small icon on the Pokemon in the box, and next to the item's name on party cards */
.cell-pic { position: relative; display: inline-block; }
.cell .held { position: absolute; right: -4px; bottom: -2px; width: 24px; height: 24px; image-rendering: pixelated;
              background: var(--panel-2); border: 1px solid var(--line); border-radius: 50%; padding: 1px; }
.cell .held-dot { display: grid; place-items: center; font-size: 13px; }
.tag.item-tag { display: inline-flex; align-items: center; gap: 3px; }
.tag.item-tag img { width: 18px; height: 18px; image-rendering: pixelated; margin: -2px 0; }

/* party order: ▲ / ▼ next to each card */
.party-row { display: flex; gap: 6px; align-items: stretch; }
.party-row > .mon { flex: 1; min-width: 0; }
.party-row .order { display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.party-row .order .btn { padding: 6px 10px; line-height: 1; }
.move-row { display: flex; gap: 6px; align-items: stretch; }
.move-row > .move { flex: 1; min-width: 0; }
.move-row .order { display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.move-row .order .btn { padding: 3px 8px; line-height: 1; font-size: 12px; }

/* ---- the battle scene (activity_scene.py data, drawn here; sizes follow the scene's width) ---- */
.bscene { position: relative; width: 100%; aspect-ratio: 16 / 9; background-size: cover; background-position: center;
          border-radius: 8px; overflow: hidden; margin: 8px 0; container-type: inline-size; user-select: none; }
.bscene::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.bscene.w-rain::after { background: rgba(40, 80, 160, .16); }
.bscene.w-sun::after { background: rgba(255, 190, 60, .14); }
.bscene.w-sand::after { background: rgba(190, 150, 70, .2); }
.bscene.w-snow::after { background: rgba(220, 235, 255, .18); }
.bscene.playing { cursor: pointer; }
.spr { position: absolute; display: flex; align-items: flex-end; justify-content: center; transition: opacity .5s, filter .5s; }
.spr img { max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain; object-position: bottom center;
           image-rendering: pixelated; }
.spr.foe { left: 63.75%; bottom: 48.9%; width: 22.5%; height: 40%; }
.spr.me { left: 15.6%; bottom: 18.2%; width: 26.25%; height: 46.7%; }
.spr.faint { opacity: .25; filter: grayscale(1); transform: translateY(6%); }
.spr.hidden-mon { opacity: .45; }
.spr.lunge-me { animation: lunge-me .45s ease-out; }
.spr.lunge-foe { animation: lunge-foe .45s ease-out; }
.spr.hit { animation: hit .5s steps(2, end); }
.spr.heal { animation: heal .8s ease-out; }
.spr.buff { animation: buff .7s ease-out; }
@keyframes lunge-me { 40% { transform: translate(14%, -10%); } }
@keyframes lunge-foe { 40% { transform: translate(-14%, 10%); } }
@keyframes hit { 0%, 50%, 100% { opacity: 1; transform: translateX(0); } 25%, 75% { opacity: .2; transform: translateX(4%); } }
@keyframes heal { 50% { filter: drop-shadow(0 0 1.2cqw #6ef09a) brightness(1.2); } }
@keyframes buff { 50% { filter: drop-shadow(0 0 1.2cqw #8ec5ff) brightness(1.15); transform: translateY(-3%); } }
.hud { position: absolute; width: 33%; padding: .8cqw 1.1cqw; border-radius: 1cqw; background: rgba(14, 18, 26, .82);
       border: 1px solid rgba(255, 255, 255, .14); font-size: 1.75cqw; line-height: 1.35; color: #eef0f4; }
.hud.foe { left: 1.5cqw; top: 1.5cqw; }
.hud.me { right: 1.5cqw; bottom: 1.5cqw; }
.hud .hn { display: flex; align-items: baseline; gap: .6cqw; white-space: nowrap; overflow: hidden; }
.hud .hn b { overflow: hidden; text-overflow: ellipsis; }
.hud .lv { margin-left: auto; color: #b0b8c6; }
.hud .g.m { color: #6ea5ff; } .hud .g.f { color: #ff82b4; } .hud .sh { color: #ffd73c; }
.hud .hts { display: flex; gap: .5cqw; margin: .3cqw 0; }
.hud .ty, .hud .tg { font-size: 1.35cqw; padding: .1cqw .6cqw; border-radius: .5cqw; color: #fff; font-weight: 600;
                     text-shadow: 0 1px 1px rgba(0, 0, 0, .4); white-space: nowrap; }
.hpbar { height: 1cqw; min-height: 5px; background: #2e3440; border-radius: 1cqw; overflow: hidden; }
.hpbar i { display: block; height: 100%; border-radius: 1cqw; transition: width .6s ease, background .6s; }
.hud .hrow { display: flex; align-items: center; justify-content: space-between; margin-top: .3cqw; }
.hud .hpt { font-variant-numeric: tabular-nums; }
.balls { display: flex; gap: .45cqw; }
.ball { width: 1.25cqw; height: 1.25cqw; min-width: 7px; min-height: 7px; border-radius: 50%;
        background: linear-gradient(#de3a3a 50%, #f0f0f0 50%); border: 1px solid rgba(0, 0, 0, .5); }
.ball.status { background: linear-gradient(#de3a3a 50%, #f0f0f0 50%); box-shadow: inset 0 0 0 .35cqw #d6ae18; }
.ball.fainted { background: #464c5a; }
.xp { height: .4cqw; min-height: 2px; background: #2e3440; border-radius: 1cqw; overflow: hidden; margin-top: .3cqw; }
.xp i { display: block; height: 100%; background: #58a0ff; }
.hud .hab { color: #b0b8c6; margin-top: .2cqw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud .tags { display: flex; flex-wrap: wrap; gap: .4cqw; margin-top: .4cqw; }
.hud .tg.side { background: #3a4458; }
.bfield { position: absolute; left: 50%; top: 1.5cqw; transform: translateX(-50%); display: flex; gap: .6cqw;
          font-size: 1.5cqw; }
.bfield span { background: rgba(14, 18, 26, .78); padding: .2cqw .8cqw; border-radius: .6cqw; white-space: nowrap; }
.bmsg { position: absolute; left: 2cqw; right: 38%; bottom: 2cqw; padding: 1cqw 1.4cqw; border-radius: 1cqw;
        background: rgba(10, 14, 20, .9); border: 1px solid rgba(255, 255, 255, .18); font-size: 2cqw; line-height: 1.3; }
.bmsg.hidden { display: none; }
.blog-wrap { margin-top: 12px; }
.blog { max-height: 320px; overflow-y: auto; background: #0c1016; border: 1px solid var(--line); border-radius: 8px;
        padding: 6px 10px; font-size: 13px; line-height: 1.45; scroll-behavior: smooth; }
.lturn + .lturn { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }
.lt { font-weight: 700; color: var(--accent); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.ll.pending { display: none; }
@media (max-width: 560px) { .hud { width: 44%; font-size: 2.6cqw; } .hud .ty, .hud .tg { font-size: 2cqw; }
                            .bmsg { right: 2cqw; bottom: auto; top: 42%; font-size: 3cqw; } }
.spr.enter { animation: enter .5s ease-out; }
@keyframes enter { from { opacity: 0; transform: scale(.6) translateY(10%); } }
.comps.waiting { visibility: hidden; }
.devcmd input, #dev-bmon, #dev-blvl { background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font: inherit; min-width: 0; }
#dev-out { white-space: pre-wrap; }
