:root {
    color-scheme: dark;
    --cr-bg: #11162a;
    --cr-surface: rgba(22, 29, 55, 0.88);
    --cr-text: #f7f9ff;
    --cr-muted: #aeb9d8;
    --cr-accent: #59e2d0;
    --cr-accent-strong: #20bfae;
    --cr-reward: #ffd166;
    --cr-danger: #ff5b7f;
    --cr-focus: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    color: var(--cr-text);
    background:
        radial-gradient(circle at 18% 0%, rgba(83, 124, 255, 0.28), transparent 42%),
        radial-gradient(circle at 86% 92%, rgba(89, 226, 208, 0.18), transparent 40%),
        linear-gradient(160deg, #11162a 0%, #171b35 58%, #101524 100%);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

.user-bar {
    flex-shrink: 0;
    margin: 0 auto 8px;
}

.cr-game {
    width: 100%;
    max-width: 480px;
    min-height: 0;
    flex: 1;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cr-hud {
    display: grid;
    grid-template-columns: 1.25fr 0.85fr 1fr;
    gap: 7px;
    flex-shrink: 0;
}

.cr-stat {
    min-width: 0;
    min-height: 51px;
    padding: 7px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 13px;
    background: rgba(255, 255, 255, 0.055);
    box-shadow: 0 7px 18px rgba(5, 8, 24, 0.18);
    backdrop-filter: blur(10px);
}

.cr-stat--crowd {
    border-color: rgba(89, 226, 208, 0.32);
    background: linear-gradient(145deg, rgba(89, 226, 208, 0.14), rgba(255, 255, 255, 0.045));
}

.cr-stat--best strong { color: var(--cr-reward); }

.cr-stat-label {
    color: var(--cr-muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1;
    text-transform: uppercase;
}

.cr-stat strong {
    margin-top: 3px;
    font-size: 20px;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.cr-stat--crowd strong { color: var(--cr-accent); }
.cr-stat--crowd strong.is-pop { animation: crCountPop 180ms cubic-bezier(0.2, 0, 0, 1); }

@keyframes crCountPop {
    45% { transform: scale(1.22); }
}

.cr-progress {
    position: relative;
    height: 10px;
    margin: 1px 21px 2px 16px;
    flex-shrink: 0;
    overflow: visible;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.10);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.28);
}

.cr-progress-fill {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--cr-accent-strong), var(--cr-accent));
    box-shadow: 0 0 10px rgba(89, 226, 208, 0.38);
    transition: width 120ms ease-out;
}

.cr-progress-runner,
.cr-progress-finish {
    position: absolute;
    top: 50%;
    transform: translateY(-54%);
    font-size: 17px;
    line-height: 1;
    pointer-events: none;
}

.cr-progress-runner { left: -17px; }
.cr-progress-finish { right: -22px; }

.cr-arena {
    position: relative;
    min-height: 0;
    flex: 1;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    background: #182445;
    box-shadow:
        0 20px 44px rgba(3, 7, 22, 0.36),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    touch-action: none;
}

#crCanvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: grab;
    outline: none;
}

#crCanvas:active { cursor: grabbing; }
.keyboard-input #crCanvas:focus {
    outline: 3px solid var(--cr-focus);
    outline-offset: -5px;
    border-radius: 18px;
}

.cr-overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: rgba(8, 12, 29, 0.67);
    backdrop-filter: blur(7px);
}

.cr-overlay.hidden { display: none; }

.cr-panel {
    width: min(100%, 332px);
    padding: 22px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 24px;
    background:
        radial-gradient(circle at 50% 0%, rgba(89, 226, 208, 0.12), transparent 46%),
        var(--cr-surface);
    box-shadow: 0 22px 55px rgba(2, 5, 20, 0.55);
}

.cr-kicker {
    margin-bottom: 6px;
    color: var(--cr-accent);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.cr-panel h1 {
    font-size: clamp(25px, 8vw, 34px);
    line-height: 1.05;
    letter-spacing: -0.025em;
}

.cr-panel > p {
    margin: 11px auto 16px;
    color: var(--cr-muted);
    font-size: 14px;
    line-height: 1.45;
}

.cr-rules {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
    margin-bottom: 16px;
}

.cr-rules span {
    min-height: 62px;
    padding: 9px 7px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: #dce5ff;
    font-size: 11px;
    line-height: 1.3;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.055);
}

.cr-rules b {
    color: #ffffff;
    font-size: 18px;
    line-height: 1;
}

#crStart {
    width: 100%;
    min-height: 50px;
    padding: 13px 18px;
    border: 0;
    border-radius: 14px;
    color: #092827;
    background: linear-gradient(135deg, #70f0df, #3acbb9);
    box-shadow:
        0 8px 22px rgba(43, 205, 185, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.52);
    font: 800 16px/1.2 inherit;
    cursor: pointer;
    transition-property: transform, filter, box-shadow;
    transition-duration: 140ms;
    transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}

#crStart:active { transform: scale(0.96); }
#crStart:focus-visible {
    outline: 3px solid var(--cr-focus);
    outline-offset: 3px;
}

@media (hover: hover) {
    #crStart:hover {
        filter: brightness(1.06);
        box-shadow: 0 10px 28px rgba(43, 205, 185, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.58);
    }
}

.cr-panel .cr-controls {
    margin: 11px 5px 0;
    color: rgba(205, 216, 244, 0.64);
    font-size: 11px;
    line-height: 1.35;
}

.cr-toast {
    position: absolute;
    top: 16%;
    left: 50%;
    z-index: 2;
    min-width: 112px;
    padding: 8px 13px;
    opacity: 0;
    transform: translate(-50%, 8px) scale(0.96);
    color: #ffffff;
    text-align: center;
    font-size: 18px;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    background: rgba(17, 25, 53, 0.86);
    box-shadow: 0 9px 28px rgba(2, 6, 20, 0.33);
    pointer-events: none;
}

.cr-toast.show {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
    transition-property: opacity, transform;
    transition-duration: 160ms;
    transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}

.cr-toast.danger { color: #ffdce4; border-color: rgba(255, 91, 127, 0.56); }
.cr-toast.reward { color: #bcfff6; border-color: rgba(89, 226, 208, 0.58); }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-height: 680px) {
    .cr-game { gap: 6px; }
    .cr-hud { gap: 5px; }
    .cr-stat { min-height: 43px; padding: 5px 8px; }
    .cr-stat strong { font-size: 18px; }
    .cr-stat-label { font-size: 9px; }
    .cr-overlay { align-items: flex-start; padding: 12px; }
    .cr-panel { margin: auto; padding: 17px; border-radius: 20px; }
    .cr-panel > p { margin: 8px auto 11px; font-size: 13px; }
    .cr-rules { margin-bottom: 11px; }
    .cr-rules span { min-height: 52px; padding: 7px 5px; }
    #crStart { min-height: 46px; padding: 11px 16px; }
}

@media (prefers-reduced-motion: reduce) {
    .cr-stat--crowd strong.is-pop { animation: none; }
    .cr-progress-fill,
    #crStart,
    .cr-toast.show { transition: none; }
}

@media (forced-colors: active) {
    .keyboard-input #crCanvas:focus,
    #crStart:focus-visible { outline-color: CanvasText; }
}
