.square.piece-moving { z-index: 4; }

dialog.replay-dialog:has(.replay-shell) {
  width: min(520px, calc(100% - 24px));
  max-height: 92svh;
}
.replay-dialog:has(.replay-shell) .dialog-body { padding: 13px 16px 16px; }
.replay-shell { width: min(100%, max(288px, calc(91svh - 225px))); margin-inline: auto; }
.replay-frame {
  display: grid; grid-template-columns: 16px minmax(0, 1fr) 16px;
  grid-template-rows: auto 16px; gap: 2px;
}
.replay-board {
  display: grid; grid-template-rows: repeat(8, minmax(0, 1fr));
  grid-column: 2; grid-row: 1; width: 100%; aspect-ratio: 1; isolation: isolate;
  overflow: hidden; box-shadow: 0 0 0 1px #73795d;
}
.replay-row { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); }
.replay-ranks, .replay-files {
  display: grid; color: #bec7ab; font: 10px/1 var(--mono); text-transform: uppercase;
}
.replay-ranks { grid-column: 1; grid-row: 1; grid-template-rows: repeat(8, 1fr); }
.replay-files { grid-column: 2; grid-row: 2; grid-template-columns: repeat(8, 1fr); }
.replay-files span, .replay-ranks span { display: grid; place-items: center; }
.replay-board .square { cursor: default; }
.replay-board .replay-from { box-shadow: inset 0 0 0 2px #a87e2e; }
.replay-board .replay-to {
  background-image: linear-gradient(#ffcd6173,#ffcd6173);
  box-shadow: inset 0 0 0 3px #896124;
}
.replay-readout { margin-top: 8px; padding: 9px 12px; min-height: 54px; background: #171e17; border-left: 2px solid #a98a57; }
.replay-readout > div { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.replay-side { font: 600 14px/1.35 var(--sans); color: #e4e7d8; }
.replay-notation { font: 600 13px/1.3 var(--mono); color: #edc88a; }
.replay-detail { margin: 3px 0 0; font: 400 12px/1.4 var(--sans); color: #c2c9b8; }
.replay-track { display: flex; gap: 12px; align-items: center; margin: 2px 0; }
.replay-track input { flex: 1; min-width: 0; height: 30px; margin: 0; accent-color: #dfb678; cursor: pointer; }
.replay-track output { color: #bdc6af; font: 11px/1 var(--mono); }
.replay-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.replay-controls button { min-height: 40px; }
.replay-shell :focus-visible { outline: 2px solid #f1cc91; outline-offset: 2px; }
@media (max-width: 450px) {
  .replay-dialog:has(.replay-shell) .dialog-body { padding: 10px 9px 12px; }
  .replay-frame { grid-template-columns: 12px minmax(0, 1fr) 12px; }
}

/* Keep the order cards and their current availability readable beside the board. */
#war-room #hand-panel {
  --class-ink: #e9c480;
  --class-art: url("assets/doctrines/field-issue.webp");
  background: #1a211b;
}
#war-room #hand-panel[data-doctrine="vanguard"] {
  --class-ink: #f4b18c;
  --class-art: url("assets/doctrines/vanguard.webp");
}
#war-room #hand-panel[data-doctrine="sentinel"] {
  --class-ink: #9ddbd5;
  --class-art: url("assets/doctrines/sentinel.webp");
}
#hand-panel .section-header { gap: 7px; padding-inline: 13px; }
#hand-panel .section-header h2 { gap: 7px; }
#hand-panel #hand-count { margin-left: auto; font: 11px/1.25 var(--sans); color: #d2d8c9; }
#hand-panel .hand-guide {
  min-height: 44px;
  padding-inline: 7px;
  font: 600 12px/1.25 var(--sans);
  color: var(--class-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}
#hand-panel .hand-class-strip {
  min-height: 54px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: linear-gradient(90deg, #161e1bf2 5%, #161e1bd6 38%, #151b173b 78%),
              var(--class-art) 70% 44% / cover;
  border-bottom: 1px solid #455144;
}
#hand-class-name { font: 700 21px/1 "Field Condensed", var(--sans); color: #f4f2e7; }
#hand-class-role { margin-top: 3px; color: var(--class-ink); font: 500 12px/1.25 var(--sans); }
#hand-panel .hand-body { padding: 9px 12px 12px; }
#hand-panel #hand-help { color: #d4dacb; line-height: 1.4; }
#hand-panel .hand-list { margin-top: 8px; }
#hand-panel .hand-card { border-color: #626f59; background: #2b352b; }
#hand-panel .hand-card.armed { border-color: var(--class-ink); box-shadow: inset 0 0 0 1px var(--class-ink); }
#hand-panel .hand-card.armed .hand-card-title { color: var(--class-ink); }
#hand-panel .hand-card[aria-disabled="true"] { border-color: #424a41; background: #242a24; }
#hand-panel .hand-card[aria-disabled="true"] img { filter: saturate(.45) brightness(.76); }
#hand-panel .hand-card-desc { color: #d2d8cc; line-height: 1.3; }
#hand-panel .hand-card-state {
  color: #d4e3bd;
  font: 600 10px/1.2 var(--mono);
  letter-spacing: .035em;
  text-transform: uppercase;
}
#hand-panel .hand-card[aria-disabled="true"] .hand-card-state { color: #cad0c5; }
#hand-panel .hand-card.armed .hand-card-state { color: var(--class-ink); }
#hand-panel .hand-rule {
  margin: 9px 0 0;
  padding-top: 7px;
  border-top: 1px solid #3d493c;
  color: #d2d9ca;
  font: 12px/1.4 var(--sans);
}
#war-room #hand-jump { display: none; }
#war-room #cancel-card, #war-room #issue-order { min-height: 44px; }
#war-room .square.protected-king::after {
  content: "";
  position: absolute;
  z-index: 2;
  top: 2px; right: 2px; bottom: auto; left: auto;
  width: clamp(13px, 1.7vw, 17px); aspect-ratio: 1;
  border: 1px solid #e6d7a6;
  border-radius: 3px;
  background: #1e271e url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23efe3bc' stroke-width='1.65'%3E%3Crect x='3' y='7' width='10' height='7' rx='1.3'/%3E%3Cpath d='M5 7V5a3 3 0 0 1 6 0v2'/%3E%3C/svg%3E") center / 85% no-repeat;
  pointer-events: none;
}
@media (min-width: 741px) {
  #hand-panel .hand-list { grid-template-columns: 1fr; gap: 6px; }
  #hand-panel .hand-card {
    display: grid;
    grid-template-columns: 80px minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    align-content: stretch;
    text-align: left;
    padding: 0 11px 0 0;
    column-gap: 11px;
    min-height: 71px;
  }
  #hand-panel .hand-card img {
    grid-column: 1; grid-row: 1 / 4;
    align-self: stretch;
    width: 100%; height: 100%; min-height: 0;
    position: absolute; inset: 0;
    object-fit: cover;
    border: 0; border-right: 1px solid #4c5849;
  }
  #hand-panel .hand-card-state { grid-column: 2; align-self: end; padding-top: 7px; }
  #hand-panel .hand-card-title { grid-column: 2; align-self: center; padding: 2px 0; font-size: 19px; }
  #hand-panel .hand-card-desc { grid-column: 2; padding: 0 0 7px; font-size: 12px; }
  #hand-panel .hand-card-qty { right: auto; left: 4px; }
}
@media (max-width: 740px) {
  #war-room:has(#hand-panel:not([hidden])) { padding-top: 6px; }
  #war-room:has(#hand-panel:not([hidden])) .hero { display: none; }
  #war-room:has(#hand-panel:not([hidden])) .game-layout { margin-top: 0; gap: 7px; }
  #war-room:has(#hand-panel:not([hidden])) .board-panel .section-header { padding-inline: 10px; gap: 9px; }
  #war-room #hand-jump:not([hidden]) {
    display: inline-flex; gap: 4px; min-height: 44px;
    color: #f3d49e; font: 600 12px var(--sans);
  }
  #war-room #hand-jump-count { font: inherit; }
  #hand-panel .hand-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  #hand-panel .hand-list:has(.hand-card:nth-child(2):last-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #hand-panel .hand-list:has(.hand-card:only-child) { grid-template-columns: minmax(0, 1fr); }
  #hand-panel .hand-list:empty { display: none; }
  #hand-panel .hand-class-strip {
    min-height: 37px; gap: 9px;
    flex-direction: row; justify-content: flex-start; align-items: baseline;
    padding: 8px 12px;
  }
  #hand-class-name { font-size: 18px; }
  #hand-class-role { margin: 0; }
  #hand-panel .hand-card { display: flex; padding: 0 0 8px; }
  #hand-panel .hand-card img {
    display: block; width: 100%; height: clamp(50px, 12vw, 82px);
    aspect-ratio: auto; border-bottom: 1px solid #53624f;
  }
  #hand-panel .hand-card-state {
    order: 1; margin-top: auto; padding: 6px 7px 0; font-size: 10px;
  }
  #hand-panel .hand-card-title { padding: 6px 7px 2px; font-size: clamp(16px, 4.3vw, 20px); }
  #hand-panel .hand-card-desc { padding: 0 7px; font-size: 12px; }
  #war-room .board-action[data-action="flip"] { min-height: 44px; }
  #war-room:has(#hand-panel:not([hidden])) .board-action[data-action="flip"] span {
    position: absolute; height: 1px; width: 1px; overflow: hidden; clip-path: inset(50%);
  }
  #war-room .board-action[data-action="flip"] { min-width: 32px; justify-content: center; padding: 0; }
}
@media (max-width: 400px) {
  #war-room #hand-panel .section-header { padding-inline: 9px; gap: 5px; }
  #hand-panel .hand-body { padding-inline: 8px; }
  #hand-panel .hand-card-title, #hand-panel .hand-card-desc, #hand-panel .hand-card-state { padding-inline: 5px; }
  #war-room .board-panel .section-header h2 { gap: 5px; }
}
