/*
 * Picture Puzzle: the tool's own components, styled in the site's design language (6 Oct 2026, on the UltraCompress Pro
 * template, the third of the twelve older tools brought onto it). Base: /libs/site-pages.css (tokens, Inter and Space
 * Grotesk, buttons, theme toggle, focus rings) and /libs/shared-nav.css (the site's header and footer). This file holds the
 * toolbar (difficulty and picture as pill selects, Upload, Resume and New Game), the board card with the welcome screen and
 * the game buttons, the stats tiles, the high-score card, the preview thumbnail, the three windows (victory, tutorial,
 * confirm), the confetti and the information sections. The puzzle board, the pieces and their states (focused, selected,
 * dragging, correct) and the animations are the original's rules with the site's colours. The original's glass panels,
 * five privacy cards with "100% client-side ... guaranteed", own footer and own theme (picture-puzzle-theme) are gone: the
 * site's toggle owns the theme and the shared footer carries the links. Every id and class the script touches keeps its name.
 */

/* ----- Tokens the tool adds (the original's names kept as aliases for the board) ----- */
:root {
    --surface: #ffffff;
    --surface-2: #f3f4f8;
    --ring: rgba(139, 92, 246, 0.18);
    --app-max: 1600px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --primary-color: #8b5cf6;
    --secondary-color: #ec4899;
    --accent-color: #f472b6;
    --success-color: #10b981;
    --warning-color: #d97706;
    --bg-tertiary: #ebe8f7;
}
:root:not([data-theme="light"]) {
    --surface: #14141f;
    --surface-2: rgba(255, 255, 255, 0.05);
    --bg-tertiary: #1f1d2e;
    --warning-color: #fbbf24;
}

/* ----- Page: full width, the page provides the side space ----- */
.container.app-container {
    max-width: calc(var(--app-max) + 2 * var(--content-gutter));
    margin-top: 16px;
}
@media (min-width: 640px) { .container.app-container { margin-top: 24px; } }

/* ----- The site header is the first thing on the page and stays at the top (11 Oct 2026: the Tools bar above it was removed; the header's own Tools link leads to the same page) ----- */
body { padding-top: 0; }
body > header { position: sticky; top: 0; z-index: 50; }
header .site-nav { position: relative; top: auto; }
.theme-toggle { top: 90px; }
@media (max-width: 639.98px) { .theme-toggle { top: 75px; } } /* the header is 81 px tall from 640 px, 65 px below */

.hidden { display: none !important; }
.text-center { text-align: center; }

/* ----- Hero: brand row, headline, tagline ----- */
.app-hero { margin: 0 0 2rem; text-align: center; }
.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 1.25rem;
    font-family: 'Space Grotesk', 'Inter', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-strong);
}
.app-brand img { width: 44px; height: 44px; border-radius: 12px; display: block; }
.app-hero h1 { margin-bottom: 0.75rem; }
.app-tagline { color: var(--text-2); font-size: 1.125rem; line-height: 1.6; max-width: 46rem; margin: 0 auto; }

/* ----- Buttons: the site's pills in the tool's sizes ----- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 9999px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.2;
    padding: 12px 24px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
.btn-primary { background: var(--gradient-brand); color: #fff; box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3); }
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text-strong); border: 1px solid var(--surface-border); padding: 11px 23px; }
.btn-secondary:hover:not(:disabled) { border-color: var(--brand); color: var(--link); transform: translateY(-2px); }
.btn-success { background: linear-gradient(135deg, #10b981, #059669); color: #fff; box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3); }
.btn-success:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(16, 185, 129, 0.4); color: #fff; }
.btn-danger { background: var(--surface); color: var(--danger); border: 1px solid rgba(185, 28, 28, 0.35); padding: 11px 23px; }
.btn-danger:hover:not(:disabled) { background: var(--danger-strong); color: #fff; border-color: transparent; transform: translateY(-2px); }
.btn-sm { font-size: 0.85rem; padding: 9px 16px; }
.btn-secondary.btn-sm, .btn-danger.btn-sm { padding: 8px 15px; }
.btn.loading { pointer-events: none; opacity: 0.7; }
.btn.loading::after { content: ''; position: absolute; width: 16px; height: 16px; border: 2px solid transparent; border-top-color: currentColor; border-radius: 50%; animation: spin 0.6s linear infinite; }
.btn-primary.pulse-highlight { animation: brandPulse 1.2s ease-in-out infinite; }
@keyframes brandPulse { 0%, 100% { box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3); } 50% { box-shadow: 0 0 0 8px rgba(139, 92, 246, 0.18), 0 8px 25px rgba(236, 72, 153, 0.4); } }
.file-upload-wrapper { position: relative; display: inline-block; }
.file-upload-wrapper input[type="file"] { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* ----- The app: the toolbar above the two columns ----- */
.app-shell { margin: 0 0 3rem; scroll-margin-top: 90px; }
.app-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 24px; margin: 0 0 1.25rem; }
.app-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.setup-group { display: flex; flex-wrap: wrap; gap: 8px; }
.setup-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px 4px 14px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 9999px;
    box-shadow: var(--surface-shadow);
    cursor: pointer;
}
.control-label { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); white-space: nowrap; }
.pill-select {
    appearance: none;
    -webkit-appearance: none;
    padding: 7px 30px 7px 12px;
    border: 1px solid transparent;
    border-radius: 9999px;
    background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 14px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-strong);
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.pill-select:hover { border-color: var(--brand); }
.pill-select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.pill-select option { color: #0a0a14; background: #fff; }

.app-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.side-column { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* ----- Cards ----- */
.card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 16px;
    box-shadow: var(--surface-shadow);
    overflow: hidden;
}
.card-header { padding: 14px 20px; border-bottom: 1px solid var(--surface-border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-title { margin: 0; font-size: 1.05rem; font-weight: 700; display: flex; align-items: center; gap: 8px; color: var(--text-strong); }
.card-body { padding: 16px 20px 20px; }

/* ----- The board card ----- */
.game-container { position: relative; padding: 24px; background: var(--surface-2); }
.game-container.paused::after {
    content: 'PAUSED';
    position: absolute;
    inset: 0;
    background: rgba(10, 10, 20, 0.78);
    color: #fff;
    font-family: 'Space Grotesk', 'Inter', sans-serif;
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    z-index: 10;
}
.puzzle-wrapper { display: flex; justify-content: center; align-items: center; min-height: 420px; }
.puzzle-board { display: grid; gap: 4px; padding: 12px; background: var(--bg-tertiary); border-radius: var(--radius-md); box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.12); max-width: 100%; }
.puzzle-piece {
    /* background-size and background-position are set per piece by the script */
    background-repeat: no-repeat;
    border-radius: var(--radius-sm);
    cursor: grab;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    position: relative;
    overflow: hidden;
}
.puzzle-piece::after { content: ''; position: absolute; inset: 0; border: 2px solid rgba(255, 255, 255, 0.2); border-radius: var(--radius-sm); pointer-events: none; }
.puzzle-piece:hover { transform: scale(1.05); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15); z-index: 10; }
.puzzle-piece:focus { outline: 3px solid var(--primary-color); outline-offset: 2px; z-index: 15; }
.puzzle-piece.dragging { opacity: 0.5; cursor: grabbing; }
.puzzle-piece.correct { cursor: default; animation: correctPlacement 0.5s ease-out; }
.puzzle-piece.correct::after { border-color: rgba(16, 185, 129, 0.7); box-shadow: 0 0 12px rgba(16, 185, 129, 0.45); }
.puzzle-piece.selected { outline: 3px solid var(--accent-color); outline-offset: 2px; z-index: 20; }
.welcome-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 380px; text-align: center; padding: 32px 20px; }
.welcome-icon { font-size: 72px; line-height: 1; margin-bottom: 18px; animation: bounce 2s infinite; }
.welcome-screen h2 { font-size: 1.5rem; margin: 0 0 10px; }
.welcome-screen p { color: var(--text-2); max-width: 36rem; margin: 0; }
.game-footer { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--surface-border); }

/* ----- Stats tiles ----- */
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat-card { text-align: center; padding: 14px 10px; border: 1px solid var(--surface-border); border-radius: 12px; background: var(--surface); transition: transform 0.2s ease, box-shadow 0.2s ease; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--surface-hover-shadow); }
.stat-label { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); margin-bottom: 4px; }
.stat-value { font-family: 'Space Grotesk', 'Inter', sans-serif; font-size: 1.6rem; font-weight: 700; color: var(--text-strong); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-value.paused { color: var(--warning-color); }

/* ----- High scores ----- */
.difficulty-filter { display: inline-flex; gap: 4px; padding: 4px; border-radius: 9999px; background: var(--surface-2); }
.filter-btn {
    padding: 6px 12px;
    border: 0;
    border-radius: 9999px;
    background: transparent;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-2);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.filter-btn:hover { color: var(--link); }
.filter-btn.active { background: var(--gradient-brand); color: #fff; box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3); }
.filter-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.scores-list { display: flex; flex-direction: column; gap: 8px; }
.score-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 12px;
    align-items: center;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 12px;
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.score-item:hover { border-color: var(--brand); transform: translateY(-2px); box-shadow: var(--surface-hover-shadow); }
.score-item.new-score { animation: highlightScore 1s ease-out; border-color: var(--success-color); }
.score-rank { width: 32px; height: 32px; border-radius: 50%; background: var(--gradient-brand); color: #fff; font-weight: 700; font-size: 0.85rem; display: flex; align-items: center; justify-content: center; }
.score-difficulty { font-size: 0.85rem; font-weight: 600; color: var(--text-strong); }
.score-moves { font-size: 0.8rem; color: var(--text-3); white-space: nowrap; }
.score-time { font-weight: 700; color: var(--text-strong); font-variant-numeric: tabular-nums; white-space: nowrap; }
.no-scores { text-align: center; padding: 24px 12px; color: var(--text-3); font-size: 0.9rem; }
.scores-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.form-hint { font-size: 0.78rem; color: var(--text-3); margin: 0; }

/* ----- Preview thumbnail ----- */
.preview-container { position: fixed; bottom: 20px; right: 20px; z-index: 100; }
.preview-image { width: 160px; height: 160px; border-radius: 14px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3); border: 3px solid var(--surface); object-fit: cover; display: block; }

/* ----- Windows ----- */
.modal-overlay { position: fixed; inset: 0; background: rgba(10, 10, 20, 0.6); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; animation: fadeIn 0.25s ease-out; }
.modal {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 20px;
    padding: 32px 28px;
    max-width: 480px;
    width: 100%;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
    animation: scaleIn 0.25s ease-out;
    text-align: center;
    max-height: 92vh;
    overflow-y: auto;
}
.modal--wide { max-width: 600px; text-align: left; }
.modal--narrow { max-width: 420px; }
.modal-icon { font-size: 64px; line-height: 1; margin-bottom: 14px; animation: bounce 1s ease-in-out; }
.modal h2 { font-size: 1.5rem; margin: 0 0 12px; }
.modal p { color: var(--text-2); margin: 0 0 20px; line-height: 1.6; }
.modal-stats { background: var(--surface-2); border-radius: 12px; padding: 6px 16px; margin: 18px 0 22px; text-align: left; }
.modal-stat-item { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--surface-border); }
.modal-stat-item:last-child { border-bottom: 0; }
.modal-stat-label { color: var(--text-2); font-weight: 600; }
.modal-stat-value { color: var(--link); font-weight: 700; font-variant-numeric: tabular-nums; }
.modal-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.tutorial-content h2 { margin-bottom: 16px; }
.tutorial-step { margin-bottom: 10px; padding: 12px 14px; background: var(--surface-2); border-radius: 12px; }
.tutorial-step h3 { color: var(--link); margin: 0 0 4px; font-size: 1rem; }
.tutorial-step p { color: var(--text-2); margin: 0; font-size: 0.92rem; line-height: 1.55; }
.modal--wide .modal-buttons { margin-top: 18px; }

/* ----- Confetti ----- */
.confetti { position: fixed; width: 10px; height: 10px; background: var(--primary-color); animation: confettiFall 3s linear; z-index: 9999; pointer-events: none; }

/* ----- Animations the script and the states use ----- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes correctPlacement { 0% { transform: scale(1); } 50% { transform: scale(1.1); box-shadow: 0 0 20px rgba(16, 185, 129, 0.6); } 100% { transform: scale(1); } }
@keyframes highlightScore { 0%, 100% { background: var(--surface); } 50% { background: rgba(16, 185, 129, 0.2); } }
@keyframes confettiFall { to { transform: translateY(100vh) rotate(360deg); opacity: 0; } }

/* ----- Information sections below the tool ----- */
.info-section { margin: 0 0 2.5rem; }
.info-section h2 { font-size: 1.75rem; margin: 0 0 1.25rem; }
.info-section > p { max-width: 70ch; color: var(--text-2); }
.info-section .info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.info-three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 1rem 0 1.5rem; }
.info-stack { display: grid; gap: 12px; }
.info-card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 16px;
    box-shadow: var(--surface-shadow);
    padding: 20px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.info-card:hover { transform: translateY(-4px); box-shadow: var(--surface-hover-shadow); }
.info-card--small { padding: 16px; box-shadow: none; }
.info-card h3 { margin: 0 0 0.75rem; font-size: 1.15rem; }
.info-card p { color: var(--text-2); margin-bottom: 0.75rem; }
.info-card p:last-child { margin-bottom: 0; }
.step-card { position: relative; padding-top: 24px; }
.step-num {
    position: absolute;
    top: -16px;
    left: 20px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--gradient-brand);
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}
.step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 0.75rem; }
.step-head h3 { margin: 0; }
.step-emoji { font-size: 1.6rem; line-height: 1; }
.info-section details.info-card { padding: 0; }
.info-section details.info-card summary {
    cursor: pointer;
    padding: 16px 20px;
    font-weight: 600;
    color: var(--text-strong);
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.info-section details.info-card summary::-webkit-details-marker { display: none; }
.info-section details.info-card summary::after { content: '+'; color: var(--link); font-weight: 700; font-size: 1.2rem; line-height: 1; flex-shrink: 0; }
.info-section details.info-card[open] summary::after { content: '\2212'; }
.info-section details.info-card p { padding: 0 20px 16px; margin: 0; color: var(--text-2); }

/* ----- Tablets and phones ----- */
@media (max-width: 1023px) {
    .app-layout { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .info-section .info-grid, .info-three { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 639px) {
    .app-hero { margin-bottom: 1.5rem; }
    .app-tagline { font-size: 1rem; }
    .app-toolbar { gap: 10px; }
    .setup-group, .setup-item { width: 100%; }
    .setup-item { justify-content: space-between; }
    .pill-select { flex: 1; min-width: 0; }
    .app-actions { width: 100%; }
    .app-actions .btn, .app-actions .file-upload-wrapper { flex: 1 1 auto; }
    .file-upload-wrapper .btn { width: 100%; }
    .game-container { padding: 12px; }
    .game-container.paused::after { font-size: 1.75rem; }
    .puzzle-wrapper { min-height: 320px; }
    .puzzle-board { padding: 8px; gap: 2px; }
    .welcome-screen { min-height: 300px; }
    .welcome-icon { font-size: 56px; }
    .game-footer { padding: 12px 16px; }
    .game-footer .btn { flex: 1 1 calc(50% - 4px); }
    .card-header { padding-left: 16px; padding-right: 16px; }
    .card-body { padding: 14px 16px 16px; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stat-value { font-size: 1.3rem; }
    .score-item { grid-template-columns: auto 1fr auto; }
    .score-moves { grid-column: 2; }
    .preview-container { bottom: 12px; right: 12px; }
    .preview-image { width: 110px; height: 110px; }
    .modal { padding: 24px 18px; }
    .modal-buttons .btn { flex: 1 1 auto; }
    .info-section h2 { font-size: 1.4rem; }
    .info-section .info-grid, .info-three { grid-template-columns: 1fr; }
    .info-card { padding: 16px; }
    .step-num { left: 16px; }
}
@media (prefers-reduced-motion: reduce) {
    .btn, .stat-card, .info-card, .score-item, .puzzle-piece { transition: none; }
    .welcome-icon, .modal-icon, .modal-overlay, .modal, .btn-primary.pulse-highlight { animation: none; }
}
@media print {
    body > header, .theme-toggle, .app-toolbar, .game-footer, .info-section, footer, .modal-overlay, .preview-container { display: none !important; }
}

/* Phones: 16 px text, 44 px tap targets (AdSense audit H-04, 8 Oct 2026) */
@media (max-width: 639.98px) {
    main button, main select, main summary, main [role="button"],
    main input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]) { min-height: 44px; }
    main div.difficulty-filter > button.filter-btn { min-width: 44px; }
}
