/**
 * puzzle.css - Sliding Puzzle game styles
 */

body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 15px;
}

.header {
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

h1 {
    font-size: 1.6rem;
}

.back-btn {
    padding: 8px 16px;
    border-radius: 20px;
}

.back-btn:hover, .back-btn:active {
    color: #764ba2;
}

.game-info {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.info-box {
    background: rgba(255,255,255,0.2);
    padding: 8px 20px;
    border-radius: 12px;
    color: white;
    font-weight: bold;
    text-align: center;
}

.info-box span {
    display: block;
    font-size: 1.3rem;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.control-btn {
    background: linear-gradient(45deg, #ff6b6b, #feca57);
    border: none;
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: bold;
    color: white;
    border-radius: 20px;
    cursor: pointer;
    transition: transform 0.2s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.control-btn:hover, .control-btn:active {
    transform: scale(1.05);
}

.control-btn.new-game {
    background: linear-gradient(45deg, #a8e6cf, #88d8b0);
}

.difficulty-select {
    padding: 10px 15px;
    font-size: 0.9rem;
    border-radius: 20px;
    border: none;
    background: white;
    color: #764ba2;
    font-weight: bold;
    cursor: pointer;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.puzzle-wrapper {
    position: relative;
    background: rgba(0,0,0,0.3);
    border-radius: 15px;
    padding: 10px;
}

.puzzle-board {
    display: grid;
    gap: 3px;
    background: rgba(0,0,0,0.5);
    border-radius: 10px;
    overflow: hidden;
}

.puzzle-piece {
    background-size: cover;
    background-position: center;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    border-radius: 3px;
    touch-action: none;
    will-change: transform;
    backface-visibility: hidden;
}

.puzzle-piece:hover {
    transform: scale(1.02);
    box-shadow: 0 0 10px rgba(255,255,255,0.5);
}

.puzzle-piece.empty {
    background: rgba(0,0,0,0.3) !important;
    cursor: default;
}

.puzzle-piece.empty:hover {
    transform: none;
    box-shadow: none;
}

.puzzle-piece.moveable {
    animation: moveableGlow 1.2s ease-in-out infinite;
}

/* Dad reaction container */
.dad-reaction {
    position: absolute;
    top: -50px;
    right: -20px;
    font-size: 2.5rem;
    transition: transform 0.2s ease;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.3));
    z-index: 50;
}

.preview-container {
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.preview-container.visible {
    opacity: 1;
    visibility: visible;
}

.preview-label {
    color: white;
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.preview-image {
    width: 150px;
    height: 150px;
    object-fit: cover;
    border-radius: 10px;
    border: 3px solid white;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
}

.peek-btn {
    background: linear-gradient(45deg, #ff6b6b, #feca57);
}

.peek-btn:active, .peek-btn.peeking {
    background: linear-gradient(45deg, #feca57, #48dbfb);
    transform: scale(0.95);
}

.win-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    display: none;
}

.win-overlay.show {
    display: flex;
}

.win-content {
    background: white;
    padding: 40px;
    border-radius: 25px;
    text-align: center;
    animation: bounceIn 0.5s;
    margin: 20px;
}

@keyframes bounceIn {
    0% { transform: scale(0); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.win-content h2 {
    font-size: 2rem;
    color: #764ba2;
    margin-bottom: 10px;
}

.win-content p {
    font-size: 1.1rem;
    color: #666;
    margin-bottom: 20px;
}

/* Confetti container override (game-common.css .confetti targets individual pieces) */
.confetti {
    position: fixed;
    pointer-events: none;
    z-index: 999;
}

/* Pulsing glow on moveable pieces */
@keyframes moveableGlow {
    0%, 100% { box-shadow: 0 0 8px rgba(255,215,0,0.5); }
    50% { box-shadow: 0 0 20px rgba(255,215,0,0.9), 0 0 30px rgba(255,215,0,0.4); }
}

/* Easter egg: Ghost in empty space */
@keyframes ghostFloat {
    0% { opacity: 0; transform: translateY(0) scale(0.5); }
    20% { opacity: 1; transform: translateY(-10px) scale(1); }
    80% { opacity: 1; transform: translateY(-60px) scale(1.2); }
    100% { opacity: 0; transform: translateY(-100px) scale(0.8); }
}

.ghost-boo {
    position: absolute;
    font-size: 3rem;
    pointer-events: none;
    z-index: 100;
    animation: ghostFloat 2s ease-out forwards;
    text-shadow: 0 0 10px rgba(255,255,255,0.8);
}

.ghost-boo .boo-text {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1rem;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    white-space: nowrap;
}

/* Easter egg: Winking picture */
@keyframes winkSquish {
    0%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(0.1); }
}

.puzzle-board.winking {
    animation: winkSquish 0.3s ease-in-out;
}

.wink-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 5rem;
    pointer-events: none;
    z-index: 100;
    animation: bounceIn 0.5s ease-out;
}

/* Level Select Overlay */
.level-select-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    display: none;
    overflow-y: auto;
    padding: 20px;
}

.level-select-overlay.show {
    display: flex;
}

.level-select-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 30px;
    border-radius: 25px;
    text-align: center;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.level-select-content h2 {
    color: white;
    font-size: 1.8rem;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.level-tile {
    background: white;
    border-radius: 15px;
    padding: 15px 10px;
    cursor: pointer;
    transition: all 0.2s;
    border: 3px solid transparent;
}

.level-tile:hover:not(.locked) {
    transform: scale(1.05);
    border-color: #feca57;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
}

.level-tile.locked {
    background: rgba(255,255,255,0.3);
    cursor: not-allowed;
    opacity: 0.7;
}

.level-tile .level-number {
    font-size: 1.5rem;
    font-weight: bold;
    color: #764ba2;
}

.level-tile.locked .level-number {
    color: #999;
}

.level-tile .level-name {
    font-size: 0.85rem;
    color: #666;
    margin: 5px 0;
    font-weight: 500;
}

.level-tile .level-info {
    font-size: 0.75rem;
    color: #999;
}

.level-tile .level-stars {
    font-size: 1rem;
    margin-top: 8px;
}

.level-tile .lock-icon {
    font-size: 1.5rem;
    margin-top: 5px;
}

/* Level info display during gameplay */
.level-info-display {
    background: rgba(255,255,255,0.25);
    padding: 8px 20px;
    border-radius: 12px;
    color: white;
    font-weight: bold;
    text-align: center;
}

.level-info-display .level-title {
    font-size: 1rem;
}

.level-info-display .par-info {
    font-size: 0.8rem;
    opacity: 0.9;
}

/* Win stars animation */
.win-stars {
    font-size: 3rem;
    margin: 20px 0;
}

.win-star {
    display: inline-block;
    animation: starPop 0.4s ease-out forwards;
    opacity: 0;
    transform: scale(0);
}

.win-star:nth-child(1) { animation-delay: 0.1s; }
.win-star:nth-child(2) { animation-delay: 0.3s; }
.win-star:nth-child(3) { animation-delay: 0.5s; }

.win-star.empty {
    filter: grayscale(100%);
    opacity: 0.4;
}

@keyframes starPop {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.win-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 15px;
}

.win-content .par-text {
    color: #888;
    font-size: 0.95rem;
    margin-bottom: 5px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .puzzle-piece.moveable {
        animation: none;
        box-shadow: 0 0 15px rgba(255,215,0,0.8);
    }

    .puzzle-piece {
        transition: none !important;
    }

    .dad-reaction {
        transition: none !important;
    }
}

@media (max-width: 500px) {
    h1 { font-size: 1.3rem; }
    .info-box { padding: 6px 12px; }
    .info-box span { font-size: 1.1rem; }
    .preview-image { width: 80px; height: 80px; }
    .level-grid { grid-template-columns: repeat(2, 1fr); }
    .level-select-content { padding: 20px 15px; }
    .level-tile { padding: 12px 8px; }
    .win-stars { font-size: 2.5rem; }
}

/* Timer warning animations */
@keyframes timerShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

.timer-warning {
    background: rgba(255, 100, 100, 0.4) !important;
    animation: timerShake 0.4s ease-in-out infinite;
}

.timer-critical {
    background: rgba(255, 50, 50, 0.6) !important;
    animation: timerShake 0.2s ease-in-out infinite;
}

.timer-warning span, .timer-critical span {
    color: #fff !important;
    text-shadow: 0 0 10px rgba(255,0,0,0.8);
}

/* Move warnings */
.moves-warning {
    background: rgba(255, 150, 50, 0.4) !important;
}

.moves-danger {
    background: rgba(255, 80, 80, 0.4) !important;
}

/* Oops popup */
@keyframes oopsPopup {
    0% { opacity: 0; transform: translate(-50%, 0) scale(0.5); }
    30% { opacity: 1; transform: translate(-50%, -15px) scale(1.3); }
    100% { opacity: 0; transform: translate(-50%, -40px) scale(0.8); }
}

.oops-popup {
    position: fixed;
    font-size: 1.5rem;
    font-weight: bold;
    color: #ff4444;
    pointer-events: none;
    z-index: 100;
    animation: oopsPopup 1s ease-out forwards;
}

/* Dad warning popup */
@keyframes warningSlide {
    0% { opacity: 0; transform: translateY(20px); }
    20% { opacity: 1; transform: translateY(0); }
    80% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-10px); }
}

.dad-warning {
    position: fixed;
    top: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    padding: 12px 20px;
    border-radius: 20px;
    font-size: 1.2rem;
    font-weight: bold;
    color: #764ba2;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 150;
    animation: warningSlide 2.5s ease-out forwards;
}

/* Game over overlay */
.game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.game-over-overlay.show {
    display: flex;
}

.game-over-content {
    background: linear-gradient(135deg, #ff6b6b, #ff8e8e);
    padding: 40px;
    border-radius: 25px;
    text-align: center;
    animation: bounceIn 0.5s;
    margin: 20px;
    color: white;
}

.game-over-content h2 {
    font-size: 2.5rem;
    margin-bottom: 15px;
}

.game-over-content p {
    font-size: 1.1rem;
    margin-bottom: 10px;
}

.game-over-content .dad-message {
    font-style: italic;
    opacity: 0.9;
    margin-bottom: 20px;
}

/* Easter Egg: Patience - Sleep Zzz floating */
@keyframes puzzle-floatUp {
    0% { opacity: 0; transform: translateY(0) scale(0.5); }
    20% { opacity: 1; transform: translateY(-20px) scale(1); }
    100% { opacity: 0; transform: translateY(-100px) scale(1.5); }
}

.sleep-zzz {
    position: fixed;
    font-size: 2rem;
    pointer-events: none;
    z-index: 200;
    animation: puzzle-floatUp 2s ease-out forwards;
}

/* Dream complete message */
.dream-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(100, 100, 200, 0.95);
    color: white;
    padding: 20px 40px;
    border-radius: 20px;
    font-size: 1.3rem;
    font-weight: bold;
    z-index: 300;
    animation: bounceIn 0.5s ease;
}

/* Startled dad */
@keyframes startleJump {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-20px) scale(1.3); }
}

.dad-reaction.startled {
    animation: startleJump 0.4s ease;
}

/* Easter Egg: Speedrun runner */
@keyframes runAcross {
    0% { left: -100px; }
    100% { left: calc(100vw + 100px); }
}

.speedrun-runner {
    position: fixed;
    top: 50%;
    font-size: 4rem;
    z-index: 300;
    animation: runAcross 1s linear forwards;
    filter: drop-shadow(5px 0 10px rgba(0,0,0,0.3));
}

/* Speedrun text with motion blur */
@keyframes speedTextPop {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}

.speedrun-text {
    position: fixed;
    top: 40%;
    left: 50%;
    font-size: 3.5rem;
    font-weight: bold;
    color: #ff4444;
    text-shadow: 5px 0 15px rgba(255,68,68,0.8),
                 10px 0 25px rgba(255,68,68,0.5),
                 -5px 0 15px rgba(255,68,68,0.8);
    z-index: 300;
    animation: speedTextPop 2s ease-out forwards;
}

/* Speed shake */
@keyframes speedShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

body.speed-shake {
    animation: speedShake 0.5s ease-in-out;
}

/* Easter Egg: Shake - Piece wobble */
@keyframes pieceWobble {
    0%, 100% { transform: rotate(0deg) scale(1); }
    15% { transform: rotate(12deg) scale(1.05); }
    30% { transform: rotate(-10deg) scale(0.95); }
    45% { transform: rotate(8deg) scale(1.03); }
    60% { transform: rotate(-6deg) scale(0.97); }
    75% { transform: rotate(4deg) scale(1.01); }
    90% { transform: rotate(-2deg) scale(0.99); }
}

.puzzle-piece.wobbling {
    animation: pieceWobble 0.8s ease-in-out;
}

/* Dizzy dad */
@keyframes dizzySpiral {
    0%, 100% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(20deg) scale(1.1); }
    50% { transform: rotate(-15deg) scale(0.9); }
    75% { transform: rotate(10deg) scale(1.05); }
}

.dad-reaction.dizzy {
    animation: dizzySpiral 0.4s ease-in-out 3;
}

/* Konami egg */
.puzzle_konami-text {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.5rem;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
    z-index: 1001;
    pointer-events: none;
    animation: puzzle_konamiFade 2.5s ease forwards;
}
@keyframes puzzle_konamiFade {
    0% { opacity: 0; transform: translateX(-50%) scale(0.5); }
    20% { opacity: 1; transform: translateX(-50%) scale(1.1); }
    80% { opacity: 1; }
    100% { opacity: 0; transform: translateX(-50%) scale(1); }
}
.puzzle_konami-dad {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    background: rgba(255, 215, 0, 0.2) !important;
    background-image: none !important;
}

/* Backwards egg */
.puzzle_backwards-text {
    position: fixed;
    top: 35%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.4rem;
    font-weight: bold;
    color: #ff6b6b;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
    z-index: 1001;
    pointer-events: none;
    animation: puzzle_backwardsFade 3s ease forwards;
}
@keyframes puzzle_backwardsFade {
    0% { opacity: 0; transform: translateX(-50%) translateY(10px); }
    15% { opacity: 1; transform: translateX(-50%) translateY(0); }
    80% { opacity: 1; }
    100% { opacity: 0; }
}
.puzzle_backwards-compass {
    position: fixed;
    top: 25%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 3rem;
    z-index: 1001;
    pointer-events: none;
    animation: puzzle_compassSpin 2s ease forwards;
}
@keyframes puzzle_compassSpin {
    0% { transform: translateX(-50%) rotate(0deg); opacity: 1; }
    80% { transform: translateX(-50%) rotate(1080deg); opacity: 1; }
    100% { transform: translateX(-50%) rotate(1080deg); opacity: 0; }
}
.puzzle_backwards-tint {
    filter: sepia(0.3) hue-rotate(-30deg) saturate(1.5) !important;
    transition: filter 0.3s ease;
}

/* Corner tap egg */
.puzzle_corner-glow {
    box-shadow: 0 0 15px 5px rgba(255, 215, 0, 0.8) !important;
    z-index: 10;
    transition: box-shadow 0.3s ease;
}
.puzzle_corner-text {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.4rem;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
    z-index: 1001;
    pointer-events: none;
    animation: puzzle_cornerFade 2.5s ease forwards;
}
@keyframes puzzle_cornerFade {
    0% { opacity: 0; transform: translateX(-50%) scale(0.5); }
    20% { opacity: 1; transform: translateX(-50%) scale(1.1); }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .puzzle_konami-text,
    .puzzle_backwards-text,
    .puzzle_backwards-compass,
    .puzzle_corner-text {
        animation: none !important;
    }
    .puzzle_konami-text,
    .puzzle_backwards-text,
    .puzzle_corner-text { opacity: 1; }
    .puzzle_backwards-compass { opacity: 0; }
}
