/* Game Template Styles — Matched to ColorifyMe website design */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800;900&display=swap');

* {
    box-sizing: border-box;
    user-select: none;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: #FDF0ED;
    display: flex;
    flex-direction: row;
    height: 100vh;
    overflow: hidden;
    overscroll-behavior: none;
}

/* ─── Sidebars ─── */
.sidebar {
    background: #ffffff;
    display: flex;
    z-index: 10;
    border-color: #f3e8ff;
}

#left-sidebar {
    width: clamp(56px, 5vw, 76px);
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 0.4rem;
    gap: clamp(4px, 0.8vh, 10px);
    border-right: 2px solid #f0e0e0;
    box-shadow: 2px 0 12px rgba(255, 75, 145, 0.06);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
}

#right-sidebar {
    width: clamp(240px, 26vw, 340px);
    flex-direction: row;
    padding: 0.5rem;
    gap: 0.4rem;
    border-left: 2px solid #f0e0e0;
    box-shadow: -2px 0 12px rgba(255, 75, 145, 0.06);
}

/* ─── Palette Container ─── */
#palette-container {
    flex: 1;
    background: #fdf8f6;
    border-radius: 16px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.04);
    position: relative;
    border: 1px solid #f0e0e0;
}

#palette-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(253, 240, 237, 0.85);
    border-radius: 16px;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

#palette-container.disabled-palette::after {
    opacity: 1;
    pointer-events: all;
}

/* ─── Tools Container ─── */
#tools-container {
    width: clamp(50px, 5vw, 68px);
    display: flex;
    flex-direction: column;
    gap: clamp(4px, 0.6vh, 8px);
    align-items: center;
    padding-top: 4px;
}

/* Hide scrollbar on left sidebar */
#left-sidebar::-webkit-scrollbar {
    display: none;
}

/* ─── Main Canvas Area ─── */
main {
    flex: 1;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    touch-action: none;
    background: #FDF0ED;
}

#canvas-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(255, 75, 145, 0.08), 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 2px solid white;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    border-radius: 14px;
}

#line-layer {
    opacity: 0;
    pointer-events: none;
}

#vector-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    mix-blend-mode: multiply;
    border-radius: 14px;
}

/* ─── Buttons ─── */
.action-btn,
.tool-btn {
    background: linear-gradient(135deg, #FF4B91, #FF8F3D);
    color: white;
    border: none;
    border-radius: clamp(8px, 1.2vh, 14px);
    width: clamp(36px, 4vw, 52px);
    height: clamp(36px, 4vw, 52px);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1rem, 1.2vw, 1.4rem);
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(255, 75, 145, 0.25);
    transition: all 0.15s ease;
    flex-shrink: 0;
    line-height: 1;
}

.action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(255, 75, 145, 0.35);
}

.action-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 4px rgba(255, 75, 145, 0.2);
}

.tool-btn {
    background: #ffffff;
    border: 2px solid #e8d5f5;
    box-shadow: 0 3px 8px rgba(143, 54, 222, 0.1);
    border-radius: 14px;
    margin-bottom: 2px;
}

.tool-btn:hover {
    border-color: #d4b5ef;
    box-shadow: 0 4px 12px rgba(143, 54, 222, 0.15);
}

.tool-btn.active {
    background: linear-gradient(135deg, #fff0f5, #ffe8ec);
    border-color: #FF4B91;
    box-shadow: 0 2px 8px rgba(255, 75, 145, 0.2);
    transform: translateY(1px);
}

/* ─── Custom Color Picker ─── */
#custom-color-wrapper {
    margin-bottom: 16px;
    width: 100%;
    height: 40px;
    border-radius: 14px;
    background: linear-gradient(to right,
            #FF4B91, #FF8F3D, #FFD700, #00FF00, #3b82f6, #8B5CF6, #FF4B91);
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
    border: 2px solid #f0e0e0;
}

#custom-color {
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    position: absolute;
    top: 0;
    left: 0;
}

/* ─── Color / Pattern / Sticker Grids ─── */
.grid-section {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: clamp(6px, 0.6vw, 10px);
    justify-items: center;
    padding-bottom: 4px;
}

.color-btn,
.pattern-btn,
.sticker-btn {
    width: clamp(32px, 3vw, 44px);
    height: clamp(32px, 3vw, 44px);
    border-radius: 50%;
    border: 2px solid #f0e0e0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1rem, 1.2vw, 1.4rem);
    background-color: white;
    background-position: center;
    background-size: cover;
    line-height: 1;
}

.color-btn:hover,
.pattern-btn:hover,
.sticker-btn:hover {
    transform: scale(1.1);
    border-color: #FF4B91;
}

.color-btn.active,
.pattern-btn.active,
.sticker-btn.active {
    transform: scale(1.15);
    border-color: #FF4B91;
    box-shadow: 0 4px 12px rgba(255, 75, 145, 0.3);
}

/* ─── Brush Size Slider ─── */
.size-slider-box {
    background: rgba(255, 75, 145, 0.08);
    border-radius: 16px;
    padding: clamp(6px, 1vh, 16px) 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(4px, 0.8vh, 12px);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.05);
    width: 100%;
    border: 1px solid #f0e0e0;
    flex-shrink: 1;
    min-height: 0;
}

.size-indicator {
    width: clamp(12px, 1.5vh, 18px);
    height: clamp(12px, 1.5vh, 18px);
    background: linear-gradient(135deg, #FF4B91, #FF8F3D);
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(255, 75, 145, 0.3);
    flex-shrink: 0;
}

#brush-size {
    -webkit-appearance: slider-vertical;
    appearance: slider-vertical;
    width: 8px;
    height: clamp(50px, 10vh, 100px);
    outline: none;
    accent-color: #FF4B91;
    flex-shrink: 1;
}

.section-title {
    width: 100%;
    text-align: center;
    font-weight: 700;
    color: #ccc;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
    grid-column: 1 / -1;
}

/* ─── Ripple Effect ─── */
.ripple {
    position: absolute;
    width: 30px;
    height: 30px;
    background: rgba(255, 75, 145, 0.15);
    border: 2px solid #FF4B91;
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(1);
    animation: rippleAnim 0.4s ease-out forwards;
    pointer-events: none;
    z-index: 100;
}

@keyframes rippleAnim {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(3);
        opacity: 0;
    }
}

/* ─── Loading Indicator ─── */
#loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(253, 240, 237, 0.92);
    backdrop-filter: blur(8px);
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: 800;
    color: #FF4B91;
    letter-spacing: 1px;
}

/* ─── Status Indicator ─── */
#status-indicator {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: #ffffff;
    border: 2px solid #FF4B91;
    border-radius: 24px;
    padding: 8px 24px;
    font-weight: 700;
    font-size: 0.85rem;
    color: #FF4B91;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    box-shadow: 0 4px 16px rgba(255, 75, 145, 0.12);
    z-index: 50;
    pointer-events: none;
    transition: all 0.2s ease-out;
}

/* ─── Palette Tabs ─── */
.palette-tab {
    display: none;
    flex-direction: column;
    width: 100%;
    gap: 12px;
}

.palette-tab.active-tab {
    display: flex;
}

/* ─── Gallery & Confirm Popups ─── */
#gallery-popup,
#confirm-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.gallery-content {
    background: white;
    padding: 28px;
    border-radius: 24px;
    border: 2px solid #f0e0e0;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    width: 90%;
    height: 90vh;
    max-width: 90%;
    display: flex;
    flex-direction: column;
    position: relative;
}

.gallery-content h2 {
    margin-top: 0;
    color: #FF4B91;
    text-align: center;
    text-transform: uppercase;
    font-weight: 800;
    letter-spacing: 1px;
    font-size: 1.4rem;
}

.close-btn {
    position: absolute;
    top: -12px;
    right: -12px;
    background: linear-gradient(135deg, #FF4B91, #FF8F3D);
    color: white;
    border: 3px solid white;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(255, 75, 145, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.15s ease;
}

.close-btn:hover {
    transform: scale(1.1);
}

.close-btn:active {
    transform: scale(0.95);
}

#gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
    gap: 0.625rem;
    overflow-y: auto;
    padding: 0.25rem;
    flex: 1;
    min-height: 0;
    align-content: start;
}

.gallery-item {
    background: #fdf8f6;
    border: 0.125rem solid #f0e0e0;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    /* overflow: hidden; */
    aspect-ratio: 0.85 / 1;
    position: relative;
}

.gallery-item:hover {
    transform: translateY(-0.125rem);
    border-color: #FF4B91;
    box-shadow: 0 0.375rem 1rem rgba(255, 75, 145, 0.15);
}

.gallery-item img {
    width: 100%;
    flex: 1;
    min-height: 0;
    object-fit: contain;
    pointer-events: none;
    padding: 0.375rem;
}

.gallery-label {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.92);
    text-align: center;
    padding: 0.3rem 0.375rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: #FF4B91;
    border-top: 1px solid #f0e0e0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
    min-width: 0;
    box-sizing: border-box;
}

/* ─── Gallery Pagination ─── */
.gallery-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 0 0.25rem;
    flex-shrink: 0;
}

.gallery-pagination button {
    background: linear-gradient(135deg, #FF4B91, #FF8F3D);
    color: white;
    border: none;
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 0.125rem 0.5rem rgba(255, 75, 145, 0.25);
    transition: all 0.15s ease;
}

.gallery-pagination button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 0.25rem 0.75rem rgba(255, 75, 145, 0.35);
}

.gallery-pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.gallery-pagination .page-info {
    font-size: 0.8rem;
    font-weight: 700;
    color: #FF4B91;
    min-width: 5rem;
    text-align: center;
}

/* ─── Responsive / Mobile Layout ─── */
@media (max-width: 900px),
(orientation: portrait) {
    body {
        flex-direction: column;
    }

    #left-sidebar {
        width: 100%;
        height: auto;
        padding: 8px 10px;
        flex-direction: row;
        border-right: none;
        border-bottom: 2px solid #f0e0e0;
        overflow-x: auto;
        flex-shrink: 0;
        align-items: center;
        justify-content: flex-start;
        gap: 8px;
        box-shadow: 0 2px 8px rgba(255, 75, 145, 0.06);
    }

    .action-btn,
    .tool-btn {
        width: 46px;
        height: 46px;
        font-size: 1.2rem;
    }

    .size-slider-box {
        flex-direction: row;
        height: auto;
        width: auto;
        padding: 8px 16px;
        border-radius: 20px;
    }

    #brush-size {
        -webkit-appearance: none;
        appearance: none;
        width: 80px;
        height: 8px;
        accent-color: #FF4B91;
    }

    #right-sidebar {
        width: 100%;
        height: auto;
        flex-direction: column;
        border-left: none;
        border-top: 2px solid #f0e0e0;
        padding: 8px;
        gap: 8px;
        flex-shrink: 0;
        overflow-x: hidden;
        box-shadow: 0 -2px 8px rgba(255, 75, 145, 0.06);
    }

    #tools-container {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
        justify-content: flex-start;
        height: auto;
        padding: 4px 0;
        gap: 8px;
        flex-shrink: 0;
    }

    #palette-container {
        padding: 8px;
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        width: 100%;
        min-height: 72px;
    }

    .palette-tab {
        flex-direction: row;
        gap: 10px;
        width: max-content;
        align-items: center;
        overflow: visible;
    }

    .grid-section {
        display: flex;
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: 8px;
        overflow: visible;
        padding-bottom: 4px;
    }

    .color-btn,
    .pattern-btn,
    .sticker-btn {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }

    .section-title {
        display: none;
    }

    #status-indicator {
        top: 8px;
        padding: 5px 14px;
        font-size: 0.75rem;
        display: none;
    }

    #custom-color-wrapper {
        width: 70px;
        height: 44px;
        flex-shrink: 0;
        margin-bottom: 0px;
    }

    /* Gallery responsive on mobile */
    .gallery-content {
        width: 96%;
        height: 94vh;
        max-width: 96%;
        padding: 1rem;
        border-radius: 1rem;
    }

    .gallery-content h2 {
        font-size: 1.1rem;
        margin-bottom: 0.625rem;
    }

    #gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
        gap: 0.5rem;
    }

    .gallery-label {
        font-size: 0.7rem;
        padding: 0.1875rem 0.25rem;
    }

    .gallery-pagination button {
        padding: 0.375rem 0.75rem;
        font-size: 0.7rem;
    }

    .gallery-pagination .page-info {
        font-size: 0.7rem;
    }
}

/* ─── Scrollbar Styling ─── */
#palette-container::-webkit-scrollbar,
#gallery-grid::-webkit-scrollbar {
    width: 6px;
}

#palette-container::-webkit-scrollbar-track,
#gallery-grid::-webkit-scrollbar-track {
    background: transparent;
}

#palette-container::-webkit-scrollbar-thumb,
#gallery-grid::-webkit-scrollbar-thumb {
    background: rgba(255, 75, 145, 0.2);
    border-radius: 10px;
}

#palette-container::-webkit-scrollbar-thumb:hover,
#gallery-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 75, 145, 0.4);
}

/* ─── Progress Indicator ─── */
#progress-indicator {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 75, 145, 0.15);
    border-radius: 28px;
    padding: 6px 14px 6px 6px;
    box-shadow: 0 4px 16px rgba(255, 75, 145, 0.1), 0 1px 4px rgba(0, 0, 0, 0.04);
    transition: all 0.4s cubic-bezier(.4, 0, .2, 1);
    pointer-events: none;
    opacity: 0;
    transform: translateY(-8px);
}

#progress-indicator.visible {
    opacity: 1;
    transform: translateY(0);
}

#progress-indicator.complete {
    border-color: rgba(0, 200, 100, 0.4);
    background: rgba(240, 255, 240, 0.9);
    box-shadow: 0 4px 20px rgba(0, 200, 100, 0.2), 0 0 30px rgba(0, 200, 100, 0.08);
    animation: progressPulse 1.5s ease-in-out infinite;
}

@keyframes progressPulse {

    0%,
    100% {
        box-shadow: 0 4px 20px rgba(0, 200, 100, 0.2), 0 0 30px rgba(0, 200, 100, 0.08);
    }

    50% {
        box-shadow: 0 4px 24px rgba(0, 200, 100, 0.35), 0 0 40px rgba(0, 200, 100, 0.15);
    }
}

#progress-ring {
    width: 36px;
    height: 36px;
    transform: rotate(-90deg);
    flex-shrink: 0;
}

.progress-ring-bg {
    fill: none;
    stroke: rgba(255, 75, 145, 0.12);
    stroke-width: 4;
}

.progress-ring-fill {
    fill: none;
    stroke: url(#progressGradient);
    stroke-width: 4;
    stroke-linecap: round;
    stroke-dasharray: 113.097;
    stroke-dashoffset: 113.097;
    transition: stroke-dashoffset 0.6s cubic-bezier(.4, 0, .2, 1);
}

#progress-indicator.complete .progress-ring-fill {
    stroke: #00c864;
}

#progress-text {
    font-size: 0.8rem;
    font-weight: 800;
    color: #FF4B91;
    letter-spacing: 0.5px;
    min-width: 32px;
    text-align: center;
    transition: color 0.4s ease;
}

#progress-indicator.complete #progress-text {
    color: #00a854;
}

/* ─── Confetti Canvas ─── */
#confetti-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 200;
    pointer-events: none;
}

/* ─── Responsive Progress Indicator ─── */
@media (max-width: 900px),
(orientation: portrait) {
    #progress-indicator {
        top: 8px;
        right: 8px;
        padding: 4px 10px 4px 4px;
        gap: 6px;
        border-radius: 22px;
    }

    #progress-ring {
        width: 28px;
        height: 28px;
    }

    #progress-text {
        font-size: 0.7rem;
        min-width: 26px;
    }
}