/* Menu surfaces reserve header and actions; only their content may scroll.
   Specific setup, rules, avatar and result dialogs already own this contract. */
body[data-menu-page] { overflow: hidden; }
body[data-menu-page] .app-shell { height: 100dvh; max-width: none; padding: 0; display: flex; flex-direction: column; }
.menu-page:not([hidden]) { display: flex; flex-direction: column; width: 100%; min-height: 0; flex: 1; color: var(--pop-ink); background: transparent; }
.menu-page-heading, .menu-page-actions { flex: none; padding: 16px max(20px, calc((100vw - 1100px) / 2)); }
.menu-page-heading h2 { margin: 0; font-size: clamp(25px, 4vw, 38px); }
.menu-page-content { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 max(20px, calc((100vw - 1100px) / 2)); }
.menu-page-actions { display: flex; justify-content: space-between; gap: 12px; }
.menu-page-heading h2, .remote-cpu-dialog.menu-page > h2 { text-align: center; }
#setup-dialog .dialog-heading { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; gap: 12px; }
#setup-dialog .dialog-heading h2 { grid-column: 2; text-align: center; }
#setup-dialog .local-setup-heading, #setup-dialog .local-setup-actions { padding-inline: max(20px, calc((100vw - 1100px) / 2)); }
#setup-dialog .local-setup-content { padding-inline: max(20px, calc((100vw - 1100px) / 2)); }
.menu-page select { min-height: 44px; color: var(--pop-ink); background: #fffbee; border: var(--pop-border); border-radius: 5px; font: 18px var(--font-ui); }
.game-help-inline { width: 44px; flex: none; }
/* Real cards from the selected game, shared with its catalogue box. */
.game-preview { --preview-card-width: min(clamp(72px, 12vh, 132px), calc((100vw - 80px) / 3)); position: relative; width: calc(var(--preview-card-width) * 2.8); height: calc(var(--preview-card-width) * 1.7); margin: 12px auto; flex: none; pointer-events: none; }
.game-preview .card-art { position: absolute; width: var(--preview-card-width); height: auto; top: 12px; left: calc(50% - var(--preview-card-width) / 2); border-radius: 6px; box-shadow: 3px 5px 0 #28282070; transform-origin: 50% 90%; }
.game-preview .card-art:nth-child(1) { transform: translateX(-65%) rotate(-21deg); }
.game-preview .card-art:nth-child(2) { transform: translateY(-10px) rotate(-4deg); }
.game-preview .card-art:nth-child(3) { transform: translateX(65%) rotate(18deg); }
.game-help-page .menu-page-content { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); align-content: start; gap: 28px; padding-block: 12px; container-type: inline-size; }
.game-help-page .menu-page-content:focus-visible { outline: 2px solid var(--pop-felt-edge); outline-offset: -2px; }
.game-help-page .game-preview { --preview-card-width: min(12vh, 132px, 10cqi); position: sticky; top: 12px; align-self: start; }
.game-help-rules { min-width: 0; }
@media (max-width: 700px) {
  .game-help-page .menu-page-content { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .game-help-page .game-preview { --preview-card-width: clamp(52px, 16vw, 76px); position: relative; top: auto; }
}
@media (max-height: 500px) {
  .game-preview { --preview-card-width: 52px; margin-block: 10px; }
}
@media (min-width: 540px) and (max-height: 500px) {
  .game-help-page .menu-page-content { grid-template-columns: minmax(92px, 21%) minmax(0, 1fr); gap: 12px; }
  .game-help-page .game-preview { --preview-card-width: min(7vw, 52px); position: sticky; top: 8px; }
  #setup-dialog .setup-table-content { display: grid; grid-template-columns: 140px minmax(0, 1fr); align-items: center; }
  #setup-dialog .setup-table-content > :is(#setup-new-options, .setup-participants, #rule-options-fields) { grid-column: 2; }
  #setup-dialog .setup-table-content > .game-preview { grid-row: 1 / span 3; }
}
.game-menu-item { position: relative; min-width: 0; }
.game-menu-item > .game-box { width: 100%; height: 100%; }
.game-menu-item .box-action { min-height: 44px; }
.game-menu-item .box-name { min-width: 0; overflow-wrap: normal; }
@media (max-width: 899px) {
  .game-menu-item .game-box { grid-template-columns: minmax(0, 1fr); }
  .game-menu-item .box-action { min-width: 0; padding-inline: 6px; font-size: 17px; }
  .game-menu-item .box-action > [aria-hidden] { display: none; }
}
@media (max-width: 400px) {
  .game-menu-item .box-name { font-size: 20px; }
  .game-menu-item .box-art { min-width: 0; height: 90px; }
  .game-menu-item .box-art .card-art { width: 50px; left: calc(50% - 25px); }
  .game-menu-item .box-art .card-art:nth-child(1) { transform: translateX(-14px) rotate(-17deg); }
  .game-menu-item .box-art .card-art:nth-child(3) { transform: translateX(14px) rotate(16deg); }
}
body:not([data-remote-role]) #main-menu { max-width: 1600px; }
/* The whole local box is one control. Fit the fan in the space below its name. */
#main-menu > .game-boxes .game-box { grid-template: auto minmax(0, 1fr) / minmax(0, 1fr); text-align: center; }
#main-menu > .game-boxes .box-art { grid-area: 2 / 1; align-self: stretch; height: auto; container-type: size; }
#main-menu > .game-boxes .box-art .card-art {
  width: min(36cqw, 62cqh, 112px); top: 50%; left: 50%; translate: -50% -50%;
}
#main-menu > .game-boxes .box-art .card-art:nth-child(1) { transform: translateX(-43%) rotate(-18deg); }
#main-menu > .game-boxes .box-art .card-art:nth-child(2) { transform: translateY(-4%) rotate(-3deg); }
#main-menu > .game-boxes .box-art .card-art:nth-child(3) { transform: translateX(43%) rotate(17deg); }
@media (min-width: 1100px) {
  /* Fifteen boxes make three complete rows. Height expands with the screen. */
  body:not([data-remote-role]) .game-boxes { min-height: 100%; grid-template-columns: repeat(5, minmax(0, 1fr)); grid-auto-rows: minmax(142px, 1fr); gap: clamp(16px, 2vh, 24px); padding: 10px 12px 14px; }
  body:not([data-remote-role]) .game-box { min-height: 0; padding: 14px; gap: 4px; }
  body:not([data-remote-role]) .box-name { font-size: clamp(24px, 1.9vw, 32px); }
}
@media (min-width: 701px) and (max-width: 1099px), (orientation: landscape) and (max-width: 1099px) {
  body:not([data-remote-role]) .game-boxes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  body:not([data-remote-role]) .game-box { min-height: 190px; padding: 18px 12px; }
  body:not([data-remote-role]) .box-name { font-size: 24px; }
}
.remote-cpu-dialog.menu-page { margin: 0; padding: 16px max(20px, calc((100vw - 1100px) / 2)); max-width: none; max-height: none; border: 0; box-shadow: none; }
.remote-cpu-dialog.menu-page .remote-configuration { flex: 1; min-height: 0; }
.remote-cpu-dialog.menu-page .remote-configuration-content { align-content: safe center; grid-auto-rows: max-content; padding-inline: max(4px, calc((100% - 640px) / 2)); }
.remote-cpu-dialog.menu-page .remote-configuration-content > label { display: grid; gap: 8px; font-size: 18px; }
.remote-cpu-dialog.menu-page .remote-configuration-content > label select { height: 44px; padding: 6px 10px; }
.remote-cpu-dialog.menu-page .remote-lobby-actions { justify-content: space-between; border: 0; }
.remote-cpu-dialog.menu-page .remote-lobby-actions .button { flex: none; }
.remote-cpu-dialog.menu-page h2 { flex: none; }
body[data-remote-role="display"] .game-menu-item .game-box { grid-template-columns: minmax(0, 1fr); }
body[data-remote-role="display"] .game-menu-item .box-art { display: none; }
@media (max-height: 500px) {
  .menu-page-heading, .menu-page-actions { padding-block: 8px; }
}
[data-gamepad-focus]:focus { outline: 3px solid var(--pop-ink); outline-offset: 3px; box-shadow: 0 0 0 6px var(--pop-paper, #fff3d8); }
.input-help { margin-block: 12px; }
.input-help summary { min-height: 44px; padding-block: 10px; cursor: pointer; }
.input-help li { margin-block: 8px; }
.menu-dialog[open] { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); overflow: hidden; }
.menu-dialog > .dialog-heading, .menu-dialog-heading { flex: none; }
.menu-dialog .close-button { flex: none; min-width: 44px; width: 44px; height: 44px; }
.menu-dialog-content { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 4px; }
.menu-dialog-actions { flex: none; padding-top: 8px; }
#table-tools-actions .button { min-height: 44px; margin: 0; }
.menu-dialog-actions:not(:has(> :not([hidden]))) { display: none; }
.menu-dialog .history { max-height: none; overflow: visible; }
.menu-dialog-heading h2 { margin: 0 0 12px; }
.menu-dialog .dialog-heading { gap: 12px; }
.menu-dialog .dialog-heading h2 { min-width: 0; margin: 0; }
.result-dialog-actions > #remote-next-game { flex: 1 1 150px; min-height: 44px; }

body[data-screen="menu"]:not([data-remote-role]) {
  overflow: hidden;
  .app-shell { height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)); display: flex; flex-direction: column; }
  .topbar { flex: none; }
  #main-menu { flex: 1; min-height: 0; width: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 8px; }
  .about-footer { flex: none; margin-top: 6px; }
  .about-content { position: absolute; z-index: 8; bottom: 100%; left: 0; width: min(600px, 90vw); max-height: 50dvh; overflow: auto; margin: 0; }
  #main-menu:has(.beta-entry) { overflow: hidden; }
}
.beta-entry { height: 100%; margin: 0 auto; display: flex; flex-direction: column; }
.beta-entry > h2 { flex: none; margin: 0 0 8px; }
.beta-entry .remote-join { flex: 1; min-height: 0; width: 100%; margin: 0 auto; display: flex; flex-direction: column; }
.beta-entry-content { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 4px; }
.beta-entry-actions { flex: none; display: flex; flex-wrap: wrap; gap: 8px; }
.beta-entry-actions > button { flex: 1 1 140px; min-height: 44px; }

/* The TV keeps its grid; phones place this same content in a single scroll area. */
.remote-lobby-content { display: contents; }
body[data-remote-role="controller"][data-screen="menu"] {
  overflow: hidden;
  .app-shell { height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)); display: flex; flex-direction: column; padding-block: 8px; }
  .topbar { flex: none; min-height: 44px; margin: 0 0 6px; padding: 0; }
  #main-menu { flex: 1; min-height: 0; margin: 0; }
  .remote-lobby { height: 100%; margin: 0; display: flex; flex-direction: column; padding: 10px 12px; }
  .remote-heading { flex: none; margin-bottom: 8px; }
  .remote-lobby-content { display: block; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 6px; }
  .remote-lobby-controls { position: static; flex: none; margin: 0; padding: 8px 0 0; border: 0; border-top: 2px solid var(--pop-ink); }
  .remote-lobby-controls > .button { min-height: 44px; }
  .remote-lobby-status { margin: 0; }
  .remote-game-summary { gap: 4px 12px; }
  .remote-game-summary strong { min-width: 0; overflow-wrap: anywhere; }
  .remote-seats { margin: 8px 0; }
  .remote-setup { margin: 12px auto; }
  .about-footer { flex: none; margin: 0; border: 0; }
  .about-footer summary { min-height: 44px; padding: 10px 0; }
  .about-content { position: absolute; z-index: 8; bottom: 100%; left: 0; width: min(600px, 90vw); max-height: 50dvh; overflow: auto; margin: 0; }
  &:has(.remote-join:not([hidden])) .remote-lobby-content { display: none; }
}
@media (max-height: 650px) {
  /* Once joined, spend scarce height on profiles/options, not repeated branding. */
  body[data-remote-role="controller"][data-screen="menu"]:has(.remote-join[hidden]) .remote-heading { display: none; }
}
@media (max-height: 450px) {
  .menu-dialog { padding: 12px 18px; }
  .menu-dialog .dialog-heading { margin-bottom: 8px; }
  .menu-dialog-heading h2 { font-size: 24px; margin-bottom: 8px; }
  body[data-remote-role="controller"][data-screen="menu"] {
    .remote-heading { display: none; }
    .remote-game-summary { flex: 1 1 auto; }
    .remote-lobby-controls { gap: 6px 10px; }
    .about-footer { position: absolute; right: 12px; top: 8px; }
    .about-content { bottom: auto; top: 100%; right: 0; left: auto; }
    .topbar { padding-right: 120px; }
  }
}
