@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

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

:root {
    --bg-dark: #0a0a1a;
    --bg-panel: rgba(10, 10, 30, 0.95);
    --neon-cyan: #00ffff;
    --neon-pink: #ff2d95;
    --neon-purple: #b829ff;
    --neon-yellow: #ffe600;
    --neon-green: #39ff14;
    --neon-orange: #ff6a00;
    --neon-blue: #2979ff;
    --text-primary: #e0e0ff;
    --text-secondary: #8888bb;
    --border-glow: rgba(0, 255, 255, 0.3);
    --btn-bg: rgba(20, 20, 60, 0.9);
    --btn-hover: rgba(0, 255, 255, 0.15);
    --btn-border: var(--neon-cyan);
    --font-pixel: 'Press Start 2P', monospace;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-dark);
    font-family: var(--font-pixel);
    color: var(--text-primary);
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-dark);
}

#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* ── HUD ── */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(8px, 2vw, 20px) clamp(12px, 3vw, 30px);
    pointer-events: none;
    z-index: 10;
    background: linear-gradient(to bottom, rgba(0,0,0,0.5) 0%, transparent 100%);
}

.hud-label {
    font-size: clamp(6px, 1.2vw, 10px);
    color: var(--text-secondary);
    display: block;
    letter-spacing: 1px;
}

.hud-value {
    font-size: clamp(12px, 2.5vw, 22px);
    color: var(--neon-cyan);
    text-shadow: 0 0 8px rgba(0, 255, 255, 0.5);
    display: block;
}

#hud-coins {
    display: flex;
    align-items: center;
    gap: 6px;
}

.coin-icon {
    display: inline-block;
    width: clamp(12px, 2vw, 18px);
    height: clamp(12px, 2vw, 18px);
    background: var(--neon-yellow);
    border-radius: 50%;
    box-shadow: 0 0 6px rgba(255, 230, 0, 0.6);
}

#hud-coins-value {
    color: var(--neon-yellow);
    text-shadow: 0 0 8px rgba(255, 230, 0, 0.5);
}

#hud-best .hud-value {
    color: var(--neon-pink);
    text-shadow: 0 0 8px rgba(255, 45, 149, 0.5);
}

#hud-powerup {
    position: absolute;
    top: clamp(40px, 8vh, 60px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 10;
    pointer-events: none;
}

#hud-powerup.hidden {
    display: none;
}

#powerup-bar {
    width: 100px;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
}

#powerup-fill {
    height: 100%;
    width: 100%;
    background: var(--neon-green);
    border-radius: 4px;
    transition: width 0.1s linear;
    box-shadow: 0 0 6px var(--neon-green);
}

#powerup-name {
    font-size: 8px;
    color: var(--neon-green);
    text-shadow: 0 0 4px var(--neon-green);
}

/* ── Screens ── */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    background: rgba(5, 5, 20, 0.92);
    backdrop-filter: blur(4px);
}

.screen.hidden {
    display: none;
}

.screen-content {
    text-align: center;
    padding: clamp(20px, 4vw, 50px);
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    scrollbar-width: none;
}

.screen-content::-webkit-scrollbar {
    display: none;
}

/* ── Title ── */
.game-title {
    font-size: clamp(28px, 7vw, 72px);
    line-height: 1.1;
    margin-bottom: 8px;
}

.title-pixel {
    display: block;
    color: var(--neon-cyan);
    text-shadow:
        0 0 10px rgba(0, 255, 255, 0.8),
        0 0 30px rgba(0, 255, 255, 0.4),
        0 0 60px rgba(0, 255, 255, 0.2);
    letter-spacing: 0.15em;
}

.title-dash {
    display: block;
    color: var(--neon-pink);
    text-shadow:
        0 0 10px rgba(255, 45, 149, 0.8),
        0 0 30px rgba(255, 45, 149, 0.4),
        0 0 60px rgba(255, 45, 149, 0.2);
    letter-spacing: 0.15em;
}

.title-underline {
    width: 60%;
    height: 2px;
    margin: 12px auto;
    background: linear-gradient(90deg, transparent, var(--neon-purple), var(--neon-cyan), var(--neon-purple), transparent);
    box-shadow: 0 0 8px var(--neon-purple);
}

.subtitle {
    font-size: clamp(8px, 1.5vw, 14px);
    color: var(--text-secondary);
    letter-spacing: 0.3em;
    margin-bottom: clamp(24px, 4vw, 50px);
}

/* ── Buttons ── */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: clamp(10px, 2vw, 16px);
    align-items: center;
    margin-bottom: clamp(20px, 3vw, 40px);
}

.btn {
    font-family: var(--font-pixel);
    font-size: clamp(10px, 1.6vw, 14px);
    padding: clamp(12px, 2vw, 18px) clamp(24px, 4vw, 48px);
    border: 2px solid var(--btn-border);
    background: var(--btn-bg);
    color: var(--text-primary);
    cursor: pointer;
    letter-spacing: 0.1em;
    transition: all 0.15s ease;
    min-width: clamp(180px, 40vw, 280px);
    position: relative;
    outline: none;
}

.btn:focus-visible {
    outline: 2px solid var(--neon-yellow);
    outline-offset: 2px;
}

.btn-primary {
    border-color: var(--neon-cyan);
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.3), inset 0 0 10px rgba(0, 255, 255, 0.05);
}

.btn-primary:hover, .btn-primary:focus {
    background: var(--btn-hover);
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.5), inset 0 0 15px rgba(0, 255, 255, 0.1);
    transform: scale(1.02);
}

.btn-primary:active {
    transform: scale(0.97);
    background: rgba(0, 255, 255, 0.25);
}

.btn-secondary {
    border-color: var(--neon-purple);
    box-shadow: 0 0 8px rgba(184, 41, 255, 0.2);
}

.btn-secondary:hover, .btn-secondary:focus {
    background: rgba(184, 41, 255, 0.1);
    box-shadow: 0 0 16px rgba(184, 41, 255, 0.4);
    transform: scale(1.02);
}

.btn-secondary:active {
    transform: scale(0.97);
    background: rgba(184, 41, 255, 0.2);
}

/* ── High Score on menu ── */
.menu-highscore, #menu-highscore {
    margin-top: 10px;
}

.hs-label {
    display: block;
    font-size: clamp(7px, 1.2vw, 10px);
    color: var(--text-secondary);
    letter-spacing: 0.2em;
    margin-bottom: 4px;
}

.hs-value {
    font-size: clamp(16px, 3vw, 28px);
    color: var(--neon-yellow);
    text-shadow: 0 0 10px rgba(255, 230, 0, 0.5);
}

/* ── How to Play ── */
.howto-content {
    text-align: left;
}

.screen-title {
    font-size: clamp(16px, 3.5vw, 28px);
    color: var(--neon-cyan);
    text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
    text-align: center;
    margin-bottom: clamp(16px, 3vw, 30px);
}

.howto-sections {
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 2vw, 20px);
    margin-bottom: clamp(16px, 3vw, 30px);
}

.howto-section h3 {
    font-size: clamp(8px, 1.4vw, 12px);
    color: var(--neon-pink);
    text-shadow: 0 0 6px rgba(255, 45, 149, 0.4);
    margin-bottom: 6px;
}

.howto-section p {
    font-size: clamp(7px, 1.2vw, 10px);
    color: var(--text-secondary);
    line-height: 1.8;
}

.howto-content .btn {
    display: block;
    margin: 0 auto;
}

/* ── Settings ── */
.settings-list {
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 2vw, 20px);
    margin-bottom: clamp(20px, 3vw, 40px);
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: clamp(8px, 1.5vw, 14px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.02);
}

.setting-label {
    font-size: clamp(8px, 1.3vw, 11px);
    color: var(--text-secondary);
}

.btn-toggle {
    font-family: var(--font-pixel);
    font-size: clamp(8px, 1.2vw, 10px);
    padding: clamp(6px, 1vw, 10px) clamp(14px, 2vw, 24px);
    border: 2px solid var(--neon-purple);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    min-width: 60px;
    transition: all 0.15s ease;
    outline: none;
}

.btn-toggle:focus-visible {
    outline: 2px solid var(--neon-yellow);
    outline-offset: 2px;
}

.btn-toggle.active {
    background: rgba(57, 255, 20, 0.15);
    border-color: var(--neon-green);
    color: var(--neon-green);
    box-shadow: 0 0 8px rgba(57, 255, 20, 0.3);
}

.btn-toggle:active {
    transform: scale(0.95);
}

/* ── Game Over ── */
.gameover-title {
    color: var(--neon-pink) !important;
    text-shadow: 0 0 15px rgba(255, 45, 149, 0.7) !important;
}

.new-highscore {
    font-size: clamp(10px, 2vw, 16px);
    color: var(--neon-yellow);
    text-shadow: 0 0 12px rgba(255, 230, 0, 0.8);
    margin-bottom: 16px;
    animation: hsPulse 0.8s ease-in-out infinite alternate;
}

.new-highscore.hidden {
    display: none;
}

@keyframes hsPulse {
    from { opacity: 0.7; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1.05); }
}

.gameover-stats {
    margin-bottom: clamp(20px, 3vw, 36px);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(6px, 1vw, 12px) clamp(12px, 2vw, 24px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    min-width: clamp(200px, 50vw, 320px);
    margin: 0 auto;
}

.stat-label {
    font-size: clamp(8px, 1.3vw, 11px);
    color: var(--text-secondary);
}

.stat-value {
    font-size: clamp(14px, 2.5vw, 22px);
    color: var(--neon-cyan);
    text-shadow: 0 0 6px rgba(0, 255, 255, 0.4);
}

.stat-row:last-child .stat-value {
    color: var(--neon-yellow);
    text-shadow: 0 0 6px rgba(255, 230, 0, 0.4);
}

/* ── Countdown ── */
.countdown-text {
    font-size: clamp(60px, 15vw, 120px);
    color: var(--neon-cyan);
    text-shadow:
        0 0 20px rgba(0, 255, 255, 0.8),
        0 0 40px rgba(0, 255, 255, 0.4);
    animation: countPulse 0.5s ease-out;
}

@keyframes countPulse {
    from { transform: scale(1.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ── Pause Button (HUD) ── */
.btn-pause-hud {
    position: absolute;
    top: clamp(8px, 2vw, 20px);
    right: clamp(12px, 3vw, 30px);
    z-index: 15;
    width: clamp(36px, 5vw, 48px);
    height: clamp(36px, 5vw, 48px);
    background: rgba(10, 10, 30, 0.7);
    border: 2px solid var(--neon-purple);
    color: var(--text-primary);
    font-size: clamp(14px, 2vw, 20px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    outline: none;
}

.btn-pause-hud:focus-visible {
    outline: 2px solid var(--neon-yellow);
    outline-offset: 2px;
}

.btn-pause-hud.hidden {
    display: none;
}

.btn-pause-hud:hover {
    background: rgba(184, 41, 255, 0.2);
    box-shadow: 0 0 10px rgba(184, 41, 255, 0.4);
}

.btn-pause-hud:active {
    transform: scale(0.9);
}

/* ── Touch Jump ── */
.touch-jump {
    position: absolute;
    bottom: clamp(30px, 6vh, 60px);
    right: clamp(20px, 5vw, 50px);
    z-index: 15;
    width: clamp(80px, 20vw, 120px);
    height: clamp(80px, 20vw, 120px);
    background: rgba(0, 255, 255, 0.08);
    border: 3px solid var(--neon-cyan);
    border-radius: 16px;
    color: var(--neon-cyan);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    touch-action: manipulation;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.1s ease;
}

.touch-jump:focus-visible {
    outline: 2px solid var(--neon-yellow);
    outline-offset: 2px;
}

.touch-jump.hidden {
    display: none;
}

.jump-arrow {
    font-size: clamp(22px, 5vw, 34px);
    line-height: 1;
    text-shadow: 0 0 8px rgba(0, 255, 255, 0.6);
}

.jump-label {
    font-family: var(--font-pixel);
    font-size: clamp(7px, 1.2vw, 9px);
    letter-spacing: 0.1em;
}

.touch-jump.pressed {
    background: rgba(0, 255, 255, 0.25);
    transform: scale(0.92);
    box-shadow: 0 0 25px rgba(0, 255, 255, 0.5), inset 0 0 15px rgba(0, 255, 255, 0.2);
}

/* ── Orientation Message ── */
.orientation-msg {
    position: absolute;
    inset: 0;
    z-index: 50;
    background: rgba(5, 5, 20, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 20px;
}

.orientation-msg.hidden {
    display: none;
}

.orientation-msg p {
    font-size: clamp(8px, 1.5vw, 12px);
    color: var(--text-secondary);
    text-align: center;
}

/* ── Inline Icons ── */
.inline-coin {
    display: inline-block;
    width: 10px;
    height: 10px;
    background: var(--neon-yellow);
    border-radius: 50%;
    vertical-align: middle;
    box-shadow: 0 0 4px var(--neon-yellow);
}

.inline-star {
    display: inline-block;
    width: 10px;
    height: 10px;
    background: var(--neon-green);
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
    vertical-align: middle;
    box-shadow: 0 0 4px var(--neon-green);
}

/* ── Screen Shake ── */
.shake {
    animation: screenShake 0.2s ease-out;
}

@keyframes screenShake {
    0% { transform: translate(0, 0); }
    20% { transform: translate(-3px, 2px); }
    40% { transform: translate(3px, -2px); }
    60% { transform: translate(-2px, 1px); }
    80% { transform: translate(2px, -1px); }
    100% { transform: translate(0, 0); }
}

/* ── Responsive Adjustments ── */
@media (max-width: 480px) {
    #hud {
        padding: 6px 8px;
    }

    .menu-buttons {
        gap: 8px;
    }

    .btn {
        min-width: 160px;
    }

    .setting-row {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    .touch-jump {
        bottom: 20px;
        right: 16px;
        width: 80px;
        height: 80px;
        border-radius: 12px;
    }

    .btn-pause-hud {
        top: 6px;
        right: 8px;
    }

    #hud-powerup {
        top: clamp(36px, 7vh, 50px);
    }
}

@media (min-width: 481px) and (max-width: 1024px) {
    .touch-jump {
        width: 100px;
        height: 100px;
    }
}

@media (min-height: 500px) and (max-width: 768px) {
    .howto-sections {
        gap: 10px;
    }
}

/* ── Safe area padding for notched phones ── */
@supports (padding-top: env(safe-area-inset-top)) {
    #hud {
        padding-top: calc(clamp(8px, 2vw, 20px) + env(safe-area-inset-top));
        padding-left: calc(clamp(12px, 3vw, 30px) + env(safe-area-inset-left));
        padding-right: calc(clamp(12px, 3vw, 30px) + env(safe-area-inset-right));
    }

    .touch-jump {
        bottom: calc(clamp(30px, 6vh, 60px) + env(safe-area-inset-bottom));
        right: calc(clamp(20px, 5vw, 50px) + env(safe-area-inset-right));
    }

    .btn-pause-hud {
        top: calc(clamp(8px, 2vw, 20px) + env(safe-area-inset-top));
        right: calc(clamp(12px, 3vw, 30px) + env(safe-area-inset-right));
    }
}
