* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Responsive breakpoints */
    --mobile-max: 480px;
    --tablet-min: 481px;
    --tablet-max: 768px;
    --laptop-min: 769px;
    --laptop-max: 1024px;
    --desktop-min: 1025px;
    --desktop-max: 1440px;
    --tv-min: 1441px;
    
    /* Layout variables */
    --sidebar-width-desktop: 80px;
    --sidebar-width-laptop: 70px;
    --sidebar-width-tablet: 60px;
    --sidebar-height-mobile: 55px;
    --header-height: 60px;
    --status-bar-height: 40px;
    
    /* Spacing variables - Minimal padding for maximum canvas space */
    --canvas-padding-mobile: 5px;
    --canvas-padding-tablet: 6px;
    --canvas-padding-laptop: 8px;
    --canvas-padding-desktop: 10px;
    --canvas-padding-tv: 10px;
    
    /* Icon sizes - Optimized for better visual balance */
    --icon-size-ultrawide: 21px;
    --icon-size-tv: 18px;
    --icon-size-desktop: 14px;
    --icon-size-laptop: 13px;
    --icon-size-tablet: 12px;
    --icon-size-mobile: 12px;
    --icon-size-mobile-landscape: 10px;
    
    --action-icon-size-ultrawide: 23px;
    --action-icon-size-tv: 20px;
    --action-icon-size-desktop: 17px;
    --action-icon-size-laptop: 15px;
    --action-icon-size-tablet: 14px;
    --action-icon-size-mobile: 14px;
    --action-icon-size-mobile-landscape: 12px;
    
    /* UI element padding (separate from canvas) - Optimized for more canvas space */
    --ui-padding-mobile: 6px;
    --ui-padding-tablet: 9px;
    --ui-padding-laptop: 12px;
    --ui-padding-desktop: 15px;
    --ui-padding-tv: 18px;
    
    /* Tool spacing - Reduced gaps for cleaner interface */
    --tool-gap-desktop: 8px;
    --tool-gap-laptop: 8px;
    --tool-gap-tablet: 6px;
    --tool-gap-mobile: 6px;
    --tool-group-margin: 15px;
    
    /* Header control spacing - Optimized for better layout */
    --header-control-gap: 15px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    height: 100vh;
    width: 100vw;
    display: flex;
    overflow: hidden;
    position: relative;
}

.left-sidebar {
    width: var(--sidebar-width-desktop);
    background: linear-gradient(180deg, #ffffff 0%, #f8f9fa 100%);
    border-right: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--ui-padding-desktop) 10px;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.06);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 100;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.tool-group {
    display: flex;
    flex-direction: column;
    gap: var(--tool-gap-desktop);
    align-items: center;
    width: 100%;
    margin-bottom: var(--tool-group-margin);
}

.tool-group-title {
    font-size: 10px;
    font-weight: 600;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
    text-align: center;
}

.tool-btn {
    width: 44px;
    height: 44px;
    border: 1px solid #dee2e6;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.tool-btn:hover {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-color: #007bff;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.2);
    transform: translateY(-2px);
}

.tool-btn.active {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    border-color: #0056b3;
    box-shadow: 0 6px 16px rgba(0, 123, 255, 0.4);
    transform: translateY(-1px);
}

.tool-btn svg {
    width: var(--icon-size-desktop);
    height: var(--icon-size-desktop);
    stroke-width: 2;
    transition: transform 0.2s ease;
}

.tool-btn:hover svg {
    transform: scale(1.1);
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    min-width: 0; /* Prevents flex item from overflowing */
    height: 100vh;
}

.top-header {
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    padding: 10px var(--ui-padding-desktop);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    z-index: 90;
    height: var(--header-height);
    flex-shrink: 0;
    min-height: var(--header-height);
    gap: 16px;
}

.logo {
    height: 32px;
    width: auto;
    flex-shrink: 0;
    object-fit: contain;
    transition: height 0.3s ease;
    max-width: 120px;
}

.logo:not([src]),
.logo[src=""] {
    display: none;
}

.app-title {
    font-size: 20px;
    font-weight: 700;
    color: #2c3e50;
    margin: 0;
    flex: 1;
    text-align: center;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: var(--header-control-gap);
    flex-shrink: 0;
    justify-content: flex-end;
}

.canvas-area {
    flex: 1;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    padding: var(--canvas-padding-desktop);
    background: #f0f2f5;
    min-height: 0; /* Allows flex item to shrink */
    overflow: hidden;
    position: relative;
}

#whiteboard {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    cursor: crosshair;
    transition: box-shadow 0.3s ease;
    width: 100%;
    height: 100%;
    flex: 1;
    display: block;
}

#whiteboard:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

/* Ensure canvas fills container completely */
.canvas-area {
    box-sizing: border-box;
}

#whiteboard {
    box-sizing: border-box;
    object-fit: contain;
}

.action-btn {
    padding: 8px 16px;
    border: 1px solid #007bff;
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.action-btn:hover {
    background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
}

.action-btn:disabled {
    background: #6c757d;
    border-color: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.action-btn.secondary {
    background: linear-gradient(135deg, #6c757d 0%, #545b62 100%);
    border-color: #6c757d;
}

.action-btn.secondary:hover {
    background: linear-gradient(135deg, #545b62 0%, #3d4142 100%);
}

.action-btn-icon {
    width: 40px;
    height: 40px;
    border: 1px solid #007bff;
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: relative;
}

.action-btn-icon:hover {
    background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
}

.action-btn-icon:disabled {
    background: #6c757d;
    border-color: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    opacity: 0.6;
}

.action-btn-icon.secondary {
    background: linear-gradient(135deg, #6c757d 0%, #545b62 100%);
    border-color: #6c757d;
}

.action-btn-icon.secondary:hover {
    background: linear-gradient(135deg, #545b62 0%, #3d4142 100%);
}

.action-btn-icon svg {
    width: var(--action-icon-size-desktop);
    height: var(--action-icon-size-desktop);
}

/* Tooltip styles */
.action-btn-icon[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
}

.action-btn-icon[title]:hover::before {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-bottom-color: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    pointer-events: none;
}

.status-bar {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    padding: 8px var(--ui-padding-desktop);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: #6c757d;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
    height: var(--status-bar-height);
    flex-shrink: 0;
    min-height: var(--status-bar-height);
}

.status-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-indicator {
    color: #28a745;
    font-weight: 600;
}

.divider {
    width: 100%;
    height: 1px;
    background: #011428;
    margin: 5px 0;
}

.color-palette-vertical {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    width: 70%;
    margin-bottom: 10px;
}

.color-swatch-small {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
    justify-self: center;
}

.color-swatch-small:hover {
    transform: scale(1.1);
    border-color: #007bff;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
}

.color-swatch-small.active {
    border-color: #007bff;
    box-shadow: 0 0 0 2px #007bff;
}

#colorPickerSidebar {
    width: 100%;
    height: 32px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 12px;
    transition: all 0.2s ease;
}

#colorPickerSidebar:hover {
    border-color: #007bff;
    transform: scale(1.02);
}

.size-control-vertical {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.size-label {
    font-size: 11px;
    font-weight: 600;
    color: #495057;
    text-align: center;
}

#sizeSliderSidebar {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e9ecef;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    transition: opacity 0.3s ease;
}

#sizeSliderSidebar:disabled {
    cursor: not-allowed;
}

#sizeSliderSidebar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
}

#sizeDisplaySidebar {
    color: #007bff;
    font-weight: 700;
}

/* Calculator Modal */
.calculator-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    padding: 20px;
    z-index: 1000;
    min-width: 280px;
}

.calculator-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.calculator-title {
    font-size: 16px;
    font-weight: 600;
    color: #495057;
    margin: 0;
}

.calculator-close {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 6px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.calculator-close:hover {
    background: #c82333;
}

.calculator-display {
    width: 100%;
    height: 50px;
    font-size: 18px;
    text-align: right;
    padding: 10px;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    background: #f8f9fa;
    margin-bottom: 15px;
    font-family: 'Courier New', monospace;
    color: #495057;
}

.calculator-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.calc-btn {
    height: 40px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background: #f8f9fa;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.calc-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.calc-btn:active {
    transform: scale(0.95);
}

.calc-btn.operator {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

.calc-btn.operator:hover {
    background: #0056b3;
    border-color: #0056b3;
}

.calc-btn.equals {
    background: #28a745;
    color: white;
    border-color: #28a745;
}

.calc-btn.equals:hover {
    background: #1e7e34;
    border-color: #1e7e34;
}

.calc-btn.clear {
    background: #dc3545;
    color: white;
    border-color: #dc3545;
}

.calc-btn.clear:hover {
    background: #c82333;
    border-color: #c82333;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.hidden {
    display: none !important;
}

/* Text Input Area Styles */
.text-input-area {
    position: absolute;
    border: 2px dashed #007bff;
    background: rgba(255, 255, 255, 0.95);
    min-width: 100px;
    min-height: 30px;
    padding: 4px;
    font-family: Arial, sans-serif;
    font-size: 16px;
    color: #000000;
    text-align: left;
    resize: both;
    overflow: hidden;
    z-index: 1000;
    outline: none;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.2);
    transition: all 0.3s ease;
    animation: textAreaFadeIn 0.3s ease-out;
}

.text-input-area:focus {
    border-color: #0056b3;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
    background: rgba(255, 255, 255, 1);
}

@keyframes textAreaFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Text Formatting Toolbar */
.text-formatting-toolbar {
    position: absolute;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1001;
    font-size: 12px;
    max-width: 90vw;
    flex-wrap: wrap;
}

.text-formatting-toolbar select,
.text-formatting-toolbar input[type="number"] {
    padding: 4px 6px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 12px;
    background: white;
}

.text-formatting-toolbar button {
    padding: 6px 10px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
    min-width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.text-formatting-toolbar button:hover {
    background: #f8f9fa;
    border-color: #007bff;
    transform: translateY(-1px);
}

.text-formatting-toolbar button.active {
    background: #007bff;
    color: white;
    border-color: #007bff;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
}

.text-formatting-toolbar .color-picker-btn {
    width: 32px;
    height: 28px;
    padding: 0;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid #dee2e6;
}

.text-formatting-toolbar .color-picker-btn:hover {
    border-color: #007bff;
}

/* Toolbar Groups */
.font-size-group,
.format-group,
.align-group,
.advanced-group,
.action-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 4px;
    border-left: 1px solid #e9ecef;
}

.font-size-group:first-child,
.text-formatting-toolbar>select:first-child {
    border-left: none;
    padding-left: 0;
}

.format-group button {
    min-width: 24px;
    font-weight: bold;
}

.align-group button {
    min-width: 28px;
}

.action-group button {
    min-width: 32px;
    font-weight: bold;
}

.advanced-group {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 4px;
}

.advanced-group input[type="range"] {
    height: 4px;
    background: #e9ecef;
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.advanced-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 123, 255, 0.3);
}

.advanced-group input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 3px rgba(0, 123, 255, 0.3);
}

/* Text Selection Handles */
.text-selection-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #007bff;
    border: 1px solid white;
    border-radius: 50%;
    cursor: pointer;
    z-index: 1002;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
    transition: all 0.2s ease;
}

.text-selection-handle:hover {
    background: #0056b3;
    transform: scale(1.2);
    box-shadow: 0 3px 6px rgba(0, 123, 255, 0.4);
}

.text-element-selected {
    outline: 2px dashed #007bff;
    outline-offset: 2px;
}

/* Text Element Hover Effect */
.text-element-hover {
    cursor: pointer;
    opacity: 0.8;
}

/* ===== RESPONSIVE BREAKPOINTS ===== */

/* TV Screens (1441px and up) */
@media (min-width: 1441px) {
    :root {
        --sidebar-width-desktop: 100px;
    }
    
    .logo {
        height: 40px;
    }
    
    .app-title {
        font-size: 24px;
    }
    
    .tool-btn {
        width: 50px;
        height: 50px;
    }
    
    .tool-btn svg {
        width: var(--icon-size-tv);
        height: var(--icon-size-tv);
    }
    
    .action-btn-icon {
        width: 48px;
        height: 48px;
    }
    
    .action-btn-icon svg {
        width: var(--action-icon-size-tv);
        height: var(--action-icon-size-tv);
    }
    
    .canvas-area {
        padding: var(--canvas-padding-tv);
    }
    
    .top-header {
        padding: 10px var(--ui-padding-tv);
    }
    
    .left-sidebar {
        padding: var(--ui-padding-tv) 10px;
    }
    
    .status-bar {
        padding: 8px var(--ui-padding-tv);
    }
    
    #whiteboard {
        border-radius: 12px;
    }
}

/* Desktop Screens (1025px - 1440px) */
@media (min-width: 1025px) and (max-width: 1440px) {
    .logo {
        height: 32px;
    }
    
    .app-title {
        font-size: 20px;
    }
    
    .canvas-area {
        padding: var(--canvas-padding-desktop);
    }
}

/* Laptop Screens (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .left-sidebar {
        width: var(--sidebar-width-laptop);
        padding: var(--ui-padding-laptop) 8px;
    }
    
    .tool-btn {
        width: 40px;
        height: 40px;
    }
    
    .tool-btn svg {
        width: var(--icon-size-laptop);
        height: var(--icon-size-laptop);
    }
    
    .logo {
        height: 28px;
    }
    
    .app-title {
        font-size: 18px;
    }
    
    .action-btn-icon {
        width: 36px;
        height: 36px;
    }
    
    .action-btn-icon svg {
        width: var(--action-icon-size-laptop);
        height: var(--action-icon-size-laptop);
    }
    
    .top-header {
        padding: 10px var(--ui-padding-laptop);
    }
    
    .canvas-area {
        padding: var(--canvas-padding-laptop);
    }
    
    .status-bar {
        padding: 6px var(--ui-padding-laptop);
    }
}

/* Tablet Screens (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    /* Background color dropdown tablet adjustments */
    .background-color-dropdown {
        min-width: 180px;
        max-width: 220px;
        padding: 14px;
    }
    
    .preset-colors-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        margin-bottom: 14px;
    }
    
    .preset-color-swatch {
        width: 30px;
        height: 30px;
    }
    
    #customBackgroundColor {
        height: 36px;
    }
    .left-sidebar {
        width: var(--sidebar-width-tablet);
        padding: var(--ui-padding-tablet) 6px;
    }
    
    .tool-group {
        gap: var(--tool-gap-tablet);
        margin-bottom: var(--tool-group-margin);
    }
    
    .tool-group-title {
        font-size: 9px;
        margin-bottom: 6px;
    }
    
    .tool-btn {
        width: 36px;
        height: 36px;
    }
    
    .tool-btn svg {
        width: var(--icon-size-tablet);
        height: var(--icon-size-tablet);
    }
    
    .color-palette-vertical {
        grid-template-columns: repeat(2, 1fr);
        gap: 3px;
    }
    
    .color-swatch-small {
        width: 18px;
        height: 18px;
    }
    
    .logo {
        height: 24px;
    }
    
    .app-title {
        font-size: 16px;
    }
    
    .action-btn-icon {
        width: 32px;
        height: 32px;
    }
    
    .action-btn-icon svg {
        width: var(--action-icon-size-tablet);
        height: var(--action-icon-size-tablet);
    }
    
    .top-header {
        padding: 8px var(--ui-padding-tablet);
        height: 50px;
    }
    
    .canvas-area {
        padding: var(--canvas-padding-tablet);
    }
    
    .status-bar {
        padding: 4px var(--ui-padding-tablet);
        height: 35px;
        font-size: 11px;
    }
    
    .status-left,
    .status-right {
        gap: 12px;
    }
}

/* Mobile Screens (up to 480px) */
@media (max-width: 480px) {
    body {
        flex-direction: column;
    }
    
    /* Background color dropdown mobile adjustments */
    .background-color-dropdown {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        min-width: 240px;
        max-width: 300px;
        padding: 20px;
        border-radius: 12px;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    }
    
    .background-color-dropdown-header {
        font-size: 14px;
        margin-bottom: 12px;
        padding-bottom: 8px;
    }
    
    .preset-colors-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 10px;
        margin-bottom: 20px;
    }
    
    .preset-color-swatch {
        width: 36px;
        height: 36px;
        border-radius: 8px;
        border-width: 3px;
    }
    
    .preset-color-swatch:hover {
        transform: scale(1.1);
    }
    
    .preset-color-swatch.active::after {
        font-size: 16px;
    }
    
    #customBackgroundColor {
        height: 40px;
        border-width: 3px;
        border-radius: 8px;
        font-size: 12px;
    }
    
    #customBackgroundColor::before {
        font-size: 12px;
    }
    
    /* Mobile backdrop for dropdown */
    .background-color-dropdown::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }
    
    .left-sidebar {
        width: 100%;
        height: var(--sidebar-height-mobile);
        flex-direction: row;
        padding: 6px var(--ui-padding-tablet);
        overflow-x: auto;
        overflow-y: hidden;
        border-right: none;
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
        align-items: center;
        justify-content: flex-start;
        gap: 0;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    .left-sidebar::-webkit-scrollbar {
        display: none;
    }
    
    .tool-group {
        flex-direction: row;
        margin-bottom: 0;
        margin-right: 12px;
        gap: var(--tool-gap-mobile);
        flex-shrink: 0;
        align-items: center;
    }
    
    .tool-group-title {
        display: none;
    }
    
    .tool-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        flex-shrink: 0;
    }
    
    .tool-btn svg {
        width: var(--icon-size-mobile);
        height: var(--icon-size-mobile);
    }
    
    .color-palette-vertical {
        grid-template-columns: repeat(3, 1fr);
        gap: 2px;
        width: 60px;
        margin-bottom: 6px;
    }
    
    .color-swatch-small {
        width: 14px;
        height: 14px;
    }
    
    #colorPickerSidebar {
        height: 20px;
        margin-bottom: 6px;
        width: 60px;
    }
    
    .size-control-vertical {
        width: 50px;
    }
    
    #sizeSliderSidebar {
        height: 4px;
    }
    
    .size-label {
        font-size: 9px;
    }
    
    .main-area {
        height: calc(100vh - var(--sidebar-height-mobile));
        display: flex;
        flex-direction: column;
    }
    
    .top-header {
        padding: var(--ui-padding-mobile) var(--ui-padding-tablet);
        flex-wrap: nowrap;
        gap: 8px;
        height: 50px;
        min-height: 50px;
        justify-content: space-between;
        align-items: center;
    }
    
    .header-controls {
        gap: 4px;
        flex-wrap: nowrap;
        flex-shrink: 0;
    }
    
    .logo {
        height: 20px;
    }
    
    .app-title {
        font-size: 14px;
        order: 0;
        width: auto;
        margin-bottom: 0;
        flex-shrink: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: center;
    }
    
    .action-btn-icon {
        width: 32px;
        height: 32px;
        flex-shrink: 0;
    }
    
    .action-btn-icon svg {
        width: var(--action-icon-size-mobile);
        height: var(--action-icon-size-mobile);
    }
    
    .canvas-area {
        padding: var(--canvas-padding-mobile);
        flex: 1;
        min-height: 0;
        display: flex;
    }
    
    #whiteboard {
        border-radius: 6px;
        border-width: 1px;
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
    }
    
    .status-bar {
        padding: 4px var(--ui-padding-tablet);
        height: 30px;
        min-height: 30px;
        font-size: 10px;
        display: flex !important;
        flex-shrink: 0;
        overflow: hidden;
    }
    
    .status-left,
    .status-right {
        gap: 6px;
        flex-shrink: 1;
        overflow: hidden;
    }
    
    .status-left {
        min-width: 0;
    }
    
    .status-right {
        min-width: 0;
    }
    
    .status-right span:last-child {
        display: none; /* Hide version info on mobile */
    }
}

/* Ultra-wide screens (2560px and up) */
@media (min-width: 2560px) {
    :root {
        --sidebar-width-desktop: 120px;
        --padding-desktop: 32px;
    }
    
    .logo {
        height: 48px;
    }
    
    .app-title {
        font-size: 28px;
    }
    
    .tool-btn {
        width: 60px;
        height: 60px;
    }
    
    .tool-btn svg {
        width: var(--icon-size-ultrawide);
        height: var(--icon-size-ultrawide);
    }
    
    .action-btn-icon {
        width: 56px;
        height: 56px;
    }
    
    .action-btn-icon svg {
        width: var(--action-icon-size-ultrawide);
        height: var(--action-icon-size-ultrawide);
    }
}

/* Landscape orientation adjustments for tablets and phones */
@media (max-width: 1024px) and (orientation: landscape) {
    .top-header {
        height: 45px;
        min-height: 45px;
    }
    
    .status-bar {
        height: 30px;
        min-height: 30px;
    }
    
    .canvas-area {
        padding: var(--canvas-padding-mobile);
    }
}

/* Mobile landscape specific adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .left-sidebar {
        height: 50px;
        padding: 4px var(--ui-padding-mobile);
    }
    
    .tool-btn {
        width: 32px;
        height: 32px;
        min-width: 32px;
    }
    
    .tool-btn svg {
        width: var(--icon-size-mobile-landscape);
        height: var(--icon-size-mobile-landscape);
    }
    
    .main-area {
        height: calc(100vh - 50px);
    }
    
    .top-header {
        height: 35px;
        min-height: 35px;
        padding: 4px var(--ui-padding-mobile);
    }
    
    .status-bar {
        height: 25px;
        min-height: 25px;
        font-size: 9px;
        display: flex;
    }
    
    .logo {
        height: 18px;
    }
    
    .app-title {
        font-size: 12px;
    }
    
    .action-btn-icon {
        width: 28px;
        height: 28px;
    }
    
    .action-btn-icon svg {
        width: var(--action-icon-size-mobile-landscape);
        height: var(--action-icon-size-mobile-landscape);
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    #whiteboard {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .background-color-dropdown {
        border-width: 2px;
        border-color: #000000;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    }
    
    .preset-color-swatch {
        border-width: 3px;
        border-color: #000000;
    }
    
    .preset-color-swatch:focus {
        outline-width: 4px;
        outline-color: #000000;
    }
    
    .preset-color-swatch.active {
        border-color: #000000;
        box-shadow: 0 0 0 4px #000000;
    }
    
    #backgroundColorBtn {
        border-width: 2px;
        border-color: #000000;
    }
    
    #customBackgroundColor {
        border-width: 3px;
        border-color: #000000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .preset-color-swatch,
    .background-color-dropdown,
    #backgroundColorBtn,
    #customBackgroundColor {
        transition: none;
        animation: none;
    }
    
    .preset-color-swatch:hover {
        transform: none;
    }
    
    #backgroundColorBtn.color-changed {
        animation: none;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .tool-btn {
        min-height: 44px; /* iOS accessibility guidelines */
        min-width: 44px;
    }
    
    .action-btn-icon {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Background color button touch optimization */
    #backgroundColorBtn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Touch-friendly color swatches */
    .preset-color-swatch {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Enhanced touch feedback */
    .preset-color-swatch:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
    
    #customBackgroundColor {
        min-height: 44px;
    }
    
    /* Prevent zoom on double tap */
    .canvas-area {
        touch-action: manipulation;
    }
    
    #whiteboard {
        touch-action: none; /* Prevent scrolling while drawing */
    }
    
    .background-color-dropdown {
        touch-action: manipulation;
    }
}

/* Prevent text selection during drawing */
.canvas-area,
#whiteboard,
.left-sidebar {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Smooth scrolling for sidebar on mobile */
.left-sidebar {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

.left-sidebar::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

/* Focus states for accessibility */
.tool-btn:focus,
.action-btn-icon:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Loading state for canvas */
.canvas-area.loading {
    position: relative;
}

.canvas-area.loading::after {
    content: 'Resizing canvas...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    z-index: 1000;
}

/* Responsive text elements */
.text-input-area,
.text-formatting-toolbar {
    max-width: calc(100vw - 20px);
}

@media (max-width: 480px) {
    .text-formatting-toolbar {
        flex-wrap: wrap;
        max-width: calc(100vw - 16px);
        padding: 6px;
        gap: 6px;
    }
    
    .text-formatting-toolbar button {
        min-width: 32px;
        height: 32px;
        font-size: 11px;
    }
    
    .text-formatting-toolbar select,
    .text-formatting-toolbar input[type="number"] {
        font-size: 11px;
        padding: 2px 4px;
    }
}

/* Device-specific optimizations using JavaScript-added classes */
.mobile .canvas-area {
    padding: var(--canvas-padding-mobile) !important;
}

.mobile #whiteboard {
    border-radius: 6px !important;
}

.tablet .canvas-area {
    padding: var(--canvas-padding-tablet) !important;
}

.laptop .canvas-area {
    padding: var(--canvas-padding-laptop) !important;
}

.desktop .canvas-area {
    padding: var(--canvas-padding-desktop) !important;
}

.tv .canvas-area {
    padding: var(--canvas-padding-tv) !important;
}

.touch-device .tool-btn,
.touch-device .action-btn-icon {
    transition: transform 0.1s ease;
}

.touch-device .tool-btn:active,
.touch-device .action-btn-icon:active {
    transform: scale(0.95);
}

.high-dpi #whiteboard {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Eraser Group Styles */
.eraser-group {
    position: relative;
    display: flex;
    align-items: center;
    gap: 2px;
}

.eraser-size-btn {
    width: 20px;
    height: 40px;
    border: 1px solid #007bff;
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    border-radius: 0 8px 8px 0;
    border-left: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: relative;
}

.eraser-size-btn:hover {
    background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
}

.eraser-size-btn svg {
    width: 12px;
    height: 12px;
}

#eraserBtn {
    border-radius: 8px 0 0 8px;
}

.eraser-size-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 120px;
    padding: 8px;
    margin-top: 4px;
}

.eraser-size-option {
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 4px;
    font-size: 12px;
    transition: all 0.2s ease;
}

.eraser-size-option:hover {
    background: #f8f9fa;
}

.eraser-size-option.active {
    background: #007bff;
    color: white;
}

.eraser-preview {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #6c757d;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.eraser-preview.small::after {
    content: '';
    width: 6px;
    height: 6px;
    background: currentColor;
    border-radius: 50%;
}

.eraser-preview.medium::after {
    content: '';
    width: 10px;
    height: 10px;
    background: currentColor;
    border-radius: 50%;
}

.eraser-preview.large::after {
    content: '';
    width: 14px;
    height: 14px;
    background: currentColor;
    border-radius: 50%;
}

.eraser-preview.xlarge::after {
    content: '';
    width: 16px;
    height: 16px;
    background: currentColor;
    border-radius: 50%;
}

.eraser-size-option.active .eraser-preview {
    background: rgba(255, 255, 255, 0.3);
}

.eraser-size-option.active .eraser-preview::after {
    background: white;
}

/* Active eraser button styling */
#eraserBtn.active {
    background: linear-gradient(135deg, #28a745 0%, #1e7e34 100%);
    border-color: #1e7e34;
}

#eraserBtn.active + .eraser-size-btn {
    background: linear-gradient(135deg, #28a745 0%, #1e7e34 100%);
    border-color: #1e7e34;
}

/* Removed background color styles */
.background-color-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000; /* Increased z-index to ensure visibility */
    min-width: 160px;
    padding: 12px;
    margin-top: 4px;
    max-width: 200px;
    opacity: 1;
    transform: translateY(0);
    transition: all 0.2s ease;
}

.background-color-dropdown.hidden {
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
}

.background-color-dropdown-header {
    font-size: 11px;
    font-weight: 600;
    color: #495057;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    text-align: center;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 6px;
}

.preset-colors-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
    justify-content: center;
}

.preset-color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.preset-color-swatch::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

.preset-color-swatch:hover {
    transform: scale(1.15);
    border-color: #007bff;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.4);
    z-index: 10;
}

.preset-color-swatch:hover::before {
    transform: translateX(100%);
}

.preset-color-swatch.active {
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.3);
    transform: scale(1.05);
}

.preset-color-swatch.active::after {
    content: '✓';
    color: white;
    font-size: 14px;
    font-weight: bold;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
    z-index: 2;
    position: relative;
}

.preset-color-swatch:focus {
    outline: 3px solid #007bff;
    outline-offset: 2px;
    transform: scale(1.1);
    z-index: 10;
}

.preset-color-swatch:focus:not(:hover) {
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

#customBackgroundColor {
    width: 100%;
    height: 32px;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: linear-gradient(45deg, #f8f9fa, #ffffff);
    position: relative;
    overflow: hidden;
}

#customBackgroundColor::before {
    content: 'Custom Color';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
    color: #6c757d;
    font-weight: 500;
    pointer-events: none;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

#customBackgroundColor:hover {
    border-color: #007bff;
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.2);
}

#customBackgroundColor:hover::before {
    opacity: 1;
}

#customBackgroundColor:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

/* Background color button active state */
#backgroundColorBtn.active {
    background: linear-gradient(135deg, #6f42c1 0%, #5a2d91 100%);
    border-color: #5a2d91;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(111, 66, 193, 0.3);
}

/* Color indicator for background color button */
#backgroundColorBtn .color-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    transition: all 0.2s ease;
}

#backgroundColorBtn:hover .color-indicator {
    transform: scale(1.1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* Background color button hover effect */
#backgroundColorBtn:hover {
    background: linear-gradient(135deg, #7952b3 0%, #6f42c1 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(111, 66, 193, 0.25);
}



/* Pulse animation for background color changes */
@keyframes backgroundColorPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

#backgroundColorBtn.color-changed {
    animation: backgroundColorPulse 0.3s ease-out;
}

/* Smooth dropdown animations */
@keyframes dropdownSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.background-color-dropdown:not(.hidden) {
    animation: dropdownSlideIn 0.2s ease-out;
}

/* Unsaved changes indicator */
.action-btn-icon.unsaved-changes {
    position: relative;
    animation: pulse 2s infinite;
}

.action-btn-icon.unsaved-changes::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    background: #dc3545;
    border-radius: 50%;
    border: 2px solid white;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(220, 53, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}

/* Recovery Dialog Styles */
.recovery-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.3s ease-out;
}

.recovery-dialog {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 90%;
    animation: slideUp 0.3s ease-out;
}

.recovery-dialog-header {
    padding: 20px 20px 0 20px;
    border-bottom: 1px solid #e9ecef;
}

.recovery-dialog-header h3 {
    margin: 0 0 15px 0;
    color: #2c3e50;
    font-size: 18px;
    font-weight: 600;
}

.recovery-dialog-content {
    padding: 20px;
}

.recovery-dialog-content p {
    margin: 0 0 20px 0;
    color: #495057;
    line-height: 1.5;
}

.recovery-dialog-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.recovery-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.recovery-btn.primary {
    background: #007bff;
    color: white;
}

.recovery-btn.primary:hover {
    background: #0056b3;
    transform: translateY(-1px);
}

.recovery-btn.secondary {
    background: #6c757d;
    color: white;
}

.recovery-btn.secondary:hover {
    background: #545b62;
    transform: translateY(-1px);
}

/* Notification Animations */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Mobile adjustments for recovery dialog */
@media (max-width: 480px) {
    .recovery-dialog {
        max-width: 95%;
        margin: 20px;
    }
    
    .recovery-dialog-header,
    .recovery-dialog-content {
        padding: 15px;
    }
    
    .recovery-dialog-buttons {
        flex-direction: column;
        gap: 8px;
    }
    
    .recovery-btn {
        width: 100%;
        padding: 12px;
    }
}

/* Mobile adjustments for eraser group */
@media (max-width: 480px) {
    .eraser-group {
        gap: 1px;
    }
    
    .eraser-size-btn {
        width: 16px;
        height: 32px;
    }
    
    .eraser-size-btn svg {
        width: 10px;
        height: 10px;
    }
    
    .eraser-size-dropdown {
        min-width: 100px;
        padding: 6px;
    }
    
    .eraser-size-option {
        padding: 6px 8px;
        font-size: 11px;
    }
    
    .eraser-preview {
        width: 12px;
        height: 12px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .eraser-size-btn {
        width: 18px;
        height: 32px;
    }
}

/* Print styles */
@media print {
    .left-sidebar,
    .top-header,
    .status-bar {
        display: none !important;
    }
    
    .main-area {
        width: 100% !important;
        height: 100% !important;
    }
    
    .canvas-area {
        padding: 0 !important;
        background: white !important;
    }
    
    #whiteboard {
        box-shadow: none !important;
        border: 1px solid #000 !important;
        border-radius: 0 !important;
    }
}