@font-face {
    font-family: 'Flixel';
    src: url('fonts/Flixel.ttf');
}

.flixel-font { font-family: 'Flixel' }

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
    background: #050506;
    touch-action: none;
    -webkit-text-size-adjust: 100%;
}

#game-canvas {
    position: fixed;
    inset: 0;
    display: block;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    touch-action: none;
    user-select: none;
}

.mobile-controls {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 18px;
    z-index: 20;
    display: none;
    align-items: flex-end;
    justify-content: space-between;
    pointer-events: none;
}

@supports (bottom: max(0px)) {
    .mobile-controls {
        left: max(16px, env(safe-area-inset-left));
        right: max(16px, env(safe-area-inset-right));
        bottom: max(18px, calc(env(safe-area-inset-bottom) + 10px));
    }
}

.touch-control {
    width: clamp(68px, 18vw, 92px);
    height: clamp(68px, 18vw, 92px);
    border: 2px solid rgba(255, 255, 255, 0.72);
    border-radius: 50%;
    color: rgba(255, 255, 255, 0.92);
    background: rgba(8, 9, 12, 0.42);
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.24), 0 6px 18px rgba(0, 0, 0, 0.24);
    font: 13px 'Flixel', monospace;
    letter-spacing: 0;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

.touch-control.is-pressed,
.touch-control:active {
    background: rgba(255, 255, 255, 0.24);
    transform: translateY(2px);
}

body.has-touch-controls.game-running .mobile-controls {
    display: flex;
}

body.is-paused .mobile-controls,
body.game-over-active .mobile-controls {
    display: none;
}

@media (hover: none) and (pointer: coarse) {
    body.game-running .mobile-controls {
        display: flex;
    }

    body.is-paused .mobile-controls,
    body.game-over-active .mobile-controls {
        display: none;
    }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
    body.game-running .mobile-controls {
        left: 24px;
        right: 24px;
        bottom: 40px;
    }

    .touch-control {
        width: clamp(58px, 16vh, 82px);
        height: clamp(58px, 16vh, 82px);
        font-size: 12px;
    }
}

@supports (bottom: max(0px)) {
    @media (hover: none) and (pointer: coarse) and (orientation: landscape) {
        body.game-running .mobile-controls {
            left: max(24px, calc(env(safe-area-inset-left) + 12px));
            right: max(24px, calc(env(safe-area-inset-right) + 12px));
            bottom: max(40px, calc(env(safe-area-inset-bottom) + 28px));
        }
    }
}

@media (orientation: landscape) {
    body.has-touch-controls.game-running .mobile-controls {
        left: 24px;
        right: 24px;
        bottom: 40px;
    }
}

@supports (bottom: max(0px)) {
    @media (orientation: landscape) {
        body.has-touch-controls.game-running .mobile-controls {
            left: max(24px, calc(env(safe-area-inset-left) + 12px));
            right: max(24px, calc(env(safe-area-inset-right) + 12px));
            bottom: max(40px, calc(env(safe-area-inset-bottom) + 28px));
        }
    }
}

.game-menu {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: grid;
    place-items: center;
    overflow: hidden;
    color: #f4f4f4;
    font-family: 'Flixel', monospace;
    background:
        linear-gradient(180deg, rgba(4, 4, 6, 0.18), rgba(4, 4, 6, 0.9)),
        url('../data/images/raw/midground2.png') repeat-x center 68%,
        url('../data/images/raw/background.png') repeat-x center bottom,
        #15161a;
    background-size: auto 46%, auto 70%, auto;
    image-rendering: pixelated;
}

.game-menu.is-hidden {
    display: none;
}

.game-menu[hidden],
.menu-screen[hidden],
.game-over-actions[hidden] {
    display: none;
}

.menu-skyline {
    position: absolute;
    inset: auto 0 0;
    height: 32%;
    background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.62));
    pointer-events: none;
}

.menu-content {
    position: relative;
    z-index: 1;
    width: min(90vw, 720px);
    text-align: center;
    text-shadow: 0 4px 0 rgba(0, 0, 0, 0.55);
}

.menu-content-narrow {
    width: min(90vw, 440px);
}

.menu-kicker,
.menu-status,
.password-box label,
.menu-label,
.menu-error,
.password-error {
    margin: 0;
    font-size: clamp(10px, 1.6vw, 15px);
    letter-spacing: 0;
}

.menu-content h2 {
    margin: 0 0 24px;
    font-size: clamp(22px, 4vw, 38px);
    line-height: 1;
    letter-spacing: 0;
}

.menu-content h1 {
    margin: 16px 0 34px;
    font-size: clamp(38px, 8vw, 92px);
    line-height: 0.95;
    letter-spacing: 0;
}

.menu-stack {
    display: grid;
    gap: 18px;
    justify-items: center;
}

.menu-button {
    min-width: 178px;
    min-height: 48px;
    padding: 12px 22px;
    border: 2px solid #f3f3f3;
    border-radius: 6px;
    color: #111217;
    background: #f3f3f3;
    box-shadow: 0 6px 0 #8d2525;
    font: 16px 'Flixel', monospace;
    letter-spacing: 0;
    cursor: pointer;
}

.menu-button:hover,
.menu-button:focus-visible {
    background: #ffffff;
    transform: translateY(-1px);
}

.menu-button:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #8d2525;
}

.menu-button:disabled {
    cursor: wait;
    opacity: 0.72;
}

.menu-button-small {
    min-width: 126px;
    min-height: 40px;
    padding: 9px 15px;
    font-size: 12px;
}

.menu-button-ghost {
    color: #f3f3f3;
    background: transparent;
    box-shadow: 0 6px 0 #3a3a42;
}

.menu-status {
    min-height: 20px;
    margin-top: 22px;
}

.password-panel {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.58);
}

.password-panel[hidden] {
    display: none;
}

.password-box {
    width: min(88vw, 380px);
    padding: 28px;
    border: 2px solid rgba(255, 255, 255, 0.85);
    border-radius: 8px;
    background: rgba(15, 16, 20, 0.94);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.48);
}

.menu-box {
    box-sizing: border-box;
    width: 100%;
    padding: 28px;
    border: 2px solid rgba(255, 255, 255, 0.85);
    border-radius: 8px;
    background: rgba(15, 16, 20, 0.94);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.48);
}

.password-box label {
    display: block;
    margin-bottom: 12px;
}

.menu-label {
    display: block;
    margin-bottom: 12px;
    text-align: left;
}

.password-box input,
.menu-input {
    width: 100%;
    box-sizing: border-box;
    padding: 13px 12px;
    border: 2px solid #f3f3f3;
    border-radius: 6px;
    color: #f3f3f3;
    background: #050506;
    font: 16px 'Flixel', monospace;
    outline: none;
}

.password-box input:focus,
.menu-input:focus {
    border-color: #ffce5c;
}

.password-error,
.menu-error {
    min-height: 18px;
    margin-top: 12px;
    color: #ff6666;
}

.password-actions {
    display: flex;
    gap: 14px;
    justify-content: center;
    margin-top: 22px;
}

.leaderboard-list {
    display: grid;
    gap: 8px;
    min-height: 174px;
    margin: 0 0 24px;
    text-align: left;
}

.leaderboard-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 82px;
    gap: 10px;
    align-items: center;
    min-height: 28px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.16);
    color: #f4f4f4;
    font: 12px 'Flixel', monospace;
    letter-spacing: 0;
    text-shadow: none;
}

.leaderboard-row span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-row-score {
    text-align: right;
}

.leaderboard-message,
.score-save-status {
    min-height: 18px;
    margin: 0;
    color: #f4f4f4;
    font: 11px 'Flixel', monospace;
    letter-spacing: 0;
    text-align: center;
    text-shadow: 0 3px 0 rgba(0, 0, 0, 0.55);
}

.volume-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 52px;
    gap: 14px;
    align-items: center;
    margin-bottom: 26px;
}

.volume-control input {
    width: 100%;
    accent-color: #f3f3f3;
}

.volume-value {
    color: #f4f4f4;
    font: 13px 'Flixel', monospace;
    letter-spacing: 0;
    text-align: right;
}

.pause-button {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 22;
    display: none;
    min-width: 104px;
    min-height: 38px;
    padding: 9px 14px;
    border: 2px solid rgba(255, 255, 255, 0.82);
    border-radius: 6px;
    color: #f3f3f3;
    background: rgba(8, 9, 12, 0.54);
    box-shadow: 0 5px 0 rgba(141, 37, 37, 0.88);
    font: 12px 'Flixel', monospace;
    letter-spacing: 0;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.pause-button:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 rgba(141, 37, 37, 0.88);
}

body.game-running:not(.has-touch-controls):not(.is-paused):not(.game-over-active) .pause-button-desktop {
    display: block;
}

body.has-touch-controls.game-running:not(.is-paused):not(.game-over-active) .pause-button-mobile {
    display: block;
}

.pause-panel {
    z-index: 30;
}

.game-over-actions {
    position: fixed;
    left: 50%;
    bottom: 52px;
    z-index: 24;
    transform: translateX(-50%);
    display: grid;
    gap: 14px;
    justify-items: center;
    width: min(92vw, 420px);
    font-family: 'Flixel', monospace;
    pointer-events: none;
}

.game-over-action-row {
    display: flex;
    gap: 14px;
    justify-content: center;
    pointer-events: auto;
}

.score-save-status {
    min-height: 16px;
}

@supports (bottom: max(0px)) {
    .pause-button {
        top: max(16px, calc(env(safe-area-inset-top) + 10px));
        left: max(16px, calc(env(safe-area-inset-left) + 10px));
    }

    .game-over-actions {
        bottom: max(52px, calc(env(safe-area-inset-bottom) + 44px));
    }
}

@media (hover: none) and (pointer: coarse) {
    body.game-running:not(.is-paused):not(.game-over-active) .pause-button-desktop {
        display: none;
    }

    body.game-running:not(.is-paused):not(.game-over-active) .pause-button-mobile {
        display: block;
    }

    .pause-button-mobile {
        min-width: 78px;
        min-height: 38px;
        font-size: 11px;
    }
}

@media (max-width: 520px) {
    .password-actions {
        flex-direction: column;
    }

    .menu-button,
    .menu-button-small {
        width: 100%;
    }

    .game-over-action-row {
        width: 100%;
        flex-direction: column;
    }

    .leaderboard-row {
        grid-template-columns: 30px minmax(0, 1fr) 68px;
        font-size: 10px;
    }
}
