:root {
  --bg: #0e1726; --felt: #13233a; --felt2: #182c48; --line: #2a3f5f;
  --ink: #e8eef7; --muted: #8fa3bf; --card: #fbf8f1; --card-ink: #1d2433;
  --accent: #ffcb05; --accent2: #3d7dca; --good: #3fb67b; --bad: #e25555;
  --R: #e4572e; --W: #2e86de; --L: #e0b000; --F: #b5651d; --C: #8e979e;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; }
button, select, input, textarea { font: inherit; }
button { background: #24375a; color: var(--ink); border: 1px solid #36507a; border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button:hover:not(:disabled) { background: #2d4570; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #1a1a1a; border-color: #d9ab00; font-weight: 700; }
button.primary:hover:not(:disabled) { background: #ffd83d; }
button.big { padding: 12px 28px; font-size: 16px; }
select, input, textarea { background: #0b1320; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
textarea { width: 100%; font-family: ui-monospace, monospace; font-size: 12px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 12px 0 6px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 20px; padding: 10px 18px; background: #0a111d; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.ball { width: 18px; height: 18px; border-radius: 50%; background: linear-gradient(#e33 0 45%, #111 45% 55%, #fff 55%); border: 2px solid #111; }
.tabs { display: flex; gap: 4px; }
.tabs button { background: transparent; border-color: transparent; }
.tabs button.on { background: var(--felt2); border-color: var(--line); }
.model-badge { margin-left: auto; font-size: 12px; color: var(--muted); }

main { padding: 14px 16px; }
.tab { display: none; }
.tab.on { display: block; }
.box { background: var(--felt); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }

/* 大廳 */
.lobby { max-width: 760px; margin: 30px auto; background: var(--felt); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.lobby-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field select, .field input { color: var(--ink); font-size: 14px; }
.hint-text { color: var(--muted); font-size: 13px; line-height: 1.6; }

/* 對戰桌 */
.table { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; align-items: start; }
@media (max-width: 1000px) { .table { grid-template-columns: 1fr; } }
.board { background: radial-gradient(ellipse at center, #1d3a5e 0%, var(--felt) 70%); border: 1px solid var(--line); border-radius: 16px; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.side { display: flex; flex-direction: column; gap: 8px; }
.side.me { flex-direction: column-reverse; }
.midline { border-top: 1px dashed #3a5782; text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0 0; min-height: 22px; }
.midline b { color: var(--accent); }

.infobar { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 12px; color: var(--muted); padding: 2px 6px; }
.infobar .who { color: var(--ink); font-weight: 700; font-size: 14px; }
.infobar .who.turn::before { content: "▶ "; color: var(--accent); }
.prizes { display: inline-flex; gap: 3px; }
.prizes i { width: 10px; height: 14px; border-radius: 2px; background: var(--accent); display: inline-block; }
.prizes i.taken { background: #33445f; }
.flag { padding: 1px 6px; border-radius: 10px; background: #24375a; }
.flag.used { opacity: .45; text-decoration: line-through; }
.flag.hide { visibility: hidden; }

.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.activezone { display: flex; justify-content: center; }
.slot-empty { width: 132px; min-height: 92px; border: 1px dashed #36507a; border-radius: 10px; opacity: .5; }

.mon { width: 132px; background: var(--card); color: var(--card-ink); border-radius: 10px; padding: 6px 7px; position: relative; border-top: 6px solid var(--C); box-shadow: 0 2px 6px rgba(0,0,0,.35); cursor: pointer; transition: transform .12s, box-shadow .12s; }
.mon.active { width: 210px; }
.mon:hover { transform: translateY(-2px); }
.mon.sel { box-shadow: 0 0 0 3px var(--accent); }
.mon.tgt { box-shadow: 0 0 0 3px var(--good); }
.mon.flash { animation: flash .8s; }
@keyframes flash { 0% { box-shadow: 0 0 0 6px var(--bad); } 100% { box-shadow: 0 2px 6px rgba(0,0,0,.35); } }
.t-R { border-top-color: var(--R); } .t-W { border-top-color: var(--W); } .t-L { border-top-color: var(--L); } .t-F { border-top-color: var(--F); }
.mon-head { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; }
.mon-name { font-weight: 800; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mon-hp { font-size: 11px; font-weight: 700; white-space: nowrap; }
.hpbar { height: 5px; background: #ddd5c4; border-radius: 3px; margin: 3px 0; overflow: hidden; }
.hpbar i { display: block; height: 100%; background: var(--good); }
.hpbar i.mid { background: #e0a800; } .hpbar i.low { background: var(--bad); }
.mon-sub { font-size: 10px; color: #6a7285; }
.energies { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 3px; min-height: 16px; }
.e { width: 16px; height: 16px; border-radius: 50%; color: #fff; font-size: 9px; font-style: normal; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; }
.e-R { background: var(--R); } .e-W { background: var(--W); } .e-L { background: var(--L); } .e-F { background: var(--F); } .e-C { background: var(--C); }
.conds { position: absolute; top: -10px; right: 4px; display: flex; gap: 2px; }
.cond { font-size: 10px; background: #6b2fb8; color: #fff; padding: 0 5px; border-radius: 8px; }
.dmg { position: absolute; left: -6px; top: 22px; background: var(--bad); color: #fff; font-weight: 800; font-size: 11px; border-radius: 12px; padding: 1px 6px; border: 2px solid #fff; }
.atk { font-size: 11px; display: flex; align-items: center; gap: 3px; margin-top: 3px; }
.atk .cost { display: inline-flex; gap: 1px; }
.atk .cost .e { width: 13px; height: 13px; font-size: 8px; }
.atk .an { flex: 1; font-weight: 700; }
.atk .ad { font-weight: 800; }
.atk.off { opacity: .45; }
.abil { font-size: 10px; color: #b3261e; font-weight: 700; margin-top: 2px; }

.hand { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; padding: 4px; }
.card { width: 92px; min-height: 62px; background: var(--card); color: var(--card-ink); border-radius: 8px; padding: 5px 6px; font-size: 11px; border-left: 5px solid var(--C); cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.35); transition: transform .12s; }
.card:hover { transform: translateY(-3px); }
.card.play { box-shadow: 0 0 0 2px var(--good); }
.card.sel { box-shadow: 0 0 0 3px var(--accent); }
.card .cn { font-weight: 800; font-size: 12px; line-height: 1.2; }
.card .cs { color: #6a7285; font-size: 10px; }
.card.k-item { border-left-color: #3d7dca; } .card.k-supporter { border-left-color: #d6457a; }
.card.k-energy.t-R, .card.k-pokemon.t-R { border-left-color: var(--R); }
.card.k-energy.t-W, .card.k-pokemon.t-W { border-left-color: var(--W); }
.card.k-energy.t-L, .card.k-pokemon.t-L { border-left-color: var(--L); }
.card.k-energy.t-F, .card.k-pokemon.t-F { border-left-color: var(--F); }
.card.back { background: repeating-linear-gradient(45deg, #2b4a7a 0 6px, #24406b 6px 12px); width: 34px; min-height: 48px; border: 2px solid #c9d6ea; cursor: default; }
.card.mini { width: 74px; min-height: 40px; font-size: 10px; }

/* 右側面板 */
.panel { display: flex; flex-direction: column; gap: 10px; position: sticky; top: 10px; }
.panel-controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.panel-controls .status { width: 100%; font-weight: 700; }
.panel-controls .status.thinking::after { content: " ⏳"; }
.actlist { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; }
.actlist button { text-align: left; padding: 6px 9px; display: flex; gap: 6px; align-items: center; }
.actlist button .star { color: var(--accent); }
.actlist button.best { border-color: var(--accent); }
.actlist button.end { background: #3a2432; border-color: #5c3448; }
.grp { font-size: 11px; color: var(--muted); margin-top: 4px; }
.prompt-title { font-weight: 800; color: var(--accent); margin-bottom: 6px; }
.selinfo { font-size: 12px; margin-bottom: 6px; }
.selinfo a { color: var(--accent2); cursor: pointer; }
.hintrow { display: grid; grid-template-columns: 1fr 58px 44px; gap: 6px; align-items: center; font-size: 12px; padding: 3px 0; border-bottom: 1px solid #22385a; }
.hintrow .bar { height: 6px; background: #22385a; border-radius: 3px; overflow: hidden; }
.hintrow .bar i { display: block; height: 100%; background: var(--accent2); }
.hintrow.top .lbl { color: var(--accent); font-weight: 700; }
.hintrow .wr { text-align: right; font-variant-numeric: tabular-nums; }
.detail { font-size: 12px; line-height: 1.55; min-height: 60px; }
.detail .dn { font-weight: 800; font-size: 14px; }
.logbox #log { max-height: 240px; overflow-y: auto; font-size: 12px; line-height: 1.5; }
.logbox #log .turn { color: var(--accent); margin-top: 4px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal-inner { background: var(--felt); border: 1px solid var(--line); border-radius: 16px; padding: 24px; max-width: 420px; width: 100%; text-align: center; }
.modal-inner h2 { font-size: 24px; }

/* 訓練頁 */
.train-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 14px; align-items: start; }
.form-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.form-row .field { width: 130px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.chart svg { width: 100%; height: 160px; display: block; }
.trainlog { font-size: 12px; max-height: 260px; overflow-y: auto; line-height: 1.6; font-variant-numeric: tabular-nums; }
.trainlog .ok { color: var(--good); } .trainlog .no { color: var(--muted); }
table.wt { width: 100%; border-collapse: collapse; font-size: 12px; }
table.wt td, table.wt th { padding: 3px 6px; border-bottom: 1px solid #22385a; text-align: right; font-variant-numeric: tabular-nums; }
table.wt td:first-child, table.wt th:first-child { text-align: left; }
table.wt .up { color: var(--good); } table.wt .down { color: var(--bad); }
.progress { height: 8px; background: #22385a; border-radius: 4px; overflow: hidden; margin: 6px 0; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
table.matrix { border-collapse: collapse; font-size: 12px; margin-top: 6px; }
table.matrix td, table.matrix th { padding: 5px 8px; text-align: center; border: 1px solid #22385a; }

/* 卡表 */
.rules { margin-bottom: 14px; line-height: 1.7; }
.rules ul { margin: 0; padding-left: 20px; }
.deckcol { margin-bottom: 14px; }
.cardgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 8px; }
.cardinfo { background: var(--card); color: var(--card-ink); border-radius: 10px; padding: 8px 10px; font-size: 12px; border-top: 5px solid var(--C); line-height: 1.5; }
.cardinfo .cnt { float: right; font-weight: 800; color: #6a7285; }
.card.k-stadium { border-left-color: #2e9e6b; }
.t-G { border-top-color: var(--G, #4caf50); } .t-P { border-top-color: #9c4dcc; } .t-D { border-top-color: #37474f; } .t-C { border-top-color: var(--C); }
.e-G { background: #4caf50; } .e-P { background: #9c4dcc; } .e-D { background: #37474f; } .e-M { background: #78909c; } .e-N { background: #b8860b; }
.side .row .mon, .side .row .slot-empty { width: 118px; }
.dmg { left: auto; right: -6px; top: 18px; }

/* ───── 卡片圖片（台灣官方卡片資料庫） ───── */
.card.has-img { padding: 0; width: 84px; min-height: 0; background: transparent; border-left: 0; border-radius: 5px; overflow: hidden; }
.card.has-img .ctext { display: none; }
.card .cimg { display: block; width: 100%; aspect-ratio: 63 / 88; object-fit: cover; border-radius: 5px; }
.card.has-img.play { box-shadow: 0 0 0 3px var(--good); }
.card.has-img.sel { box-shadow: 0 0 0 3px var(--accent); transform: translateY(-6px); }
.card.mini.has-img { width: 60px; }
.mon .art { height: 58px; margin: -6px -7px 5px; border-radius: 4px 4px 0 0; background-color: #ddd5c4; background-size: 118% auto; background-position: 50% 16%; background-repeat: no-repeat; }
.mon.active .art { height: 104px; background-size: 112% auto; background-position: 50% 18%; }
.detail-img { display: block; width: 100%; max-width: 250px; margin: 0 auto 8px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.cardinfo.with-img { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: start; }
.cardinfo .list-img { display: block; width: 96px; border-radius: 6px; }

/* ───── 牌庫／棄牌／獎賞卡內容 ───── */
.zone-btn { background: transparent; border: 1px solid #36507a; border-radius: 10px; padding: 1px 8px; font-size: 12px; color: var(--ink); }
.zone-btn:hover:not(:disabled) { background: #24375a; border-color: var(--accent); }
.zone-inner { max-width: 960px; max-height: 88vh; overflow-y: auto; text-align: left; }
.zone-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.zone-head h2 { font-size: 18px; margin: 0; }
.zgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin: 6px 0 12px; }
.zcard { position: relative; background: var(--card); color: var(--card-ink); border-radius: 6px; font-size: 11px; padding: 6px; min-height: 60px; }
.zcard.has-img { background: transparent; padding: 0; min-height: 0; }
.zcard.has-img .ctext { display: none; }
.zcard img { display: block; width: 100%; aspect-ratio: 63 / 88; object-fit: cover; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.zcount { position: absolute; right: -4px; bottom: -4px; background: var(--accent); color: #1a1a1a; font-weight: 800; font-size: 13px; border-radius: 10px; padding: 1px 7px; border: 2px solid var(--felt); }

/* ═════ 一頁顯示：對戰畫面依視窗高度縮放，不需要捲動 ═════ */
:root {
  --row-h: clamp(112px, 24vh, 260px);          /* 戰鬥場＋備戰區這一列的高度 */
  --active-w: calc(var(--row-h) * 0.8);
  --bench-w: calc(var(--row-h) * 0.58);
  --hand-h: clamp(74px, 15.5vh, 180px);        /* 自己手牌高度 */
  --opp-hand-h: clamp(40px, 8vh, 96px);        /* 對手手牌（顯示時） */
  --back-h: clamp(24px, 4.2vh, 44px);          /* 蓋著的手牌 */
}
html, body { height: 100%; }
body { display: flex; flex-direction: column; overflow: hidden; }
.topbar { flex: 0 0 auto; padding: 6px 14px; }
main { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 8px 12px; }
#tab-play.on { height: 100%; }
.table { height: 100%; grid-template-columns: minmax(0, 1fr) 320px; gap: 10px; align-items: stretch; }
.board { height: 100%; min-height: 0; overflow: hidden; padding: 6px 8px; gap: 4px; justify-content: space-between; }
.side { gap: 4px; min-height: 0; }
.midline { padding: 2px 0 0; min-height: 18px; font-size: 12px; }
.infobar { padding: 0 4px; gap: 4px 10px; line-height: 1.5; }

.mon, .slot-empty { box-sizing: border-box; }
.mon { display: flex; flex-direction: column; overflow: hidden; padding: 4px 6px; font-size: 11px; }
.slot-empty { min-height: 0; }
.mon .art { flex: 1 1 auto; min-height: 16px; height: auto; margin: -4px -6px 3px; background-size: cover; background-position: 50% 16%; }
.mon.active .art { height: auto; background-size: cover; background-position: 50% 18%; }
.mon .mon-name { font-size: 12px; }
.mon .hpbar { margin: 2px 0; flex: 0 0 auto; }
.mon .energies { min-height: 14px; margin-top: 2px; flex: 0 0 auto; }
.mon .e { width: 14px; height: 14px; font-size: 8px; }
.mon .atk { margin-top: 1px; font-size: 10px; }
.mon .dmg { top: 4px; right: 2px; left: auto; }
.mon .conds { top: 2px; left: 4px; right: auto; }
.mon:hover { transform: none; filter: brightness(1.05); }

/* 手牌：固定高度，放不下時重疊 */
.hand { flex-wrap: nowrap; justify-content: center; padding: 2px 4px; min-height: 0; overflow: visible; }
.side.me .hand { height: var(--hand-h); }
.side.opp .hand { height: var(--opp-hand-h); }
.side.opp .hand.backs { height: var(--back-h); }
.hand .card { flex: 0 0 auto; position: relative; }
.side.me .hand .card { height: var(--hand-h); width: calc(var(--hand-h) * 0.716); min-height: 0; }
.side.opp .hand .card { height: var(--opp-hand-h); width: calc(var(--opp-hand-h) * 0.716); min-height: 0; }
.side.opp .hand .card.back { height: var(--back-h); width: calc(var(--back-h) * 0.716); }
.hand .card .cimg { height: 100%; width: 100%; }
.hand .card:not(.has-img) { overflow: hidden; }
.hand.overlap .card + .card { margin-left: calc(-1 * var(--overlap)); }
.hand .card:hover, .hand .card.sel { z-index: 5; transform: translateY(-8px); }

/* 右側面板：固定高度，長內容在框內捲動 */
.panel { position: static; height: 100%; min-height: 0; gap: 6px; overflow: hidden; }
.panel > .box { padding: 8px 10px; }
.panel h3 { margin: 2px 0 4px; }
#promptBox { flex: 0 1 auto; max-height: 45%; overflow-y: auto; }
#actionsBox { flex: 1.3 1 0; min-height: 130px; overflow-y: auto; }
#actionsBox .actlist, #promptBox .actlist { max-height: none; overflow: visible; }
#hintBox { flex: 0 1 auto; max-height: 30%; overflow-y: auto; }
#detailBox { flex: 0 1 auto; max-height: 22%; overflow-y: auto; min-height: 0; }
#detailBox::after { content: ""; display: block; clear: both; }
.detail-img { float: left; width: 80px; max-width: 80px; margin: 0 10px 4px 0; border-radius: 6px; }
.logbox { flex: 1 1 0; min-height: 70px; display: flex; flex-direction: column; }
.logbox #log { flex: 1 1 auto; max-height: none; min-height: 0; }
.actlist button { padding: 4px 8px; font-size: 13px; }

/* 視窗太窄時改回上下排列並允許捲動 */
@media (max-width: 1000px) {
  body { overflow: auto; display: block; height: auto; }
  main { overflow: visible; }
  #tab-play.on, .table, .board, .panel { height: auto; }
  .panel { overflow: visible; }
  #actionsBox, .logbox { flex: none; }
  .logbox #log { max-height: 240px; }
}

/* ═════ 對戰場：對手在上、自己在下；戰鬥場置中，備戰區分在左右 ═════ */
.midline { flex: 0 0 auto; border-top: 1px dashed #3a5782; border-bottom: 1px dashed #3a5782; padding: 2px 0; }
.board { justify-content: space-between; }
.fieldrow { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 10px; height: var(--row-h); min-height: 0; align-items: stretch; }
.bench-part { display: flex; gap: 6px; min-width: 0; overflow: hidden; }
.bench-part.left { justify-content: flex-end; }
.bench-part.right { justify-content: flex-start; }
.bench-part .mon, .bench-part .slot-empty { flex: 0 1 var(--bench-w); width: var(--bench-w); min-width: 52px; height: 100%; }
.bench-part .mon .mon-sub, .bench-part .mon .abil { display: none; }
.bench-part .mon .mon-name { font-size: 11px; }
.active-slot { display: flex; height: 100%; }
.active-slot .mon.active, .active-slot .active-empty { width: var(--active-w); height: 100%; }
.side.me .active-slot .mon.active { box-shadow: 0 0 0 2px #3d7dca, 0 4px 14px rgba(0,0,0,.45); }
.side.opp .active-slot .mon.active { box-shadow: 0 0 0 2px #c0504d, 0 4px 14px rgba(0,0,0,.45); }
.active-slot .mon.active.sel { box-shadow: 0 0 0 3px var(--accent); }
.active-slot .mon.active.tgt { box-shadow: 0 0 0 3px var(--good); }
@media (max-width: 1000px) {
  .fieldrow { height: auto; grid-template-columns: 1fr; }
  .bench-part { justify-content: center !important; flex-wrap: wrap; height: auto; }
  .bench-part .mon, .bench-part .slot-empty { height: 130px; }
  .active-slot { justify-content: center; }
  .active-slot .mon.active, .active-slot .active-empty { height: 200px; width: 160px; }
}
/* 戰鬥場列貼近中線，多出的空間留在手牌那一側 */
.board { justify-content: flex-start; }
.board > .side { flex: 1 1 0; min-height: 0; }
.side.opp .fieldrow { margin-top: auto; }
.side.me .fieldrow { margin-bottom: auto; }
@media (max-width: 1000px) { .board > .side { flex: none; } }
/* 戰鬥場比備戰區高，並往中線切齊；備戰區往外側對齊 */
:root {
  --active-h: clamp(130px, 26vh, 290px);
  --bench-h: clamp(88px, 17.5vh, 190px);
}
.fieldrow { height: var(--active-h); align-items: stretch; }
.active-slot { height: var(--active-h); }
.active-slot .mon.active, .active-slot .active-empty { height: 100%; width: calc(var(--active-h) * 0.76); }
.bench-part { height: var(--bench-h); }
.bench-part .mon, .bench-part .slot-empty { flex: 0 1 calc(var(--bench-h) * 0.74); width: calc(var(--bench-h) * 0.74); height: 100%; }
.side.opp .bench-part { align-self: start; }
.side.opp .active-slot { align-self: end; }
.side.me .bench-part { align-self: end; }
.side.me .active-slot { align-self: start; }
@media (max-width: 1000px) {
  .fieldrow, .active-slot, .bench-part { height: auto; }
}
/* 上下兩半依內容分配高度（自己這半多了手牌），戰場列與手牌不可被壓縮 */
.board > .side { flex: 1 1 auto; }
.board .fieldrow, .board .side .hand, .board .infobar { flex-shrink: 0; }

/* ───── 競技場：戰場右側中間，卡片圖片 ───── */
.midline { position: relative; overflow: visible; }
.stadium-zone {
  --stadium-h: clamp(90px, calc((var(--active-h) - var(--bench-h)) * 2 + 10px), 220px);
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%); z-index: 4;
  height: var(--stadium-h); width: calc(var(--stadium-h) * 0.716);
  border-radius: 8px; cursor: help;
}
.stadium-zone img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 8px; box-shadow: 0 0 0 2px #2e9e6b, 0 4px 14px rgba(0,0,0,.5); }
.stadium-zone .stadium-text { height: 100%; display: flex; align-items: center; justify-content: center; text-align: center; background: var(--card); color: var(--card-ink); border-radius: 8px; font-weight: 800; padding: 6px; border-left: 5px solid #2e9e6b; }
.stadium-owner { position: absolute; left: 50%; bottom: -8px; transform: translateX(-50%); font-size: 10px; background: #1d3a2e; color: #bfe8d2; border: 1px solid #2e9e6b; border-radius: 8px; padding: 0 6px; white-space: nowrap; }
.stadium-zone.empty { border: 1px dashed #2e5a48; display: flex; align-items: center; justify-content: center; cursor: default; }
.stadium-zone.empty span { font-size: 11px; color: #4d7a66; writing-mode: vertical-rl; letter-spacing: .2em; }
@media (max-width: 1000px) { .midline .stadium-zone { position: static; transform: none; margin: 4px auto; } }

/* 先攻／後攻標籤 */
.infobar .order { font-size: 11px; font-weight: 800; padding: 0 7px; border-radius: 9px; line-height: 18px; }
.infobar .order.first { background: #d93a3a; color: #fff; }
.infobar .order.second { background: #2e9e5b; color: #fff; }

/* 真人常選動作標示 */
.human-tag { margin-left: 4px; font-size: 12px; }

/* 牌組目標 */
#planBox { flex: 0 0 auto; max-height: 26%; overflow-y: auto; font-size: 12px; line-height: 1.55; }
#planBox h3 { margin: 0 0 3px; }
#planBox .goal { color: var(--muted); }
#planBox .goal.done { color: var(--good); }
#planBox .goal.part { color: #d9b44a; }

/* 寶可夢道具 */
.mon .tool-tag { font-size: 10px; background: #e8eefc; color: #2d4570; border-radius: 6px; padding: 0 4px; margin-left: 2px; white-space: nowrap; }

.info-pre { white-space: pre-wrap; font-family: inherit; font-size: 13px; line-height: 1.6; background: rgba(0,0,0,.18); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 0; }
.paused-note { text-align: center; padding: 10px 4px; font-weight: 600; line-height: 1.7; }

/* 拖曳操作 */
#sideBottom .hand .card.play, #sideBottom .active-slot .mon.can-drag { touch-action: none; cursor: grab; }
/* 手機：手牌是一條左右滑動的捲軸，可選的牌也要能滑（pan-x 交給瀏覽器捲動，上下才是出牌） */
@media (max-width: 560px) {
  #sideBottom .hand .card.play { touch-action: pan-x; }
}
.card img, .mon img { -webkit-user-drag: none; user-select: none; }
.dragging { opacity: .35; }
.drag-ghost { position: fixed; left: 0; top: 0; z-index: 1000; pointer-events: none; opacity: .92; box-shadow: 0 12px 28px rgba(0,0,0,.55); transition: none; }
.drop-ok { outline: 2px dashed var(--good); outline-offset: 2px; }
.drop-hover { outline: 3px solid var(--accent) !important; outline-offset: 2px; transform: scale(1.04); }
.board.drop-board { box-shadow: inset 0 0 0 3px rgba(120, 220, 140, .55); border-radius: 14px; }
.drop-menu { position: fixed; z-index: 1001; background: var(--felt); border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 6px; max-width: 320px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.drop-menu button { text-align: left; }
.drop-menu .cancel { opacity: .75; }

/* 選卡視窗 */
.pick-modal { background: rgba(0,0,0,.45); }
.pick-inner { max-width: 900px; max-height: 86vh; overflow-y: auto; text-align: left; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; margin: 10px 0 14px; }
.pick-card { display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 6px; background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; transition: transform .1s, box-shadow .1s; text-align: center; }
.pick-card:hover { transform: translateY(-3px); box-shadow: 0 0 0 2px var(--good), 0 8px 18px rgba(0,0,0,.4); }
.pick-card.best { box-shadow: 0 0 0 2px var(--accent); }
.pick-card img { width: 100%; aspect-ratio: 63 / 88; object-fit: cover; border-radius: 6px; }
.pick-noimg { aspect-ratio: 63 / 88; display: flex; align-items: center; justify-content: center; background: var(--card); color: var(--card-ink); border-radius: 6px; font-weight: 600; padding: 6px; }
.pick-label { font-size: 12px; line-height: 1.35; }
.pick-others { justify-content: center; }
#pickReopen { width: 100%; margin: 6px 0; }

/* 直接點卡片使用特性／招式 */
.mon .atk.usable, .mon .abil.usable { cursor: pointer; border-radius: 4px; box-shadow: inset 0 0 0 1px var(--good); background: rgba(80, 200, 120, .16); }
.mon .atk.usable:hover, .mon .abil.usable:hover { background: rgba(80, 200, 120, .38); }
.mon.has-acts { outline: 2px solid rgba(80, 200, 120, .55); outline-offset: 1px; }
.drop-menu .best { box-shadow: 0 0 0 2px var(--accent); }

.drop-area { background: rgba(120, 220, 140, .10); box-shadow: inset 0 0 0 2px rgba(120, 220, 140, .5); border-radius: 12px; }
.drop-area.drop-hover { background: rgba(120, 220, 140, .22); outline: none !important; transform: none; }

/* 左側中間的結束回合／完成配置按鈕 */
.side-end { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); z-index: 6; padding: 8px 16px; font-size: 14px; font-weight: 700; border-radius: 999px; background: #c0392b; color: #fff; border: none; box-shadow: 0 3px 10px rgba(0,0,0,.45); cursor: pointer; }
.side-end:hover { background: #e04b3c; }
.side-end.setup { background: #2e8b57; }
.side-end.setup:hover { background: #38a869; }

/* 場上寶可夢詳細資訊 */
.drop-menu.mon-panel { max-width: 380px; width: 380px; max-height: 86vh; overflow-y: auto; }
.mp-top { display: flex; justify-content: space-between; align-items: center; }
.mp-top .cancel { padding: 2px 10px; }
.mp-body { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; font-size: 12px; line-height: 1.5; }
.mp-head { font-size: 14px; }
.mp-sec { margin: 8px 0 3px; font-weight: 700; color: var(--accent); font-size: 12px; }
.mp-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 6px; }
.mp-card { display: flex; flex-direction: column; gap: 2px; text-align: center; font-size: 10px; color: var(--muted); }
.mp-card .zcard { min-height: 0; }
.mp-atk { padding: 4px 6px; border-radius: 6px; background: rgba(255,255,255,.04); margin-bottom: 4px; }
.mp-atk.ok { box-shadow: inset 0 0 0 1px var(--good); }
.mp-atk .cost .e { font-size: 9px; }
.mp-dmg { font-weight: 700; }
.mp-ok { color: var(--good); font-size: 11px; }
.mp-notes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.mp-note { background: rgba(255,255,255,.08); border-radius: 4px; padding: 0 6px; }

/* 對戰紀錄裡的隱藏資訊（顯示對手手牌時才看得到） */
#log .secret { color: #e8c170; }

/* 赤松：能量組合 */
.crispin-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.crispin-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.crispin-pair > div { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); text-align: center; }
#crispinReset { width: 100%; margin: 6px 0; }

/* 牌組抽籤結果 */
.draw-list { margin: 8px 0 4px; padding: 0; list-style: none; }
.draw-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; margin-bottom: 6px; border-radius: 8px; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.07); min-height: 34px; }
.draw-no { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: rgba(255,255,255,.1); font-size: 12px; flex: none; }
.draw-item b { font-size: 15px; }
.draw-item.rolling .draw-name { opacity: .45; filter: blur(.6px); transform: translateY(-1px); }
.draw-item.done { background: rgba(255,214,102,.1); border-color: rgba(255,214,102,.35); }
.draw-item.done .draw-no { background: #ffd666; color: #1b1d22; font-weight: 700; }
.draw-item.hit { animation: drawHit .45s ease-out; }
@keyframes drawHit {
  0% { transform: scale(.96); box-shadow: 0 0 0 0 rgba(255,214,102,.55); }
  40% { transform: scale(1.03); box-shadow: 0 0 0 7px rgba(255,214,102,0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,214,102,0); }
}

/* 抽籤清單編輯 */
.draw-edit { max-height: 48vh; overflow: auto; margin-top: 6px; }
.draw-sec { margin-bottom: 12px; }
.draw-sec-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.draw-opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 3px 10px; }
.draw-opt { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 6px; cursor: pointer; }
.draw-opt:hover { background: rgba(255,255,255,.05); }
.draw-opt input { margin: 0; }
button.mini { padding: 2px 8px; font-size: 12px; }
button.mini.del { margin-left: auto; opacity: .6; }

/* 抽籤卡圖 */
.draw-item { min-height: 76px; }
.draw-img { width: 54px; height: 75px; object-fit: cover; border-radius: 4px; flex: none; background: rgba(255,255,255,.06); }
.draw-img.none { display: inline-flex; align-items: center; justify-content: center; color: #888; font-size: 20px; }
.draw-item.rolling .draw-img { opacity: .5; filter: blur(1px); }
.draw-item.done .draw-img { box-shadow: 0 0 0 2px rgba(255,214,102,.5); }
.opt-img { width: 26px; height: 36px; object-fit: cover; border-radius: 3px; flex: none; }
.opt-img.none { background: rgba(255,255,255,.06); display: inline-block; }
.draw-opt { align-items: center; }

/* 卡表分類與「只顯示卡圖」模式 */
.deckgroup { margin: 18px 0 6px; font-size: 16px; opacity: .85; }
.chk { display: inline-flex; align-items: center; gap: 6px; }
#cardList.img-only .cardgrid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; }
#cardList.img-only .cardinfo { padding: 4px; border-top-width: 3px; display: block; position: relative; }
#cardList.img-only .cardinfo > div > *:not(.cnt) { display: none; }
#cardList.img-only .cardinfo .list-img { width: 100%; }
#cardList.img-only .cardinfo .cnt { position: absolute; right: 6px; bottom: 4px; float: none; background: rgba(0,0,0,.72); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 13px; }
#cardList.img-only .cardinfo:not(.with-img) { min-height: 120px; }
#cardList.img-only .cardinfo:not(.with-img) > div > b { display: block; font-size: 11px; }

/* Tier 表圖片 */
.deckgroup small { font-weight: 400; opacity: .75; font-size: 13px; }
.tierbox { padding: 10px; }
.tier-img { display: block; width: 100%; max-width: 760px; margin: 8px auto 0; border-radius: 8px; }

/* ───────── 安裝到手機（PWA） ───────── */
.install-btn { background: var(--accent); color: #1a1a1a; border-color: #d9ab00; font-weight: 700; padding: 5px 12px; }
.install-btn:hover:not(:disabled) { background: #ffd83d; }
.install-tip { margin: 0; padding: 10px 18px; background: var(--felt2); border-bottom: 1px solid var(--line); color: var(--ink); line-height: 1.7; }
.install-tip b { color: var(--accent); }
/* model-badge 用 margin-left:auto 把自己推到最右，安裝鈕要排在它後面 */
.topbar .model-badge + .install-btn { margin-left: 0; }

/* 以 App 形式開啟時，避開瀏海與底部的操作列 */
@media (display-mode: standalone) {
  .topbar { padding-top: calc(10px + env(safe-area-inset-top)); padding-left: calc(18px + env(safe-area-inset-left)); padding-right: calc(18px + env(safe-area-inset-right)); }
  main { padding-bottom: calc(14px + env(safe-area-inset-bottom)); padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(16px + env(safe-area-inset-right)); }
  .install-btn { display: none; }
}

/* ═════════ 手機版面 ═════════ */

/* 平板以下：對戰桌改單欄（前面 .table 的兩欄設定寫在斷點之後，這裡要再蓋一次） */
@media (max-width: 1000px) {
  .table { grid-template-columns: minmax(0, 1fr); }
}

/* 手機直立：約 560px 以下 */
@media (max-width: 560px) {
  /* ── 整體 ── */
  body { font-size: 15px; -webkit-text-size-adjust: 100%; }
  main { padding: 8px 10px; }
  * { -webkit-tap-highlight-color: rgba(255, 203, 5, .25); }
  /* 觸控沒有真正的 hover，浮起效果會黏住，一律關掉 */
  .mon:hover, .card:hover, .hand .card:hover { transform: none; }

  /* ── 上方標題列：縮一行，分頁可橫向滑動 ── */
  .topbar { gap: 8px; padding: 8px 12px; flex-wrap: nowrap; overflow: hidden; }
  .brand { font-size: 14px; flex: none; }
  .brand .ball { width: 15px; height: 15px; }
  .tabs { flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: none; padding: 6px 10px; }
  .model-badge { display: none; }
  .install-btn { flex: none; padding: 6px 10px; font-size: 13px; }
  .install-tip { padding: 10px 12px; font-size: 13px; }

  /* ── 大廳 ── */
  .lobby { margin: 12px auto; padding: 16px 14px; border-radius: 14px; }
  .lobby-grid { grid-template-columns: 1fr; gap: 10px; }
  h1 { font-size: 19px; }
  .hint-text { font-size: 12px; }
  /* 按鈕排成一列並拉大，方便用手指按 */
  .btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
  button.big { flex: 1 1 140px; padding: 14px 16px; font-size: 16px; }

  /* ── 對戰桌：上下排列、可捲動 ── */
  .table { gap: 10px; }
  .board { padding: 6px; gap: 6px; border-radius: 12px; }
  .infobar { font-size: 11px; gap: 3px 8px; }
  .infobar .who { font-size: 13px; }

  /* 戰鬥場與備戰區：備戰區一排最多 3 隻，放不下自動換行 */
  .fieldrow { gap: 6px; }
  .bench-part { gap: 4px; }
  .bench-part .mon, .bench-part .slot-empty { flex: 0 0 auto; width: 84px; height: 112px; }
  .active-slot .mon.active, .active-slot .active-empty { width: 124px; height: 168px; }
  .mon { padding: 3px 5px; }
  .mon .mon-name { font-size: 11px; }
  .mon .e { width: 12px; height: 12px; font-size: 7px; }
  .mon .atk { font-size: 9px; }

  /* 手牌：改成橫向滑動的一條，不重疊才點得準 */
  .hand { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; overflow-y: visible; gap: 5px; padding: 4px 2px 8px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .hand::-webkit-scrollbar { display: none; }
  .hand.overlap .card + .card { margin-left: 0; }
  .side.me .hand { height: auto; }
  .side.me .hand .card { height: 118px; width: 84px; }
  .side.opp .hand { height: auto; }
  .side.opp .hand .card { height: 62px; width: 44px; }
  .side.opp .hand .card.back { height: 46px; width: 33px; }

  /* 競技場移到中線下方置中 */
  .midline .stadium-zone { --stadium-h: 110px; }

  /* ── 右側面板（在手機上變成下方區塊） ── */
  .panel { gap: 8px; }
  .panel-controls button { padding: 9px 12px; }
  /* 可選動作：加大點擊區域，太多時在框內捲動 */
  .actlist { max-height: 46vh; }
  .actlist button { padding: 10px 11px; font-size: 14px; min-height: 42px; }
  #actionsBox { min-height: 0; }
  .logbox #log { max-height: 200px; }
  .detail-img { width: 64px; max-width: 64px; }

  /* ── 彈出視窗：幾乎滿版 ── */
  .modal { padding: 10px; align-items: flex-end; }
  .modal-inner { padding: 16px 14px; max-width: none; border-radius: 16px; max-height: 88vh; overflow-y: auto; }
  .modal-inner h2 { font-size: 19px; }
  .draw-edit { max-height: 44vh; }
  .draw-opts { grid-template-columns: 1fr; }
  .draw-item { gap: 8px; padding: 6px 8px; }
  .draw-img { width: 46px; height: 64px; }

  /* ── 卡表：一行兩張卡圖 ── */
  .cardgrid { grid-template-columns: 1fr; gap: 6px; }
  .cardinfo { font-size: 12px; }
  .cardinfo.with-img { grid-template-columns: 80px 1fr; gap: 8px; }
  .cardinfo .list-img { width: 80px; }
  #cardList.img-only .cardgrid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 5px; }
  .deckgroup { font-size: 15px; margin: 14px 0 6px; }
  .tier-img { max-width: 100%; }
  textarea { font-size: 12px; }
}
/* ───────── 手機對戰：戰鬥場固定全畫面，其餘功能收在底部兩顆按鈕 ───────── */
.mobile-bar, .sheet-close { display: none; }

@media (max-width: 560px) {
  /* ── 戰鬥場固定滿版，整頁不捲動 ── */
  body.in-battle { overflow: hidden; height: 100vh; height: 100dvh; }
  body.in-battle .topbar { display: none; }
  body.in-battle main { height: 100vh; height: 100dvh; overflow: hidden; padding: 0; }
  body.in-battle #tab-play.on { height: 100%; }
  body.in-battle .table { height: 100%; grid-template-columns: 1fr; grid-template-rows: 1fr; gap: 0; }
  body.in-battle .board {
    height: 100%; min-height: 0; overflow-y: auto; overscroll-behavior: contain; border: none; border-radius: 0;
    padding: calc(4px + env(safe-area-inset-top)) 6px calc(50px + env(safe-area-inset-bottom));
    justify-content: space-between;
  }
  /* 卡片依畫面高度縮放，不同手機都剛好塞滿 */
  body.in-battle .bench-part .mon { width: calc(10dvh * 0.73); height: 10dvh; min-width: 50px; }
  body.in-battle .active-slot .mon.active { width: calc(16dvh * 0.74); height: 16dvh; min-width: 86px; }
  body.in-battle .side.me .hand .card { height: 12.5dvh; width: calc(12.5dvh * 0.72); }
  body.in-battle .side.opp .hand .card { height: 6dvh; width: calc(6dvh * 0.72); }
  body.in-battle .side.opp .hand .card.back { height: 4.5dvh; width: calc(4.5dvh * 0.72); }
  body.in-battle .midline .stadium-zone { --stadium-h: 7dvh; }

  /* ── 底部工具列：狀態 ＋ 動作 ＋ 其餘功能 ── */
  body.in-battle .mobile-bar {
    display: flex; align-items: center; gap: 8px; z-index: 32; /* 要蓋在抽屜之上，隨時能切換／關閉 */
    position: fixed; left: 0; right: 0; bottom: 0;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
    background: #0a111d; border-top: 1px solid var(--line);
  }
  .mobile-bar .mb-status { flex: 1 1 auto; min-width: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-bar button { flex: none; padding: 8px 14px; font-size: 14px; }

  /* ── 抽屜：平常整個面板收起來，按按鈕才從下方滑出 ── */
  body.in-battle .panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 31;
    height: fit-content; max-height: 55vh; max-height: 55dvh; overflow-y: auto; gap: 8px;
    padding: 10px 10px calc(58px + env(safe-area-inset-bottom));
    background: var(--felt); border-top: 1px solid var(--line); border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, .5);
  }
  body.in-battle:not(.sheet-act):not(.sheet-more) .panel { display: none; }
  body.in-battle .sheet-close { display: block; order: -1; align-self: flex-end; padding: 6px 12px; }

  /* 「▦ 動作」只給提示與動作清單 */
  body.in-battle.sheet-act #controls,
  body.in-battle.sheet-act #planBox,
  body.in-battle.sheet-act #detailBox,
  body.in-battle.sheet-act .logbox { display: none; }

  /* 「⋯」給設定、牌組目標、詳細資訊、對戰紀錄與離開 */
  body.in-battle.sheet-more #promptBox,
  body.in-battle.sheet-more #actionsBox,
  body.in-battle.sheet-more #hintBox { display: none; }

  /* 抽屜裡的區塊照內容高度，不要像桌機那樣撐滿（桌機那邊是用 #id 設的，這裡要同等權重蓋掉） */
  body.in-battle .panel > .box,
  body.in-battle .panel > #promptBox,
  body.in-battle .panel > #actionsBox,
  body.in-battle .panel > #hintBox,
  body.in-battle .panel > #detailBox,
  body.in-battle .panel > .logbox { flex: 0 0 auto; min-height: 0; max-height: none; overflow: visible; }
  .panel-controls button { padding: 9px 12px; }
  .actlist { max-height: none; }
  .actlist button { padding: 10px 11px; font-size: 14px; min-height: 42px; }
  .logbox #log { max-height: 180px; }
  .detail-img { width: 64px; max-width: 64px; }
}

/* 手機橫放（寬但很扁）：寬度夠，所以恢復「備戰左｜戰鬥場｜備戰右」與右側面板，
   但卡片全部縮小，才不會整個盤面高過螢幕 */
@media (max-width: 1000px) and (orientation: landscape) and (max-height: 540px) {
  .table { grid-template-columns: minmax(0, 1fr) 300px; gap: 8px; align-items: start; }
  .fieldrow { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); height: auto; align-items: center; gap: 6px; }
  .bench-part { flex-wrap: nowrap; height: auto; }
  .bench-part.left { justify-content: flex-end !important; }
  .bench-part.right { justify-content: flex-start !important; }
  .bench-part .mon { flex: 0 0 auto; width: 56px; height: 76px; }
  .bench-part .slot-empty, .active-slot .active-empty { display: none; }
  .bench-part .mon .mon-sub, .bench-part .mon .atk, .bench-part .mon .energies { display: none; }
  .active-slot .mon.active { width: 84px; height: 114px; }
  .mon .mon-name, .mon .mon-hp { font-size: 10px; }
  .side.me .hand { height: auto; }
  .side.me .hand .card { height: 76px; width: 54px; }
  .side.opp .hand .card { height: 44px; width: 32px; }
  .side.opp .hand .card.back { height: 32px; width: 24px; }
  .midline { display: block; text-align: center; font-size: 11px; padding: 3px 0; }
  .side-end { position: static; transform: none; display: inline-block; vertical-align: middle; margin-right: 8px; padding: 5px 12px; font-size: 12px; }
  .midline .stadium-zone { --stadium-h: 46px; position: static; transform: none; display: inline-block; vertical-align: middle; margin-left: 8px; }
  .stadium-zone.empty { display: none; }
  /* 橫放時垂直空間更少：對戰中也把上方分頁列收起來（右側面板還在，離開鈕在那裡） */
  body.in-battle .topbar { display: none; }
  .topbar { padding: 4px 12px; }
  .logbox #log { max-height: 120px; }
}

/* 手機微調（接在上面的手機版面之後） */
@media (max-width: 560px) {
  /* 面板順序：先給「可選動作」，牌組目標與紀錄往下移 */
  .panel-controls { order: 0; }
  #promptBox { order: 1; }
  #actionsBox { order: 2; }
  #hintBox { order: 3; }
  #planBox { order: 4; }
  #detailBox { order: 5; }
  .logbox { order: 6; }

  /* 戰場再壓低一點，讓「盤面＋手牌」盡量一頁看完 */
  .bench-part .mon, .bench-part .slot-empty { width: 78px; height: 100px; }
  .active-slot .mon.active, .active-slot .active-empty { width: 112px; height: 150px; }
  .side.me .hand .card { height: 104px; width: 74px; }
  .side.opp .hand .card { height: 56px; width: 40px; }
  .side.opp .hand .card.back { height: 38px; width: 28px; }
  /* 空的備戰位只留一點提示，不要佔掉整格高度 */
  .bench-part .slot-empty { height: 54px; align-self: center; }
  .active-slot .active-empty { height: 90px; width: 68px; }
  .midline .stadium-zone { --stadium-h: 84px; }
  .midline { font-size: 11px; line-height: 1.45; }
}

/* 很窄的手機（≈430px 以下）：標題只留圖示，分頁才放得下 */
@media (max-width: 430px) {
  .brand { font-size: 0; gap: 0; }
  .brand .ball { width: 18px; height: 18px; }
  .topbar { gap: 10px; padding: 8px 10px; }
}

/* 手機：戰鬥場與備戰區排成同一列，盤面才塞得進一個畫面
   （原本是「備戰左／戰鬥場／備戰右」三段各佔一列，光一邊就要 300px） */
@media (max-width: 560px) {
  .board > .side, .board > .midline { flex: 0 0 auto; }
  /* 戰鬥寶可夢自己佔一列並置中，備戰區排在外側那一列
     → 雙方的戰鬥寶可夢都緊貼中線，是畫面上最接近中間的東西 */
  .fieldrow { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 5px; }
  .active-slot { flex: 0 0 100%; display: flex; justify-content: center; }
  .side.opp .active-slot { order: 2; }   /* 對手：備戰在上、戰鬥場在下（靠中線） */
  .side.opp .bench-part.left { order: 0; }
  .side.opp .bench-part.right { order: 1; }
  .side.me .active-slot { order: 0; }    /* 自己：戰鬥場在上（靠中線）、備戰在下 */
  .side.me .bench-part.left { order: 1; }
  .side.me .bench-part.right { order: 2; }
  .bench-part { flex-wrap: wrap; justify-content: center !important; gap: 4px; }
  .bench-part .mon { width: 62px; height: 84px; }
  .bench-part .slot-empty { width: 30px; height: 44px; }
  .active-slot .mon.active { width: 100px; height: 134px; }
  .active-slot .active-empty { width: 62px; height: 84px; }
  .mon .mon-name { font-size: 10px; }
  .mon .mon-hp { font-size: 10px; }
  .bench-part .mon .mon-sub, .bench-part .mon .atk, .bench-part .mon .energies { display: none; }

  /* 競技場改成中線上的小縮圖，不再自己佔一整列
     （中線保持 block，回合說明才不會被拆成好幾段換行） */
  .midline { display: block; text-align: center; }
  .midline .stadium-zone { --stadium-h: 52px; position: static; transform: none; display: inline-block; vertical-align: middle; margin: 0 0 0 8px; }
  .stadium-zone.empty { display: none; }
}

/* 手機盤面收尾：空的備戰位不顯示、結束回合鈕排進中線 */
@media (max-width: 560px) {
  .bench-part .slot-empty, .active-slot .active-empty { display: none; }
  .side-end { position: static; transform: none; display: inline-block; vertical-align: middle; margin: 0 8px 0 0; padding: 7px 14px; font-size: 13px; }
  .midline { padding: 5px 0; }
}

@media (max-width: 560px) {
  #controls .status { font-size: 14px; }
}

/* 手機底部工具列：一定要做選擇時，動作鈕閃爍提醒（不自動彈出清單） */
.mobile-bar button.must { animation: mbPulse 1.1s ease-in-out infinite; }
@keyframes mbPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 203, 5, .7); } 50% { box-shadow: 0 0 0 7px rgba(255, 203, 5, 0); } }

/* 手機：點卡片跳出的動作／資訊面板不能寬過螢幕（mon-panel 原本固定 380px，
   比 375px 的手機還寬，會被推出畫面外），高度也要留位置給底部工具列 */
@media (max-width: 560px) {
  .drop-menu { max-width: calc(100vw - 16px); }
  .drop-menu.mon-panel { width: auto; max-width: calc(100vw - 16px); max-height: calc(100dvh - 120px); }
  .drop-menu button { white-space: normal; word-break: break-word; }
  .mp-cards { grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); }
}

/* ───────── 競技場：放在出這張卡的玩家、自己戰鬥寶可夢旁邊 ───────── */
.fieldrow { position: relative; }
.fieldrow {
  /* 戰鬥寶可夢在這一列正中央，競技場就貼在它右邊 */
  --active-half: calc(var(--active-h) * 0.76 / 2);
}
.fieldrow .stadium-zone {
  --stadium-h: clamp(64px, 12vh, 120px);
  position: absolute; left: calc(50% + var(--active-half) + 8px); right: auto; z-index: 4; margin: 0; transform: none;
  display: block; height: var(--stadium-h); width: calc(var(--stadium-h) * 0.716);
}
/* 對齊各自的戰鬥寶可夢那一列：對手的在下、自己的在上（都貼著中線） */
.side.opp .fieldrow .stadium-zone { bottom: 0; top: auto; }
.side.me .fieldrow .stadium-zone { top: 0; bottom: auto; }
.fieldrow .stadium-owner { display: none; } /* 位置本身就說明了是誰出的 */

/* ───────── 手機對戰：戰鬥場的格子固定大小，不隨場上寶可夢增減而變動 ───────── */
@media (max-width: 560px) {
  body.in-battle {
    --m-active: 16dvh;    /* 戰鬥寶可夢那一列 */
    --m-bench: 10dvh;     /* 備戰區那一列 */
    --m-hand: 12.5dvh;    /* 自己的手牌 */
    --m-opphand: 6dvh;    /* 對手的手牌 */
  }
  body.in-battle .fieldrow { height: calc(var(--m-active) + var(--m-bench) + 5px); align-content: center; }
  body.in-battle .active-slot { height: var(--m-active); align-items: center; }
  body.in-battle .bench-part { height: var(--m-bench); align-items: center; }
  body.in-battle .side.me .hand { height: var(--m-hand); }
  body.in-battle .side.opp .hand, body.in-battle .side.opp .hand.backs { height: var(--m-opphand); }
  body.in-battle .fieldrow { --active-half: calc(var(--m-active) * 0.74 / 2); }
  body.in-battle .fieldrow .stadium-zone { --stadium-h: calc(var(--m-active) * 0.72); left: calc(50% + var(--active-half) + 6px); }
}
