:root {
    --primary: #ff6b6b;
    --primary-light: #ffa8a8;
    --secondary: #4dabf7;
    --accent-yellow: #ffd43b;
    --accent-green: #51cf66;
    --accent-purple: #cc5de8;
    --accent-orange: #ff922b;
    
    --bg-gradient-start: #e7f5ff;
    --bg-gradient-end: #fff4e6;
    
    --card-bg: rgba(255, 255, 255, 0.94);
    --card-border: rgba(255, 255, 255, 0.8);
    --card-shadow: 0 10px 25px -5px rgba(50, 50, 93, 0.15), 0 6px 12px -5px rgba(0, 0, 0, 0.1);
    
    --slot-bg: #f1f3f5;
    --slot-border: #ced4da;
    --slot-matched-bg: #ebfbee;
    --slot-matched-border: #51cf66;
    
    --text-main: #2b2c34;
    --text-muted: #6c757d;
    --font-heading: 'Fredoka', cursive, sans-serif;
    --font-body: 'Nunito', sans-serif;
    
    --radius-sm: 12px;
    --radius-md: 20px;
    --radius-lg: 28px;
    --radius-pill: 9999px;
}

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

html, body {
    width: 100%; height: 100%; overflow-x: hidden;
    font-family: var(--font-body); color: var(--text-main);
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    background-attachment: fixed;
}

/* Background animated decorative sky */
.sky-background { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 0; overflow: hidden; }
.cloud { position: absolute; background: rgba(255, 255, 255, 0.65); border-radius: var(--radius-pill); }
.cloud-1 { width: 220px; height: 60px; top: 8%; left: -50px; animation: floatCloud1 45s linear infinite; }
.cloud-2 { width: 280px; height: 75px; top: 35%; right: -100px; animation: floatCloud2 55s linear infinite; }
.cloud-3 { width: 180px; height: 50px; bottom: 15%; left: 10%; animation: floatCloud1 65s linear infinite; }
.floating-shape { position: absolute; opacity: 0.15; animation: slowSpin 25s linear infinite; }
.float-1 { top: 15%; right: 12%; width: 70px; height: 70px; border: 8px solid var(--accent-purple); border-radius: 50%; }
.float-2 { top: 60%; left: 8%; width: 60px; height: 60px; background: var(--accent-yellow); clip-path: polygon(50% 0%, 0% 100%, 100% 100%); }
.float-3 { bottom: 8%; right: 18%; width: 55px; height: 55px; background: var(--accent-green); border-radius: 14px; transform: rotate(25deg); }
.float-4 { top: 42%; left: 3%; width: 50px; height: 50px; background: var(--primary); clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }

@keyframes floatCloud1 { 0% { transform: translateX(0); } 100% { transform: translateX(calc(100vw + 300px)); } }
@keyframes floatCloud2 { 0% { transform: translateX(0); } 100% { transform: translateX(calc(-100vw - 300px)); } }
@keyframes slowSpin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

#confetti-canvas { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 100; }

.game-wrapper {
    position: relative; z-index: 1; display: flex; flex-direction: column;
    min-height: 100vh; max-width: 1060px; margin: 0 auto; padding: 16px 20px 24px;
}

/* Header */
.game-header {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 12px 18px; background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(14px); border-radius: var(--radius-lg); border: 2px solid var(--card-border);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
}
.header-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 52px; height: 52px; padding: 0;
    font-family: var(--font-heading); font-size: 1.5rem; font-weight: 700;
    color: var(--text-main); text-decoration: none; background: #fff;
    border: 2px solid #e9ecef; border-radius: var(--radius-pill); cursor: pointer;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05); transition: all 0.2s;
}
.header-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(0, 0, 0, 0.1); }
.back-btn { background: linear-gradient(135deg, #f8f9fa, #e9ecef); }
.header-center { display: flex; flex-direction: column; align-items: center; text-align: center; }
.game-title { margin: 0; font-size: 2.2rem; line-height: 1; color: #2b2c34; display: flex; align-items: center; justify-content: center; gap: 6px; }
.round-badge { min-width: 28px; text-align: center; font-family: var(--font-heading); font-size: 0.9rem; color: #fff; background: var(--secondary); padding: 3px 10px; border-radius: var(--radius-pill); }
.header-controls { display: flex; gap: 10px; }
.toggle-btn { width: 52px; height: 52px; padding: 0; }
.toggle-pill { display: none; }
.toggle-btn.active { border-color: #74c0fc; background: #e7f5ff; }

/* Screens */
.screen { display: none; flex-direction: column; flex: 1; align-items: center; justify-content: center; gap: 20px; animation: fadeIn 0.4s ease; }
.screen.active { display: flex; }
.screen[hidden] { display: none !important; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Start */
.start-card {
    background: var(--card-bg); backdrop-filter: blur(12px); border: 3px solid var(--card-border);
    border-radius: var(--radius-lg); padding: 40px; box-shadow: var(--card-shadow);
    text-align: center; width: 100%; max-width: 600px;
}
.start-stars { font-size: 2.5rem; letter-spacing: 6px; margin-bottom: 16px; }
.start-title { font-size: 3rem; line-height: 1; color: var(--primary); margin-bottom: 18px; }
.start-subtext, .instruction-text, .silhouette-label, .object-label, .celebration-subtext { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Main Game Board */
.instruction-banner { text-align: center; margin: 10px 0; }
.instruction-text {
    display: inline-block; font-size: 0.8rem; letter-spacing: 0.18em; font-weight: 900;
    color: #343a40; background: rgba(255, 255, 255, 0.9); padding: 10px 18px; border-radius: var(--radius-pill);
    border: 2px dashed #b197fc; text-transform: uppercase;
}

.silhouettes-section, .objects-tray-section {
    background: var(--card-bg); backdrop-filter: blur(12px); border: 3px solid var(--card-border);
    border-radius: var(--radius-lg); box-shadow: var(--card-shadow); padding: 20px; width: 100%;
}
.objects-tray-section.single-item {
    display: flex; justify-content: center; align-items: center; min-height: 220px;
}
.silhouettes-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; justify-items: center;
}
.silhouette-slot {
    width: 100%; max-width: 180px; height: 160px; background: var(--slot-bg);
    border: 3px dashed var(--slot-border); border-radius: var(--radius-md);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transition: all 0.2s; position: relative;
}
.silhouette-slot.drag-over { transform: scale(1.05); background: #e7f5ff; border-color: #339af0; }
.silhouette-slot.matched { border-style: solid; border-color: var(--slot-matched-border); background: var(--slot-matched-bg); }

.silhouette-outline-svg { width: 90px; height: 90px; pointer-events: none; }
.silhouette-slot.matched .silhouette-outline-svg { display: none; }
.silhouette-label { display: none; }

.slot-matched-content { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100%; animation: popIn 0.4s; }
.slot-matched-content svg { width: 90px; height: 90px; filter: drop-shadow(0 6px 12px rgba(0,0,0,0.12)); }
.slot-matched-badge { position: absolute; top: -10px; right: -10px; width: 28px; height: 28px; background: #51cf66; color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; border: 3px solid #fff; font-size: 1rem; }
@keyframes popIn { 0% { transform: scale(0.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.draggable-card {
    position: relative; width: 180px; height: 160px; background: #fff; border-radius: var(--radius-md);
    border: 3px solid #f1f3f5; box-shadow: 0 8px 18px rgba(0,0,0,0.08); display: flex; flex-direction: column;
    align-items: center; justify-content: center; cursor: grab; touch-action: none;
    transition: transform 0.2s, box-shadow 0.2s; will-change: transform;
}
.draggable-card:hover:not(.dragging):not(.locked) { transform: translateY(-5px); border-color: #d0ebff; box-shadow: 0 14px 26px rgba(0,0,0,0.12); }
.draggable-card.dragging { cursor: grabbing; z-index: 1000 !important; transform: scale(1.12) rotate(3deg); border-color: #339af0; transition: none !important; }
.draggable-card.returning { transition: transform 0.35s !important; }
.draggable-card.locked { pointer-events: none; }
.object-svg { width: 90px; height: 90px; pointer-events: none; transition: transform 0.2s; }
.object-label { display: none; }

/* Celebration */
#screen-celebration {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.45); backdrop-filter: blur(8px);
    z-index: 200; display: flex;
}
.celebration-card { background: #fff; border-radius: var(--radius-lg); padding: 40px; text-align: center; width: 90%; max-width: 440px; box-shadow: 0 24px 48px rgba(0,0,0,0.25); border: 4px solid var(--accent-yellow); transform: scale(0.8); animation: celebratePop 0.4s forwards; }
@keyframes celebratePop { to { transform: scale(1); } }
.celebration-stars { font-size: 2.5rem; letter-spacing: 6px; margin-bottom: 12px; animation: starsBounce 0.8s ease infinite alternate; }
@keyframes starsBounce { to { transform: translateY(-8px); } }
.celebration-title { font-size: 3rem; line-height: 1; color: #ff6b6b; margin-bottom: 22px; }
.celebration-subtext { display: none; }

.celebration-buttons { display: flex; flex-direction: column; gap: 12px; }
.action-btn { min-width: 84px; min-height: 84px; padding: 0; font-family: var(--font-heading); font-size: 2rem; border-radius: 28px; cursor: pointer; transition: all 0.2s; border: none; }
.action-btn.primary { background: linear-gradient(135deg, #51cf66, #2b8a3e); color: #fff; box-shadow: 0 8px 20px rgba(81,207,102,0.4); }
.action-btn.primary:hover { transform: translateY(-3px); }
.action-btn.secondary { background: #fff; border: 2px solid #ced4da; color: #495057; }
.action-btn.secondary:hover { background: #f8f9fa; border-color: #adb5bd; }

@media (max-width: 768px) {
    .silhouettes-grid { grid-template-columns: repeat(3, 1fr); }
    .silhouette-slot { height: 130px; }
    .silhouette-outline-svg, .object-svg, .slot-matched-content svg { width: 70px; height: 70px; }
    .objects-tray-section.single-item { min-height: 180px; }
}
@media (max-width: 480px) {
    .silhouettes-grid { grid-template-columns: repeat(2, 1fr); }
}
