:root {
  --bg: #120e1c;
  --panel: #1e1830ee;
  --panel2: #2a2242;
  --line: #4a3d6e;
  --text: #f3ecff;
  --dim: #a99cc8;
  --gold: #ffd36a;
  --blue: #5ad1ff;
  --red: #ff5a6a;
  --green: #6aea7a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif; }
body { overflow: hidden; }
#app { height: 100%; }
[hidden] { display: none !important; }
button { font: inherit; color: var(--text); background: linear-gradient(#4a3d7a, #33295a); border: 2px solid #7a68b8; border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 700; touch-action: manipulation; }
button:hover:not(:disabled) { filter: brightness(1.15); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
button.big { font-size: 1.15rem; padding: 12px 22px; background: linear-gradient(#ffcf5a, #e88a2a); color: #2a1408; border-color: #ffe9a8; }
button.ghost { background: #ffffff10; border-color: #ffffff30; }
button.small { padding: 4px 10px; font-size: .85rem; }
button.icon { padding: 6px 10px; }
input, select { font: inherit; color: var(--text); background: #0e0a18; border: 2px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
h1, h2 { margin: 0 0 12px; }
h2 small { color: var(--dim); font-weight: 400; font-size: .75rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.row.center { justify-content: center; }
.grow { flex: 1; }
.panel { background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: 0 6px 24px #0008; }
.panel.narrow { max-width: 760px; width: calc(100% - 32px); }
.center { text-align: center; }
.note { color: var(--dim); font-size: .85rem; margin-top: 8px; min-height: 1.2em; }
.lbl { color: var(--dim); font-size: .9rem; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#title { background: url(assets/art/backgrounds/main-menu.png) center/cover; image-rendering: pixelated; gap: 10px; }
#title .logo { width: min(720px, 90vw); filter: drop-shadow(0 6px 12px #000a); }
#title .tag { font-size: 1.2rem; text-shadow: 0 2px 4px #000; margin: 0 0 18px; }
#profile { background: url(assets/art/backgrounds/team-showcase.png) center/cover; }
.field { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.trainer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; max-height: 52vh; overflow: auto; padding: 4px; }
.trainer-grid button { padding: 4px; background: var(--panel2); border-color: transparent; display: flex; flex-direction: column; align-items: center; font-size: .8rem; font-weight: 400; }
.trainer-grid button.sel { border-color: var(--gold); background: #4a3a22; }
.trainer-grid img { width: 64px; height: 64px; image-rendering: pixelated; }

/* Lobby */
#lobby { justify-content: flex-start; background: linear-gradient(#120e1cdd, #120e1cee), url(assets/art/backgrounds/team-showcase.png) center/cover; }
.topbar { width: 100%; display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: #0c0816cc; border-bottom: 2px solid var(--line); }
.mini-logo { height: 40px; }
.me { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; text-align: left; }
.me img { width: 36px; height: 36px; image-rendering: pixelated; background: #0006; border-radius: 6px; }
.me span { display: flex; flex-direction: column; line-height: 1.1; }
.me small { color: var(--gold); font-weight: 400; }
.net { font-size: .8rem; color: var(--dim); }
.net.on { color: var(--green); }
.lobby-body { flex: 1; width: 100%; max-width: 1400px; display: grid; grid-template-columns: minmax(320px, 420px) 1fr; gap: 14px; padding: 14px 16px; min-height: 0; }
.left { display: flex; flex-direction: column; gap: 14px; min-height: 0; overflow: auto; }
.right { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.team-slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.slot { background: var(--panel2); border: 2px dashed var(--line); border-radius: 10px; min-height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; padding: 4px; cursor: pointer; font-size: .85rem; }
.slot.filled { border-style: solid; }
.slot .ord { position: absolute; top: 4px; left: 6px; color: var(--gold); font-weight: 900; }
.slot .x { position: absolute; top: 2px; right: 4px; padding: 0 6px; font-size: .8rem; background: #0006; border: 0; }
.play { display: flex; flex-direction: column; gap: 10px; }
.play .big { width: 100%; }
#roomCode { width: 80px; }
.type-filters { display: flex; flex-wrap: wrap; gap: 4px; }
.type-chip { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px 2px 3px; border-radius: 999px; font-size: .78rem; font-weight: 700; border: 2px solid transparent; background: #ffffff14; }
.type-chip img { width: 18px; height: 18px; }
button.type-chip.sel { border-color: var(--gold); background: #4a3a22; }
.roster { flex: 1; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; align-content: start; padding-right: 4px; }
.card { background: var(--panel2); border: 2px solid transparent; border-radius: 10px; padding: 4px 4px 6px; display: flex; flex-direction: column; align-items: center; cursor: pointer; font-weight: 400; }
.card:hover { border-color: #7a68b8; }
.card.sel { border-color: var(--gold); }
.card.inteam { outline: 2px solid var(--green); }
.card b { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.card small { color: var(--dim); font-size: .72rem; }
.card .types { display: flex; gap: 2px; }
.card .types img { width: 18px; height: 18px; }
.thumb { width: 128px; height: 96px; max-width: 100%; background-repeat: no-repeat; background-size: 768px 192px; background-position: 0 0; image-rendering: pixelated; }
.card .thumb { width: 108px; height: 81px; background-size: 648px 162px; }
.detail .head { display: flex; gap: 10px; align-items: center; }
.detail .head .thumb { flex: none; }
.stat { display: grid; grid-template-columns: 52px 34px 1fr; gap: 6px; align-items: center; font-size: .8rem; }
.stat .bar { height: 8px; background: #0008; border-radius: 4px; overflow: hidden; }
.stat .bar i { display: block; height: 100%; background: var(--blue); }
.moves { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.mv { display: flex; gap: 6px; align-items: center; background: #0006; border-radius: 8px; padding: 4px; font-size: .78rem; }
.mv img { width: 32px; height: 32px; }
.mv small { color: var(--dim); display: block; }

/* Overlays */
.overlay { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box { max-width: 640px; width: calc(100% - 32px); max-height: 86vh; overflow: auto; }
.modal-box p, .modal-box li { line-height: 1.6; color: #e0d8f4; }
.board { width: 100%; border-collapse: collapse; }
.board td, .board th { padding: 6px; border-bottom: 1px solid var(--line); text-align: left; }
.board img { width: 28px; height: 28px; vertical-align: middle; image-rendering: pixelated; }
.result-box { position: relative; width: min(960px, 96vw); }
.result-box img { width: 100%; display: block; border-radius: 12px; image-rendering: pixelated; }
#resultText { position: absolute; left: 0; right: 0; bottom: 70px; text-align: center; font-size: 1.4rem; font-weight: 900; text-shadow: 0 2px 6px #000; }
.result-box .row { position: absolute; left: 0; right: 0; bottom: 16px; }

/* Battle */
#battle { background: #000; justify-content: flex-start; }
#stage { position: relative; width: min(100vw, calc((100vh - 120px) * 16 / 9)); aspect-ratio: 16 / 9; }
#c { width: 100%; height: 100%; display: block; image-rendering: pixelated; touch-action: none; }
#hudTop { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: flex-start; gap: 8px; padding: 1%; pointer-events: none; }
.side-card { flex: 1; max-width: 40%; display: flex; gap: 8px; align-items: center; background: #0c0816cc; border: 2px solid var(--line); border-radius: 12px; padding: 6px 10px; }
.side-card.right { flex-direction: row-reverse; text-align: right; margin-left: auto; }
.side-card .av { width: 44px; height: 44px; image-rendering: pixelated; background: #0006; border-radius: 8px; flex: none; }
.side-card .info { flex: 1; min-width: 0; }
.side-card .nm { font-size: .8rem; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-card .mon { font-weight: 900; font-size: 1rem; display: flex; gap: 4px; align-items: center; }
.side-card.right .mon { justify-content: flex-end; }
.side-card .mon img { width: 18px; height: 18px; }
.hp { height: 12px; background: #0009; border-radius: 6px; overflow: hidden; margin-top: 3px; border: 1px solid #fff3; }
.hp i { display: block; height: 100%; background: linear-gradient(#8aff8a, #3cc84a); transition: width .15s; }
.hp i.mid { background: linear-gradient(#ffe36a, #e8b02a); }
.hp i.low { background: linear-gradient(#ff7a6a, #d83a3a); }
.side-card.right .hp i { margin-left: auto; }
.pips { display: flex; gap: 4px; margin-top: 4px; }
.side-card.right .pips { justify-content: flex-end; }
.pips span { width: 12px; height: 12px; border-radius: 50%; background: var(--green); border: 1px solid #0008; }
.pips span.down { background: #555; }
.pips span.cur { outline: 2px solid #fff; }
.hptxt { font-size: .7rem; color: var(--dim); }
#clock { font-size: 1.6rem; font-weight: 900; background: #0c0816cc; border: 2px solid var(--line); border-radius: 10px; padding: 2px 14px; font-variant-numeric: tabular-nums; }
#clock.sd { color: var(--red); border-color: var(--red); }
#surrenderBtn { position: absolute; left: 1%; bottom: 2%; }
#muteBtn2 { position: absolute; right: 1%; bottom: 2%; }
#vs { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 4%; background: #000c; font-size: 2rem; font-weight: 900; }
#vs .who { display: flex; flex-direction: column; align-items: center; gap: 6px; }
#vs .who img.p { width: 160px; height: 160px; image-rendering: pixelated; }
#vs .team { display: flex; }
#vs .team .thumb { width: 96px; height: 72px; background-size: 576px 144px; }
#vs .vs { font-size: 4rem; color: var(--gold); text-shadow: 0 4px 0 #a04010; }
#vs small { color: var(--gold); font-size: 1rem; }
#pickBox { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--panel); border: 2px solid var(--gold); border-radius: 14px; padding: 14px; text-align: center; }
#pickBox .row { justify-content: center; margin-top: 8px; }
#pickBox button { display: flex; flex-direction: column; align-items: center; font-weight: 400; }
#toast { position: absolute; left: 50%; top: 18%; transform: translateX(-50%); background: #000c; padding: 6px 14px; border-radius: 8px; font-weight: 700; pointer-events: none; }
#controls { width: min(100vw, 1200px); display: flex; gap: 10px; padding: 8px; align-items: stretch; justify-content: center; flex-wrap: wrap; }
#moveBtns { display: grid; grid-template-columns: repeat(4, minmax(100px, 150px)); gap: 6px; }
.mb { position: relative; overflow: hidden; display: flex; align-items: center; gap: 6px; padding: 6px; text-align: left; font-weight: 700; font-size: .85rem; min-height: 56px; border-width: 3px; }
.mb img { width: 36px; height: 36px; flex: none; position: relative; }
.mb span { position: relative; line-height: 1.15; }
.mb small { display: block; font-weight: 400; color: var(--dim); font-size: .7rem; }
.mb .cd, .act i { position: absolute; left: 0; bottom: 0; width: 100%; background: #000a; pointer-events: none; }
.mb.ready.inrange { box-shadow: 0 0 12px #ffe36a; border-color: #ffe36a; }
.mb.queued { border-color: var(--blue); }
.mb kbd, .act kbd { position: absolute; right: 4px; top: 2px; font-size: .65rem; color: var(--dim); font-family: inherit; }
#bench { display: flex; gap: 6px; }
.bn { position: relative; padding: 2px 4px; display: flex; flex-direction: column; align-items: center; font-size: .7rem; font-weight: 400; min-width: 84px; }
.bn .thumb { width: 72px; height: 54px; background-size: 432px 108px; }
.bn .hp { width: 100%; height: 6px; }
.bn.down { filter: grayscale(1); opacity: .5; }
#actBtns { display: flex; gap: 6px; }
.act { position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: center; padding: 4px 8px; font-size: .8rem; min-width: 64px; }
.act img { width: 30px; height: 30px; position: relative; }
.act span { position: relative; }
.act.on { border-color: var(--green); }

@media (max-width: 900px) {
  .lobby-body { grid-template-columns: 1fr; overflow: auto; }
  .right { min-height: 60vh; }
  #moveBtns { grid-template-columns: repeat(2, 1fr); width: 100%; }
  .mini-logo { display: none; }
  #stage { width: 100vw; }
  .side-card .av { display: none; }
  #vs .who img.p { width: 96px; height: 96px; }
}
.slot .types img { width: 20px; height: 20px; }
.slot b { font-size: .85rem; text-align: center; }
.slot .thumb { width: 100%; max-width: 128px; background-size: 600% 200%; aspect-ratio: 4 / 3; height: auto; }
