:root {
    --bg: #030405;
    --bg-soft: #080b0f;

    --panel: rgba(10, 14, 20, 0.90);

    --text: #f4f7f9;
    --muted: #7f8a94;

    --accent: #3545b0;
    --accent-bright: #6475ff;
    --accent-soft: rgba(53, 69, 176, 0.18);

    --danger: #df4459;
    --border: rgba(255, 255, 255, 0.08);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

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

html {
    background: var(--bg);
}

body {
    min-height: 100vh;

    padding:
        max(18px, env(safe-area-inset-top))
        max(18px, env(safe-area-inset-right))
        max(18px, env(safe-area-inset-bottom))
        max(18px, env(safe-area-inset-left));

    background:
        radial-gradient(
            circle at 50% 0%,
            rgba(53, 69, 176, 0.18),
            transparent 34%
        ),
        linear-gradient(
            180deg,
            var(--bg-soft) 0%,
            var(--bg) 100%
        );

    color: var(--text);

    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Helvetica,
        Arial,
        sans-serif;

    -webkit-font-smoothing: antialiased;
}

button,
a {
    font: inherit;
}

.gridrun-shell {
    width: min(100%, 980px);
    margin: 0 auto;
}

.gridrun-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 28px;

    margin-bottom: 24px;
}

.back-link {
    display: inline-block;
    margin-bottom: 20px;

    color: var(--muted);
    text-decoration: none;

    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.11em;
}

.back-link:hover,
.back-link:focus-visible {
    color: var(--text);
}

.eyebrow {
    margin-bottom: 9px;

    color: var(--accent-bright);

    font-size: 12px;
    font-weight: 760;
    letter-spacing: 0.20em;
}

h1 {
    margin: 0;

    font-size: clamp(36px, 7vw, 72px);
    line-height: 0.95;
    letter-spacing: -0.05em;

    overflow-wrap: anywhere;
}

.subtitle {
    margin: 12px 0 0;

    color: var(--muted);
    font-size: 17px;
}

.system-state {
    display: flex;
    align-items: center;
    gap: 9px;

    padding-bottom: 7px;

    color: var(--muted);

    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.12em;
    white-space: nowrap;
}

.system-dot {
    width: 7px;
    height: 7px;

    border-radius: 50%;

    background: var(--accent-bright);

    box-shadow:
        0 0 10px rgba(100, 117, 255, 0.92);
}

.game-frame {
    overflow: hidden;

    border: 1px solid rgba(53, 69, 176, 0.40);
    border-radius: 20px;

    background: var(--panel);

    box-shadow:
        0 28px 80px rgba(0, 0, 0, 0.38);
}

.hud {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));

    border-bottom: 1px solid var(--border);

    background:
        linear-gradient(
            90deg,
            rgba(53, 69, 176, 0.10),
            transparent 46%
        );
}

.hud-block {
    min-width: 0;

    padding: 15px 18px;

    border-right: 1px solid var(--border);
}

.hud-block:last-child {
    border-right: 0;
}

.hud-label {
    display: block;
    margin-bottom: 5px;

    color: var(--muted);

    font-size: 9px;
    font-weight: 760;
    letter-spacing: 0.17em;
}

.hud strong {
    display: block;
    overflow: hidden;

    color: var(--text);

    font-size: 18px;
    font-weight: 740;
    letter-spacing: 0.06em;

    text-overflow: ellipsis;
    white-space: nowrap;
}

#lives {
    color: var(--accent-bright);
}

.game-area {
    position: relative;

    max-width: 684px;
    margin: 0 auto;

    overflow: hidden;

    background: #020305;

    touch-action: none;
}

#game {
    display: block;

    width: 100%;
    height: auto;

    aspect-ratio: 19 / 21;

    background: #020305;

    touch-action: none;
}

.scanlines {
    position: absolute;
    inset: 0;

    pointer-events: none;

    opacity: 0.07;

    background:
        repeating-linear-gradient(
            180deg,
            rgba(255, 255, 255, 0.13) 0,
            rgba(255, 255, 255, 0.13) 1px,
            transparent 1px,
            transparent 4px
        );
}

.game-overlay {
    position: absolute;
    inset: 0;

    display: grid;
    place-items: center;

    padding: 24px;

    overflow: auto;

    background:
        radial-gradient(
            circle at 50% 50%,
            rgba(53, 69, 176, 0.12),
            rgba(2, 3, 5, 0.78) 54%,
            rgba(2, 3, 5, 0.94) 100%
        );

    backdrop-filter: blur(2px);
}

.overlay-panel {
    width: min(100%, 470px);

    padding: 30px 28px;

    border: 1px solid rgba(53, 69, 176, 0.42);
    border-radius: 18px;

    background: rgba(7, 10, 15, 0.91);

    text-align: center;
}

.overlay-kicker {
    margin-bottom: 12px;

    color: var(--accent-bright);

    font-size: 11px;
    font-weight: 780;
    letter-spacing: 0.20em;
}

.overlay-kicker.danger {
    color: var(--danger);
}

.overlay-panel h2 {
    margin: 0;

    font-size: clamp(34px, 8vw, 58px);
    line-height: 1;
    letter-spacing: -0.045em;

    overflow-wrap: anywhere;
}

.overlay-panel p {
    margin: 18px 0 0;

    color: var(--muted);

    font-size: 15px;
    line-height: 1.55;
}

.overlay-panel p strong {
    color: var(--text);
}

.start-button {
    width: 100%;
    min-height: 52px;

    margin-top: 22px;
    padding: 0 24px;

    border: 1px solid var(--accent-bright);
    border-radius: 999px;

    background: var(--accent);
    color: #fff;

    cursor: pointer;

    font-weight: 760;
    letter-spacing: 0.11em;
}

.start-button:hover {
    background: var(--accent-bright);
}

.controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 16px;

    margin-top: 20px;

    color: var(--muted);

    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
}

.mobile-controls-hint {
    display: none;
}

.pause-indicator {
    position: absolute;
    top: 50%;
    left: 50%;

    transform: translate(-50%, -50%);

    min-width: 220px;

    padding: 14px 18px;

    border: 1px solid rgba(53, 69, 176, 0.50);
    border-radius: 12px;

    background: rgba(5, 7, 10, 0.94);
    color: var(--text);

    cursor: pointer;

    font-size: 14px;
    font-weight: 760;
    letter-spacing: 0.16em;

    z-index: 5;
}

.pause-indicator small {
    display: block;

    margin-top: 7px;

    color: var(--muted);

    font-size: 9px;
    letter-spacing: 0.10em;
}

.hidden {
    display: none !important;
}


/* TOUCH */

.touch-pad {
    display: none;

    align-items: center;
    justify-content: space-between;
    gap: 18px;

    padding: 16px 18px;

    border-top: 1px solid var(--border);

    background:
        linear-gradient(
            180deg,
            rgba(53, 69, 176, 0.06),
            rgba(5, 7, 10, 0.74)
        );

    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.dpad {
    display: grid;
    grid-template-columns: repeat(3, 62px);
    grid-template-rows: repeat(2, 62px);
    gap: 7px;
}

.touch-button {
    min-width: 58px;
    min-height: 58px;

    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 14px;

    background: rgba(255, 255, 255, 0.055);
    color: var(--text);

    cursor: pointer;

    font-size: 23px;
    font-weight: 800;

    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.touch-button:active,
.touch-button.is-active {
    background: rgba(53, 69, 176, 0.30);
    border-color: rgba(100, 117, 255, 0.76);
}

.touch-button.up {
    grid-column: 2;
    grid-row: 1;
}

.touch-button.left {
    grid-column: 1;
    grid-row: 2;
}

.touch-button.down {
    grid-column: 2;
    grid-row: 2;
}

.touch-button.right {
    grid-column: 3;
    grid-row: 2;
}

.touch-button.pause {
    min-width: 88px;
    min-height: 88px;

    border-color: rgba(100, 117, 255, 0.45);

    font-size: 18px;
    letter-spacing: 0.08em;
}


/* MOBILE */

@media (max-width: 760px), (pointer: coarse) {
    body {
        padding:
            max(12px, env(safe-area-inset-top))
            max(12px, env(safe-area-inset-right))
            max(12px, env(safe-area-inset-bottom))
            max(12px, env(safe-area-inset-left));
    }

    .gridrun-header {
        display: block;
        margin-bottom: 18px;
    }

    .back-link {
        margin-bottom: 15px;
    }

    .system-state {
        display: none;
    }

    .hud-block {
        padding: 10px 5px;
        text-align: center;
    }

    .hud-label {
        font-size: 8px;
        letter-spacing: 0.08em;
    }

    .hud strong {
        font-size: 14px;
        letter-spacing: 0.02em;
    }

    .desktop-controls {
        display: none;
    }

    .mobile-controls-hint {
        display: flex;
    }

    .game-frame.is-playing .touch-pad {
        display: flex;
    }

    .game-frame.is-idle .game-area,
    .game-frame.is-gameover .game-area {
        min-height: 520px;
    }

    .game-frame.is-idle #game,
    .game-frame.is-gameover #game {
        position: absolute;
        inset: 0;

        width: 100%;
        height: 100%;

        aspect-ratio: auto;
    }

    .game-overlay {
        place-items: start center;
        padding: 18px 14px;
    }

    .overlay-panel {
        width: 100%;
        margin: auto 0;
        padding: 22px 16px;
    }
}

@media (max-width: 430px) {
    .dpad {
        grid-template-columns: repeat(3, 54px);
        grid-template-rows: repeat(2, 54px);
        gap: 6px;
    }

    .touch-button {
        min-width: 50px;
        min-height: 50px;
    }

    .touch-button.pause {
        min-width: 72px;
        min-height: 72px;
    }

    .touch-pad {
        padding: 12px;
    }
}

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