/* ===== CRASH — Royale Violet ===== */
#game-crash {
    --rv-gold: #f5c451;
    --rv-gold-bright: #ffd76a;
    --rv-gold-deep: #b9822a;
    --rv-violet: #8b5cf6;
    --rv-emerald: #22c55e;
    --rv-red: #ef4444;
    --rv-text: #f5f0ff;
    --rv-text2: #a79fc2;
    --rv-text3: #6f6794;
    --acc: #22c55e;
    font-family: -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--rv-text);
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    flex-direction: column;
    gap: 10px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
}
#game-crash > * { flex-shrink: 0; }

/* ---------- self-contained Royale Violet header ---------- */
.rv-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 2px;
}
.rv-back {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    color: var(--rv-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.rv-back:active { transform: scale(0.92); }
.rv-user { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.rv-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid rgba(245, 196, 81, 0.55);
    box-shadow: 0 0 12px rgba(245, 196, 81, 0.3);
    background: #1a1030;
}
.rv-avatar3d { width: 100%; height: 100%; object-fit: cover; }
.rv-name { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.rv-name span:first-child { font-weight: 800; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rv-uid { font-size: 0.7rem; color: var(--rv-text3); font-weight: 600; }
.rv-balance { text-align: right; }
.rv-balance-label { display: block; font-size: 0.6rem; letter-spacing: 0.1em; color: var(--rv-text3); font-weight: 700; }
.rv-balance-value {
    font-size: 1.25rem;
    font-weight: 900;
    background: linear-gradient(180deg, #ffe9a8, #f5c451 55%, #c98f1f);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    white-space: nowrap;
}
.rv-coin { font-size: 0.95rem; }

/* ---------- stage card ---------- */
.rv-stage {
    --acc: #22c55e;
    position: relative;
    border-radius: 20px;
    padding: 12px;
    background:
        radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, var(--acc) 14%, transparent), transparent 60%),
        linear-gradient(165deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
    border: 1px solid rgba(245, 196, 81, 0.22);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
}

/* ---------- period + W/L record ---------- */
.crash-topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 2px; }
.crash-period-label { font-size: 0.62rem; letter-spacing: 0.12em; color: var(--rv-text3); font-weight: 700; margin-right: 6px; }
.crash-period-value { font-family: ui-monospace, monospace; font-size: 0.85rem; font-weight: 800; color: var(--rv-gold-bright); }
.crash-record { display: flex; align-items: center; gap: 6px; }
.crash-record-item {
    font-size: 0.72rem;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
}
.crash-record-item.win { color: #4ade80; border-color: rgba(34, 197, 94, 0.4); }
.crash-record-item.lose { color: #f87171; border-color: rgba(239, 68, 68, 0.4); }
.crash-record-more {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    border: 1px solid rgba(139, 92, 246, 0.5);
    background: rgba(139, 92, 246, 0.18);
    color: #c4b5fd;
    font-size: 1rem;
    cursor: pointer;
}
.crash-record-more:active { transform: scale(0.92); }

/* ---------- recent results strip ---------- */
.crash-history-wrap { display: flex; align-items: center; gap: 6px; }
.crash-history {
    flex: 1;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 10px 2px 3px;
    scrollbar-width: none;
    min-width: 0;
}
.crash-history::-webkit-scrollbar { display: none; }
.crash-history-item {
    position: relative;
    flex: 0 0 auto;
    padding: 6px 11px;
    border-radius: 10px;
    font-size: 0.78rem;
    font-weight: 800;
    color: #fff;
}
.crash-history-item.low {
    background: linear-gradient(180deg, #22c55e, #15803d);
    box-shadow: 0 3px 10px rgba(34, 197, 94, 0.35);
}
.crash-history-item.high {
    background: linear-gradient(180deg, #8b5cf6, #6d28d9);
    box-shadow: 0 3px 10px rgba(139, 92, 246, 0.4);
}
.crash-history-item.newest { outline: 2px solid var(--rv-gold); outline-offset: 1px; }
.crash-history-item .hist-new {
    position: absolute;
    top: -9px;
    right: -5px;
    font-size: 0.5rem;
    font-weight: 900;
    color: var(--rv-gold-bright);
    letter-spacing: 0.06em;
    transform: rotate(6deg);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}
.crash-hist-chart {
    flex-shrink: 0;
    width: 40px;
    height: 36px;
    border-radius: 11px;
    border: 1px solid rgba(139, 92, 246, 0.55);
    background: linear-gradient(180deg, #8b5cf6, #6d28d9);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}
.crash-hist-chart:active { transform: scale(0.94); }

/* ---------- graph ---------- */
.crash-display { position: relative; }
#crash-canvas {
    width: 100%;
    aspect-ratio: 560 / 420;
    height: auto;
    display: block;
    border-radius: 14px;
    border: 1px solid rgba(139, 92, 246, 0.25);
    background:
        radial-gradient(100% 80% at 50% 0%, rgba(139, 92, 246, 0.08), transparent 60%),
        #120a24;
}
.crash-multiplier {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    line-height: 1.1;
    color: #4ade80;
    text-shadow: 0 2px 14px rgba(0, 0, 0, 0.8), 0 0 24px rgba(34, 197, 94, 0.4);
    pointer-events: none;
    white-space: nowrap;
}
.crash-multiplier.crashed { color: #f87171; text-shadow: 0 2px 14px rgba(0, 0, 0, 0.8), 0 0 24px rgba(239, 68, 68, 0.4); }
.crash-status {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.78rem;
    font-weight: 800;
    padding: 7px 15px;
    border-radius: 10px;
    background: rgba(10, 6, 22, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    white-space: nowrap;
    pointer-events: none;
    backdrop-filter: blur(4px);
}
.crash-status.countdown {
    font-size: 2.4rem;
    font-weight: 900;
    background: transparent;
    border: none;
    backdrop-filter: none;
    background: linear-gradient(180deg, #ffe9a8, #f5c451 55%, #c98f1f);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: none;
    filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.7));
}
.crash-status.flying { color: #4ade80; }
.crash-status.crashed { color: #f87171; }

/* ---------- live bets overlay (inside the graph) ---------- */
.crash-live {
    position: absolute;
    top: 56px;
    left: 8px;
    width: 168px;
    max-height: 58%;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    background: rgba(10, 6, 22, 0.62);
    border: 1px solid rgba(139, 92, 246, 0.3);
    backdrop-filter: blur(6px);
    overflow: hidden;
    z-index: 3;
}
.crash-live-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    color: var(--rv-text2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.crash-live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 8px #ef4444;
    animation: crash-live-pulse 1.2s ease-in-out infinite;
}
@keyframes crash-live-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}
.crash-live-count {
    margin-left: auto;
    background: rgba(139, 92, 246, 0.3);
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 0.66rem;
    color: #e9e2ff;
}
.crash-live-list { overflow-y: auto; padding: 4px; scrollbar-width: none; }
.crash-live-list::-webkit-scrollbar { display: none; }
.crash-live-empty { font-size: 0.7rem; color: var(--rv-text3); text-align: center; padding: 8px; }
.crash-live-row {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 6px;
    font-size: 0.68rem;
    border-radius: 8px;
}
.crash-live-row.mine { background: rgba(245, 196, 81, 0.14); outline: 1px solid rgba(245, 196, 81, 0.4); }
.crash-live-player { font-weight: 700; color: var(--rv-text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 64px; }
.crash-live-pdot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.crash-live-pdot.playing { background: #60a5fa; box-shadow: 0 0 6px #60a5fa; }
.crash-live-pdot.cashed { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
.crash-live-pdot.lost { background: #f87171; }
.crash-live-stake { margin-left: auto; font-weight: 800; color: var(--rv-text); font-variant-numeric: tabular-nums; }
.crash-live-out { font-weight: 800; font-size: 0.64rem; }
.crash-live-out.won { color: #4ade80; }

/* ---------- two bet slots ---------- */
.crash-controls { width: 100%; }
.crash-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.crash-slot {
    border-radius: 16px;
    padding: 10px;
    background:
        radial-gradient(120% 90% at 50% 0%, rgba(139, 92, 246, 0.08), transparent 60%),
        linear-gradient(165deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.015));
    border: 1px solid rgba(245, 196, 81, 0.18);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}
.crash-slot.active { border-color: rgba(34, 197, 94, 0.6); box-shadow: 0 0 14px rgba(34, 197, 94, 0.25); }
.crash-slot-head { display: flex; justify-content: center; }
.crash-slot-tag {
    font-size: 0.62rem;
    font-weight: 900;
    letter-spacing: 0.14em;
    color: var(--rv-gold-bright);
}
.crash-amount-box { display: flex; align-items: center; gap: 4px; }
.crash-amt-btn {
    width: 30px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.07);
    color: var(--rv-text);
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
}
.crash-amt-btn:active { transform: scale(0.92); }
.crash-amt-input {
    flex: 1;
    min-width: 0;
    height: 32px;
    border-radius: 10px;
    border: 1px solid rgba(245, 196, 81, 0.4);
    background: rgba(10, 6, 22, 0.6);
    color: #ffd76a;
    font-size: 0.9rem;
    font-weight: 800;
    text-align: center;
    font-variant-numeric: tabular-nums;
    box-shadow: inset 0 1px 0 rgba(255, 233, 168, 0.12);
}
.crash-auto-label { font-size: 0.6rem; color: var(--rv-text3); font-weight: 700; letter-spacing: 0.04em; }
.crash-quick-row {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
    margin-top: 4px;
}
.crash-quick-row::-webkit-scrollbar { display: none; }
.crash-quick-btn {
    flex: 0 0 auto;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 0.64rem;
    font-weight: 800;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    color: var(--rv-text2);
    cursor: pointer;
}
.crash-quick-btn.active {
    background: linear-gradient(180deg, var(--rv-gold-bright), #e8a91c);
    border-color: transparent;
    color: #2a1a00;
    box-shadow: 0 4px 12px rgba(245, 196, 81, 0.35);
}
.crash-bet-btn {
    width: 100%;
    padding: 12px 4px;
    border: none;
    border-radius: 14px;
    font-size: 0.8rem;
    font-weight: 900;
    letter-spacing: 0.04em;
    cursor: pointer;
    color: #06130c;
    background: linear-gradient(180deg, #4ade80, #16a34a);
    box-shadow: 0 8px 20px rgba(34, 197, 94, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.crash-bet-btn:active { transform: scale(0.97); }
.crash-bet-btn:disabled { opacity: 0.45; }
.crash-cashout-btn {
    width: 100%;
    padding: 12px 4px;
    border: none;
    border-radius: 14px;
    font-size: 0.8rem;
    font-weight: 900;
    letter-spacing: 0.04em;
    cursor: pointer;
    color: #2a1a00;
    background: linear-gradient(180deg, var(--rv-gold-bright), #e8a91c);
    box-shadow: 0 8px 20px rgba(245, 196, 81, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    animation: crash-cashout-glow 1s ease-in-out infinite;
}
.crash-cashout-btn span { font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.crash-cashout-btn.auto { background: linear-gradient(180deg, #c4b5fd, #8b5cf6); color: #1e1040; box-shadow: 0 8px 20px rgba(139, 92, 246, 0.45); }
@keyframes crash-cashout-glow {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.12); }
}
.crash-cashout-btn:active { transform: scale(0.97); }

/* ---------- history modal ---------- */
.crash-hist-modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(6, 3, 14, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.crash-hist-card {
    width: 100%;
    max-width: 380px;
    max-height: 76vh;
    display: flex;
    flex-direction: column;
    border-radius: 20px;
    padding: 14px;
    background: linear-gradient(165deg, #2a1a4e, #150a28);
    border: 1px solid rgba(245, 196, 81, 0.3);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}
.crash-hist-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.crash-hist-title { font-weight: 900; font-size: 1rem; color: var(--rv-gold-bright); }
.crash-hist-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.07);
    color: var(--rv-text);
    cursor: pointer;
    font-size: 0.85rem;
}
.crash-hist-table-head, .crash-hist-row {
    display: grid;
    grid-template-columns: 1.4fr 0.8fr 0.8fr 1fr;
    gap: 6px;
    align-items: center;
}
.crash-hist-table-head {
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: var(--rv-text3);
    padding: 6px 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.crash-hist-body { overflow-y: auto; scrollbar-width: none; }
.crash-hist-body::-webkit-scrollbar { display: none; }
.crash-hist-row { padding: 8px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); font-size: 0.74rem; }
.crash-hist-period { font-family: ui-monospace, monospace; color: var(--rv-text2); }
.crash-hist-stake { font-weight: 800; font-variant-numeric: tabular-nums; }
.crash-hist-result { font-weight: 900; font-size: 0.68rem; }
.crash-hist-result.win { color: #4ade80; }
.crash-hist-result.lose { color: #f87171; }
.crash-hist-result.pending { color: var(--rv-text3); }
.crash-hist-cash { display: flex; flex-direction: column; gap: 1px; font-weight: 700; }
.crash-hist-cash .up { color: #4ade80; }
.crash-hist-cash .down { color: #f87171; }
.crash-hist-empty { text-align: center; padding: 24px; color: var(--rv-text3); font-size: 0.82rem; }

@media (prefers-reduced-motion: reduce) {
    .crash-live-dot, .crash-cashout-btn { animation: none !important; }
}

@media (max-width: 340px) {
    .crash-slots { gap: 6px; }
    .crash-slot { padding: 8px; }
    .crash-bet-btn, .crash-cashout-btn { font-size: 0.72rem; }
    .crash-live { width: 150px; }
}
