:root {
    --timer-normal: var(--primary-color);
    --timer-warning: var(--ui-flame-text);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--bg-color);
    min-height: 100vh;
    padding: 10px;
    font-family: 'Poppins', 'Arial', sans-serif;
    overflow-x: hidden;
    color: var(--text-color);
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

/* Pull to Refresh Indicator */
.ptr-indicator {
    position: fixed;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-color);
    color: var(--ui-on-accent);
    padding: 12px 24px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 13px;
    z-index: 9998;
    transition: top 0.3s ease;
    box-shadow: var(--ui-accent-shadow);
}

.ptr-indicator.visible {
    top: 20px;
}

.ptr-indicator i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.merged-card {
    padding: 12px;
    margin-bottom: 12px;
}

/* Stats Cards */
.stats-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--ui-gap, 12px);
    margin-bottom: 12px;
}

.stat-card {
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--ui-shadow);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
}

.stat-card.pool-card::before {
    background: linear-gradient(180deg, var(--accent-green) 0%, var(--ui-ok-deep) 100%);
}

.stat-card.bigpool-card::before {
    background: linear-gradient(180deg, var(--accent-orange) 0%, var(--ui-warn-deep) 100%);
}

.stat-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.stat-card-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.stat-card.pool-card .stat-card-icon {
    background: linear-gradient(135deg, var(--accent-green) 0%, var(--ui-ok-deep) 100%);
    color: var(--ui-on-accent);
}

.stat-card.bigpool-card .stat-card-icon {
    background: linear-gradient(135deg, var(--accent-orange) 0%, var(--ui-warn-deep) 100%);
    color: var(--ui-on-accent);
}

.stat-card-title {
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card-value {
    margin-bottom: 4px;
}

.stat-card.pool-card .stat-card-value {
    color: var(--ui-ok-deep);
}

.stat-card.bigpool-card .stat-card-value {
    color: var(--ui-warn-deep);
}

.stat-card-subtitle {
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-card-subtitle i {
    font-size: 9px;
}

/* PRICE DISPLAY CARD */
.price-display {
    text-align: center;
    padding: 15px 10px;
    background: var(--ui-grad-purple);
    color: var(--ui-on-accent);
    border-radius: 12px;
    margin-bottom: 12px;
    position: relative;
    overflow: hidden;
}

.price-display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--ui-warn), transparent);
    animation: scan 3s linear infinite;
}

@keyframes scan {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

@keyframes slide {
    0% { transform: translateX(-10px); }
    50% { transform: translateX(10px); }
    100% { transform: translateX(-10px); }
}

.price-value {
    font-size: 24px;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    margin: 5px 0;
    text-shadow: 0 2px 4px var(--ui-scrim-20);
}

.price-label {
    font-size: 12px;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 5px;
}

/* Timer Section */
.timer-section {
    text-align: center;
    margin-bottom: 10px;
    padding: 10px;
    background: linear-gradient(135deg, var(--bg-color) 0%, var(--card-bg) 100%);
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.timer-title {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.timer-display {
    font-size: 26px;
    font-weight: 700;
    color: var(--timer-normal);
    font-family: 'Courier New', monospace;
    margin: 4px 0;
    line-height: 1;
    text-shadow: 0 2px 4px var(--ui-accent-ring);
    transition: all 0.3s ease;
}

.timer-display.closing {
    color: var(--timer-warning);
    animation: pulse-timer 0.5s infinite;
    text-shadow: 0 0 20px var(--ui-flame);
}

@keyframes pulse-timer {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

.timer-info-row {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed var(--border-color);
}

.timer-info-row strong {
    color: var(--accent-green);
}

/* Betting Section */
.betting-section {
    padding: 12px;
    background: linear-gradient(135deg, var(--bg-color) 0%, var(--card-bg) 100%);
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.betting-title {
    font-size: 12px;
    color: var(--text-color);
    font-weight: 600;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Quick Bet Buttons - ABOVE input */
.quick-bet-container {
    margin-bottom: 8px;
}

.quick-bet-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.quick-bet-header i {
    color: var(--accent-orange);
    font-size: 14px;
}

.quick-bet-header span {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.quick-bet-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.quick-bet-btn {
    flex: 1;
    min-width: 50px;
    padding: 8px 4px;
    background: linear-gradient(135deg, var(--card-bg) 0%, var(--bg-color) 100%);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px var(--shadow-color);
}

.quick-bet-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--ui-accent-shadow);
}

.quick-bet-btn:active {
    transform: translateY(0);
}

.quick-bet-btn.selected {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    border-color: var(--primary-color);
    color: var(--ui-on-accent);
    box-shadow: var(--ui-accent-shadow);
}

/* Bet Amount Input */
.bet-amount-container {
    margin-bottom: 12px;
}

.bet-amount-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bet-amount-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 8px 12px;
    transition: all 0.3s ease;
}

.bet-amount-input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--ui-focus-ring);
}

.bet-amount-input {
    flex: 1;
    border: none;
    background: none;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-color);
    outline: none;
    font-family: 'Courier New', monospace;
}

.bet-amount-currency {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
}

.max-btn {
    background: var(--accent-blue);
    color: var(--ui-on-accent);
    border: none;
    padding: 4px 12px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Potential Win Display */
.potential-win-box {
    background: var(--ui-purple-bg);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 12px;
    border: 1px solid var(--accent-purple);
    display: none;
}

.potential-win-box.visible {
    display: block;
}

.potential-win-box .win-label {
    font-size: 11px;
    color: var(--accent-purple);
    margin-bottom: 4px;
}

.potential-win-box .win-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent-purple);
}

.potential-win-box .win-capped {
    font-size: 10px;
    color: var(--ui-bad-text);
    margin-top: 4px;
}

/* Number Buttons with Bet Info */
.number-buttons-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

/* Desktop styles - only applied on larger screens */
@media (min-width: 1024px) {
    body {
        padding: 20px;
    }
    
    .container {
        max-width: 800px;
    }
    
    .merged-card {
        padding: 20px;
    }
    
    .stats-container {
        gap: 15px;
    }
    
    .stat-card {
        padding: 15px;
    }
    
    .stat-card-value {
        font-size: 24px;
    }
    
    .price-display {
        padding: 20px;
    }
    
    .price-value {
        font-size: 32px;
    }
    
    .timer-display {
        font-size: 36px;
    }
    
    .number-buttons-grid {
        grid-template-columns: repeat(10, 1fr);
        gap: 10px;
    }
    
    .number-btn {
        height: 60px;
        font-size: 18px;
    }
    
    .bet-amount-input {
        font-size: 20px;
    }
    
    .place-bet-btn {
        font-size: 18px;
        padding: 16px;
    }
    
    .modal-content {
        max-width: 450px;
        padding: 30px;
    }
    
    .toast {
        bottom: 30px;
        right: 30px;
        min-width: 350px;
    }
    
    .quick-bet-btn {
        font-size: 14px;
        padding: 8px 4px;
    }
}

.number-btn-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    touch-action: pan-y;
}

.number-btn {
    height: 48px;
    width: 100%;
    background: linear-gradient(135deg, var(--card-bg) 0%, var(--bg-color) 100%);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-color);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px var(--shadow-color);
    position: relative;
    overflow: hidden;
    user-select: none;
}

.number-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--ui-accent-shadow);
}

.number-btn.selected {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    border-color: var(--primary-color);
    color: var(--ui-on-accent);
    transform: scale(1.05);
    box-shadow: var(--ui-accent-shadow);
}

.number-btn.has-bets {
    border-color: var(--accent-green);
    background: var(--ui-ok-bg);
}

.number-btn.selected.has-bets {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    border-color: var(--primary-color);
}

.number-btn .win-percent {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 8px;
    opacity: 0.7;
}

.bet-info {
    font-size: 9px;
    color: var(--text-secondary);
    text-align: center;
    font-weight: 600;
    line-height: 1.2;
    min-height: 24px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.bet-info .bet-amount {
    color: var(--accent-green);
    font-size: 10px;
}

.bet-info .bet-count {
    color: var(--text-secondary);
    font-size: 8px;
}

.number-btn-container:hover .bet-info {
    color: var(--text-color);
}

/* Bet Button */
.bet-button-container {
    margin-top: 10px;
}

.place-bet-btn {
    width: 100%;
    padding: 14px;
    height: auto;
    background: var(--jf-grad);
    color: var(--ui-on-accent);
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: var(--ui-accent-shadow);
}

.place-bet-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--ui-accent-lift-sm);
}

.place-bet-btn:disabled {
    background: var(--ui-disabled-bg);
    cursor: not-allowed;
    box-shadow: none;
}

/* Info Box */
.betting-info-box {
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    padding: 10px;
    background: var(--ui-warn-bg);
    border-radius: 8px;
    border: 1px solid var(--ui-warn-line);
    margin-top: 10px;
}

.betting-info-box strong {
    color: var(--primary-color);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 15px;
}

.modal-content {
    width: 100%;
    max-width: 400px;
    padding: 25px;
    position: relative;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(50px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}


.close-modal {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.close-modal:hover {
    background: var(--bg-color);
    color: var(--primary-color);
}

.modal-body {
    text-align: center;
    margin-bottom: 20px;
}

.modal-body .selected-number-display {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--ui-on-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    font-weight: 700;
    margin: 0 auto 15px;
    box-shadow: var(--ui-accent-shadow);
}

.modal-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.modal-row:last-child {
    border-bottom: none;
}


.modal-row .value {
    font-weight: 700;
}

.modal-row .value.highlight {
    color: var(--primary-color);
}

.modal-footer {
    display: flex;
    gap: 10px;
}

.modal-btn {
    flex: 1;
}

.modal-btn.confirm {
    background: var(--jf-grad);
    color: var(--ui-on-accent);
}

.modal-btn.confirm:hover {
    background: var(--jf-grad);
    filter: saturate(1.15) brightness(1.04);
    transform: translateY(-1px);
}


/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    border-left: 4px solid var(--primary-color);
    display: flex;
    align-items: center;
    gap: 12px;
    transform: translateX(500px);
    transition: transform 0.3s ease;
    z-index: 3000;
    min-width: 300px;
}

.toast.show {
    transform: translateX(0);
}

.toast.success {
    border-left-color: var(--accent-green);
}

.toast.error {
    border-left-color: var(--ui-bad);
}

.toast-icon {
    color: var(--primary-color);
}

.toast.success .toast-icon {
    color: var(--accent-green);
}

.toast.error .toast-icon {
    color: var(--ui-bad-text);
}

/* Mobile Optimization */
@media (max-width: 768px) {
    body { padding: 8px; }
    .price-display { padding: 12px 8px; margin-bottom: 10px; }
    .price-value { font-size: 20px; }
    .merged-card { padding: 10px; margin-bottom: 10px; }

    .stats-container { gap: 8px; }
    .stat-card { padding: 10px; }
    .stat-card-icon { width: 28px; height: 28px; font-size: 12px; }
    .stat-card-title { font-size: 10px; }
    .stat-card-value { font-size: 16px; }

    .timer-display { font-size: 22px; }
    .number-buttons-grid { gap: 6px; }
    .number-btn { height: 44px; font-size: 14px; }
    .bet-info { font-size: 8px; min-height: 20px; }
    .bet-info .bet-amount { font-size: 9px; }
    .bet-info .bet-count { font-size: 7px; }
    .place-bet-btn { font-size: 14px; padding: 12px; }
    .betting-info-box { font-size: 9px; padding: 8px; }
    .bet-amount-input { font-size: 16px; }
    
    /* Mobile adjustments for quick bet */
    .quick-bet-buttons {
        gap: 4px;
    }
    
    .quick-bet-btn {
        font-size: 12px;
        padding: 6px 2px;
        min-width: 45px;
    }
}

@media (max-width: 480px) {
    body { padding: 6px; }
    .price-display { padding: 10px 6px; }
    .price-value { font-size: 18px; }
    .merged-card { padding: 8px; }

    .stat-card { padding: 8px; }
    .stat-card-icon { width: 24px; height: 24px; font-size: 11px; }
    .stat-card-title { font-size: 9px; }
    .stat-card-value { font-size: 14px; }

    .timer-display { font-size: 20px; }
    .number-btn { height: 40px; font-size: 13px; }
    .bet-info { font-size: 7px; min-height: 18px; }
    .bet-info .bet-amount { font-size: 8px; }
    .bet-info .bet-count { font-size: 6px; }
    .place-bet-btn { font-size: 13px; padding: 10px; }
    
    .quick-bet-btn {
        font-size: 11px;
        padding: 5px 2px;
        min-width: 40px;
    }
}

/* ===== JFun Games additions (from games/assets/jfun-theme.css, same CSS variables) ===== */
.jf-toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); background: var(--text-color); color: var(--ui-on-accent); padding: 10px 18px; border-radius: 30px; font-size: 13px; font-weight: 600; z-index: 9999; box-shadow: var(--ui-shadow); max-width: 90%; text-align: center; }
.jf-btn-outline { width: 100%; padding: 12px; background: transparent; color: var(--primary-color); border: 2px solid var(--primary-color); border-radius: 12px; font-size: 14px; font-weight: 700; cursor: pointer; text-transform: uppercase; letter-spacing: 0.5px; font-family: inherit; display: flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.jf-btn-outline:hover { background: var(--ui-row-hover); }
.jf-btn-text { background: none; border: none; color: var(--text-secondary); font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; padding: 8px; text-decoration: none; }
.jf-seg { display: flex; background: var(--bg-color); border: 1px solid var(--border-color); border-radius: 10px; padding: 3px; gap: 3px; margin-bottom: 10px; }
.jf-seg button { flex: 1; padding: 8px 4px; border: none; border-radius: 8px; background: transparent; font-size: 13px; font-weight: 600; color: var(--text-secondary); cursor: pointer; font-family: inherit; }
.jf-seg button.active { background: var(--primary-color); color: var(--ui-on-accent); box-shadow: var(--ui-accent-shadow); }
.jf-player-row { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.jf-player-pill { flex: 1; min-width: 120px; display: flex; align-items: center; gap: 6px; background: var(--card-bg); border: 2px solid var(--border-color); border-radius: 10px; padding: 8px 10px; font-size: 13px; font-weight: 600; color: var(--text-color); }
.jf-player-pill.active { border-color: var(--primary-color); box-shadow: 0 2px 8px var(--ui-accent-ring); }
.jf-player-pill .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border-color); flex: none; }
.jf-badge-bot { background: var(--accent-orange); color: var(--ui-on-accent); font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 8px; letter-spacing: 0.5px; }
.jf-game-head { display: flex; align-items: center; gap: 12px; }
.jf-game-icon { width: 52px; height: 52px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 24px; color: var(--ui-on-accent); flex: none; }
.jf-game-icon.ttt { background: linear-gradient(135deg, var(--primary-color), var(--primary-dark)); }
.jf-game-icon.barah { background: linear-gradient(135deg, var(--accent-blue), var(--ui-info-deep)); }
.jf-game-icon.ludo { background: linear-gradient(135deg, var(--accent-orange), var(--ui-warn-deep)); }
.jf-game-name { font-size: 16px; font-weight: 700; color: var(--text-color); }
.jf-game-desc { font-size: 12px; color: var(--text-secondary); }
.jf-note { font-size: 11px; color: var(--text-secondary); margin: 8px 0; text-align: center; }
.jf-error { font-size: 11px; color: var(--timer-warning); font-weight: 600; text-align: center; margin: 6px 0; }
.jf-board-wrap { display: flex; justify-content: center; margin: 10px 0; }

/* ===== Ludo Mehfil specific (from games/ludomehfil.php) ===== */
    .ld-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
    .ld-dice { width: 48px; height: 48px; margin: 6px auto 0; border: 2px solid var(--ld-die-border); border-radius: 12px; background: var(--ld-die-face); color: var(--ld-pip); font-size: 26px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
    .jf-player-pill.out { opacity: 0.5; filter: grayscale(1); }
    @keyframes ld-pulse { 0%, 100% { box-shadow: 0 0 0 2px var(--ld-hl-gap, transparent), 0 0 0 5px var(--ld-hl, var(--accent-orange)), 0 2px 6px var(--ui-scrim-30); opacity: 1; } 50% { box-shadow: 0 0 0 2px var(--ld-hl-gap, transparent), 0 0 0 8px var(--ld-hl, var(--accent-orange)), 0 2px 6px var(--ui-scrim-30); opacity: 0.75; } }
    #board-wrap div[style*="cursor: pointer"] > div { animation: ld-pulse 1s ease-in-out infinite; }
    .ld-yard-glow { stroke-width: 5; stroke-opacity: 1; }
    @media (prefers-reduced-motion: no-preference) {
      @keyframes ld-yard-glow { 0%, 100% { stroke-opacity: 0.35; stroke-width: 3; filter: drop-shadow(0 0 2px var(--gc)); } 50% { stroke-opacity: 1; stroke-width: 7; filter: drop-shadow(0 0 8px var(--gc)); } }
      .ld-yard-glow { animation: ld-yard-glow 1.4s ease-in-out infinite; }
    }
.ld-dice.ld-tap { cursor: pointer; border-color: var(--ld-hl, var(--accent-orange)); box-shadow: 0 0 0 2px var(--ld-hl-gap, transparent), 0 0 0 5px var(--ld-hl, var(--accent-orange)); }
.ld-dice:focus-visible { outline: 3px solid var(--ld-hl, var(--accent-orange)); outline-offset: 3px; }
@media (prefers-reduced-motion: no-preference) {
    @keyframes ld-dice-ready {
        0%, 100% { box-shadow: 0 0 0 2px var(--ld-hl-gap, transparent), 0 0 0 5px var(--ld-hl, var(--accent-orange)); }
        50% { box-shadow: 0 0 0 2px var(--ld-hl-gap, transparent), 0 0 0 9px var(--ld-hl, var(--accent-orange)); }
    }
    .ld-dice.ld-tap:not(.rolling):not(.landed) { animation: ld-dice-ready 1.2s ease-in-out infinite; }
}

/* Ludo dice in the roller's yard: placeDice() in game.js sets left/top to the centre of the yard of the player whose roll it is (DICE_YARD).
   There is NO transition or animation on left/top/transform of #dice-box, so on a turn change the dice appears in the new yard at once;
   it only spins in place (3D cube, ludo.css). Size: 48px box scaled by --ld-k; --ld-s matches the box so the cube is a true cube. */
html body.jg-ludo #board-wrap { position: relative; }
html body.jg-ludo #board-wrap > #dice-box { position: absolute; left: 0; top: 0; margin: 0; width: 48px; height: 48px; --ld-s: 48px; z-index: 12; display: none; transform: translate(-50%, -50%) scale(var(--ld-k, 0.7)); }
html body.jg-ludo #board-wrap > #dice-box.ld-yard-on { display: flex; }

/* Ludo match screen: the old timer block is gone. The legacy nodes (#turn-text, #turn-timer, #roll-history, #roll-btn) stay in the DOM
   inside .ld-hidden-legacy so game.js never hits a missing element; they are never shown. */
html body.jg-ludo .ld-hidden-legacy { display: none !important; }

/* Stake / Prize pill: ONE floating rounded chip (Stake | Prize | gear). #match-info keeps its id; the gear #ld-settings-btn opens #ld-settings-modal (Sound, Auto-move (#auto-btn is the switch) and Leave Match live there).
   Phone portrait: last item of the fit column, so it sits above the bottom nav (the screen height already ends above #bottom-footer); the margin adds --ui-gap and,
   only when there is no nav, the safe-area inset. --ld-nav-h (nav height, set by game.js) is used when the fit layer is off. Wide / landscape: it stays in its grid cell. */
html body.jg-ludo #match-info.ld-pill { 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; 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); }
html body.jg-ludo #screen-match.jf-fit #match-info.ld-pill { display: flex; }
html body.jg-ludo #screen-match.jf-fit > #match-info.ld-pill { flex: 0 0 auto; margin: 0 auto calc(var(--ui-gap) + max(0px, env(safe-area-inset-bottom, 0px) - var(--ld-nav-h, 0px))); padding: var(--ui-s1) var(--ui-s1) var(--ui-s1) var(--ui-s4); font-size: var(--ui-fs-sm); }
html body.jg-ludo #screen-match:not(.jf-fit) > #match-info.ld-pill { margin-bottom: calc(var(--ui-gap) + var(--ld-nav-h, 0px) + var(--jf-nav-gap) + env(safe-area-inset-bottom, 0px)); }
/* fit layer: the screen height already ends above the nav; keep the notch inset (and the nav gap) clear inside it */
html body.jg-ludo #screen-match.jf-fit[style*="display: block"] { padding-bottom: env(safe-area-inset-bottom, 0px); }
/* lobby header: small History link, right side; the title wraps instead of pushing it out (360px) */
html body.jg-ludo .ld-head-txt { flex: 1 1 auto; min-width: 0; }
html body.jg-ludo .ld-head-link { flex: none; text-decoration: none; }
@media (max-width: 380px) { html body.jg-ludo .ld-head-link { padding: 0 var(--ui-s3); } }
html body.jg-ludo .ld-info-txt { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: var(--ui-gap); }
html body.jg-ludo .ld-pill-col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
html body.jg-ludo .ld-pill-lbl { font-size: var(--ui-fs-xs); font-weight: 500; color: var(--ui-muted); }
html body.jg-ludo .ld-pill-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); }
html body.jg-ludo .ld-pill-prize { color: var(--ui-accent); }
html body.jg-ludo .ld-pill-div { flex: none; align-self: stretch; width: 1px; margin: var(--ui-s1) 0; background: var(--ui-border); }
@media (max-width: 380px) {
    html body.jg-ludo #match-info.ld-pill { gap: var(--ui-s1); }
    html body.jg-ludo .ld-info-txt { gap: var(--ui-gap-sm); }
    html body.jg-ludo .ld-pill-val { font-size: var(--ui-fs-xs); }
}
html body.jg-ludo .ld-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; }
html body.jg-ludo .ld-gear:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 2px; }
html body.jg-ludo .ld-settings-modal .modal-content { max-width: 320px; padding: var(--ui-s4); }
html body.jg-ludo .ld-set-row { display: flex; align-items: center; justify-content: space-between; gap: var(--ui-gap); min-height: 44px; padding: var(--ui-s1) 0; }
html body.jg-ludo .ld-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); }
html body.jg-ludo .ld-set-help { margin-top: 2px; font-size: var(--ui-fs-xs); font-weight: 500; color: var(--ui-muted); }
html body.jg-ludo .ld-set-ctl { flex: none; display: flex; align-items: center; gap: var(--ui-gap-sm); }
html body.jg-ludo .ld-set-state { min-width: 3ch; text-align: right; font-size: var(--ui-fs-xs); font-weight: 700; color: var(--ui-muted); }
html body.jg-ludo .ld-set-leave { width: 100%; margin-top: var(--ui-s3); }

/* "Tap a glowing token" = small floating pill above the bottom edge of the board wrap (shown only while game.js sets display:block).
   The shared jfun-fit.css hides #turn-hint on short phones with !important, so the shown state is re-enabled here (Ludo only). */
html body.jg-ludo #board-wrap > #turn-hint { position: absolute; left: 50%; bottom: var(--ui-s2); transform: translateX(-50%); z-index: 8; margin: 0; width: max-content; max-width: calc(100% - 16px); box-sizing: border-box; padding: 2px var(--ui-s3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 1px solid var(--ld-hl, var(--accent-orange)); border-radius: var(--ui-r-pill); background: var(--jf-glass-strong); color: var(--ld-hl, var(--accent-orange)); box-shadow: inset 0 1px 0 var(--ui-glass-edge); font-size: var(--ui-fs-xs); font-weight: 700; line-height: 1.4; pointer-events: none; }
html body.jg-ludo #screen-match.jf-fit #board-wrap > #turn-hint[style*="display: block"] { display: block !important; }
html body.jg-ludo #screen-match.jf-fit { gap: 4px; }
html.jf-fit-on body.jg-ludo { padding-left: 4px; padding-right: 4px; }

/* Ludo capture effect: captured token shrinks + fades, then fades back in inside its yard (classes set by board.js) */
@media (prefers-reduced-motion: no-preference) {
    @keyframes ld-tok-in { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: scale(1); } }
    html body.jg-ludo #board-wrap .ld-tok-out { transform: scale(0.3) !important; opacity: 0 !important; transition: transform .35s ease-in, opacity .35s ease-in !important; }
    html body.jg-ludo #board-wrap .ld-tok-in { animation: ld-tok-in .3s ease-out both; }
}

/* Ludo corner chips: compact player chips around the board (layout here, look from the kit tokens). board.js fit() and jfun-fit size the board. */
html body.jg-ludo .ld-corners { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "red green" "board board" "blue yellow"; min-width: 0; min-height: 0; padding: 0 var(--ui-s1); }
html body.jg-ludo .ld-corners > #board-wrap { grid-area: board; margin: 0; min-width: 0; min-height: 0; align-items: center; justify-content: center; }
html body.jg-ludo #screen-match.jf-fit > .ld-corners { flex: 1 1 0; margin: 0; }
html body.jg-ludo #screen-match.jf-fit .ld-corners > #board-wrap { overflow: hidden; }
html body.jg-ludo #screen-match.ld-chips-on > #pills { display: none; }

/* every chip has exactly the same fixed box (no username, no variable text); my chip gets an absolutely positioned YOU tag, the countdown is an overlay on the avatar */
html body.jg-ludo .ld-chip { position: relative; display: inline-flex; align-items: center; gap: var(--ui-gap-sm); flex: none; width: 76px; height: 32px; box-sizing: border-box; padding: 2px var(--ui-s2) 2px 2px; border: 2px solid var(--ld-c); 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; }
/* chips touch their yard: --ld-dx / --ld-dy (set on #ld-corners by placeChips in game.js) = distance between the board square and the edge of its box; the chip is moved by it with a transform (layout and neighbours never change) */
html body.jg-ludo .ld-chip-red { grid-area: red; justify-self: start; margin-bottom: var(--ui-s1); transform: translate(var(--ld-dx, 0px), var(--ld-dy, 0px)); }
html body.jg-ludo .ld-chip-green { grid-area: green; justify-self: end; margin-bottom: var(--ui-s1); transform: translate(calc(var(--ld-dx, 0px) * -1), var(--ld-dy, 0px)); }
html body.jg-ludo .ld-chip-blue { grid-area: blue; justify-self: start; margin-top: var(--ui-s1); transform: translate(var(--ld-dx, 0px), calc(var(--ld-dy, 0px) * -1)); }
html body.jg-ludo .ld-chip-yellow { grid-area: yellow; justify-self: end; margin-top: var(--ui-s1); transform: translate(calc(var(--ld-dx, 0px) * -1), calc(var(--ld-dy, 0px) * -1)); }
html body.jg-ludo .ld-chip-av { position: relative; flex: none; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--ld-c); color: var(--ui-on-accent); text-shadow: 0 1px 2px var(--ui-scrim-40); }
html body.jg-ludo .ld-chip-you { position: absolute; top: -9px; right: -2px; padding: 0 var(--ui-s1); border-radius: var(--ui-r-pill); background: var(--ld-c); color: var(--ui-on-accent); font-size: 10px; font-weight: 700; line-height: 14px; letter-spacing: 0.3px; pointer-events: none; }
html body.jg-ludo .ld-chip-sub { flex: 1 1 auto; min-width: 0; text-align: center; white-space: nowrap; color: var(--ui-muted); font-variant-numeric: tabular-nums; }
html body.jg-ludo .ld-chip--turn { opacity: 1; box-shadow: 0 0 0 2px var(--ld-c), 0 0 6px var(--ld-c); }
html body.jg-ludo .ld-chip--turn .ld-tmr { display: inline-flex; }
html body.jg-ludo .ld-chip--warn .ld-tmr { --ld-tc: var(--timer-warning); color: var(--timer-warning); }
html body.jg-ludo .ld-chip--out { opacity: 0.5; filter: grayscale(1); box-shadow: none; }
/* active player's countdown = separate round badge (26px, seconds inside a thin conic ring) in the free strip beside the chip: right of the left chips (red, blue), left of the right chips (green, yellow).
   Absolute + pointer-events none, so the chip size, the avatar and the board never change; shown only on the chip whose turn it is; value mirrored from the one turn timer by updateChipTimer in game.js (--ld-deg = remaining share); last 5 s = warning colour + pulse. */
html body.jg-ludo .ld-tmr { display: none; position: absolute; top: 50%; 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(--ld-tc, var(--ld-c)) var(--ld-deg, 360deg), var(--ui-border) 0); color: var(--ui-text); 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; }
html body.jg-ludo .ld-tmr::before { content: ""; position: absolute; z-index: -1; top: 2px; bottom: 2px; left: 2px; right: 2px; border-radius: 50%; background: var(--ui-surface-solid); }
html body.jg-ludo .ld-chip-red .ld-tmr,
html body.jg-ludo .ld-chip-blue .ld-tmr { left: calc(100% + var(--ui-s2)); }
html body.jg-ludo .ld-chip-green .ld-tmr,
html body.jg-ludo .ld-chip-yellow .ld-tmr { right: calc(100% + var(--ui-s2)); }
@media (prefers-reduced-motion: no-preference) {
    html body.jg-ludo .ld-chip--warn .ld-tmr { animation: pulse-timer 0.5s infinite; }
}

/* wide / landscape: chips go to the left and right of the board (height is the scarce space there) */
@media (min-width: 900px), (orientation: landscape) and (max-height: 520px) and (min-width: 560px) {
    html body.jg-ludo #screen-match > .ld-corners { grid-area: board; margin: 0; align-self: stretch; min-height: 0; }
    html body.jg-ludo .ld-corners { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "red board green" ". board ." "blue board yellow"; column-gap: var(--ui-gap-sm); }
    html body.jg-ludo .ld-chip-red,
    html body.jg-ludo .ld-chip-green,
    html body.jg-ludo .ld-chip-blue,
    html body.jg-ludo .ld-chip-yellow { margin-top: 0; margin-bottom: 0; }
    /* the strip beside a side chip is the board, so the badge goes below the top chips and above the bottom chips */
    html body.jg-ludo .ld-chip-red .ld-tmr,
    html body.jg-ludo .ld-chip-green .ld-tmr { left: 50%; right: auto; top: calc(100% + var(--ui-s2)); margin: 0 0 0 -13px; }
    html body.jg-ludo .ld-chip-blue .ld-tmr,
    html body.jg-ludo .ld-chip-yellow .ld-tmr { left: 50%; right: auto; top: auto; bottom: calc(100% + var(--ui-s2)); margin: 0 0 0 -13px; }
}

/* glass without blur: the match-screen chips, timer badge, pill, gear, hint pill, dice and board wrap never blur (they move, or sit on the board; only the top bar, the bottom nav and the dialog carry a blur) */
html body.jg-ludo :is(.ld-chip, .ld-chip-av, .ld-chip-you, .ld-tmr, #match-info.ld-pill, .ld-gear, #turn-hint, #dice-box, #board-wrap) { -webkit-backdrop-filter: none; backdrop-filter: none; }
