:root {
    --bg-color: #12141a;
    --game-bg: #1e222b;
    --text-primary: #f0f4f8;
    --text-accent: #3b82f6;
    --warning-color: #f59e0b;
    --critical-color: #ef4444;
    --modal-bg: rgba(18, 20, 26, 0.85);
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    padding: 10px;
}

.game-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    width: 100%;
    max-width: 500px;
    margin: auto;
    position: relative;
}

#game-container {
    position: relative;
    width: 100%;
    max-height: calc(100vh - 170px);
    aspect-ratio: 5 / 7;
    background-color: var(--game-bg);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 0 4px rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    overflow: hidden;
    touch-action: none;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    z-index: 10;
}

#score-display {
    display: flex;
    flex-direction: column;
}

#score-display .label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: rgba(255, 255, 255, 0.6);
    font-weight: 700;
}

#score-value {
    font-size: 2.5rem;
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

#avalanche-warning {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    width: 150px;
}

#avalanche-warning .label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 700;
    margin-bottom: 5px;
}

#warning-bar-container {
    width: 100%;
    height: 10px;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 5px;
    overflow: hidden;
}

#warning-bar {
    height: 100%;
    width: 0%;
    background-color: var(--warning-color);
    transition: width 0.3s ease, background-color 0.3s ease;
}

.critical #warning-bar {
    background-color: var(--critical-color);
    animation: pulse-critical 0.5s infinite alternate;
}

.critical .label {
    color: var(--critical-color);
    animation: text-pulse 0.5s infinite alternate;
}

@keyframes pulse-critical {
    from { opacity: 1; box-shadow: 0 0 5px var(--critical-color); }
    to { opacity: 0.5; box-shadow: 0 0 15px var(--critical-color); }
}

@keyframes text-pulse {
    from { opacity: 1; }
    to { opacity: 0.6; }
}

/* Modals */
#game-over-modal, #start-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-bg);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
    opacity: 1;
    transition: opacity 0.3s ease;
}

#game-over-modal.hidden, #start-modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: rgba(255, 255, 255, 0.05);
    padding: clamp(20px, 5vw, 40px);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    width: 90%;
    max-width: 420px;
    margin: 0 auto;
}

.modal-content h1 {
    font-size: clamp(1.6rem, 5.5vw, 2.5rem);
    font-weight: 900;
    margin-bottom: 10px;
    color: var(--text-primary);
    text-shadow: 0 2px 10px rgba(255,255,255,0.2);
    letter-spacing: 2px;
    line-height: 1.2;
}

.modal-content h2 {
    font-size: clamp(2rem, 7vw, 3rem);
    font-weight: 900;
    color: var(--critical-color);
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow: 0 0 15px rgba(239, 68, 68, 0.5);
}

.modal-content p {
    font-size: clamp(0.9rem, 3.5vw, 1.2rem);
    margin-bottom: 10px;
    color: rgba(255, 255, 255, 0.8);
}

.modal-content p span {
    font-weight: 700;
    color: var(--text-primary);
}

.instructions {
    font-size: clamp(0.8rem, 3vw, 1rem) !important;
    color: rgba(255, 255, 255, 0.6) !important;
}

.instructions.warning {
    color: var(--critical-color) !important;
    font-weight: 700;
    margin-top: 15px;
    margin-bottom: 25px;
}

button {
    margin-top: clamp(15px, 4vw, 25px);
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    border: none;
    padding: clamp(10px, 3vw, 15px) clamp(20px, 6vw, 30px);
    font-size: clamp(1rem, 3.5vw, 1.2rem);
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
    transition: transform 0.1s, box-shadow 0.2s, background 0.2s;
    letter-spacing: 1px;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.6);
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
}

button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.4);
}

/* Mobile Controls & Responsive layout styling */
#mobile-controls {
    display: none;
    justify-content: center;
    gap: 40px;
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    z-index: 20;
}

body.touch-device #mobile-controls {
    display: flex;
}

.ctrl-btn {
    width: 70px;
    height: 70px;
    background: rgba(30, 34, 43, 0.6);
    border: 2px solid rgba(59, 130, 246, 0.4);
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 1.8rem;
    font-weight: bold;
    cursor: pointer;
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s ease;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    outline: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.ctrl-btn:active {
    background: rgba(59, 130, 246, 0.3);
    border-color: var(--text-accent);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.6);
    transform: scale(0.92);
}

.instructions-hint {
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
    font-size: clamp(0.75rem, 2.5vw, 0.9rem);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-top: 5px;
    pointer-events: none;
}

.instructions-hint strong {
    color: var(--text-accent);
}

/* Visibility classes */
.mobile-only {
    display: none !important;
}

.desktop-only {
    display: inline !important;
}

body.touch-device .desktop-only {
    display: none !important;
}

body.touch-device .mobile-only {
    display: inline !important;
}

/* Landscape overlay for mobile screens to maximize game viewport size */
@media (max-height: 600px) and (orientation: landscape) {
    #mobile-controls {
        position: absolute;
        bottom: 25px;
        left: 0;
        right: 0;
        padding: 0 30px;
        justify-content: space-between;
        pointer-events: none;
    }
    .ctrl-btn {
        pointer-events: auto;
        width: 60px;
        height: 60px;
        font-size: 1.5rem;
    }
    #game-container {
        max-height: 80vh;
    }
}
