/* --- BASE SETUP --- */
:root {
    /* These defaults are overridden by HTML injection */
    --main-color: #00d2ff; 
    --main-font: sans-serif;
    --bg-color: #111;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: white;
    font-family: var(--main-font);
    overflow: hidden; /* Prevent scrolling explicitly */
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- BACKGROUND PARTICLES --- */
.star {
    position: fixed;
    color: var(--main-color); /* Emojis/Text take color */
    opacity: 0;
    pointer-events: none;
    z-index: 0;
    font-size: 20px; /* Default size for chars */
    user-select: none;
}
/* No longer using border-radius circles, using text */
@keyframes starPulse {
    0%, 100% { opacity: 0; transform: scale(0.5) rotate(0deg); }
    50% { opacity: 0.6; transform: scale(1.2) rotate(20deg); }
}

/* --- UI LAYOUT --- */
/* --- UI LAYERS --- */
.ui-layer {
    /* Base layer for the Game UI */
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-sizing: border-box; /* Ensures padding doesn't mess up the width */
    /* Use the phone's safe area OR 30px, whichever is bigger */
    padding-top: max(30px, env(safe-area-inset-top));
}

/* NEW: Dedicated class for Start/Win/Resume screens */
/* This fixes the "funky black box" issue by locking it to the viewport */
.fullscreen-overlay {
    position: fixed; /* Locks to screen, ignores scrolling */
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100vh; /* Fallback */
    height: 100dvh; /* Mobile viewport fix */
    background: rgba(0, 0, 0, 0.92); /* Dark, sleek background */
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    text-align: center;
    padding: 20px;
    box-sizing: border-box;

    /* --- THE FIX --- */
    box-sizing: border-box;
    padding: 20px;
    /* Add extra space at the top so it never hits the clock */
    padding-top: max(40px, env(safe-area-inset-top));
}

/* Make the title big and nice */
.overlay-title {
    font-size: 2.5rem;
    font-weight: 900;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: white;
    text-shadow: 0 0 20px var(--main-color);
}
/* Header Area */
.ui-top {
    padding: 15px 20px;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* Never shrink header */
}

.progress-track {
    width: 100px; height: 6px;
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
    overflow: hidden;
}
#progress-fill {
    height: 100%;
    background: var(--main-color);
    width: 0%;
    transition: width 0.5s ease;
    box-shadow: 0 0 10px var(--main-color);
}

#sub-message-container {
    text-align: center;
    padding: 5px;
    font-size: 0.9rem;
    opacity: 0.8;
    flex-shrink: 0;
}

/* --- MAIN CONTENT AREA (The Fix) --- */
.stage-content {
    flex: 1; /* Take remaining space */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* Center vertically */
    width: 100%;
    position: relative;
    overflow: hidden; /* Keep content inside */
}

/* --- CAMERA STYLES --- */
/* Ensure the wrapper allows absolute positioning inside it */
.video-wrapper {
    position: relative; /* Critical for overlay positioning */
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    max-height: 65vh; 
}

/* FIX: Force overlay to sit ON TOP of the video */
#overlay-img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); /* Center it perfectly */
    width: 100%; 
    height: 100%;
    max-width: 90%; /* Must match #video max-width */
    max-height: 60vh; /* Must match #video max-height */
    object-fit: contain; /* Keep aspect ratio */
    opacity: 0.6; /* See-through */
    pointer-events: none; /* Let clicks pass through to video */
    z-index: 10;
    display: none; /* Hidden by default */
}

/* Ensure Square Mode overlay matches square video */
.mode-square #overlay-img {
    aspect-ratio: 1 / 1;
    width: auto;
}

#video, #canvas {
    max-width: 90%;
    max-height: 60vh; /* Critical fix for scrolling */
    border: 3px solid var(--main-color);
    border-radius: 20px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    background: #000;
    object-fit: cover;
}

/* Shape Modes */
.mode-square #video, .mode-square #canvas { aspect-ratio: 1/1; width: auto; height: auto; }
.mode-full #video, .mode-full #canvas { width: 90%; height: 60vh; }

.mirrored { transform: scaleX(-1); }

/* --- CONTROLS --- */
#camera-controls {
    margin-top: 20px;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 20px;
    z-index: 20;
    padding-bottom: 20px; /* Safe area */
    flex-shrink: 0;
}

button {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255,255,255,0.4);
    color: white;
    padding: 12px 24px;
    border-radius: 50px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: transform 0.1s;
    font-family: var(--main-font);
}
button:active { transform: scale(0.95); }

/* Specific Buttons */
#btn-snap {
    width: 70px; height: 70px;
    border-radius: 50%;
    border: 4px solid white;
    background: rgba(255,255,255,0.2);
}
.icon-btn {
    width: 50px; height: 50px;
    padding: 0; border-radius: 50%;
    font-size: 20px;
}

/* --- INPUT CARDS --- */
.card {
    background: rgba(255,255,255,0.1);
    padding: 30px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.2);
    text-align: center;
    width: 80%;
    max-width: 300px;
}
input[type="text"] {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: none;
    margin-bottom: 15px;
    text-align: center;
    font-size: 1.1rem;
    box-sizing: border-box;
}

/* --- SPINNER & OVERLAYS --- */
#loading-spinner {
    position: fixed; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 40px; height: 40px;
    border: 4px solid rgba(255,255,255,0.1);
    border-top: 4px solid var(--main-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 200;
    display: none;
}
@keyframes spin { to { transform: translate(-50%,-50%) rotate(360deg); } }

#feedback-overlay {
    position: fixed; top: 20%; left: 0; width: 100%;
    pointer-events: none; z-index: 150;
    display: flex; justify-content: center;
}
#feedback-text {
    background: rgba(255,255,255,0.95);
    color: #000;
    padding: 10px 25px;
    border-radius: 30px;
    font-weight: bold;
    opacity: 0; transition: opacity 0.3s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}


/* --- EXISTING CSS ABOVE --- */

/* NEW TIMER STYLE */
#countdown-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 6rem;
    font-weight: 900;
    color: white;
    text-shadow: 0 0 20px rgba(0,0,0,0.8);
    pointer-events: none;
    display: none;
    z-index: 50;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Fix Input Field on Start Screen */
#journey-code:focus {
    outline: 2px solid var(--main-color);
    background: white;
    color: black;
}

/* Ensure Grid Stage handles scrolling if image is tall */
#grid-stage {
    justify-content: flex-start; /* Start from top */
    padding-top: 40px;
    overflow-y: auto;
}
