/* Puzzle Game Styles */
:root {
    --primary: #a36105;
    --primary-hover: #659531;
    --accent: #ffc107;
    --accent-dark: #ff9800;
}

* { box-sizing: border-box; }

body {
    background-color: #f3f7f2;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    font-family: 'Comic Sans MS', 'Nunito Sans', cursive, sans-serif;
}

/* ── Top bar (during gameplay) ── */
.game-topbar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(255,255,255,0.85);
    border-bottom: 2px solid rgba(163, 97, 5, 0.15);
    backdrop-filter: blur(4px);
    flex-shrink: 0;
    gap: 8px;
}

.back-btn {
    padding: 8px 16px;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 50px;
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
    font-weight: bold;
    transition: all 0.25s ease;
    font-family: inherit;
    white-space: nowrap;
}

.back-btn:hover {
    background: var(--primary);
    color: #fff;
    transform: translateY(-2px);
}

.puzzle-instruction {
    text-align: center;
    font-size: 0.8rem;
    color: #666;
    margin: 0;
    flex: 1;
}

.hint-btn {
    padding: 8px 18px;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 50px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: #fff;
    border: none;
    font-weight: bold;
    box-shadow: 0 3px 10px rgba(0,0,0,0.15);
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    white-space: nowrap;
}

.hint-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    filter: brightness(1.1);
}

/* ── Selection Screen ── */
.selection-screen {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: linear-gradient(135deg, #f3f7f2 0%, #fffdf5 100%);
    z-index: 500;
    overflow-y: auto;
    padding: 16px;
}

.selection-box {
    background: #fff;
    border-radius: 20px;
    padding: 20px 18px;
    max-width: 660px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(163, 97, 5, 0.12);
    text-align: center;
    margin: auto;
}

.selection-title {
    font-size: 1.3rem;
    color: var(--primary);
    margin: 0 0 14px 0;
    font-weight: bold;
}

.selection-label {
    font-size: 0.95rem;
    color: #555;
    margin: 10px 0 8px;
    font-weight: bold;
    text-align: left;
}

.profession-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 6px;
}

.profession-card {
    border: 3px solid #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
    aspect-ratio: 1;
}

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

.profession-card:hover {
    border-color: var(--accent);
    transform: scale(1.05);
}

.profession-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(163, 97, 5, 0.25);
}

.difficulty-btns {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.diff-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 14px;
    border: 3px solid #e0e0e0;
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s, background 0.2s;
    min-width: 85px;
    font-family: inherit;
}

.diff-btn:hover {
    border-color: var(--accent);
    background: #fff9f0;
    transform: translateY(-2px);
}

.diff-btn.selected {
    border-color: var(--primary);
    background: linear-gradient(135deg, #fff9f0, #fffdf5);
    box-shadow: 0 0 0 3px rgba(163, 97, 5, 0.2);
}

.diff-icon { font-size: 1rem; }
.diff-name { font-size: 0.9rem; font-weight: bold; color: #333; }
.diff-pieces { font-size: 0.72rem; color: #999; }

/* ── Mode Selection ── */
.mode-btns {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 18px;
}

.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 12px 20px;
    border: 3px solid #e0e0e0;
    border-radius: 14px;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s, background 0.2s, box-shadow 0.2s;
    min-width: 120px;
    font-family: inherit;
}

.mode-btn:hover {
    border-color: var(--accent);
    background: #fff9f0;
    transform: translateY(-2px);
}

.mode-btn.selected {
    border-color: var(--primary);
    background: linear-gradient(135deg, #fff9f0, #fffdf5);
    box-shadow: 0 0 0 3px rgba(163, 97, 5, 0.2);
}

.mode-icon { font-size: 1.4rem; }
.mode-name { font-size: 0.9rem; font-weight: bold; color: #333; }
.mode-desc { font-size: 0.72rem; color: #999; }

.start-btn {
    padding: 13px 44px;
    font-size: 1.2rem;
    font-weight: bold;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: #fff;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(163, 97, 5, 0.35);
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.start-btn:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 8px 24px rgba(163, 97, 5, 0.45);
}

/* ── Puzzle Board ── */
.puzzle-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    flex: 1;
}

.puzzle-board {
    display: grid;
    gap: 2px;
    border: 4px solid var(--primary);
    background-color: var(--primary);
    border-radius: 6px;
    overflow: hidden;
    margin-top: 8px;
    width: min(92vw, 640px);
    height: min(92vw, 640px);
}

.puzzle-piece {
    width: 100%;
    height: 100%;
    cursor: pointer;
    will-change: background-position;
    image-rendering: -webkit-optimize-contrast;
    transform: translateZ(0);
    background-repeat: no-repeat;
    transition: filter 0.15s ease;
}

.puzzle-piece:hover:not(.empty) {
    filter: brightness(1.08);
}

.puzzle-piece.empty {
    background: #e8f0e0 !important;
    cursor: default;
}

.puzzle-piece.hint {
    outline: 3px solid var(--accent);
    outline-offset: -3px;
    box-shadow: inset 0 0 8px rgba(255,193,7,0.6);
}

/* ── Reward Overlay ── */
#reward-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, rgba(163,97,5,0.92), rgba(101,149,49,0.92));
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    color: white;
    text-align: center;
    font-family: inherit;
}

#reward-overlay h2 {
    font-size: 2.8rem;
    margin-bottom: 10px;
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#reward-overlay p {
    font-size: 1.2rem;
    margin-bottom: 28px;
    opacity: 0.9;
}

.restart-btn {
    padding: 14px 40px;
    font-size: 1.1rem;
    background-color: #fff;
    color: var(--primary);
    border: none;
    border-radius: 30px;
    cursor: pointer;
    font-weight: bold;
    font-family: inherit;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.restart-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

/* ── Classic Mode ── */
.classic-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    flex: 1;
    gap: 12px;
    padding: 8px 8px 0;
    overflow-y: auto;
}

.classic-board {
    display: grid;
    gap: 2px;
    border: 4px solid var(--primary);
    background-color: var(--primary);
    border-radius: 6px;
    overflow: hidden;
    width: min(90vw, 580px);
    height: min(90vw, 580px);
    flex-shrink: 0;
}

.classic-slot {
    background: rgba(232, 240, 224, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: background 0.15s, box-shadow 0.15s;
}

.classic-slot.drag-over {
    background: rgba(101, 149, 49, 0.25);
    box-shadow: inset 0 0 0 3px var(--primary-hover);
}

.classic-slot .slot-number {
    color: rgba(163, 97, 5, 0.35);
    font-weight: bold;
    font-size: 1rem;
    pointer-events: none;
    user-select: none;
}

.classic-piece {
    background-repeat: no-repeat;
    cursor: grab;
    touch-action: none;
    user-select: none;
    transition: opacity 0.15s, box-shadow 0.15s;
}

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

.classic-piece.hint {
    outline: 3px solid var(--accent);
    outline-offset: -3px;
    box-shadow: inset 0 0 8px rgba(255,193,7,0.6);
}

/* Piece inside board slot fills it entirely */
.classic-slot .classic-piece {
    width: 100%;
    height: 100%;
}

/* Piece in the tray has fixed thumb size */
.tray-piece {
    width: 82px;
    height: 82px;
    border-radius: 6px;
    border: 2px solid rgba(163, 97, 5, 0.25);
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.tray-piece:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 10px rgba(0,0,0,0.18);
    transform: scale(1.07);
    transition: transform 0.12s, box-shadow 0.12s;
}

.piece-tray {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-content: flex-start;
    padding: 10px;
    background: rgba(255,255,255,0.75);
    border: 2px solid rgba(163, 97, 5, 0.18);
    border-radius: 14px;
    width: min(92vw, 640px);
    max-height: 260px;
    overflow-y: auto;
    min-height: 100px;
    flex-shrink: 0;
}

/* ── Spinner ── */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spinner-img {
    animation: spin 1s linear infinite;
}
