/* ENH-248 shared three-panel History surface.  The replay timeline and authority
   remain the existing History implementation; this file owns only composition. */
body.history-replay-mode #history-screen.replaying {
  overflow: hidden;
  padding: 5px 8px 8px;
  color: #17231f;
  background: var(--history-table, #d5e0dc);
}
body.history-replay-mode #history-screen.replaying .lobby-inner {
  width: 100%; height: 100%; max-width: none; gap: 4px;
}
body.history-replay-mode #history-screen.replaying .history-heading {
  display: none;
}
body.history-replay-mode #history-screen.replaying .historyworkspace,
body.history-replay-mode #history-screen.replaying .historydetail {
  min-height: 0; overflow: hidden;
}
body.history-replay-mode #history-screen.replaying .historyworkspace {
  display: flex; flex: 1;
}
body.history-replay-mode #history-screen.replaying .historydetail {
  flex: 1; height: 100%; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none;
}

.history-v2-shell {
  --history-felt: #18704f; --history-table: #eef2f0; --history-player: #fbfdf9;
  --history-panel: #16231f; --history-player-text: #142820; --history-panel-text: #f4fbf8;
  --history-communication: #f4efe4; --history-information: #fff8dd;
  --history-communication-text: #17231f; --history-information-text: #17231f;
  --history-button: #21483d; --history-button-text: #f4fff9; --history-player-header: #e7ece9;
  --history-hand-rank: 26px; --history-hand-heading: 14px; --history-seat: 21px;
  --history-auction: 17px; --history-played: 28px; --history-ui-font: 19px;
  display: grid; grid-template-rows: auto minmax(0, 1fr); width: 100%; height: 100%; min-height: 0;
  overflow: hidden; color: #17231f; background: var(--history-table);
  font: 400 var(--history-ui-font)/1.3 Inter, ui-sans-serif, system-ui, sans-serif;
}
.history-v2-shell[data-size="compact"] {
  --history-hand-rank: 22px; --history-hand-heading: 12px; --history-seat: 18px;
  --history-auction: 13px; --history-played: 24px;
}
.history-v2-shell[data-size="large"] {
  --history-hand-rank: 30px; --history-hand-heading: 16px; --history-seat: 24px;
  --history-auction: 17px; --history-played: 32px;
}
.history-v2-shell[data-font-size="standard"] { --history-ui-font: 16px; --history-hand-heading: 14px; --history-auction: 15px; }
.history-v2-shell[data-font-size="large"] { --history-ui-font: 19px; --history-hand-heading: 18px; --history-auction: 18px; }
.history-v2-shell[data-font-size="extra-large"] { --history-ui-font: 22px; --history-hand-heading: 21px; --history-auction: 21px; }
.history-v2-shell * { box-sizing: border-box; }
.history-v2-contextbar {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 12px;
  min-height: 42px; padding: 5px 9px; color: var(--history-panel-text); border-bottom: 1px solid #52645d;
  background: var(--history-panel);
}
.history-v2-contextbar strong { color: #f4d465; font-size: 1.15em; letter-spacing: .04em; }
.history-v2-contextbar span { overflow: hidden; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.history-v2-contextbar small { color: #dcebe5; font-size: .78em; white-space: nowrap; }
.history-v2-contextbar #history-v2-back {
  width: auto; min-height: 34px; padding: 4px 9px; color: var(--history-button-text) !important;
  border-color: var(--history-button) !important; background: var(--history-button) !important; white-space: nowrap;
}
.history-v2-layout {
  display: grid; grid-template-areas: "controls workspace communication";
  grid-template-columns: 190px minmax(560px, 1fr) 270px; min-height: 0; overflow: hidden;
}
.history-v2-layout[data-panel-side="right"] {
  grid-template-areas: "communication workspace controls";
  grid-template-columns: 270px minmax(560px, 1fr) 190px;
}
.history-v2-layout[data-chat-minimized="true"] { grid-template-columns: 190px minmax(560px, 1fr) 64px; }
.history-v2-layout[data-panel-side="right"][data-chat-minimized="true"] { grid-template-columns: 64px minmax(560px, 1fr) 190px; }
.history-v2-controls {
  grid-area: controls; display: flex; min-width: 0; min-height: 0; overflow-y: auto;
  flex-direction: column; gap: 7px; color: var(--history-panel-text);
  border-right: 1px solid #52645d; background: var(--history-panel);
}
.history-v2-layout[data-panel-side="right"] .history-v2-controls { border-right: 0; border-left: 1px solid #52645d; }
.history-v2-heading { display: grid; gap: 2px; padding: 9px 10px 4px; }
.history-v2-heading strong { color: #f4d465; font-size: 1.28em; letter-spacing: .04em; }
.history-v2-heading span { color: #d1e1db; font-size: .82em; }
.history-v2-board { display: grid; justify-items: center; color: #173228; border-block: 1px solid #c9c0a8; background: #f7f0df; }
.history-v2-board .board-diagram { display: block; width: 116px; height: 116px; margin: 7px auto 3px; }
.history-v2-board .board-diagram text { font-family: Inter, ui-sans-serif, system-ui, sans-serif; text-anchor: middle; dominant-baseline: middle; }
.history-v2-board .board-diagram .board-dealer { font-size: 7px; }
.history-v2-board .board-diagram .board-number { fill: #173228; font-size: 28px; font-weight: 600; }
.history-v2-vulnerability { display: flex; width: 100%; align-items: center; justify-content: center; gap: 6px; padding: 5px; color: #a51e22; border-top: 1px solid #b8aa89; background: #e4d6b5; }
.history-v2-vulnerability span { font-size: .72em; }
.history-v2-vulnerability strong { font-size: 1em; }
#history-screen .history-v2-contract {
  display: grid; width: 100%; min-height: 67px; place-items: center; gap: 0; padding: 6px;
  color: var(--history-information-text); border: 0; border-radius: 0; background: var(--history-information);
}
.history-v2-contract span { color: #5a6a64; font-size: .7em; }
.history-v2-contract strong { color: inherit; font-size: 1.18em; font-weight: 600; }
.history-v2-tricks { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 0 7px; }
.history-v2-tricks div { min-height: 57px; padding: 5px; color: var(--history-information-text); border: 2px solid #8bb5a6; border-radius: 4px; background: var(--history-information); text-align: center; }
.history-v2-tricks span { display: block; color: #52625c; font-size: .7em; }
.history-v2-tricks strong { display: block; font-size: 1.35em; font-weight: 600; }
.history-v2-source { display: grid; gap: 2px; margin: 0 7px 8px; padding: 8px; border: 1px solid #60716b; border-radius: 4px; }
.history-v2-source span, .history-v2-source small { color: #cbdad5; font-size: .7em; }
.history-v2-source strong { color: var(--history-panel-text); font-size: .92em; }

.history-v2-workspace { grid-area: workspace; min-width: 0; min-height: 0; padding: 7px; background: var(--history-felt); }
body.history-replay-mode #history-screen .history-v2-workspace .replaytable {
  position: relative; display: grid; width: 100%; height: 100%; min-width: 0; min-height: 0;
  max-width: none; margin: 0; padding: 9px; overflow: hidden;
  grid-template-areas: "board north options" "west center east" "status south actions";
  grid-template-columns: minmax(150px, .9fr) minmax(250px, 1.35fr) minmax(155px, .95fr);
  grid-template-rows: minmax(155px, 1.1fr) minmax(110px, .65fr) minmax(155px, 1.1fr);
  gap: 9px; align-items: center; align-content: normal;
  border: 2px solid #0a3e31; border-radius: 0;
  background: var(--history-felt); box-shadow: inset 0 0 60px #0002;
}
.history-v2-shell[data-size="large"] .replaytable {
  grid-template-rows: minmax(155px, 1.1fr) minmax(140px, .65fr) minmax(155px, 1.1fr) !important;
}
body.history-replay-mode #history-screen .replaytable .gui-replay-board {
  grid-area: board; align-self: start; display: grid; grid-template-columns: 1fr auto; gap: 3px;
  min-width: 0; max-width: none; padding: 7px 9px; border-color: #c9b86d; border-radius: 4px;
  background: #fff8dd; color: #4d421e; font-size: 13px; line-height: 1.2;
}
body.history-replay-mode #history-screen .gui-replay-board :is(.gui-replay-dealer,.gui-replay-contract,.gui-replay-score) { grid-column: 1 / -1; }
body.history-replay-mode #history-screen .replaytable .dealhand {
  position: static; width: 100%; min-width: 0; max-width: 100%; max-height: none; height: auto;
  padding: 0; overflow: hidden; color: var(--history-player-text); border: 2px solid #d9e3df;
  border-radius: 4px; background: var(--history-player); box-shadow: 0 4px 12px #0004;
}
body.history-replay-mode #history-screen .replaytable .dealhand.n { grid-area: north; align-self: start; justify-self: center; }
body.history-replay-mode #history-screen .replaytable .dealhand.w { grid-area: west; }
body.history-replay-mode #history-screen .replaytable .dealhand.e { grid-area: east; }
body.history-replay-mode #history-screen .replaytable .dealhand.s { grid-area: south; align-self: end; justify-self: center; }
body.history-replay-mode #history-screen .replaytable .dealhand.focus { outline: 4px solid #f2c744; outline-offset: 1px; box-shadow: 0 0 0 2px #fff2b4; }
body.history-replay-mode #history-screen .replaytable .lbl {
  display: grid; grid-template-columns: 42px minmax(0, 1fr); min-height: 42px; margin: 0; padding: 0 8px 0 0; overflow: hidden; color: var(--history-player-text);
  border-bottom: 1px solid #b8c8c2; border-radius: 0; background: var(--history-player-header);
  font: 700 var(--history-hand-heading)/1.15 Inter, ui-sans-serif, system-ui, sans-serif;
  align-items: center; white-space: nowrap;
}
.replay-seat-marker { display: grid; align-self: stretch; place-items: center; color: #fff; background: #185b4c; font-size: var(--history-seat); }
.replay-seat-marker.vulnerable { background: #a9221b; }
.replay-player-name { min-width: 0; padding-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.history-replay-mode #history-screen .replaytable .diagramhand {
  width: 100%; min-width: 0; max-width: 100%; margin: 0; padding: 5px 7px 7px;
  color: var(--history-player-text); border: 0; border-radius: 0; background: var(--history-player);
}
body.history-replay-mode #history-screen .replaytable .diagramrow {
  display: flex; min-height: 26px; align-items: baseline; gap: 3px; overflow: hidden;
  color: var(--history-player-text); font-size: var(--history-hand-rank); line-height: 1.05;
  flex-wrap: nowrap; white-space: nowrap;
}
body.history-replay-mode #history-screen .replaytable .diagramrow .slbl {
  width: 26px; flex: 0 0 26px; font-size: calc(var(--history-hand-rank) + 2px);
}
body.history-replay-mode #history-screen .replaytable .diagramrank {
  min-width: 0; padding: 0 1px; color: var(--history-player-text);
  font: 700 var(--history-hand-rank)/1.05 Georgia, serif;
}
body.history-replay-mode #history-screen .replaytable .diagramvoid { font-size: var(--history-hand-rank); }
body.history-replay-mode #history-screen .replay-auction-surface {
  position: static; grid-area: options; align-self: start; z-index: 8; width: 100%; min-width: 0;
}
body.history-replay-mode #history-screen .replay-auction-surface > .btn { min-height: 40px; }
body.history-replay-mode #history-screen .replay-auction-surface .replay-auction {
  max-height: 100%; overflow: auto; padding: 5px; border-radius: 4px; background: #f7f4ec;
}
body.history-replay-mode #history-screen .replay-auction-surface .cap { position: sticky; top: -5px; z-index: 2; padding: 3px; background: #f7f4ec; }
body.history-replay-mode #history-screen .replay-auction-surface .auction,
body.history-replay-mode #history-screen .replay-auction-surface .auction :is(th,td,button) { font-size: var(--history-auction); }
body.history-replay-mode #history-screen .replaycenter {
  position: absolute; grid-area: auto; left: 30%; right: 30%; top: var(--replay-mid-top, 35%);
  width: auto; height: var(--replay-mid-height, 142px); min-height: 142px;
  overflow: hidden; border: 1px solid #ffffff4d; border-radius: 10px; background: #05261c59;
}
.history-v2-shell[data-size="large"] .replaycenter { min-height: 142px !important; }
body.history-replay-mode #history-screen .replaycenter .card {
  width: 48px; height: 65px; --card-rank-size: var(--history-played); --card-suit-size: var(--history-played);
}
body.history-replay-mode #history-screen .replay-hcp-layer > .replay-hcp-value { background: #05261ce6; }
body.history-replay-mode #history-screen .replay-hcp-value {
  min-width: 50px; padding: 3px 5px; gap: 0 3px; font-size: calc(var(--history-hand-heading) * .78);
}
body.history-replay-mode #history-screen .replay-hcp-value strong { font-size: calc(var(--history-hand-heading) * 1.05); }
body.history-replay-mode #history-screen .replay-hcp-value small { font-size: calc(var(--history-hand-heading) * .52); }
body.history-replay-mode #history-screen .replay-dd-inline {
  position: static; grid-area: status; align-self: end; justify-self: start; z-index: 2;
  width: 100%; max-width: 190px; padding: 5px 7px; color: #17231f;
  border: 1px solid #aebcb7; border-radius: 4px; background: #f7f4ecf2;
}
body.history-replay-mode #history-screen .replay-actions {
  position: static; grid-area: actions; align-self: end; display: grid !important; width: 100%;
  grid-template-columns: minmax(0, 1fr); margin: 0; padding: 5px; gap: 4px; border: 1px solid #ffffff73; border-radius: 5px;
  background: #05261ce6;
}
body.history-replay-mode #history-screen .replay-actions .replay-transport { display: grid; grid-template-columns: repeat(4, minmax(38px, 1fr)); gap: 3px; }
body.history-replay-mode #history-screen .replay-actions .replay-transport .btn { min-width: 38px; min-height: 40px; padding: 3px; color: var(--history-button-text); border-color: var(--history-button); background: var(--history-button); font-size: 19px; }
body.history-replay-mode #history-screen .replay-actions .replay-speed-control {
  display: grid; grid-template-columns: auto repeat(3, minmax(0, 1fr)); align-items: center; gap: 3px;
  color: #f3fbf7;
}
body.history-replay-mode #history-screen .replay-actions .replay-speed-control > span {
  display: grid; width: 28px; height: 28px; place-items: center; font-size: 15px;
}
body.history-replay-mode #history-screen .replay-actions .replay-speed-control .btn {
  min-width: 0; min-height: 30px; padding: 2px 3px; color: #dce9e4; border-color: #779087; background: transparent; font-size: 13px;
}
body.history-replay-mode #history-screen .replay-actions .replay-speed-control .btn[aria-pressed="true"] {
  color: var(--history-button-text); border-color: #f4d465; background: var(--history-button); font-weight: 800;
}
body.history-replay-mode #history-screen .replay-actions .replay-other {
  min-height: 35px; color: var(--history-button-text) !important; border-color: var(--history-button) !important;
  background: var(--history-button) !important;
}
body.history-replay-mode #history-screen .replay-actions .replay-other:disabled {
  color: #bdcbc6 !important; opacity: .72;
}
body.history-replay-mode #history-screen .replaytable > .replay-status { grid-area: center; }

.history-v2-communication {
  grid-area: communication; display: flex; min-width: 0; min-height: 0; overflow: hidden;
  align-items: stretch; flex-direction: column; justify-content: flex-end; color: var(--history-communication-text);
  border-left: 1px solid #aebcb7; background: var(--history-communication);
}
.history-v2-layout[data-panel-side="right"] .history-v2-communication { border-right: 1px solid #aebcb7; border-left: 0; }
#history-chat-slot { display: flex; width: 100%; height: 50%; min-height: 240px; margin-top: auto; overflow: hidden; }
#history-chat-slot #direct-chat-host { position: static; display: block; width: 100%; height: 100%; min-width: 0; padding: 0; }
#history-chat-slot kb-chat-panel { display: block; width: 100%; height: 100%; }
.history-v2-layout[data-chat-minimized="true"] #history-chat-slot { height: auto; min-height: 0; }

@media (max-width: 900px) {
  body.history-replay-mode #history-screen.replaying { overflow: auto; }
  body.history-replay-mode #history-screen.replaying .historydetail { overflow: visible; }
  .history-v2-shell { height: auto; min-height: 100%; overflow: visible; }
  .history-v2-layout, .history-v2-layout[data-panel-side="right"] {
    grid-template-areas: "workspace workspace" "controls communication";
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); overflow: visible;
  }
  .history-v2-workspace { height: calc(100dvh - var(--history-top, 64px) - 90px); min-height: 590px; max-height: 720px; }
  .history-v2-controls { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: start; overflow: visible; padding: 8px; border-top: 1px solid #52645d; border-right: 0; }
  .history-v2-heading { padding: 0; }
  .history-v2-board { grid-column: 2; grid-row: 1 / span 2; }
  .history-v2-board .board-diagram { width: 92px; height: 92px; }
  #history-screen .history-v2-contract { grid-column: 3; grid-row: 1; }
  .history-v2-tricks { grid-column: 4; grid-row: 1; padding: 0; }
  .history-v2-source { grid-column: 1 / span 2; margin: 0; }
  .history-v2-communication { min-height: 280px; overflow: visible; border-top: 1px solid #aebcb7; }
  #history-chat-slot { height: 100%; min-height: 280px; }
}

@media (max-width: 700px) {
  .history-v2-contextbar { grid-template-columns: auto 1fr; gap: 6px; }
  .history-v2-contextbar span { text-align: right; }
  .history-v2-contextbar small { grid-column: 1; white-space: normal; }
  .history-v2-contextbar #history-v2-back { grid-column: 2; width: 100%; }
  .history-v2-contextbar #history-v2-back { font-size: 0; }
  .history-v2-contextbar #history-v2-back::after { content: "Back"; font-size: 14px; }
  .history-v2-workspace { height: 690px; padding: 4px; }
  body.history-replay-mode #history-screen .history-v2-workspace .replaytable {
    grid-template-columns: minmax(92px, .9fr) minmax(112px, 1.2fr) minmax(92px, .9fr);
    grid-template-rows: minmax(150px, 1fr) minmax(145px, .85fr) minmax(150px, 1fr);
    gap: 5px; padding: 5px;
  }
  body.history-replay-mode #history-screen .replaytable .gui-replay-board { padding: 4px; font-size: 10px; }
  body.history-replay-mode #history-screen .replaytable .lbl { min-height: 28px; padding: 4px; font-size: .78em; }
  body.history-replay-mode #history-screen .replaytable .diagramhand { padding: 3px; }
  body.history-replay-mode #history-screen .replaytable .diagramrow { min-height: 25px; font-size: 18px; gap: 1px; }
  body.history-replay-mode #history-screen .replaytable .diagramrow .slbl { width: 21px; flex-basis: 21px; font-size: 19px; }
  body.history-replay-mode #history-screen .replaytable .diagramrank { font-size: 18px; padding: 0; }
  body.history-replay-mode #history-screen .replay-auction-surface .auction,
  body.history-replay-mode #history-screen .replay-auction-surface .auction :is(th,td,button) { font-size: 11px; }
  body.history-replay-mode #history-screen .replay-auction-surface .cap > span { display: none; }
  body.history-replay-mode #history-screen .replay-auction-surface .cap { justify-content: flex-end; }
  body.history-replay-mode #history-screen .replay-auction-surface .cap .btn { min-width: 44px; padding-inline: 3px; }
  body.history-replay-mode #history-screen .replay-dd-inline { padding: 3px; font-size: 9px; }
  body.history-replay-mode #history-screen .replay-dd-inline .replay-dd-title { font-size: 9px; }
  body.history-replay-mode #history-screen .replay-actions { padding: 3px; }
  body.history-replay-mode #history-screen .replay-actions .replay-transport { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  body.history-replay-mode #history-screen .replay-actions .replay-transport .btn { min-width: 20px; min-height: 36px; padding-inline: 0; font-size: 14px; }
  body.history-replay-mode #history-screen .replay-actions .replay-speed-control > span { width: 20px; }
  body.history-replay-mode #history-screen .replay-actions .replay-speed-control .btn { min-height: 29px; font-size: 10px; }
  body.history-replay-mode #history-screen .replay-actions .replay-other { min-height: 31px; padding: 2px; font-size: 10px; }
  .history-v2-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-v2-heading { grid-column: 1 / -1; }
  .history-v2-board { display: none; }
  #history-screen .history-v2-contract { grid-column: 1; grid-row: auto; }
  .history-v2-tricks { grid-column: 2; grid-row: auto; }
  .history-v2-source { grid-column: 1 / -1; }
  .history-v2-layout, .history-v2-layout[data-panel-side="right"] { display: flex; flex-direction: column; }
  .history-v2-workspace { order: 1; }
  .history-v2-controls { order: 2; }
  .history-v2-communication { order: 3; }
}

/* ENH-058 portrait-phone replay composition.  The same replay data and
   transport remain in use; only the protected table geometry changes. */
@media (max-width: 560px) and (min-height: 500px) {
  body.history-replay-mode #history-screen.replaying { padding:0;overflow:auto; }
  .history-v2-shell { min-height:100dvh;height:auto;padding-top:env(safe-area-inset-top); }
  .history-v2-contextbar {
    position:sticky;z-index:12;top:0;grid-template-columns:auto minmax(0,1fr) auto;
    min-height:50px;padding:4px max(5px,env(safe-area-inset-right)) 4px max(5px,env(safe-area-inset-left));gap:5px
  }
  .history-v2-contextbar strong { font-size:15px; }
  .history-v2-contextbar span { text-align:left;font-size:12px; }
  .history-v2-contextbar small { display:none; }
  .history-v2-contextbar #history-v2-back { grid-column:auto;width:44px;min-width:44px;min-height:44px;padding:2px;font-size:0; }
  .history-v2-contextbar #history-v2-back::after { content:"Back";font-size:11px; }
  .history-v2-layout, .history-v2-layout[data-panel-side="right"] { display:flex;min-height:0;flex-direction:column;overflow:visible; }
  .history-v2-workspace { order:1;width:100%;height:700px;min-height:700px;max-height:none;padding:4px; }
  body.history-replay-mode #history-screen .history-v2-workspace .replaytable {
    display:grid;grid-template-columns:min(30vw,124px) minmax(0,1fr) min(30vw,124px);
    grid-template-rows:auto minmax(170px,1fr) auto auto auto!important;
    grid-template-areas:"north north north" "west center east" "auction auction auction" "south south south" "status options actions";
    gap:4px;width:100%;height:100%;min-width:0;min-height:0;padding:4px;overflow:hidden
  }
  body.history-replay-mode #history-screen .replaytable .dealhand.n,
  body.history-replay-mode #history-screen .replaytable .dealhand.s { width:100%;max-width:100%;justify-self:stretch; }
  body.history-replay-mode #history-screen .replaytable .dealhand.n { grid-area:north; }
  body.history-replay-mode #history-screen .replaytable .dealhand.s { grid-area:south; }
  body.history-replay-mode #history-screen .replaytable .dealhand.w { grid-area:west;align-self:center; }
  body.history-replay-mode #history-screen .replaytable .dealhand.e { grid-area:east;align-self:center; }
  body.history-replay-mode #history-screen .replaytable .lbl {
    grid-template-columns:31px minmax(0,1fr);min-height:28px;padding:0 4px 0 0;font-size:12px
  }
  .replay-seat-marker { font-size:18px; }
  body.history-replay-mode #history-screen .replaytable :is(.dealhand.n,.dealhand.s) .diagramhand {
    display:flex;min-height:46px;height:auto!important;flex-direction:row!important;align-items:stretch;gap:1px;padding:2px;overflow:hidden
  }
  body.history-replay-mode #history-screen .replaytable :is(.dealhand.n,.dealhand.s) .diagramrow { display:contents; }
  body.history-replay-mode #history-screen .replaytable :is(.dealhand.n,.dealhand.s) .diagramrow>.slbl,
  body.history-replay-mode #history-screen .replaytable :is(.dealhand.n,.dealhand.s) .diagramvoid { display:none; }
  body.history-replay-mode #history-screen .replaytable :is(.dealhand.n,.dealhand.s) .diagramrank {
    display:grid;min-width:0;min-height:44px;place-items:center;flex:1 1 0;padding:0;
    border:1px solid #afbbb6;border-radius:4px;background:#fffdf8;color:transparent;font-size:0
  }
  body.history-replay-mode #history-screen .replaytable :is(.dealhand.n,.dealhand.s) .diagramrank::after {
    content:attr(data-card-label);color:#17222b;font:800 clamp(11px,3.2vw,15px)/1 Inter,system-ui,sans-serif
  }
  body.history-replay-mode #history-screen .replaytable :is(.dealhand.n,.dealhand.s) .diagramrow:has(.slbl.red) .diagramrank::after { color:#b51f37; }
  body.history-replay-mode #history-screen .replaytable :is(.dealhand.w,.dealhand.e) .diagramhand { padding:3px; }
  body.history-replay-mode #history-screen .replaytable :is(.dealhand.w,.dealhand.e) .diagramrow { min-height:22px;font-size:14px;gap:1px; }
  body.history-replay-mode #history-screen .replaytable :is(.dealhand.w,.dealhand.e) .diagramrow .slbl { width:18px;flex-basis:18px;font-size:17px; }
  body.history-replay-mode #history-screen .replaytable :is(.dealhand.w,.dealhand.e) .diagramrank { min-height:20px;font-size:14px; }
  body.history-replay-mode #history-screen .replaycenter {
    position:relative!important;grid-area:center!important;inset:auto!important;
    width:auto!important;height:auto!important;min-height:160px!important;
    align-self:stretch;justify-self:stretch
  }
  body.history-replay-mode #history-screen .replay-auction-surface { grid-area:options;align-self:stretch;min-width:0; }
  body.history-replay-mode #history-screen .replay-auction-surface:has(.replay-auction) {
    position:relative;z-index:9;inset:auto;grid-area:auction;justify-self:center;width:min(340px,100%);max-height:180px;overflow:auto
  }
  body.history-replay-mode #history-screen .replay-auction-surface .replay-auction { max-height:100%;overflow:auto; }
  body.history-replay-mode #history-screen .replaytable .gui-replay-board { display:none; }
  body.history-replay-mode #history-screen .replay-dd-inline {
    position:absolute;left:5px;bottom:5px;grid-area:status;
    width:205px;max-width:calc(100vw - 135px);font-size:11px
  }
  body.history-replay-mode #history-screen .replay-dd-inline .replay-dd-title { font-size:11px; }
  body.history-replay-mode #history-screen .replay-dd-table :is(th,td) { padding:2px; }
  body.history-replay-mode #history-screen .replay-actions { grid-area:actions;min-width:0; }
  body.history-replay-mode #history-screen .replay-actions .replay-transport .btn { min-width:0;min-height:40px; }
  .history-v2-controls { order:2;grid-template-columns:repeat(2,minmax(0,1fr));padding:6px; }
  .history-v2-communication { order:3;min-height:240px;padding-bottom:env(safe-area-inset-bottom); }
}

/* Reference2 landscape-phone replay.  Replay controls occupy the right edge;
   the four disclosed hands, auction/trick and South hand use the full felt. */
@media (max-height: 560px) and (max-width: 1000px) {
  body.history-replay-mode #history-screen.replaying { padding:0;overflow:hidden; }
  .history-v2-shell { grid-template-rows:44px minmax(0,1fr);height:100dvh;min-height:0; }
  .history-v2-contextbar {
    grid-template-columns:auto minmax(0,1fr) auto;min-height:44px;padding:3px 5px;gap:5px
  }
  .history-v2-contextbar strong { font-size:14px; }
  .history-v2-contextbar span { text-align:left;font-size:11px; }
  .history-v2-contextbar small { display:none; }
  .history-v2-contextbar #history-v2-back { min-width:44px;min-height:38px;padding:2px 5px;font-size:11px; }
  .history-v2-layout,
  .history-v2-layout[data-panel-side="right"] {
    display:grid;grid-template-areas:"workspace";grid-template-columns:minmax(0,1fr);min-height:0;overflow:hidden
  }
  .history-v2-controls,.history-v2-communication { display:none; }
  .history-v2-workspace { grid-area:workspace;width:100%;height:100%;min-height:0;max-height:none;padding:2px; }
  body.history-replay-mode #history-screen .history-v2-workspace .replaytable {
    display:grid;grid-template-columns:190px minmax(180px,1fr) 240px 142px;
    grid-template-rows:minmax(0,1fr) minmax(0,1fr) 64px!important;
    grid-template-areas:"west center north actions" "east center north actions" "south south south actions";
    gap:3px;width:100%;height:100%;min-width:0;min-height:0;padding:3px;overflow:hidden
  }
  body.history-replay-mode #history-screen .replaytable .dealhand { min-height:0;align-self:stretch;box-shadow:none; }
  body.history-replay-mode #history-screen .replaytable .dealhand.n { grid-area:north;align-self:stretch; }
  body.history-replay-mode #history-screen .replaytable .dealhand.w { grid-area:west;align-self:stretch; }
  body.history-replay-mode #history-screen .replaytable .dealhand.e { grid-area:east;align-self:stretch; }
  body.history-replay-mode #history-screen .replaytable .dealhand.s { grid-area:south;align-self:stretch;justify-self:stretch; }
  body.history-replay-mode #history-screen .replaytable .lbl {
    grid-template-columns:28px minmax(0,1fr);min-height:25px;height:25px;padding:0 3px 0 0;font-size:10px
  }
  .replay-seat-marker { font-size:16px; }
  body.history-replay-mode #history-screen .replaytable .diagramhand { padding:2px 4px;height:calc(100% - 25px);overflow:hidden; }
  body.history-replay-mode #history-screen .replaytable .diagramrow { min-height:22px;gap:1px;font-size:17px; }
  body.history-replay-mode #history-screen .replaytable .diagramrow .slbl { width:19px;flex-basis:19px;font-size:18px; }
  body.history-replay-mode #history-screen .replaytable .diagramrank { padding:0;font-size:17px; }
  body.history-replay-mode #history-screen .replaytable .dealhand.s .diagramhand {
    display:flex;height:39px!important;min-height:39px;flex-direction:row!important;align-items:stretch;gap:1px;padding:1px;overflow:hidden
  }
  body.history-replay-mode #history-screen .replaytable .dealhand.s .diagramrow { display:contents; }
  body.history-replay-mode #history-screen .replaytable .dealhand.s .diagramrow>.slbl,
  body.history-replay-mode #history-screen .replaytable .dealhand.s .diagramvoid { display:none; }
  body.history-replay-mode #history-screen .replaytable .dealhand.s .diagramrank {
    display:grid;min-width:0;min-height:37px;place-items:center;flex:1 1 0;padding:0;
    border:1px solid #afbbb6;border-radius:3px;background:#fffdf8;color:transparent;font-size:0
  }
  body.history-replay-mode #history-screen .replaytable .dealhand.s .diagramrank::after {
    content:attr(data-card-label);color:#17222b;font:800 12px/1 Inter,system-ui,sans-serif
  }
  body.history-replay-mode #history-screen .replaytable .dealhand.s .diagramrow:has(.slbl.red) .diagramrank::after { color:#b51f37; }
  body.history-replay-mode #history-screen .replaycenter {
    position:relative!important;grid-area:center!important;inset:auto!important;width:100%!important;height:100%!important;
    min-height:0!important;align-self:stretch;justify-self:stretch
  }
  body.history-replay-mode #history-screen .replay-auction-surface,
  body.history-replay-mode #history-screen .replay-auction-surface:has(.replay-auction) {
    position:relative;z-index:9;inset:auto;grid-area:center;align-self:stretch;width:100%;max-height:100%;overflow:auto
  }
  body.history-replay-mode #history-screen .replaytable .gui-replay-board { display:none; }
  body.history-replay-mode #history-screen .replay-dd-inline {
    position:absolute;z-index:10;left:198px;bottom:60px;width:min(180px,22vw);max-width:none;font-size:8px
  }
  body.history-replay-mode #history-screen .replay-actions {
    grid-area:actions;align-self:stretch;display:flex!important;min-width:0;height:100%;flex-direction:column;padding:3px;overflow:auto
  }
  body.history-replay-mode #history-screen .replay-actions .replay-transport { grid-template-columns:1fr 1fr; }
  body.history-replay-mode #history-screen .replay-actions .replay-transport .btn { min-width:0;min-height:40px; }
  body.history-replay-mode #history-screen .replay-actions .replay-speed-control { grid-template-columns:1fr; }
  body.history-replay-mode #history-screen .replay-actions .replay-speed-control > span { display:none; }
}

/* ENH-058 account-selected phone hands.  Diagram is suit-grouped text with a
   deliberate inter-suit gap; Compact cards put suit above rank and separate
   suit groups more strongly than adjacent cards. */
@media (max-width: 560px) and (min-height: 500px) {
  :root[data-hand-display=diagram] body.history-replay-mode #history-screen .replaytable
    :is(.dealhand.n,.dealhand.s) .diagramhand {
    display:flex!important;height:46px!important;min-height:46px;align-items:stretch;justify-content:center;
    flex-direction:row!important;gap:clamp(6px,2vw,10px);padding:1px 4px;overflow:hidden
  }
  :root[data-hand-display=diagram] body.history-replay-mode #history-screen .replaytable
    :is(.dealhand.n,.dealhand.s) .diagramrow {
    display:flex!important;min-width:0;min-height:44px;align-items:center;flex:0 1 auto;gap:1px;overflow:visible
  }
  :root[data-hand-display=diagram] body.history-replay-mode #history-screen .replaytable
    :is(.dealhand.n,.dealhand.s) .diagramrow>.slbl {
    display:block!important;width:auto;min-width:15px;flex:0 0 auto;font:900 19px/1 Inter,system-ui,sans-serif
  }
  :root[data-hand-display=diagram] body.history-replay-mode #history-screen .replaytable
    :is(.dealhand.n,.dealhand.s) .diagramrank {
    display:grid;width:auto;min-width:13px;height:44px;min-height:44px;place-items:center;flex:0 1 auto;
    padding:0 1px;color:#17222b!important;border:0;background:transparent;
    font:800 clamp(14px,4.1vw,18px)/1 Inter,system-ui,sans-serif
  }
  :root[data-hand-display=diagram] body.history-replay-mode #history-screen .replaytable
    :is(.dealhand.n,.dealhand.s) .diagramrank::after { content:none!important; }
  :root[data-hand-display=diagram] body.history-replay-mode #history-screen .replaytable
    :is(.dealhand.n,.dealhand.s) .diagramvoid { display:block;font-size:15px; }
}
@media (max-height: 560px) and (max-width: 1000px) {
  :root[data-hand-display=diagram] body.history-replay-mode #history-screen .replaytable .dealhand.s .diagramhand {
    display:flex!important;height:39px!important;min-height:39px;align-items:stretch;justify-content:center;
    flex-direction:row!important;gap:10px;padding:1px 4px;overflow:hidden
  }
  :root[data-hand-display=diagram] body.history-replay-mode #history-screen .replaytable .dealhand.s .diagramrow {
    display:flex!important;min-width:0;min-height:37px;align-items:center;flex:0 1 auto;gap:2px;overflow:visible
  }
  :root[data-hand-display=diagram] body.history-replay-mode #history-screen .replaytable .dealhand.s .diagramrow>.slbl {
    display:block!important;width:auto;min-width:14px;flex:0 0 auto;font:900 17px/1 Inter,system-ui,sans-serif
  }
  :root[data-hand-display=diagram] body.history-replay-mode #history-screen .replaytable .dealhand.s .diagramrank {
    display:grid;width:auto;min-width:13px;height:37px;min-height:37px;place-items:center;flex:0 1 auto;
    padding:0 1px;color:#17222b!important;border:0;background:transparent;font:800 16px/1 Inter,system-ui,sans-serif
  }
  :root[data-hand-display=diagram] body.history-replay-mode #history-screen .replaytable .dealhand.s .diagramrank::after { content:none!important; }
  :root[data-hand-display=diagram] body.history-replay-mode #history-screen .replaytable .dealhand.s .diagramvoid { display:block;font-size:14px; }
}
@media (max-width: 560px) and (min-height: 500px), (max-height: 560px) and (max-width: 1000px) {
  :root[data-hand-display=cards] body.history-replay-mode #history-screen .replaytable .dealhand .hand.horizontal {
    display:flex;box-sizing:border-box;width:100%;height:auto;min-height:0;align-items:stretch;justify-content:center;
    flex-wrap:nowrap;gap:2px;margin:0;padding:1px 2px;overflow:hidden;background:var(--history-player)
  }
  :root[data-hand-display=cards] body.history-replay-mode #history-screen .replaytable .dealhand .hand.horizontal .card {
    display:grid;width:auto;min-width:0;height:auto;min-height:27px;place-items:center;flex:1 1 0;
    margin:0;padding:1px;color:#17222b;border:1px solid #afbbb6;border-radius:3px;background:#fffdf8;box-shadow:none
  }
  :root[data-hand-display=cards] body.history-replay-mode #history-screen .replaytable .dealhand .hand.horizontal .card.red { color:#b51f37; }
  :root[data-hand-display=cards] body.history-replay-mode #history-screen .replaytable .dealhand .hand.horizontal .card.suit-start:not(:first-child) { margin-left:7px; }
  :root[data-hand-display=cards] body.history-replay-mode #history-screen .replaytable .dealhand .hand.horizontal .card .idx {
    position:static;display:flex;align-items:center;justify-content:center;flex-direction:column;gap:0;transform:none;line-height:.86
  }
  :root[data-hand-display=cards] body.history-replay-mode #history-screen .replaytable .dealhand .hand.horizontal .card .idx .is {
    order:0;font:900 clamp(11px,3.2vw,16px)/.9 Inter,system-ui,sans-serif
  }
  :root[data-hand-display=cards] body.history-replay-mode #history-screen .replaytable .dealhand .hand.horizontal .card .idx .ir {
    order:1;font:850 clamp(10px,3vw,15px)/1 Inter,system-ui,sans-serif
  }
}
@media (max-width: 560px) and (min-height: 500px) {
  :root[data-hand-display=cards] body.history-replay-mode #history-screen .replaytable .dealhand .hand.horizontal {
    height:46px
  }
}
@media (max-height: 560px) and (max-width: 1000px) {
  :root[data-hand-display=cards] body.history-replay-mode #history-screen .replaytable .dealhand .hand.horizontal {
    height:39px
  }
  :root[data-hand-display=cards] body.history-replay-mode #history-screen .replaytable .dealhand .hand.horizontal .card .idx .is {
    font-size:13px;line-height:.9
  }
  :root[data-hand-display=cards] body.history-replay-mode #history-screen .replaytable .dealhand .hand.horizontal .card .idx .ir {
    font-size:12px;line-height:.95
  }
}
