/* TuxPaint Web - Design System */

:root {
    --primary-blue: #3498db;
    --primary-yellow: #f1c40f;
    --primary-red: #e74c3c;
    --toolbar-width: 80px;
    --palette-width: 100px;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #ecf0f1;
    -webkit-user-drag: none;
    touch-action: none;
    /* Crucial for mobile drawing and preventing accidental selection */
}

#paintCanvas, #canvas-wrapper {
    touch-action: none !important;
    -webkit-tap-highlight-color: transparent;
}

img {
    -webkit-user-drag: none;
}

.app-container {
    height: 100vh;
    height: 100dvh;
    width: 100vw;
}

/* Toolbar Styling */
.toolbar {
    background: #2c3e50;
    z-index: 1000;
    display: grid !important;
    grid-template-columns: repeat(2, 1fr);
    align-content: start;
    gap: 4px;
    padding: 8px !important;
}

.palette {
    background: #bdc3c7;
    z-index: 1000;
}

/* Desktop vs Mobile positioning */
@media (min-width: 768px) {
    .toolbar {
        width: 140px;
        /* Adjusted for two columns */
        border-right: 4px solid #34495e;
        overflow-y: auto;
    }

    .palette {
        width: var(--palette-width);
        border-left: 4px solid #95a5a6;
    }
}

@media (max-width: 767px) {
    /* App-Like Mobile Layout */

    /* 1. Main Toolbar (Bottom) */
    .toolbar {
        width: 100%;
        height: auto;
        min-height: 58px;
        flex-shrink: 0 !important;
        display: flex !important;
        flex-direction: row;
        flex-wrap: nowrap !important;
        overflow-x: auto;
        overflow-y: hidden;
        background: rgba(255, 255, 255, 0.95);
        border-top: 1px solid rgba(0, 0, 0, 0.1);
        padding: 8px 15px !important;
        gap: 8px;
        align-items: center;
        scrollbar-width: none;
    }

    .toolbar::-webkit-scrollbar {
        display: none;
    }

    /* Mobile Toolbar Icons */
    .tool-btn {
        flex: 0 0 42px;
        /* Fixed width reduced */
        height: 42px;
        /* Height reduced */
        min-width: 42px;
        border-radius: 12px;
        background: #f8f9fa;
        border: none;
        box-shadow: none;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .tool-btn img,
    .tool-btn span {
        font-size: 20px !important;
        /* Icons smaller */
        width: auto !important;
        /* Let width be natural for emojis */
        height: auto !important;
        max-width: 24px !important;
        /* Constraint */
        max-height: 24px !important;
        margin: 0 !important;
        padding: 0 !important;
        line-height: 1 !important;
        /* Reset line height */
        display: inline-flex !important;
        /* Better for emojis/icons */
        align-items: center;
        justify-content: center;
        object-fit: contain;
    }

    .tool-btn.active {
        background: #3498db;
        color: white;
        box-shadow: 0 2px 6px rgba(52, 152, 219, 0.3);
        transform: translateY(-1px);
    }

    .tool-btn.active img {
        filter: brightness(0) invert(1);
    }

    /* 2. Bottom Palette Bar (Stacked above Toolbar) */
    .palette {
        width: 100%;
        height: auto;
        flex-shrink: 0 !important;
        display: flex;
        flex-direction: column;
        padding: 8px 10px;
        background: #fff;
        border-top: 1px solid rgba(0, 0, 0, 0.1);
        z-index: 1900;
        gap: 4px;
    }

    /* First Row: Controls (Home, Size, Save) */
    .d-flex-mobile-controls {
        display: flex;
        width: 100%;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        /* Tighter */
    }

    /* Hide desktop items we don't need or repurpose them */
    .palette .divider,
    .palette .text-center {
        display: none !important;
    }

    /* Size Control Compact */
    .size-control {
        flex: 1;
        min-width: 0;
        padding: 0 5px;
        background: #f8f9fa;
        border-radius: 6px;
        height: 32px;
        /* Reduced height */
        display: flex;
        align-items: center;
    }

    .size-control input[type=range] {
        width: 100%;
        margin: 0;
        cursor: pointer;
    }

    /* Make the track more visible */
    .form-range::-webkit-slider-runnable-track {
        background-color: #dee2e6 !important;
        height: 6px;
        border-radius: 3px;
    }

    .form-range::-moz-range-track {
        background-color: #dee2e6 !important;
        height: 6px;
        border-radius: 3px;
    }

    .form-range::-webkit-slider-thumb {
        background-color: #3498db !important;
        margin-top: -5px !important;
        /* Center on track */
    }

    .form-range::-moz-range-thumb {
        background-color: #3498db !important;
    }

    #size-preview {
        display: none;
    }

    /* Second Row: Colors */
    .palette-grid {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
        width: 100%;
        overflow-x: auto;
        gap: 6px;
        /* Tighter gap */
        padding-bottom: 2px;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .palette-grid::-webkit-scrollbar {
        display: none;
    }

    .color-swatch {
        flex: 0 0 28px !important;
        /* Smaller colors */
        width: 28px !important;
        height: 28px !important;
        border-radius: 50%;
        border: 2px solid #edeff0;
        display: block !important;
        margin: 0 !important;
    }

    /* 3. Canvas Area */
    #canvas-wrapper {
        flex: 1;
        width: 100%;
        margin: 0;
        padding: 10px;
        background: #f0f2f5;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
    }

    #paintCanvas {
        box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
        border-radius: 8px;
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
        background-color: transparent;
        position: relative;
        z-index: 10;
    }

    .practice-outline {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        max-width: calc(100% - 20px);
        /* Account for wrapper padding */
        max-height: calc(100% - 20px);
        width: auto;
        height: auto;
        object-fit: contain;
        pointer-events: none;
        opacity: 0.6;
        z-index: 1;
    }

    /* Hide desktop-specifics */
    .d-md-block {
        display: none !important;
    }



    .user-badge .home-btn {
        display: none;
        /* Hide home btn in badge on mobile, it's in palette */
    }

    /* Floating Action Button Adjustment */
    #mobileSettingsBtn {
        display: none !important;
    }

    /* Ensure size control doesn't squash */
    .size-control {
        min-width: 120px;
        padding: 0 10px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .size-control input[type=range] {
        height: 4px;
        /* Slimmer track */
    }

    #saveBtn,
    #soundToggle {
        height: 36px;
        border-radius: 20px;
        white-space: nowrap;
        display: flex;
        align-items: center;
        padding: 0 16px;
        font-size: 0.85rem;
    }

    #soundToggle {
        width: 36px;
        padding: 0;
        justify-content: center;
        border-radius: 50%;
    }
}

/* Button Styling */
.tool-btn {
    width: 100%;
    aspect-ratio: 1 / 1;
    min-width: 45px;
    border: 3px solid #34495e;
    background: #fff;
    border-radius: 12px;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, background-color 0.2s;
    cursor: pointer;
}

.tool-btn img {
    width: 32px;
    height: 32px;
}

.tool-btn:hover {
    transform: scale(1.05);
    background-color: #f1c40f;
}

.tool-btn.active {
    background-color: var(--primary-yellow);
    border-color: #f39c12;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}

/* Canvas Styling */
#canvas-wrapper {
    background: #bdc3c7;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto; /* Enable scroll if canvas exceeds visible area */
    position: relative;
}

.practice-outline {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    opacity: 0.6;
    z-index: 1;
    transform-origin: center center;
    transition: transform 0.1s ease-out;
}

#paintCanvas {
    background-color: transparent;
    cursor: crosshair;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 10;
    transform-origin: center center;
    transition: transform 0.1s ease-out;
}

.zoom-controls .btn-group-vertical {
    border: 2px solid rgba(0, 0, 0, 0.05);
}

.zoom-btn:hover {
    background-color: #3b82f6 !important;
    color: white !important;
}

/* Color Swatches */
.palette-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
}



.color-swatch {
    width: 30px;
    height: 30px;
    border: 2px solid #fff;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.color-swatch.selected {
    border-color: #000;
    transform: scale(1.1);
}

/* Size Preview */
#size-preview {
    border-radius: 50%;
    background: #000;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.divider {
    height: 2px;
    grid-column: span 2;
    width: 100%;
    background: #7f8c8d;
    margin: 10px 0;
}

.btn-circle {
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Floating Text Box (MS Word Style) */
.floating-text-box {
    position: absolute;
    background: rgba(255, 255, 255, 0.8);
    border: 2px dashed #3498db;
    outline: none;
    resize: none;
    padding: 4px;
    z-index: 1500;
    overflow: hidden;
    line-height: 1.2;
    font-family: Arial, sans-serif;
}

/* Custom Color Picker Styling */
/* Premium Tools Locking */
.tool-btn[data-premium="true"] {
    position: relative;
}

body:not(.logged-in) .tool-btn[data-premium="true"]:after {
    content: "🔒";
    position: absolute;
    top: -2px;
    right: -2px;
    font-size: 10px;
    background: white;
    border-radius: 50%;
    padding: 1px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    z-index: 5;
}

body:not(.logged-in) .tool-btn[data-premium="true"] img,
body:not(.logged-in) .tool-btn[data-premium="true"] span {
    filter: grayscale(1) opacity(0.6);
}

body:not(.logged-in) .tool-btn[data-premium="true"]:hover {
    background: #f8d7da !important;
    border-color: #f5c6cb !important;
}

/* Global Range Slider Visibility Fix */
.form-range::-webkit-slider-runnable-track {
    background-color: #dee2e6 !important;
    height: 6px;
    border-radius: 3px;
}

.form-range::-moz-range-track {
    background-color: #dee2e6 !important;
    height: 6px;
    border-radius: 3px;
}

.form-range::-webkit-slider-thumb {
    background-color: #3498db !important;
    margin-top: -5px !important;
}

.form-range::-moz-range-thumb {
    background-color: #3498db !important;
}