/* v126 — ergonomic constraints only. Load AFTER table-ui and voice-integration.
   No viewport JS: dvh reflows on browser chrome/orientation changes; vh fallback. */
@media (pointer:coarse) {
  body input:not([type="checkbox"]):not([type="radio"]), body textarea, body select {
    font-size:16px!important; min-height:44px;
  }
  #voice-controls button, .chat111-close, .table-secondary-actions > summary {
    min-height:44px; min-width:44px;
  }
}
@media (pointer:coarse), (max-width:900px) {
  .room-chat-compose input, .room-chat-compose textarea,
  #inGameChatInput, #roomChatInput { font-size:16px; }
  .room-chat-compose input, .room-chat-compose textarea { min-width:0; }
  .turn-actions button, .table-secondary-actions > summary,
  .chat111-close, .room-chat-compose button { touch-action:manipulation; }
  /* Keep native scrolling/pinch zoom; do not override hand drag's touch-action. */
  .room-chat-feed, .table-secondary-panel, .chat111-drawer {
    -webkit-overflow-scrolling:touch;
    overscroll-behavior-y:contain;
  }
  .chat111-drawer .room-chat-compose, .chat111-close { flex-shrink:0; }
}
@media (max-width:900px) {
  body:not(.is-setup) .app-shell { height:100vh; height:100dvh; min-height:0; }
  body:not(.is-setup) .reference-hud .turn-actions > #voice-controls:not([hidden]) {
    display:flex!important; height:auto; min-height:54px;
    box-sizing:border-box; flex:0 0 100%; width:100%; min-width:0;
    margin:0; padding:4px 6px; gap:6px; align-self:stretch;
    flex-direction:row; flex-wrap:nowrap; justify-content:flex-start; overflow-x:auto; overflow-y:hidden;
    -webkit-overflow-scrolling:touch;
  }
  body:not(.is-setup) .reference-hud .turn-actions #voice-controls button {
    flex-shrink:0;
    width:auto; height:44px; min-height:44px; min-width:44px;
    margin:0; padding:6px 8px; font-size:11px; line-height:1.2;
    white-space:nowrap;
  }
  body:not(.is-setup) .reference-hud .turn-actions #voice-controls [role=status] {
    flex:1 1 80px; min-width:0; font-size:11px; overflow-wrap:anywhere;
    line-height:14px; max-height:28px; overflow:hidden;
  }
  body.chat111-open #inGameChat.chat111-drawer:not([hidden]) {
    left:max(12px,env(safe-area-inset-left,0px))!important;
    right:max(12px,env(safe-area-inset-right,0px))!important;
    max-height:calc(100vh - 100px - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px));
    max-height:calc(100dvh - 100px - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px));
    scroll-padding-bottom:12px;
  }
  .table-secondary-actions[open] > .table-secondary-panel {
    max-height:calc(100vh - 100px - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px));
    max-height:calc(100dvh - 100px - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px));
  }
}
@media (max-width:900px) and (orientation:portrait) {
  /* The desktop grid begins at 821px in legacy sheets; tablet portrait
     must not retain its three narrow columns under the mobile action rail. */
  body:not(.is-setup) .controls.reference-hud {
    grid-template-columns:minmax(0,1fr);
    grid-template-areas:'hint' 'hand' 'action';
  }
  body:not(.is-setup) .reference-hud .hud-hand-frame { grid-area:hand; min-width:0; }
  body:not(.is-setup) .reference-hud .turn-actions { grid-area:action; }
  body:not(.is-setup) .reference-hud #scoreList { display:none; }
  /* Preserve the existing fan height; reserve a second rail row ONLY with voice. */
  body:not(.is-setup) .controls.reference-hud:has(.turn-actions > #voice-controls:not([hidden])) {
    height:calc(292px + env(safe-area-inset-bottom,0px));
    grid-template-rows:28px minmax(0,1fr) 108px;
  }
  body:not(.is-setup) .reference-hud .turn-actions:has(> #voice-controls:not([hidden])) {
    display:flex; flex-direction:row; flex-wrap:wrap; align-content:center;
    height:108px; min-height:108px; gap:4px 8px;
  }
  body:not(.is-setup) .reference-hud .turn-actions:has(> #voice-controls:not([hidden])) > .table-secondary-actions {
    flex:0 0 76px; width:76px;
  }
}
@media (max-width:360px) {
  body:not(.is-setup) .reference-hud .turn-actions #voice-controls button {
    font-size:11px; padding:6px;
    white-space:nowrap;
  }
  body:not(.is-setup) .reference-hud .turn-actions #voice-controls [role=status] {
    line-height:14px; max-height:28px; overflow:hidden;
  }
}
@media (max-width:900px) and (orientation:landscape) and (max-height:600px) {
  /* Legacy landscape is a side panel: do not import the desktop 3-column HUD
     into its 270–370px width (it previously left only 12px for the hand). */
  body:not(.is-setup) .controls.reference-hud {
    box-sizing:border-box; display:grid; grid-template-columns:minmax(0,1fr);
    grid-template-rows:28px minmax(90px,1fr) auto;
    grid-template-areas:'hint' 'hand' 'action';
    min-width:0; min-height:0; overflow-y:auto; overflow-x:hidden;
    padding:4px max(10px,env(safe-area-inset-right,0px)) max(8px,env(safe-area-inset-bottom,0px)) 10px;
    gap:6px; align-content:stretch;
  }
  body:not(.is-setup) .reference-hud .hud-hand-frame {
    grid-area:hand; display:block; min-width:0; min-height:0; overflow:hidden;
  }
  body:not(.is-setup) .reference-hud #hand {
    box-sizing:border-box; width:100%; height:100%; min-width:0; min-height:0;
    padding:14px 18px 20px; overflow-x:auto; overflow-y:hidden;
  }
  body:not(.is-setup) .reference-hud .turn-actions {
    grid-area:action; display:flex; flex-direction:row; flex-wrap:wrap;
    align-content:center; align-items:center; justify-content:center;
    width:100%; height:auto; min-height:48px; gap:4px 8px;
  }
  body:not(.is-setup) .reference-hud .turn-actions > button:not(#mobileChatToggle) {
    flex:1 1 0; width:auto; min-width:0;
  }
  body:not(.is-setup) .reference-hud .turn-actions > .table-secondary-actions {
    flex:0 0 76px; width:76px;
  }
  body:not(.is-setup) .reference-hud #scoreList { display:none; }
}
/* Touch tablets must not fall into the desktop-only 901–1200px gap:
   its chat and 3-column HUD previously expanded below the physical screen. */
@media (pointer:coarse) and (min-width:901px) and (max-width:1200px) {
  body:not(.is-setup) { overflow:hidden; }
  body:not(.is-setup) .app-shell {
    box-sizing:border-box; width:100%; max-width:none; margin:0; padding:6px;
    display:grid; height:100vh; height:100dvh; min-height:0; gap:4px;
    grid-template-columns:minmax(0,1fr);
    grid-template-rows:36px 40px minmax(0,1fr) 292px;
    grid-template-areas:'topbar' 'status' 'board' 'controls';
  }
  body:not(.is-setup) .topbar { grid-area:topbar; position:static; height:36px; min-height:0; margin:0; padding:0; }
  body:not(.is-setup) .status-strip { grid-area:status; min-height:0; margin:0; padding:2px 8px; overflow:hidden; }
  body:not(.is-setup) .board-wrap { grid-area:board; height:100%; min-height:0; margin:0; overflow:hidden; }
  body:not(.is-setup) #board, body:not(.is-setup) .poker-table { height:100%; min-height:0!important; max-height:none; }
  body:not(.is-setup) .controls.reference-hud {
    grid-area:controls; position:static; box-sizing:border-box; width:100%; height:292px;
    display:grid; grid-template-columns:minmax(0,1fr); grid-template-rows:28px minmax(0,1fr) 108px;
    grid-template-areas:'hint' 'hand' 'action'; padding:4px 8px; gap:4px; min-height:0;
  }
  body:not(.is-setup) .reference-hud .hud-hand-frame { grid-area:hand; min-height:0; min-width:0; overflow:hidden; }
  body:not(.is-setup) .reference-hud #hand { width:100%; height:100%; min-height:0; overflow-x:auto; }
  body:not(.is-setup) .reference-hud #scoreList { display:none; }
  body:not(.is-setup) .reference-hud .turn-actions {
    grid-area:action; position:relative; display:flex; flex-wrap:wrap; align-content:center;
    justify-content:center; gap:4px 8px; width:100%; height:108px; min-height:108px;
  }
  body:not(.is-setup) .reference-hud .turn-actions > #voice-controls:not([hidden]) {
    display:flex!important; flex:0 0 100%; flex-direction:row; flex-wrap:nowrap;
    box-sizing:border-box; width:100%; height:54px; min-height:54px; margin:0; padding:4px 6px;
    overflow-x:auto; align-items:center; gap:6px;
  }
  body:not(.is-setup) .reference-hud #voice-controls button { width:auto; height:44px; min-width:44px; flex-shrink:0; padding:6px 10px; font-size:12px; }
  body:not(.is-setup) .reference-hud #voice-controls [role=status] { min-width:0; max-height:28px; line-height:14px; overflow:hidden; }
  body:not(.is-setup) #mobileChatToggle:not([hidden]), body:not(.is-setup) #hudBtn { display:inline-flex; align-items:center; justify-content:center; min-width:44px; min-height:44px; }
  body:not(.is-setup) .log-panel { position:fixed; display:none; inset:48px 12px 12px auto; width:min(440px,90vw); z-index:840; overflow:auto; }
  body:not(.is-setup).hud-open .log-panel { display:block; }
  body:not(.is-setup) .table-secondary-actions { display:block; position:relative; width:76px; flex:0 0 76px; }
  body:not(.is-setup) .table-secondary-actions > summary { display:flex; align-items:center; justify-content:center; min-height:44px; cursor:pointer; }
  body:not(.is-setup) .table-secondary-actions:not([open]) > .table-secondary-panel { display:none; }
  body:not(.is-setup) .table-secondary-actions[open] > .table-secondary-panel {
    display:grid; position:absolute; right:0; bottom:calc(100% + 8px); width:240px; max-height:50dvh;
    padding:10px; gap:8px; background:#101e2bf5; border:1px solid #bda16b; border-radius:12px;
    z-index:850; overflow:auto;
  }
  body:not(.is-setup) .table-secondary-panel > button { min-height:44px; }
  body.chat111-open #inGameChat.chat111-drawer:not([hidden]) {
    display:block!important; position:fixed!important; inset:64px 12px 72px!important; width:auto!important;
    max-height:calc(100dvh - 136px); overflow:auto; z-index:830; padding:14px;
    background:#101e2bf5; border:1px solid #bda16b; border-radius:12px;
  }
  .chat111-drawer .chat111-close { display:block; min-height:44px; margin-bottom:10px; }
  .chat111-drawer .room-chat-feed { max-height:45dvh; overflow:auto; }
  .chat111-drawer .room-chat-compose { display:flex; gap:8px; }
  .chat111-drawer .room-chat-compose input { min-width:0; flex:1; }
}
