/* JFun Gaming UI - Ludo lobby, header, dialogs, history (Step 9)
   Loaded AFTER the page CSS and jfun-game.css. Everything is scoped under html body.jg-ludo.
   PRESENTATION ONLY. The match screen (#screen-match, #board-wrap, dice, tokens, player pills)
   is never restyled here: lobby rules are scoped to #screen-stake / #screen-search only. */

/* ---------- Page ---------- */
html body.jg-ludo {
  background: var(--jf-page-bg); background-attachment: fixed; color: var(--text-color);
  font-family: var(--jg-font-body);
}
html body.jg-ludo .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-ludo #screen-stake,
html body.jg-ludo #screen-search { padding-bottom: calc(var(--jf-nav-clear) + env(safe-area-inset-bottom, 0px)); }

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

/* section titles */
html body.jg-ludo #screen-stake .jf-game-name,
html body.jg-ludo #screen-stake .quick-bet-header span:first-child,
html body.jg-ludo #screen-search .timer-title {
  font: 700 20px var(--jg-font-display); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-color); text-shadow: var(--ld-title-glow);
}
html body.jg-ludo #screen-stake .jf-game-desc { font-size: 12px; color: var(--text-secondary); }
html body.jg-ludo #screen-stake .quick-bet-header { min-height: 32px; margin-bottom: 8px; justify-content: space-between; }
html body.jg-ludo #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-ludo #screen-search .timer-section { background: var(--jg-surface-2); border-radius: var(--jg-radius-sm); padding: 14px 10px; }
html body.jg-ludo #screen-search .timer-display { font-family: var(--jg-font-display); font-size: 34px; font-variant-numeric: tabular-nums; }
html body.jg-ludo #screen-search .timer-info-row { color: var(--text-secondary); }

/* stake amounts + 2 / 4 player choice */
html body.jg-ludo #screen-stake .quick-bet-buttons { gap: 8px; }
html body.jg-ludo #screen-stake .quick-bet-btn,
html body.jg-ludo #screen-stake .jf-seg button {
  min-height: 56px; border-radius: 16px; background: var(--card-bg); color: var(--text-color);
  border: 1px solid var(--border-color); box-shadow: none; transform: none;
  font: 700 18px var(--jg-font-display); letter-spacing: 0.02em; touch-action: manipulation;
}
html body.jg-ludo #screen-stake .quick-bet-btn { flex: 1 1 64px; min-width: 64px; padding: 0 8px; }
html body.jg-ludo #screen-stake .quick-bet-btn:hover,
html body.jg-ludo #screen-stake .jf-seg button:hover { transform: none; box-shadow: none; }
html body.jg-ludo #screen-stake .quick-bet-btn:active,
html body.jg-ludo #screen-stake .jf-seg button:active { transform: scale(0.97); }
html body.jg-ludo #screen-stake .quick-bet-btn.selected,
html body.jg-ludo #screen-stake .jf-seg button.active {
  background: var(--jf-grad); color: var(--ui-on-accent); border-color: transparent; box-shadow: var(--jg-glow);
}
html body.jg-ludo #screen-stake .jf-seg {
  background: transparent; border: 0; padding: 0; gap: 8px; margin-bottom: 12px;
}
html body.jg-ludo #screen-stake .jf-seg button { flex: 1 1 0; padding: 0 8px; }
html body.jg-ludo #screen-stake .potential-win-box { border-radius: var(--jg-radius-sm); }
html body.jg-ludo #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-ludo #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-ludo #screen-stake .place-bet-btn:hover:not(:disabled) { transform: none; box-shadow: var(--jg-glow); }
html body.jg-ludo #screen-stake .place-bet-btn:active:not(:disabled) { transform: scale(0.97); }
html body.jg-ludo #screen-stake .place-bet-btn:disabled {
  background: var(--jg-surface-2); color: var(--text-secondary); box-shadow: none; opacity: 1;
}
html body.jg-ludo #screen-stake #active-other-link { display: flex; align-items: center; justify-content: center; }
/* secondary action (Cancel search) */
html body.jg-ludo #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-ludo #screen-search .jf-btn-outline:hover { background: transparent; }
html body.jg-ludo #screen-search .jf-btn-outline:active { transform: scale(0.97); }

/* notes, errors, search seats */
html body.jg-ludo #screen-stake .jf-note { color: var(--text-secondary); }
html body.jg-ludo #screen-stake .jf-error { color: var(--jg-bad); }
html body.jg-ludo #screen-stake #low-balance a {
  color: var(--jf-active) !important; display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px;
}
html body.jg-ludo #screen-search .jf-player-pill {
  min-height: 44px; border-radius: 16px; background: var(--card-bg); border: 1px solid var(--border-color); color: var(--text-color);
}
html body.jg-ludo #screen-search .jf-player-pill.active { border-color: var(--jf-pink); }

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

/* ---------- Dialogs (confirm, leave, result) ---------- */
html body.jg-ludo .modal-content {
  padding: 20px; max-height: 100%; overflow-y: auto;
}
html body.jg-ludo .modal-title {
  font: 700 20px var(--jg-font-display); text-transform: uppercase; letter-spacing: 0.06em;
}
html body.jg-ludo .close-modal {
  min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; color: var(--text-color);
}
html body.jg-ludo .modal-footer { flex-wrap: wrap; }
html body.jg-ludo .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-ludo .modal-btn.confirm { background: var(--jf-grad); color: var(--ui-on-accent); box-shadow: var(--jg-glow); transform: none; filter: none; }
html body.jg-ludo .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-ludo-history { padding-bottom: calc(var(--jf-nav-clear) + env(safe-area-inset-bottom, 0px)); }

/* ---------- History page ---------- */
html body.jg-ludo-history .stats-container { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--ui-gap, 12px); }
html body.jg-ludo-history .stat-card {
  min-width: 0; transform: none;
}
html body.jg-ludo-history .stat-card-value { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
html body.jg-ludo-history .referral-header h3,
html body.jg-ludo-history .section-title {
  font: 700 20px var(--jg-font-display); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ui-text);
}
html body.jg-ludo-history .history-cards-container { display: flex; flex-direction: column; gap: var(--ui-gap, 12px); }
html body.jg-ludo-history .history-card {
  padding: var(--ui-pad-md, 12px); transform: none; min-width: 0;
}
html body.jg-ludo-history .history-card:hover { transform: none; }
html body.jg-ludo-history .amount-display { font-family: var(--jg-font-display); font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
html body.jg-ludo-history .amount-display.positive { color: var(--ui-ok-text); }
html body.jg-ludo-history .amount-display.negative { color: var(--ui-bad-text); }
@media (max-width: 599px) {
  html body.jg-ludo-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-ludo-history .bet-type-badge {
  font: 700 12px var(--jg-font-body);
}
/* pagination = horizontally scrollable pill bar, 44px pills */
html body.jg-ludo-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-ludo-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-ludo-history .pagination-btn:first-child { margin-left: auto; }
html body.jg-ludo-history .pagination-btn:last-child { margin-right: auto; }
html body.jg-ludo-history .empty-state .btn { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; border-radius: 14px; }

/* ---------- Dark Pro board: dice (Ludo) ---------- */
html body.jg-ludo .ld-dice { background: var(--ld-die-face); border-color: var(--ld-die-border); color: var(--ld-pip); box-shadow: var(--ld-die-glow); }

/* ---- Real Dice Faces (Ludo) ---------- */
html body.jg-ludo .ld-dice { width: 56px; height: 56px; }
html body.jg-ludo .ld-dice.ld-face { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); padding: 8px; box-sizing: border-box; font-size: 0; }
html body.jg-ludo .ld-pip { width: 10px; height: 10px; margin: auto; border-radius: 50%; background: currentColor; box-shadow: 0 0 6px currentColor; }
html body.jg-ludo .ld-pip.off { visibility: hidden; }

/* ---- Wide / landscape layout (Ludo match screen) ---------- */
@media (min-width: 900px), (orientation: landscape) and (max-height: 520px) and (min-width: 560px) {
  html body.jg-ludo #screen-match[style*="display: block"] { display: grid !important; grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: auto auto 1fr; grid-template-areas: "board cards" "board info" "board ."; column-gap: 16px; row-gap: 10px; align-items: start; }
  html body.jg-ludo #screen-match > #pills { grid-area: cards; margin: 0; }
  html body.jg-ludo #screen-match > #match-info { grid-area: info; }
  /* chips on screen = #pills hidden: no empty "cards" row, so no gap above the info row (Leave Match now lives in the settings pop-up) */
  html body.jg-ludo #screen-match.ld-chips-on[style*="display: block"] { grid-template-rows: auto 1fr; grid-template-areas: "board info" "board ."; }
}
@media (orientation: landscape) and (max-height: 520px) and (min-width: 560px) and (max-width: 899px) {
  html body.jg-ludo #screen-match[style*="display: block"] { grid-template-columns: minmax(0, 1fr) 240px; column-gap: 12px; }
}

/* ---- 3D dice cube (Ludo) ---------- */
html body.jg-ludo .ld-dice { --ld-s: 56px; -webkit-perspective: calc(var(--ld-s) * 5); perspective: calc(var(--ld-s) * 5); box-sizing: border-box; position: relative; }
html body.jg-ludo #screen-match.jf-fit .ld-dice { --ld-s: 56px; }
@media (max-height: 760px) { html body.jg-ludo #screen-match.jf-fit .ld-dice { --ld-s: 40px; } }
@media (max-height: 640px) { html body.jg-ludo #screen-match.jf-fit .ld-dice { --ld-s: 34px; } }
html body.jg-ludo .ld-dice.ld-on { border-width: 0; background: transparent; padding: 0; display: block; font-size: 0; }
html body.jg-ludo .ld-dice.ld-on:not(.ld-tap) { box-shadow: var(--ld-die-glow); }
html body.jg-ludo .ld-dice .ld-dash { font-size: 26px; font-weight: 700; }
html body.jg-ludo .ld-dice.ld-on .ld-dash { display: none; }
html body.jg-ludo .ld-dice:not(.ld-on) .ld-cube { display: none; }
html body.jg-ludo .ld-cube { position: absolute; left: 0; top: 0; width: 100%; height: 100%; -webkit-transform-style: preserve-3d; transform-style: preserve-3d; -webkit-transform: rotateX(0deg) rotateY(0deg); transform: rotateX(0deg) rotateY(0deg); will-change: transform; }
html body.jg-ludo .ld-cf { position: absolute; left: 0; top: 0; width: 100%; height: 100%; box-sizing: border-box; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); padding: calc(var(--ld-s) * 0.15); border-radius: calc(var(--ld-s) * 0.22); background: var(--ld-die-face); border: 1px solid var(--ld-die-border); box-shadow: var(--ld-die-inset); color: var(--ld-pip); -webkit-backface-visibility: hidden; backface-visibility: hidden; }
html body.jg-ludo .ld-cf .ld-pip { width: calc(var(--ld-s) * 0.18); height: calc(var(--ld-s) * 0.18); box-shadow: none; }
html body.jg-ludo .ld-cf1 { -webkit-transform: translateZ(calc(var(--ld-s) / 2)); transform: translateZ(calc(var(--ld-s) / 2)); }
html body.jg-ludo .ld-cf6 { -webkit-transform: rotateY(180deg) translateZ(calc(var(--ld-s) / 2)); transform: rotateY(180deg) translateZ(calc(var(--ld-s) / 2)); }
html body.jg-ludo .ld-cf3 { -webkit-transform: rotateY(90deg) translateZ(calc(var(--ld-s) / 2)); transform: rotateY(90deg) translateZ(calc(var(--ld-s) / 2)); }
html body.jg-ludo .ld-cf4 { -webkit-transform: rotateY(-90deg) translateZ(calc(var(--ld-s) / 2)); transform: rotateY(-90deg) translateZ(calc(var(--ld-s) / 2)); }
html body.jg-ludo .ld-cf2 { -webkit-transform: rotateX(90deg) translateZ(calc(var(--ld-s) / 2)); transform: rotateX(90deg) translateZ(calc(var(--ld-s) / 2)); }
html body.jg-ludo .ld-cf5 { -webkit-transform: rotateX(-90deg) translateZ(calc(var(--ld-s) / 2)); transform: rotateX(-90deg) translateZ(calc(var(--ld-s) / 2)); }
html body.jg-ludo .ld-cube.show-1 { -webkit-transform: rotateX(0deg) rotateY(0deg); transform: rotateX(0deg) rotateY(0deg); }
html body.jg-ludo .ld-cube.show-2 { -webkit-transform: rotateX(-90deg) rotateY(0deg); transform: rotateX(-90deg) rotateY(0deg); }
html body.jg-ludo .ld-cube.show-3 { -webkit-transform: rotateX(0deg) rotateY(-90deg); transform: rotateX(0deg) rotateY(-90deg); }
html body.jg-ludo .ld-cube.show-4 { -webkit-transform: rotateX(0deg) rotateY(90deg); transform: rotateX(0deg) rotateY(90deg); }
html body.jg-ludo .ld-cube.show-5 { -webkit-transform: rotateX(90deg) rotateY(0deg); transform: rotateX(90deg) rotateY(0deg); }
html body.jg-ludo .ld-cube.show-6 { -webkit-transform: rotateX(0deg) rotateY(180deg); transform: rotateX(0deg) rotateY(180deg); }
html body.jg-ludo .ld-dice.rolling { animation: none; }
@media (prefers-reduced-motion: no-preference) {
  @-webkit-keyframes ld-spin-1 { from { -webkit-transform: rotateX(720deg) rotateY(720deg); } to { -webkit-transform: rotateX(0deg) rotateY(0deg); } }
  @keyframes ld-spin-1 { from { transform: rotateX(720deg) rotateY(720deg); } to { transform: rotateX(0deg) rotateY(0deg); } }
  html body.jg-ludo .ld-dice.rolling .ld-cube.show-1 { -webkit-animation: ld-spin-1 0.6s cubic-bezier(0.2, 0.7, 0.3, 1); animation: ld-spin-1 0.6s cubic-bezier(0.2, 0.7, 0.3, 1); }
  @-webkit-keyframes ld-spin-2 { from { -webkit-transform: rotateX(630deg) rotateY(720deg); } to { -webkit-transform: rotateX(-90deg) rotateY(0deg); } }
  @keyframes ld-spin-2 { from { transform: rotateX(630deg) rotateY(720deg); } to { transform: rotateX(-90deg) rotateY(0deg); } }
  html body.jg-ludo .ld-dice.rolling .ld-cube.show-2 { -webkit-animation: ld-spin-2 0.6s cubic-bezier(0.2, 0.7, 0.3, 1); animation: ld-spin-2 0.6s cubic-bezier(0.2, 0.7, 0.3, 1); }
  @-webkit-keyframes ld-spin-3 { from { -webkit-transform: rotateX(720deg) rotateY(630deg); } to { -webkit-transform: rotateX(0deg) rotateY(-90deg); } }
  @keyframes ld-spin-3 { from { transform: rotateX(720deg) rotateY(630deg); } to { transform: rotateX(0deg) rotateY(-90deg); } }
  html body.jg-ludo .ld-dice.rolling .ld-cube.show-3 { -webkit-animation: ld-spin-3 0.6s cubic-bezier(0.2, 0.7, 0.3, 1); animation: ld-spin-3 0.6s cubic-bezier(0.2, 0.7, 0.3, 1); }
  @-webkit-keyframes ld-spin-4 { from { -webkit-transform: rotateX(720deg) rotateY(810deg); } to { -webkit-transform: rotateX(0deg) rotateY(90deg); } }
  @keyframes ld-spin-4 { from { transform: rotateX(720deg) rotateY(810deg); } to { transform: rotateX(0deg) rotateY(90deg); } }
  html body.jg-ludo .ld-dice.rolling .ld-cube.show-4 { -webkit-animation: ld-spin-4 0.6s cubic-bezier(0.2, 0.7, 0.3, 1); animation: ld-spin-4 0.6s cubic-bezier(0.2, 0.7, 0.3, 1); }
  @-webkit-keyframes ld-spin-5 { from { -webkit-transform: rotateX(810deg) rotateY(720deg); } to { -webkit-transform: rotateX(90deg) rotateY(0deg); } }
  @keyframes ld-spin-5 { from { transform: rotateX(810deg) rotateY(720deg); } to { transform: rotateX(90deg) rotateY(0deg); } }
  html body.jg-ludo .ld-dice.rolling .ld-cube.show-5 { -webkit-animation: ld-spin-5 0.6s cubic-bezier(0.2, 0.7, 0.3, 1); animation: ld-spin-5 0.6s cubic-bezier(0.2, 0.7, 0.3, 1); }
  @-webkit-keyframes ld-spin-6 { from { -webkit-transform: rotateX(720deg) rotateY(900deg); } to { -webkit-transform: rotateX(0deg) rotateY(180deg); } }
  @keyframes ld-spin-6 { from { transform: rotateX(720deg) rotateY(900deg); } to { transform: rotateX(0deg) rotateY(180deg); } }
  html body.jg-ludo .ld-dice.rolling .ld-cube.show-6 { -webkit-animation: ld-spin-6 0.6s cubic-bezier(0.2, 0.7, 0.3, 1); animation: ld-spin-6 0.6s cubic-bezier(0.2, 0.7, 0.3, 1); }
}
@media (prefers-reduced-motion: reduce) {
  html body.jg-ludo .ld-dice, html body.jg-ludo .ld-cube { animation: none !important; transition: none !important; }
}

/* ---- Dice floor shadow + landing pop (Ludo) ----------
   The dice (#board-wrap > #dice-box) sits in the yard of the player whose roll it is and appears there at once (see dashboard.css
   "Ludo dice in the roller's yard"). It only spins in place (ld-spin-N on .ld-cube above). The outer box is never moved by an
   animation or transition: the landing pop keeps translate(-50%, -50%) and only scales (max 1.06). No bounce. */
html body.jg-ludo .ld-dice::after { content: ""; position: absolute; left: 12%; width: 76%; bottom: calc(var(--ld-s) * -0.14); height: calc(var(--ld-s) * 0.14); border-radius: 50%; background: radial-gradient(ellipse at center, var(--ld-die-floor) 0%, transparent 75%); opacity: 0.55; pointer-events: none; z-index: -1; display: none; }
html body.jg-ludo .ld-dice.ld-on::after { display: block; }
@media (prefers-reduced-motion: no-preference) {
  @-webkit-keyframes ld-land { 0% { -webkit-transform: translate(-50%, -50%) scale(calc(var(--ld-k, 0.7) * 1.06)); } 100% { -webkit-transform: translate(-50%, -50%) scale(var(--ld-k, 0.7)); } }
  @keyframes ld-land { 0% { transform: translate(-50%, -50%) scale(calc(var(--ld-k, 0.7) * 1.06)); } 100% { transform: translate(-50%, -50%) scale(var(--ld-k, 0.7)); } }
  html body.jg-ludo .ld-dice.landed { -webkit-animation: ld-land 0.22s ease-out; animation: ld-land 0.22s ease-out; }
}
@media (prefers-reduced-motion: reduce) {
  html body.jg-ludo .ld-dice.rolling, html body.jg-ludo .ld-dice.landed { -webkit-animation: none !important; animation: none !important; }
}

/* 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-ludo.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-ludo.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)); }
