/* JFun Fit v1 - match screen fills the space above the footer. Active only while #screen-match has .jf-fit (set by jfun-fit.js). */

/* 1. Default: phone portrait, any width */
html body #screen-match.jf-fit[style*="display: block"] { display: flex !important; flex-direction: column; height: var(--jf-avail, auto); min-height: 0; overflow-x: hidden; overflow-y: auto; gap: 6px; }
html body #screen-match.jf-fit > #pills,
html body #screen-match.jf-fit > .timer-section,
html body #screen-match.jf-fit > #match-info,
html body #screen-match.jf-fit > .bt-cap,
html body #screen-match.jf-fit > div:last-child { flex: 0 0 auto; margin-top: 0; margin-bottom: 0; }
html body #screen-match.jf-fit > .jf-board-wrap { flex: 1 1 0; min-height: 0; margin: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }

/* 2. Wide / landscape: keep the grid areas of the game css, only give the screen a height */
@media (min-width: 900px), (orientation: landscape) and (max-height: 520px) and (min-width: 560px) {
  html body #screen-match.jf-fit[style*="display: block"] { display: grid !important; height: var(--jf-avail, auto); overflow-y: auto; column-gap: 16px; row-gap: 10px; }
  html body #screen-match.jf-fit > .jf-board-wrap { align-self: stretch; min-height: 0; margin: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; }
}

@media (orientation: landscape) and (max-height: 520px) and (min-width: 560px) and (max-width: 899px) {
  html body #screen-match.jf-fit[style*="display: block"] { column-gap: 12px; }
}

/* 3. Compact mode by screen height */
@media (max-height: 760px) {
  html body #screen-match.jf-fit .timer-section { padding: 6px 8px; margin: 0; }
  html body #screen-match.jf-fit .timer-title { font-size: 13px; }
  html body #screen-match.jf-fit .timer-display { font-size: 20px; }
  html body #screen-match.jf-fit .ld-dice { width: 40px; height: 40px; margin-top: 4px; }
  html body #screen-match.jf-fit .ld-roll { margin-top: 6px; }
  html body #screen-match.jf-fit .ld-hint { margin-top: 4px; }
  html body #screen-match.jf-fit #match-info { padding: 6px; font-size: 11px; margin: 0; }
  html body #screen-match.jf-fit .jf-player-row { margin: 0; gap: 6px; }
  html body #screen-match.jf-fit .jfpc { min-height: 0; max-height: 52px; padding: 4px 8px; }
  html body #screen-match.jf-fit .jfpc-av { width: 32px; height: 32px; font-size: 16px; }
}
@media (max-height: 640px) {
  html body #screen-match.jf-fit #roll-history,
  html body #screen-match.jf-fit #turn-hint,
  html body #screen-match.jf-fit .jfpc-sub { display: none !important; }
  html body #screen-match.jf-fit .ld-dice { width: 34px; height: 34px; }
  html body #screen-match.jf-fit .ld-roll { height: 38px; min-height: 38px; padding-top: 0; padding-bottom: 0; }
  html body #screen-match.jf-fit .jf-btn-text { font-size: 12px; }
}
@media (max-height: 540px) {
  html body #screen-match.jf-fit .timer-display { font-size: 16px; }
  html body #screen-match.jf-fit #match-info { display: none; }
  html body #screen-match.jf-fit > .bt-cap { font-size: 11px; }
  html body #screen-match.jf-fit .jfpc { max-height: 44px; }
  html body #screen-match.jf-fit .jfpc-av { width: 28px; height: 28px; font-size: 14px; }
}

/* 4. Tic Tac Toe board (CSS board, sized from --jf-board-px) */
html body.jg-tictactoe #screen-match.jf-fit .ttt-board { width: var(--jf-board-px, min(320px, 100%)); max-width: 100%; }
html body.jg-tictactoe #screen-match.jf-fit .ttt-board { max-height: 100%; }
@media (min-width: 900px) {
  html body.jg-tictactoe #screen-match.jf-fit .ttt-board { width: min(var(--jf-board-px, 380px), 460px); }
}
html body.jg-tictactoe #screen-match.jf-fit .ttt-cell { font-size: clamp(22px, calc(var(--jf-board-px, 320px) * 0.14), 60px); }

/* 5. Fix v2 - keep the player cards (and their TURN badge) clear of the sticky top bar */
html body #screen-match.jf-fit[style*="display: block"] { box-sizing: border-box; padding-top: 16px; scroll-padding-top: 16px; }
html body #screen-match.jf-fit .jfpc-flag { top: -8px; z-index: 2; }
