:root {
    --rr-bg: #020b16;
    --rr-panel: #03172a;
    --rr-panel-soft: rgba(3, 23, 42, 0.86);
    --rr-border: rgba(125, 211, 252, 0.2);
    --rr-text: #e0f2fe;
    --rr-muted: #94a3b8;
    --rr-cyan: #38bdf8;
    --rr-blue: #2563eb;
    --rr-green: #34d399;
    --rr-amber: #fbbf24;
    --rr-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    color: var(--rr-text);
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background:
        radial-gradient(
            circle at 50% -20%,
            rgba(14, 165, 233, 0.22),
            transparent 40%
        ),
        linear-gradient(180deg, #03172a, var(--rr-bg));
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    font: inherit;
}

.rr-shell {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.rr-topbar {
    min-height: 70px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding:
        max(0.8rem, env(safe-area-inset-top, 0px))
        clamp(1rem, 3vw, 2.2rem)
        0.8rem;
    border-bottom: 1px solid rgba(125, 211, 252, 0.12);
    background: rgba(2, 11, 22, 0.78);
    backdrop-filter: blur(18px);
}

.rr-brand {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    color: inherit;
    text-decoration: none;
}

.rr-brand img {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    object-fit: contain;
}

.rr-brand span {
    min-width: 0;
    display: grid;
}

.rr-brand strong {
    font-size: 0.9rem;
}

.rr-brand small {
    overflow: hidden;
    color: var(--rr-muted);
    font-size: 0.7rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tc-game-back {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    margin-left: auto;
    padding: 0.65rem 0.9rem;
    color: #dbeafe;
    font-size: 0.76rem;
    font-weight: 800;
    text-decoration: none;
    border: 1px solid var(--rr-border);
    border-radius: 13px;
    background: rgba(8, 47, 73, 0.58);
}

.rr-top-actions {
    display: flex;
    gap: 0.55rem;
}

.rr-icon-button {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    color: white;
    border: 1px solid var(--rr-border);
    border-radius: 13px;
    background: rgba(8, 47, 73, 0.58);
    cursor: pointer;
}

.rr-main {
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    place-items: center;
    padding: clamp(0.8rem, 2.5vw, 2rem);
}

.rr-game-card {
    width: min(1120px, 100%);
    overflow: hidden;
    border: 1px solid var(--rr-border);
    border-radius: clamp(18px, 2vw, 28px);
    background:
        linear-gradient(
            180deg,
            rgba(8, 47, 73, 0.84),
            rgba(3, 23, 42, 0.94)
        );
    box-shadow: var(--rr-shadow);
}

.rr-hud {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1px;
    background: rgba(125, 211, 252, 0.12);
}

.rr-hud-box {
    min-width: 0;
    min-height: 70px;
    display: grid;
    place-content: center;
    gap: 0.2rem;
    padding: 0.75rem;
    text-align: center;
    background: rgba(3, 23, 42, 0.94);
}

.rr-hud-box span {
    color: var(--rr-muted);
    font-size: 0.62rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.rr-hud-box strong {
    font-size: 1.15rem;
}

.rr-beat-track {
    position: relative;
    height: 8px;
    overflow: hidden;
    background: rgba(2, 11, 22, 0.9);
}

.rr-beat-track span {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 2;
    color: rgba(224, 242, 254, 0.78);
    font-size: 0.52rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    transform: translate(-50%, -50%);
    white-space: nowrap;
}

.rr-beat-fill {
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--rr-cyan), var(--rr-green));
}

.rr-canvas-wrap {
    position: relative;
    width: 100%;
    height: min(68vh, 660px);
    min-height: 500px;
    overflow: hidden;
    isolation: isolate;
    touch-action: none;
    background:
        radial-gradient(
            circle at 50% -10%,
            rgba(125, 211, 252, 0.2),
            transparent 44%
        ),
        linear-gradient(
            180deg,
            #166789,
            #0a627c 42%,
            #07536b 72%,
            #04394e
        );
}

#rrCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
}

.rr-water-glow {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background:
        linear-gradient(
            105deg,
            transparent 10%,
            rgba(186, 230, 253, 0.08) 35%,
            transparent 55%
        );
}

.rr-vignette {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    box-shadow: inset 0 0 80px rgba(2, 11, 22, 0.42);
}

.rr-screen {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: none;
    place-items: center;
    padding: 1rem;
    background: rgba(2, 11, 22, 0.76);
    backdrop-filter: blur(10px);
}

.rr-screen-active {
    display: grid;
}

.rr-screen-card {
    width: min(520px, 100%);
    max-height: calc(100% - 1rem);
    overflow-y: auto;
    padding: clamp(1.25rem, 4vw, 2.2rem);
    text-align: center;
    border: 1px solid rgba(125, 211, 252, 0.24);
    border-radius: 24px;
    background:
        linear-gradient(
            180deg,
            rgba(8, 47, 73, 0.96),
            rgba(3, 23, 42, 0.98)
        );
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}

.rr-kicker {
    color: #7dd3fc;
    font-size: 0.68rem;
    font-weight: 900;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.rr-screen-card h1,
.rr-screen-card h2 {
    margin: 0.65rem 0;
}

.rr-screen-card h1 {
    font-size: clamp(2rem, 8vw, 4rem);
}

.rr-screen-card p {
    margin: 0 auto 1.25rem;
    color: #cbd5e1;
    line-height: 1.65;
}

.rr-control-grid,
.rr-results-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
    margin: 1rem 0;
}

.rr-control-grid span,
.rr-results-grid div {
    padding: 0.8rem;
    border: 1px solid rgba(125, 211, 252, 0.14);
    border-radius: 14px;
    color: var(--rr-muted);
    font-size: 0.76rem;
    background: rgba(2, 11, 22, 0.32);
}

.rr-results-grid div {
    display: grid;
    gap: 0.3rem;
}

.rr-results-grid strong {
    color: white;
    font-size: 1.15rem;
}

.rr-best {
    margin: 0.8rem 0 1.2rem;
    color: var(--rr-muted);
}

.rr-best strong {
    color: white;
}

.rr-final-score {
    display: grid;
    gap: 0.3rem;
    margin: 1rem 0;
}

.rr-final-score span {
    color: var(--rr-muted);
    font-size: 0.7rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.rr-final-score strong {
    font-size: 2.8rem;
}

.rr-primary-button {
    min-height: 50px;
    padding: 0.8rem 1.2rem;
    color: white;
    font-weight: 900;
    border: 1px solid rgba(125, 211, 252, 0.36);
    border-radius: 15px;
    background: linear-gradient(180deg, #38bdf8, #2563eb);
    cursor: pointer;
}

.rr-lane-buttons {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 12;
    display: grid;
    gap: 0.35rem;
}

.rr-lane-buttons button {
    min-width: 72px;
    min-height: 38px;
    color: white;
    font-size: 0.68rem;
    font-weight: 900;
    border: 1px solid rgba(125, 211, 252, 0.36);
    border-radius: 12px;
    background: rgba(3, 23, 42, 0.76);
    backdrop-filter: blur(8px);
    cursor: pointer;
}

.rr-game-footer {
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1rem;
    color: var(--rr-muted);
    font-size: 0.77rem;
    background: rgba(3, 23, 42, 0.96);
}

.rr-game-footer b {
    color: #dbeafe;
}

.rr-game-badge {
    flex: 0 0 auto;
    padding: 0.28rem 0.55rem;
    color: #fde68a;
    border: 1px solid rgba(251, 191, 36, 0.28);
    border-radius: 999px;
    background: rgba(146, 64, 14, 0.18);
}

@media (max-width: 720px) {
    .rr-topbar {
        gap: 0.45rem;
        padding-right: 0.65rem;
        padding-left: 0.65rem;
    }

    .rr-brand img {
        width: 38px;
        height: 38px;
    }

    .rr-brand small {
        display: none;
    }

    .tc-game-back {
        min-height: 38px;
        padding: 0.5rem 0.65rem;
        border-radius: 11px;
    }

    .tc-game-back span:last-child {
        display: none;
    }

    .rr-icon-button {
        width: 38px;
        height: 38px;
        border-radius: 11px;
    }

    .rr-main {
        display: block;
        padding: 0;
    }

    .rr-game-card {
        width: 100%;
        height: calc(100dvh - 70px);
        display: grid;
        grid-template-rows:
            auto
            8px
            minmax(0, 1fr)
            auto;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .rr-hud-box {
        min-height: 58px;
        padding: 0.45rem 0.25rem;
    }

    .rr-hud-box span {
        font-size: 0.52rem;
    }

    .rr-hud-box strong {
        font-size: 0.95rem;
    }

    .rr-canvas-wrap {
        height: 100%;
        min-height: 0;
    }

    .rr-game-footer {
        min-height: 44px;
        padding:
            0.55rem
            0.7rem
            max(0.55rem, env(safe-area-inset-bottom, 0px));
    }

    .rr-game-footer > span:first-child {
        display: none;
    }

    .rr-game-badge {
        margin-left: auto;
    }

    .rr-screen-card {
        padding: 1rem;
    }

    .rr-control-grid,
    .rr-results-grid {
        grid-template-columns: 1fr;
    }
}

/* -------------------------------------------------
   TanksConnected arcade standalone viewport owner
-------------------------------------------------- */

@media (display-mode: standalone) and (max-width: 720px) {
    html,
    body {
        width: 100%;
        height: 100%;
        min-height: 0;
        overflow: hidden;
        overscroll-behavior: none;
    }

    .rr-shell {
        width: 100%;
        height: 100svh;
        min-height: 0;
        max-height: 100svh;
        overflow: hidden;
    }

    .rr-topbar {
        flex: 0 0 auto;
        padding-top: max(
            0.55rem,
            env(safe-area-inset-top, 0px)
        );
    }

    .rr-main {
        flex: 1 1 auto;
        min-height: 0;
        display: block;
        overflow: hidden;
        padding: 0;
    }

    .rr-game-card {
        width: 100%;
        height: 100%;
        min-height: 0;
        max-height: 100%;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        border: 0;
        border-radius: 0;
    }

    .rr-hud {
        flex: 0 0 auto;
    }

    .rr-beat-track {
        flex: 0 0 auto;
    }

    .rr-canvas-wrap {
        flex: 1 1 0;
        width: 100%;
        height: 0;
        min-height: 0;
        max-height: none;
        overflow: hidden;
    }

    .rr-game-footer {
        display: none;
    }

    .rr-lane-buttons {
        bottom: max(
            12px,
            env(safe-area-inset-bottom, 0px)
        );
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}
