:root {
    --maxWidth: 450px;
    --bg: #151517;
    --border: #ccc;
    --borderSelected: #ff4444;
    --accent: #4CAF50;
    --pieceW: 100px;
    --pieceH: 178px;
    --puzzleCols: 3;
    --puzzleRows: 3;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    background: var(--bg);
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

#scaler {
    height: 100vh;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    transform-origin: center;
}

#content {
    width: 100%;
    max-width: var(--maxWidth);
    height: 100%;
    padding: 20px;
    gap: 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#counter {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 18px;
    font-weight: bold;
    pointer-events: none;
    z-index: 10;
}

#puzzle-container {
    display: grid;
    grid-template-columns: repeat(var(--puzzleCols), var(--pieceW));
    grid-template-rows: repeat(var(--puzzleRows), var(--pieceH));
    gap: 2px;
}

#puzzle-container.hidden {
    display: none;
}

.piece {
    width: var(--pieceW);
    height: var(--pieceH);
    cursor: pointer;
    background-size: calc(var(--pieceW) * var(--puzzleCols)) 
                     calc(var(--pieceH) * var(--puzzleRows));
    border: 2px solid var(--border);
    transition: border-color 0.2s ease;
}

.piece.selected {
    border: 2px solid var(--borderSelected);
}

#full-image {
    width: calc(var(--pieceW) * var(--puzzleCols));
    height: calc(var(--pieceH) * var(--puzzleRows));
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 8px;
    pointer-events: none;
}

#full-image.hidden {
    display: none;
}

.buttons-container {
	display: flex;
	flex-direction: row-reverse;
	gap: 10px;
}

#next-btn,
#download-btn {
	width: 140px;
    padding: 10px 20px;
    font-size: 20px;
	text-align: center;
    border-radius: 8px;
    color: #fff;
    border: none;
    cursor: pointer;
    transition: 0.2s ease;
}

#next-btn {
	background: var(--accent);
}

#download-btn {
    background: #2196F3;
}

#next-btn:hover,
#download-btn:hover {
    filter: brightness(0.9);
}

#next-btn.hidden,
#download-btn.hidden {
    display: none;
}

#completion-screen {
    color: #fff;
    text-align: center;
    padding: 20px;
}

.completion-message h2 {
    font-size: 24px;
    margin-bottom: 12px;
    color: var(--accent);
}

.completion-message p {
    font-size: 18px;
    line-height: 1.5;
}

.preloader {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
	flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index:1000000;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.preloader .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255,255,255,0.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

.preloader .preload-progress {
	color: #fff;
    font-size: 18px;
    text-align: center;
	margin-top: 25px;
}
