/* Drawing Board Styles - Mobile First */

/* Header */
.drawing-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #F6CB00;
    z-index: 1000;
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    max-width: 1280px;
    margin: 0 auto;
    gap: 16px;
}

.logo {
    font-size: 24px;
    font-weight: 700;
    color: #2563EB;
    margin: 0;
    white-space: nowrap;
}

.header-buttons {
    display: flex;
    gap: 12px;
    flex: 1;
    justify-content: center;
}

.header-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

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

.header-btn svg {
    width: 24px;
    height: 24px;
    stroke: #333;
    stroke-width: 2;
    fill: none;
}

.share-btn {
    padding: 10px 20px;
    border: none;
    background: #000000;
    border-radius: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    color: #FFFFFF;
    white-space: nowrap;
}

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

.share-btn svg {
    width: 18px;
    height: 18px;
    stroke: #FFFFFF;
    stroke-width: 2.5;
    fill: none;
}

@media (max-width: 768px) {
    .header-content {
        padding: 12px 16px;
        gap: 8px;
    }

    .logo {
        font-size: 20px;
    }

    .header-buttons {
        gap: 8px;
    }

    .header-btn {
        width: 40px;
        height: 40px;
    }

    .share-btn {
        padding: 8px 14px;
        font-size: 13px;
        gap: 6px;
    }

    .share-btn svg {
        width: 16px;
        height: 16px;
    }
}

@media (max-width: 480px) {
    .logo {
        font-size: 18px;
    }

    .header-btn {
        width: 36px;
        height: 36px;
    }

    .header-btn svg {
        width: 20px;
        height: 20px;
    }

    .share-btn {
        height: 36px;
        padding: 6px 12px;
        font-size: 12px;
    }
}

.drawing-container {
    position: relative;
    width: 100%;
    min-height: 100vh; /* Full viewport height to push footer down */
    overflow: hidden;
    background: #F6CB00;
    display: flex;
    align-items: center; /* Center vertically */
    justify-content: center;
    padding: 100px 20px 140px 20px; /* Top padding for header, bottom for controls */
}

@media (max-width: 768px) {
    .drawing-container {
        padding: 80px 20px 160px 20px; /* Less top padding on mobile */
    }
}

/* Canvas Container */
.canvas-wrapper {
    position: relative;
    width: 90vw;
    max-width: 400px;
    aspect-ratio: 158 / 206;
}

/* SVG Background - hide it, we draw on canvas now */
.union-svg {
    display: none;
}

/* Canvas Container created by Fabric.js */
.canvas-container {
    z-index: 1;
}

/* Canvas Elements */
.canvas-container canvas {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    cursor: crosshair !important;
}

/* Legacy rule for initial canvas */
#drawing-canvas {
    position: absolute;
    top: 0;
    left: 0;
}

/* Tool buttons (used in bottom toolbar) */
.tool-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: relative;
}

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

.tool-btn svg {
    width: 24px;
    height: 24px;
    stroke: #333;
    stroke-width: 2;
    fill: none;
}

.tool-btn.active {
    background: #F6CB00;
}

/* Thickness Button - inside left toolbar */
.thickness-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: relative;
}

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

.thickness-btn-preview {
    border-radius: 50%;
    background: #333;
    width: 14px;
    height: 14px;
    transition: all 0.2s ease;
}

/* Bottom Toolbar Container */
.bottom-toolbar-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    z-index: 100;
    align-items: flex-end; /* Align to bottom */
}

/* Left Tool Panel - Now horizontal at bottom */
.left-toolbar {
    display: flex;
    flex-direction: row;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 24px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Right Color Palette - Now horizontal at bottom */
.right-toolbar {
    position: relative;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 24px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-width: calc(100vw - 40px);
}

/* When expanded, round top corners */
.right-toolbar.expanded {
    border-radius: 24px;
}

.base-colors {
    display: flex;
    flex-direction: row;
    gap: 10px;
    align-items: center;
}

.expanded-colors {
    position: absolute;
    bottom: calc(100% - 20px); /* Increased overlap for more seamless look */
    left: 0;
    right: 0;
    z-index: -1; /* Behind base-colors to create seamless look */
    display: flex;
    flex-direction: column-reverse; /* Reverse to expand upward */
    gap: 10px;
    padding: 0 16px 30px 16px; /* Extra bottom padding for overlap */
    background: rgba(255, 255, 255, 0.95);
    border-radius: 24px 24px 0 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
}

.right-toolbar.expanded .expanded-colors {
    max-height: 500px; /* Enough for 3 rows */
    opacity: 1;
    padding: 12px 16px 30px 16px; /* Add top padding when expanded */
}

.color-row {
    display: flex;
    flex-direction: row;
    gap: 10px;
    justify-content: center;
}

.color-btn {
    width: 44px;
    height: 44px;
    min-width: 44px; /* Prevent shrinking */
    border: 3px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0; /* Prevent shrinking on overflow */
}

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

.color-btn.active {
    border-color: #fff;
    box-shadow: 0 0 0 2px #333;
}

.palette-toggle-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border: 3px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    background: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.palette-toggle-btn:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Thickness Selector with Vertical Slider */
.thickness-selector {
    position: fixed;
    bottom: 230px; /* Above thickness panel */
    left: 20px; /* Left edge with same margin as bottom toolbar */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 102;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.thickness-selector.show {
    opacity: 1;
    pointer-events: auto;
}

/* Vertical Slider using CSS rotation */
.thickness-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 150px;
    height: 8px;
    background: linear-gradient(to right, #ddd 0%, #ddd 100%);
    border-radius: 4px;
    outline: none;
    transform: rotate(-90deg);
    cursor: pointer;
}

/* Slider thumb */
.thickness-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: #F6CB00;
    border: 3px solid #fff;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.thickness-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.thickness-slider::-webkit-slider-thumb:active {
    transform: scale(0.95);
}

.thickness-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: #F6CB00;
    border: 3px solid #fff;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.thickness-slider::-moz-range-thumb:hover {
    transform: scale(1.1);
}

.thickness-slider::-moz-range-thumb:active {
    transform: scale(0.95);
}

/* Thickness Panel with Horizontal Presets */
.thickness-panel {
    position: fixed;
    bottom: 100px; /* Above bottom toolbar */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 0;
    background: transparent;
    z-index: 101;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    max-width: calc(100vw - 40px);
}

.thickness-panel.show {
    opacity: 1;
    pointer-events: auto;
}

.thickness-preset-btn {
    width: 48px;
    height: 48px;
    border: 3px solid transparent;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.thickness-preset-btn:hover {
    background: #e8e8e8;
    transform: scale(1.05);
}

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

.thickness-preset-btn.active {
    border-color: #F6CB00;
    background: #FFF9E6;
    box-shadow: 0 0 0 2px #F6CB00;
}

.preset-circle {
    background: #333;
    border-radius: 50%;
    transition: all 0.2s ease;
}

/* Custom Cursor Preview on Canvas */
.brush-cursor {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.8);
    transform: translate(-50%, -50%);
    display: none;
    opacity: 0.8;
}

.brush-cursor.show {
    display: block;
}

/* Hide default cursor on canvas when drawing */
.canvas-container canvas {
    cursor: none !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .bottom-toolbar-container {
        flex-direction: row; /* Keep horizontal on mobile */
        gap: 8px;
        max-width: calc(100vw - 20px);
        left: 50%;
        transform: translateX(-50%);
    }

    .left-toolbar {
        padding: 10px 12px;
        gap: 8px;
        flex-shrink: 0; /* Don't shrink tools */
    }

    .right-toolbar {
        padding: 10px;
        max-width: none;
        flex: 1;
    }

    .base-colors {
        gap: 8px;
    }

    .expanded-colors {
        gap: 8px;
    }

    .color-row {
        gap: 8px;
    }

    .tool-btn,
    .color-btn,
    .thickness-btn,
    .palette-toggle-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }

    .thickness-btn-preview {
        width: 12px;
        height: 12px;
    }
}

/* Small mobile screens */
@media (max-width: 380px) {
    .left-toolbar {
        padding: 8px;
        gap: 6px;
    }

    .right-toolbar {
        max-width: calc(100vw - 16px);
        padding: 8px 6px;
    }

    .base-colors {
        gap: 6px;
    }

    .expanded-colors {
        gap: 6px;
    }

    .color-row {
        gap: 6px;
    }

    .tool-btn,
    .color-btn,
    .thickness-btn,
    .palette-toggle-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    .thickness-btn-preview {
        width: 10px;
        height: 10px;
    }

    .bottom-toolbar-container {
        bottom: 15px;
        max-width: calc(100vw - 16px);
    }
}

/* Landscape mobile */
@media (orientation: landscape) and (max-height: 500px) {
    .drawing-container {
        padding-top: 70px;
    }

    .bottom-toolbar-container {
        bottom: 10px;
    }
}
