/* JFun Gaming UI - Barah Tehni lobby, header, dialogs, history (Step 11)
   Loaded AFTER the page CSS and jfun-game.css. Everything is scoped under html body.jg-barah.
   PRESENTATION ONLY. The match screen (#screen-match, #board-wrap, board nodes, pieces, .bt-cap, player pills)
   is never restyled here: lobby rules are scoped to #screen-stake / #screen-search only. */

/* ---------- Page ---------- */
html body.jg-barah {
  background: var(--jf-page-bg); background-attachment: fixed; color: var(--text-color);
  font-family: var(--jg-font-body);
}
html body.jg-barah .container { max-width: 1200px; }

/* ---------- Lobby / setup screens: #screen-stake, #screen-search ---------- */
/* keep the last button clear of the floating footer (lobby only, not the board screen) */
html body.jg-barah #screen-stake,
html body.jg-barah #screen-search { padding-bottom: calc(var(--jf-nav-clear) + env(safe-area-inset-bottom, 0px)); }

html body.jg-barah #screen-stake .merged-card,
html body.jg-barah #screen-search .merged-card {
  padding: var(--ui-pad-lg, 16px);
}

/* section titles */
html body.jg-barah #screen-stake .jf-game-name,
html body.jg-barah #screen-stake .quick-bet-header span:first-child,
html body.jg-barah #screen-search .timer-title {
  font: 700 20px var(--jg-font-display); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-color); text-shadow: 0 0 14px var(--ui-accent-glow);
}
html body.jg-barah #screen-stake .jf-game-desc { font-size: 12px; color: var(--text-secondary); }
html body.jg-barah #screen-stake .quick-bet-header { min-height: 32px; margin-bottom: 8px; justify-content: space-between; }
html body.jg-barah #screen-stake .quick-bet-header span#cur-code {
  font: 600 12px var(--jg-font-body); color: var(--text-secondary); text-shadow: none;
}
html body.jg-barah #screen-search .timer-section { background: var(--jf-glass); border: 1px solid var(--jf-glass-border); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-radius: var(--jg-radius-sm); padding: 14px 10px; }
html body.jg-barah #screen-search .timer-display { font-family: var(--jg-font-display); font-size: 34px; font-variant-numeric: tabular-nums; }
html body.jg-barah #screen-search .timer-info-row { color: var(--text-secondary); }

/* stake amounts */
html body.jg-barah #screen-stake .quick-bet-buttons { gap: 8px; }
html body.jg-barah #screen-stake .quick-bet-btn {
  min-height: 56px; border-radius: 16px; background: var(--jf-glass); color: var(--text-color);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid var(--jf-glass-border); box-shadow: none; transform: none;
  font: 700 18px var(--jg-font-display); letter-spacing: 0.02em; touch-action: manipulation;
}
html body.jg-barah #screen-stake .quick-bet-btn { flex: 1 1 64px; min-width: 64px; padding: 0 8px; }
html body.jg-barah #screen-stake .quick-bet-btn:hover { transform: none; box-shadow: none; }
html body.jg-barah #screen-stake .quick-bet-btn:active { transform: scale(0.97); }
html body.jg-barah #screen-stake .quick-bet-btn.selected {
  background: var(--jf-grad); color: var(--ui-on-accent); border-color: transparent; box-shadow: var(--jg-glow);
}
html body.jg-barah #screen-stake .potential-win-box { border-radius: var(--jg-radius-sm); }
html body.jg-barah #screen-stake .win-value { font-family: var(--jg-font-display); font-variant-numeric: tabular-nums; }

/* primary action buttons (Find match, Go to match) */
html body.jg-barah #screen-stake .place-bet-btn {
  width: 100%; min-height: 52px; padding: 0 20px; border-radius: 14px; background: var(--jf-grad); color: var(--ui-on-accent);
  font: 700 19px var(--jg-font-display); letter-spacing: 0.04em; text-transform: uppercase;
  box-shadow: var(--jg-glow); transform: none; touch-action: manipulation;
}
html body.jg-barah #screen-stake .place-bet-btn:hover:not(:disabled) { transform: none; box-shadow: var(--jg-glow); }
html body.jg-barah #screen-stake .place-bet-btn:active:not(:disabled) { transform: scale(0.97); }
html body.jg-barah #screen-stake .place-bet-btn:disabled {
  background: var(--jg-surface-2); color: var(--text-secondary); box-shadow: none; opacity: 1;
}
html body.jg-barah #screen-stake #active-other-link { display: flex; align-items: center; justify-content: center; }
/* secondary action (Cancel search) */
html body.jg-barah #screen-search .jf-btn-outline {
  min-height: 52px; border-radius: 14px; background: transparent; border: 1.5px solid var(--jf-pink); color: var(--jf-active);
  font: 700 19px var(--jg-font-display); letter-spacing: 0.04em; text-transform: uppercase; touch-action: manipulation;
}
html body.jg-barah #screen-search .jf-btn-outline:hover { background: transparent; }
html body.jg-barah #screen-search .jf-btn-outline:active { transform: scale(0.97); }

/* notes, errors */
html body.jg-barah #screen-stake .jf-note { color: var(--text-secondary); }
html body.jg-barah #screen-stake .jf-error { color: var(--jg-bad); }
html body.jg-barah #screen-stake #low-balance a {
  color: var(--jf-active) !important; display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px;
}

/* searching / waiting text: subtle pulse (opacity only, off for reduced motion) */
@keyframes jg-barah-wait { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }
@media (prefers-reduced-motion: no-preference) {
  html body.jg-barah #screen-search .timer-title,
  html body.jg-barah #screen-search #search-sub { animation: jg-barah-wait 2s ease-in-out infinite; }
}

/* ---------- Dialogs (confirm, leave, result) ---------- */
html body.jg-barah .modal-content {
  padding: 20px; max-height: 100%; overflow-y: auto;
}
html body.jg-barah .modal-title {
  font: 700 20px var(--jg-font-display); text-transform: uppercase; letter-spacing: 0.06em;
}
html body.jg-barah .close-modal {
  min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; color: var(--text-color);
}
html body.jg-barah .modal-footer { flex-wrap: wrap; }
html body.jg-barah .modal-btn {
  flex: 1 1 120px;
  text-decoration: none;
  font: 700 19px var(--jg-font-display); text-transform: uppercase; touch-action: manipulation;
}
html body.jg-barah .modal-btn.confirm { background: var(--jf-grad); color: var(--ui-on-accent); box-shadow: var(--jg-glow); transform: none; filter: none; }
html body.jg-barah .modal-btn:active { transform: scale(0.97); }

/* ---------- Bottom nav (includes/bottom_nav.php): the pill + its size tokens come from jfun-game.css NAVIGATION; history page keeps its last card clear of it ---------- */
html body.jg-barah-history { padding-bottom: calc(var(--jf-nav-clear) + env(safe-area-inset-bottom, 0px)); }

/* ---------- History page ---------- */
html body.jg-barah-history .stats-container { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--ui-gap, 12px); }
html body.jg-barah-history .stat-card {
  min-width: 0; transform: none;
}
html body.jg-barah-history .stat-card-value { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
html body.jg-barah-history .referral-header h3,
html body.jg-barah-history .section-title {
  font: 700 20px var(--jg-font-display); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ui-text);
}
html body.jg-barah-history .history-cards-container { display: flex; flex-direction: column; gap: var(--ui-gap, 12px); }
html body.jg-barah-history .history-card {
  padding: var(--ui-pad-md, 12px); transform: none; min-width: 0;
}
html body.jg-barah-history .history-card:hover { transform: none; }
html body.jg-barah-history .amount-display { font-family: var(--jg-font-display); font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
html body.jg-barah-history .amount-display.positive { color: var(--ui-ok-text); }
html body.jg-barah-history .amount-display.negative { color: var(--ui-bad-text); }
@media (max-width: 599px) {
  html body.jg-barah-history .history-details { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
}
/* result badges: colours come from the kit pastel tokens (Won ok, Lost bad, Draw warn, Cancelled/refund info) */
html body.jg-barah-history .bet-type-badge {
  font: 700 12px var(--jg-font-body);
}
/* pagination = horizontally scrollable pill bar, 44px pills */
html body.jg-barah-history .pagination {
  justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
  gap: 8px; padding: 6px 2px; max-width: 100%;
}
html body.jg-barah-history .pagination-btn {
  flex: 0 0 auto; padding: 0 14px;
  display: inline-flex; align-items: center; justify-content: center;
  font: 700 19px var(--jg-font-display);
}
html body.jg-barah-history .pagination-btn:first-child { margin-left: auto; }
html body.jg-barah-history .pagination-btn:last-child { margin-right: auto; }
html body.jg-barah-history .empty-state .btn { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; border-radius: 14px; }

/* ---- Match screen (Barah Tehni) on the shared match UI (jfun-matchui.css): #bt-grid = chip row / board / chip row, #match-info = Stake | Prize | gear pill.
   The board is never flipped: red (seat 1) is drawn on top, blue (seat 2) at the bottom, so the red chip sits above and the blue chip below the board.
   The old cards, timer, captured line and Leave link live in .bt-hidden-legacy (kept in the DOM for game.js, never shown; .bt-fallback shows them if the shared UI did not load). */
html body.jg-barah .bt-hidden-legacy { display: none !important; }
html body.jg-barah #screen-match.bt-fallback .bt-hidden-legacy { display: block !important; }
html body.jg-barah #screen-match.bt-fallback > #bt-grid .jm-row { display: none; }
/* phone portrait: the fit layer makes the screen a flex column of the visible height; the grid takes the free height, the pill is the last item */
html body.jg-barah #screen-match.jf-fit > #bt-grid { flex: 1 1 0; min-height: 0; margin: 0; }
html body.jg-barah #bt-grid > #board-wrap { overflow: hidden; display: flex; }
html body.jg-barah #bt-grid .jm-row-top { margin-bottom: var(--ui-s2); }
html body.jg-barah #bt-grid .jm-row-bottom { margin-top: var(--ui-s2); }
html body.jg-barah #screen-match.jf-fit > #match-info.jm-bar { display: flex; flex: 0 0 auto; padding: var(--ui-s1) var(--ui-s1) var(--ui-s1) var(--ui-s4); font-size: var(--ui-fs-sm); margin: 0 auto calc(var(--ui-gap) + max(0px, env(safe-area-inset-bottom, 0px) - var(--jm-nav-h, 0px))); }
html body.jg-barah #screen-match:not(.jf-fit) > #match-info.jm-bar { margin-top: var(--ui-gap); }
/* wide / landscape: board + chips on the left, the pill in a side column (height is the scarce space) */
@media (min-width: 900px), (orientation: landscape) and (max-height: 520px) and (min-width: 560px) {
  html body.jg-barah #screen-match[style*="display: block"] { display: grid !important; grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: minmax(0, 1fr); grid-template-areas: "game info"; column-gap: 16px; align-items: stretch; }
  html body.jg-barah #screen-match > #bt-grid { grid-area: game; margin: 0; min-height: 0; }
  html body.jg-barah #screen-match > #match-info.jm-bar { grid-area: info; align-self: center; margin: 0; }
  html body.jg-barah #screen-match > .bt-hidden-legacy { grid-area: info; }
}
@media (orientation: landscape) and (max-height: 520px) and (min-width: 560px) and (max-width: 899px) {
  html body.jg-barah #screen-match[style*="display: block"] { grid-template-columns: minmax(0, 1fr) 240px; column-gap: 12px; }
}
/* short landscape: the two chips go to the LEFT of the board (red top-left, blue bottom-left) and the board takes the full height;
   the column gap leaves room for the round timer badge */
@media (orientation: landscape) and (max-height: 520px) and (min-width: 560px) {
  html body.jg-barah #bt-grid { grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top board" ". board" "bottom board"; column-gap: calc(var(--ui-s6) + var(--ui-s2)); }
  html body.jg-barah #bt-grid .jm-row { padding-left: 0; padding-top: 0; margin: 0; transform: none; }
  html body.jg-barah #bt-grid .jm-row-top { align-self: start; }
  html body.jg-barah #bt-grid .jm-row-bottom { align-self: end; }
}

/* pool / big pool icon discs: kit forces accent-text on .stat-card-icon (higher specificity); keep white icon on a deep-enough gradient (>= 3:1) */
html body.jg-barah.jg-ui.jg-ui .stat-card.pool-card .stat-card-icon { color: var(--ui-on-accent); background: linear-gradient(135deg, var(--ui-ok), var(--ui-ok-deep)); }
html body.jg-barah.jg-ui.jg-ui .stat-card.bigpool-card .stat-card-icon { color: var(--ui-on-accent); background: linear-gradient(135deg, var(--ui-flame), var(--ui-flame-deep)); }
