/* ══════════════════════════════════════════════════
   RESET & BASE
   ══════════════════════════════════════════════════ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: #0a0808;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* ══════════════════════════════════════════════════
   GAME WRAPPER & BORDERS
   ══════════════════════════════════════════════════ */
#maze-outer-wrapper {
    width: 100vw;
    height: 100vh;
    max-width: none;
    margin: 0;
    position: relative;
    background: #000;
    border-radius: 0;
    overflow: hidden;
    border: none;
    box-shadow: 0 0 0 1px #1a0e06, 
                0 0 40px rgba(180, 80, 0, .15), 
                0 0 80px rgba(100, 40, 0, .1), 
                inset 0 0 60px rgba(0, 0, 0, .8);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* In modalità finestra usiamo un aspetto 16:10 per risparmiare pixel e guadagnare FPS */
#maze-outer-wrapper:not(:fullscreen) #maze-game-container {
    width: min(100vw, calc(100vh * 1.6));
    height: min(100vh, calc(100vw / 1.6));
    aspect-ratio: 16/10;
}

/* Ottimizzazione FPS per Schermo Intero */
#maze-outer-wrapper:fullscreen {
    box-shadow: none;
}

#maze-outer-wrapper:fullscreen #vignette {
    opacity: 0.5;
}

#maze-outer-wrapper::before,
#maze-outer-wrapper::after {
    content: '';
    position: absolute;
    width: 60px;
    height: 60px;
    z-index: 50;
    pointer-events: none;
}

#maze-outer-wrapper::before {
    top: 0;
    left: 0;
    border-top: 2px solid #6a3a1a;
    border-left: 2px solid #6a3a1a;
}

#maze-outer-wrapper::after {
    bottom: 0;
    right: 0;
    border-bottom: 2px solid #6a3a1a;
    border-right: 2px solid #6a3a1a;
}

/* ══════════════════════════════════════════════════
   OVERLAYS & EFFECTS
   ══════════════════════════════════════════════════ */
#game-message {
    position: absolute;
    top: 28%;
    left: 50%;
    transform: translateX(-50%);
    color: #f5d98a;
    background: linear-gradient(135deg, rgba(20, 10, 5, .97), rgba(40, 20, 8, .97));
    border: 1px solid #6a3a1a;
    border-radius: 2px;
    padding: 12px 28px;
    font-family: 'Cinzel', serif;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 2px;
    display: none;
    z-index: 25;
    white-space: nowrap;
    box-shadow: 0 0 30px rgba(200, 80, 0, .3);
    text-shadow: 0 0 20px rgba(255, 160, 50, .8);
    animation: msgGlow .3s ease-out;
}

@keyframes msgGlow {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

#slash-anim {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 150%;
    height: 10px;
    background: linear-gradient(90deg, transparent, rgba(255, 220, 150, .9), white, rgba(255, 220, 150, .9), transparent);
    box-shadow: 0 0 30px rgba(255, 200, 100, .8);
    transform: translate(-50%, -50%) rotate(45deg) scaleX(0);
    z-index: 20;
    border-radius: 5px;
}

#flash-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, rgba(255, 200, 100, .6) 0%, rgba(200, 80, 0, .3) 60%, transparent 100%);
    opacity: 0;
    pointer-events: none;
    z-index: 25;
}

/* Invisibility shimmer */
#invis-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 16;
    opacity: 0;
    transition: opacity .6s;
    background: linear-gradient(160deg, rgba(40, 180, 255, .05) 0%, rgba(60, 220, 255, .12) 40%, rgba(20, 120, 200, .08) 100%);
    border: none;
}

#invis-overlay.active {
    opacity: 1;
    animation: invisPulse 1.8s ease-in-out infinite;
}

#invis-overlay.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(90deg, transparent 0, transparent 40px, rgba(60, 200, 255, .04) 40px, rgba(60, 200, 255, .04) 41px);
    pointer-events: none;
}

@keyframes invisPulse {
    0%, 100% {
        opacity: .65;
        box-shadow: inset 0 0 60px rgba(40, 180, 255, .15);
    }
    50% {
        opacity: 1;
        box-shadow: inset 0 0 80px rgba(60, 220, 255, .25);
    }
}

#burn-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 14;
    opacity: 0;
    transition: opacity .4s;
    background: linear-gradient(180deg, rgba(255, 80, 0, .12) 0%, rgba(200, 40, 0, .08) 50%, transparent 100%);
    box-shadow: inset 0 0 80px rgba(255, 100, 0, .15);
}

#burn-overlay.active {
    opacity: 1;
    animation: burnPulse 1s ease-in-out infinite;
}

@keyframes burnPulse {
    0%, 100% {
        opacity: .7;
    }
    50% {
        opacity: 1;
    }
}

#freeze-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 14;
    opacity: 0;
    transition: opacity .4s;
    background: linear-gradient(180deg, rgba(100, 200, 255, .1) 0%, rgba(60, 150, 220, .06) 50%, transparent 100%);
    box-shadow: inset 0 0 80px rgba(100, 180, 255, .12);
}

#freeze-overlay.active {
    opacity: 1;
    animation: freezePulse 1.2s ease-in-out infinite;
}

@keyframes freezePulse {
    0%, 100% {
        opacity: .6;
    }
    50% {
        opacity: 1;
    }
}

/* ══════════════════════════════════════════════════
   HUD & STATS
   ══════════════════════════════════════════════════ */
#health-ui {
    position: absolute;
    top: 14px;
    left: 16px;
    font-size: 18px;
    z-index: 25;
    letter-spacing: 1px;
    filter: drop-shadow(0 0 6px rgba(255, 0, 0, .6));
}

#stats-ui {
    position: absolute;
    top: 10px;
    right: 16px;
    font-family: 'Cinzel', serif;
    font-size: 15px;
    color: #d4b483;
    z-index: 25;
    text-align: right;
    line-height: 1.8;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0), rgba(15, 8, 3, .7));
    padding: 8px 12px;
    border-radius: 2px;
}

#stats-ui .stat-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

#stats-ui .stat-icon {
    font-size: 14px;
}

/* ══════════════════════════════════════════════════
   GAME CONTAINER & ICONS
   ══════════════════════════════════════════════════ */
#maze-game-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: #000;
}

#chase-icon {
    position: absolute;
    top: 45px;
    left: 56px;
    font-size: 28px;
    display: none;
    z-index: 10;
    pointer-events: none;
    opacity: .95;
    filter: drop-shadow(0 0 12px #ff2200) drop-shadow(0 0 24px #ff000088);
    animation: chaseFlicker .8s infinite alternate;
}

@keyframes chaseFlicker {
    from {
        opacity: .8;
        transform: scale(1);
    }
    to {
        opacity: 1;
        transform: scale(1.08);
    }
}

#hourglass-icon {
    position: absolute;
    top: 45px;
    left: 18px;
    font-size: 26px;
    display: none;
    z-index: 10;
    pointer-events: none;
    opacity: .75;
    animation: hgSpin 2s linear infinite;
}

@keyframes hgSpin {
    0%, 100% {
        transform: rotate(0deg);
    }
    50% {
        transform: rotate(180deg);
    }
}

/* ══════════════════════════════════════════════════
   UI PANELS (COMMANDS, MINIMAP, LOG)
   ══════════════════════════════════════════════════ */
#maze-ui {
    position: absolute;
    bottom: 18px;
    left: 18px;
    color: #b8956a;
    font-family: 'Cinzel', serif;
    font-size: 11px;
    line-height: 1.9;
    letter-spacing: .5px;
    background: linear-gradient(135deg, rgba(10, 5, 2, .92), rgba(20, 10, 4, .88));
    padding: 14px 18px;
    border-radius: 2px;
    border: 1px solid rgba(100, 55, 20, .4);
    border-top: 1px solid rgba(160, 90, 30, .5);
    pointer-events: none;
    z-index: 10;
}

#maze-ui .cmd-title {
    font-family: 'Cinzel Decorative', serif;
    font-size: 9px;
    letter-spacing: 3px;
    color: #c8905a;
    border-bottom: 1px solid rgba(100, 55, 20, .5);
    padding-bottom: 6px;
    margin-bottom: 6px;
    display: block;
    text-transform: uppercase;
}

#maze-ui .cmd-key {
    display: inline-block;
    background: rgba(80, 45, 15, .5);
    border: 1px solid rgba(140, 80, 30, .4);
    border-radius: 2px;
    padding: 0 4px;
    font-size: 10px;
    color: #e0b870;
    font-family: 'IM Fell English SC', serif;
    min-width: 22px;
    text-align: center;
}

#maze-ui .cmd-panic { color: #d4624a; }
#maze-ui .cmd-fs { color: #c8d460; }
#maze-ui .cmd-space { color: #e0d0a0; }
#maze-ui .cmd-pot { color: #66ddff; }

#vignette {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at 50% 50%, transparent 50%, rgba(0, 0, 0, 0.6) 100%);
    pointer-events: none;
    z-index: 5;
}

#scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: linear-gradient(to bottom, transparent 75%, rgba(0,0,0,0.03) 75%);
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 6;
    opacity: 0.4;
}

#minimap-wrap {
    position: absolute;
    bottom: 18px;
    right: 18px;
    z-index: 12;
    pointer-events: none;
    border: 4px solid #3a2a1a;
    border-radius: 2px;
    background: rgba(0, 0, 0, .8);
    padding: 3px;
    box-shadow: 0 0 10px rgba(180, 80, 0, .2);
}

#minimap-canvas {
    display: block;
    image-rendering: pixelated;
    width: 180px;
    height: 180px;
}

#event-log {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    width: 300px;
    z-index: 12;
    pointer-events: none;
    display: flex;
    flex-direction: column-reverse;
    gap: 2px;
}

.log-line {
    font-family: 'Cinzel', serif;
    font-size: 10px;
    background: rgba(0, 0, 0, .75);
    border-left: 2px solid rgba(160, 80, 20, .5);
    padding: 3px 8px;
    border-radius: 0 2px 2px 0;
    letter-spacing: .5px;
    animation: logFade 4s ease-out forwards;
}

@keyframes logFade {
    0%, 70% { opacity: 1; }
    100% { opacity: 0; }
}

.dmg-float {
    position: absolute;
    z-index: 30;
    font-family: 'Cinzel Decorative', serif;
    font-size: 24px;
    font-weight: 900;
    pointer-events: none;
    text-shadow: 0 0 8px currentColor;
    animation: dmgAnim .9s ease-out forwards;
}

@keyframes dmgAnim {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-28px) scale(.85);
    }
}

#hs-panel {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Cinzel', serif;
    font-size: 10px;
    color: rgba(180, 130, 60, .7);
    z-index: 12;
    pointer-events: none;
    letter-spacing: 1px;
    text-align: center;
    white-space: nowrap;
}

/* ══════════════════════════════════════════════════
   WIN / LOSE SCREENS
   ══════════════════════════════════════════════════ */
#win-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(160deg, rgba(5, 2, 0, .97), rgba(15, 7, 3, .98), rgba(5, 2, 0, .97));
    color: white;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
    font-family: 'Cinzel', serif;
    text-align: center;
}

#win-screen::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 500px;
    height: 500px;
    border-radius: 50%;
    background: radial-gradient(ellipse at center, rgba(100, 50, 10, .15), transparent 70%);
    pointer-events: none;
}

#win-screen .win-ornament {
    font-size: 40px;
    margin-bottom: 10px;
    opacity: .6;
    animation: ornPulse 3s ease-in-out infinite;
}

@keyframes ornPulse {
    0%, 100% {
        opacity: .5;
        transform: scale(1);
    }
    50% {
        opacity: .8;
        transform: scale(1.05);
    }
}

#end-title {
    font-family: 'Cinzel Decorative', serif;
    font-size: 2.8rem;
    letter-spacing: 4px;
    text-transform: uppercase;
    margin-bottom: 6px;
    animation: titleReveal .8s ease-out forwards;
    position: relative;
    z-index: 1;
}

@keyframes titleReveal {
    from {
        opacity: 0;
        transform: translateY(20px) scale(.95);
        letter-spacing: 12px;
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.win-divider {
    width: 200px;
    height: 1px;
    background: linear-gradient(90deg, transparent, currentColor, transparent);
    margin: 12px auto;
    opacity: .4;
}

#win-subtitle {
    font-family: 'Cinzel', serif;
    font-size: .85rem;
    color: #8a7060;
    letter-spacing: 3px;
    margin-bottom: 8px;
    text-transform: uppercase;
}

#win-stats {
    font-family: 'Cinzel', serif;
    font-size: .75rem;
    color: #7a6050;
    letter-spacing: 1px;
    margin-bottom: 20px;
    line-height: 1.8;
}

#restart-btn {
    font-family: 'Cinzel Decorative', serif;
    padding: 14px 40px;
    font-size: .95rem;
    font-weight: 700;
    letter-spacing: 3px;
    background: transparent;
    color: #c8905a;
    border: 1px solid #6a3a1a;
    border-radius: 2px;
    cursor: pointer;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
    transition: all .3s;
    box-shadow: 0 0 20px rgba(180, 80, 0, .1), inset 0 0 20px rgba(0, 0, 0, .5);
}

#restart-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(180, 100, 30, .15), transparent);
    transition: left .4s;
}

#restart-btn:hover {
    color: #f0c070;
    border-color: #c87830;
    transform: translateY(-1px);
}

#restart-btn:hover::before {
    left: 100%;
}

/* ══════════════════════════════════════════════════
   TITLE & DIFFICULTY OVERLAYS
   ══════════════════════════════════════════════════ */
#game-title-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(160deg, #050200, #0d0600, #050200);
    z-index: 30;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 1s ease-in-out;
}

#game-title-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

#game-title-overlay .main-title {
    font-family: 'Cinzel Decorative', serif;
    font-size: 4rem;
    color: #c8905a;
    letter-spacing: 8px;
    animation: tGlow 2s ease-in-out infinite alternate;
}

@keyframes tGlow {
    from {
        text-shadow: 0 0 40px rgba(200, 120, 50, .6), 0 0 80px rgba(180, 80, 0, .3);
    }
    to {
        text-shadow: 0 0 60px rgba(230, 150, 60, .8), 0 0 100px rgba(200, 100, 0, .5);
    }
}

#game-title-overlay .sub-title {
    font-family: 'IM Fell English SC', serif;
    font-size: 1rem;
    color: #6a4a2a;
    letter-spacing: 6px;
    margin-top: 10px;
}

#game-title-overlay .title-deco {
    font-size: 24px;
    margin: 15px 0;
    opacity: .5;
}

#difficulty-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 31;
    display: flex;
    justify-content: center;
    align-items: center;
    background: transparent;
    backdrop-filter: blur(2px);
    transition: opacity 0.8s ease-in-out;
}

#difficulty-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.diff-card {
    width: min(620px, 92%);
    background: linear-gradient(135deg, rgba(10, 5, 2, .95), rgba(22, 10, 4, .92));
    border: 1px solid rgba(140, 80, 30, .45);
    border-top: 1px solid rgba(200, 120, 60, .55);
    box-shadow: 0 0 30px rgba(180, 80, 0, .18), inset 0 0 30px rgba(0, 0, 0, .6);
    padding: 22px 22px 18px;
    border-radius: 3px;
    text-align: center;
    color: #d4b483;
}

.diff-title {
    font-family: 'Cinzel Decorative', serif;
    font-size: 1.6rem;
    letter-spacing: 3px;
    color: #c8905a;
    text-transform: uppercase;
    margin-bottom: 10px;
}

.diff-sub {
    font-family: 'Cinzel', serif;
    font-size: 12px;
    letter-spacing: 1px;
    color: #8a7060;
    line-height: 1.6;
    margin-bottom: 16px;
}

.diff-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.diff-btn {
    font-family: 'Cinzel Decorative', serif;
    padding: 12px 26px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 2px;
    background: transparent;
    color: #c8905a;
    border: 1px solid #6a3a1a;
    border-radius: 2px;
    cursor: pointer;
    text-transform: uppercase;
    transition: all .25s;
    box-shadow: 0 0 18px rgba(180, 80, 0, .10), inset 0 0 18px rgba(0, 0, 0, .45);
}

.diff-btn:hover {
    color: #f0c070;
    border-color: #c87830;
    transform: translateY(-1px);
}

.diff-btn:disabled {
    opacity: .45;
    cursor: default;
    transform: none;
}

.diff-btn-hard {
    border-color: rgba(255, 80, 80, .55);
    color: #ffb0b0}

.diff-btn-hard:hover {
    border-color: rgba(255, 120, 120, .75);
    color: #ffd0d0;
}
