/* JFun Match UI v1 - shared match-screen component (avatar chips, Stake | Prize | gear pill, Settings pop-up).
   Look copied 1:1 from the Ludo match screen (assets/games/ludo/dashboard.css .ld-chip / .ld-tmr / .ld-pill / .ld-settings-modal).
   Classes are prefixed jm-. Colours ONLY through var(--...) tokens (player colour = --jm-c, set by jfun-matchui.js). No backdrop-filter on moving parts.
   Layout: .jm-grid = top chip row / board / bottom chip row; the board wrapper (#board-wrap or .jf-board-wrap) stays the fit target of jfun-fit.js. */

/* ---------- layout: top chip row / board / bottom chip row ---------- */
.jm-grid { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top" "board" "bottom"; min-width: 0; min-height: 0; }
.jm-grid > #board-wrap,
.jm-grid > .jf-board-wrap { grid-area: board; margin: 0; min-width: 0; min-height: 0; align-items: center; justify-content: center; }
/* chip rows start at the left edge of the (square, centred) board: --jf-board-px is set by jfun-fit.js; without it the offset is 0 */
.jm-row { display: flex; align-items: center; gap: var(--ui-gap-sm); min-width: 0; box-sizing: border-box; padding-left: max(0px, calc((100% - var(--jf-board-px, 100%)) / 2)); }
.jm-row:empty { display: none; }
.jm-row-top { grid-area: top; padding-top: var(--ui-s3); margin-bottom: var(--ui-s1); transform: translateY(var(--jm-slack, 0px)); }
.jm-row-bottom { grid-area: bottom; margin-top: var(--ui-s1); transform: translateY(calc(var(--jm-slack, 0px) * -1)); }

/* ---------- avatar chip (same size in every state: 76 x 32, 2px border) ---------- */
.jm-chip { position: relative; display: inline-flex; align-items: center; gap: var(--ui-gap-sm); flex: none; width: 76px; min-width: 76px; max-width: 76px; height: 32px; min-height: 32px; max-height: 32px; box-sizing: border-box; padding: 2px var(--ui-s2) 2px 2px; border: 2px solid var(--jm-c, var(--ui-accent)); border-radius: var(--ui-r-pill); background: var(--jf-glass-strong); color: var(--ui-text); font-family: var(--ui-font-display); font-size: var(--ui-fs-xs); font-weight: 700; line-height: 1.2; opacity: 0.8; -webkit-backdrop-filter: none; backdrop-filter: none; }
.jm-chip-av { position: relative; flex: none; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--jm-c, var(--ui-accent)); color: var(--ui-on-accent); text-shadow: 0 1px 2px var(--ui-scrim-40); }
.jm-chip-you { position: absolute; top: -9px; right: -2px; padding: 0 var(--ui-s1); border-radius: var(--ui-r-pill); background: var(--jm-c, var(--ui-accent)); color: var(--ui-on-accent); font-size: 10px; font-weight: 700; line-height: 14px; letter-spacing: 0.3px; pointer-events: none; }
.jm-chip-sub { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: center; white-space: nowrap; color: var(--jm-sc, var(--ui-muted)); font-variant-numeric: tabular-nums; }
.jm-chip-ic { margin-right: var(--ui-s1); font-size: 10px; }
.jm-chip--turn { opacity: 1; box-shadow: 0 0 0 2px var(--jm-c, var(--ui-accent)), 0 0 6px var(--jm-c, var(--ui-accent)); }
.jm-chip--out { opacity: 0.5; filter: grayscale(1); box-shadow: none; }

/* countdown = separate round badge (26px, seconds inside a thin conic ring) in the free strip right of the chip; absolute + pointer-events none,
   so the chip size and the avatar never change. Shown only on the active chip. --jm-deg = remaining share. Last 5 s = warning colour + pulse. */
.jm-tmr { display: none; position: absolute; top: 50%; left: calc(100% + var(--ui-s2)); margin-top: -13px; isolation: isolate; align-items: center; justify-content: center; width: 26px; height: 26px; box-sizing: border-box; border-radius: 50%; background: conic-gradient(var(--jm-tc, var(--jm-c, var(--ui-accent))) var(--jm-deg, 360deg), var(--ui-border) 0); color: var(--ui-text); font-family: var(--ui-font-display); font-size: var(--ui-fs-xs); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; text-shadow: none; pointer-events: none; z-index: 3; }
.jm-tmr::before { content: ""; position: absolute; z-index: -1; top: 2px; bottom: 2px; left: 2px; right: 2px; border-radius: 50%; background: var(--ui-surface-solid); }
.jm-chip--turn .jm-tmr { display: inline-flex; }
.jm-chip--warn .jm-tmr { --jm-tc: var(--ui-flame-text); color: var(--ui-flame-text); }
@keyframes jm-pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.05); opacity: 0.8; } }
@media (prefers-reduced-motion: no-preference) {
    .jm-chip--warn .jm-tmr { animation: jm-pulse 0.5s infinite; }
}

/* ---------- Stake | Prize | gear pill ----------
   In-flow last item of the screen. With the fit layer (.jf-fit) the screen already ends above the nav: it only adds the gap (+ the notch inset when there is no nav).
   Without it the margin lifts the pill above the bottom nav: --jm-nav-h (nav height, set by jfun-matchui.js on the pill) + --jf-nav-gap + env(safe-area-inset-bottom). */
.jm-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--ui-gap-sm); box-sizing: border-box; width: 100%; max-width: 420px; min-width: 0; margin: 0 auto calc(var(--ui-gap) + var(--jm-nav-h, 0px) + var(--jf-nav-gap, 0px) + env(safe-area-inset-bottom, 0px)); padding: var(--ui-s1) var(--ui-s1) var(--ui-s1) var(--ui-s4); border: 1px solid var(--ui-border); border-radius: var(--ui-r-pill); background: var(--jf-glass-strong); color: var(--ui-text); box-shadow: var(--ui-shadow), var(--ui-accent-shadow), inset 0 1px 0 var(--ui-glass-edge); text-align: left; font-size: var(--ui-fs-sm); -webkit-backdrop-filter: none; backdrop-filter: none; }
.jf-fit > .jm-bar { flex: 0 0 auto; margin-bottom: calc(var(--ui-gap) + max(0px, env(safe-area-inset-bottom, 0px) - var(--jm-nav-h, 0px))); }
.jm-bar-txt { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: var(--ui-gap); }
.jm-bar-col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.jm-bar-lbl { font-size: var(--ui-fs-xs); font-weight: 500; color: var(--ui-muted); }
.jm-bar-val { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--ui-font-display); font-size: var(--ui-fs-sm); font-weight: 700; color: var(--ui-text); }
.jm-bar-prize { color: var(--ui-accent); }
.jm-bar-div { flex: none; align-self: stretch; width: 1px; margin: var(--ui-s1) 0; background: var(--ui-border); }
.jm-gear { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; margin: 0; padding: 0; border: 1px solid var(--ui-border); border-radius: var(--ui-r-pill); background: var(--jf-glass-strong); color: var(--ui-text); box-shadow: inset 0 1px 0 var(--ui-glass-edge); font-size: var(--ui-fs-sm); cursor: pointer; -webkit-backdrop-filter: none; backdrop-filter: none; }
.jm-gear:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 2px; }
@media (max-width: 380px) {
    .jm-bar { gap: var(--ui-s1); }
    .jm-bar-txt { gap: var(--ui-gap-sm); }
    .jm-bar-val { font-size: var(--ui-fs-xs); }
}

/* ---------- Settings pop-up (modal kit look: glass panel, title, close x; opened with JF.openModal when present) ---------- */
.jm-settings { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 2000; align-items: center; justify-content: center; box-sizing: border-box; padding: var(--ui-s4); background: var(--ui-overlay); }
.jm-settings-panel { position: relative; box-sizing: border-box; width: 100%; max-width: 320px; padding: var(--ui-s4); background: var(--ui-glass-modal); -webkit-backdrop-filter: var(--jf-blur); backdrop-filter: var(--jf-blur); border: 1px solid var(--ui-border); border-radius: var(--ui-r-lg); box-shadow: var(--ui-shadow), inset 0 1px 0 var(--ui-glass-edge); color: var(--ui-text); }
.jm-settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--ui-s3); }
.jm-settings-title { font-family: var(--ui-font-display); font-size: var(--ui-fs-lg); font-weight: 700; color: var(--ui-text); }
.jm-settings-x { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; margin: 0; padding: 0; border: none; border-radius: 50%; background: none; color: var(--ui-muted); font-size: 24px; line-height: 1; cursor: pointer; }
.jm-settings-x:hover { color: var(--ui-accent); }
.jm-settings-x:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 2px; }
.jm-set-row { display: flex; align-items: center; justify-content: space-between; gap: var(--ui-gap); min-height: 44px; padding: var(--ui-s1) 0; }
.jm-set-label { flex: 1 1 auto; text-align: left; min-width: 0; font-size: var(--ui-fs-sm); font-weight: 700; color: var(--ui-text); }
.jm-set-ctl { flex: none; display: flex; align-items: center; gap: var(--ui-gap-sm); }
.jm-set-state { min-width: 3ch; text-align: right; font-size: var(--ui-fs-xs); font-weight: 700; color: var(--ui-muted); }
.jm-set-leave { width: 100%; margin-top: var(--ui-s3); }
