* { margin: 0; padding: 0; box-sizing: border-box; }

body { 
    overflow: hidden; 
    background: radial-gradient(ellipse at bottom, #1B2838 0%, #090A0F 100%);
    font-family: 'Cinzel', 'Times New Roman', serif; 
    touch-action: none; 
    user-select: none;
    -webkit-user-select: none;
}

#canvas-container { 
    width: 100vw; height: 100vh; 
    position: fixed; top: 0; left: 0; z-index: 1; 
    cursor: grab; 
}
#canvas-container:active { cursor: grabbing; }

/* Loader */
#loader {
    position: fixed; inset: 0;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #0a0a0a 100%);
    z-index: 1000;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transition: opacity 1s ease-out;
}
.tree-icon { font-size: 80px; animation: bounce 1s ease infinite; }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-20px); } }
.spinner {
    width: 50px; height: 50px; margin: 20px;
    border: 2px solid rgba(212, 175, 55, 0.2); 
    border-top: 2px solid #d4af37; border-radius: 50%; 
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { color: #d4af37; font-size: 16px; letter-spacing: 3px; text-transform: uppercase; }

/* UI Layer */
#ui-layer {
    position: fixed; inset: 0;
    z-index: 10; pointer-events: none;
    display: flex; flex-direction: column; align-items: center;
    padding-top: 30px;
}

.ui-hidden { opacity: 0 !important; pointer-events: none !important; }

#main-title { 
    font-family: 'Great Vibes', cursive;
    color: #fceea7; font-size: clamp(40px, 10vw, 72px); 
    font-weight: 400; letter-spacing: 4px; 
    text-shadow: 0 0 60px rgba(252, 238, 167, 0.8), 0 0 120px rgba(255, 200, 100, 0.4);
    background: linear-gradient(180deg, #fff 0%, #ffd700 50%, #ff8c00 100%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    animation: glow 3s ease-in-out infinite alternate;
}
@keyframes glow {
    from { filter: drop-shadow(0 0 20px rgba(255, 215, 0, 0.5)); }
    to { filter: drop-shadow(0 0 40px rgba(255, 215, 0, 0.8)); }
}

#subtitle {
    color: rgba(255, 255, 255, 0.7); font-size: 18px; letter-spacing: 8px;
    margin-top: -5px; font-family: 'Cinzel', serif;
}

/* Controls */
.controls-wrapper {
    position: absolute; top: 100px; right: 20px;        
    pointer-events: auto;
    display: flex; flex-direction: column; align-items: flex-end;
    gap: 10px; z-index: 20;
}

.btn-group { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }

.control-btn {
    background: rgba(10, 10, 20, 0.7); 
    border: 1px solid rgba(212, 175, 55, 0.5); 
    color: #d4af37; padding: 12px 20px; 
    cursor: pointer; text-transform: uppercase; 
    letter-spacing: 2px; font-size: 11px;
    transition: all 0.3s ease;
    display: flex; align-items: center; gap: 8px;
    backdrop-filter: blur(10px); 
    border-radius: 8px;
    min-width: 130px;
}
.control-btn:hover, .control-btn.active { 
    background: linear-gradient(135deg, #d4af37 0%, #f0c850 100%); 
    color: #000; 
    box-shadow: 0 0 30px rgba(212, 175, 55, 0.6);
    transform: translateX(-5px);
}
.control-btn i { width: 16px; text-align: center; }
input[type="file"] { display: none; }

.hint-text {
    color: rgba(212, 175, 55, 0.6); font-size: 10px;
    letter-spacing: 1px; text-align: right; max-width: 200px;
    line-height: 1.5;
}

/* Mode Buttons */
#mode-bar {
    position: absolute; bottom: 30px; left: 50%;
    transform: translateX(-50%);
    display: flex; gap: 15px;
    z-index: 20; pointer-events: auto;
}
.mode-btn {
    width: 55px; height: 55px; border-radius: 50%;
    background: rgba(0,0,0,0.6);
    border: 2px solid rgba(212, 175, 55, 0.5);
    color: #d4af37; font-size: 22px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.3s;
    backdrop-filter: blur(10px);
}
.mode-btn:hover { 
    transform: scale(1.1); 
    border-color: #d4af37;
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.5);
}
.mode-btn:active, .mode-btn.active { 
    transform: scale(0.95); 
    background: linear-gradient(135deg, #d4af37, #f0c850); 
}

/* Webcam */
#webcam-wrapper {
    position: fixed; bottom: 100px; left: 20px;         
    width: 160px; height: 120px;
    border: 1px solid rgba(212, 175, 55, 0.5); 
    box-shadow: 0 0 30px rgba(0,0,0,0.8);
    border-radius: 10px; overflow: hidden; 
    opacity: 0; pointer-events: none;
    z-index: 50; background: #000;
    transition: opacity 0.5s ease; 
}
#webcam { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }

#debug-info {
    position: fixed; bottom: 10px; left: 50%;
    transform: translateX(-50%);
    color: rgba(212, 175, 55, 0.5); font-size: 11px;
    font-family: monospace; pointer-events: none; z-index: 51;
    text-align: center; letter-spacing: 1px;
}

/* Message Box */
#msg-box {
    position: fixed; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid #d4af37;
    padding: 25px 40px; color: #d4af37;
    z-index: 200; text-align: center;
    display: none; border-radius: 15px;
    backdrop-filter: blur(20px);
    box-shadow: 0 0 50px rgba(212, 175, 55, 0.3);
}

/* Stats Dashboard */
#footer-stats {
    position: absolute; bottom: 25px; right: 25px;
    z-index: 40; pointer-events: auto;
    display: flex; flex-direction: column; gap: 12px;
    background: rgba(8, 15, 25, 0.8);
    backdrop-filter: blur(15px);
    padding: 18px;
    border-radius: 15px;
    border: 1px solid rgba(212, 175, 55, 0.3);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
    width: 180px;
    transition: all 0.4s ease;
}
.stats-title {
    color: rgba(212, 175, 55, 0.9);
    font-size: 10px; letter-spacing: 2px;
    text-align: center; padding-bottom: 8px;
    border-bottom: 1px solid rgba(212, 175, 55, 0.2);
}
.stats-row { display: flex; justify-content: space-around; }
.stats-item { display: flex; align-items: center; gap: 8px; }
.stats-value { color: #fff; font-weight: bold; font-size: 16px; text-shadow: 0 0 10px rgba(255,255,255,0.3); }

/* Responsive */
@media (max-width: 768px) {
    .controls-wrapper { top: 80px; right: 10px; }
    .control-btn { padding: 10px 15px; font-size: 10px; min-width: 110px; }
    #mode-bar { bottom: 20px; gap: 10px; }
    .mode-btn { width: 48px; height: 48px; font-size: 20px; }
    #webcam-wrapper { width: 120px; height: 90px; bottom: 80px; left: 10px; }
    #footer-stats { bottom: 15px; right: 15px; width: 160px; padding: 12px; }
}

/* Snowflakes CSS Animation (fallback) */
.snowflake {
    position: fixed;
    color: #fff;
    font-size: 1em;
    top: -20px;
    z-index: 5;
    animation: fall linear infinite;
    pointer-events: none;
    opacity: 0.8;
}
@keyframes fall {
    to { transform: translateY(100vh) rotate(360deg); }
}