﻿/* BingoRon mobile vertical layout. Keep portrait/mobile-flow rules here. */
@media (max-width: 980px) {
  .app-header {
    grid-template-columns: 1fr auto;
  }

  .header-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 42px;
    gap: 8px;
    width: min(420px, 100%);
    justify-self: end;
  }

  .credits-button,
  .account-button {
    min-width: 0;
  }

  .account-button {
    justify-content: center;
  }

  .settings-button {
    width: 42px;
    min-width: 42px;
  }

  .top-nav {
    display: flex;
    grid-column: 1 / -1;
    width: 100%;
    justify-self: stretch;
    order: 3;
  }

  .top-nav button,
  .top-nav .nav-tab {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .market-shell,
  .preview-shell,
  .leaderboard-grid,
  .game-shell {
    grid-template-columns: 1fr;
  }

  .table-chat-panel {
    width: min(292px, calc(100% - 32px));
  }

  .filters-panel {
    position: static;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-block {
    border-right: 1px solid var(--line);
  }

  .panel-block:nth-child(2n),
  .panel-block:last-child {
    border-right: 0;
  }
}

@media (max-width: 680px) {
  :root {
    --mobile-page-gutter: 12px;
  }

  .app-header,
  .market-shell,
  .preview-shell,
  .leaderboard-shell,
  .game-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .app-header {
    grid-template-columns: 1fr;
    gap: 12px;
    align-items: stretch;
    overflow: hidden;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    padding-bottom: 10px;
  }

  .app-header > *,
  .market-main,
  .filters-panel,
  .preview-controls-panel,
  .preview-stage,
  .leaderboard-hero,
  .leaderboard-panel,
  .game-setup-panel,
  .game-stage {
    min-width: 0;
    max-width: calc(100vw - var(--mobile-page-gutter) - var(--mobile-page-gutter));
  }

  .brand-lockup {
    gap: 10px;
  }

  .brand-mark {
    width: 40px;
    border-radius: 9px;
  }

  .brand-logo {
    width: 36px;
    height: 36px;
  }

  .credits-button,
  .account-button {
    min-width: 0;
    padding: 0 10px;
  }

  .header-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 42px;
    gap: 6px;
    width: calc(100vw - var(--mobile-page-gutter) - var(--mobile-page-gutter));
    justify-self: stretch;
  }

  .settings-button {
    position: static;
    width: 42px;
    min-width: 42px;
    height: 42px;
    border-color: var(--line);
    background: #fff;
    color: var(--ink);
    box-shadow: none;
  }

  .account-button {
    justify-content: center;
  }

  .account-name {
    max-width: 92px;
  }

  .brand-lockup p {
    display: none;
  }

  .top-nav {
    display: flex;
    width: calc(100vw - var(--mobile-page-gutter) - var(--mobile-page-gutter));
    min-width: 0;
    max-width: 100%;
    justify-self: stretch;
    overflow: visible;
    border-radius: 10px;
  }

  .top-nav button,
  .top-nav .nav-tab {
    flex: 1 1 0;
    min-width: 0;
    padding: 8px 7px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .market-toolbar,
  .toolbar-controls,
  .game-toolbar,
  .game-actions {
    display: grid;
    align-items: stretch;
    width: 100%;
    gap: 10px;
  }

  .market-toolbar h2 {
    font-size: 1.45rem;
  }

  .toolbar-controls {
    grid-template-columns: 1fr;
  }

  .sort-control {
    min-width: 0;
    width: 100%;
  }

  .segmented-control {
    width: 100%;
  }

  .segmented-control button {
    flex: 1 1 0;
    min-width: 0;
  }

  .filters-panel {
    grid-template-columns: 1fr;
  }

  .stats-strip,
  .game-hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stats-strip article,
  .game-hud article {
    padding: 12px;
  }

  .panel-block,
  .panel-block:nth-child(2n) {
    border-right: 0;
  }

  .cards-grid,
  .cards-grid.compact {
    grid-template-columns: minmax(0, 1fr);
  }

  .collection-card-shell {
    width: min(100%, 360px);
    justify-self: center;
  }

  .preview-stage {
    min-height: 480px;
    padding: 16px;
  }

  .preview-card-slot {
    width: min(320px, calc(100vw - 48px));
  }

  .leaderboard-hero {
    display: grid;
  }

  .leaderboard-season-card {
    min-width: 0;
  }

  .leaderboard-row {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .leaderboard-score {
    grid-column: 2;
    justify-self: start;
  }

  .game-shell {
    gap: 14px;
  }

  .game-stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
  }

  .game-toolbar,
  .game-hud,
  .called-ball-strip,
  .game-cards-grid {
    grid-column: 1;
    grid-row: auto;
  }

  .game-setup-panel {
    overflow: hidden;
    width: calc(100vw - var(--mobile-page-gutter) - var(--mobile-page-gutter));
  }

  .game-control-header,
  .game-table-tabs,
  .game-join-block,
  .game-picker-block,
  .game-start-actions,
  .game-prize-table {
    padding: 12px;
  }

  .game-table-tabs {
    grid-template-columns: repeat(3, minmax(142px, 1fr));
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .game-table-button {
    scroll-snap-align: start;
  }

  .game-card-picker {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    max-height: none;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .game-selection-header {
    min-width: 0;
  }

  .game-selection-header strong {
    min-width: 0;
    overflow: hidden;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .game-picker-empty {
    flex: 0 0 100%;
    width: 100%;
    min-width: 0;
  }

  .game-picker-card {
    grid-template-columns: auto 40px minmax(132px, 1fr);
    min-width: 232px;
  }

  .game-picker-art,
  .game-picker-fallback {
    width: 40px;
  }

  .game-start-actions {
    grid-template-columns: 1fr 1fr;
  }

  .game-prize-table {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-prize-table div {
    display: grid;
    gap: 4px;
    align-content: start;
  }

  .game-toolbar {
    grid-template-columns: 1fr;
  }

  .game-toolbar h2 {
    font-size: 1.2rem;
    line-height: 1.2;
  }

  .game-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-actions button,
  .audio-action {
    min-width: 0;
    width: 100%;
  }

  .called-ball-strip {
    flex-wrap: nowrap;
    min-height: 58px;
    overflow-x: auto;
    padding: 8px;
    -webkit-overflow-scrolling: touch;
  }

  .called-ball,
  .called-ball-empty {
    flex: 0 0 auto;
  }

  .called-ball {
    width: 42px;
  }

  .game-cards-grid {
    min-height: 720px;
  }

  .game-cards-grid.table-theme-fiesta,
  .game-cards-grid.table-theme-beach,
  .game-cards-grid.table-theme-halloween {
    --theme-scene-height: 720px;
  }

  .table-chat-panel {
    top: auto;
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
    min-height: 0;
    height: min(46vh, 320px);
  }

  .credits-dialog,
  .settings-menu {
    top: auto;
    right: calc(8px + env(safe-area-inset-right, 0px));
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    left: calc(8px + env(safe-area-inset-left, 0px));
    width: auto;
    max-height: min(78vh, 640px);
    border-radius: 12px;
  }

  .game-cards-grid .game-empty {
    padding-right: 0;
    padding-bottom: min(46vh, 320px);
  }

  .win-row {
    grid-template-columns: 1fr;
  }

  .detail-drawer {
    width: 100vw;
    max-width: none;
    padding:
      calc(14px + env(safe-area-inset-top, 0px))
      calc(14px + env(safe-area-inset-right, 0px))
      calc(18px + env(safe-area-inset-bottom, 0px))
      calc(14px + env(safe-area-inset-left, 0px));
  }

  .drawer-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  :root {
    --mobile-page-gutter: 10px;
  }

  .app-header,
  .market-shell,
  .preview-shell,
  .leaderboard-shell,
  .game-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .brand-lockup h1 {
    font-size: 1rem;
  }

  .credits-button span {
    font-size: 0.7rem;
  }

  .credits-button small {
    font-size: 0.56rem;
  }

  .account-name {
    max-width: 72px;
  }

  .top-nav button {
    font-size: 0.78rem;
    padding: 8px 5px;
  }

  .stats-strip,
  .game-hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-hud span {
    font-size: 1.06rem;
  }

  .current-ball-tile span {
    font-size: 1.28rem;
  }

  .game-table-tabs {
    grid-template-columns: repeat(3, minmax(128px, 1fr));
  }

  .game-picker-card {
    min-width: 218px;
  }

  .game-actions {
    grid-template-columns: 1fr 1fr;
  }

  .called-ball {
    width: 38px;
  }

  .called-ball-face small {
    font-size: 0.38rem;
  }

  .called-ball-face strong {
    font-size: 0.78rem;
  }

  .settings-avatar-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .settings-daub-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 680px), (max-height: 520px) and (max-width: 980px) {
  html,
  body,
  .game-shell {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }

  html::-webkit-scrollbar,
  body::-webkit-scrollbar,
  .game-shell::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }

  .mobile-game-stepbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: calc(100vw - var(--mobile-page-gutter) - var(--mobile-page-gutter));
    margin: 0 auto;
    border: 1px solid rgba(216, 222, 223, 0.95);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    padding: 4px;
    box-shadow: 0 10px 22px rgba(29, 35, 41, 0.08);
    backdrop-filter: blur(10px);
  }

  .mobile-game-stepbar button {
    min-height: 34px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 900;
    cursor: pointer;
  }

  .mobile-game-stepbar button.active {
    background: var(--teal);
    color: #fff;
  }

  .mobile-game-stepbar button:disabled {
    color: rgba(107, 119, 128, 0.5);
    cursor: not-allowed;
  }

  .game-shell {
    display: block;
    min-height: auto;
    padding-top: 12px;
    padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  }

  .game-shell[data-mobile-step="rooms"] .game-stage,
  .game-shell[data-mobile-step="cards"] .game-stage,
  .game-shell[data-mobile-step="game"] .game-setup-panel {
    display: none;
  }

  .game-shell[data-mobile-step="rooms"] .game-setup-panel,
  .game-shell[data-mobile-step="cards"] .game-setup-panel {
    display: grid;
    width: calc(100vw - var(--mobile-page-gutter) - var(--mobile-page-gutter));
    max-width: none;
    margin: 12px auto 0;
    overflow: visible;
  }

  .game-shell[data-mobile-step="rooms"] .game-join-block,
  .game-shell[data-mobile-step="rooms"] .game-picker-block,
  .game-shell[data-mobile-step="rooms"] .mobile-card-confirm,
  .game-shell[data-mobile-step="rooms"] .game-start-actions,
  .game-shell[data-mobile-step="rooms"] .game-prize-table {
    display: none;
  }

  .game-shell[data-mobile-step="cards"] .game-control-header,
  .game-shell[data-mobile-step="cards"] .game-prize-table {
    display: none;
  }

  .game-shell[data-mobile-step="cards"] .game-join-block {
    display: grid;
    padding: 12px 14px;
  }

  .game-table-tabs {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
    overflow: visible;
    padding: 12px;
    scroll-snap-type: none;
  }

  .game-table-button {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px 12px;
    align-items: start;
    width: 100%;
    min-height: 150px;
    border-radius: 12px;
    padding: 14px;
    background:
      radial-gradient(circle at 90% 10%, rgba(214, 154, 25, 0.13), transparent 34%),
      #fff;
  }

  .game-table-button > strong {
    font-size: 1.08rem;
  }

  .game-table-button > small {
    justify-self: end;
    border-radius: 999px;
    background: rgba(24, 126, 127, 0.08);
    color: var(--teal);
    padding: 4px 9px;
    text-align: right;
  }

  .game-room-metrics {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .game-room-metric {
    display: grid;
    gap: 2px;
    border: 1px solid rgba(216, 222, 223, 0.82);
    border-radius: 8px;
    background: rgba(247, 250, 250, 0.86);
    padding: 8px;
  }

  .game-room-metric small {
    color: var(--muted);
    font-size: 0.66rem;
    font-weight: 900;
    text-transform: uppercase;
  }

  .game-room-metric strong {
    color: var(--ink);
    font-size: 0.88rem;
    line-height: 1.1;
  }

  .game-room-cta {
    display: flex;
    grid-column: 1 / -1;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    border-radius: 999px;
    background: var(--teal);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 900;
  }

  .game-card-picker {
    display: grid;
    gap: 10px;
    max-height: none;
    overflow: visible;
    padding: 0;
  }

  .game-picker-card {
    grid-template-columns: auto 54px minmax(0, 1fr);
    min-width: 0;
    width: 100%;
    min-height: 74px;
    border-radius: 10px;
    padding: 10px;
  }

  .game-picker-art,
  .game-picker-fallback {
    width: 54px;
  }

  .mobile-card-confirm {
    position: sticky;
    bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: minmax(92px, 0.42fr) minmax(0, 1fr);
    gap: 10px;
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    padding:
      10px
      12px
      calc(10px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -14px 28px rgba(29, 35, 41, 0.1);
    backdrop-filter: blur(10px);
  }

  .game-shell[data-mobile-step="game"] {
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(var(--mobile-page-gutter) * -1);
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
  }

  .game-shell[data-mobile-step="game"] .mobile-game-stepbar {
    left: var(--mobile-page-gutter);
    width: calc(100vw - var(--mobile-page-gutter) - var(--mobile-page-gutter));
    margin-left: var(--mobile-page-gutter);
  }

  .game-shell[data-mobile-step="game"] .game-stage {
    display: grid;
    grid-template-columns: minmax(320px, 0.88fr) minmax(430px, 1.12fr);
    grid-template-rows: auto auto minmax(460px, auto);
    width: 980px;
    max-width: none;
    min-width: 980px;
    padding: 12px 14px 28px;
  }

  .game-shell[data-mobile-step="game"] .game-toolbar {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    align-items: end;
    justify-content: space-between;
  }

  .game-shell[data-mobile-step="game"] .game-actions {
    display: flex;
    width: auto;
  }

  .game-shell[data-mobile-step="game"] .game-actions button,
  .game-shell[data-mobile-step="game"] .audio-action {
    width: auto;
    min-width: 108px;
  }

  .game-shell[data-mobile-step="game"] .game-hud {
    grid-column: 2;
    grid-row: 1 / span 2;
    grid-template-columns: repeat(5, minmax(96px, 1fr));
  }

  .game-shell[data-mobile-step="game"] .called-ball-strip {
    grid-column: 1;
    grid-row: 2;
    flex-wrap: wrap;
    overflow: visible;
  }

  .game-shell[data-mobile-step="game"] .called-ball {
    width: 46px;
  }

  .game-shell[data-mobile-step="game"] .game-cards-grid {
    grid-column: 1 / -1;
    grid-row: 3;
    min-height: 720px;
  }

  .game-shell[data-mobile-step="game"] .game-cards-grid.table-theme-fiesta,
  .game-shell[data-mobile-step="game"] .game-cards-grid.table-theme-beach,
  .game-shell[data-mobile-step="game"] .game-cards-grid.table-theme-halloween {
    --theme-scene-height: 720px;
  }

  .game-shell[data-mobile-step="game"] .table-chat-panel {
    top: 16px;
    right: 16px;
    bottom: auto;
    left: auto;
    width: min(320px, calc(100% - 32px));
    height: clamp(360px, 58vh, 520px);
    max-height: calc(100% - 32px);
  }

  .game-shell[data-mobile-step="game"] .game-cards-grid .game-empty {
    padding-right: min(356px, 40%);
    padding-bottom: 0;
  }
}

