/* Custom-room mobile companion: the livestream is the only ball caller. */

@media (max-width: 980px) {
  body.custom-room-companion {
    --companion-header-height: 54px;
    --companion-tool-dock-height: calc(76px + env(safe-area-inset-bottom, 0px));
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    width: 100svw;
    height: 100svh;
    overflow: hidden;
    background: #000;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] {
    position: fixed;
    inset: 0;
    display: block;
    width: 100svw;
    height: 100svh;
    min-height: 0;
    overflow: hidden;
    background: #000;
    padding:
      calc(6px + env(safe-area-inset-top, 0px))
      calc(6px + env(safe-area-inset-right, 0px))
      calc(6px + env(safe-area-inset-bottom, 0px))
      calc(6px + env(safe-area-inset-left, 0px));
    transform: none;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .game-stage {
    display: flex !important;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    background: #000;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .focused-game-header {
    position: relative;
    z-index: 30;
    display: grid;
    flex: 0 0 var(--companion-header-height);
    grid-template-columns: minmax(0, 1fr) auto 42px;
    align-items: center;
    width: 100%;
    min-height: var(--companion-header-height);
    border: 1px solid rgba(102, 187, 255, 0.18);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(9, 19, 31, 0.98), rgba(2, 7, 13, 0.98));
    padding: 5px 5px 5px 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .focused-game-brand {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .focused-game-brand img {
    width: 34px;
    height: 34px;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .focused-game-brand strong {
    overflow: hidden;
    color: #fff;
    font-size: 1rem;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .called-ball-exit {
    position: static;
    display: block;
    grid-column: 3;
    justify-self: end;
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    border: 0;
    border-radius: 50%;
    background: #fff url("assets/Icons/Cancel.png") center / 76% 76% no-repeat;
    padding: 0;
    color: transparent;
    font-size: 0;
    box-shadow: 0 5px 16px rgba(0, 0, 0, 0.32);
  }

  body.custom-room-companion .companion-signup-button {
    grid-column: 2;
    min-width: 66px;
    min-height: 34px;
    border: 1px solid rgba(132, 214, 255, 0.8);
    border-radius: 9px;
    background: linear-gradient(180deg, #238ee9, #0648a9 58%, #032f7b);
    padding: 0 10px;
    color: #fff;
    font: 800 0.72rem/1 system-ui, sans-serif;
    letter-spacing: 0;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.46), 0 4px 12px rgba(0, 80, 190, 0.28);
  }

  body.custom-room-companion .companion-identity-row:not([hidden]) {
    position: relative;
    z-index: 25;
    display: grid;
    flex: 0 0 34px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px;
    width: 100%;
    min-height: 34px;
    border: 1px solid rgba(102, 187, 255, 0.16);
    border-radius: 10px;
    background: rgba(5, 15, 25, 0.98);
    padding: 3px 5px 3px 9px;
    color: rgba(214, 232, 244, 0.7);
    font: 700 0.65rem/1 system-ui, sans-serif;
  }

  body.custom-room-companion .companion-identity-row strong {
    overflow: hidden;
    color: #fff;
    font-size: 0.78rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.custom-room-companion .companion-identity-row.offline-replay:not([hidden]) {
    grid-template-columns: minmax(0, 1fr);
    min-height: 38px;
    padding: 5px 10px;
    border-color: rgba(255, 209, 87, 0.34);
    background: linear-gradient(180deg, rgba(48, 34, 7, 0.98), rgba(20, 14, 3, 0.98));
  }

  body.custom-room-companion .companion-identity-row.offline-replay strong {
    color: #ffe58a;
    font-size: clamp(0.68rem, 2.9vw, 0.82rem);
    line-height: 1.2;
    text-align: center;
    white-space: normal;
  }

  body.custom-room-companion .companion-identity-row button {
    min-height: 26px;
    border: 1px solid rgba(108, 209, 203, 0.5);
    border-radius: 7px;
    background: rgba(38, 129, 139, 0.24);
    padding: 0 9px;
    color: #8ce4df;
    font: 800 0.63rem/1 system-ui, sans-serif;
    letter-spacing: 0;
  }

  body.custom-room-companion .companion-name-dialog {
    width: min(360px, calc(100svw - 28px));
    max-width: none;
    border: 1px solid rgba(107, 203, 255, 0.38);
    border-radius: 16px;
    background: linear-gradient(180deg, #0b1d2e, #040b12);
    padding: 0;
    color: #fff;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.72);
  }

  body.custom-room-companion .companion-name-dialog::backdrop {
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(3px);
  }

  body.custom-room-companion .companion-name-form {
    display: grid;
    gap: 10px;
    padding: 15px;
  }

  body.custom-room-companion .companion-name-form header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 38px;
    align-items: start;
    gap: 12px;
  }

  body.custom-room-companion .companion-name-form h2 {
    margin: 2px 0 0;
    color: #fff;
    font-size: 1.22rem;
    line-height: 1.1;
  }

  body.custom-room-companion .companion-name-form .field-label {
    color: rgba(226, 240, 249, 0.78);
  }

  body.custom-room-companion .companion-name-form .text-input {
    border-color: rgba(116, 202, 240, 0.42);
    background: rgba(255, 255, 255, 0.96);
    color: #17202a;
  }

  body.custom-room-companion .companion-name-form p {
    min-height: 30px;
    margin: 0;
    color: rgba(211, 230, 241, 0.7);
    font-size: 0.72rem;
    line-height: 1.35;
  }

  body.custom-room-companion .companion-name-form p.error {
    color: #ff9388;
  }

  body.custom-room-companion .companion-name-close {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 9px;
    background: #fff;
    padding: 4px;
  }

  body.custom-room-companion .companion-name-close img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] :is(
    .game-room-header-banner,
    .game-toolbar,
    .game-hud,
    .called-ball-row,
    .win-ledger,
    .other-player-cards-zone,
    .game-celebration-overlay
  ) {
    display: none !important;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .creator-control-row:not([hidden]) {
    position: relative;
    z-index: 20;
    display: block;
    flex: 0 0 auto;
    min-height: 36px;
    overflow-x: auto;
    border: 1px solid rgba(102, 187, 255, 0.16);
    border-radius: 11px;
    background: rgba(7, 16, 27, 0.96);
    padding: 3px;
    scrollbar-width: none;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .creator-control-row::-webkit-scrollbar {
    display: none;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .creator-draw-controls:not([hidden]) {
    display: grid;
    grid-template-columns: repeat(6, minmax(74px, 1fr));
    gap: 4px;
    min-width: 478px;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] :is(.creator-room-code, .creator-control-button) {
    min-width: 0;
    min-height: 30px;
    border-radius: 8px;
    padding: 0 7px;
    font-size: 0.62rem;
    white-space: nowrap;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .game-cards-grid {
    --companion-card-width: min(84vw, 360px);
    position: relative;
    display: flex !important;
    flex: 1 1 auto;
    align-items: center;
    justify-content: flex-start;
    gap: 14px;
    width: 100%;
    min-height: 0 !important;
    height: auto;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: max(12px, calc((100vw - var(--companion-card-width)) / 2));
    overscroll-behavior: contain;
    border: 0;
    border-radius: 16px;
    background: #000 !important;
    padding:
      10px
      max(12px, calc((100vw - var(--companion-card-width)) / 2))
      calc(var(--companion-tool-dock-height) + 6px);
    box-shadow: none;
    scrollbar-width: none;
    touch-action: pan-x;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .game-cards-grid::-webkit-scrollbar {
    display: none;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .game-card-frame {
    position: relative;
    top: auto;
    left: auto;
    flex: 0 0 var(--companion-card-width);
    width: var(--companion-card-width) !important;
    max-width: 360px;
    margin: 0;
    scroll-snap-align: center;
    scroll-snap-stop: always;
    transform: none !important;
    touch-action: manipulation;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .game-card-frame .bingo-card {
    aspect-ratio: 5 / 5.35;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .game-card-footer {
    min-height: 42px;
    border-radius: 0 0 10px 10px;
    font-size: 0.82rem;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .game-empty {
    flex: 0 0 min(86vw, 360px);
    align-self: center;
    min-height: 180px;
    margin: auto;
    border: 1px solid rgba(102, 187, 255, 0.2);
    background: rgba(8, 18, 29, 0.96);
    color: rgba(231, 244, 255, 0.82);
  }

  body.custom-room-companion .mobile-game-quick-tools {
    position: fixed;
    z-index: 4800;
    inset: auto 0 0;
    display: block;
    height: var(--companion-tool-dock-height);
    border-top: 1px solid rgba(102, 187, 255, 0.12);
    background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.94) 24%);
    pointer-events: none;
  }

  body.custom-room-companion.offline-replay-mode {
    --companion-tool-dock-height: env(safe-area-inset-bottom, 0px);
  }

  body.custom-room-companion.offline-replay-mode .mobile-game-quick-tools {
    display: none !important;
  }

  body.custom-room-companion .mobile-quick-tool-battlepass {
    display: none !important;
  }

  body.custom-room-companion .mobile-quick-tool-chat,
  body.custom-room-companion:not(.mobile-chat-collapsed) .mobile-quick-tool-chat {
    position: fixed;
    right: calc(14px + env(safe-area-inset-right, 0px));
    bottom: calc(9px + env(safe-area-inset-bottom, 0px));
    left: auto;
    width: clamp(92px, 24vw, 112px);
    min-width: 0;
    min-height: 0;
    aspect-ratio: 3 / 2;
    border: 0;
    border-radius: 0;
    background: transparent !important;
    padding: 0;
    box-shadow: none;
    pointer-events: auto;
  }

  body.custom-room-companion.mobile-chat-open .game-shell[data-mobile-step="game"] .table-chat-panel {
    position: fixed;
    z-index: 4900;
    top: auto;
    right: calc(8px + env(safe-area-inset-right, 0px));
    bottom: calc(var(--companion-tool-dock-height) + 6px);
    left: calc(8px + env(safe-area-inset-left, 0px));
    width: auto;
    height: min(430px, calc(100svh - var(--companion-header-height) - var(--companion-tool-dock-height) - 34px));
    min-height: min(250px, calc(100svh - var(--companion-header-height) - var(--companion-tool-dock-height) - 34px));
    max-height: calc(100svh - var(--companion-header-height) - var(--companion-tool-dock-height) - 34px);
    border-radius: 14px;
    transform: translateY(calc(-1 * var(--mobile-chat-lift, 0px)));
    transition: transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: transform;
  }

  body.custom-room-companion.chat-keyboard-active.mobile-chat-open .game-shell[data-mobile-step="game"] .table-chat-panel {
    bottom: calc(var(--companion-tool-dock-height) + 6px);
  }
}

@media (max-width: 980px) and (orientation: landscape) {
  body.custom-room-companion {
    --companion-header-height: 48px;
    --companion-tool-dock-height: calc(60px + env(safe-area-inset-bottom, 0px));
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .game-cards-grid {
    --companion-card-width: min(42vw, calc((100svh - var(--companion-header-height) - var(--companion-tool-dock-height) - 72px) * 0.92), 300px);
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .focused-game-brand img {
    width: 30px;
    height: 30px;
  }

  body.custom-room-companion .game-shell[data-mobile-step="game"] .focused-game-brand strong {
    font-size: 0.9rem;
  }

  body.custom-room-companion .mobile-quick-tool-chat,
  body.custom-room-companion:not(.mobile-chat-collapsed) .mobile-quick-tool-chat {
    width: 84px;
  }

  body.custom-room-companion.mobile-chat-open .game-shell[data-mobile-step="game"] .table-chat-panel {
    right: calc(8px + env(safe-area-inset-right, 0px));
    left: auto;
    width: min(360px, 46vw);
  }
}
