/*
 * Gravity Flip Runner Styles
 * Copyright (c) 2026 VersionBear - https://versionbear.itssljk.com
 * Licensed under MIT: https://opensource.org/licenses/MIT
 */

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

:root {
    --bg-dark: #06060e;
    --accent: #6c5ce7;
    --accent-glow: #a29bfe;
    --danger: #ff4757;
    --success: #2ed573;
    --gold: #ffc048;
    --text: #e8e8f0;
    --text-dim: #6a6a88;
    --radius: 14px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bot: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    -webkit-touch-callout: none;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

body {
    font-family: 'Outfit', system-ui, sans-serif;
    background: var(--bg-dark);
    background-image: radial-gradient(ellipse 80% 60% at 50% 120%, rgba(108, 92, 231, 0.08) 0%, transparent 60%);
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    padding: var(--safe-top) var(--safe-right) var(--safe-bot) var(--safe-left);
}

#game-wrapper {
    position: relative;
    width: 840px;
    max-width: 96vw;
    max-height: calc(100vh - 20px);
    max-height: calc(100dvh - 20px);
    aspect-ratio: 840/420;
}

#hud {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 6px 4px 8px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 5;
    pointer-events: none;
}

.hud-group {
    display: flex;
    gap: 20px;
    align-items: flex-end
}

#hud .hud-item .label {
    font-size: .6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-dim)
}

#hud .hud-item .value {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--accent-glow);
    text-shadow: 0 0 18px rgba(108, 92, 231, .4);
    line-height: 1
}

#best-display .value {
    color: var(--success);
    text-shadow: 0 0 14px rgba(46, 213, 115, .3)
}

#combo-display {
    transition: opacity .2s
}

#combo-display .value {
    color: var(--gold);
    text-shadow: 0 0 14px rgba(255, 192, 72, .35)
}

#speed-display .value {
    font-size: .85rem;
    font-weight: 700;
    color: var(--text-dim)
}

canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: var(--radius);
    box-shadow: 0 0 0 1px rgba(108, 92, 231, .2), 0 10px 40px rgba(0, 0, 0, .6);
    touch-action: none;
}

.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    background: rgba(4, 4, 12, .88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 10;
    transition: opacity .4s ease;
    padding: 16px;
    top: 0;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none
}

.overlay h1 {
    font-size: 2.6rem;
    font-weight: 900;
    margin-bottom: 4px;
    background: linear-gradient(135deg, #c0b3ff, var(--accent), #8b7cf7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -.02em;
    text-align: center
}

.overlay .subtitle {
    font-size: .9rem;
    color: var(--text-dim);
    margin-bottom: 28px;
    text-align: center
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 22px;
    width: min(320px, 90%)
}

.stat-card {
    background: rgba(255, 255, 255, .04);
    border: 1px solid rgba(255, 255, 255, .06);
    border-radius: 10px;
    padding: 10px 6px;
    text-align: center
}

.stat-card.main {
    grid-column: 1/-1;
    background: rgba(108, 92, 231, .08);
    border-color: rgba(108, 92, 231, .18)
}

.stat-card .stat-value {
    font-size: 1rem;
    font-weight: 800;
    color: var(--accent-glow);
    line-height: 1
}

.stat-card.main .stat-value {
    font-size: 2.4rem
}

.stat-card .stat-label {
    font-size: .58rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-dim);
    margin-top: 3px
}

.new-best-badge {
    display: inline-block;
    font-size: .68rem;
    font-weight: 800;
    color: var(--success);
    background: rgba(46, 213, 115, .1);
    border: 1px solid rgba(46, 213, 115, .2);
    border-radius: 8px;
    padding: 3px 12px;
    margin-top: 5px;
    opacity: 0;
    transition: opacity .3s
}

.new-best-badge.show {
    opacity: 1
}

.btn {
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 800;
    padding: 14px 42px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), #5341c9);
    box-shadow: 0 4px 22px rgba(108, 92, 231, .35), inset 0 1px 0 rgba(255, 255, 255, .1);
    transition: transform .15s, box-shadow .15s;
    outline: none;
    -webkit-tap-highlight-color: transparent
}

.btn:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 8px 32px rgba(108, 92, 231, .5)
}

.btn:active {
    transform: translateY(0) scale(.97)
}

.key-hint {
    margin-top: 12px;
    font-size: .72rem;
    color: var(--text-dim)
}

.key-hint kbd {
    display: inline-block;
    font-family: 'Outfit', sans-serif;
    background: rgba(255, 255, 255, .07);
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 5px;
    padding: 2px 8px;
    font-size: .68rem;
    margin: 0 2px
}

#toast-container {
    position: absolute;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    pointer-events: none;
    width: 100%;
}

.toast {
    font-size: .8rem;
    font-weight: 800;
    padding: 5px 14px;
    border-radius: 8px;
    animation: toastIn .3s ease, toastOut .4s ease 1.2s forwards;
    white-space: nowrap
}

.toast.milestone {
    color: #fff;
    background: linear-gradient(135deg, var(--accent), #8b7cf7);
    box-shadow: 0 4px 18px rgba(108, 92, 231, .4)
}

.toast.nearmiss {
    color: var(--gold);
    background: rgba(255, 192, 72, .12);
    border: 1px solid rgba(255, 192, 72, .25);
    font-size: .72rem
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-12px) scale(.9)
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1)
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0)
    }

    to {
        opacity: 0;
        transform: translateY(-8px)
    }
}

#touch-zone {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 5;
    -webkit-tap-highlight-color: transparent
}

#tap-flash {
    position: fixed;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    background: rgba(162, 155, 254, .06);
    opacity: 0;
    transition: opacity .08s
}

#rotate-hint {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--bg-dark);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    color: var(--text-dim);
    font-size: .9rem;
    text-align: center;
    padding: 20px
}

#rotate-hint .icon {
    font-size: 3rem;
    animation: wiggle 1.5s ease-in-out infinite
}

@keyframes wiggle {

    0%,
    100% {
        transform: rotate(0deg)
    }

    25% {
        transform: rotate(20deg)
    }

    75% {
        transform: rotate(-20deg)
    }
}

/* -- Mobile Responsive -- */
@media(max-width:600px) {
    #game-wrapper {
        max-width: 100vw;
        padding: 0 2px
    }

    canvas {
        border-radius: 10px
    }

    .overlay {
        top: 38px;
        border-radius: 10px;
        padding: 12px
    }

    .overlay h1 {
        font-size: 1.6rem
    }

    .overlay .subtitle {
        font-size: .75rem;
        margin-bottom: 18px
    }

    .btn {
        padding: 12px 34px;
        font-size: .9rem
    }

    .key-hint {
        display: none
    }

    #hud {
        padding: 4px 4px 6px
    }

    .hud-group {
        gap: 14px
    }

    #hud .hud-item .label {
        font-size: .5rem
    }

    #hud .hud-item .value {
        font-size: 1.15rem
    }

    #speed-display .value {
        font-size: .72rem
    }

    .stat-card.main .stat-value {
        font-size: 2rem
    }

    .stat-card .stat-value {
        font-size: .85rem
    }

    .stats-grid {
        gap: 8px;
        margin-bottom: 16px
    }

    #toast-container {
        top: 48px
    }

    .toast {
        font-size: .7rem;
        padding: 4px 10px
    }
}

@media(max-width:400px) {
    .overlay h1 {
        font-size: 1.35rem
    }

    .stats-grid {
        width: 95%
    }
}

/* Portrait phone: suggest landscape */
@media(max-width:500px) and (orientation:portrait) and (hover:none) {
    #rotate-hint {
        display: flex
    }
}

/* Touch devices: show full-screen touch zone & hide keyboard hints */
@media(hover:none) and (pointer:coarse) {
    #touch-zone {
        display: block
    }

    .key-hint {
        display: none !important
    }
}

/* Footer */
#game-footer {
    text-align: center;
    padding: 10px 0;
    font-size: .75rem;
    color: var(--text-dim)
}

#game-footer a {
    color: var(--accent-glow);
    text-decoration: none;
    transition: color .2s
}

#game-footer a:hover {
    color: var(--accent);
    text-decoration: underline
}
