/* A choice can always be put down, even when its card list needs to scroll. */
#modal-root .table-ceremony {
  z-index: 1150;
  pointer-events: auto;
  overscroll-behavior: contain;
}
body.is-in-game:has(.table-choice) .battlefield:has(.selection-buttons) > :is(.latest-play,.selection-buttons) { visibility: hidden; }
.table-choice[tabindex="-1"]:focus { outline: none; }

/* One reading frame in the foyer, catalogue, kiosk and at the table. */
#modal-root .table-ceremony:has([data-ceremony='card']) {
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
           max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
#modal-root .table-choice[data-ceremony='card'] {
  --mat: clamp(12px, 3.5vw, 16px);
  display: flex;
  flex-direction: column;
  width: min(100%, 354px);
  max-height: 100%;
  padding: 0;
  overflow: hidden;
  border: 1px solid #837757;
  border-radius: 9px;
  background: #22332c;
  box-shadow: 0 12px 38px #09140f66;
}
#modal-root [data-ceremony='card'] .modal-head {
  position: static;
  flex: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  padding: 4px 5px 2px var(--mat);
  border: 0;
  background: transparent;
}
#modal-root [data-ceremony='card'] .modal-head h2 {
  margin: 0;
  text-align: left;
  font: 500 19px/1.1 Georgia, 'Times New Roman', serif;
  letter-spacing: 0;
  color: #eee6d3;
}
#modal-root [data-ceremony='card'] .modal-close {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  color: #efdfb5;
  border: 0;
  border-radius: 50%;
}
#modal-root [data-ceremony='card'] .modal-close::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid #79806b;
  border-radius: inherit;
  background: #2d3e35;
}
#modal-root [data-ceremony='card'] .modal-close svg { position: relative; }
#modal-root [data-ceremony='card'] .modal-close:hover::before { border-color: #c3b184; background: #394b3f; }
#modal-root [data-ceremony='card'] .modal-close:focus-visible { outline: 2px solid #f0d296; outline-offset: -6px; }
#modal-root [data-ceremony='card'] .inspector-back {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 7px;
  min-height: 42px;
  padding: 0 4px 0 0;
  border-radius: 3px;
  background: transparent;
  color: #eadcb8;
  font: 600 13px/1.25 system-ui, sans-serif;
}
#modal-root [data-ceremony='card'] .inspector-back:hover { color: #fff8e5; text-decoration: underline; text-underline-offset: 3px; }
#modal-root [data-ceremony='card'] .inspector-back:focus-visible { outline: 2px solid #f0d296; outline-offset: 1px; }
#modal-root [data-ceremony='card'] .modal-content {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0 var(--mat) var(--mat);
  scrollbar-width: thin;
  scrollbar-color: #a89a74 #22332c;
}
#modal-root .card-inspector { gap: 12px; }
#modal-root .card-inspector :is(.inspector-card,.inspector-actions) { width: 100%; min-width: 0; }
#modal-root .card-inspector .playing-card { min-height: 0; aspect-ratio: 5 / 7; }
#modal-root .card-inspector .card-body { flex: 1 1 0; overflow-y: auto; }
#modal-root .card-inspector .card-body > * { flex: none; }
#modal-root .card-inspector .playing-card:hover { transform: none; filter: none; }
#modal-root .card-inspector .card-art { flex: none; height: auto; min-height: 0; aspect-ratio: var(--face-art-aspect); }
#modal-root .inspector-actions .action-disabled-reason { margin: 7px 0 0; color: #e2d9c3; text-align: center; }

body.is-in-game .table-choice:not([data-ceremony='generic'],[data-ceremony='rules'],[data-ceremony='end-confirm']) {
  border: 1px solid #927d52;
  border-radius: 6px;
  background: linear-gradient(135deg, #293e34, #1c2d28 60%, #20332d);
  box-shadow: 0 12px 40px #07141177, inset 0 1px #c8b78b24;
  padding: 12px clamp(9px, 1.6vw, 22px);
}
body.is-in-game .table-ceremony:has([data-ceremony='pending']) {
  padding-block: clamp(60px, 16dvh, 155px) clamp(100px, 35dvh, 270px);
  padding-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right));
}
body.is-in-game .table-choice[data-ceremony='pending'] { width: fit-content; min-width: min(100%, 340px); max-width: min(100%, 830px); }
body.is-in-game .table-choice[data-ceremony='pending'] {
  display: flex;
  flex-direction: column;
  max-height: 100%;
  overflow: hidden;
}
body.is-in-game .table-choice[data-ceremony='pending'] .modal-head {
  flex: none;
  justify-content: center;
  padding: 3px 8px 10px;
}
body.is-in-game .table-choice[data-ceremony='pending'] .modal-content {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 0;
  padding-bottom: 3px;
}
body.is-in-game .table-choice[data-ceremony='pending'] .modal-content > p {
  flex: none;
  margin-bottom: 13px;
  text-wrap: pretty;
}
body.is-in-game .table-choice[data-ceremony='pending'] .choice-options {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  align-content: flex-start;
  padding: 4px 7px 10px;
  scrollbar-width: thin;
  scrollbar-color: #bba373 #24443e;
}
body.is-in-game .table-choice[data-ceremony='pending'] .choice-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .playing-card {
  flex: 1 0 auto;
}
body.is-in-game .choice-footer {
  flex: none;
  display: flex;
  justify-content: center;
  padding: 12px 4px 3px;
}
body.is-in-game .table-choice .choice-dismiss,
.game-v2 .pending-lever {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: auto;
  padding: 7px 15px;
  border: 1px solid #ead3a2;
  border-radius: 4px;
  color: #292e27;
  background: linear-gradient(116deg, #c8aa71, #f1d7a3 52%, #d2b783);
  box-shadow: inset 0 1px #fff2c8, 0 2px #907344, 0 4px 8px #15222177;
  font: 600 13px/1.3 system-ui, sans-serif;
  text-align: center;
}
body.is-in-game .table-choice .choice-dismiss {
  flex: 0 1 auto;
  width: min(100%, 280px);
  height: auto;
  min-height: 46px;
  font-size: 15px;
}
body.is-in-game .table-choice .choice-dismiss:hover:not(:disabled),
.game-v2 .pending-lever:hover:not(:disabled) { background: #f2dba9; color: #232c26; }
body.is-in-game .table-choice .choice-dismiss:active:not(:disabled),
.game-v2 .pending-lever:active:not(:disabled) { transform: translateY(1px); }
@media (max-width: 700px) {
  body.is-in-game .table-ceremony:has([data-ceremony='pending']) {
    padding-block: max(94px, 22dvh, env(safe-area-inset-top)) max(104px, 29dvh, env(safe-area-inset-bottom));
    padding-inline: 9px;
  }
  body.is-in-game .table-choice[data-ceremony='pending'] { width: min(100%, 520px); min-width: 0; padding-block: 8px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .modal-head { padding: 0 2px 4px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .modal-content > p { margin: 0 auto 5px; font-size: 12px; line-height: 1.35; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .playing-card { min-height: 174px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-options { padding-block: 3px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card { gap: 2px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-footer { padding-block: 5px 0; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-options[data-strip='true'] {
    flex-wrap: nowrap; overflow: auto; justify-content: safe center;
    scroll-snap-type: x proximity; scroll-padding-inline: 4px;
  }
  body.is-in-game .table-choice[data-ceremony='pending'] [data-strip='true'] .choice-card { flex: 0 0 max(136px, calc(50% - 6px)); scroll-snap-align: start; }
  body.is-in-game .table-choice[data-ceremony='pending'] [data-strip='true']:has(> :nth-child(3)) .choice-card { flex-basis: max(136px, 43%); }
  body.is-in-game:has([data-ceremony='pending']) .game-v2 { min-height: 0; height: 100dvh; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-options { gap: 12px 10px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card {
    flex: 0 1 min(165px, calc(50% - 5px));
  }
  body.is-in-game .choice-footer { padding-top: 8px; }
  .game-v2 .pending-lever { min-height: 33px; padding-inline: 8px; font-size: 12px; }
}

/* The tabletop keeps a full row beneath the selected card for the two actions. */
.game-v2 .battlefield { container: arena / size; }
.game-v2 .battlefield:has(> .selection-buttons) {
  grid-template-rows: auto minmax(0, 1fr) auto;
  row-gap: 4px;
}
.game-v2 .battlefield > .selection-buttons {
  grid-column: 1 / -1;
  grid-row: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px;
  gap: 6px;
  width: min(100%, 360px);
  margin-inline: auto;
  padding: 2px 0;
}
.game-v2 .battlefield > .selection-buttons > button {
  width: 100%;
  min-width: 0;
  height: auto;
  min-height: 38px;
  padding: 6px 7px;
  border-radius: 4px;
  font: 600 13px/1.15 system-ui, sans-serif;
}
.game-v2 .selection-buttons .arena-cancel {
  border: 1px solid #b7a77d;
  color: #f0e5c9;
  background: linear-gradient(155deg, #405347, #273c35);
  box-shadow: inset 0 1px #72816a66, 0 2px #172821;
}
.game-v2 .selection-buttons .arena-cancel:hover { border-color: #efd596; background: #43584b; color: #fff4d7; }
.game-v2 .selection-buttons .arena-cancel:active { transform: translateY(1px); }
@media (max-width: 700px) {
  .game-v2 .battlefield > .selection-buttons { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 32px; gap: 5px; }
  .game-v2 .battlefield > .selection-buttons > button { min-height: 40px; padding-inline: 3px; font-size: 12px; }
}
@media (min-width: 601px) {
  .game-v2 .battlefield:has(> .selection-buttons) { padding-bottom: 6px; }
}

.game-v2 .battlefield > .selection-buttons { width:min(100%,415px); grid-template-columns:minmax(0,1fr) minmax(0,1fr) minmax(62px,auto); }
.game-v2 .selection-buttons [data-command="card-detail"] { border:1px solid #82785d; background:#26332f; color:#e8dab7; }

.game-v2 .arena-action-area .event-route { flex-wrap: nowrap; max-width: 100%; }
.game-v2 .event-route :is(.event-actor,.event-target) {
  min-width: 0; max-width: 16ch; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.game-v2 .event-route .event-arrow { flex: none; }

/* In a shallow arena the deck uses the entire left column. The selected print
   becomes a horizontal title card, with its full rules one button away. */
@container arena (max-height: 205px) {
  .game-v2 .battlefield .battlefield-topline,
  .game-v2 .battlefield:has(.last-play-rest) .battlefield-topline { grid-column: 2 / -1; grid-row: 1; }
  .game-v2 .battlefield > .selection-buttons { grid-column: 2 / -1; }
  .game-v2 .battlefield .ether-apparatus {
    grid-row: 1 / -1;
    grid-template: 30px 18px 20px / repeat(2, minmax(0, 1fr));
    align-content: center; align-items: center; gap: 3px;
  }
  .game-v2 .battlefield .ether-deck {
    grid-area: 1 / 1; width: 19px; height: 26px; margin: 0;
    box-shadow: 1px 2px #ceb67c, 2px 4px #28473c;
  }
  .game-v2 .ether-deck::before, .game-v2 .ether-deck::after { inset: -4px; }
  .game-v2 .battlefield .dynamite-rack { grid-area: 1 / 2; gap: 1px; width: 100%; }
  .game-v2 .battlefield .dynamite-sticks { max-width: 100%; max-height: 14px; overflow: hidden; }
  .game-v2 .battlefield .dynamite-rack b { font-size: 14px; }
  .game-v2 .battlefield .deck-count { grid-area: 2 / 1 / 3 / -1; gap: 3px; }
  .game-v2 .battlefield .deck-count b { font-size: 16px; }
  .game-v2 .battlefield .rift-widget { grid-area: 1 / 1 / 3 / -1; width: 35px; }
  .game-v2 .battlefield :is(.discard-tray,.ash-brazier) { grid-row: 3; min-height: 20px; align-content: center; }
  .game-v2 .battlefield .latest-play:not(.is-empty) {
    grid-template: minmax(0,1fr) / minmax(0,1fr) minmax(0,.9fr);
    gap: 5px; align-items: center;
  }
  .game-v2 .latest-play .arena-card-wrap .playing-card {
    display: grid;
    grid-template: 4px minmax(0,1fr) / minmax(0,.48fr) minmax(0,1fr);
    width: min(100%,200px); height: min(100%,76px); aspect-ratio: auto;
  }
  .game-v2 .latest-play .arena-card-wrap .card-top {
    grid-column: 1 / -1; height: 4px; min-height: 0; padding: 0; overflow: hidden;
  }
  .game-v2 .latest-play .arena-card-wrap .card-top > * { visibility: hidden; }
  .game-v2 .latest-play .arena-card-wrap .card-art { display: block; height: 100%; min-height: 0; }
  .game-v2 .latest-play .arena-card-wrap .card-body { justify-content: center; padding: 2px 5px; }
  .game-v2 .latest-play .arena-card-wrap .card-body h3 {
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
    font-size: clamp(11px, calc((100cqh - 10px) / 2.1), 15px); line-height: 1.05; text-wrap: wrap;
  }
  .game-v2 .latest-play .arena-card-wrap :is(.card-rules,.card-keywords) { display: none; }
}
@container arena (max-height: 155px) {
  .game-v2 .battlefield:has(.last-play-rest) .battlefield-topline { grid-column: 2; }
  .game-v2 .battlefield > .last-play-rest {
    grid-row: 1 / 3; justify-content: center; gap: 2px;
  }
  .game-v2 .last-play-rest figcaption { font-size: 10px; line-height: 1.05; }
  .game-v2 .last-play-rest .resting-card { width: 100%; height: min(55%,48px); aspect-ratio: auto; }
  .game-v2 .last-play-rest .playing-card { border-top: 4px solid var(--district); }
  .game-v2 .last-play-rest :is(.card-art,.card-top,.card-rules) { display: none; }
  .game-v2 .last-play-rest .card-body { justify-content: center; padding: 2px 4px; }
  .game-v2 .last-play-rest .card-body h3 {
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
    font-size: clamp(10px, 10cqw, 13px); line-height: 1.05;
  }
}
@container arena (max-height: 205px) and (max-width: 460px) {
  .game-v2 .battlefield .latest-play:not(.is-empty) {
    grid-template: minmax(0,1fr) auto / minmax(0,1fr); gap: 2px;
  }
  .game-v2 .arena-action-area .play-preview { display: none; }
  .game-v2 .arena-action-area .event-route { line-height: 1; }
  .game-v2 .event-route .event-arrow { font-size: 13px; }
  .game-v2 .battlefield > .selection-buttons { grid-template-columns: 1fr 1fr .8fr; gap: 3px; }
  .game-v2 .battlefield > .selection-buttons > button { font-size: 11px; padding: 2px; }
}
@container arena (max-height: 124px) and (max-width: 460px) {
  .game-v2 .battlefield:has(.current-target) .latest-play .arena-action-area { display: none; }
  .game-v2 .battlefield > .selection-buttons > button { min-height: 30px; }
}

@media (min-width: 1001px) and (max-height: 790px) {
  body.is-in-game .table-choice[data-ceremony='pending'] { padding-block: 7px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .playing-card { width: 198px; min-height: 178px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .card-art { flex-basis: 35px; height: 35px; min-height: 35px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .card-body { padding: 5px 7px; gap: 2px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .card-bottom { padding-top: 3px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-options { padding-block: 2px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .modal-head,
  body.is-in-game .table-choice[data-ceremony='pending'] .modal-content > p { padding-bottom: 4px; margin-bottom: 4px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-footer { padding-top: 4px; }
}

/* On a short landscape screen the hand and the decision share a row. */
@media (max-height: 500px) and (min-width: 601px) and (max-width: 1000px) {
  body.is-in-game:has([data-ceremony='pending']) .game-v2 {
    margin-left: 0;
    width: 46%;
    min-height: 0;
    height: 100dvh;
    padding: 8px;
    grid-template-rows: minmax(0, 1fr);
  }
  body.is-in-game:has([data-ceremony='pending']) .game-v2 :is(.game-toolbar,.turn-console,.game-dock,.battlefield,.authority-aside,.right-sidebar) { display: none; }
  body.is-in-game:has([data-ceremony='pending']) .game-v2 .table-layout {
    grid-row: 1;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0,1fr) minmax(0,1.15fr);
  }
  body.is-in-game:has([data-ceremony='pending']) .game-v2 .near-side {
    grid-column: 1;
    grid-row: 2;
    height: 100%;
    grid-template: minmax(0,1fr) / minmax(0,1fr);
  }
  body.is-in-game:has([data-ceremony='pending']) .game-v2 .near-side :is(.my-seat,.relic-dock) { display: none; }
  body.is-in-game:has([data-ceremony='pending']) .game-v2 .hand-zone { grid-area: 1 / 1; }
  body.is-in-game .table-ceremony:has([data-ceremony='pending']) { justify-content: flex-end; padding: 7px; }
  body.is-in-game .table-choice[data-ceremony='pending'] { width: 53%; min-width: 0; padding: 6px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .modal-head { padding: 2px 4px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .modal-content > p { margin-bottom: 4px; font-size: 12px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-options { gap: 8px; }
  body.is-in-game .table-choice[data-ceremony='pending'] [data-strip='true'] { flex-wrap: nowrap; overflow: auto; justify-content: safe center; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card { flex: 0 0 max(145px, 43%); }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .playing-card { width: 100%; min-height: 170px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-footer { padding-top: 3px; }
}

/* Small phones use a single, vertically scrolling list. The district art
   stays alongside the rules so a complete option fits above the footer. */
@media (max-width: 600px) and (max-height: 620px) {
  body.is-in-game:has([data-ceremony='pending']) .game-v2 { grid-template-rows: 0 48px minmax(0,1fr) 35px; }
  body.is-in-game:has([data-ceremony='pending']) .game-toolbar { visibility: hidden; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-options:has(.choice-card) {
    display: grid; grid-template-columns: minmax(0,1fr); justify-content: stretch;
    overflow: hidden auto; scroll-snap-type: none; gap: 6px; padding: 2px 3px;
  }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card { position: relative; min-width: 0; gap: 0; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .playing-card {
    display: grid; grid-template: 17px minmax(36px,1fr) / 68px minmax(0,1fr);
    width: 100%; height: auto; min-height: 82px;
  }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .card-top { grid-area: 1 / 1; height: 17px; min-height: 0; padding: 2px 4px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .card-art { grid-area: 2 / 1; height: 100%; min-height: 0; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .card-body { grid-area: 1 / 2 / 3; padding: 5px 7px; gap: 2px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .card-body h3 { font-size: 15px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .card-rules { font-size: 12px; line-height: 1.25; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .card-bottom { padding-top: 2px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card .card-price { left: 44px; right: auto; top: 20px; }
  body.is-in-game .table-choice[data-ceremony='pending'] .choice-card-label {
    position: absolute; left: 1px; bottom: 1px; width: 68px;
    padding: 2px; background: #20352fec; border-radius: 0 0 0 4px; font-size: 10px;
  }
}
