/* A plain night ground keeps both riders legible in every skin and filter. */
#battle-picture:has(#duel-stage:not([hidden])) #battlefield { background:#000 }
#duel-stage {
  position:absolute; z-index:1; inset:0 0 auto; margin-inline:auto; box-sizing:border-box;
  width:min(1040px,92%); max-height:30%; padding-block:clamp(6px,1.1vw,16px);
  display:grid; grid-template-columns:minmax(0,1fr) clamp(47px,11%,112px) minmax(0,1fr);
  align-items:center; gap:clamp(2px,.45vw,8px); overflow:hidden; container-type:inline-size;
  pointer-events:none; color:var(--bright);
}
.duel-fighter {
  position:relative; isolation:isolate; aspect-ratio:var(--duel-bar-ratio);
  --fill:var(--ui-bar-jade);
}
.duel-fighter::before {
  content:""; position:absolute; inset:0; z-index:1;
  background:var(--ui-duel-bar) center / 100% 100% no-repeat;
  image-rendering:var(--skin-rendering);
}
.duel-fighter:last-child { --fill:var(--ui-bar-crimson); --origin:right }
.duel-fighter:last-child::before { transform:scaleX(-1) }
.duel-portrait {
  position:absolute; left:var(--duel-portrait-left); top:var(--duel-portrait-top);
  width:var(--duel-portrait-w); height:var(--duel-portrait-h);
  display:grid; align-content:center; overflow:hidden;
  clip-path:polygon(26% 0,74% 0,100% 26%,100% 74%,74% 100%,26% 100%,0 74%,0 26%);
}
.duel-fighter:last-child .duel-portrait { left:auto; right:var(--duel-portrait-left) }
.duel-portrait .troop-face { width:100%; height:auto; aspect-ratio:4 / 5 }
.duel-fighter-name,.duel-fighter-stats,.duel-health {
  position:absolute; z-index:2; left:var(--duel-channel-left); width:var(--duel-channel-w);
}
.duel-fighter:last-child :is(.duel-fighter-name,.duel-fighter-stats,.duel-health) {
  left:auto; right:var(--duel-channel-left); text-align:right;
}
.duel-fighter-name {
  bottom:calc(100% - var(--duel-channel-top) + .95cqi + 4px);
  color:#ffedbd; line-height:0; white-space:nowrap; text-shadow:0 2px 3px #0a0705;
}
.duel-fighter-name strong { display:inline-block; font:700 clamp(14px,2.6cqi,27px)/1 var(--serif); letter-spacing:.065em }
.duel-fighter-name strong.rom-name { zoom:2; font-size:0; color:transparent; background-repeat:no-repeat; image-rendering:pixelated }
.duel-health { top:var(--duel-channel-top); height:var(--duel-channel-h); overflow:hidden }
.duel-health i {
  position:absolute; inset:0; transform-origin:var(--origin,left);
  background:var(--fill) center / 100% 100% no-repeat; image-rendering:var(--skin-rendering);
}
.duel-health .hp-trail { background-image:var(--ui-bar-gold); filter:brightness(1.4) saturate(.62) }
@media(prefers-reduced-motion:no-preference){.duel-health.taking-damage .hp-trail{transition:transform .62s ease-out .11s}}
.duel-fighter-stats {
  top:calc(var(--duel-channel-top) + var(--duel-channel-h) + 1.4cqi);
  display:flex; align-items:baseline; gap:.42em; white-space:nowrap;
  color:#ffebc5; font:700 clamp(14px,1.15vw,18px)/1.05 var(--body);
  font-variant-numeric:tabular-nums; text-shadow:0 1px 2px #000,0 0 4px #000;
}
.duel-fighter:last-child .duel-fighter-stats { justify-content:flex-end }
.duel-fighter-stats span + span::before { content:"·"; margin-right:.42em; color:#b89053 }
.duel-move { color:#f8cb7e }
.duel-crest { display:grid; justify-items:center; gap:2px; text-align:center; text-shadow:0 1px 3px #100906 }
.duel-crest::before {
  content:""; width:100%; aspect-ratio:3.2;
  background:var(--ui-duel-crest) center / contain no-repeat; image-rendering:var(--skin-rendering);
}
.duel-crest strong {font:700 clamp(16px,2.4cqi,25px)/1 var(--serif);letter-spacing:.09em}
.duel-crest span {font:600 clamp(10px,1.3cqi,13px)/1.1 var(--body);color:#edddbb}
@container (max-width:650px) {
  .duel-fighter-name strong { font:650 clamp(13px,3cqi,19px)/1 var(--body) }
  .duel-fighter-name strong.rom-name { zoom:1 }
  .duel-fighter-stats { gap:.24em }
  .duel-fighter-stats span + span::before { margin-right:.24em }
}
@container (max-width:470px) {
  .duel-fighter-stats { top:calc(var(--duel-channel-top) + var(--duel-channel-h) + 1px); flex-wrap:wrap; align-content:start; gap:0 3px }
  .duel-fighter-stats .duel-move { flex-basis:100% }
  .duel-fighter-stats .duel-move::before { content:none }
}
@media (max-width:520px) {
  #duel-stage { padding-block:3px 21px }
}
#duel-pad:not([hidden]) {
  --duel-card:clamp(46px,4.1vw,72px);
  flex:0 1 auto; min-width:0; justify-content:flex-start; gap:8px;
  padding:4px 6px; background:var(--ui-panel) center / 160px repeat var(--deck);
  border:6px solid var(--brass); border-image:var(--ui-frame) var(--frame-slice) / 6px round;
}
#battle-dock[data-duel=true]:has(#duel-pad:not([hidden])) {justify-content:center;gap:6px}
#duel-pad .duel-keys {gap:4px}
#duel-pad .duel-keys strong {color:var(--gold);writing-mode:vertical-rl;letter-spacing:.12em}
#duel-pad .duel-keys button,.practice-actions .duel-keys button {
  border:4px solid var(--brass); border-image:var(--ui-socket) var(--socket-slice) / 4px round;
  background:var(--ui-panel) center / 100px repeat var(--deck);text-shadow:0 1px 2px #000;
}
:is(#duel-pad,.practice-actions) .duel-keys button:is(:enabled:hover,[aria-pressed=true]){
  border-image-source:var(--ui-socket-active);color:var(--bright);
}
#duel-pad .duel-keys button {
  position:relative;isolation:isolate;overflow:hidden;box-sizing:border-box;flex:none;
  width:var(--duel-card);height:var(--duel-card);aspect-ratio:1;
  display:inline-flex;justify-content:center;align-items:flex-end;padding:1px 2px;
  color:#fff1d3;font:600 12px/1.15 var(--body);
}
#duel-pad .duel-keys button::before {position:absolute;z-index:-2;inset:0;width:auto;height:auto;aspect-ratio:1;border:0}
#duel-pad .duel-keys button::after {
  content:"";position:absolute;z-index:-1;inset:auto 0 0;height:1.38em;
  background:var(--ui-panel) center / 96px repeat #1c1610;opacity:.93;box-shadow:0 -1px #d8b77878;
}
#duel-pad .duel-keys kbd {
  position:absolute;top:1px;right:1px;padding:0 3px;margin:0;
  color:var(--bright);background:#100d0ee0;border:1px solid var(--brass);line-height:1.1;
}
.practice-actions .duel-keys button {display:inline-flex;align-items:center;gap:4px;padding:2px 5px}
.practice-actions .duel-keys [data-choice]::before {
  content:"";width:22px;height:22px;flex:none;background-image:var(--ui-icons);background-size:600% 600%;
  background-position:calc(var(--ix)*20%) calc(var(--iy)*20%);image-rendering:var(--skin-rendering);
}
@media(max-width:580px){
  #duel-pad:not([hidden]){--duel-card:clamp(36px,10.3vw,48px);gap:3px;justify-content:center}
  #duel-pad .duel-keys{gap:3px}
}

#duel-console { display:contents }
#duel-console .duel-wing, #duel-console .duel-divider { display:none }
#battle-dock:has(#duel-console[data-layout]) {
  display:grid; grid-template-columns:minmax(0,1fr); justify-items:center; align-items:center;
  padding:8px clamp(6px,1.5vw,24px);
}
#battle-dock:has(#duel-console[data-layout]) :is(.command-frame,#dock-left) { display:none }
#duel-console[data-layout] {
  --duel-card:clamp(54px,4.4vw,80px);
  --order-type:clamp(16px,1.2vw,22px);
  --hint-type:clamp(14px,.9vw,18px);
  --crest-width:clamp(90px,8vw,160px);
  width:min(100%,1640px); min-width:0; display:grid;
  grid-template-columns:minmax(0,1fr) auto minmax(0,1fr); align-items:center;
  column-gap:clamp(5px,1.25vw,28px);
}
#duel-console[data-layout] .duel-wing {
  display:flex; gap:clamp(4px,1vw,18px); align-items:center; justify-content:flex-end;
  grid-column:1; grid-row:1; min-width:0;
}
#duel-console[data-layout] .duel-wing[data-side=right] { flex-direction:row-reverse; grid-column:3 }
.duel-medallion { flex:none; display:grid; justify-items:center; gap:3px; color:#ffe1a7 }
.duel-medallion strong { font:700 clamp(21px,1.55vw,30px)/1.15 var(--serif); letter-spacing:.04em; white-space:nowrap }
.duel-medallion-frame {
  width:clamp(50px,4.5vw,80px); aspect-ratio:4 / 5; box-sizing:border-box;
  display:grid;
}
.duel-medallion-frame .troop-face { width:100%; height:100%; background-repeat:no-repeat }
.duel-plaque {
  flex:none; display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:5px 12px; margin:0;
  width:clamp(198px,16vw,272px); box-sizing:border-box;
  border:10px solid transparent;
  border-image:var(--ui-stat-plaque) var(--stat-plaque-slice) fill / 10px stretch;
  padding:4px 7px; font:700 clamp(26px,1.9vw,36px)/1.15 var(--body); font-variant-numeric:tabular-nums;
}
.duel-plaque div { display:flex; gap:4px; align-items:baseline; justify-content:space-between }
.duel-plaque dt { font-size:.78em; color:#f0d49a } .duel-plaque dd { color:#fff4df; margin:0 }
#duel-console[data-layout] #duel-pad:not([hidden]) {
  --duel-card:inherit; grid-column:2; grid-row:1; display:grid; justify-items:center; gap:6px;
}
#duel-console[data-layout] #duel-pad .duel-keys { justify-content:center }
#duel-console[data-layout] #duel-pad .duel-keys strong { display:none }
#duel-console[data-layout] .duel-keys { position:relative; padding-bottom:calc(var(--hint-type) * 1.35) }
#duel-console[data-layout] .duel-keys small {
  position:absolute; inset:auto 0 0; color:#e4d4ba; font:600 var(--hint-type)/1.35 var(--body); text-align:center;
  overflow:hidden; white-space:nowrap; text-overflow:ellipsis;
}
@media (min-width:1150px) {
  #battle-dock:has(#duel-console[data-layout]) { box-sizing:border-box; height:186px; min-height:186px }
}
#duel-console[data-layout] :is(#duel-pad > button,.practice-actions > button,.practice-actions select,.practice-actions label) {
  font:700 var(--order-type)/1.2 var(--body); color:#fff0d2;
}
#duel-console[data-layout] :is(#duel-pad > button,.practice-actions > button,.practice-actions select) { min-height:2em; padding:2px 9px }
#duel-console[data-layout] .practice-escape { min-inline-size:calc(3em + 24px) }
#duel-console[data-layout] .duel-keys button { font:700 var(--order-type)/1.15 var(--body); color:#fff4df; white-space:nowrap }
#duel-console[data-layout] kbd { font:700 var(--hint-type)/1.1 var(--body); color:#ffe9bf }
#duel-console[data-layout] #duel-pad > button::before { content:none }
body.practicing #duel-console[data-layout=practice] #practice-orders {
  --hand-width:max(calc(3 * var(--duel-card) + 8px),calc(10.5 * var(--order-type) + 20px));
  grid-column:2; grid-row:1; display:grid;
  grid-template-columns:var(--hand-width) auto var(--hand-width); align-items:center; gap:clamp(3px,1vw,16px);
}
#duel-console[data-layout] :is(#practice-orders .duel-divider,.duel-spectator-divider) {
  display:grid; place-items:center; gap:7px; color:#ffdf96;
  font:700 clamp(24px,1.9vw,36px)/1.15 var(--serif); letter-spacing:.08em; white-space:nowrap;
  text-shadow:0 2px 3px #100906;
}
#duel-console[data-layout] .duel-spectator-divider { grid-column:2; grid-row:1 }
#duel-console:has(#duel-pad:not([hidden]),#practice-orders:not([hidden])) .duel-spectator-divider { display:none }
#duel-console[data-layout] .duel-divider::before {
  content:""; width:var(--crest-width); aspect-ratio:3.2;
  background:var(--ui-duel-crest) center / contain no-repeat; image-rendering:var(--skin-rendering);
}
#duel-console[data-layout] #practice-orders fieldset {
  padding:0; border:0; background:none; text-align:center;
}
#duel-console[data-layout] #practice-orders legend { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%) }
#duel-console[data-layout] .practice-actions {
  display:flex; justify-content:center; gap:4px;
}
#duel-console[data-layout] .practice-actions > div { flex-basis:100% }
#duel-console[data-layout] .practice-actions .duel-keys { flex-wrap:wrap; justify-content:center; gap:3px }
#duel-console[data-layout] .practice-actions .duel-keys button {
  position:relative; isolation:isolate; overflow:hidden; justify-content:center; align-items:flex-end;
  width:var(--duel-card); height:var(--duel-card); aspect-ratio:1; padding:0;
}
#duel-console[data-layout] .practice-actions .duel-keys [data-choice]::before {
  position:absolute; inset:0; z-index:-2; width:auto; height:auto;
}
#duel-console[data-layout] .practice-actions .duel-keys button::after {
  content:""; position:absolute; inset:auto 0 0; z-index:-1; height:1.3em; opacity:.93;
  background:var(--deck) var(--ui-panel) center / 96px;
}
#duel-console[data-layout] .practice-actions kbd {
  position:absolute; right:0; top:0; padding:0 2px; background:#13100de8; line-height:1.2;
}
@media (max-width:1149px) {
  #duel-console[data-layout] {
    --duel-card:clamp(44px,6.5vw,60px);
    --order-type:clamp(16px,2vw,20px);
    grid-template-columns:minmax(0,1fr) auto minmax(0,1fr); gap:4px 8px;
  }
  #duel-console[data-layout] #duel-pad:not([hidden]), body.practicing #duel-console[data-layout=practice] #practice-orders {
    grid-column:1/-1; grid-row:2; justify-self:center;
  }
  .duel-medallion-frame { width:42px }
  .duel-plaque { width:clamp(170px,21vw,220px); border-width:7px; border-image-width:7px; padding:2px 4px; gap:3px 8px }
}
@media (max-width:580px) {
  #duel-console[data-layout] { grid-template-columns:repeat(2,minmax(0,1fr)); gap:4px; --crest-width:80px }
  #duel-console[data-layout] .duel-wing { flex-direction:column; gap:3px; align-items:stretch }
  #duel-console[data-layout] .duel-wing[data-side=right] { grid-column:2; flex-direction:column }
  .duel-medallion { display:flex; justify-content:center; align-items:center; gap:6px }
  .duel-wing[data-side=right] .duel-medallion { flex-direction:row-reverse }
  .duel-medallion-frame { width:32px }
  .duel-plaque { width:100%; max-width:220px; margin-inline:auto; font-size:24px }
  body.practicing #duel-console[data-layout=practice] #practice-orders {
    width:100%; grid-template-columns:repeat(2,minmax(0,1fr)); gap:3px 5px;
  }
  #duel-console[data-layout] #practice-orders .duel-divider, #duel-console[data-layout] .duel-spectator-divider {
    grid-column:1/-1; grid-row:1; display:flex; justify-content:center; gap:8px;
  }
  #duel-console[data-layout] .duel-spectator-divider { grid-row:2 }
  #duel-console[data-layout] #practice-orders fieldset { grid-row:2 }
  #duel-console[data-layout] .practice-actions { margin-inline:auto }
  #duel-console[data-layout] .practice-actions :is(select,button) { padding-inline:3px }
  #duel-console[data-layout] .practice-escape { min-inline-size:calc(3em + 12px) }
}
@media (max-width:580px) and (orientation:portrait) {
  body.practicing:not(.battle-fullscreen):has(#duel-console[data-layout=practice]) #screen { min-height:min(40dvh,62.5vw) }
}
