* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Comic Sans MS', cursive, sans-serif;
}

body {
    position: relative;
    background:
        radial-gradient(circle at 8% 12%, rgba(255, 214, 102, 0.96) 0 8%, transparent 9%),
        radial-gradient(circle at 90% 18%, rgba(96, 165, 250, 0.9) 0 9%, transparent 10%),
        radial-gradient(circle at 20% 82%, rgba(244, 114, 182, 0.9) 0 9%, transparent 10%),
        radial-gradient(circle at 85% 84%, rgba(52, 211, 153, 0.9) 0 9%, transparent 10%),
        linear-gradient(145deg, #fef3c7 0%, #f9a8d4 34%, #bfdbfe 68%, #bbf7d0 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    overflow-x: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="160" height="160" viewBox="0 0 160 160"><g fill="rgba(255,255,255,0.18)"><circle cx="28" cy="30" r="18"/><circle cx="122" cy="48" r="20"/><circle cx="54" cy="112" r="16"/><circle cx="112" cy="118" r="15"/></g></svg>');
    background-repeat: repeat;
    opacity: 0.8;
}

.game-container {
    position: relative;
    z-index: 1;
    background: linear-gradient(145deg, rgba(255,255,255,0.96), rgba(254,243,199,0.95));
    padding: 25px;
    border-radius: 20px;
    box-shadow: 0 12px 28px rgba(30,41,59,0.15);
    max-width: 1100px;
    width: 100%;
    text-align: center;
    border: 4px solid rgba(255,255,255,0.8);
}

.top-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.title-block {
    flex: 1;
    text-align: center;
}

.rainbow-title {
    margin-bottom: 5px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.02em;
    text-shadow: 2px 2px 0 rgba(255,255,255,0.8);
}

.rainbow-title span {
    display: inline-block;
}

.rainbow-title .title-space {
    width: 0.7em;
    min-width: 0.7em;
}

.rainbow-title span:nth-child(1) { color: #f59e0b; }
.rainbow-title span:nth-child(2) { color: #ef4444; }
.rainbow-title span:nth-child(3) { color: #f97316; }
.rainbow-title span:nth-child(4) { color: #facc15; }
.rainbow-title span:nth-child(5) { color: #22c55e; }
.rainbow-title span:nth-child(6) { color: #14b8a6; }
.rainbow-title span:nth-child(7) { color: #3b82f6; }
.rainbow-title span:nth-child(8) { color: #dc2626; }
.rainbow-title span:nth-child(9) { color: #f59e0b; }
.rainbow-title span:nth-child(10) { color: #ef4444; }
.rainbow-title span:nth-child(11) { color: #8b5cf6; }
.rainbow-title span:nth-child(12) { color: #f97316; }
.rainbow-title span:nth-child(13) { color: #22c55e; }
.rainbow-title span:nth-child(14) { color: #3b82f6; }
.rainbow-title span:nth-child(15) { color: #facc15; }
.rainbow-title span:nth-child(16) { color: #ef4444; }
.rainbow-title span:nth-child(17) { color: #8b5cf6; }
.rainbow-title span:nth-child(18) { color: #f59e0b; }
.rainbow-title span:nth-child(19) { color: #22c55e; }
.rainbow-title span:nth-child(20) { color: #14b8a6; }
.rainbow-title span:nth-child(21) { color: #3b82f6; }
.rainbow-title span:nth-child(22) { color: #ec4899; }
.rainbow-title span:nth-child(23) { color: #f97316; }

.rainbow-subtitle {
    margin-bottom: 15px;
    font-size: 0.95rem;
    font-weight: 700;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.06em;
}

.rainbow-subtitle {
    background: linear-gradient(90deg, #1d4ed8, #d97706, #be185d, #15803d, #7c3aed);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.top-header::before,
.top-header::after {
    content: "🎲";
    font-size: 1.8rem;
    opacity: 0.8;
    animation: toyBounce 3s ease-in-out infinite;
}

.top-header::after {
    content: "🧩";
    animation-delay: 1s;
}

@keyframes toyBounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-8px) rotate(8deg); }
}

.exit-btn {
    display: inline-block;
    background: linear-gradient(135deg, #ef4444, #f97316);
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    border-radius: 999px;
    padding: 10px 18px;
    box-shadow: 0 8px 18px rgba(239, 68, 68, 0.22);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.exit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(239, 68, 68, 0.3);
}

.hidden {
    display: none !important;
}

/* Gallery Screen Styles */
.gallery-screen {
    position: relative;
    border-radius: 18px;
    padding: 18px 14px 10px;
    background:
        linear-gradient(135deg, rgba(255,255,255,0.72), rgba(255,255,255,0.38)),
        url('assets/1-the forest.png') center/35% no-repeat,
        url('assets/2-rabbits.png') top right/30% no-repeat,
        url('assets/4-circus.png') bottom left/28% no-repeat;
    background-blend-mode: screen, normal, normal, normal;
    border: 3px solid rgba(190, 242, 100, 0.9);
    box-shadow: inset 0 0 0 2px rgba(255,255,255,0.5);
}

.gallery-3d-title {
    margin-bottom: 15px;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.04em;
    line-height: 1.1;
    font-size: clamp(1.8rem, 2.4vw, 2.6rem);
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: none;
    text-shadow:
        0 1px 0 #fff,
        0 2px 0 #f0f0f0,
        0 3px 0 #d9d9d9,
        0 4px 0 #c7c7c7,
        0 5px 0 #b5b5b5,
        0 7px 12px rgba(38, 38, 38, 0.25);
}

.gallery-3d-title span {
    display: inline-block;
    transform: translateY(-1px);
}

.gallery-3d-title span:nth-child(1) { color: #1d4ed8; }
.gallery-3d-title span:nth-child(2) { color: #7c2d12; }
.gallery-3d-title span:nth-child(3) { color: #b45309; }
.gallery-3d-title span:nth-child(4) { color: #166534; }
.gallery-3d-title span:nth-child(5) { color: #dc2626; }
.gallery-3d-title span:nth-child(6) { color: #7c3aed; }
.gallery-3d-title span:nth-child(7) { color: #991b1b; }
.gallery-3d-title span:nth-child(8) { color: #dc2626; }
.gallery-3d-title span:nth-child(9) { color: #0f766e; }
.gallery-3d-title span:nth-child(10) { color: #1d4ed8; }
.gallery-3d-title span:nth-child(11) { color: #7c2d12; }
.gallery-3d-title span:nth-child(12) { color: #dc2626; }
.gallery-3d-title span:nth-child(13) { color: #166534; }
.gallery-3d-title span:nth-child(14) { color: #b45309; }
.gallery-3d-title span:nth-child(15) { color: #7c3aed; }
.gallery-3d-title span:nth-child(16) { color: #991b1b; }
.gallery-3d-title span:nth-child(17) { color: #1d4ed8; }
.gallery-3d-title span:nth-child(18) { color: #0f766e; }

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 15px;
    padding: 10px;
}

.gallery-thumb {
    aspect-ratio: 1;
    background-size: cover;
    background-position: center;
    border: 4px solid #bef264;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    overflow: hidden;
}

.gallery-thumb:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 15px rgba(0,0,0,0.15);
    border-color: #65a30d;
}

.difficulty-badge {
    background: rgba(101, 163, 13, 0.9);
    color: #000;
    font-size: 0.8rem;
    padding: 3px 8px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-weight: bold;
}

/* Game Screen Layout */
.game-layout {
    display: flex;
    gap: 20px;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.reference-panel {
    width: 260px;
    background: linear-gradient(135deg, #fef9c3 0%, #f9a8d4 100%);
    border: 3px solid #bef264;
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 8px 18px rgba(0,0,0,0.08);
}

.reference-panel h3 {
    margin-bottom: 8px;
    font-size: 1rem;
    background: linear-gradient(90deg, #0f766e, #1d4ed8, #7c2d12);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.reference-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid #65a30d;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

.puzzle-board {
    width: 500px;
    height: 500px;
    background: linear-gradient(135deg, #dcfce7 0%, #dbeafe 100%);
    border: 3px solid #bef264;
    border-radius: 8px;
    padding: 0;
    display: grid;
    gap: 0;
    background-size: 500px 500px;
    background-position: center;
    background-repeat: no-repeat;
    background-origin: content-box;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,0.5);
}

.drop-slot {
    background-color: transparent;
    border: 1px dashed rgba(77, 124, 15, 0.55);
    width: 100%;
    height: 100%;
}

.drop-slot.correct {
    border: 1px dashed rgba(77, 124, 15, 0.55);
    background-color: transparent;
}

.pieces-tray {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    background: linear-gradient(135deg, #fef3c7 0%, #dbeafe 100%);
    padding: 10px;
    border-radius: 8px;
    width: 480px;
    height: 500px;
    overflow-y: auto;
    border: 3px solid #bef264;
    align-content: start;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,0.5);
}

.puzzle-piece {
    width: 100%;
    background-size: 500px 500px;
    cursor: grab;
    border-radius: 2px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.puzzle-piece:active {
    cursor: grabbing;
}

/* Footer Controls */
.score-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.1rem;
    font-weight: bold;
    color: #333;
    padding: 0 10px;
}

.control-btn {
    background: #ef4444;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.control-btn:hover {
    background: #dc2626;
}

.hub-link {
    background: #65a30d;
    color: white;
    padding: 8px 14px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.hub-link:hover {
    background: #4d7c0f;
}