/* Match HUD and read-only deck viewer. Other game screens are untouched. */
.battle-layout .topbar { justify-content: flex-end; z-index: 18; }
.battle-layout .battle-status-strip { display: grid; gap: 6px; min-width: 0; }
.battle-layout .battle-details { min-width: 0; font-size: 12px; }
.battle-layout .battle-details > summary { padding: 10px 0; color: #d7c69e; cursor: pointer; }
.battle-layout .battle-details .hero-target { width: 100%; margin: 6px 0; }
.battle-layout .battle-details .system-status-panel { padding: 10px 0; }
.battle-layout #playerHand .card { opacity: 1; background-color: #101813; }
.battle-layout #playerHand .card.unplayable { opacity: 1; filter: none; }
.battle-layout #playerHand .card-art { background-color: #141a17; }
.sound-preference { margin-top: 16px; }
.sound-preference label { display: flex; justify-content: space-between; align-items: center; min-height: 44px; gap: 20px; }
.sound-preference input { width: 18px; height: 18px; accent-color: #8ca981; }

.battle-layout .deck-pack {
  justify-self: center; align-self: center; position: relative; isolation: isolate;
  display: grid; place-content: center; gap: 7px; width: 110px; height: 152px;
  margin: 8px; padding: 18px 10px; border: 1px solid #c9a768; border-radius: 5px;
  background: #122b22; color: #efdfb7; cursor: pointer;
  box-shadow: inset 0 0 0 4px #14271f, inset 0 0 0 5px #b3935c88, 0 8px 16px #0009;
  transition: transform 180ms, box-shadow 180ms;
}
.battle-layout .deck-dock { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-width: 0; z-index: 1; }
.battle-layout .deck-dock #endTurnButton { flex: 0 0 auto; }
.deck-pack::before, .deck-pack::after { content: ""; position: absolute; inset: 0; z-index: -1; border: 1px solid #977c51; border-radius: 5px; background: #13251c; transform: translate(5px, 4px) rotate(4deg); }
.deck-pack::before { transform: translate(-5px, 2px) rotate(-6deg); }
.deck-pack-back { display: grid; place-items: center; width: 42px; height: 42px; margin: 0 auto 3px; border: 1px solid #ae925d88; transform: rotate(45deg); }
.deck-pack-back > span { width: 26px; height: 26px; transform: rotate(-45deg); }
.deck-pack strong { font: 600 16px "Songti SC", Georgia, serif; }
.deck-pack > span:last-child { font-size: 12px; color: #cdbd97; }
.battle-layout .deck-pack:hover { transform: translateY(-4px); box-shadow: inset 0 0 0 4px #14271f, inset 0 0 0 5px #d3b676, 0 12px 20px #0009; }
.remaining-deck-dialog {
  position: fixed; inset: 0 0 0 auto; margin: 16px; width: min(560px, calc(100vw - 32px));
  max-width: none; height: calc(100dvh - 32px); max-height: none; padding: 0;
  border: 1px solid #ae925d; border-radius: 6px; color: #f0e5d1; background: #101d18;
  box-shadow: -16px 0 70px #0008; overflow: hidden;
}
.remaining-deck-dialog[open] { display: flex; flex-direction: column; animation: deck-drawer-in 180ms ease-out; }
.remaining-deck-dialog::backdrop { background: #02070680; }
.remaining-deck-dialog > header { flex: 0 0 auto; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 20px; border-bottom: 1px solid #b7975d55; }
.remaining-deck-dialog h2 { margin: 0; font: 600 22px "Songti SC", Georgia, serif; }
.remaining-deck-dialog header p { margin: 5px 0 0; color: #c7b794; font-size: 13px; }
.remaining-deck-dialog header button { display: grid; place-items: center; flex: 0 0 36px; width: 36px; height: 36px; padding: 8px; background: transparent; border: 1px solid #ae925d66; color: #eddfc4; border-radius: 4px; cursor: pointer; }
[data-hud-icon] { display: block; }
[data-hud-icon] svg { display: block; width: 100%; height: 100%; }
.remaining-deck-dialog header [data-hud-icon] { width: 18px; height: 18px; }
.remaining-deck-dialog :is(button, summary, [tabindex]):focus-visible { outline: 2px solid #acdbce; outline-offset: -2px; }
.remaining-deck-cards { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-content: start; align-items: start; gap: 20px 14px; padding: 20px; scrollbar-width: thin; scrollbar-color: #9d895f #101d18; }
.remaining-deck-card { min-width: 0; }
.remaining-card-art { position: relative; aspect-ratio: 2 / 3; overflow: hidden; border: 1px solid #8e825f; border-radius: 4px; background: #19271f; box-shadow: 0 4px 8px #0007; }
.remaining-card-art img { width: 100%; height: 100%; display: block; object-fit: cover; object-position: center 18%; }
.remaining-card-placeholder { display: grid; place-items: center; height: 100%; color: #dbc99f; }
.remaining-card-cost, .remaining-card-count { position: absolute; top: 5px; padding: 4px 6px; border: 1px solid #c9a768; border-radius: 3px; background: #15231bf2; color: #fff2d6; font-size: 12px; }
.remaining-card-cost { left: 5px; }
.remaining-card-count { right: 5px; background: #652d37; }
.remaining-card-caption { padding-top: 8px; }
.remaining-deck-card h3 { margin: 0; color: #f4e9d6; font: 600 14px/1.4 "Songti SC", Georgia, serif; overflow-wrap: anywhere; }
.remaining-card-type { margin: 4px 0; font-size: 11px; line-height: 1.5; color: #c8b98f; }
.remaining-card-effect { font-size: 12px; line-height: 1.6; color: #c4d0c8; }
.remaining-card-effect summary { cursor: pointer; }
.remaining-card-effect p { margin: 8px 0 0; overflow-wrap: anywhere; }
.remaining-deck-empty { grid-column: 1 / -1; padding: 60px 0; text-align: center; color: #d3c6ac; }
@keyframes deck-drawer-in { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: translateX(0); } }

/* The salon HUD uses grid contents so controls keep their original bindings. */
.battle-salon .game-shell.battle-layout { gap: 8px 14px; padding: 12px 18px; }
.battle-salon .battle-layout :is(.center-board, .target-zone) { display: contents; }
.battle-salon .battle-layout .topbar { background: none; border: 0; padding: 0; min-height: 32px; }
.battle-salon .battle-layout .battle-status-strip { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; align-items: center; gap: 2px 16px; text-shadow: 0 1px 4px #000; }
.battle-salon .battle-layout .turn-counter { flex-basis: auto; min-height: 28px; font-size: 16px; background: none; border: 0; padding: 0; color: #f1d8a0; }
.battle-salon .battle-layout .battle-status-strip .trait-status { min-height: 0; padding: 0; font-size: 11px; }
.battle-salon .battle-layout #onlineBattleStatus { flex-basis: 100%; text-align: center; justify-content: center; }
.battle-salon .battle-layout .log-panel { display: flex; flex-direction: column; padding: 12px 10px; border: 1px solid #c8a36735; border-radius: 3px; background: #08170c38; overflow: hidden; }
.battle-salon .battle-layout .log-panel h2 { font-size: 13px; margin: 0 0 12px; }
.battle-salon .battle-layout .battle-log { min-height: 0; max-height: none; overflow: auto; font-size: 12px; line-height: 1.65; color: #e2e5d9; text-shadow: 0 1px 3px #000; scrollbar-width: thin; }
.battle-salon .battle-layout .battle-details { align-self: start; max-height: 100%; overflow: auto; border-top: 1px solid #bc9b6244; background: #06100940; padding: 0 10px; scrollbar-width: thin; }
.battle-salon .battle-layout .battle-details:not([open]) { background: none; }
.battle-salon .battle-layout .battle-details summary { color: #dcca9f; }
.battle-salon .battle-layout .battle-emote-area { align-self: center; justify-content: flex-start; min-width: 0; }
.battle-salon .battle-layout .emote-button { width: auto; background: #101c1266; }
.battle-salon .battle-layout .emote-panel { position: absolute; z-index: 15; top: calc(100% + 6px); bottom: auto; left: 0; width: 210px; max-width: calc(100vw - 40px); }
.battle-salon .battle-layout .emote-bubble { position: fixed; top: 75px; bottom: auto; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 40px); z-index: 15; }
.battle-salon .battle-layout #turnNotice { align-self: center; margin: 0; text-align: center; font-size: 12px; color: #e2d7bb; text-shadow: 0 1px 4px #000; }
.battle-salon .battle-layout #turnNotice:not(.is-action-notice) { visibility: hidden; }
.battle-salon .battle-layout .hand-panel { background: none; border: 0; padding: 0; gap: 0; }
.battle-layout .hand-row { --hand-card-height: 210px; align-items: center; }
.battle-layout .hand-row .card,
.battle-salon .battle-layout .hand-row .card,
.battle-layout:has(#mulliganPanel:not(.hidden)) .hand-row .card {
  flex: 0 0 auto; width: calc(var(--hand-card-height) * 2 / 3); height: var(--hand-card-height);
  min-height: 0; max-height: none; aspect-ratio: 2 / 3;
}
.battle-salon .battle-layout .hand-row { padding: 6px 5px; }
.battle-salon .battle-layout .hand-row .card { border: 0; box-shadow: 0 5px 12px #0007; }
.battle-salon .battle-layout .hand-panel:has(#mulliganPanel:not(.hidden)) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(176px, 47%);
  grid-template-rows: minmax(0, 1fr);
}
.battle-salon .battle-layout .hand-panel:has(#mulliganPanel:not(.hidden)) .hand-row {
  grid-area: 1 / 1;
  min-width: 0;
  justify-content: safe center;
}
.battle-salon .battle-layout .mulligan-panel {
  grid-area: 1 / 2;
  align-self: center;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  max-height: 100%;
  padding: 10px;
  gap: 8px;
  text-align: left;
}
.battle-salon .battle-layout .mulligan-panel > div:first-child { display: flex; flex-direction: column; min-height: 0; }
.battle-salon .battle-layout .mulligan-panel strong { flex: 0 0 auto; }
.battle-salon .battle-layout .mulligan-panel p { min-height: 0; overflow: auto; scrollbar-width: thin; }
.battle-salon .battle-layout .mulligan-actions { flex-direction: column; align-items: stretch; gap: 6px; }
.battle-salon .battle-layout .mulligan-actions span { text-align: center; }
.battle-salon .battle-layout #mulliganConfirmButton { width: 100%; min-height: 36px; padding: 6px 8px; font-size: 13px; }
.battle-salon .battle-layout #deckCount { display: none; }
.battle-salon .battle-layout #playerHand .card { opacity: 1; background: #112219; }
.battle-salon .battle-layout #playerHand .card-art { background: #141c17; }

@media (min-width: 1000px) {
  body:not(.battle-salon) .battle-layout .deck-dock { grid-area: info; align-self: end; }
  body:not(.battle-salon) .battle-layout .center-board { padding-bottom: 220px; }
  .battle-salon .game-shell.battle-layout {
    grid-template-columns: 170px minmax(0, 1fr) 176px;
    grid-template-areas: none;
    grid-template-rows: 56px minmax(132px, 1fr) 24px minmax(132px, 1fr) 224px;
  }
  .battle-salon .game-shell.battle-layout:has(#mulliganPanel:not(.hidden)) { grid-template-rows: 56px minmax(132px, 1fr) 24px minmax(132px, 1fr) 224px; }
  .battle-salon .battle-layout > .topbar { grid-area: 1 / 3; align-self: center; }
  .battle-salon .battle-layout .battle-status-strip { grid-area: 1 / 2; }
  .battle-salon .battle-layout .battle-emote-area { grid-area: 1 / 1; }
  .battle-salon .battle-layout .log-panel { grid-area: 2 / 1 / 4 / 2; }
  .battle-salon .battle-layout .battle-details { grid-area: 4 / 1; }
  .battle-salon .battle-layout > .opponent-panel { grid-area: 2 / 2 / 3 / 4; }
  .battle-salon .battle-layout #turnNotice { grid-area: 3 / 2 / 4 / 4; }
  .battle-salon .battle-layout > .player-panel:not(.opponent-panel) { grid-area: 4 / 2 / 5 / 4; }
  .battle-salon .battle-layout > .hand-panel { grid-area: 5 / 1 / 6 / 3; }
  .battle-salon .battle-layout > .deck-dock { grid-area: 5 / 3; }
  .battle-salon .battle-layout .player-panel { grid-template-columns: minmax(0, 1fr) 90px; padding: 4px 0; }
  .battle-salon .battle-layout .opponent-panel { grid-template-columns: 90px minmax(0, 1fr); }
  .battle-salon .battle-layout .hero { min-height: 0; height: min(100%, 154px); padding-top: 9px; }
}
@media (max-width: 999px) {
  .battle-salon .game-shell.battle-layout { grid-template-columns: minmax(0, 1fr); }
  .battle-salon .battle-layout > .topbar { order: 0; }
  .battle-salon .battle-layout .battle-status-strip { order: 1; padding: 6px 0; }
  .battle-salon .battle-layout > .opponent-panel { order: 2; }
  .battle-salon .battle-layout #turnNotice { order: 3; }
  .battle-salon .battle-layout > .player-panel:not(.opponent-panel) { order: 4; }
  .battle-salon .battle-layout > .hand-panel { order: 5; }
  .battle-layout > .deck-dock { order: 6; justify-self: end; flex-direction: row; }
  .battle-layout .deck-dock .deck-pack { width: 90px; height: 135px; }
  .battle-salon .battle-layout .battle-emote-area { order: 7; }
  .battle-salon .battle-layout .log-panel { order: 8; max-height: 160px; }
  .battle-salon .battle-layout .battle-details { order: 9; }
  .battle-salon .battle-layout .hand-panel { min-height: 202px; }
  .battle-salon .battle-layout .hand-row { --hand-card-height: 186px; flex-basis: 202px; }
}
@media (max-width: 540px) {
  .battle-salon .game-shell.battle-layout { padding: 8px; }
  .remaining-deck-dialog { margin: 8px; width: calc(100vw - 16px); height: calc(100dvh - 16px); }
  .remaining-deck-dialog > header { padding: 16px; }
  .remaining-deck-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 16px; gap: 18px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .remaining-deck-dialog[open] { animation: none; }
  .battle-layout .deck-pack { transition: none; }
}
.salon-reduced-motion .remaining-deck-dialog[open] { animation: none; }
.salon-reduced-motion .battle-layout .deck-pack { transition: none; }

/* Keep routine controls out of the card table. */
.battle-layout .battle-menu { position: relative; z-index: 16; }
.battle-layout .battle-menu > summary { display: grid; place-items: center; width: 36px; height: 36px; cursor: pointer; color: #e4d1a6; border: 1px solid #b99a6355; border-radius: 4px; background: #101c14b3; list-style: none; }
.battle-menu > summary::-webkit-details-marker { display: none; }
.battle-menu > summary [data-hud-icon] { width: 20px; height: 20px; }
.battle-layout .battle-menu .top-actions { position: absolute; top: calc(100% + 6px); right: 0; display: flex; flex-direction: column; width: 112px; padding: 6px; border: 1px solid #b99a6377; border-radius: 4px; background: #112019; box-shadow: 0 8px 24px #0007; }
.battle-layout .battle-menu:not([open]) .top-actions { display: none; }
.battle-layout .battle-menu .top-actions button { width: 100%; min-height: 36px; }
.stat-label { font: inherit; }
.battle-salon .battle-layout .log-panel { align-self: start; max-height: 190px; border-color: transparent; border-left-color: #c8a36744; background: #08170c28; }
.battle-salon .battle-layout .board-row { display: flex; justify-content: center; gap: 12px; padding: 10px 6px; }
.battle-salon .battle-layout .board-row .empty-slot { display: none; }
.battle-salon .battle-layout .board-row .board-card { flex: 0 1 140px; margin: 0; overflow: visible; border-radius: 48% 48% 9px 9px; background: #15251c; border: 2px solid #b9b597; }
.battle-salon .battle-layout .board-row .board-card .card-art { inset: 0; width: 100%; height: 100%; border-radius: inherit; overflow: hidden; }
.battle-salon .battle-layout .board-card .card-top { display: none; }
.battle-salon .battle-layout .board-card .card-name { font-size: 11px; bottom: 43px; }
.battle-salon .battle-layout .board-card .keywords { bottom: 27px; }
.battle-salon .battle-layout .board-card .stats { left: -4px; right: -4px; bottom: -3px; }
.battle-salon .battle-layout .board-card .stat-label { display: none; }
.battle-salon .battle-layout .board-card .stats > span { display: grid; place-items: center; min-width: 29px; height: 31px; padding: 2px 5px; border: 1px solid #d4c18d; border-radius: 8px 8px 12px 12px; color: #fff4d9; font: 600 23px/1 Georgia, serif; text-shadow: 0 1px 3px #000; }
.battle-salon .battle-layout .board-card .stats .atk { background: #264e60; }
.battle-salon .battle-layout .board-card .stats .hp { background: #833e45; }
.battle-salon .battle-layout .board-card .evolve-button { top: 28px; right: 2px; width: 25px; height: 25px; }
.battle-salon .battle-layout .board-card .evolve-button:disabled { visibility: hidden; }
.battle-layout .board-card.is-evolved { border-color: #edcc83; box-shadow: 0 0 0 2px #705032, 0 0 0 4px #d6ae65, 0 6px 17px #0008; }
.battle-salon .battle-layout .board-row .board-card.is-evolved { border: 3px double #ffe5a5; box-shadow: 0 0 0 2px #705032, 0 0 0 4px #d6ae65, 0 6px 17px #0008; }
.battle-layout .board-card.is-evolved::before { content: ""; position: absolute; inset: 3px; z-index: 2; border: 1px solid #ffe9b38c; border-radius: inherit; pointer-events: none; }
.battle-salon .battle-layout .board-card.is-evolved::after { content: ""; position: absolute; inset: -8px auto auto calc(50% - 8px); width: 16px; height: 16px; padding: 0; border-radius: 2px; z-index: 3; background: #dec38a; border: 1px solid #fff0c5; box-shadow: 0 0 0 2px #6b5031; transform: rotate(45deg); pointer-events: none; }
.battle-salon .battle-layout .board-card.is-evolved:hover { box-shadow: 0 0 0 2px #916a36, 0 0 0 4px #ffe0a2, 0 8px 18px #0008; }
.battle-salon .battle-layout .board-card:is(.selected, .attack-drop-ready) { outline-offset: 6px; }
.battle-salon .battle-layout #endTurnButton { min-width: 74px; min-height: 38px; border-radius: 50%; background: #6b303a; }
@media (max-width: 540px) {
  .battle-salon .battle-layout .board-card .stats > span { min-width: 26px; height: 28px; font-size: 20px; }
}
@media (max-width: 999px) {
  .battle-salon .battle-layout .board-row { justify-content: safe center; }
  .battle-salon .battle-layout .board-row .board-card { flex-shrink: 0; width: 110px; flex-basis: 110px; }
}
