/* ===== PREMIUM JIGSAW PUZZLE DESIGN SYSTEM ===== */

:root {
    --bg-gradient: linear-gradient(135deg, #0f0b21 0%, #150e33 50%, #060212 100%);
    --primary: #c084fc; /* Neon violet */
    --primary-glow: rgba(192, 132, 252, 0.4);
    --secondary: #22d3ee; /* Neon cyan */
    --secondary-glow: rgba(34, 211, 238, 0.4);
    --accent: #f43f5e; /* Vibrant Rose */
    --accent-glow: rgba(244, 63, 94, 0.4);
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.07);
    --glass-glow: rgba(192, 132, 252, 0.05);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --panel-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background: var(--bg-gradient);
    color: var(--text-main);
    font-family: 'Outfit', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    padding-bottom: 60px; /* Space for the 50px bottom ad banner */
}

/* ===== APP STORE HEADER COMPATIBILITY ===== */
.game-header {
    background: rgba(10, 6, 24, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: color 0.2s ease;
}

.back-link:hover {
    color: var(--primary);
}

.header-title {
    font-size: 1.15rem;
    font-weight: 900;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-difficulty {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(34, 211, 238, 0.15);
    color: var(--secondary);
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid rgba(34, 211, 238, 0.3);
    letter-spacing: 1px;
}

/* ===== MAIN GAME WRAPPER ===== */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 10px 16px 20px 16px;
    position: relative;
}

#game-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* ===== HUD DISPLAY ===== */
#hud {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.hud-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 10px 8px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: transform 0.2s ease;
}

.hud-value {
    font-size: 1.3rem;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
}

.hud-value.glow-cyan {
    color: var(--secondary);
    text-shadow: 0 0 10px var(--secondary-glow);
}

.hud-value.glow-purple {
    color: var(--primary);
    text-shadow: 0 0 10px var(--primary-glow);
}

.hud-value.glow-rose {
    color: var(--accent);
    text-shadow: 0 0 10px var(--accent-glow);
}

.hud-label {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-top: 2px;
}

/* ===== CANVAS BOARD WRAPPER ===== */
#game-canvas-wrap {
    width: 100%;
    aspect-ratio: 1;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 20px;
    border: 1px solid var(--glass-border);
    overflow: hidden;
    position: relative;
    box-shadow: var(--panel-shadow);
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}

#game-canvas:active {
    cursor: grabbing;
}

/* ===== PIECE TRAY (SCROLLABLE DOCK) ===== */
#tray-container {
    width: 100%;
    background: rgba(10, 6, 24, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 12px;
    box-shadow: var(--panel-shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: relative;
}

.tray-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    padding: 0 4px;
}

#piece-tray {
    width: 100%;
    height: 86px;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 6px;
    scroll-behavior: smooth;
    scrollbar-width: none; /* Firefox */
    touch-action: pan-x;
}

#piece-tray::-webkit-scrollbar {
    display: none; /* Safari and Chrome */
}

/* Individual Piece Cards inside the Tray */
.piece-card {
    flex: 0 0 72px;
    width: 72px;
    height: 72px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: grab;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), background 0.2s ease, border-color 0.2s ease;
    touch-action: none;
    position: relative;
}

.piece-card:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(192, 132, 252, 0.2);
    transform: scale(1.05);
}

.piece-card.dragging {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

.piece-card canvas {
    max-width: 100%;
    max-height: 100%;
}

/* ===== CONTROLS ===== */
#game-controls {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.ctrl-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 12px;
    border-radius: 16px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: background 0.2s, transform 0.2s, border-color 0.2s;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.ctrl-btn:active {
    transform: scale(0.97);
}

/* ===== OVERLAYS (MENU, SELECTORS, COMPLETE) ===== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(3, 2, 8, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
    padding: 20px;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    background: rgba(20, 15, 40, 0.6);
    border: 1px solid var(--glass-border);
    border-radius: 28px;
    width: 100%;
    max-width: 400px;
    padding: 30px 24px;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.8), 0 0 100px rgba(192, 132, 252, 0.08);
    text-align: center;
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.overlay.hidden .overlay-content {
    transform: scale(0.9);
}

.overlay h2 {
    font-size: 1.8rem;
    font-weight: 900;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.overlay .subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

/* Button UI */
.primary-btn {
    width: 100%;
    background: linear-gradient(135deg, #c084fc, #9333ea);
    border: none;
    color: #fff;
    padding: 14px;
    border-radius: 18px;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(147, 51, 234, 0.3);
    transition: all 0.2s ease;
}

.primary-btn:hover {
    box-shadow: 0 12px 30px rgba(147, 51, 234, 0.45);
    transform: translateY(-2px);
}

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

.secondary-btn {
    width: 100%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 14px;
    border-radius: 18px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    margin-top: 10px;
    transition: all 0.2s ease;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* Image Selection Grids */
.selector-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.selector-card {
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid var(--glass-border);
    border-radius: 18px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s;
    position: relative;
    aspect-ratio: 1;
}

.selector-card.selected {
    border-color: var(--secondary);
    box-shadow: 0 0 15px var(--secondary-glow);
    transform: scale(1.03);
}

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

.selector-label {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(10, 6, 24, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    color: var(--text-main);
    font-size: 0.75rem;
    font-weight: 800;
    padding: 6px;
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* Grid Size Selectors */
.size-selector-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.size-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    padding: 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.size-btn.active {
    background: rgba(192, 132, 252, 0.15);
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: 0 0 10px var(--primary-glow);
}

/* Success overlays */
.stars-row {
    font-size: 2.2rem;
    margin-bottom: 12px;
    color: #eab308;
    text-shadow: 0 0 15px rgba(234, 179, 8, 0.4);
    letter-spacing: 4px;
    animation: stars-bounce 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

.stats-summary {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 24px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.summary-item {
    text-align: center;
}

.summary-val {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--secondary);
}

.summary-lbl {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-top: 2px;
}

/* Toast Messages */
.ms-toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translate(-50%, -20px);
    background: rgba(20, 15, 40, 0.85);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 8px 18px;
    border-radius: 30px;
    font-size: 0.8rem;
    font-weight: 700;
    z-index: 1100;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    pointer-events: none;
}

.ms-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ===== DESCRIPTION / SEO COMPONENT ===== */
.game-info-section {
    width: 100%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 20px;
    margin-top: 20px;
    box-shadow: var(--panel-shadow);
}

.game-info-section h2, 
.game-info-section h3 {
    margin-bottom: 10px;
    font-weight: 800;
    color: var(--text-main);
}

.game-info-section h2 {
    font-size: 1.25rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.game-info-section h3 {
    font-size: 0.95rem;
    margin-top: 15px;
    color: var(--secondary);
}

.game-info-section p {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.game-info-section ul {
    list-style-type: none;
    margin-bottom: 12px;
}

.game-info-section li {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted);
    margin-bottom: 6px;
    position: relative;
    padding-left: 16px;
}

.game-info-section li::before {
    content: "🧩";
    position: absolute;
    left: 0;
    font-size: 0.7rem;
    top: 1px;
}

/* ===== AD CONTAINER BOTTOM FIXED ===== */
#bottom-ad.pmg-bottom-ad {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 320px;
    height: 50px;
    z-index: 9999;
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* ===== ANIMATIONS ===== */
@keyframes stars-bounce {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.1); }
    70% { transform: scale(0.9); }
    100% { transform: scale(1); opacity: 1; }
}

/* Mobile landscape and large viewports adjustment */
@media (max-height: 650px) {
    main {
        padding-top: 4px;
        padding-bottom: 4px;
        gap: 6px;
    }
    .hud-card {
        padding: 6px 4px;
    }
    #game-canvas-wrap {
        max-width: 280px;
        max-height: 280px;
    }
    #piece-tray {
        height: 70px;
    }
    .piece-card {
        flex: 0 0 58px;
        width: 58px;
        height: 58px;
    }
}
