/* === Gravity Flip — endless gravity runner === */

:root {
    --gf-night: hsl(228, 45%, 9%);
    --gf-night-deep: hsl(230, 50%, 5%);
    --gf-cyan: hsl(190, 85%, 55%);
    --gf-coral: hsl(10, 90%, 62%);
    --gf-violet: hsl(262, 80%, 66%);
    --gf-gold: hsl(42, 93%, 54%);
    --gf-text: hsl(220, 40%, 92%);
    --gf-text-dim: hsl(220, 25%, 68%);
    --gf-panel: rgba(15, 17, 38, 0.87);
    --gf-border: hsla(190, 70%, 60%, 0.22);

    --gf-font-display: 'Orbitron', 'Bahnschrift', 'Trebuchet MS', sans-serif;
    --gf-font-body: 'Outfit', 'Segoe UI', system-ui, sans-serif;
}

html,
body {
    margin: 0;
    padding: 0;
    background:
        radial-gradient(120% 70% at 50% -10%, hsl(228, 45%, 13%) 0%, transparent 60%),
        var(--gf-night-deep);
    font-family: var(--gf-font-body);
    color: var(--gf-text);
}

.gf-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 12px 12px calc(20px + env(safe-area-inset-bottom));
    box-sizing: border-box;
}

/* === Header === */
.gf-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.gf-header-side {
    display: flex;
    min-width: 0;
}

.gf-header-right {
    justify-content: flex-end;
    gap: 8px;
}

.gf-title {
    margin: 0;
    font-family: var(--gf-font-display);
    font-size: clamp(1.05rem, 4vw, 1.4rem);
    font-weight: 700;
    letter-spacing: 0.14em;
    text-align: center;
    background: linear-gradient(100deg, var(--gf-cyan) 20%, var(--gf-coral) 80%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-transform: uppercase;
}

.gf-back-btn {
    flex-shrink: 0;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--gf-border);
    color: var(--gf-text-dim);
    text-decoration: none;
    font-size: 0.85rem;
    transition: color 0.2s, border-color 0.2s;
}

.gf-back-btn:hover {
    color: var(--gf-text);
    border-color: var(--gf-cyan);
}

.gf-icon-btn {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 1px solid var(--gf-border);
    background: rgba(16, 20, 44, 0.6);
    color: var(--gf-text);
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s;
}

.gf-icon-btn:hover {
    border-color: var(--gf-cyan);
}

.gf-icon-btn:active {
    transform: scale(0.94);
}

.gf-pause-glyph,
.gf-pause-glyph::after {
    display: block;
    width: 4px;
    height: 14px;
    border-radius: 2px;
    background: currentColor;
}

.gf-pause-glyph {
    position: relative;
    margin-right: 8px;
}

.gf-pause-glyph::after {
    content: "";
    position: absolute;
    left: 8px;
    top: 0;
}

.gf-sound-off {
    display: none;
}

.gf-icon-btn.is-muted .gf-sound-on {
    display: none;
}

.gf-icon-btn.is-muted .gf-sound-off {
    display: block;
}

/* === HUD === */
.gf-hud {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.gf-hud-chip {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--gf-border);
    background: rgba(16, 20, 44, 0.55);
}

.gf-hud-label {
    font-family: var(--gf-font-display);
    font-size: 0.75rem;
    letter-spacing: 0.14em;
    color: var(--gf-text-dim);
}

.gf-hud-value {
    font-family: var(--gf-font-display);
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--gf-cyan);
    min-width: 3.2em;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.gf-hud-best .gf-hud-value {
    color: var(--gf-gold);
}

#hudBest.record-beaten {
    animation: gf-gold-flash 0.9s ease-in-out 3;
}

@keyframes gf-gold-flash {

    0%,
    100% {
        text-shadow: none;
    }

    50% {
        text-shadow: 0 0 14px hsla(42, 93%, 60%, 0.9);
        color: hsl(45, 100%, 68%);
    }
}

.gf-hud-coins .gf-hud-value {
    color: var(--gf-violet);
    min-width: 2em;
}

/* === Stage === */
.gf-stage {
    --stage-w: min(calc(100vw - 24px), calc((100dvh - 180px) * (800 / 450)));
    position: relative;
    width: min(100%, var(--stage-w));
    aspect-ratio: 800 / 450;
    margin: 0 auto;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid var(--gf-border);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.35),
        0 18px 48px rgba(0, 0, 0, 0.5),
        0 0 64px hsla(190, 82%, 50%, 0.08);
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    background: #101426;
    cursor: pointer;
}

@supports not (height: 100dvh) {
    .gf-stage {
        --stage-w: min(calc(100vw - 24px), calc((100vh - 180px) * (800 / 450)));
    }
}

/* Short viewports = landscape phones: reclaim chrome space. */
@media (max-height: 540px) {
    .gf-stage {
        --stage-w: min(calc(100vw - 16px), calc((100dvh - 108px) * (800 / 450)));
    }

    @supports not (height: 100dvh) {
        .gf-stage {
            --stage-w: min(calc(100vw - 16px), calc((100vh - 108px) * (800 / 450)));
        }
    }
}

/* Rotate hint is for phones only; a narrow desktop window stays playable. */
@media (orientation: portrait) and (min-width: 769px) {
    .sbg-rotate-hint.force-landscape {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .gf-stage {
        border-radius: 12px;
    }
}

#gameCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* === Overlays === */
.gf-overlay {
    position: absolute;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 14px;
    background: linear-gradient(to bottom, hsla(230, 55%, 6%, 0.5), hsla(230, 55%, 6%, 0.8));
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.hidden {
    display: none !important;
}

.gf-panel {
    width: min(340px, 100%);
    max-height: 100%;
    overflow-y: auto;
    padding: 22px 20px;
    text-align: center;
    border-radius: 20px;
    border: 1px solid var(--gf-border);
    background: var(--gf-panel);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55), inset 0 1px 0 hsla(220, 60%, 90%, 0.06);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 13px;
    animation: gf-rise 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@media (prefers-reduced-motion: reduce) {
    .gf-panel {
        animation: none;
    }
}

@keyframes gf-rise {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.gf-logo-badge {
    position: relative;
    width: 58px;
    height: 58px;
    border-radius: 18px;
    background: linear-gradient(160deg, hsl(228, 45%, 20%), hsl(232, 55%, 12%) 70%);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45), inset 0 1px 0 hsla(220, 60%, 90%, 0.08);
    overflow: hidden;
}

.gf-logo-floor {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 9px;
    height: 7px;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--gf-cyan), hsl(190, 85%, 42%));
}

.gf-logo-ceiling {
    position: absolute;
    left: 10px;
    right: 10px;
    top: 9px;
    height: 7px;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--gf-coral), hsl(10, 90%, 48%));
}

.gf-logo-cube {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border-radius: 5px;
    background: linear-gradient(160deg, #d9fbff, var(--gf-cyan));
    box-shadow: 0 0 12px hsla(190, 90%, 65%, 0.8);
}

.gf-panel-title {
    margin: 0;
    font-family: var(--gf-font-display);
    font-size: 1.3rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    color: var(--gf-text);
}

.gf-panel-subtitle {
    margin: -6px 0 0;
    font-size: 0.85rem;
    color: var(--gf-text-dim);
}

.gf-menu-best {
    margin: 0;
    font-family: var(--gf-font-display);
    font-size: 0.78rem;
    letter-spacing: 0.12em;
    color: var(--gf-text-dim);
}

.gf-menu-best span:last-child {
    color: var(--gf-gold);
    font-weight: 700;
}

/* === Buttons === */
.gf-btn {
    display: block;
    width: 100%;
    min-height: 50px;
    padding: 12px 18px;
    border-radius: 14px;
    font-family: var(--gf-font-display);
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    transition: transform 0.15s, filter 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}

.gf-btn:active {
    transform: translateY(1px) scale(0.98);
}

.gf-btn-primary {
    border: none;
    color: #1d1503;
    background: linear-gradient(160deg, hsl(45, 96%, 62%), hsl(40, 93%, 50%));
    box-shadow: 0 8px 24px hsla(42, 93%, 54%, 0.35), inset 0 1px 0 hsla(50, 100%, 85%, 0.6);
}

.gf-btn-primary:hover {
    filter: brightness(1.07);
}

.gf-btn-ghost {
    border: 1px solid var(--gf-border);
    color: var(--gf-text-dim);
    background: transparent;
}

.gf-btn-ghost:hover {
    color: var(--gf-text);
    border-color: var(--gf-cyan);
}

.gf-hint {
    margin: 2px 0 0;
    font-size: 0.78rem;
    line-height: 1.6;
    color: var(--gf-text-dim);
}

.gf-hint kbd {
    display: inline-block;
    min-width: 20px;
    padding: 2px 5px;
    margin: 0 2px;
    border-radius: 6px;
    border: 1px solid var(--gf-border);
    border-bottom-width: 2px;
    font-family: var(--gf-font-body);
    font-size: 0.78rem;
    color: var(--gf-text);
    background: rgba(255, 255, 255, 0.05);
}

/* === Game over results === */
.gf-record-badge {
    padding: 6px 14px;
    border-radius: 999px;
    font-family: var(--gf-font-display);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    color: #241a02;
    background: linear-gradient(120deg, hsl(45, 96%, 62%), hsl(36, 95%, 55%));
    box-shadow: 0 0 22px hsla(42, 93%, 54%, 0.55);
    animation: gf-pulse 1.1s ease-in-out infinite alternate;
}

@media (prefers-reduced-motion: reduce) {
    .gf-record-badge {
        animation: none;
    }
}

@keyframes gf-pulse {
    from {
        transform: scale(1);
        box-shadow: 0 0 14px hsla(42, 93%, 54%, 0.4);
    }

    to {
        transform: scale(1.05);
        box-shadow: 0 0 30px hsla(42, 93%, 54%, 0.75);
    }
}

.gf-results {
    display: flex;
    gap: 8px;
    width: 100%;
}

.gf-result-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 6px;
    border-radius: 14px;
    border: 1px solid var(--gf-border);
    background: rgba(255, 255, 255, 0.03);
}

.gf-result-label {
    font-family: var(--gf-font-display);
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    color: var(--gf-text-dim);
}

.gf-result-value {
    font-family: var(--gf-font-display);
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--gf-cyan);
    font-variant-numeric: tabular-nums;
}

.gf-result-box:nth-child(2) .gf-result-value {
    color: var(--gf-gold);
}

.gf-result-box:nth-child(3) .gf-result-value {
    color: var(--gf-violet);
}

/* === Ads helpers === */
.ad-mobile-banner {
    margin-top: 14px;
}

@media (min-width: 1025px) {
    .ad-mobile-banner {
        display: none;
    }
}

/* === Focus visibility === */
.gf-btn:focus-visible,
.gf-icon-btn:focus-visible,
.gf-back-btn:focus-visible {
    outline: 2px solid var(--gf-cyan);
    outline-offset: 2px;
}
