@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@600;800;900&family=Kanit:wght@300;400;600;700&display=swap');

:root {
    --bg-dark: #07090e;
    --panel-bg: rgba(14, 18, 28, 0.85);
    --panel-border: rgba(90, 110, 140, 0.35);
    --blood-red: #ff1e38;
    --blood-dark: #6e0b17;
    --spectral-purple: #9d4edd;
    --wraith-cyan: #38bdf8;
    --relic-gold: #fbbf24;
    --battery-blue: #06b6d4;
    --exit-green: #10b981;
    --text-primary: #f1f5f9;
    --text-muted: #94a3b8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: 'Kanit', sans-serif;
    color: var(--text-primary);
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #000;
}

/* Canvas styling */
#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Red Vignette Overlay for Chase Mode */
#chase-vignette {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    box-shadow: inset 0 0 120px 45px rgba(255, 10, 40, 0.85);
    transition: opacity 0.25s ease-in-out;
    z-index: 20;
}

#chase-vignette.active {
    opacity: 1;
    animation: heartbeatVignette 0.55s infinite alternate ease-in-out;
}

@keyframes heartbeatVignette {
    0% {
        box-shadow: inset 0 0 90px 30px rgba(255, 15, 45, 0.65);
        filter: brightness(1);
    }
    100% {
        box-shadow: inset 0 0 160px 65px rgba(255, 0, 30, 0.95);
        filter: brightness(0.85) saturate(1.4);
    }
}

/* CRT Screen Effect overlay */
.scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.28) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
    background-size: 100% 3px, 4px 100%;
    z-index: 25;
    opacity: 0.75;
}

/* Top HUD Banner */
#hud-top {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 30;
}

.hud-panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(8px);
    border-radius: 12px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.65);
    pointer-events: auto;
}

.room-display {
    font-size: 15px;
    font-weight: 600;
    color: #e2e8f0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.room-tag {
    color: var(--wraith-cyan);
    background: rgba(56, 189, 248, 0.15);
    padding: 3px 10px;
    border-radius: 6px;
    border: 1px solid rgba(56, 189, 248, 0.35);
    letter-spacing: 0.5px;
}

.relic-counter {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--relic-gold);
}

.relic-icon {
    font-size: 20px;
    filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.8));
    animation: relicPulse 2s infinite ease-in-out;
}

@keyframes relicPulse {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 6px rgba(251, 191, 36, 0.6)); }
    50% { transform: scale(1.15); filter: drop-shadow(0 0 14px rgba(251, 191, 36, 1)); }
}

/* Action Buttons in HUD */
.hud-actions {
    display: flex;
    gap: 10px;
}

.hud-btn {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.35);
    color: #f8fafc;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.hud-btn:hover {
    background: rgba(51, 65, 85, 0.9);
    border-color: rgba(56, 189, 248, 0.6);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.25);
}

.hud-btn.active {
    background: rgba(239, 68, 68, 0.25);
    border-color: var(--blood-red);
    color: #fca5a5;
}

/* Bottom HUD: Stamina & Stealth Status */
#hud-bottom {
    position: absolute;
    bottom: 20px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    z-index: 30;
}

.stamina-container {
    width: 260px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(8px);
    border-radius: 12px;
    padding: 10px 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.65);
}

.stamina-header {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
}

.stamina-bar-bg {
    width: 100%;
    height: 10px;
    background: rgba(30, 41, 59, 0.8);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.stamina-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #0ea5e9, #38bdf8);
    border-radius: 6px;
    transition: width 0.1s linear, background 0.3s ease;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.6);
}

.stamina-bar-fill.depleted {
    background: linear-gradient(90deg, #dc2626, #ef4444);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.8);
}

/* Speed Badge Indicator */
.speed-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(6px);
    width: fit-content;
    transition: all 0.2s ease;
}

.speed-badge.burst {
    border-color: #38bdf8;
    background: rgba(14, 165, 233, 0.25);
    color: #7dd3fc;
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
    animation: burstPulse 0.6s infinite alternate;
}

.speed-badge.fast {
    border-color: #06b6d4;
    background: rgba(6, 182, 212, 0.2);
    color: #67e8f9;
}

.speed-badge.tired {
    border-color: #f59e0b;
    background: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
}

.speed-badge.exhausted {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    animation: exhaustedPulse 0.5s infinite alternate;
}

.speed-badge.dash {
    border-color: #ec4899;
    background: rgba(236, 72, 153, 0.35);
    color: #fbcfe8;
    box-shadow: 0 0 16px rgba(236, 72, 153, 0.6);
}

.speed-badge.sneak {
    border-color: #a855f7;
    background: rgba(168, 85, 247, 0.2);
    color: #d8b4fe;
}

.speed-badge.walk {
    border-color: rgba(255, 255, 255, 0.15);
    color: #cbd5e1;
}

@keyframes burstPulse {
    0% { transform: scale(1); filter: brightness(1); }
    100% { transform: scale(1.05); filter: brightness(1.2); }
}

@keyframes exhaustedPulse {
    0% { transform: scale(1); filter: drop-shadow(0 0 2px red); }
    100% { transform: scale(1.04); filter: drop-shadow(0 0 8px red); }
}

/* Noise & Stealth Status Pill */
.stealth-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(6px);
    width: fit-content;
}

.stealth-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #22c55e;
    box-shadow: 0 0 8px #22c55e;
}

.stealth-status-pill.hiding {
    border-color: rgba(56, 189, 248, 0.6);
    background: rgba(14, 116, 144, 0.35);
}

.stealth-status-pill.hiding .stealth-dot {
    background-color: #38bdf8;
    box-shadow: 0 0 10px #38bdf8;
}

.stealth-status-pill.danger {
    border-color: rgba(239, 68, 68, 0.7);
    background: rgba(185, 28, 28, 0.35);
    animation: dangerPill 0.6s infinite alternate;
}

.stealth-status-pill.danger .stealth-dot {
    background-color: #ef4444;
    box-shadow: 0 0 12px #ef4444;
}

@keyframes dangerPill {
    0% { transform: scale(1); }
    100% { transform: scale(1.04); }
}

/* Wraith Proximity Heartbeat bar on the right */
#hud-right {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    pointer-events: none;
    z-index: 30;
}

.wraith-meter-panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(8px);
    border-radius: 12px;
    padding: 8px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.65);
}

.heartbeat-icon {
    font-size: 20px;
    color: var(--blood-red);
    transition: transform 0.15s ease;
}

.heartbeat-icon.beating {
    animation: heartPulse 0.4s infinite alternate;
}

@keyframes heartPulse {
    0% { transform: scale(1); filter: drop-shadow(0 0 2px var(--blood-red)); }
    100% { transform: scale(1.35); filter: drop-shadow(0 0 14px var(--blood-red)); }
}

.wraith-state-text {
    font-size: 13px;
    font-weight: 700;
    color: #e2e8f0;
}

/* Interactive Closet Prompt floating hint */
#closet-prompt {
    position: absolute;
    bottom: 95px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid var(--wraith-cyan);
    color: #f0fdf4;
    padding: 8px 18px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    display: none;
    align-items: center;
    gap: 8px;
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.45);
    z-index: 35;
    animation: promptBounce 1.2s infinite ease-in-out;
}

@keyframes promptBounce {
    0%, 100% { transform: translate(-50%, 0); }
    50% { transform: translate(-50%, -6px); }
}

.key-badge {
    background: #38bdf8;
    color: #0f172a;
    padding: 2px 7px;
    border-radius: 6px;
    font-weight: 800;
    font-size: 12px;
}

/* Mobile Virtual Joystick & Touch Controls */
#mobile-controls {
    position: absolute;
    bottom: 15px;
    left: 0;
    right: 0;
    display: none;
    justify-content: space-between;
    padding: 0 24px;
    pointer-events: none;
    z-index: 40;
}

.touch-dpad-container {
    width: 140px;
    height: 140px;
    background: rgba(30, 41, 59, 0.45);
    border: 2px solid rgba(148, 163, 184, 0.3);
    border-radius: 50%;
    position: relative;
    pointer-events: auto;
    touch-action: none;
    backdrop-filter: blur(4px);
}

.touch-stick {
    width: 52px;
    height: 52px;
    background: radial-gradient(circle, #38bdf8, #0284c7);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 14px rgba(56, 189, 248, 0.8);
    pointer-events: none;
}

.touch-actions {
    display: grid;
    grid-template-columns: repeat(2, 58px);
    gap: 10px;
    align-items: center;
    pointer-events: auto;
}

.touch-circle-btn {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(6px);
    color: white;
    font-size: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    touch-action: none;
    transition: transform 0.1s ease;
}

.touch-circle-btn:active, .touch-circle-btn.pressed {
    transform: scale(0.92);
    border-color: #38bdf8;
    background: rgba(56, 189, 248, 0.35);
}

.touch-circle-btn.sprint-btn.pressed {
    border-color: #f97316;
    background: rgba(249, 115, 22, 0.45);
}

.touch-circle-btn.dash-btn {
    border-color: #38bdf8;
    background: rgba(14, 165, 233, 0.3);
}

.touch-circle-btn.dash-btn:active, .touch-circle-btn.dash-btn.pressed {
    border-color: #ec4899;
    background: rgba(236, 72, 153, 0.45);
}

.touch-circle-btn.sneak-btn {
    border-color: #a855f7;
    background: rgba(168, 85, 247, 0.25);
}

.touch-circle-btn.sneak-btn.pressed {
    border-color: #c084fc;
    background: rgba(168, 85, 247, 0.55);
}

.touch-btn-sub {
    font-size: 8.5px;
    font-weight: 700;
    text-transform: uppercase;
    margin-top: -2px;
}

/* Modal Overlay (Title, Map, Victory, Game Over) */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 7, 12, 0.88);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

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

.modal-card {
    background: linear-gradient(145deg, #111827, #0b0f19);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 20px;
    padding: 32px;
    max-width: 580px;
    width: 90%;
    text-align: center;
    box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.9), 0 0 35px rgba(147, 51, 234, 0.15);
    position: relative;
    overflow: hidden;
}

.modal-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #9333ea, #38bdf8, #ef4444);
}

.modal-title {
    font-family: 'Cinzel', serif;
    font-size: 32px;
    font-weight: 900;
    letter-spacing: 2px;
    margin-bottom: 8px;
    background: linear-gradient(180deg, #ffffff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.modal-subtitle {
    font-size: 14px;
    color: #94a3b8;
    margin-bottom: 24px;
    line-height: 1.6;
}

.hero-wraith-img {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    object-fit: cover;
    margin: 0 auto 20px auto;
    border: 3px solid rgba(239, 68, 68, 0.6);
    box-shadow: 0 0 25px rgba(239, 68, 68, 0.5);
    animation: wraithBreathe 3s infinite alternate ease-in-out;
}

@keyframes wraithBreathe {
    0% { transform: scale(1); box-shadow: 0 0 20px rgba(239, 68, 68, 0.4); }
    100% { transform: scale(1.06); box-shadow: 0 0 35px rgba(239, 68, 68, 0.85); }
}

.controls-guide-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    text-align: left;
    background: rgba(15, 23, 42, 0.6);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 24px;
    font-size: 13px;
}

.guide-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.guide-key {
    background: #1e293b;
    border: 1px solid #475569;
    padding: 3px 8px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 11px;
    color: #38bdf8;
    min-width: 44px;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, #ef4444, #b91c1c);
    color: white;
    font-family: 'Kanit', sans-serif;
    font-size: 18px;
    font-weight: 700;
    padding: 14px 38px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(239, 68, 68, 0.45);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.btn-primary:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 30px rgba(239, 68, 68, 0.65);
    filter: brightness(1.1);
}

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

/* Blueprint Map Modal */
.blueprint-card {
    max-width: 680px;
    width: 95%;
    padding: 24px;
    background: #091322;
    border: 2px solid #0284c7;
    box-shadow: 0 0 35px rgba(2, 132, 199, 0.35);
}

.blueprint-grid-preview {
    width: 100%;
    height: 340px;
    background: #040b15;
    border: 1px dashed rgba(56, 189, 248, 0.4);
    border-radius: 10px;
    position: relative;
    overflow: hidden;
    margin: 16px 0;
}

#map-canvas {
    width: 100%;
    height: 100%;
}

.blueprint-legend {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 12px;
    color: #cbd5e1;
    margin-bottom: 16px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

/* JUMPSCARE OVERLAY */
#jumpscare-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 200;
    display: none;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#jumpscare-img {
    width: 110%;
    height: 110%;
    object-fit: cover;
    filter: contrast(1.7) brightness(1.2) drop-shadow(0 0 40px red);
    animation: jumpscareShake 0.08s infinite alternate, jumpscareZoom 0.9s forwards ease-in;
}

@keyframes jumpscareShake {
    0% { transform: translate(-12px, -8px) rotate(-1deg); }
    100% { transform: translate(14px, 12px) rotate(1.5deg); }
}

@keyframes jumpscareZoom {
    0% { transform: scale(1); filter: contrast(1.3) brightness(0.9); }
    70% { transform: scale(1.4); filter: contrast(2.2) brightness(1.6) invert(0.15); }
    100% { transform: scale(1.65); filter: contrast(2.5) brightness(1.9) hue-rotate(320deg); }
}

/* Victory styling */
.victory-card {
    border-color: rgba(16, 185, 129, 0.4);
    box-shadow: 0 0 45px rgba(16, 185, 129, 0.3);
}

.victory-title {
    font-family: 'Cinzel', serif;
    color: #34d399;
    font-size: 34px;
    margin-bottom: 12px;
}

.victory-stats {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: 12px;
    padding: 16px;
    margin: 18px 0;
    display: flex;
    justify-content: space-around;
}

.stat-item {
    text-align: center;
}

.stat-val {
    font-size: 26px;
    font-weight: 800;
    color: #f1f5f9;
}

.stat-lbl {
    font-size: 12px;
    color: #94a3b8;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #mobile-controls {
        display: flex;
    }
    .hud-panel {
        padding: 6px 10px;
        gap: 8px;
    }
    .room-display {
        font-size: 13px;
    }
    .stamina-container {
        width: 170px;
        padding: 8px 10px;
    }
    .controls-guide-grid {
        grid-template-columns: 1fr;
    }
    .modal-card {
        padding: 20px;
    }
}
