body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: black;
    font-family: 'Courier New', Courier, monospace;
    touch-action: none; /* Prevent browser zooming/scrolling on tap */
}

/* Webcam feed acting as the AR background */
#webcam-feed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    /* We don't mirror it, backward facing normally looks right */
}

/* A-Frame scene overlay */
a-scene {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
}

/* UI Layer should sit above the 3D scene but let touches pass through */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    pointer-events: none; /* Allows tap through to body/scene */
}

/* Camera Obscura Viewfinder */
#viewfinder {
    position: absolute;
    top: 50%; left: 50%;
    width: 250px; height: 250px;
    margin-top: -125px; margin-left: -125px;
    pointer-events: none;
}
.corner {
    position: absolute; width: 30px; height: 30px; 
    border: 3px solid rgba(255,255,255,0.7); 
    box-shadow: inset 0 0 5px rgba(255,0,0,0.5), 0 0 5px rgba(255,0,0,0.5);
}
.top-left { top: 0; left: 0; border-right: none; border-bottom: none; }
.top-right { top: 0; right: 0; border-left: none; border-bottom: none; }
.bottom-left { bottom: 0; left: 0; border-right: none; border-top: none; }
.bottom-right { bottom: 0; right: 0; border-left: none; border-top: none; }

#capture-circle {
    position: absolute;
    top: 50%; left: 50%;
    width: 80px; height: 80px;
    margin-top: -40px; margin-left: -40px;
    border: 2px dashed rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    transition: all 0.2s;
}

#capture-circle.charging {
    border-color: yellow;
    box-shadow: 0 0 10px yellow;
    transform: scale(0.9);
}

#capture-circle.fatal {
    border: 4px solid red;
    box-shadow: 0 0 20px red;
    background: rgba(255, 0, 0, 0.2);
    transform: scale(1.1);
}

#fatal-frame-alert {
    position: absolute;
    top: -50px; left: 50%;
    transform: translateX(-50%);
    color: red;
    font-size: 28px;
    font-weight: bold;
    text-shadow: 0 0 15px red, 0 0 5px white;
    opacity: 0;
    white-space: nowrap;
}

#fatal-frame-alert.active {
    opacity: 1;
    animation: flashAlert 0.15s infinite alternate;
}

@keyframes flashAlert {
    from { opacity: 1; } to { opacity: 0.3; }
}

#spirit-filament {
    position: absolute;
    top: 15px; left: 50%;
    width: 20px; height: 20px;
    border-radius: 50%;
    margin-left: -10px;
    background: radial-gradient(circle, #fff 0%, rgba(255,255,255,0) 70%);
    box-shadow: 0 0 10px 5px rgba(0, 100, 255, 0.5);
    transition: all 0.3s;
}
#spirit-filament.red { 
    box-shadow: 0 0 20px 10px rgba(255, 0, 0, 0.9); 
    background: radial-gradient(circle, #ffaaaa 0%, rgba(255,0,0,0) 70%); 
}

/* HUD System */
#hud {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#health-bar-container {
    width: 200px;
    height: 20px;
    background: rgba(50, 0, 0, 0.8);
    border: 2px solid #a00;
}

#health-bar {
    width: 100%;
    height: 100%;
    background: #f00;
    transition: width 0.3s ease;
}

#score {
    color: white;
    font-size: 24px;
    text-shadow: 2px 2px 4px #000;
    font-weight: bold;
}

#ammo-display {
    color: #dfdfdf;
    font-size: 20px;
    text-shadow: 2px 2px 4px #000;
}

#level-display {
    position: absolute;
    top: 20px;
    right: 20px;
    color: #ffaa00;
    font-size: 30px;
    font-weight: bold;
    text-shadow: 0 0 10px red;
}

/* The Flash */
#flash-effect {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    opacity: 0;
    transition: opacity 0.1s;
    pointer-events: none;
}

.flash-active {
    opacity: 0.9 !important;
}

.flash-red {
    background: red !important;
    opacity: 0.8 !important;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100; /* Ensure it stays above A-Frame canvas */
    background: rgba(0, 0, 0, 0.85);
    color: #e00;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto; /* Buttons need pointer events */
    text-align: center;
}

.screen h1 {
    font-size: 40px;
    margin-bottom: 10px;
    text-shadow: 0 0 10px red;
}

.screen p {
    font-size: 20px;
    color: #aaa;
    max-width: 80%;
}

.hidden {
    display: none !important;
}

button {
    margin-top: 30px;
    padding: 15px 30px;
    font-size: 22px;
    background: #400;
    color: white;
    border: 2px solid red;
    border-radius: 5px;
    cursor: pointer;
    font-family: inherit;
    text-transform: uppercase;
    box-shadow: 0 0 10px red;
    transition: all 0.2s ease;
}

button:hover {
    background: red;
    color: white;
    box-shadow: 0 0 20px red;
}

/* =================== V3: Store UI =================== */
#shop-btn {
    margin-top: 10px;
    padding: 5px 10px;
    background: rgba(100, 0, 0, 0.7);
    color: white;
    border: 1px solid #ff4444;
    border-radius: 5px;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    pointer-events: auto;
}

.shop-items {
    display: flex;
    gap: 15px;
    margin: 20px 0;
    justify-content: center;
}

.shop-item {
    background: rgba(50, 0, 0, 0.8);
    border: 2px solid #a00;
    padding: 15px;
    border-radius: 8px;
    width: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.shop-item h3 { margin: 0 0 10px 0; font-size: 18px; color: #ff8888; }
.shop-item p { font-size: 12px; line-height: 1.4; margin-bottom: 15px; flex-grow: 1; }
.buy-btn {
    background: #000;
    color: #0f0;
    border: 1px solid #0f0;
    padding: 8px;
    border-radius: 5px;
    width: 100%;
    cursor: pointer;
}
.buy-btn:disabled { color: #555; border-color: #555; cursor: not-allowed; }
#close-shop-btn { margin-top: 20px; background: transparent; color: white; border: 1px solid white; padding: 10px 30px; }

/* =================== V3: Film Selector =================== */
#film-selector {
    position: absolute;
    bottom: 20px;
    left: 20px;
    display: flex;
    gap: 10px;
    z-index: 50;
    pointer-events: auto;
}

.film-slot {
    width: 45px;
    height: 45px;
    background: rgba(0,0,0,0.6);
    border: 2px solid #555;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #888;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 0 5px #000;
    transition: all 0.2s;
}

.film-slot small { font-size: 10px; opacity: 0.8; }
.film-slot.active { border-color: #ffcccc; color: white; box-shadow: 0 0 15px #ff0000; background: rgba(150,0,0,0.5); transform: scale(1.1); }

/* =================== V3: Horror VFX =================== */
#glitch-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 100;
    background: repeating-linear-gradient(0deg, rgba(255,255,255,0.05), rgba(255,255,255,0.05) 1px, transparent 1px, transparent 2px);
    opacity: 0;
    transition: opacity 0.2s;
    mix-blend-mode: overlay;
}

@keyframes vhsTear {
    0% { transform: translateX(0); filter: hue-rotate(0deg); opacity: 0.5; }
    20% { transform: translateX(-15px) skewY(2deg); filter: hue-rotate(90deg); opacity: 1; }
    40% { transform: translateX(10px) skewY(-2deg); filter: hue-rotate(-90deg); opacity: 0.8; }
    100% { transform: translateX(0); filter: hue-rotate(0deg); opacity: 0.5; }
}

#glitch-overlay.active {
    opacity: 1;
    animation: vhsTear 0.2s infinite;
}

#cracked-glass-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 200;
    background-image: radial-gradient(circle, transparent 20%, rgba(200, 0, 0, 0.8) 80%),
                      url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M50,50 L20,10 M50,50 L80,15 M50,50 L10,60 M50,50 L90,70 M50,50 L30,90 M50,50 L70,95 M50,50 L5,35 M50,50 L95,40" stroke="white" stroke-width="0.5" fill="none"/></svg>');
    background-size: cover;
    opacity: 0;
}

#cracked-glass-overlay.active {
    opacity: 1;
    transition: opacity 0.05s ease-out;
}

/* =================== AUTH & LEADERBOARD =================== */
.auth-box {
    background: rgba(30, 0, 0, 0.9);
    border: 2px solid #a00;
    padding: 30px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 80%;
    max-width: 320px;
    box-shadow: 0 0 20px rgba(255, 0, 0, 0.4);
}

.auth-input {
    width: 100%;
    padding: 12px;
    margin: 8px 0;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid #550000;
    color: white;
    font-size: 16px;
    box-sizing: border-box;
    border-radius: 5px;
    text-align: center;
}

.auth-input:focus {
    outline: none;
    border-color: red;
    box-shadow: 0 0 10px red;
}

.leaderboard-entry {
    background: rgba(40, 0, 0, 0.8);
    border: 1px solid #ff4444;
    padding: 10px;
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #ffcccc;
}

.leaderboard-entry span.rank {
    font-weight: bold;
    color: #ffaa00;
    font-size: 18px;
    width: 30px;
}
.leaderboard-entry span.name {
    flex-grow: 1;
    text-align: left;
    margin-left: 10px;
    font-weight: bold;
}
.leaderboard-entry span.score {
    color: #88ff88;
}

.bottom-right-shop {
    position: absolute;
    bottom: 25px;
    right: 20px;
    background: rgba(20, 0, 0, 0.9);
    border: 2px solid #880000;
    color: #ffcccc;
    padding: 12px 18px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.5);
    transition: all 0.2s;
    pointer-events: auto;
    z-index: 50;
    text-shadow: 0 0 5px red;
}

.bottom-right-shop:active {
    transform: scale(0.95);
    background: #550000;
}

/* =================== FEEDBACK EMOJIS =================== */
.feedback-emj {
    filter: grayscale(100%) opacity(60%);
    cursor: pointer;
    transition: all 0.2s;
    padding: 0 5px; /* Larger hit area */
}
.feedback-emj:hover, .feedback-emj.hovered {
    filter: grayscale(0%) opacity(100%);
    transform: scale(1.15);
}
.feedback-emj.selected {
    filter: grayscale(0%) opacity(100%);
    transform: scale(1.25);
    background: radial-gradient(circle, rgba(255,255,0,0.4) 0%, rgba(0,0,0,0) 70%);
}
