/* --- DESIGN SYSTEM --- */
:root {
    /* Color Palette (HSL) - Autumn Forest */
    --color-bg-dark: hsl(25, 40%, 88%);
    --color-bg-glass: hsla(25, 35%, 8%, 0.65);
    --color-border-glass: hsla(0, 0%, 100%, 0.08);
    --color-text-main: hsl(30, 15%, 95%);
    --color-text-muted: hsl(30, 10%, 70%);
    
    --color-primary: hsl(25, 95%, 53%); /* Squirrel Orange */
    --color-primary-glow: hsla(25, 95%, 53%, 0.45);
    --color-primary-hover: hsl(25, 95%, 60%);
    
    --color-danger: hsl(355, 80%, 55%); /* Toadstool Red */
    --color-danger-glow: hsla(355, 80%, 55%, 0.4);
    
    --color-success: hsl(45, 95%, 50%); /* Golden Acorn Yellow */
    --color-success-glow: hsla(45, 95%, 50%, 0.3);
    
    /* Layout & Styling Tokens */
    --font-heading: 'Outfit', 'Inter', system-ui, -apple-system, sans-serif;
    --font-body: 'Inter', system-ui, -apple-system, sans-serif;
    --border-radius-lg: 24px;
    --border-radius-md: 16px;
    --border-radius-sm: 8px;
    --transition-smooth: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    --transition-quick: all 0.15s ease-out;
}

/* --- RESET & BASIC STYLES --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: var(--color-bg-dark);
    color: var(--color-text-main);
    font-family: var(--font-body);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    margin: 0;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* --- GAME CONTAINER --- */
#game-container {
    position: relative;
    width: 100vw;
    height: 56.25vw; /* 16:9 Aspect Ratio */
    max-width: 1024px;
    max-height: 576px;
    background: #0d0602;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), 0 0 40px rgba(211, 84, 0, 0.15);
    overflow: hidden;
    border-radius: var(--border-radius-lg);
    border: 2px solid var(--color-border-glass);
}

@media (min-aspect-ratio: 16/9) {
    #game-container {
        width: 177.78vh;
        height: 100vh;
    }
}

#game-container:fullscreen {
    max-width: none;
    max-height: none;
    border-radius: 0;
    border: none;
}

/* --- GAME CANVAS --- */
#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* --- HUD LAYER --- */
.hud-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.hud-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.hud-left, .hud-right {
    display: flex;
    align-items: center;
    gap: 16px;
    pointer-events: auto;
}

.hud-center {
    display: flex;
    flex-grow: 1;
    justify-content: center;
    max-width: 350px;
    margin: 0 20px;
}

.hud-stat {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--color-bg-glass);
    border: 1px solid var(--color-border-glass);
    border-radius: var(--border-radius-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.hud-stat .label {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.hud-stat .value {
    font-size: 1.15rem;
    font-weight: 700;
    font-family: var(--font-heading);
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.hud-stat .icon {
    font-size: 1.3rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.boost-meter {
    position: relative;
    width: 100%;
    height: 24px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--color-border-glass);
    border-radius: 12px;
    overflow: hidden;
    backdrop-filter: blur(8px);
    pointer-events: auto;
}

.boost-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-success));
    box-shadow: 0 0 12px var(--color-primary-glow);
    transition: width 0.1s ease-out;
}

.boost-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
    white-space: nowrap;
}

.hud-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 44px;
    height: 44px;
    border-radius: var(--border-radius-md);
    background: var(--color-bg-glass);
    border: 1px solid var(--color-border-glass);
    color: var(--color-text-main);
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: var(--transition-quick);
}

.hud-btn:hover {
    background: hsla(25, 35%, 15%, 0.85);
    transform: scale(1.05);
    color: var(--color-primary);
    box-shadow: 0 0 10px var(--color-primary-glow);
}

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

/* --- UI OVERLAY & SCREENS --- */
#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    pointer-events: none;
}

.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 32px;
    background: var(--color-bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.4s cubic-bezier(0.25, 0.8, 0.25, 1), 
                visibility 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

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

.overlay-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* --- LOGO / HEADER --- */
.logo-container {
    text-align: center;
    margin-bottom: 32px;
    animation: floatAnimation 4s ease-in-out infinite;
}

.avatar-animation {
    font-size: 4.5rem;
    margin-bottom: 8px;
    display: inline-block;
    filter: drop-shadow(0 8px 16px rgba(0,0,0,0.4));
    transition: var(--transition-smooth);
}

.overlay-screen:hover .avatar-animation {
    transform: translateY(-8px) rotate(5deg) scale(1.05);
}

.game-title {
    font-family: var(--font-heading);
    font-size: 2.8rem;
    font-weight: 800;
    line-height: 1;
    color: #fff;
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.5), 
                 0 0 30px var(--color-primary-glow);
    background: linear-gradient(135deg, #fff 40%, var(--color-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.game-subtitle {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--color-primary);
    text-transform: uppercase;
    letter-spacing: 0.25em;
    margin-top: 4px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* --- BUTTONS --- */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 280px;
}

.btn {
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 700;
    padding: 14px 28px;
    border-radius: var(--border-radius-md);
    border: none;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: var(--transition-quick);
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    text-decoration: none;
    display: inline-block;
}

.primary-btn {
    background: linear-gradient(135deg, var(--color-primary), hsl(15, 95%, 45%));
    color: #fff;
    box-shadow: 0 6px 20px rgba(211, 84, 0, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(211, 84, 0, 0.5);
    background: linear-gradient(135deg, var(--color-primary-hover), hsl(15, 95%, 50%));
}

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

.secondary-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--color-text-main);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

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

.back-btn {
    margin-top: 24px;
    width: 100%;
    max-width: 180px;
}

.best-score-badge {
    margin-top: 32px;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    background: rgba(0, 0, 0, 0.3);
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid var(--color-border-glass);
}

.best-score-badge strong {
    color: var(--color-primary);
}

/* --- HOW TO PLAY SCREEN --- */
.screen-title {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 24px;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.screen-title.text-danger {
    color: var(--color-danger);
    text-shadow: 0 0 15px var(--color-danger-glow);
}

.how-to-content {
    display: flex;
    gap: 32px;
    max-width: 720px;
    background: rgba(0, 0, 0, 0.3);
    padding: 24px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--color-border-glass);
}

.control-guide {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    padding-right: 24px;
}

.guide-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.key-badge {
    display: inline-block;
    background: #3e2213;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--border-radius-sm);
    padding: 4px 10px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #fff;
    width: fit-content;
    box-shadow: 0 3px 0 rgba(0,0,0,0.5);
}

.touch-badge {
    background: var(--color-primary);
    color: #000;
    font-weight: 700;
    font-size: 10px;
    padding: 3px 8px;
    border-radius: 10px;
    margin-right: 8px;
    display: inline-block;
    border: 1px solid var(--color-primary-glow);
    text-transform: uppercase;
}

.action-desc {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.items-guide {
    flex: 1.2;
    display: flex;
    flex-direction: column;
    gap: 12px;
    justify-content: center;
}

.item-desc {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
}

.icon-big {
    font-size: 1.5rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

/* --- SETTINGS SCREEN --- */
.settings-content {
    width: 100%;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: rgba(0, 0, 0, 0.3);
    padding: 28px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--color-border-glass);
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.setting-row label {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--color-text-muted);
    min-width: 120px;
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
    transition: var(--transition-quick);
    box-shadow: 0 0 8px var(--color-primary-glow);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    background: var(--color-primary-hover);
}

.slider-value {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
    min-width: 45px;
    text-align: right;
}

.toggle-row {
    justify-content: space-between;
}

input[type="checkbox"] {
    position: relative;
    width: 46px;
    height: 24px;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.3s;
}

input[type="checkbox"]:checked {
    background: var(--color-success);
}

input[type="checkbox"]::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input[type="checkbox"]:checked::before {
    transform: translateX(22px);
}

/* --- GAME OVER & RESULTS --- */
.results-panel {
    width: 100%;
    max-width: 320px;
    background: rgba(0,0,0,0.4);
    border-radius: var(--border-radius-md);
    border: 1px solid var(--color-border-glass);
    padding: 20px;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-row {
    display: flex;
    justify-content: space-between;
    font-size: 1rem;
    color: var(--color-text-muted);
}

.result-row strong {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    color: #fff;
}

.new-record {
    color: var(--color-primary);
    font-family: var(--font-heading);
    font-weight: 800;
    text-align: center;
    font-size: 1.25rem;
    margin-top: 8px;
    animation: pulseAnimation 1.5s ease-in-out infinite;
    text-shadow: 0 0 10px var(--color-primary-glow);
}

/* --- ANIMATIONS --- */
@keyframes floatAnimation {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}

@keyframes pulseAnimation {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* Mobile landscape adjustments */
@media (max-width: 768px) {
    #game-container {
        border-radius: 0;
        max-height: none;
        max-width: none;
    }
    
    .how-to-content {
        flex-direction: column;
        gap: 16px;
        max-height: 250px;
        overflow-y: auto;
    }
    
    .control-guide {
        border-right: none;
        border-bottom: 1px solid rgba(255,255,255,0.08);
        padding-right: 0;
        padding-bottom: 16px;
    }
    
    .game-title {
        font-size: 2.2rem;
    }
    
    .game-subtitle {
        font-size: 1.1rem;
    }
}

.desktop-only-controls {
    display: block;
}

.mobile-only-controls {
    display: none;
}

@media (max-width: 768px) {
    .desktop-only-controls {
        display: none;
    }
    .mobile-only-controls {
        display: block;
    }
}

/* --- PORTRAIT ROTATION WARNING --- */
#portrait-warning {
    display: none;
}

@media (max-width: 768px) and (orientation: portrait) {
    #portrait-warning {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: #0d0602;
        z-index: 9999;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        color: #fff;
        text-align: center;
        padding: 24px;
        box-sizing: border-box;
    }
    
    #portrait-warning .icon {
        font-size: 64px;
        margin-bottom: 20px;
        animation: rotatePhone 2.0s infinite ease-in-out;
    }
    
    #portrait-warning .title {
        font-family: 'Outfit', sans-serif;
        font-size: 22px;
        font-weight: 700;
        margin-bottom: 10px;
        color: var(--color-primary);
    }
    
    #portrait-warning .subtitle {
        font-family: 'Inter', sans-serif;
        font-size: 14px;
        line-height: 1.5;
        color: var(--color-text-muted);
    }
}

@keyframes rotatePhone {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(-90deg); }
    100% { transform: rotate(0deg); }
}
