/* ============================================================
   18-ingame-layout.css — In-game layout (final overrides)
   ============================================================ */

/* Game screen: left board fills height; right column scrolls so 2 cards are not clipped */
/* Bottom nav bar is hidden (display:none !important in 11-bottom-nav.css), so
   reserve 0 space for it instead of leaving an empty gap at the bottom of
   the select/game screens. */
:root { --nav-h: 0px; }

body.in-game { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px)); }

body.in-game #phase-game {
  display: flex !important;
  flex-direction: column;
  /* Prefer min-height over rigid height so Telegram WebView viewport glitches
     cannot collapse .game-main to 0 (black empty area under hist-bar). */
  min-height: calc(100vh - var(--nav-h) - env(safe-area-inset-bottom, 0px));
  min-height: calc(100dvh - var(--nav-h) - env(safe-area-inset-bottom, 0px));
  min-height: calc(var(--tg-vh, 100vh) - var(--nav-h) - env(safe-area-inset-bottom, 0px));
  height: auto;
  /* FIX: a floor with no ceiling (max-height: none) meant #phase-game itself
     had nothing stopping it from growing past the viewport — and with 2+
     cards, .call-side's natural content (ball + controls + every card
     stacked) is exactly what made it grow, because nothing below actually
     bounded it. .player-card-wrap's "flex:1 1 auto; min-height:0" (meant to
     make IT the one that scrolls) only works once some ancestor truly caps
     the available height; without that, #phase-game, .game-main, .left-col
     and .call-side all simply stretched to fit every card, so the whole page
     became one tall block and scrolling it to reach card 2/3 dragged the
     1-75 board (which never itself grew) up and out of view along with
     everything else. One card stayed inside the viewport by luck, not
     because anything was actually constrained, which is why only "more than
     one card" ever showed the problem. Mirroring min-height as a real
     max-height gives #phase-game the same ceiling it already has a floor
     for, so .player-card-wrap is finally the thing that's forced to shrink
     and scroll internally — the board and ball/controls now stay fixed at
     any card count, and overflow-y above stays a rare fallback (e.g. a very
     short/landscape viewport where even the chrome above .game-main does
     not fit) rather than the normal path for "I picked more than one card". */
  /* The 480px floor inside each max() is the same "never collapse to 0"
     guarantee the min-height comment above describes, applied to the new
     ceiling: a transient viewport-unit glitch clamps to 480px (enough for
     stats-row + hist-bar + a readable .game-main) instead of crushing
     #phase-game to 0. On any real device the calc() side is always the
     larger operand, so max() picks it and the ceiling behaves exactly like
     the viewport height. */
  max-height: max(480px, calc(100vh - var(--nav-h) - env(safe-area-inset-bottom, 0px)));
  max-height: max(480px, calc(100dvh - var(--nav-h) - env(safe-area-inset-bottom, 0px)));
  max-height: max(480px, calc(var(--tg-vh, 100vh) - var(--nav-h) - env(safe-area-inset-bottom, 0px)));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body.in-game .stats-row { flex: none; padding: 6px 8px 4px; }

body.in-game .stat-box { padding: 4px 2px; }

body.in-game .stat-label { line-height: 1.15; margin-bottom: 0; }

body.in-game .stat-value { line-height: 1.25; }

body.in-game .sound-round { width: 36px; height: 36px; font-size: 16px; }

body.in-game .hist-bar { flex: none; margin: 2px 8px 0; padding: 4px 8px; min-height: 0; }

body.in-game .game-main {
  flex: 1 1 auto;
  /* Never let the board+ball area collapse to zero height */
  min-height: min(52vh, 420px);
  padding: 6px 8px 6px;
  align-items: stretch;
  overflow: visible;
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
}

body.in-game .left-col { display: flex; flex-direction: column; min-height: 0; }

body.in-game .left-sticky {
  position: static;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

body.in-game .numbers-list {
  flex: 1 1 0;
  min-height: 280px;
  display: flex !important;
  flex-direction: column;
  max-height: none;
  overflow: hidden;
  padding: 5px 5px 6px;
  visibility: visible !important;
}

body.in-game .list-header { flex: none; padding-bottom: 3px; }

body.in-game .list-header span { padding: 1px 0; font-size: 13px; }

body.in-game .list-body {
  flex: 1 1 auto;
  min-height: 300px;
  gap: 3px;
  grid-template-rows: repeat(15, minmax(0, 1fr));
}

body.in-game .list-num {
  height: auto;
  min-height: 0;
  font-size: clamp(9px, 1.5vh, 12px);
  border-radius: 6px;
}

body.in-game .bottom-area { flex: none; padding: 6px 0 0; }

body.in-game .cards-count { font-size: 17px; line-height: 1.1; margin-bottom: 0; }

body.in-game .cards-count-row { margin-bottom: 3px; }

body.in-game .cards-icon { width: 30px; height: 30px; padding: 3px; gap: 1.5px; }

body.in-game .promo-marquee { padding: 4px 0; font-size: 10.5px; margin-bottom: 5px; }

body.in-game .refresh-big { padding: 7px; font-size: 12px; margin-bottom: 4px; border-radius: 10px; }

body.in-game .game-id { font-size: 10px; line-height: 1.2; }

/* The ball/draw/AUTO/BINGO controls never scroll - only the card list below
   them does (.player-card-wrap), and only a touch that starts on the cards
   can move it. A touch over the ball display has nothing to grab here.
   #phase-game above is now scrollable (overflow-y:auto, as a fallback for
   when the min-heights below add up to more than the real viewport) - so
   overflow:hidden on .call-side can no longer be what blocks that touch from
   moving anything: overflow:hidden never blocked scroll-chaining to an
   ancestor to begin with, it only clipped .call-side's own content. The
   touch-action:none on every .call-side child except .player-card-wrap,
   right below, is what actually keeps this guarantee, however this file's
   overflow values change in the future. */
body.in-game .call-side {
  min-height: 200px;
  max-height: none;
  gap: 6px;
  overflow: visible;
  align-items: stretch;
  display: flex !important;
  flex-direction: column;
  visibility: visible !important;
}

body.in-game .call-side > *:not(.player-card-wrap) {
  touch-action: none;
}

body.in-game .ball-sticky {
  position: static;
  padding: 0 0 6px;
  background: var(--bg);
}

body.in-game .current-ball { width: 78px; height: 78px; font-size: 25px; }

body.in-game .wait-msg {
  font-size: 14px;
  line-height: 1.5;
  margin-top: 10px;
  padding: 12px 14px;
  background: rgba(20, 24, 40, 0.92);
  border: 1px solid rgba(255, 180, 80, 0.35);
  border-radius: 12px;
  color: #f0e6d2;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}

body.in-game .player-card-wrap {
  flex: 1 1 auto;
  min-height: 0;
  margin-bottom: 0;
  padding-bottom: 4px;   /* was 20px — wasted empty space that hid the 2nd card */
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  /* On a viewport taller than the card needs (desktop Mini App window, or embedded inside
     another app's WebView), center the card group instead of leaving it top-pinned with dead
     space below. "safe" drops back to plain top-alignment the instant a 2nd card no longer
     fits, so the existing scroll-to-reveal-card-2 behavior below is unaffected either way. */
  display: flex;
  flex-direction: column;
  justify-content: safe center;
}

/* 2 cards: tighter stack so the second card is at least partially visible without scrolling */
body.in-game #player-cards.multi[data-count="2"] {
  gap: 6px;
  padding-bottom: 0;
}


@media (max-height: 640px) {
  body.in-game .promo-marquee { display: none; }
  body.in-game .current-ball { width: 68px; height: 68px; font-size: 22px; }
}
