@media (max-width: 850px) {
  body { min-width: 0; }
  .screen { min-width: 0; }
  .join-screen,.lobby-screen { min-height: 100dvh; }
  .join-card,.lobby-card { min-width: 0; max-width: 100%; padding: 18px; border-radius: 17px; }
  .join-card h1 { font-size: clamp(29px, 9.5vw, 58px); }
  .avatar-picker { margin: 12px 0; }
  .avatar-current { width: 84px; height: 84px; font-size: 51px; }
  .lobby-card #lobby-room-code { font: 800 clamp(16px, 4.7vw, 26px)/1.25 ui-monospace, monospace; overflow-wrap: anywhere; }
  .invite-row input { min-width: 0; }
  .invite-row .small-action { min-height: 44px; }
  .lobby-card select,.lobby-card input { max-width: 100%; font-size: 16px; }
  .property-option { min-height: 64px; }
  .property-option small { font-size: 13px; line-height: 1.35; }
  .lobby-card .fam-pick,.lobby-card .room-action { min-height: 44px; }

  body.in-game { overflow: auto; }
  body.in-game main { height: auto; }
  #game-screen {
    --hand-width: clamp(67px, 22vw, 93px);
    --phone-dock-space: calc(var(--hand-width) * 1000 / 708 + 142px);
    display: block;
    height: auto;
    min-height: 100dvh;
    padding: 8px 8px calc(var(--phone-dock-space) + env(safe-area-inset-bottom));
  }
  #game-screen .game-header {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px 8px;
    margin-bottom: 8px;
  }
  #game-screen .brand { font-size: clamp(14px, 4.5vw, 21px); }
  #game-screen .brand small, #game-screen .room-pill { display: none; }
  #game-screen .header-tools { grid-column: 2; grid-row: 1; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  #game-screen .turn-banner { display: block; grid-column: 1/-1; grid-row: 2; max-width: none; width: 100%; white-space: normal; }
  #game-screen .game-header .room-actions { grid-row: 3; gap: 5px; }
  #game-screen .header-tools .sound-toggle,
  #game-screen .room-actions .room-action { min-height: 44px; min-width: 44px; }

  #game-screen .board-shell {
    height: auto;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'market' 'supplies' 'table';
    padding: 8px;
    gap: 8px;
  }
  #game-screen .market-rail {
    grid-area: market;
    z-index: 100;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    align-items: center;
  }
  #game-screen .market-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
  #game-screen .drawer-tab { padding: .3rem .45rem; }
  #game-screen .drawer-tab span { font-size: clamp(9px, 2.65vw, 12px); letter-spacing: 0; }
  #game-screen .special-actions { display: flex; flex-direction: row; gap: 5px; margin: 0; }
  body:not(.market-docked) #game-screen .small-action.wild-action,
  body:not(.market-docked) #game-screen .small-action.fam-action { width: 40px; min-height: 44px; }
  body:not(.market-docked) #game-screen .small-action.wild-action img,
  body:not(.market-docked) #game-screen .small-action.fam-action img,
  body:not(.market-docked) #game-screen .small-action.fam-action .buy-fam-thumb { width: 40px; height: 55px; object-fit: cover; }
  #game-screen .market-drawer .drawer-content {
    position: fixed;
    inset: auto 8px max(10px, env(safe-area-inset-bottom)) 8px;
    width: auto;
    max-height: min(475px, 78dvh);
    border-radius: 13px;
    box-shadow: 0 0 0 100vmax #10081772, 0 8px 35px #0e0618c9;
  }
  #game-screen .market-pin { display: none; }
  #game-screen .drawer-close { width: 44px; height: 44px; }
  #game-screen .drawer-cards { overscroll-behavior: contain; }

  #game-screen .supply-rail {
    grid-area: supplies;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 0;
    gap: 4px;
    border: 0;
  }
  #game-screen .supply-rail > :is(.supply-stack,.token-stack,.prize-mini,.vyal-stack,.chips-bank,.log-toggle) {
    min-width: 0; min-height: 44px; width: 100%; padding: 3px; gap: 3px;
  }
  #game-screen .supply-rail img { width: 24px; height: 30px; }
  #game-screen .supply-rail span { font-size: clamp(8px, 2.2vw, 11px); overflow-wrap: anywhere; }
  #game-screen .supply-rail span b { display: block; margin: 0; font-size: 13px; }
  #game-screen .supply-rail span br { display: none; }
  #game-screen .log-toggle { margin: 0; font-size: 11px; }

  #game-screen .table-stage { grid-area: table; display: block; height: auto; min-height: 0; padding: 8px; }
  #game-screen .players-orbit {
    position: relative; inset: auto; display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 8px;
    pointer-events: auto;
  }
  #game-screen .table-stage .player-seat {
    position: relative; inset: auto !important; transform: none !important;
    width: 100% !important; max-width: 390px; min-width: 0;
    margin: 0 auto; padding: 7px;
  }
  #game-screen .table-stage .player-seat .player-core {
    grid-template-columns: 29px minmax(0, 1fr) 39px !important; gap: 4px !important;
  }
  #game-screen .table-stage .player-seat .avatar-box { width: 29px !important; min-height: 58px !important; font-size: 21px !important; }
  #game-screen .table-stage .player-seat .familiar-card { width: 39px !important; min-height: 58px !important; }
  #game-screen .table-stage .player-seat .player-main { padding: 3px !important; min-height: 58px; }
  #game-screen .table-stage .player-seat .player-name { font-size: 11px !important; }
  #game-screen .table-stage .player-seat .main-resources { gap: 4px; }
  #game-screen .table-stage .player-seat .main-resources img { width: 13px !important; height: 13px !important; }
  #game-screen .table-stage .player-seat .main-resources span { font-size: 10px !important; }
  .player-seat .hp-bar span { font-size: 9px; white-space: nowrap; }
  #game-screen .table-stage .player-seat .seat-power {
    position: static; transform: none; margin: 0 0 5px; padding: 3px 6px; font-size: 11px;
  }
  .property-plate { width: 100%; min-width: 0; min-height: 36px; white-space: normal; overflow-wrap: anywhere; }

  #game-screen .self-dock {
    position: fixed;
    inset: auto 8px max(5px, env(safe-area-inset-bottom)) 8px;
    z-index: 80; padding: 7px; gap: 4px;
  }
  #game-screen .self-toolbar { display: grid; height: auto; gap: 4px; }
  #game-screen #self-stats { width: 100%; justify-content: space-between; gap: 5px; }
  #game-screen .self-name { min-width: 0; max-width: none; font-size: 13px; }
  #game-screen .self-meta { flex: 0 0 auto; gap: 4px; }
  #game-screen .stat-chip { font-size: 10px; padding: 3px 5px; }
  #game-screen .stat-chip.power { font-size: 10px; }
  #game-screen .dock-tools { flex-wrap: wrap; gap: 4px; }
  #game-screen .dock-tools button { min-height: 44px; height: auto; width: auto; padding: 4px 8px; font-size: 11px; }
  #game-screen .dock-tools .end-turn { margin-left: auto; }
  #game-screen .hand-zone { flex: none; align-items: end; gap: 7px; }
  #game-screen .hand-content { height: auto; min-width: 0; }
  #game-screen .hand-row {
    flex: none;
    height: calc(var(--hand-width) * 1000 / 708 + 9px);
    padding: 1px 2px 6px;
    touch-action: pan-x;
  }
  #game-screen .hand-row .card { height: calc(var(--hand-width) * 1000 / 708); min-height: 0; overflow: hidden; }
  #game-screen .hand-row .card-zoom { top: 3px; right: 3px; }
  #game-screen .self-piles { flex: 0 0 auto; gap: 4px; padding-bottom: 5px; }
  #game-screen .self-pile { width: 34px; font-size: 8px; }
  #game-screen .self-pile img { width: 32px; height: 46px; }
  #game-screen .self-pile b { width: 15px; height: 15px; font-size: 9px; }
  #game-screen .self-utilities { left: 0; right: 0; width: auto; }
  #game-screen .hand-row .card-zoom { width: 36px; height: 36px; font-size: 21px; }

  .modal { padding: 10px; }
  .modal .modal-card, #decision-modal .modal-card {
    max-height: calc(100dvh - 20px);
    padding: 16px;
    overflow: auto;
    overscroll-behavior: contain;
  }
  .modal-close { min-width: 44px; min-height: 44px; }
  .modal-card .target-button { min-height: 44px; }
  .activity-toast, .link-state, .waiting-banner { width: max-content; max-width: calc(100vw - 24px); overflow-wrap: anywhere; }
}

@media (max-width: 850px) and (max-height: 470px) and (orientation: landscape) {
  #game-screen { --hand-width: 62px; }
  #game-screen .self-dock { max-width: 520px; margin-inline: auto; }
}
