/* Portrait combat uses the whole stage; its HUD floats above the world. */
.is-online-battle #online-root { --battle-hand-height:118px; --battle-rail:44px; --battle-gap:8px; --battle-controls-height:164px; }
.is-online-battle #online-content { padding:0; }
.battle-game { background:#173f55; }
.battle-game .battle-playfield { flex:1; min-height:0; }
.battle-game .battle-game-hud {
  position:absolute; inset:0 0 auto; z-index:10; min-height:0;
  padding:calc(12px + env(safe-area-inset-top)) 10px 12px; gap:7px;
  border:0; box-shadow:none;
  background:linear-gradient(#081d32b8,#081d3266 70%,transparent);
  pointer-events:none;
}
.battle-game-hud .battle-rival { align-items:flex-start; gap:7px; }
.battle-game-hud .battle-rival-badge { width:34px; height:40px; filter:drop-shadow(0 3px #08203e); }
.battle-game-hud .battle-rival strong {
  font:400 clamp(17px,4.8vw,22px)/1.15 var(--game-type); max-width:200px;
  color:#ffe6ae; -webkit-text-stroke:.8px #191c32; paint-order:stroke fill;
  text-shadow:0 2px #091c32;
}
.battle-game-hud .battle-rival small { font-size:12px; font-weight:800; letter-spacing:.2px; color:#f3f3de; text-shadow:0 2px #092640; }
.battle-game #battle-clock {
  min-width:67px; min-height:48px; padding:12px 4px 3px; border:2px solid #091b31;
  border-radius:8px; background:#092139c9; font-size:31px; position:relative;
  box-shadow:inset 0 1px #7eb0c666;
}
.battle-game #battle-clock:before { content:'TIME LEFT'; position:absolute; top:3px; left:0; right:0; font:800 8px/1 'DM Sans',sans-serif; letter-spacing:.6px; color:#e7dfb8; }
.battle-game .battle-menu-button { pointer-events:auto; min-width:44px; min-height:48px; border:2px solid #092d4c; font-size:24px; background:linear-gradient(#318ac6,#155784); }
.battle-game .battle-crown-line {
  position:absolute; top:40%; right:max(7px,env(safe-area-inset-right)); z-index:9;
  transform:translateY(-50%); flex-direction:column-reverse;
  height:auto; width:44px; padding:5px; gap:7px; border:1px solid #91c0cc80;
  border-radius:8px; background:#0a2b45d9; line-height:1.2;
  pointer-events:none; box-shadow:0 2px #102b40;
}
.battle-game .battle-crown-line>span { display:flex; flex-direction:column; align-items:center; gap:2px; font-size:10px; line-height:1.2; }
.battle-game .battle-crown-line>span:last-child { flex-direction:column-reverse; }
.battle-game .battle-crown-line strong { margin:0; font-size:22px; line-height:1; }
.battle-game .battle-crown-line>span[aria-hidden=true] { display:none; }
.battle-game .battle-connection { top:calc(121px + env(safe-area-inset-top)); left:12px; right:12px; padding:9px 11px; font-size:13px; font-weight:650; }
.battle-game .battle-connection-actions { top:calc(173px + env(safe-area-inset-top)); }
.battle-game .battle-connection-actions button { min-height:48px; font-size:14px; }
.battle-game .battle-countdown { font-size:clamp(76px,23vw,110px); -webkit-text-stroke:3px #6b411b; text-shadow:0 5px #102849; }
.battle-game .battle-controls {
  display:grid; grid-template-columns:var(--battle-rail) minmax(0,1fr); grid-template-rows:var(--battle-hand-height) 24px;
  column-gap:8px; row-gap:10px; padding:10px 9px calc(9px + env(safe-area-inset-bottom));
  border-top:3px solid #44c5f2; background:linear-gradient(#177ab6,#115288 75%,#0c396c);
  box-shadow:inset 0 2px #9bdef8,0 -3px #082d50,0 -8px 20px #102b4055;
}
.battle-controls .battle-next { grid-column:1; grid-row:1 / 3; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:7px; min-width:0; margin:0; color:#fff6d1; text-shadow:0 2px #082340; }
.battle-next-label { font:400 15px/1.1 var(--game-type); }
.battle-next-art { display:block; width:43px; height:61px; position:relative; border:2px solid #ffdf70; border-radius:6px; background:linear-gradient(#477eaf,#142c60); box-shadow:0 3px #08274b; }
.battle-next-art img { width:100%; height:100%; object-fit:cover; border-radius:3px; }
.battle-next-art b { position:absolute; bottom:-9px; left:50%; transform:translateX(-50%); display:grid; place-items:center; width:23px; height:25px; background:linear-gradient(#dd8eea,#9947c6); border:1px solid #f3d3ff; border-radius:50%; font:400 17px/1 var(--game-type); }
.battle-cycle-art { width:43px; height:56px; display:grid; place-items:center; filter:drop-shadow(0 3px #08274b); }
.battle-cycle-art .icon { width:43px; height:56px; }
.battle-next>small { font-size:11px; font-weight:800; white-space:nowrap; }
.battle-controls .hand { grid-column:2; grid-row:1; gap:var(--battle-gap); align-self:end; }
.battle-controls .battle-hand-card {
  height:var(--battle-hand-height); min-height:0; border:3px solid #d6e5ed; border-radius:9px;
  background:radial-gradient(ellipse at 45% 15%,color-mix(in srgb,var(--ally-glow) 65%,#eaf6ff),#245d94 63%,#12366c);
  box-shadow:inset 0 0 0 2px #365e88,inset 0 3px #ffffffaa,0 4px #092749,0 5px 4px #061d4180;
  overflow:visible; touch-action:manipulation;
}
.battle-controls .battle-hand-card .hand-portrait { z-index:0; inset:0 0 24px; border-radius:5px; }
.battle-controls .hand-portrait img { object-fit:cover; object-position:center 28%; transform:scale(1.08); filter:drop-shadow(0 3px 2px #0b254377); }
.battle-controls .hand-portrait img.monster-face-art { object-position:center 36%;transform:scale(1.04); }
.battle-next-art img.monster-face-art { object-position:center 36%; }
.battle-controls .battle-hand-card>strong {
  position:absolute; z-index:1; left:0; right:0; bottom:17px; min-height:26px; padding:3px 2px;
  font:400 12px/1.05 var(--game-type); text-wrap:balance;
  background:linear-gradient(#103d6880,#082b53ed); color:#fff6dc; text-shadow:0 2px #10203e;
  -webkit-text-stroke:.35px #14213a; paint-order:stroke fill; border-radius:0;
}
.battle-controls .battle-hand-card .hand-energy {
  top:auto; bottom:-8px; left:50%; transform:translateX(-50%); width:31px; height:34px;
  border:2px solid #ffc5fb; border-radius:50%; font-size:26px;
  background:linear-gradient(#edb1ff,#b44be3 70%,#842fc0); box-shadow:inset 0 2px #ffe1ff,0 3px #452070;
}
.battle-controls .hand-shortcut { display:none; }
.battle-controls .battle-hand-card.selected { transform:translateY(-7px); border-color:#ffe277; box-shadow:inset 0 0 0 2px #b77825,inset 0 3px #fff3ae,0 4px #896321,0 0 15px #ffdf6faa; }
.battle-controls .battle-hand-card.needs-energy .hand-portrait { filter:grayscale(1); opacity:.78; }
.battle-controls .battle-hand-card.needs-energy .hand-energy { background:linear-gradient(#b9a4c9,#78648c); border-color:#d2c4dc; }
.battle-controls .battle-hand-card.deployment-pending:after { top:33px; font-size:11px; padding:5px 1px; }
.battle-controls .battle-energy-line { grid-column:2; grid-row:2; position:relative; gap:5px; margin:0; min-height:24px; }
.battle-controls .battle-energy-line>span { position:absolute; z-index:2; left:-10px; top:-4px; width:34px; height:34px; display:grid; place-items:center; border-radius:55% 55% 60% 40%; background:linear-gradient(#f49aff,#b934df); border:2px solid #fbd3ff; box-shadow:0 2px #4a206e; font-size:23px; color:#ffebff; }
.battle-controls .battle-energy-line>strong { position:absolute; z-index:3; left:30px; top:3px; min-width:38px; color:#fff7ff; font:400 18px/1 var(--game-type); text-shadow:0 2px #511872; }
.battle-controls .battle-energy-track { width:100%; height:22px; border:2px solid #092d59; border-radius:6px; box-shadow:inset 0 2px #09264d,0 1px #6eb6db; }
.battle-controls .battle-energy-track>i { background:repeating-linear-gradient(90deg,transparent 0 calc(10% - 1px),#852dba 10%),linear-gradient(#e8a8ff,#bd59e8); box-shadow:inset 0 3px #f7cbff; }
.battle-controls .battle-energy-line>small { flex:none; min-width:0; font:400 17px/1 var(--game-type); }
.battle-controls .battle-energy-line>small:empty { display:none; }
.battle-controls .battle-lane-actions {
  position:absolute; left:10px; right:10px; bottom:calc(100% + 13px); margin:0; gap:10px;
  pointer-events:none;
}
.battle-controls .battle-lane-actions button { pointer-events:auto; min-width:68px; width:72px; min-height:52px!important; height:auto; flex:none; font:800 11px/1.15 'DM Sans',sans-serif!important; padding:4px; display:flex; flex-direction:column; align-items:center; justify-content:center; border:2px solid #8ad7ef; border-radius:13px; background:linear-gradient(#256c96d9,#103b65e6); box-shadow:inset 0 2px #b9e7f366,0 3px #09243d; }
.battle-controls .battle-lane-actions button:first-child:before { content:'↖'; font-size:20px; line-height:1; }
.battle-controls .battle-lane-actions button:last-child:before { content:'↗'; font-size:20px; line-height:1; }
.battle-controls .battle-lane-actions>span { flex:0 1 auto; max-width:210px; padding:5px 10px; border-radius:20px; background:#092c47cc; font-size:12px; color:#fff4cd; line-height:1.3; text-shadow:0 1px #07223b; }
.battle-controls .battle-placement-status { bottom:calc(100% + 73px); left:12px; right:12px; padding:9px 12px; font-size:13px; }
.is-online-battle #online-status { bottom:calc(241px + env(safe-area-inset-bottom)); font-size:13px; }
.battle-game .battle-action-recovery { font-size:13px; max-width:360px; }
.battle-game .battle-action-recovery button { font-size:13px; min-height:48px; }
.is-online-battle .game-battle-dialog h2 { font-size:30px; }
.is-online-battle .game-battle-dialog p,.is-online-battle .game-battle-help { font-size:15px; line-height:1.5; }
.is-online-battle .game-dialog-menu button,.is-online-battle .game-dialog-actions button { min-height:52px; font-size:17px; }
@media(max-width:374px) {
  .is-online-battle #online-root { --battle-hand-height:110px; --battle-rail:38px; --battle-gap:6px; }
  .battle-game .battle-controls { padding-left:7px; padding-right:7px; column-gap:7px; }
  .battle-game-hud .battle-rival strong { max-width:158px; font-size:17px; }
  .battle-game-hud .battle-rival small { font-size:11px; }
  .battle-game #battle-clock { min-width:61px; font-size:29px; }
  .battle-next-art { width:37px; height:54px; }
  .battle-next-label { font-size:14px; }
  .battle-controls .battle-hand-card>strong { font-size:11px; }
}
@media(max-height:440px) and (orientation:landscape) {
  .is-online-battle #online-root { --battle-hand-height:80px; --battle-rail:36px; }
  .battle-game .battle-controls { padding-top:7px; row-gap:8px; padding-bottom:5px; }
  .battle-game .battle-game-hud { padding-top:5px; }
  .battle-controls .battle-hand-card>strong { bottom:12px; font-size:11px; }
  .battle-controls .battle-hand-card .hand-energy { width:27px; height:29px; font-size:22px; }
  .battle-controls .battle-lane-actions { bottom:calc(100% + 7px); }
  .battle-game .battle-connection { top:100px; }
}
/* Short phones reserve a compact HUD band instead of covering tower health. */
@media(max-height:650px) and (orientation:portrait) {
  .is-online-battle #online-root { --battle-hand-height:98px; --battle-controls-height:144px; }
  .battle-game .battle-game-hud { position:relative; flex:none; height:calc(96px + env(safe-area-inset-top)); align-items:flex-start; }
  .battle-game #battle-phase { top:calc(64px + env(safe-area-inset-top)); padding:5px 8px; }
  .battle-game .battle-crown-line { top:calc(62px + env(safe-area-inset-top)); height:30px; }
  .battle-game .battle-connection { top:8px; }
  .battle-game .battle-connection-actions { top:60px; }
}
@media(min-width:600px) and (min-height:600px) {
  .is-online-battle #online-root { --battle-hand-height:154px; --battle-rail:58px; --battle-gap:13px; }
  .battle-game .battle-controls { padding:14px 18px calc(12px + env(safe-area-inset-bottom)); row-gap:14px; }
  .battle-controls .battle-hand-card>strong { font-size:17px; min-height:30px; bottom:23px; }
  .battle-controls .battle-hand-card .hand-energy { width:40px; height:44px; font-size:32px; }
  .battle-next-art { width:55px; height:78px; }
  .battle-next-label { font-size:20px; }
}
@media(prefers-reduced-motion:reduce) {
  .battle-controls .battle-hand-card { transition:none!important; }
}

/* Keep controls clear of camera cut-outs in either orientation. */
.battle-game .battle-game-hud{padding-left:max(10px,env(safe-area-inset-left));padding-right:max(10px,env(safe-area-inset-right))}
.battle-game .battle-controls{padding-left:max(9px,env(safe-area-inset-left));padding-right:max(9px,env(safe-area-inset-right))}
.battle-controls .battle-lane-actions{left:max(10px,env(safe-area-inset-left));right:max(10px,env(safe-area-inset-right))}

/* Battle information stays at the edge, leaving both bridges open to aim. */
.battle-game .battle-crown-line {
  top:calc(78px + env(safe-area-inset-top)); right:max(10px,env(safe-area-inset-right));
  transform:none; flex-direction:row; justify-content:space-evenly;
  width:105px; height:35px; padding:3px 7px; gap:7px;
  border:1px solid #b2d5e099; border-radius:9px;
  background:linear-gradient(105deg,#103e60ed,#0c2946ed);
  box-shadow:inset 0 1px #d4f5ff24,0 3px 8px #06203355;
}
.battle-game .battle-crown-line>span,
.battle-game .battle-crown-line>span:last-child { flex-direction:row; gap:4px; font-size:10px; }
.battle-game .battle-crown-line strong { font-size:23px; color:#9deaff; }
.battle-game .battle-crown-line>span:last-child strong { color:#ffa7a4; }
.battle-game #battle-phase {
  position:absolute; z-index:9; left:max(10px,env(safe-area-inset-left));
  top:calc(80px + env(safe-area-inset-top)); max-width:calc(100% - 136px);
  padding:7px 10px; border:1px solid #a8d7f099; border-radius:8px;
  background:linear-gradient(#174b70e8,#0c304ee8); color:#e5f8ff;
  font:800 12px/1.3 'DM Sans',sans-serif; letter-spacing:.2px;
  text-shadow:0 1px #09243c; pointer-events:none;
}
.battle-game #battle-phase:empty { display:none; }
.battle-game #battle-clock[data-label]:before { content:attr(data-label); }
.battle-game[data-phase="overtime"] #battle-clock,
.battle-game[data-phase="final-seconds"] #battle-clock {
  border-color:#ffbd74; color:#ffe6a6; background:linear-gradient(#732e3ee8,#421f38e8);
  box-shadow:inset 0 1px #ffe7b966,0 0 0 1px #502439,0 3px 8px #061b3455;
}
.battle-game[data-phase="overtime"] #battle-phase,
.battle-game[data-phase="final-seconds"] #battle-phase { border-color:#ffc36d; background:linear-gradient(#8b4333ed,#642c35ed); color:#fff0bc; }
.battle-game[data-phase="double-energy"] #battle-phase { border-color:#edc1ff; background:linear-gradient(#643888ed,#3a2965ed); color:#fbe8ff; }
.battle-game[data-phase="countdown"] #battle-phase { border-color:#ffe18a; color:#ffedac; }
.battle-game .battle-menu-button:focus-visible,
.battle-controls .battle-hand-card:focus-visible,
.battle-controls .battle-lane-actions button:focus-visible { outline:3px solid #fff5b4; outline-offset:4px; }
.battle-game #online-arena:focus-visible { outline:3px solid #ffe589; outline-offset:-4px; }
.battle-controls .battle-energy-track { isolation:isolate; }
.battle-controls .battle-energy-track>#battle-energy-fill { position:relative; z-index:1; }
.battle-controls .battle-energy-track>#battle-energy-reserved {
  position:absolute; z-index:2; top:0; left:0; width:0; height:100%;
  background:repeating-linear-gradient(135deg,#ffdf9e90 0 4px,#a767b160 4px 8px);
  box-shadow:inset 1px 0 #fff0c2aa,inset 0 2px #f8e0ff55;
}
.battle-controls .battle-energy-line>#battle-energy-reservation {
  position:absolute; z-index:4; right:7px; top:5px; min-width:0; margin:0;
  color:#ffe4a8; font:800 10px/1 'DM Sans',sans-serif; text-shadow:0 1px 2px #2e183c;
}
.battle-controls .battle-energy-line>#battle-energy-reservation:empty { display:none; }
.battle-game[data-energy-multiplier="2"] .battle-energy-line>#battle-energy-reservation,
.battle-game[data-energy-multiplier="3"] .battle-energy-line>#battle-energy-reservation { right:34px; }
.battle-controls .battle-energy-line>#battle-energy-multiplier { margin-left:3px; color:#ffe1ff; }
.battle-controls .hand-kind {
  position:absolute; z-index:2; right:3px; top:3px; display:flex; align-items:center; gap:2px;
  padding:3px 4px; border:1px solid #b4e4ff66; border-radius:4px;
  background:#0b3457d9; color:#d3f0ff; font:800 8px/1 'DM Sans',sans-serif;
  text-shadow:0 1px #072540; pointer-events:none;
}
.battle-controls .hand-kind svg { width:12px; height:12px; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
.battle-controls [data-card-kind="spell"] .hand-kind { color:#ffe5a4; border-color:#ffe6a780; background:#503656e6; }
.battle-controls .hand-ready {
  position:absolute; z-index:3; left:3px; right:3px; top:29px; display:none;
  padding:4px 2px; border-radius:4px; color:#fff1c7; background:#123852e8;
  font:800 10px/1.2 'DM Sans',sans-serif; text-shadow:0 1px #08223d; pointer-events:none;
}
.battle-controls .battle-hand-card[data-battle-availability="needs-energy"] .hand-ready,
.battle-controls .battle-hand-card[data-battle-availability="sending"] .hand-ready,
.battle-controls .battle-hand-card[data-battle-availability="unconfirmed"] .hand-ready { display:block; }
.battle-controls .battle-hand-card[data-battle-availability="unconfirmed"] { border-color:#ffbd85; }
.battle-controls .battle-hand-card[data-battle-availability]::after { content:none; }
.battle-controls .battle-hand-card { touch-action:none; user-select:none; -webkit-user-select:none; }
.is-card-dragging .battle-controls .battle-hand-card.selected { cursor:grabbing; }
.battle-controls .battle-lane-actions>span { max-width:238px; font-size:12px; white-space:normal; text-wrap:balance; }
@media(max-width:374px) {
  .battle-controls .hand-kind { gap:1px; padding:2px; font-size:7px; }
  .battle-controls .hand-kind svg { width:10px; height:10px; }
  .battle-controls .hand-ready { font-size:9px; }
  .battle-controls .battle-energy-line>#battle-energy-reservation { font-size:9px; }
  .battle-controls .battle-lane-actions>span { max-width:180px; font-size:11px; }
}
@media(min-width:600px) and (min-height:600px) {
  .battle-controls .hand-kind { font-size:10px; padding:4px 5px; }
  .battle-controls .hand-kind svg { width:15px; height:15px; }
  .battle-controls .hand-ready { top:35px; font-size:12px; padding:5px; }
  .battle-controls .battle-energy-line>#battle-energy-reservation { font-size:11px; }
  .battle-game #battle-phase { font-size:14px; }
}
@media(max-height:440px) and (orientation:landscape) {
  .battle-game .battle-crown-line { top:64px; }
  .battle-game #battle-phase { top:66px; }
  .battle-controls .hand-kind span { display:none; }
  .battle-controls .hand-ready { top:21px; padding:2px; font-size:9px; }
}

/* Keep the confirmed next-card identity visible in the compact rail. */
.battle-controls .battle-next{gap:4px}
.battle-next .battle-next-name{display:block;max-width:100%;margin-top:4px;font:800 10px/1.15 'DM Sans',sans-serif;overflow-wrap:anywhere;text-align:center;color:#fff3c6}
@media(max-height:440px) and (orientation:landscape){
  .battle-controls .battle-next{gap:2px}
  .battle-next-art{width:30px;height:38px}
  .battle-next-art b{width:18px;height:19px;bottom:-5px;font-size:13px}
  .battle-next .battle-next-name{margin-top:3px;font-size:9px}
  .battle-next-label{font-size:11px}
}
/* On-demand battle text remains readable at narrow widths and enlarged text. */
.battle-readable-summary{overflow-wrap:anywhere}
.battle-readable-summary .battle-readable-caption{font-size:12px;line-height:1.5}
.battle-readable-side{margin:12px 0;padding:10px;border:1px solid #84b4d977;border-radius:9px;background:#0c3159}
.battle-readable-side h3{margin:0 0 8px;font-size:20px;color:#fff0b6}
.battle-readable-side h4{margin:10px 0 5px;font-size:14px}
.battle-readable-towers{margin:0}
.battle-readable-towers>div,.battle-readable-side li{display:flex;flex-wrap:wrap;justify-content:space-between;gap:4px 12px;padding:5px 0;font-size:14px;line-height:1.4}
.battle-readable-towers dd{margin:0;font-weight:800;color:#fff0bc;font-variant-numeric:tabular-nums}
.battle-readable-side ul{list-style:none;padding:0;margin:0}
.battle-readable-side li>span{min-width:0;flex:1}
.battle-readable-side li>strong{flex:none;color:#e9f4ff}
