html, body {
    margin: 0;
    height: 100%;
    width: 100%;
    background: #0e0e12;
    color: #e8e6f0;
    font-family: 'Press Start 2P', system-ui, sans-serif;
    overflow: hidden;
    overflow-x: hidden;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

body {
    display: flex;
    flex-direction: column;
    max-width: 100vw;
}

/* Loading screen */
.loading-screen {
    position: fixed;
    inset: 0;
    background: #0e0e12;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.5s ease-out;
    overflow: hidden;
    max-width: 100vw;
}

.loading-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
    padding: 40px;
    max-width: calc(100vw - 40px);
    box-sizing: border-box;
}

.loading-content h1 {
    color: #ffd54f;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.9);
    margin-bottom: 20px;
    font-size: 32px;
}

.ai-attribution {
    font-size: 13px;
    color: #ffd54f;
    text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.9);
    margin: 10px 0 30px 0;
    text-decoration: underline;
    text-decoration-color: #ffd54f;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
    animation: fadeInGlow 2s ease-in-out infinite alternate;
    font-weight: bold;
    line-height: 1.8;
}

@keyframes fadeInGlow {
    0% { 
        opacity: 0.85; 
        text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.9);
    }
    100% { 
        opacity: 1; 
        text-shadow: 2px 2px 12px rgba(255, 213, 79, 0.8), 0 0 20px rgba(255, 213, 79, 0.4);
    }
}

.loading-spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto 30px;
    border: 6px solid #2a2d37;
    border-top: 6px solid #ffd54f;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    transition: opacity 0.3s ease-out;
}

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

.loading-text {
    font-size: 12px;
    color: #e8e6f0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    margin: 20px 0;
    transition: opacity 0.3s ease-out;
}

.loading-bar-container {
    width: 300px;
    max-width: calc(100vw - 80px);
    height: 40px;
    background: #2a2d37;
    border: 3px solid #4a3f2f;
    border-radius: 10px;
    margin: 20px auto;
    overflow: hidden;
    position: relative;
    cursor: default;
    transition: all 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-sizing: border-box;
}

.loading-bar-container.ready {
    background: linear-gradient(135deg, #4caf50, #45a049);
    border-color: #66bb6a;
    cursor: pointer;
    height: 50px;
    box-shadow: 0 4px 20px rgba(76, 175, 80, 0.4);
    animation: buttonPulse 2s ease-in-out infinite;
}

@keyframes buttonPulse {
    0%, 100% { 
        box-shadow: 0 4px 20px rgba(76, 175, 80, 0.4);
    }
    50% { 
        box-shadow: 0 4px 30px rgba(76, 175, 80, 0.7);
    }
}

.loading-bar-container.ready:hover {
    background: linear-gradient(135deg, #66bb6a, #4caf50);
    transform: scale(1.05);
    box-shadow: 0 6px 25px rgba(76, 175, 80, 0.6);
}

.loading-bar-container.ready:active {
    transform: scale(0.98);
}

.loading-bar {
    height: 100%;
    background: linear-gradient(90deg, #ffd54f, #ffb300);
    width: 0%;
    transition: width 0.3s ease-out, opacity 0.5s ease-out;
    box-shadow: 0 0 10px rgba(255, 213, 79, 0.5);
}

.loading-bar-container.ready .loading-bar {
    opacity: 0;
}

.loading-bar-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease-in 0.3s;
    font-weight: bold;
}

.loading-bar-container.ready .loading-bar-text {
    opacity: 1;
}

.loading-percentage {
    font-size: 14px;
    color: #ffd54f;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    transition: opacity 0.3s ease-out;
}

#game {
    display: block;
    flex: 1;
    width: 100%;
    max-width: 100vw;
    background: #14161d;
    image-rendering: pixelated;
}

#ui {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    max-width: 100vw;
}

#hud {
    width: 100%;
    max-width: 100vw;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: linear-gradient(135deg, #5d4e37 0%, #4a3f2f 50%, #3d3426 100%);
    padding: 12px 20px;
    border-bottom: 4px solid #2a2112;
    font-size: 11px;
    box-shadow: 
        inset 0 2px 4px rgba(255, 255, 255, 0.15),
        inset 0 -2px 4px rgba(0, 0, 0, 0.3),
        0 4px 8px rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
    box-sizing: border-box;
}

#hud.hidden {
    display: none;
}

#hud span {
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.hud-left, .hud-right {
    flex: 0 0 120px;
}

.hud-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.hud-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.hud-menu-btn {
    font-family: inherit;
    background: linear-gradient(135deg, #6b5742 0%, #564635 50%, #453828 100%);
    color: #ffd54f;
    border: 3px solid #2a2112;
    border-radius: 6px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 10px;
    box-shadow: 
        inset 0 1px 3px rgba(255, 255, 255, 0.2),
        inset 0 -2px 3px rgba(0, 0, 0, 0.3),
        0 3px 6px rgba(0, 0, 0, 0.4);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    transition: all 0.1s;
    pointer-events: auto;
}

.hud-menu-btn:hover {
    filter: brightness(1.15);
    transform: translateY(-1px);
    box-shadow: 
        inset 0 1px 3px rgba(255, 255, 255, 0.25),
        inset 0 -2px 3px rgba(0, 0, 0, 0.3),
        0 4px 8px rgba(0, 0, 0, 0.5);
}

.hud-menu-btn:active {
    transform: translateY(1px);
    box-shadow: 
        inset 0 1px 3px rgba(0, 0, 0, 0.4),
        inset 0 -1px 2px rgba(255, 255, 255, 0.1),
        0 2px 4px rgba(0, 0, 0, 0.3);
}

.hud-health {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-lives {
    margin-left: 12px;
}

.health-label {
    color: #ffd54f;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    font-size: 11px;
    min-width: 30px;
}

.health-bar-container {
    width: 150px;
    height: 16px;
    background: #2a2112;
    border: 2px solid #4a3f2f;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.health-bar {
    height: 100%;
    background: linear-gradient(90deg, #66bb6a 0%, #81c784 50%, #66bb6a 100%);
    width: 100%;
    transition: width 0.3s ease-out;
    box-shadow: 
        inset 0 2px 4px rgba(255, 255, 255, 0.3),
        0 0 6px rgba(102, 187, 106, 0.5);
}

.health-bar.low {
    background: linear-gradient(90deg, #ef5350 0%, #e57373 50%, #ef5350 100%);
    box-shadow: 
        inset 0 2px 4px rgba(255, 255, 255, 0.3),
        0 0 6px rgba(239, 83, 80, 0.5);
}

.health-text {
    color: #e8e6f0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    font-size: 10px;
    min-width: 60px;
}

.center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, #5d4e37 0%, #4a3f2f 50%, #3d3426 100%);
    padding: 40px 50px;
    border: 6px solid #2a2112;
    border-radius: 12px;
    box-shadow: 
        inset 0 2px 6px rgba(255, 255, 255, 0.2),
        inset 0 -3px 6px rgba(0, 0, 0, 0.4),
        0 6px 16px rgba(0, 0, 0, 0.7),
        0 0 0 2px #4a3f2f;
    text-align: center;
    pointer-events: auto;
    z-index: 100;
    box-sizing: border-box;
}

#nameInputModal {
    z-index: 10001;
    min-width: 500px;
    overflow: hidden;
}

.center h1, .center h2 {
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.9);
    color: #ffd54f;
    margin: 0 0 20px 0;
    font-size: 24px;
}

.center h1 {
    font-size: 28px;
}

.center h3 {
    font-size: 12px;
    color: #ffd54f;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    margin: 0 0 12px 0;
}

.center p {
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    margin: 14px 0;
    font-size: 11px;
}

#mainMenu {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 360px;
}

#mainMenu button {
    width: 100%;
    font-size: 14px;
}

#levelButtons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin: 16px 0;
    max-width: 500px;
}

#levelButtons button {
    padding: 16px 12px;
    font-size: 11px;
    margin: 0;
    min-width: 95px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#levelButtons button:disabled {
    cursor: not-allowed;
    filter: grayscale(0.7) brightness(0.6);
}

#levelButtons button:disabled:hover {
    transform: none;
    filter: grayscale(0.7) brightness(0.6);
}

label {
    color: #ffd54f;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    cursor: pointer;
}

input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
}

input[type="text"]:focus {
    outline: none;
    border-color: #ffd54f;
    box-shadow: 
        inset 0 2px 4px rgba(0, 0, 0, 0.5),
        0 0 8px rgba(255, 213, 79, 0.4);
}

input[type="text"]::placeholder {
    color: #6b5742;
    opacity: 0.8;
}

button {
    font-family: inherit;
    background: linear-gradient(135deg, #6b5742 0%, #564635 50%, #453828 100%);
    color: #ffd54f;
    border: 3px solid #2a2112;
    border-radius: 6px;
    padding: 14px 24px;
    margin: 8px;
    cursor: pointer;
    font-size: 12px;
    box-shadow: 
        inset 0 1px 3px rgba(255, 255, 255, 0.2),
        inset 0 -2px 3px rgba(0, 0, 0, 0.3),
        0 3px 6px rgba(0, 0, 0, 0.4);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    transition: all 0.1s;
}

button:hover { 
    filter: brightness(1.15);
    transform: translateY(-1px);
    box-shadow: 
        inset 0 1px 3px rgba(255, 255, 255, 0.25),
        inset 0 -2px 3px rgba(0, 0, 0, 0.3),
        0 4px 8px rgba(0, 0, 0, 0.5);
}

button:active {
    transform: translateY(1px);
    box-shadow: 
        inset 0 1px 3px rgba(0, 0, 0, 0.4),
        inset 0 -1px 2px rgba(255, 255, 255, 0.1),
        0 2px 4px rgba(0, 0, 0, 0.3);
}

.resurrect-btn {
    background: linear-gradient(135deg, #4caf50, #45a049) !important;
    border-color: #66bb6a !important;
    font-size: 14px;
    animation: pulsate 1.5s ease-in-out infinite;
}

.resurrect-btn:hover {
    background: linear-gradient(135deg, #66bb6a, #4caf50) !important;
    box-shadow: 
        inset 0 1px 3px rgba(255, 255, 255, 0.25),
        inset 0 -2px 3px rgba(0, 0, 0, 0.3),
        0 4px 15px rgba(76, 175, 80, 0.5);
}

@keyframes pulsate {
    0%, 100% { box-shadow: 0 0 10px rgba(76, 175, 80, 0.3); }
    50% { box-shadow: 0 0 20px rgba(76, 175, 80, 0.6); }
}

.hidden { display: none; }

/* Cutscene styles */
.cutscene-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.5s ease-in;
    overflow: hidden;
    max-width: 100vw;
}

.cutscene-content {
    width: 90%;
    max-width: min(700px, calc(100vw - 40px));
    position: relative;
    box-sizing: border-box;
}

.chat-bubble {
    background: linear-gradient(135deg, #2a2d37, #1a1d27);
    border: 3px solid #4a3f2f;
    border-radius: 15px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6);
    position: relative;
    animation: slideUp 0.4s ease-out;
    box-sizing: border-box;
}

.chat-bubble::before {
    content: '';
    position: absolute;
    bottom: -15px;
    left: 40px;
    width: 0;
    height: 0;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-top: 15px solid #2a2d37;
}

.chat-name {
    font-size: 14px;
    color: #ffd54f;
    margin-bottom: 12px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.chat-text {
    font-size: 12px;
    color: #e8e6f0;
    line-height: 1.6;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
}

.cutscene-continue {
    text-align: center;
    font-size: 10px;
    color: #ffd54f;
    animation: blink 1.5s ease-in-out infinite;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { 
        opacity: 0;
        transform: translateY(30px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from { 
        opacity: 1;
        transform: translateY(0);
    }
    to { 
        opacity: 0;
        transform: translateY(30px);
        visibility: hidden;
    }
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

#upgradePanel {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
    min-width: 480px;
}

#upgradePanel button { 
    width: 100%;
    font-size: 13px;
    padding: 16px 28px;
}

#pause button, #gameover button {
    display: block;
    width: 280px;
    margin: 10px auto;
    font-size: 13px;
}

/* Ensure upgrade panel actually hides when .hidden is applied (override ID specificity) */
#upgradePanel.hidden { display: none; }

/* Countdown overlay */
#countdown {
    font-size: 64px;
    background: linear-gradient(135deg, #5d4e37 0%, #4a3f2f 50%, #3d3426 100%);
    border: 6px solid #2a2112;
    box-shadow: 
        inset 0 2px 6px rgba(255, 255, 255, 0.2),
        inset 0 -3px 6px rgba(0, 0, 0, 0.4),
        0 6px 16px rgba(0, 0, 0, 0.7),
        0 0 0 2px #4a3f2f;
    pointer-events: none;
    min-width: 200px;
    color: #ffd54f;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.9);
    padding: 20px 40px;
}

/* Achievement notification */
.achievement-popup {
    position: fixed;
    top: 80px;
    right: -400px;
    width: 320px;
    background: linear-gradient(135deg, #5d4e37 0%, #4a3f2f 50%, #3d3426 100%);
    border: 4px solid #ffd54f;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 
        inset 0 2px 6px rgba(255, 255, 255, 0.2),
        inset 0 -3px 6px rgba(0, 0, 0, 0.4),
        0 6px 16px rgba(0, 0, 0, 0.7);
    pointer-events: none;
    transition: right 0.5s ease-out;
    z-index: 1000;
}

.achievement-popup.show {
    right: 20px;
}

.achievement-title {
    font-size: 10px;
    color: #ffd54f;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    margin-bottom: 8px;
}

.achievement-name {
    font-size: 12px;
    color: #66bb6a;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    margin-bottom: 4px;
}

.achievement-desc {
    font-size: 8px;
    color: #e8e6f0;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

/* Boss flash effect - Lightning */
.boss-flash {
    position: fixed;
    inset: 0;
    background: 
        radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, 0.9) 0%, transparent 30%),
        radial-gradient(ellipse at 70% 60%, rgba(200, 220, 255, 0.8) 0%, transparent 25%),
        radial-gradient(ellipse at 50% 80%, rgba(255, 255, 255, 0.7) 0%, transparent 20%),
        linear-gradient(180deg, rgba(200, 220, 255, 0.3) 0%, rgba(100, 150, 255, 0.2) 100%);
    pointer-events: none;
    z-index: 999;
    animation: lightningFlash 1.2s ease-out;
}

@keyframes lightningFlash {
    0% { opacity: 0; filter: brightness(1); }
    5% { opacity: 1; filter: brightness(3); }
    10% { opacity: 0.3; filter: brightness(1.5); }
    15% { opacity: 1; filter: brightness(3.5); }
    25% { opacity: 0.5; filter: brightness(2); }
    30% { opacity: 1; filter: brightness(4); }
    35% { opacity: 0; filter: brightness(1); }
    45% { opacity: 0.8; filter: brightness(2.5); }
    50% { opacity: 0; filter: brightness(1); }
    100% { opacity: 0; filter: brightness(1); }
}

/* Mobile Controls */
#mobileControls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 200px;
    pointer-events: none;
    z-index: 500;
}

#joystickContainer {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 140px;
    height: 140px;
    pointer-events: auto;
}

#joystickBase {
    position: absolute;
    width: 140px;
    height: 140px;
    background: radial-gradient(circle, rgba(74, 63, 47, 0.6) 0%, rgba(42, 33, 18, 0.4) 100%);
    border: 4px solid rgba(255, 213, 79, 0.4);
    border-radius: 50%;
    box-shadow: 
        inset 0 2px 6px rgba(0, 0, 0, 0.5),
        0 4px 12px rgba(0, 0, 0, 0.5);
}

#joystickStick {
    position: absolute;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #6b5742 0%, #564635 50%, #453828 100%);
    border: 3px solid #ffd54f;
    border-radius: 50%;
    top: 40px;
    left: 40px;
    box-shadow: 
        inset 0 2px 4px rgba(255, 255, 255, 0.3),
        0 3px 8px rgba(0, 0, 0, 0.6);
    transition: all 0.1s;
}


/* Mobile responsiveness */
@media (max-width: 768px), (hover: none) {
    .center {
        padding: 20px 24px;
        max-width: calc(100vw - 40px);
        max-height: 80vh;
        overflow-y: auto;
        font-size: 10px;
        -webkit-overflow-scrolling: touch;
        box-sizing: border-box;
    }
    
    /* Allow scrolling in menus */
    .center, .center * {
        touch-action: auto;
    }
    
    .center h1 {
        font-size: 20px;
    }
    
    .center h2 {
        font-size: 16px;
    }
    
    .center h3 {
        font-size: 10px;
    }
    
    .center p {
        font-size: 9px;
    }
    
    #mainMenu {
        min-width: 280px;
    }
    
    #mainMenu button {
        font-size: 11px;
    }
    
    #nameInputModal {
        min-width: unset;
        width: calc(100vw - 40px);
    }
    
    button {
        font-size: 10px;
        padding: 10px 16px;
    }
    
    #hud {
        font-size: 9px;
        padding: 8px 10px;
        gap: 12px;
    }
    
    .hud-left, .hud-right {
        flex: 0 0 80px;
    }
    
    .hud-center {
        gap: 6px;
    }
    
    .hud-row {
        gap: 12px;
    }
    
    .hud-menu-btn {
        padding: 6px 12px;
        font-size: 9px;
    }
    
    .health-bar-container {
        width: 100px;
    }
    
    .hud-lives {
        margin-left: 8px;
    }
    
    #upgradePanel {
        min-width: unset;
        width: calc(100vw - 40px);
    }
    
    #achievementsMenu {
        min-width: unset !important;
        max-width: calc(100vw - 40px) !important;
        width: calc(100vw - 40px) !important;
    }
    
    #achievementsMenu > div {
        flex-direction: column !important;
    }
    
    #levelButtons {
        grid-template-columns: repeat(3, 1fr);
    }
    
    #levelButtons button {
        min-width: 70px;
        font-size: 9px;
    }
    
    .loading-content h1 {
        font-size: 24px;
    }
    
    .loading-text {
        font-size: 10px;
    }
    
    .loading-percentage {
        font-size: 12px;
    }
    
    #joystickContainer {
        bottom: 30px;
        right: 15px;
    }
    
    /* Adjust achievement notification for mobile */
    .achievement-popup {
        width: 280px;
        font-size: 9px;
    }
    
    .achievement-popup.show {
        right: 10px;
        top: 60px;
    }
}

@media (max-width: 480px) {
    #hud {
        font-size: 8px;
        padding: 6px 8px;
    }
    
    .hud-left, .hud-right {
        flex: 0 0 60px;
    }
    
    .hud-menu-btn {
        padding: 5px 10px;
        font-size: 8px;
    }
    
    .hud-row {
        gap: 8px;
    }
    
    .health-bar-container {
        width: 80px;
    }
    
    .hud-lives {
        margin-left: 6px;
    }
}

