/* === Sky Climber — Endless Vertical Platformer === */

:root {
    --sc-night: hsl(248, 45%, 9%);
    --sc-night-deep: hsl(250, 50%, 5%);
    --sc-cyan: hsl(190, 82%, 54%);
    --sc-cyan-soft: hsla(190, 82%, 60%, 0.16);
    --sc-gold: hsl(42, 93%, 54%);
    --sc-gold-soft: hsla(42, 93%, 54%, 0.18);
    --sc-coral: hsl(14, 88%, 62%);
    --sc-text: hsl(220, 40%, 92%);
    --sc-text-dim: hsl(220, 25%, 68%);
    --sc-panel: rgba(16, 12, 40, 0.86);
    --sc-border: hsla(190, 80%, 65%, 0.22);

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

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

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

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

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

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

.sc-title {
    margin: 0;
    font-family: var(--sc-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(--sc-cyan) 20%, var(--sc-gold) 80%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-transform: uppercase;
}

.sc-icon-btn {
    color: var(--sc-text);
}

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

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

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

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

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

.sc-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(--sc-border);
    background: rgba(20, 16, 52, 0.6);
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s;
}

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

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

.sc-pause-glyph,
.sc-pause-glyph::after {
    display: block;
    width: 4px;
    height: 14px;
    border-radius: 2px;
    background: var(--sc-text);
}

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

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

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

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

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

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

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

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

@keyframes sc-gold-flash {

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

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

/* === Stage === */
.sc-stage {
    --stage-h: min(calc(100dvh - 190px), 760px);
    position: relative;
    width: min(100%, calc(var(--stage-h) * 400 / 640));
    aspect-ratio: 400 / 640;
    margin: 0 auto;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid var(--sc-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: #141034;
}

@supports not (height: 100dvh) {
    .sc-stage {
        --stage-h: min(calc(100vh - 190px), 760px);
    }
}

/* Short viewports = landscape phones: reclaim chrome space. */
@media (max-height: 540px) {
    .sc-stage {
        --stage-h: min(calc(100dvh - 108px), 760px);
    }

    @supports not (height: 100dvh) {
        .sc-stage {
            --stage-h: min(calc(100vh - 108px), 760px);
        }
    }
}

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

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

.hidden {
    display: none !important;
}

.sc-panel {
    width: min(320px, 100%);
    padding: 26px 22px;
    text-align: center;
    border-radius: 20px;
    border: 1px solid var(--sc-border);
    background: var(--sc-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: 14px;
    animation: sc-rise 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

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

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

.sc-logo-badge {
    width: 58px;
    height: 58px;
    border-radius: 18px;
    background: linear-gradient(160deg, hsl(190, 82%, 46%), hsl(248, 60%, 38%) 70%);
    display: grid;
    place-items: center;
    box-shadow: 0 8px 22px hsla(190, 82%, 50%, 0.35), inset 0 1px 0 hsla(255, 255%, 255%, 0.25);
}

.sc-logo-badge span {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: radial-gradient(circle at 32% 28%, #ffffff 0 18%, var(--sc-gold) 19% 100%);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
}

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

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

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

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

/* === Buttons === */
.sc-btn {
    display: block;
    width: 100%;
    min-height: 50px;
    padding: 12px 18px;
    border-radius: 14px;
    font-family: var(--sc-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;
}

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

.sc-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);
}

.sc-btn-primary:hover {
    filter: brightness(1.07);
    box-shadow: 0 10px 30px hsla(42, 93%, 54%, 0.5), inset 0 1px 0 hsla(50, 100%, 85%, 0.6);
}

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

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

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

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

.sc-hint-touch {
    display: none;
}

@media (pointer: coarse) {

    .sc-hint-desktop,
    .sc-hint kbd {
        display: none;
    }

    .sc-hint-touch {
        display: block;
    }
}

/* === Game over results === */
.sc-record-badge {
    padding: 6px 14px;
    border-radius: 999px;
    font-family: var(--sc-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: sc-pulse 1.1s ease-in-out infinite alternate;
}

@keyframes sc-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);
    }
}

.sc-results {
    display: flex;
    gap: 10px;
    width: 100%;
}

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

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

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

.sc-result-box:last-child .sc-result-value {
    color: var(--sc-gold);
}

/* === Touch controls === */
.sc-touch-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 110;
    display: none;
    justify-content: space-between;
    padding: 0 14px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}

body.sc-playing .sc-touch-controls {
    opacity: 1;
}

.sc-stage.touch-detected .sc-touch-controls,
.sc-stage.always-touch .sc-touch-controls {
    display: flex;
}

@media (pointer: coarse) {
    .sc-touch-controls {
        display: flex;
    }
}

.sc-touch-btn {
    width: 74px;
    height: 74px;
    border-radius: 50%;
    border: 1px solid hsla(190, 80%, 65%, 0.35);
    background: hsla(248, 45%, 14%, 0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    cursor: pointer;
    pointer-events: auto;
    touch-action: none;
    display: grid;
    place-items: center;
    transition: transform 0.08s, background 0.08s, border-color 0.08s;
    -webkit-tap-highlight-color: transparent;
}

.sc-touch-btn.pressed {
    transform: scale(0.92);
    background: hsla(190, 82%, 40%, 0.45);
    border-color: var(--sc-cyan);
}

.sc-arrow-left,
.sc-arrow-right {
    width: 22px;
    height: 22px;
    background: var(--sc-text);
    opacity: 0.9;
}

.sc-arrow-left {
    clip-path: polygon(100% 0, 100% 100%, 0 50%);
}

.sc-arrow-right {
    clip-path: polygon(0 0, 0 100%, 100% 50%);
}

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

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

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