/* ═══════════════════════════════════════════════════
   BUILD & BURN THE FALLAS — COMPLETE STYLESHEET
   Festival-inspired dark theme with fire colors
   Right-side puzzle tray layout
   ═══════════════════════════════════════════════════ */

/* ── RESET & BASE ── */
*, *::before, *::after {
    margin: 0; padding: 0; box-sizing: border-box;
}
html, body {
    width: 100%; height: 100%; overflow: hidden;
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: #111122;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
    cursor: default;
}

.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════
   LOADING SCREEN
   ═══════════════════════════════════════════════════ */
#loadingScreen {
    position: fixed; inset: 0; z-index: 9999;
    background: linear-gradient(160deg, #FFF8E1 0%, #FFECB3 50%, #FFF3E0 100%);
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.6s ease;
}
#loadingScreen.fade-out { opacity: 0; pointer-events: none; }
.loader-content { text-align: center; }
.loader-emoji { font-size: 4rem; animation: pulse 1.5s ease-in-out infinite; display: flex; justify-content: center; }
.loader-title {
    font-size: 1.8rem; font-weight: 900; margin: 15px 0 5px;
    background: linear-gradient(135deg, #FF6B35, #FFD700, #FF4444);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.loader-sub { font-size: 0.9rem; color: #888; }
.loader-sub .en-sub { color: #aaa; }
.loader-bar {
    width: 200px; height: 4px; margin: 20px auto 0;
    background: rgba(0,0,0,0.06); border-radius: 2px;
    overflow: hidden;
}
.loader-fill {
    width: 0%; height: 100%;
    background: linear-gradient(90deg, #FF6B35, #FFD700);
    border-radius: 2px;
    animation: loadFill 2s ease-out forwards;
}
@keyframes loadFill { to { width: 100%; } }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); } }

/* ═══════════════════════════════════════════════════
   START SCREEN
   ═══════════════════════════════════════════════════ */
#startScreen {
    position: fixed; inset: 0; z-index: 1000;
    background: linear-gradient(160deg, #FFF8E1 0%, #FFECB3 40%, #FFF3E0 100%);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.start-content { text-align: center; max-width: 500px; }
.start-emoji { display: flex; gap: 8px; justify-content: center; margin-bottom: 15px; }
.start-title {
    font-size: clamp(2rem, 6vw, 3rem); font-weight: 900;
    background: linear-gradient(135deg, #E65100, #FF8F00, #BF360C);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; line-height: 1.2; margin-bottom: 15px;
}
.start-desc {
    font-size: 1rem; color: #555;
    line-height: 1.6; margin-bottom: 8px;
}
.start-desc-en {
    font-size: 0.7rem; color: #aaa; font-style: italic;
    margin-bottom: 25px;
}
/* ── Small English subtitles ── */
.en-sub {
    font-size: 0.7rem; color: #aaa; font-style: italic;
    font-weight: 400;
}
.en-sub-screen {
    font-size: 0.75rem; color: rgba(255,255,255,0.4); font-style: italic;
    margin: -5px 0 10px;
}
.start-rules {
    text-align: left; margin-bottom: 30px;
    background: rgba(255,255,255,0.6); border: 1px solid rgba(255,152,0,0.1);
    border-radius: 16px; padding: 18px 20px;
}
.rule {
    display: flex; align-items: center; gap: 12px;
    padding: 8px 0; font-size: 0.85rem; font-weight: 700;
    color: #777;
}
.rule-icon { display: flex; align-items: center; flex-shrink: 0; }
.rule + .rule { border-top: 1px solid rgba(0,0,0,0.05); }

/* ── SHARED BUTTON STYLE ── */
.btn-fire {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 16px 40px; border: none; border-radius: 50px;
    font-size: 1.1rem; font-weight: 900; letter-spacing: 1px;
    background: linear-gradient(135deg, #FF6B35, #FFD700);
    color: #1a0a2e; cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 30px rgba(255,107,53,0.4);
}
.btn-fire:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 40px rgba(255,107,53,0.6);
}
.btn-fire:active { transform: scale(0.98); }

.btn-icon { flex-shrink: 0; }

.back-link {
    display: block; margin-top: 18px;
    color: #bbb; font-size: 0.8rem; font-weight: 700;
    text-decoration: none; transition: color 0.2s;
}
.back-link:hover { color: #E65100; }
#startScreen .back-link { color: #ccc; }
#startScreen .back-link:hover { color: #E65100; }

/* ═══════════════════════════════════════════════════
   HUD — TOP BAR
   ═══════════════════════════════════════════════════ */
#hud {
    position: fixed; top: 0; left: 0; right: 0; z-index: 500;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; height: 56px;
    background: rgba(10,10,26,0.9);
    backdrop-filter: blur(15px);
    border-bottom: 1px solid rgba(255,100,50,0.15);
}
.hud-item { display: flex; flex-direction: column; align-items: center; }
.hud-label {
    font-size: 0.6rem; font-weight: 800; letter-spacing: 2px;
    color: rgba(255,255,255,0.35);
    display: flex; align-items: center; gap: 4px;
}
.hud-icon { color: rgba(255,255,255,0.35); vertical-align: middle; }
.hud-value { font-size: 1.1rem; font-weight: 900; color: #FFD700; }
.hud-phase .hud-value { font-size: 0.8rem; color: #FF6B35; }

/* Timer bar */
#timerBar {
    position: fixed; top: 56px; left: 0; right: 0; z-index: 500;
    height: 4px; background: rgba(255,255,255,0.06);
}
#timerFill {
    height: 100%; width: 100%;
    background: linear-gradient(90deg, #FFD700, #FF6B35, #FF4444);
    transition: width 0.3s linear;
    border-radius: 0 2px 2px 0;
}
#timerFill.danger { background: linear-gradient(90deg, #FF4444, #FF0000); animation: timerPulse 0.5s ease infinite; }
@keyframes timerPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ═══════════════════════════════════════════════════
   THREE.JS CANVAS — shifted left to make room for tray
   ═══════════════════════════════════════════════════ */
#canvasContainer {
    position: fixed; top: 0; left: 0; bottom: 0;
    right: 0;
    z-index: 1;
}
#canvasContainer canvas {
    display: block; width: 100%; height: 100%;
}

/* ═══════════════════════════════════════════════════
   PUZZLE TRAY — Right-side vertical panel
   ═══════════════════════════════════════════════════ */
#puzzleTray {
    position: fixed; top: 60px; right: 0; bottom: 0; z-index: 200;
    width: 180px;
    padding: 12px 10px 20px;
    background: rgba(10,10,26,0.92);
    backdrop-filter: blur(15px);
    border-left: 1px solid rgba(255,100,50,0.15);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.tray-label {
    text-align: center; font-size: 0.65rem; font-weight: 800;
    color: rgba(255,255,255,0.3); letter-spacing: 1.5px; margin-bottom: 10px;
    display: flex; align-items: center; justify-content: center; gap: 6px;
}
.tray-icon { color: rgba(255,255,255,0.3); flex-shrink: 0; }
#trayPieces {
    display: flex; flex-direction: column; gap: 6px;
    align-items: center; flex: 1;
}
.puzzle-piece {
    width: 140px;
    height: 48px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    gap: 6px;
    font-weight: 900; cursor: grab;
    transition: all 0.25s ease;
    position: relative;
    border: 2px solid;
    -webkit-user-drag: none;
    touch-action: none;
    flex-shrink: 0;
}
.puzzle-piece:hover {
    transform: translateX(-4px) scale(1.05);
    z-index: 10;
}
.puzzle-piece:active { cursor: grabbing; }
.puzzle-piece.dragging {
    opacity: 0.85; transform: scale(1.12);
    z-index: 999; cursor: grabbing;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.puzzle-piece .piece-emoji { font-size: 1.2rem; pointer-events: none; display: flex; align-items: center; }
.puzzle-piece .piece-label {
    font-size: 0.5rem; letter-spacing: 1px;
    pointer-events: none; opacity: 0.7;
}
.puzzle-piece.placed {
    opacity: 0.3; pointer-events: none;
    transform: scale(0.85);
}

/* Piece color themes */
.piece-head   { background: rgba(255,200,150,0.15); border-color: rgba(255,200,150,0.4); color: #FFDAB9; }
.piece-hat    { background: rgba(255,60,60,0.15);   border-color: rgba(255,60,60,0.4);   color: #FF6B6B; }
.piece-body   { background: rgba(100,150,255,0.15); border-color: rgba(100,150,255,0.4); color: #8CB4FF; }
.piece-arm    { background: rgba(100,200,255,0.15); border-color: rgba(100,200,255,0.4); color: #80D8FF; }
.piece-leg    { background: rgba(100,150,255,0.15); border-color: rgba(100,150,255,0.4); color: #82B1FF; }
.piece-base   { background: rgba(180,130,80,0.15);  border-color: rgba(180,130,80,0.4);  color: #D4A574; }
.piece-hand   { background: rgba(255,220,180,0.15); border-color: rgba(255,220,180,0.4); color: #FFE0B2; }
.piece-eye    { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.3); color: #E0E0E0; }
.piece-mouth  { background: rgba(255,100,100,0.15); border-color: rgba(255,100,100,0.4); color: #FF8A80; }

/* ═══════════════════════════════════════════════════
   BURN UI — Phase 2 button
   ═══════════════════════════════════════════════════ */
#burnUI {
    position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%);
    z-index: 300; text-align: center;
}
.burn-text {
    font-size: 0.85rem; font-weight: 800;
    color: rgba(255,255,255,0.5); margin-bottom: 12px;
}
.btn-burn {
    font-size: 1.3rem; padding: 18px 50px;
    background: linear-gradient(135deg, #FF4444, #FF6B35, #FFD700);
    animation: burnGlow 1.5s ease-in-out infinite;
}
@keyframes burnGlow {
    0%, 100% { box-shadow: 0 8px 30px rgba(255,68,68,0.4); }
    50% { box-shadow: 0 8px 50px rgba(255,68,68,0.8), 0 0 80px rgba(255,107,53,0.3); }
}

/* ═══════════════════════════════════════════════════
   WIN SCREEN
   ═══════════════════════════════════════════════════ */
#winScreen {
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(255,248,225,0.97);
    backdrop-filter: blur(10px);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    animation: fadeIn 0.8s ease;
}
.win-content { text-align: center; max-width: 420px; }
.win-emoji { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; }
.win-title {
    font-size: 2rem; font-weight: 900;
    background: linear-gradient(135deg, #BF360C, #E65100);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; margin-bottom: 10px;
}
.win-rank {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 20px;
    border-radius: 30px; font-size: 0.85rem; font-weight: 900;
    letter-spacing: 2px; margin-bottom: 20px;
    background: linear-gradient(135deg, rgba(255,143,0,0.1), rgba(255,179,0,0.1));
    border: 1px solid rgba(255,143,0,0.3); color: #E65100;
}
.win-stats {
    display: flex; gap: 20px; justify-content: center; margin-bottom: 25px;
}
.win-stat {
    display: flex; flex-direction: column;
    background: rgba(255,255,255,0.7);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 14px; padding: 14px 24px;
}
.ws-label { font-size: 0.65rem; font-weight: 800; color: #bbb; letter-spacing: 2px; }
.ws-value { font-size: 1.5rem; font-weight: 900; color: #E65100; }

/* ═══════════════════════════════════════════════════
   LOSE SCREEN
   ═══════════════════════════════════════════════════ */
#loseScreen {
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(255,248,225,0.97);
    backdrop-filter: blur(10px);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    animation: fadeIn 0.8s ease;
}
.lose-content { text-align: center; max-width: 400px; }
.lose-emoji { display: flex; justify-content: center; margin-bottom: 10px; }
.lose-title {
    font-size: 2rem; font-weight: 900;
    color: #D32F2F; margin-bottom: 10px;
}
.lose-desc {
    font-size: 0.9rem; color: #999;
    margin-bottom: 25px; line-height: 1.6;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ═══════════════════════════════════════════════════
   PARTICLE CANVAS (fire & fireworks overlay)
   ═══════════════════════════════════════════════════ */
#particleCanvas {
    position: fixed; inset: 0; z-index: 400;
    pointer-events: none;
}

/* ═══════════════════════════════════════════════════
   TOAST NOTIFICATION
   ═══════════════════════════════════════════════════ */
.toast {
    position: fixed; top: 75px; left: 50%; transform: translateX(-50%) translateY(-20px);
    z-index: 600;
    padding: 10px 24px; border-radius: 30px;
    background: rgba(0,0,0,0.85); backdrop-filter: blur(10px);
    border: 1px solid rgba(255,215,0,0.3);
    font-size: 0.85rem; font-weight: 800; color: #FFD700;
    opacity: 0; transition: all 0.4s cubic-bezier(0.34,1.56,0.64,1);
    pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ═══════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════ */
@media (max-width: 600px) {
    #puzzleTray {
        width: 120px;
        padding: 8px 6px 16px;
    }
    .puzzle-piece {
        width: 100px;
        height: 40px;
    }
    .puzzle-piece .piece-emoji svg { width: 18px; height: 18px; }
    #hud { padding: 0 10px; height: 48px; }
    .hud-value { font-size: 0.95rem; }
    .btn-burn { font-size: 1rem; padding: 14px 30px; }
}

@media (max-width: 400px) {
    #puzzleTray { width: 100px; }
    .puzzle-piece { width: 85px; height: 36px; }
}
