/* MODIFIED: Theme variables now match the Puzzle Paradise homepage for consistency */
:root {
    --success-color: #34d399;
    --danger-color: #fb7185;
}

.dark {
    --bg-color: #090a0f;
    --panel-bg: rgba(31, 41, 55, 0.5);
    --text-primary: #ffffff;
    --text-secondary: #a3aed3;
    --border-color: rgba(255, 255, 255, 0.1);
    --neon-color: #a78bfa; /* Jigsaw Puzzle Purple */
    --neon-glow: rgba(167, 139, 250, 0.5);
    --shadow-color: rgba(0,0,0,0.3);
}

.light {
    --bg-color: #f3f4f6;
    --panel-bg: rgba(255, 255, 255, 0.5);
    --text-primary: #171b2e;
    --text-secondary: #5a648a;
    --border-color: rgba(200, 205, 228, 0.7);
    --neon-color: #8b5cf6; /* Jigsaw Puzzle Purple (Light) */
    --neon-glow: rgba(139, 92, 246, 0.4);
    --shadow-color: rgba(0,0,0,0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    position: relative;
    transition: background-color 0.5s ease;
}

.dark body {
    background-image: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);
}

/* ADDED: Global Header for navigation and branding */
#global-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    z-index: 10001;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
}

.app-title-link {
    text-decoration: none;
}

.app-title {
    font-family: 'Lobster', cursive;
    font-size: 2rem;
    background-image: linear-gradient(to right, #60a5fa, #a78bfa, #4ade80);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#app-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    padding: 2rem;
    padding-top: 80px; /* Make space for global header */
    overflow-y: auto;
}

/* Original App Styles Below */
.screen { width: 100%; height: 100%; }
.hidden { display: none !important; }
#setup-screen { display: flex; align-items: center; justify-content: center; }

.setup-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    max-width: 1400px;
    max-height: 90vh;
    gap: 1.5rem;
}

.setup-header {
    display: flex;
    justify-content: center; /* Center the "Jigsaw Puzzle" title */
    align-items: center;
    flex-shrink: 0;
}

.setup-header h1 {
    font-size: 2rem;
    font-weight: 700;
}

.control-btn {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.control-btn:hover {
    color: var(--text-primary);
    border-color: var(--neon-color);
    box-shadow: 0 0 10px var(--neon-glow);
}
.theme-toggle-btn { padding: 0.5rem; }
.theme-toggle-btn svg { width: 20px; height: 20px; }
#mute-btn svg { width: 20px; height: 20px; }


.setup-content-grid {
    display: grid;
    grid-template-columns: 2fr 1.2fr;
    gap: 1.5rem;
    flex-grow: 1;
    min-height: 0;
}

.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    border-radius: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px 0 var(--shadow-color);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#library-filters { margin-bottom: 1.5rem; display: flex; gap: 0.5rem; flex-wrap: wrap; flex-shrink: 0; }
.filter-btn { padding: 0.5rem 1rem; border-radius: 999px; background-color: transparent; color: var(--text-secondary); border: 1px solid var(--border-color); cursor: pointer; transition: all 0.2s ease; }
.filter-btn.active { background-color: var(--neon-color); color: white; border-color: var(--neon-color); }
#puzzle-library { flex-grow: 1; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); grid-auto-rows: min-content; overflow-y: auto; padding: 0.5rem; }
#puzzle-library::-webkit-scrollbar { width: 6px; }
#puzzle-library::-webkit-scrollbar-track { background: transparent; }
#puzzle-library::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
.library-item { aspect-ratio: 1 / 1; border-radius: 0.75rem; overflow: hidden; cursor: pointer; border: 2px solid transparent; transition: all 0.2s ease; position: relative; }
.library-item img { width: 100%; height: 100%; object-fit: cover; }
.library-item.selected { border-color: var(--neon-color); box-shadow: 0 0 15px var(--neon-glow); }
#library-pagination { padding-top: 1rem; border-top: 1px solid var(--border-color); display: flex; justify-content: center; align-items: center; gap: 1rem; flex-shrink: 0; }
.pagination-btn { background-color: transparent; padding: 0.5rem 1rem; border-radius: 0.5rem; color: var(--text-secondary); border: 1px solid var(--border-color); cursor: pointer; transition: all 0.2s ease; }
.pagination-btn:hover { border-color: var(--neon-color); color: var(--text-primary); }
.pagination-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.settings-panel { display: flex; flex-direction: column; gap: 1rem; overflow-y: auto; padding: 0.25rem; }
.settings-panel::-webkit-scrollbar { width: 6px; }
.settings-panel::-webkit-scrollbar-track { background: transparent; }
.settings-panel::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
.settings-module { background: rgba(0,0,0,0.1); border: 1px solid var(--border-color); border-radius: 1rem; padding: 1rem; }
.settings-module h4 { font-size: 0.875rem; font-weight: 500; margin-bottom: 0.75rem; color: var(--text-secondary); text-align: left; }
.upload-area { width: 100%; aspect-ratio: 16 / 9; border: 2px dashed var(--border-color); border-radius: 0.75rem; display: flex; justify-content: center; align-items: center; position: relative; overflow: hidden; background-color: transparent; transition: all 0.3s ease; }
.upload-area:hover { border-color: var(--neon-color); box-shadow: inset 0 0 15px var(--neon-glow); }
#image-preview { width: 100%; height: 100%; object-fit: contain; }
#image-upload { display: none; }
.upload-label { cursor: pointer; text-align: center; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 100%; }
.upload-label .icon { width: 28px; height: 28px; color: var(--neon-color); margin: 0 auto 0.5rem; }
#puzzle-type-indicator { position: absolute; bottom: 0.5rem; background: rgba(0,0,0,0.6); color: white; font-size: 0.75rem; font-weight: 500; padding: 0.25rem 0.75rem; border-radius: 999px; left: 50%; transform: translateX(-50%); }
#remove-image-btn { position: absolute; top: 0.5rem; right: 0.5rem; width: 2rem; height: 2rem; border-radius: 50%; border: none; background-color: rgba(0,0,0, 0.5); color: white; font-size: 1.5rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; z-index: 10; }
#remove-image-btn:hover { background-color: var(--danger-color); transform: scale(1.1); }
.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.option-label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.5rem; color: var(--text-secondary); }
select { width: 100%; padding: 0.75rem; border-radius: 0.5rem; border: 1px solid var(--border-color); background-color: transparent; color: var(--text-primary); font-family: 'Inter', sans-serif; font-size: 0.9rem; transition: all 0.2s; appearance: none; background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23a3aed3' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e"); background-position: right 0.5rem center; background-repeat: no-repeat; background-size: 1.5em 1.5em; }
select:focus { outline: none; border-color: var(--neon-color); box-shadow: 0 0 10px var(--neon-glow); }
select option { background-color: var(--bg-color); color: var(--text-primary); }
.start-button { width: 100%; padding: 1rem; border: none; background: var(--neon-color); color: white; font-size: 1rem; font-weight: 700; border-radius: 0.75rem; cursor: pointer; transition: all 0.3s ease; text-transform: uppercase; letter-spacing: 0.05em; }
.start-button:hover:not(:disabled) { box-shadow: 0 0 20px var(--neon-glow); }
.start-button:disabled { background: var(--text-secondary); cursor: not-allowed; color: var(--bg-color); }
#error-message { color: var(--danger-color); font-size: 0.875rem; margin-top: 1rem; height: 1.25rem; text-align: center; }
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; background-color: rgba(0,0,0,0.7); backdrop-filter: blur(10px); z-index: 10000; }
.modal-content { background: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 1.5rem; padding: 2rem; width: 90%; max-width: 500px; position: relative; }
#close-modal-btn, .close-potd-modal-btn { position: absolute; top: 1rem; right: 1rem; background: none; border: none; font-size: 2rem; color: var(--text-secondary); cursor: pointer; transition: color 0.2s ease; }
#close-modal-btn:hover, .close-potd-modal-btn:hover { color: var(--text-primary); }
.modal-content ol { padding-left: 1.25rem; }
.modal-content li { margin-bottom: 0.75rem; }
.modal-content ul { padding-left: 1rem; margin-top: 0.5rem; font-size: 0.9rem; list-style-type: '→ '; }
#potd-modal .modal-content { display: flex; flex-direction: column; gap: 1rem; }
#potd-modal-image { width: 100%; height: auto; border-radius: 1rem; }
#game-screen { display: flex; flex-direction: column; gap: 1.5rem; }
#game-header { flex-shrink: 0; display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 1.5rem; background-color: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 1rem; box-shadow: 0 8px 32px 0 var(--shadow-color); width: 100%; }
.header-section { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.header-section.left { justify-content: flex-start; flex: 1; }
.header-section.center { justify-content: center; flex: 2; }
.header-section.right { justify-content: flex-end; flex: 1; }
#game-header button { width: auto; background-color: rgba(0,0,0,0.2); color: var(--text-secondary); border: 1px solid var(--border-color); padding: 0.5rem 1rem; font-weight: 500; font-size: 0.875rem; display: flex; align-items: center; gap: 0.5rem; border-radius: 0.5rem; transition: all 0.2s ease; }
#game-header button:hover:not(:disabled) { color: var(--text-primary); border-color: var(--neon-color); }
#reference-thumbnail-container { width: 70px; height: 50px; border-radius: 0.375rem; overflow: hidden; cursor: pointer; border: 2px solid var(--border-color); transition: all 0.2s; }
#reference-thumbnail-container:hover { border-color: var(--neon-color); }
#reference-thumbnail { width: 100%; height: 100%; object-fit: cover; }
#timer-container { display: flex; align-items: center; gap: 0.5rem; background-color: rgba(0,0,0,0.2); color: var(--text-primary); border: 1px solid var(--border-color); padding: 0.5rem 1rem; border-radius: 0.5rem; }
#timer-display { font-size: 1.1rem; font-weight: 600; font-variant-numeric: tabular-nums; }
#pause-btn { padding: 0.5rem; width: 36px; height: 36px; justify-content: center; }
#pause-btn svg { margin: 0; }
#pieces-remaining-container { font-size: 0.875rem; color: var(--text-secondary); }
#pieces-remaining-count { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); margin-left: 0.5rem; }
.toggle-switch { display: flex; align-items: center; gap: 0.5rem; }
.toggle-switch label { font-size: 0.875rem; color: var(--text-secondary); cursor: pointer; }
.toggle-switch input { appearance: none; width: 36px; height: 20px; border-radius: 10px; background-color: rgba(0,0,0,0.2); border: 1px solid var(--border-color); position: relative; cursor: pointer; transition: all 0.4s ease; }
.toggle-switch input::before { content: ''; position: absolute; width: 14px; height: 14px; border-radius: 50%; background-color: var(--text-secondary); top: 2px; left: 2px; transition: all 0.2s ease; }
.toggle-switch input:checked { background-color: var(--neon-color); }
.toggle-switch input:checked::before { transform: translateX(16px); background-color: white; }
#game-area { flex-grow: 1; position: relative; min-height: 0; overflow: hidden; background-color: var(--panel-bg); border-radius: 1rem; border: 1px solid var(--border-color); }
#puzzle-board-container { position: absolute; display: grid; place-items: center; }
#puzzle-board { position: relative; display: grid; place-items: center; width: 100%; height: 100%; }
#puzzle-grid-wrapper { position: relative; box-shadow: inset 0 2px 4px 0 rgba(0,0,0,0.2); }
.puzzle-board-shaped #puzzle-grid-wrapper { box-shadow: none; background: none !important; }
#board-guide-canvas, #board-outline-canvas { position: absolute; top: 0; left: 0; pointer-events: none; }
#board-guide-canvas { z-index: 0; }
#board-outline-canvas { z-index: 2; }
.placeholder { position: absolute; pointer-events: none; z-index: 1; transition: background-color 0.2s; }
.ghost-piece { position: absolute; opacity: 0.4; pointer-events: none; background-size: cover; z-index: 1; }
.puzzle-piece { position: absolute; cursor: grab; background-size: cover; z-index: 2; transition: transform 0.15s ease-out, box-shadow 0.15s ease-out, opacity 0.2s ease; border-radius: 4px; }
.puzzle-piece.selected { box-shadow: 0 0 15px 3px var(--neon-color); outline: 2px solid var(--neon-color); }
#selection-box { position: absolute; border: 1px dashed var(--neon-color); background-color: var(--neon-glow); pointer-events: none; z-index: 9998; }
.puzzle-piece.hidden-by-filter { opacity: 0; pointer-events: none; transform: scale(0.8); }
.puzzle-piece.dragging { cursor: grabbing; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.3), 0 10px 10px -5px rgba(0,0,0,0.2); z-index: 1000; transition: none; }
.puzzle-piece.solved { pointer-events: none; z-index: 1; box-shadow: none; outline: none; }
@keyframes piece-snap-pulse { 0% { transform: scale(1); } 50% { transform: scale(1.05); } 100% { transform: scale(1); } }
.puzzle-piece.just-solved { animation: piece-snap-pulse 0.4s ease-out; }
@keyframes piece-snap-glow { 0% { filter: drop-shadow(0 0 0 rgba(52, 211, 153, 0)); } 50% { filter: drop-shadow(0 0 10px var(--success-color)); } 100% { filter: drop-shadow(0 0 0 rgba(52, 211, 153, 0)); } }
.puzzle-piece.shaped-snap-effect { animation: piece-snap-glow 0.5s ease-out; }
.overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(13, 15, 26, 0.7); backdrop-filter: blur(10px); display: flex; justify-content: center; align-items: center; flex-direction: column; z-index: 9999; }
.spinner { width: 50px; height: 50px; border: 5px solid rgba(255, 255, 255, 0.3); border-top-color: var(--neon-color); border-radius: 50%; animation: spin 1s linear infinite; }
#loading-overlay p { color: white; margin-top: 1rem; font-size: 1.1rem; }
@keyframes spin { to { transform: rotate(360deg); } }
.win-box { background: var(--panel-bg); border: 1px solid var(--border-color); padding: 2.5rem; border-radius: 1.5rem; text-align: center; box-shadow: 0 8px 32px 0 var(--shadow-color); transition: transform 0.3s ease, opacity 0.3s ease; position: relative; z-index: 2; }
#confetti-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.win-box h2 { font-size: 2rem; font-weight: 700; color: var(--success-color); margin-bottom: 0.5rem; }
.win-box p { color: var(--text-primary); margin-bottom: 1.5rem; }
#final-time { color: var(--text-primary); font-weight: 500; margin-bottom: 1.5rem; margin-top: -1rem; font-size: 1rem; }
.win-box button { width: auto; padding: 0.75rem 2rem; background: var(--neon-color); color: white; font-weight: bold; border: none; border-radius: 0.5rem; }
.win-box button:hover { box-shadow: 0 0 15px var(--neon-glow); }
.close-modal-big-btn { position: absolute; top: 1rem; right: 2rem; font-size: 3rem; color: white; cursor: pointer; font-weight: 300; line-height: 1; text-shadow: 0 2px 4px rgba(0,0,0,0.3); }

@media (max-width: 900px) {
    #global-header { padding: 0.75rem 1rem; }
    .app-title { font-size: 1.5rem; }
    #app-container { padding: 1rem; padding-top: 70px; }
    .setup-header { flex-direction: column; gap: 1rem; }
    .setup-content-grid { grid-template-columns: 1fr; }
    .settings-panel { overflow-y: visible; }
    #game-header { flex-direction: column; height: auto; padding: 0.75rem; }
    .header-section { width: 100%; justify-content: center !important; }
    #game-area { display: flex; flex-direction: column; gap: 1rem; background: none; border: none; box-shadow: none; }
}
