/* --- Mobile one-screen --------------------------- */
@media (max-width: 980px) {
  :root {
    --card-w: 46px;
    --card-h: 66px;
    --hand-card-w: calc(var(--card-w) * 1.12);
    --hand-card-h: calc(var(--card-h) * 1.12);
    --card-label-size: clamp(1.05rem, 6.6vw, 2rem);
    --edge-band-height: clamp(88px, 15vh, 112px);
    --pile-card-w: calc(var(--card-w) * 2);
    --pile-card-h: calc(var(--card-h) * 2);
  }
  body.game-active { overflow: hidden; }
  body.game-active .app-shell {
    height: var(--app-vh); padding: 0; gap: 0;
    grid-template-rows: auto minmax(0,1fr);
  }
  body.game-active .board { height: 100%; border-radius: 0; border: none; padding: 5px; gap: 5px; grid-template-rows: 1fr auto 1fr; }

  .app-shell { width: 100%; max-width: 100%; margin: 0; }
  .main-header { padding: 5px 8px; border-radius: 0; border-bottom: 1px solid #d8e7de; }
  .main-header h1 { font-size: 0.92rem; }
  .main-header p { display: none; }
  .status-pill { font-size: 0.72rem; padding: 2px 7px; }
  .phase-pill  { font-size: 1.44rem; padding: 2px 7px; }

  .opponent-row .row-head { padding: 3px 6px; }
  .opponent-row .row-head { height: var(--edge-band-height); }
  .player-name { font-size: 1.56rem; }
  .badge       { font-size: 0.68rem; padding: 1px 5px; }
  .card-back   { border-radius: 3px; border-width: 1px; }

  .meld-slots  { gap: 4px; }
  .phase-slot  { padding: 4px; min-height: clamp(92px, 13vh, 120px); gap: 3px; border-radius: 8px; }
  .phase-slot-label {
    display: block;
    width: 100%;
    font-size: clamp(0.82rem, 3.1vw, 1rem);
    line-height: 1.08;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .meld-slots.triple-slot .phase-slot-label {
    font-size: clamp(0.7rem, 2.4vw, 0.9rem);
  }
  .meld-slots.quad-slot .phase-slot-label {
    font-size: clamp(0.64rem, 2vw, 0.82rem);
  }
  .phase-action-btn { width: 24px; height: 24px; font-size: 0.8rem; border-radius: 6px; }
  .phase-add-btn { width: min(var(--hand-card-w), 100%); height: auto; aspect-ratio: 52 / 74; font-size: 0.9rem; }
  .phase-hit-btn {
    width: min(var(--hand-card-w), 100%);
    max-width: var(--hand-card-w);
    height: auto;
    aspect-ratio: 52 / 74;
    font-size: 0.86rem;
  }
  .stage-card  { width: 22px; min-width: 22px; height: 32px; border-radius: 4px; }
  .stage-card span, .stage-card .card-label { font-size: 0.7rem; }

  .board-center { gap: 8px; }
  .pile-btn  { width: 100%; min-height: 132px; padding: 5px 4px; border-radius: 10px; }
  .pile-stack, .pile-card-face { border-radius: 5px; }
  .pile-label { font-size: 1.24rem; }
  .pile-btn strong { font-size: 0.62rem; }

  .my-row  { gap: 4px; }
  :root {
    --phase-band-height: clamp(96px, 17vh, 140px);
  }
  .hand-row { padding: 5px; gap: 4px; border-radius: 8px; }
  .hand-meta {
    top: 4px;
    right: 34px;
    gap: 5px;
  }
  .hand-count-badge {
    min-width: 26px;
    height: 26px;
    font-size: 0.9rem;
    top: 4px;
    right: 6px;
    padding: 0 6px;
  }
  .hand-row .hand-count-badge {
    top: 4px;
    right: 40px;
  }
  .phase-index-badge {
    min-width: 26px;
    height: 26px;
    font-size: 0.9rem;
    padding: 0 6px;
  }
  #opponentPanel .phase-index-badge {
    top: 4px;
    right: 38px;
  }
  .hand-row .phase-index-badge {
    top: 4px;
    right: 72px;
  }
  .reaction-toggle-btn {
    width: 26px;
    height: 26px;
    right: 6px;
    top: 4px;
    bottom: auto;
    font-size: 0.82rem;
  }
  .reaction-panel {
    right: 6px;
    bottom: calc(100% + 4px);
    top: auto;
    width: min(200px, calc(100% - 12px));
    gap: 4px;
    padding: 6px;
  }
  .reaction-choice-btn {
    font-size: 0.74rem;
    padding: 5px 7px;
  }
  #opponentPanel .reaction-bubble,
  .hand-row .reaction-bubble {
    top: 34px;
    right: 6px;
    font-size: 0.74rem;
    max-width: min(190px, calc(100% - 12px));
  }
  .btn-discard { font-size: 0.72rem; padding: 4px 8px; min-height: 28px; }

  .my-hand-cards {
    flex-wrap: nowrap;
    justify-content: safe center;
    gap: 3px; padding: 8px 6px 4px;
    overflow-x: clip;
    overflow-y: visible;
    align-items: flex-end;
  }
  .my-hand-cards .card-obj {
    flex: 1 1 0;
    min-width: 0;
    max-width: var(--hand-card-w);
    width: min(var(--hand-card-w), 100%);
    height: auto;
    aspect-ratio: 52 / 74;
  }
  .card-obj.card-hand {
    height: auto; border-radius: 8px;
    box-shadow: 0 2px 4px rgba(20,35,55,.12);
  }
  .card-obj.card-slot {
    width: min(var(--hand-card-w), 100%);
    min-width: 0;
    max-width: var(--hand-card-w);
    height: auto;
    aspect-ratio: 52 / 74;
    border-radius: 6px;
  }
  .card-obj.card-pile, .draw-card-back { width: var(--pile-card-w); height: var(--pile-card-h); border-radius: 5px; }

  .toast { left: 8px; right: 8px; bottom: 8px; max-width: none; }
  .event-popup {
    top: 25%;
    width: calc(100vw - 22px);
    font-size: 1rem;
    padding: 16px 14px;
    border-radius: 14px;
  }
  .reaction-banner {
    top: 25%;
    width: calc(100vw - 22px);
    padding: 14px 62px 14px 12px;
    border-radius: 14px;
    font-size: 0.8rem;
  }
  .quick-match-sheet {
    width: calc(100vw - 22px);
    border-radius: 14px;
    padding: 12px;
  }
  .quick-match-btn-label {
    font-size: 0.92rem;
  }
  .quick-match-btn-time {
    min-width: 40px;
    margin-left: 7px;
    font-size: 0.9rem;
  }
  .quick-match-sections {
    grid-template-columns: 1fr;
  }
  .quick-match-grid {
    gap: 8px;
  }
  #quickMatchModeCards {
    grid-template-columns: 1fr;
  }
  .quick-match-card {
    min-height: 64px;
    padding: 9px 10px;
  }
  .quick-match-card strong {
    font-size: 1rem;
  }
  .lobby-grid { grid-template-columns: 1fr; }
  .mode-grid { grid-template-columns: 1fr; }
  .start-logo-showcase {
    width: 100%;
    border-radius: 12px;
    padding: 8px;
    margin-top: 8px;
    margin-bottom: 10px;
  }
  .start-logo-image { border-radius: 10px; }
  .settings-row { grid-template-columns: 1fr; }
  .phase-picker { grid-template-columns: 1fr; max-height: 180px; }
  .lobby-top .btn { width: 100%; }
  .lobby-top-actions {
    width: 100%;
    justify-content: stretch;
  }
  .join-row { flex-direction: column; align-items: center; }
  .join-row input, .join-row .btn {
    width: min(360px, 100%);
  }

  #lobbySection {
    padding: 12px;
    border-radius: 14px;
  }

  #lobbySection .lobby-top {
    padding: 10px;
    gap: 10px;
  }

  #lobbySection .lobby-title-block h2 {
    font-size: clamp(1.15rem, 5.8vw, 1.5rem);
  }

  #lobbySection .lobby-title-line {
    flex-direction: row;
    align-items: center;
  }

  #lobbySection #lobbyInfo {
    font-size: 0.95rem;
  }

  #lobbySection #roomInfo {
    font-size: 0.76rem;
    padding: 4px 9px;
  }

  #lobbySection .lobby-top-actions {
    min-width: 0;
    width: 100%;
    gap: 7px;
    grid-template-columns: 1fr;
  }

  #lobbySection .lobby-top-actions .btn {
    min-height: 42px;
    font-size: 1rem;
  }

  #lobbySection .lobby-grid {
    grid-template-columns: 1fr;
    margin-top: 10px;
    gap: 10px;
  }

  #lobbySection .settings-row {
    grid-template-columns: 1fr;
  }

  #lobbySection .mode-choice-cards {
    grid-template-columns: 1fr;
  }

  #lobbySection .count-choice-cards {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  #lobbySection .phase-mode-cards {
    grid-template-columns: 1fr 1fr;
  }

  #lobbySection .lobby-pane-phases {
    grid-column: auto;
  }

  #lobbySection .lobby-pane {
    padding: 11px;
    border-radius: 12px;
  }

  #lobbySection .lobby-pane h3 {
    font-size: 1.06rem;
    margin-bottom: 8px;
  }

  #lobbySection .player-chip {
    font-size: 1.02rem;
    padding: 9px 10px;
  }

  body.lobby-active .app-shell {
    height: auto;
    grid-template-rows: auto auto;
    padding: 0;
    gap: 0;
  }

  body.lobby-active .main-header {
    border-radius: 0;
  }

  body.lobby-active #lobbySection {
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
}

@media (max-width: 640px) {
  :root {
    --card-w: 40px;
    --card-h: 57px;
    --card-label-size: clamp(0.85rem, 3vw, 1.1rem);
    --pile-card-w: calc(var(--card-w) * 2);
    --pile-card-h: calc(var(--card-h) * 2);
  }
  .card-obj.card-hand,
  .card-obj.card-pile,
  .draw-card-back {
    width: var(--card-w);
    height: var(--card-h);
  }
  .card-obj.card-slot {
    width: min(var(--hand-card-w), 100%);
    min-width: 0;
    max-width: var(--hand-card-w);
    height: auto;
    aspect-ratio: 52 / 74;
  }
  .card-obj.card-pile,
  .draw-card-back {
    width: var(--pile-card-w);
    height: var(--pile-card-h);
  }
  .opponent-cards .card-back {
    flex: 1 1 0;
    min-width: 0;
    max-width: var(--hand-card-w);
    width: min(var(--hand-card-w), 100%);
    height: auto;
    aspect-ratio: 52 / 74;
  }
  .phase-slot-label {
    font-size: clamp(0.74rem, 3.2vw, 0.92rem);
  }
  .quick-match-grid {
    grid-template-columns: 1fr;
  }
  .quick-match-actions {
    justify-content: stretch;
  }
  .quick-match-actions .btn {
    flex: 1 1 0;
  }
  .phase-slot { min-height: 0; }
  .pile-btn { min-height: 60px; }
}

@media (max-width: 420px) {
  :root {
    --card-w: 34px;
    --card-h: 49px;
    --hand-card-w: calc(var(--card-w) * 1.1);
    --hand-card-h: calc(var(--card-h) * 1.1);
    --card-label-size: clamp(0.7rem, 2.8vw, 0.9rem);
    --pile-card-w: calc(var(--card-w) * 2);
    --pile-card-h: calc(var(--card-h) * 2);
  }

  .meld-slots { gap: 3px; }
  .phase-slot { padding: 3px; }
  .phase-slot-cards { gap: 2px; }

  .phase-slot-label {
    font-size: clamp(0.62rem, 2.8vw, 0.82rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.05;
  }

  .phase-action-btn { width: 20px; height: 20px; font-size: 0.7rem; }

  .player-name { font-size: 1.2rem; }
  .opponent-row .player-name { max-width: calc(100% - 96px); }
}
