/* Mobile & tablet layout — loaded after styles.css */

/* ---- Tablet (≤900px) ---- */
@media (max-width: 900px) {
  .shell {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .topbar {
    --topbar-height: 68px;
    height: 68px;
    gap: 16px;
  }

  .brand {
    font-size: 22px;
  }

  .landing {
    padding-top: 18px;
  }

  .games-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Rules panel is long — hide during play on smaller screens */
  .game-layout .rules {
    display: none;
  }
}

/* ---- Large phone (≤720px) ---- */
@media (max-width: 720px) {
  .header-note {
    display: none;
  }

  .topbar {
    --topbar-height: 60px;
    height: 60px;
    gap: 12px;
  }

  .brand {
    font-size: 21px;
  }

  .brand-mark {
    width: 24px;
    height: 24px;
    font-size: 14px;
  }

  footer {
    flex-direction: column;
    align-items: center;
    gap: 6px;
    height: auto;
    padding: 14px 0 max(14px, env(safe-area-inset-bottom));
    text-align: center;
  }

  /* Game shell — flex column; scroll lives in .game-area when needed */
  .game-screen {
    overflow: hidden;
  }

  .game-header {
    height: auto;
    min-height: 56px;
    padding: max(10px, env(safe-area-inset-top)) 14px 10px;
    flex-wrap: wrap;
    gap: 8px 10px;
  }

  .game-title {
    font-size: 20px;
    flex: 1 1 auto;
    min-width: 0;
  }

  .game-header-actions {
    flex: 1 1 100%;
    justify-content: space-between;
    gap: 10px;
  }

  .multiplayer-btn,
  .leave-multiplayer-btn,
  .header-auth-btn {
    padding: 10px 12px;
    font-size: 11px;
    flex: 1 1 auto;
    text-align: center;
    max-width: 100%;
  }

  .header-auth-panel {
    right: max(14px, env(safe-area-inset-right));
    left: max(14px, env(safe-area-inset-left));
    width: auto;
  }

  .round-note {
    font-size: 9px;
    white-space: nowrap;
  }

  .game-area {
    padding: 12px 8px max(12px, env(safe-area-inset-bottom));
    place-items: start center;
    align-content: start;
  }

  .game-layout {
    width: 100%;
  }

  /* Felt table */
  .table {
    padding: 14px 10px 12px;
    border-width: 5px;
    border-radius: 18px;
    min-height: min(70vh, 520px);
    min-height: min(70dvh, 520px);
  }

  .players {
    min-height: 400px;
  }

  .opponent.left,
  .opponent.right {
    top: 10%;
    bottom: calc(var(--table-hand-height) + 28px);
  }

  .card-stack {
    display: none;
  }

  .tichu-table .card-stack {
    display: flex;
  }

  .tichu-table .hand {
    justify-content: center;
    padding-left: var(--table-action-width);
    padding-right: var(--table-action-width);
  }

  .trick {
    width: 168px;
    height: 144px;
  }

  .table-message {
    top: 56%;
    white-space: normal;
    max-width: 92%;
    line-height: 1.4;
    font-size: 10px;
  }

  .hand-label {
    bottom: calc(var(--table-hand-height) + 4px);
    left: 8px;
    right: var(--table-action-width);
  }

  .hand {
    gap: 2px;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    transform: none;
    padding: 12px var(--table-action-width) 8px 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
    scrollbar-width: none;
  }

  .hand::-webkit-scrollbar {
    display: none;
  }

  .hand .game-card:not(.card-img) {
    width: 38px;
    height: 56px;
    font-size: 11px;
    flex: none;
  }

  .action-panel {
    bottom: 10px;
    right: 8px;
    z-index: 6;
  }

  .action-panel button,
  .pass-controls button {
    min-height: 40px;
    padding: 10px 12px;
  }

  /* Overlays & modals */
  .hearts-scorecard {
    width: min(440px, 96%);
    max-height: 88%;
    padding: 16px;
  }

  .hearts-scorecard h3 {
    font-size: 22px;
  }

  .pass-controls {
    top: 60%;
    width: min(320px, 94%);
  }

  .received-panel {
    top: 42%;
    width: min(300px, 94%);
    padding: 10px;
  }

  .wish-picker {
    top: 48%;
    width: min(340px, 94%);
  }

  .wish-picker.tichu-wish-picker {
    top: 32%;
  }

  .exchange-slots {
    top: 12%;
    gap: 6px;
  }

  .exchange-slot {
    min-width: 56px;
    padding: 6px;
  }

  /* Bridge */
  .bidding-box {
    width: min(430px, 96%);
    padding: 12px;
  }

  .table.bridge-bidding .bidding-box {
    bottom: calc(var(--table-hand-height) + 32px);
    max-height: min(36vh, 280px);
    max-height: min(36dvh, 280px);
  }

  .bid-btn {
    min-height: 38px;
  }

  .contract-banner {
    max-width: 94%;
    white-space: normal;
    text-align: center;
    line-height: 1.35;
  }

  /* Memory / Eights */
  .memory-board {
    gap: 6px;
    width: 100%;
  }

  .memory-board[data-cols="6"] .memory-card {
    height: 68px;
  }

  .memory-card {
    height: 76px;
  }

  .draw-pile {
    left: 2%;
    top: 36%;
    font-size: 9px;
  }

  .discard .game-card:not(.card-img) {
    width: 68px;
    height: 96px;
    font-size: 22px;
  }

  .suit-choices {
    top: 60%;
    width: min(300px, 94%);
  }

  /* Backgammon */
  .bg-players-banner {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
    margin-bottom: 10px;
  }

  .bg-player-chip {
    font-size: 18px;
    padding: 6px 14px;
  }

  .bg-vs {
    font-size: 13px;
  }

  .bg-hud {
    font-size: 10px;
    gap: 8px 12px;
  }

  /* Multiplayer lobby */
  .multiplayer-lobby {
    padding: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .lobby-panel,
  .multiplayer-panel {
    padding: 20px 16px;
    border-radius: 12px;
    max-height: calc(100dvh - 24px);
  }

  .lobby-panel h2,
  .multiplayer-panel h2 {
    font-size: 24px;
  }

  .lobby-invite-link {
    grid-template-columns: 1fr;
  }

  .lobby-primary,
  .lobby-secondary,
  .lobby-close,
  .lobby-invite {
    width: 100%;
    margin: 8px 0 0;
    padding: 12px;
    min-height: 44px;
  }

  .lobby-incoming-actions {
    flex-direction: column;
  }

  .lobby-incoming-actions button {
    width: 100%;
    min-height: 44px;
  }

  .lobby-field input {
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  /* Toast & wait overlays */
  .toast {
    left: 12px;
    right: 12px;
    bottom: max(16px, env(safe-area-inset-bottom));
    transform: none;
    width: auto;
    text-align: center;
  }

  .mp-wait-overlay {
    padding: 14px 12px;
  }

  .mp-wait-pulse {
    font-size: 17px;
  }

  .tichu-call-controls,
  .tichu-play-controls {
    flex-wrap: wrap;
    justify-content: center;
  }

  .tichu-prompt {
    top: 40%;
    width: min(400px, 96%);
    gap: 12px;
  }

  .tichu-call-controls button {
    flex: 1 1 100%;
    min-height: 44px;
  }

  .pass-controls.tichu-play-controls {
    bottom: calc(var(--table-hand-height) + 22px);
    left: 8px;
    right: var(--table-action-width);
  }
}

/* ---- Phone (≤620px) ---- */
@media (max-width: 620px) {
  .shell {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .landing {
    padding: 14px 0 20px;
  }

  .games-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .game-tile {
    min-height: 0;
  }

  .tile-copy {
    padding: 10px 11px;
  }

  .tile-copy h3 {
    font-size: 17px;
  }

  .tile-copy p:not(.game-number) {
    font-size: 10px;
    line-height: 1.3;
  }

  .tile-art {
    aspect-ratio: 246 / 208;
  }

  .play-button {
    padding: 6px 9px;
  }

  .game-area {
    padding: 8px 4px max(10px, env(safe-area-inset-bottom));
  }

  .table {
    min-height: 460px;
    padding: 12px 8px 10px;
  }

  .players {
    min-height: 360px;
  }

  .hand .game-card:not(.card-img) {
    width: 34px;
    height: 50px;
    font-size: 10px;
  }

  .hand-label {
    bottom: calc(var(--table-hand-height) + 2px);
    left: 8px;
    right: var(--table-action-width);
  }

  .trick {
    width: 140px;
    height: 120px;
  }

  .trick-card .game-card:not(.card-img) {
    width: 40px;
    height: 58px;
    font-size: 13px;
  }

  .table-message {
    top: 52%;
  }

  .table.bridge-bidding .bidding-box {
    bottom: calc(var(--table-hand-height) + 28px);
    max-height: min(32vh, 240px);
    max-height: min(32dvh, 240px);
  }

  .opponent .hand.dummy .game-card:not(.card-img) {
    width: 24px;
    height: 36px;
    font-size: 8px;
  }

  .memory-card {
    height: 68px;
    font-size: 20px;
  }

  .game-title {
    font-size: 18px;
  }

  .back span {
    display: none;
  }
}

/* ---- Small phone (≤480px) ---- */
@media (max-width: 480px) {
  .games-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .game-tile {
    height: auto;
    min-height: 0;
    flex-direction: row;
    align-items: stretch;
  }

  .game-tile:hover {
    transform: none;
  }

  .tile-art {
    width: 34%;
    aspect-ratio: auto;
    min-height: 96px;
    height: auto;
    align-self: stretch;
    flex: none;
  }

  .tile-copy {
    flex: 1;
    justify-content: center;
    padding: 12px 14px;
  }

  .players {
    min-height: 320px;
  }

  .table {
    min-height: 420px;
    border-radius: 14px;
  }

  .hand .game-card:not(.card-img) {
    width: 30px;
    height: 44px;
    font-size: 9px;
  }

  .bid-row {
    gap: 2px;
  }

  .bid-btn {
    font-size: 10px;
    padding: 8px 2px;
  }

  footer span {
    font-size: 8px;
    letter-spacing: 0;
  }
}

/* ---- Very small (≤360px) ---- */
@media (max-width: 360px) {
  .hand .game-card:not(.card-img) {
    width: 27px;
    height: 40px;
    font-size: 8px;
  }

  .game-tile .tile-art {
    width: 32%;
    aspect-ratio: auto;
    min-height: 88px;
  }
}
