/* CSS Reset & Global Styling */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background-color: #0d0f18;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #ffffff;
}

/* Main Container */
#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    touch-action: none;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* General Overlay System */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    visibility: hidden;
    z-index: 200;
}

.overlay.active {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}

#hud {
    z-index: 100;
    flex-direction: column;
    justify-content: space-between;
    align-items: stretch;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px)) 16px;
    pointer-events: none;
}

#loading-screen {
    z-index: 300;
}

/* Glassmorphism UI Panels */
.glass-panel {
    background: rgba(18, 22, 38, 0.82);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 20px;
    padding: 24px 28px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), inset 0 1px 1px rgba(255, 255, 255, 0.2);
    text-align: center;
    max-width: 92%;
    width: 420px;
    max-height: 90dvh;
    overflow-y: auto;
}

/* Titles and Headers */
.badge {
    display: inline-block;
    padding: 4px 12px;
    background: linear-gradient(90deg, #ff9900, #ff5500);
    color: #fff;
    font-weight: 800;
    font-size: 0.75rem;
    letter-spacing: 2px;
    border-radius: 20px;
    margin-bottom: 12px;
    text-transform: uppercase;
}

.game-title {
    font-size: 2.3rem;
    font-weight: 900;
    line-height: 1.1;
    background: linear-gradient(180deg, #ffffff 30%, #ffcc00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 20px rgba(255, 204, 0, 0.3);
    margin-bottom: 8px;
    letter-spacing: 1px;
}

.danger-title {
    color: #ff3366;
    font-size: 2.2rem;
    font-weight: 900;
    letter-spacing: 1px;
    margin-bottom: 4px;
    text-shadow: 0 0 15px rgba(255, 51, 102, 0.4);
}

.tagline, .subtitle {
    font-size: 0.95rem;
    color: #a0aabf;
    margin-bottom: 20px;
}

/* Loader */
.loader {
    width: 48px;
    height: 48px;
    border: 5px solid rgba(255, 204, 0, 0.2);
    border-bottom-color: #ffcc00;
    border-radius: 50%;
    margin: 20px auto;
    animation: rotation 1s linear infinite;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: 1px;
    cursor: pointer;
    border: none;
    outline: none;
    transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
    text-transform: uppercase;
    touch-action: manipulation;
}

.primary-btn {
    background: linear-gradient(135deg, #ffaa00, #ff4400);
    color: #ffffff;
    box-shadow: 0 8px 20px rgba(255, 85, 0, 0.4);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 25px rgba(255, 85, 0, 0.6);
}

.primary-btn:active {
    transform: translateY(1px);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}

.glowing {
    animation: pulseGlow 2s infinite;
}

@keyframes pulseGlow {
    0% { box-shadow: 0 0 15px rgba(255, 170, 0, 0.4); }
    50% { box-shadow: 0 0 30px rgba(255, 170, 0, 0.8); }
    100% { box-shadow: 0 0 15px rgba(255, 170, 0, 0.4); }
}

.icon-btn {
    width: 46px;
    height: 46px;
    padding: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    font-size: 1.2rem;
    color: #fff;
}

.icon-btn.muted {
    opacity: 0.5;
    background: rgba(0, 0, 0, 0.3);
}

.menu-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 20px;
    gap: 12px;
}

.audio-toggles {
    display: flex;
    gap: 8px;
}

.controls-hint {
    font-size: 0.75rem;
    color: #8a94a6;
    text-align: right;
}

/* Instructions */
.instructions-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
    text-align: left;
}

.instruction-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.06);
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.85rem;
    color: #d1d5db;
}

.inst-icon {
    font-size: 1.4rem;
}

/* HUD Top Bar */
.hud-top {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.hud-stats {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.hud-card {
    background: rgba(18, 22, 38, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 6px 12px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    min-width: 75px;
}

.hud-label {
    font-size: 0.6rem;
    color: #ffaa00;
    font-weight: 800;
    letter-spacing: 1px;
}

.hud-value {
    font-size: 1rem;
    font-weight: 900;
    color: #fff;
}

.hud-actions {
    display: flex;
    gap: 8px;
    pointer-events: auto;
}

.hud-btn {
    pointer-events: auto;
}

/* Mobile On-Screen Touch Controls */
#mobile-controls {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: auto;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
    pointer-events: none;
    z-index: 150;
}

.touch-side {
    display: flex;
    gap: 12px;
    align-items: center;
}

.touch-btn {
    min-width: 68px;
    min-height: 68px;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: rgba(18, 22, 38, 0.65);
    border: 2px solid rgba(255, 255, 255, 0.35);
    color: #ffffff;
    font-size: 1.5rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), inset 0 1px 1px rgba(255, 255, 255, 0.3);
    outline: none;
    cursor: pointer;
    pointer-events: auto;
    touch-action: none;
    transition: transform 0.08s ease, background-color 0.08s ease, border-color 0.08s ease;
    -webkit-tap-highlight-color: transparent;
}

.touch-btn:active, .touch-btn.active {
    background: rgba(255, 170, 0, 0.75);
    border-color: #ffffff;
    transform: scale(0.92);
    box-shadow: 0 4px 12px rgba(255, 170, 0, 0.6);
}

.jump-btn {
    width: auto;
    min-width: 110px;
    height: 68px;
    padding: 0 20px;
    border-radius: 34px;
    font-size: 1rem;
    font-weight: 900;
    letter-spacing: 1px;
    background: linear-gradient(135deg, rgba(255, 150, 0, 0.85), rgba(255, 50, 0, 0.85));
    border: 2px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 8px 25px rgba(255, 85, 0, 0.5);
}

.jump-btn:active, .jump-btn.active {
    background: linear-gradient(135deg, rgba(255, 200, 0, 0.95), rgba(255, 80, 0, 0.95));
    transform: scale(0.92);
}

/* Stats in Game Over */
.stats-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.stat-box {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 10px 4px;
    display: flex;
    flex-direction: column;
}

.stat-box.highlight {
    background: rgba(255, 204, 0, 0.15);
    border: 1px solid rgba(255, 204, 0, 0.4);
}

.stat-label {
    font-size: 0.6rem;
    color: #8a94a6;
    font-weight: 700;
}

.stat-value {
    font-size: 1rem;
    font-weight: 900;
    color: #ffffff;
    margin-top: 4px;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    .glass-panel {
        padding: 20px;
        width: 95%;
    }
    .game-title {
        font-size: 1.8rem;
    }
    .controls-hint {
        display: none;
    }
    .hud-card {
        min-width: 65px;
        padding: 4px 8px;
    }
    .hud-label {
        font-size: 0.55rem;
    }
    .hud-value {
        font-size: 0.9rem;
    }
    .icon-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    .touch-btn {
        min-width: 62px;
        min-height: 62px;
        width: 62px;
        height: 62px;
        font-size: 1.3rem;
    }
    .jump-btn {
        min-width: 98px;
        height: 62px;
        padding: 0 14px;
        font-size: 0.9rem;
    }
}
