* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Avenir Next Rounded', 'Avenir Next', 'Nunito', 'Helvetica Rounded', 'Trebuchet MS', 'Arial Rounded MT Bold', 'Comic Sans MS', system-ui, -apple-system, sans-serif;
    background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.game-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    width: 100%;
    height: 100vh;
}

.puzzle-board {
    position: relative;
    width: 800px;
    height: 640px;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.background-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

.puzzles-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(6, 1fr);
    z-index: 2;
}

.puzzle-piece {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: default;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.puzzle-piece::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 50%);
    pointer-events: none;
}

.puzzle-piece.current {
    background: linear-gradient(135deg, #f6ad55 0%, #ed8936 100%);
    animation: pulse 1s infinite;
    z-index: 10;
    box-shadow: 0 0 20px rgba(246, 173, 85, 0.6);
    border: 2px solid #fff;
}

.puzzle-piece.uncovered {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8) rotateY(90deg);
}

.puzzle-piece.wrong {
    animation: shake 0.4s ease;
    background: linear-gradient(135deg, #fc8181 0%, #e53e3e 100%);
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes uncoverPiece {
    0% { 
        opacity: 1; 
        transform: scale(1) rotateY(0deg);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.1) rotateY(45deg);
    }
    100% { 
        opacity: 0; 
        transform: scale(0.8) rotateY(90deg);
    }
}

.puzzle-piece.uncover-animation {
    animation: uncoverPiece 0.4s ease forwards;
}

/* Progress Indicator */
.progress-indicator {
    position: fixed;
    top: 20px;
    left: 20px;
    background: #4ECDC4;
    color: white;
    padding: 15px 25px;
    border-radius: 20px;
    font-size: 20px;
    box-shadow: 0 4px 0 #3BA99C;
}

/* Current Key Display */
.current-key-display {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 15px 30px;
    border-radius: 25px;
    font-size: 24px;
    color: #333;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 15px;
}

.current-key {
    background: linear-gradient(135deg, #f6ad55 0%, #ed8936 100%);
    color: white;
    padding: 10px 20px;
    border-radius: 15px;
    font-size: 32px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    box-shadow: 0 4px 0 #c05621;
    min-width: 60px;
    text-align: center;
}

/* Home Button */
.home-button {
    position: fixed;
    top: 20px;
    right: 20px;
    background: linear-gradient(180deg, #FF6B6B 0%, #EE5A5A 100%);
    color: #fff;
    padding: 14px 22px;
    border-radius: 18px;
    font-size: 18px;
    border: none;
    cursor: pointer;
    box-shadow: 0 5px 0 #CC4444;
    transition: transform 0.1s, box-shadow 0.1s;
}

.home-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 0 #CC4444;
}

.home-button:active {
    transform: translateY(2px);
    box-shadow: 0 3px 0 #CC4444;
}

/* Sound Toggle */
.sound-toggle {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #FFE66D;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 4px 0 #F4A261;
}

/* Instructions */
.instructions {
    position: fixed;
    bottom: 30px;
    background: rgba(255, 255, 255, 0.9);
    padding: 15px 30px;
    border-radius: 20px;
    font-size: 18px;
    color: #333;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

/* Celebration */
.celebration {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 72px;
    color: #FFE66D;
    text-shadow: 3px 3px 0 #FF6B6B;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    text-align: center;
}

.celebration.show {
    animation: celebrate 1s ease forwards;
}

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

/* Start Screen */
.start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    z-index: 2000;
    overflow-y: auto;
    padding: 20px;
    padding-top: 30px;
}

.start-screen h1 {
    font-size: 56px;
    color: #FFE66D;
    text-shadow: 4px 4px 0 #FF6B6B;
    margin-bottom: 10px;
}

.puzzle-icon {
    font-size: 80px;
    margin-bottom: 30px;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.start-btn {
    background: linear-gradient(180deg, #4ECDC4 0%, #44A08D 100%);
    color: white;
    border: none;
    padding: 20px 60px;
    font-size: 32px;
    font-family: inherit;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 6px 0 #2D7A6E;
    transition: transform 0.1s, box-shadow 0.1s;
    margin-top: 20px;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 #2D7A6E;
}

.start-btn:active {
    transform: translateY(2px);
    box-shadow: 0 4px 0 #2D7A6E;
}

.language-buttons {
    display: flex;
    gap: 20px;
    margin-top: 20px;
}

.lang-btn {
    background: linear-gradient(180deg, #FF6B6B 0%, #EE5A5A 100%);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 24px;
    font-family: inherit;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 5px 0 #CC4444;
    transition: transform 0.1s, box-shadow 0.1s;
}

.lang-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 0 #CC4444;
}

.lang-btn:active {
    transform: translateY(2px);
    box-shadow: 0 3px 0 #CC4444;
}

.lang-btn.polish {
    background: linear-gradient(180deg, #DC143C 0%, #B22222 100%);
    box-shadow: 0 5px 0 #8B0000;
}

.lang-btn.polish:hover {
    box-shadow: 0 7px 0 #8B0000;
}

.lang-btn.polish:active {
    box-shadow: 0 3px 0 #8B0000;
}

.lang-btn.english {
    background: linear-gradient(180deg, #3366CC 0%, #2255AA 100%);
    box-shadow: 0 5px 0 #1A4488;
}

.lang-btn.english:hover {
    box-shadow: 0 7px 0 #1A4488;
}

.lang-btn.english:active {
    box-shadow: 0 3px 0 #1A4488;
}

.lang-btn.active {
    transform: translateY(-3px);
    box-shadow: 0 8px 0 rgba(0, 0, 0, 0.28);
    outline: 3px solid rgba(255, 255, 255, 0.7);
}

/* Image Selection */
.image-selector-container {
    width: 100%;
    max-width: 500px;
    margin-top: 10px;
}

.image-buttons {
    display: flex;
    gap: 12px;
    padding: 15px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.5) rgba(0,0,0,0.1);
    background: rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    max-width: 500px;
}

.image-buttons::-webkit-scrollbar {
    height: 8px;
}

.image-buttons::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

.image-buttons::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 4px;
}

.image-buttons::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.7);
}

.image-btn {
    flex: 0 0 auto;
    width: 100px;
    height: 100px;
    border: 4px solid transparent;
    border-radius: 15px;
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    scroll-snap-align: center;
    position: relative;
}

.image-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-btn .random-icon {
    font-size: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: calc(100% - 22px);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.image-btn .image-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    font-size: 11px;
    padding: 4px 3px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.image-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
}

.image-btn.active {
    border-color: #FFE66D;
    transform: scale(1.08);
    box-shadow: 0 0 20px rgba(255, 230, 109, 0.6);
}

/* Size Selection Buttons */
.size-buttons {
    display: flex;
    gap: 15px;
    margin-top: 10px;
    justify-content: center;
}

.size-btn {
    background: linear-gradient(180deg, #9f7aea 0%, #805ad5 100%);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 20px;
    font-family: inherit;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 5px 0 #6b46c1;
    transition: transform 0.1s, box-shadow 0.1s;
}

.size-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 0 #6b46c1;
}

.size-btn:active {
    transform: translateY(2px);
    box-shadow: 0 3px 0 #6b46c1;
}

.size-btn.active {
    background: linear-gradient(180deg, #ffd54f 0%, #ff9e00 100%);
    color: #241400;
    box-shadow: 0 5px 0 #cc7a00;
    outline: 3px solid rgba(255, 255, 255, 0.7);
    transform: translateY(-3px);
}

/* Finish Screen */
.finish-screen {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    padding: 20px;
}

.finish-card {
    background: linear-gradient(180deg, #ffe27a 0%, #ffc94a 100%);
    border-radius: 24px;
    padding: 30px 28px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    max-width: 400px;
    width: 100%;
    animation: popIn 0.4s ease;
}

.finish-title {
    font-size: 28px;
    color: #5a3b00;
    margin-bottom: 20px;
}

.finish-image-preview {
    width: 100%;
    max-width: 300px;
    height: 200px;
    margin: 0 auto 20px;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
}

.finish-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.finish-button {
    background: linear-gradient(180deg, #4ECDC4 0%, #44A08D 100%);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 20px;
    font-size: 20px;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 6px 0 #2D7A6E;
    transition: transform 0.1s, box-shadow 0.1s;
}

.finish-button:active {
    transform: translateY(2px);
    box-shadow: 0 3px 0 #2D7A6E;
}

@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Confetti */
.confetti-screen {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 2500;
}

.confetti-piece {
    position: absolute;
    top: -12px;
    width: 8px;
    height: 14px;
    border-radius: 2px;
    opacity: 0;
    transform: translateY(0) rotate(0deg);
    animation: confettiFall var(--d, 0.95s) ease-out forwards;
    animation-delay: var(--delay, 0s);
    background: var(--c, #ff6b6b);
}

@keyframes confettiFall {
    0% { opacity: 0; transform: translate3d(0, -10px, 0) rotate(var(--r, 0deg)); }
    10% { opacity: 1; }
    100% { opacity: 1; transform: translate3d(var(--drift, 0px), 120vh, 0) rotate(calc(var(--r, 0deg) + 240deg)); }
}

/* Responsive Styles */
@media (max-width: 900px) {
    .puzzle-board {
        width: 100%;
        max-width: 600px;
        height: auto;
        aspect-ratio: 10 / 8;
    }

    .puzzle-piece {
        font-size: 20px;
    }

    .current-key-display {
        bottom: 80px;
        font-size: 18px;
        padding: 12px 20px;
    }

    .current-key {
        font-size: 24px;
        padding: 8px 15px;
    }
}

@media (max-width: 600px) {
    .start-screen {
        padding: 10px;
        padding-top: 15px;
        justify-content: flex-start;
    }
    
    .puzzle-board {
        max-width: 95vw;
    }

    .puzzle-piece {
        font-size: 14px;
    }

    .start-screen h1 {
        font-size: 24px;
        margin-bottom: 5px;
    }

    .puzzle-icon {
        font-size: 35px;
        margin-bottom: 8px;
    }
    
    .start-screen p {
        font-size: 12px !important;
        margin: 5px 0 !important;
    }

    .language-buttons {
        flex-direction: row;
        gap: 8px;
        margin-top: 8px;
    }

    .lang-btn {
        font-size: 12px;
        padding: 8px 16px;
    }

    .image-selector-container {
        margin-top: 5px;
    }

    .image-buttons {
        padding: 8px;
        max-width: 95vw;
        max-height: 85px;
        gap: 8px;
    }
    
    .image-btn {
        width: 65px;
        height: 65px;
    }
    
    .image-btn .image-name {
        font-size: 8px;
        padding: 2px;
    }
    
    .size-buttons {
        gap: 6px;
        margin-top: 8px;
    }
    
    .size-btn {
        font-size: 12px;
        padding: 8px 14px;
    }
    
    .start-btn {
        font-size: 18px;
        padding: 12px 30px;
        margin-top: 10px;
    }

    .progress-indicator {
        font-size: 14px;
        padding: 10px 15px;
        top: 10px;
        left: 10px;
    }

    .home-button {
        font-size: 14px;
        padding: 10px 15px;
        top: 10px;
        right: 10px;
    }

    .sound-toggle {
        font-size: 12px;
        padding: 6px 12px;
    }

    .instructions {
        font-size: 14px;
        padding: 10px 20px;
        bottom: 15px;
    }

    .current-key-display {
        bottom: 60px;
        font-size: 16px;
    }

    .celebration {
        font-size: 48px;
    }
}

/* On-screen Keyboard */
.on-screen-keyboard {
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    max-width: 640px;
    width: calc(100% - 20px);
    z-index: 100;
    backdrop-filter: blur(10px);
}

.key-row {
    display: flex;
    justify-content: center;
    gap: 4px;
}

.key-btn {
    flex: 1 1 0;
    max-width: 48px;
    height: 44px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(180deg, #f6ad55 0%, #ed8936 100%);
    color: white;
    font-size: 16px;
    font-weight: 700;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0 3px 0 #c05621, 0 4px 10px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: transform 0.05s ease, box-shadow 0.1s ease;
}

.key-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #c05621, 0 2px 5px rgba(0, 0, 0, 0.15);
}

/* Keyboard Toggle Button */
.keyboard-toggle {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: #FFE66D;
    border: none;
    padding: 8px 16px;
    border-radius: 16px;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 4px 0 #F4A261;
    z-index: 50;
}

/* Mobile keyboard adjustments */
@media (max-width: 600px) {
    .on-screen-keyboard {
        padding: 8px;
        gap: 4px;
        bottom: 5px;
    }
    
    .key-row {
        gap: 3px;
    }
    
    .key-btn {
        max-width: 32px;
        height: 38px;
        font-size: 13px;
        border-radius: 8px;
    }
    
    .keyboard-toggle {
        top: 56px;
        font-size: 12px;
        padding: 6px 12px;
    }
    
    /* Adjust game layout when keyboard is visible */
    .game-container {
        height: auto;
        padding-bottom: 200px;
    }
    
    .puzzle-board {
        max-height: 45vh;
    }
    
    .current-key-display {
        bottom: 180px;
        font-size: 12px;
        padding: 6px 12px;
        gap: 8px;
    }
    
    .current-key {
        font-size: 18px;
        padding: 6px 12px;
        min-width: 40px;
    }
    
    .instructions {
        display: none;
    }
    
    /* Bigger image buttons on mobile for better visibility */
    .image-buttons {
        padding: 8px;
        max-height: 80px;
    }
    
    .image-btn {
        width: 60px;
        height: 60px;
    }
    
    .image-btn .image-name {
        font-size: 8px;
        padding: 2px;
    }
}
