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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow: hidden;
    touch-action: none;
    height: 100vh;
    width: 100vw;
}

/* Screen Management */
.screen {
    display: none;
    width: 100vw;
    height: 100vh;
    position: absolute;
    top: 0;
    left: 0;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Difficulty Selection Screen */
#difficulty-screen h1 {
    color: white;
    font-size: clamp(2rem, 5vw, 3rem);
    margin-bottom: 2rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.difficulty-buttons {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    justify-content: center;
    padding: 0 2rem;
}

.difficulty-btn {
    width: clamp(140px, 20vw, 180px);
    height: clamp(140px, 20vw, 180px);
    border-radius: 20px;
    border: none;
    background: white;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
    transition: transform 0.2s;
    font-weight: bold;
}

.difficulty-btn:active {
    transform: scale(0.95);
}

.difficulty-number {
    font-size: clamp(3rem, 8vw, 4rem);
    color: #667eea;
}

.difficulty-label {
    font-size: clamp(1.2rem, 4vw, 1.5rem);
    color: #333;
    margin-top: 0.5rem;
}

/* Image Selection Screen */
#image-screen h1 {
    color: white;
    font-size: clamp(2rem, 5vw, 3rem);
    margin-top: 2rem;
    margin-bottom: 2rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    padding: 2rem;
    max-width: 1000px;
    overflow-y: auto;
    max-height: calc(100vh - 200px);
}

.image-option {
    cursor: pointer;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
    transition: transform 0.2s;
    background: white;
}

.image-option img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    display: block;
}

.image-option:active {
    transform: scale(0.95);
}

/* Back Button */
.back-btn {
    position: absolute;
    top: 15px;
    left: 15px;
    padding: 12px 24px;
    font-size: clamp(1.2rem, 3vw, 1.5rem);
    background: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    z-index: 2000;
    font-weight: bold;
    color: #667eea;
}

.back-btn:active {
    transform: scale(0.95);
}

/* Game Screen - SIMPLIFIED FOR IPAD */
#game-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 70px 10px 10px 10px;
}

#puzzle-board {
    position: relative;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    padding: 15px;
}

#ghost-canvas {
    position: absolute;
    top: 15px;
    left: 15px;
    opacity: 0.25;
    pointer-events: none;
}

#puzzle-slots {
    position: relative;
    display: grid;
    gap: 0;
}



/* Puzzle Pieces - OPTIMIZED FOR TOUCH */
.puzzle-piece {
    position: fixed;
    cursor: grab;
    touch-action: none;
    z-index: 10;
    filter: drop-shadow(0 8px 16px rgba(0,0,0,0.5));
    transition: filter 0.2s;
}

.puzzle-piece:active {
    cursor: grabbing;
    z-index: 1000;
    filter: drop-shadow(0 12px 24px rgba(0,0,0,0.6));
}

.puzzle-piece.placed {
    cursor: default;
    pointer-events: none;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.puzzle-piece canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Pieces Container */
#pieces-container {
    pointer-events: none;
}

#pieces-container .puzzle-piece {
    pointer-events: auto;
}

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

/* Loading Screen */
#loading-screen {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

#loading-screen p {
    color: white;
    font-size: clamp(1.5rem, 4vw, 2rem);
    margin-top: 2rem;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 6px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}