/* Crash */

.cr-stage {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
}

.cr-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 18px 0;
}

.cr-top .cas-phase {
    flex: none;
    transition: color 0.2s, border-color 0.2s;
}

.cr-history {
    display: flex;
    flex: 1;
    justify-content: flex-end;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 18%);
    mask-image: linear-gradient(90deg, transparent, #000 18%);
}

.cr-history span {
    flex: none;
    height: 26px;
    padding: 0 9px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--cas-on-dark-2);
    font: 700 12px/26px var(--cas-mono);
    font-variant-numeric: tabular-nums;
}

.cr-history .is-low {
    color: #fda4af;
    background: rgba(244, 63, 94, 0.1);
}

.cr-history .is-mid {
    color: #6ee7b7;
    background: rgba(16, 185, 129, 0.12);
}

.cr-history .is-high {
    color: #fcd34d;
    background: rgba(245, 184, 61, 0.15);
}

.cr-history .is-new {
    animation: cr-chip-in 0.5s var(--cas-spring);
}

@keyframes cr-chip-in {
    from {
        opacity: 0;
        transform: translateX(14px) scale(0.8);
    }
}

/* screen */

.cr-screen {
    position: relative;
    flex: 1;
    min-height: 400px;
    margin: 12px 18px 0;
    overflow: hidden;
    border: 1px solid var(--cas-line);
    border-radius: 18px;
    background:
        radial-gradient(90% 80% at 0% 100%, rgba(99, 102, 241, 0.2), transparent 62%),
        radial-gradient(60% 60% at 100% 0%, rgba(240, 171, 252, 0.08), transparent 70%),
        linear-gradient(180deg, #0a0f1c, #060910);
    isolation: isolate;
}

.cr-screen::before {
    content: "";
    position: absolute;
    top: -240px;
    right: -240px;
    bottom: 0;
    left: 0;
    z-index: -1;
    background-image:
        radial-gradient(1.5px 1.5px at 22px 34px, rgba(255, 255, 255, 0.85), transparent),
        radial-gradient(1px 1px at 118px 82px, rgba(255, 255, 255, 0.6), transparent),
        radial-gradient(1.6px 1.6px at 204px 158px, rgba(199, 210, 254, 0.9), transparent),
        radial-gradient(1px 1px at 62px 196px, rgba(255, 255, 255, 0.5), transparent),
        radial-gradient(1.2px 1.2px at 172px 18px, rgba(255, 255, 255, 0.65), transparent),
        radial-gradient(1px 1px at 92px 138px, rgba(240, 171, 252, 0.7), transparent);
    background-size: 240px 240px;
    opacity: 0.55;
    animation: cr-stars var(--star-dur, 9s) linear infinite;
    animation-play-state: paused;
}

.cr-stage[data-phase="flight"] .cr-screen::before,
.cr-stage[data-phase="cashed"] .cr-screen::before {
    animation-play-state: running;
}

@keyframes cr-stars {
    to {
        transform: translate(-240px, 240px);
    }
}

.cr-screen.is-shake {
    animation: cr-shake 0.5s;
}

@keyframes cr-shake {
    15% { transform: translate(-6px, 3px); }
    30% { transform: translate(5px, -4px); }
    45% { transform: translate(-4px, 2px); }
    60% { transform: translate(3px, -2px); }
    80% { transform: translate(-1px, 1px); }
}

.cr-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* rocket */

.cr-rocket {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 3;
    width: 64px;
    height: 64px;
    pointer-events: none;
    transition: opacity 0.25s;
    will-change: transform;
}

.cr-rocket__img {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.55));
}

.cr-rocket__flame {
    position: absolute;
    bottom: 2px;
    left: 2px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(254, 215, 170, 0.95), rgba(249, 115, 22, 0.55) 45%, transparent 72%);
    opacity: 0;
    filter: blur(1.5px);
    transition: opacity 0.2s;
}

.cr-stage[data-phase="idle"] .cr-rocket__img {
    animation: cr-bob 2.6s ease-in-out infinite;
}

.cr-stage[data-phase="idle"][data-result="won"] .cr-rocket,
.cr-stage[data-phase="idle"][data-result="lost"] .cr-rocket,
.cr-stage[data-phase="crashed"] .cr-rocket {
    opacity: 0;
}

.cr-stage[data-phase="accepted"] .cr-rocket__img {
    animation: cr-rumble 0.09s linear infinite;
}

.cr-stage[data-phase="accepted"] .cr-rocket__flame {
    opacity: 0.55;
    animation: cr-flame 0.14s ease-in-out infinite alternate;
}

.cr-stage[data-phase="flight"] .cr-rocket__flame,
.cr-stage[data-phase="cashed"] .cr-rocket__flame {
    opacity: 1;
    animation: cr-flame 0.12s ease-in-out infinite alternate;
}

@keyframes cr-bob {
    50% { transform: translate(2px, -4px); }
}

@keyframes cr-rumble {
    25% { transform: translate(1px, -1px); }
    50% { transform: translate(-1px, 1px); }
    75% { transform: translate(1px, 1px); }
}

@keyframes cr-flame {
    from { transform: scale(0.82); }
    to { transform: scale(1.18); }
}

.cr-boom {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 4;
    width: 120px;
    height: 120px;
    opacity: 0;
    pointer-events: none;
}

.cr-boom.is-on {
    animation: cr-boom 0.9s var(--cas-ease) forwards;
}

@keyframes cr-boom {
    0% { opacity: 0; scale: 0.3; }
    18% { opacity: 1; scale: 1.15; }
    60% { opacity: 1; scale: 1; }
    100% { opacity: 0; scale: 1.3; }
}

.cr-flag {
    position: absolute;
    z-index: 4;
    padding: 5px 10px;
    border-radius: 9px;
    background: linear-gradient(180deg, #4ade80, #10b981);
    box-shadow: 0 10px 24px -8px rgba(16, 185, 129, 0.8);
    color: #022c22;
    font: 800 12px/1 var(--cas-mono);
    white-space: nowrap;
    transform: translate(-50%, -100%);
    pointer-events: none;
    animation: cr-flag-in 0.45s var(--cas-spring);
}

.cr-flag::after {
    content: "";
    position: absolute;
    bottom: -5px;
    left: 50%;
    width: 10px;
    height: 10px;
    background: #10b981;
    transform: translateX(-50%) rotate(45deg);
    border-radius: 2px;
    z-index: -1;
}

@keyframes cr-flag-in {
    from {
        opacity: 0;
        transform: translate(-50%, -60%) scale(0.7);
    }
}

/* readout */

.cr-readout {
    position: absolute;
    top: 34%;
    left: 50%;
    z-index: 2;
    display: grid;
    justify-items: center;
    gap: 8px;
    width: min(92%, 520px);
    text-align: center;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.cr-readout__mult {
    color: #fff;
    font: 800 clamp(46px, 6.4vw, 84px)/1 var(--cas-mono);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.04em;
    text-shadow: 0 10px 34px rgba(0, 0, 0, 0.55);
    transition: color 0.2s;
}

.cr-readout__sub {
    color: var(--cas-on-dark-2);
    font-size: 14px;
    font-weight: 600;
}

.cr-stage[data-phase="idle"]:not([data-result="won"]):not([data-result="lost"]) .cr-readout__mult {
    color: rgba(255, 255, 255, 0.28);
}

.cr-stage[data-result="won"] .cr-readout__mult {
    color: #34d399;
    text-shadow: 0 0 40px rgba(52, 211, 153, 0.35);
}

.cr-stage[data-result="won"] .cr-readout__sub {
    color: #a7f3d0;
}

.cr-stage[data-result="lost"] .cr-readout__mult {
    color: #fb7185;
    text-shadow: 0 0 40px rgba(244, 63, 94, 0.35);
}

.cr-stage[data-result="lost"] .cr-readout__sub {
    color: #fecdd3;
}

.cr-stage[data-phase="idle"][data-result] .cr-readout__mult {
    opacity: 0.75;
}

/* handshake */

.cr-handshake {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 8px;
    background: rgba(6, 9, 15, 0.5);
    backdrop-filter: blur(3px);
    animation: cr-fade-in 0.2s ease-out;
}

@keyframes cr-fade-in {
    from { opacity: 0; }
}

@property --cr-p {
    syntax: "<number>";
    inherits: false;
    initial-value: 0;
}

.cr-handshake__ring {
    position: relative;
    width: 64px;
    height: 64px;
    margin-bottom: 6px;
    border-radius: 50%;
    background: conic-gradient(var(--tone) calc(var(--cr-p) * 1turn), rgba(255, 255, 255, 0.08) 0);
    -webkit-mask: radial-gradient(circle, transparent 55%, #000 57%);
    mask: radial-gradient(circle, transparent 55%, #000 57%);
}

.cr-handshake.is-on .cr-handshake__ring {
    animation: cr-ring var(--hs, 1.2s) linear forwards;
}

@keyframes cr-ring {
    to { --cr-p: 1; }
}

.cr-handshake__title {
    color: #fff;
    font-size: 19px;
    font-weight: 800;
}

.cr-handshake__sub {
    color: var(--cas-on-dark-3);
    font: 600 12.5px var(--cas-mono);
}

/* rule under the chart */

.cr-rule {
    justify-content: flex-start;
    padding: 12px 20px 16px;
    text-align: left;
}

.cr-rule .cas-i {
    flex: none;
    width: 16px;
    height: 16px;
    color: var(--tone);
}

/* panel */

.cr-target {
    display: grid;
    gap: 8px;
    transition: opacity 0.2s;
}

.cr-target.is-off {
    opacity: 0.5;
}

.cr-target .cas-chip {
    flex: 1;
}

@media (max-width: 960px) {
    .cr-screen {
        min-height: 320px;
    }
}

@media (max-width: 640px) {
    .cr-top {
        padding: 12px 12px 0;
    }

    .cr-screen {
        min-height: 280px;
        margin: 10px 12px 0;
        border-radius: 14px;
    }

    .cr-rocket {
        width: 50px;
        height: 50px;
    }

    .cr-rocket__flame {
        width: 24px;
        height: 24px;
    }

    .cr-readout {
        top: 32%;
    }

    .cr-readout__sub {
        font-size: 12.5px;
    }

    .cr-rule {
        padding: 10px 14px 14px;
        font-size: 12.5px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cr-screen::before,
    .cr-rocket__img,
    .cr-rocket__flame {
        animation: none !important;
    }
}
