/* Image Puzzle Game Styles */

* { box-sizing: border-box; }

body {
    font-family: 'S-CoreDream-3Light', sans-serif;
    background: #1a1a2e;
    color: #eee;
    margin: 0;
    min-height: 100vh;
}

header {
    background: linear-gradient(135deg, #16213e, #0f3460);
    border-bottom: 2px solid #e94560;
}

header h1 {
    color: #fff;
    font-size: 1.4rem;
    margin: 0.6rem;
}

.main-container {
    padding: 16px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: calc(100vh - 60px);
}

.puzzle-wrapper {
    width: 100%;
    max-width: 860px;
    position: relative;
}

/* --- Screens --- */
.screen { width: 100%; }
.screen.hidden { display: none !important; }
.screen.overlay-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(6px);
    z-index: 100;
}

/* --- Intro Screen --- */
.intro-content {
    background: linear-gradient(135deg, #16213e, #0f3460);
    border-radius: 20px;
    padding: 32px 24px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.game-title {
    font-size: 2.2rem;
    font-weight: 900;
    color: #fff;
    margin: 0 0 8px;
    letter-spacing: 2px;
}

.game-desc {
    color: #aaa;
    font-size: 1rem;
    margin: 0 0 28px;
}

.mode-label {
    color: #aaa;
    font-size: 0.85rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin: 0 0 12px;
}

.mode-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 28px;
    flex-wrap: wrap;
}

.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px 20px;
    border-radius: 14px;
    border: 2px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.05);
    color: #ccc;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 90px;
}

.mode-btn:hover {
    border-color: #e94560;
    background: rgba(233,69,96,0.1);
    color: #fff;
    transform: translateY(-2px);
}

.mode-btn.active {
    border-color: #e94560;
    background: rgba(233,69,96,0.2);
    color: #fff;
    box-shadow: 0 0 20px rgba(233,69,96,0.3);
}

.mode-grid {
    font-size: 1.4rem;
    font-weight: 900;
    color: inherit;
}

.mode-desc {
    font-size: 0.75rem;
    color: inherit;
    opacity: 0.8;
}

/* Image selection */
.image-select { margin-bottom: 28px; }

.image-thumbs {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.img-thumb {
    width: 70px;
    height: 70px;
    border-radius: 10px;
    border: 3px solid rgba(255,255,255,0.15);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.img-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.img-thumb:hover {
    border-color: #e94560;
    transform: scale(1.08);
}

.img-thumb.active {
    border-color: #e94560;
    box-shadow: 0 0 16px rgba(233,69,96,0.5);
}

.start-btn {
    padding: 14px 48px;
    font-size: 1.1rem;
    font-weight: 700;
    background: linear-gradient(135deg, #e94560, #c23152);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 1px;
    box-shadow: 0 6px 24px rgba(233,69,96,0.4);
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 32px rgba(233,69,96,0.55);
}

.start-btn:active { transform: translateY(0); }

/* --- Game Header --- */
.game-header {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 16px;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 8px 20px;
    min-width: 80px;
}

.stat-label {
    font-size: 0.7rem;
    color: #888;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
}

/* --- Game Area --- */
.game-area {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
}

/* Puzzle Board */
.puzzle-board {
    display: grid;
    gap: 3px;
    background: #0f3460;
    border: 3px solid #e94560;
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 0 30px rgba(233,69,96,0.25);
    flex-shrink: 0;
}

.puzzle-board.mode-3x3 { grid-template-columns: repeat(3, 1fr); }
.puzzle-board.mode-4x3 { grid-template-columns: repeat(4, 1fr); }
.puzzle-board.mode-4x4 { grid-template-columns: repeat(4, 1fr); }

.puzzle-piece {
    position: relative;
    background-size: cover;
    background-position: center;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.12s, box-shadow 0.12s;
    user-select: none;
    overflow: hidden;
}

.puzzle-piece::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 6px;
    border: 2px solid rgba(255,255,255,0.08);
    pointer-events: none;
}

.puzzle-piece:hover {
    transform: scale(1.04);
    z-index: 2;
    box-shadow: 0 4px 16px rgba(233,69,96,0.4);
}

.puzzle-piece.selected {
    transform: scale(1.06);
    z-index: 3;
    box-shadow: 0 0 0 3px #e94560, 0 6px 24px rgba(233,69,96,0.6);
}

.puzzle-piece.correct {
    cursor: default;
}

.puzzle-piece.correct::after {
    border-color: rgba(46,213,115,0.4);
}

.puzzle-piece.swap-anim {
    transition: transform 0.2s ease, opacity 0.15s;
    opacity: 0.8;
}

/* Piece number badge */
.piece-num {
    position: absolute;
    bottom: 3px;
    right: 5px;
    font-size: 0.6rem;
    color: rgba(255,255,255,0.5);
    line-height: 1;
    pointer-events: none;
}

/* Preview Panel */
.preview-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    min-width: 120px;
}

.preview-label {
    font-size: 0.75rem;
    color: #888;
    margin: 0;
    letter-spacing: 0.5px;
}

.preview-img-wrap {
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid rgba(255,255,255,0.15);
    width: 120px;
    height: 120px;
    flex-shrink: 0;
}

.preview-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.hint-btn {
    padding: 8px 16px;
    font-size: 0.8rem;
    background: rgba(255,255,255,0.07);
    color: #ccc;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.hint-btn:hover {
    background: rgba(233,69,96,0.15);
    border-color: #e94560;
    color: #fff;
}

/* Hint overlay on board */
.puzzle-board.show-hint .puzzle-piece {
    opacity: 0.35;
}

.puzzle-board.show-hint::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: var(--hint-img);
    background-size: cover;
    background-position: center;
    border-radius: 8px;
    z-index: 10;
    pointer-events: none;
    opacity: 0.85;
}

/* --- Game Footer --- */
.game-footer {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 16px;
    flex-wrap: wrap;
}

.footer-btn {
    padding: 10px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.5px;
}

.footer-btn.primary {
    background: linear-gradient(135deg, #e94560, #c23152);
    color: white;
    box-shadow: 0 4px 16px rgba(233,69,96,0.35);
}

.footer-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(233,69,96,0.5);
}

.footer-btn.secondary {
    background: rgba(255,255,255,0.08);
    color: #ccc;
    border: 1px solid rgba(255,255,255,0.15);
}

.footer-btn.secondary:hover {
    background: rgba(255,255,255,0.14);
    color: #fff;
    border-color: rgba(255,255,255,0.3);
}

/* --- Clear Screen --- */
.clear-content {
    background: linear-gradient(135deg, #16213e, #0f3460);
    border-radius: 24px;
    padding: 40px 32px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 24px 80px rgba(0,0,0,0.6);
    max-width: 360px;
    width: 90%;
}

.clear-icon {
    font-size: 3.5rem;
    margin-bottom: 8px;
    animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes popIn {
    from { transform: scale(0) rotate(-30deg); opacity: 0; }
    to { transform: scale(1) rotate(0deg); opacity: 1; }
}

.clear-title {
    font-size: 2rem;
    font-weight: 900;
    color: #fff;
    margin: 0 0 24px;
}

.clear-stats {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 28px;
}

.clear-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.clear-stat-label {
    font-size: 0.75rem;
    color: #888;
}

.clear-stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: #e94560;
}

.clear-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* --- Responsive --- */
@media (max-width: 600px) {
    .game-area {
        flex-direction: column;
        align-items: center;
    }
    .preview-panel {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        min-width: unset;
        width: 100%;
    }
    .preview-img-wrap {
        width: 80px;
        height: 80px;
    }
    .game-header {
        gap: 8px;
    }
    .stat-box {
        padding: 6px 12px;
        min-width: 60px;
    }
    .stat-value { font-size: 1rem; }
    .intro-content { padding: 24px 16px; }
    .game-title { font-size: 1.7rem; }
    .mode-btn { min-width: 76px; padding: 12px 14px; }
}

footer {
    background: linear-gradient(135deg, #16213e, #0f3460);
    color: #666;
    border-top: 1px solid rgba(255,255,255,0.05);
}
footer p { color: #555; }
