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

html {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    padding: 20px;
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    overflow-x: hidden;
    position: relative;
    touch-action: manipulation;
    /* Prevent zoom on iOS when double-tapping */
    -webkit-text-size-adjust: 100%;
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior-y: contain;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
}

header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

header h1 {
    font-size: 3.5em;
    margin-bottom: 8px;
    font-weight: 700;
    letter-spacing: -1px;
}

header p {
    font-size: 1.1em;
    font-weight: 400;
    opacity: 0.95;
}

.main-content {
    display: flex;
    gap: 24px;
    background: white;
    border-radius: 16px;
    padding: 24px;
    position: relative;
    transition: gap 0.3s ease;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.toolbar {
    width: 280px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    max-height: calc(100vh - 200px);
    padding-right: 8px;
    /* Smooth scrolling on iOS */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sidebar collapsed state */
.main-content.sidebar-collapsed .toolbar {
    width: 0;
    min-width: 0;
    padding: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

/* Sidebar Toggle Button */
.sidebar-toggle-btn {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(calc(-800px + 280px + 24px), -50%);
    z-index: 1000;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 0 12px 12px 0;
    width: 36px;
    height: 80px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2em;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.2);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
    /* iOS Safari fixes */
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.3);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    /* Ensure button is always clickable */
    pointer-events: auto;
    /* Prevent button from being affected by transforms on parent */
    will-change: transform;
}

.sidebar-toggle-btn:hover {
    width: 42px;
    box-shadow: 2px 0 16px rgba(102, 126, 234, 0.5);
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

.sidebar-toggle-btn:active {
    transform: translate(calc(-800px + 280px + 24px), -50%) scale(0.95);
}

.main-content.sidebar-collapsed .sidebar-toggle-btn {
    transform: translate(calc(-800px + 24px), -50%);
}

.main-content.sidebar-collapsed .sidebar-toggle-btn:active {
    transform: translate(calc(-800px + 24px), -50%) scale(0.95);
}

.toggle-icon {
    transition: transform 0.3s ease;
    display: inline-block;
    line-height: 1;
}

.main-content.sidebar-collapsed .toggle-icon {
    transform: rotate(180deg);
}

/* Large desktops - perfectly centered layout */
@media (min-width: 1641px) {
    .sidebar-toggle-btn {
        /* Position relative to centered container (max-width: 1600px) */
        /* 50% - half of max-width + toolbar width + padding */
        left: 50%;
        transform: translate(calc(-800px + 280px + 24px), -50%);
    }
    
    .sidebar-toggle-btn:active {
        transform: translate(calc(-800px + 280px + 24px), -50%) scale(0.95);
    }
    
    .main-content.sidebar-collapsed .sidebar-toggle-btn {
        transform: translate(calc(-800px + 24px), -50%);
    }
    
    .main-content.sidebar-collapsed .sidebar-toggle-btn:active {
        transform: translate(calc(-800px + 24px), -50%) scale(0.95);
    }
}

/* Medium to large screens - button stays with toolbar */
@media (max-width: 1640px) and (min-width: 1025px) {
    .sidebar-toggle-btn {
        left: 20px;
        transform: translate(0, -50%);
        margin-left: calc(280px + 24px);
    }
    
    .sidebar-toggle-btn:active {
        transform: translate(0, -50%) scale(0.95);
    }
    
    .main-content.sidebar-collapsed .sidebar-toggle-btn {
        margin-left: 0;
        transform: translate(0, -50%);
    }
    
    .main-content.sidebar-collapsed .sidebar-toggle-btn:active {
        transform: translate(0, -50%) scale(0.95);
    }
}

.tool-section {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 18px;
    border: 1px solid #e9ecef;
    transition: all 0.2s ease;
}

.tool-section:hover {
    background: #f1f3f5;
    border-color: #dee2e6;
}

.tool-section h3 {
    margin-bottom: 14px;
    color: #212529;
    font-size: 0.95em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px !important;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    padding: 4px;
    margin: -4px;
    margin-bottom: 14px;
    border-radius: 6px;
    transition: background 0.15s ease;
}

.section-header:hover {
    background: rgba(102, 126, 234, 0.08);
}

.section-collapse-btn {
    background: none;
    border: none;
    color: #667eea;
    font-size: 0.9em;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
    font-weight: 700;
    min-width: 24px;
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.section-collapse-btn:hover {
    background: rgba(102, 126, 234, 0.15);
    transform: scale(1.1);
}

.tool-section.collapsed .section-collapse-btn {
    transform: rotate(-90deg);
}

.tool-section.collapsed .section-collapse-btn:hover {
    transform: rotate(-90deg) scale(1.1);
}

.section-content {
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    opacity: 1;
}

.tool-section.collapsed .section-content {
    max-height: 0;
    opacity: 0;
    margin: 0;
    padding: 0;
}

.tool-btn, .effect-btn {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 8px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 500;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    position: relative;
}

.tool-btn::after {
    content: attr(data-shortcut);
    position: absolute;
    top: 6px;
    right: 8px;
    background: rgba(102, 126, 234, 0.15);
    color: #667eea;
    font-size: 0.7em;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 4px;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.tool-btn:hover::after {
    opacity: 1;
    background: rgba(102, 126, 234, 0.25);
}

.tool-btn.active::after {
    background: rgba(255, 255, 255, 0.3);
    color: white;
    opacity: 1;
}

.tool-btn:hover, .effect-btn:hover {
    transform: translateY(-1px);
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
    background: #f8f9ff;
}

/* Active/pressed state for touch feedback */
.tool-btn:active, .effect-btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.2);
    transition: all 0.1s ease;
}

.tool-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    transform: translateY(0);
}

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

.selection-actions, .history-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 12px;
}

.selection-actions {
    grid-template-columns: repeat(3, 1fr);
}

.action-btn {
    padding: 10px 8px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    color: #495057;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.action-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
    background: #f8f9ff;
}

.action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.action-btn:active:not(:disabled) {
    transform: translateY(0) scale(0.95);
    box-shadow: 0 1px 3px rgba(102, 126, 234, 0.2);
}

.color-wheel-container {
    margin-bottom: 16px;
    padding: 14px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%);
    border-radius: 10px;
    border: 1px solid rgba(102, 126, 234, 0.15);
}

.color-wheel-container label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: #212529;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#color-picker {
    width: 100%;
    height: 48px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-appearance: none;
    appearance: none;
}

/* iOS specific color input styling */
#color-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

#color-picker::-webkit-color-swatch {
    border: none;
    border-radius: 6px;
}

#color-picker:hover {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

#color-picker:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.15);
}

.current-color-display {
    margin-top: 10px;
    text-align: center;
    padding: 10px;
    background: white;
    border-radius: 6px;
    border: 1px solid #e9ecef;
}

#color-hex {
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Courier New', monospace;
    font-weight: 600;
    font-size: 0.95em;
    color: #667eea;
    letter-spacing: 0.5px;
}

.color-palette {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.color-btn {
    width: 100%;
    height: 44px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1), inset 0 -1px 2px rgba(0, 0, 0, 0.1);
}

.color-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15), inset 0 -1px 2px rgba(0, 0, 0, 0.1);
}

.color-btn.active {
    border: 3px solid #212529;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3), 0 4px 12px rgba(0, 0, 0, 0.2);
    transform: scale(1.05);
}

.color-btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
}

#brush-size {
    width: calc(100% - 50px);
    margin-right: 12px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(to right, #667eea, #764ba2);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

#brush-size::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: white;
    border: 2px solid #667eea;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.15s;
}

#brush-size::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 3px 8px rgba(102, 126, 234, 0.4);
}

#brush-size::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: white;
    border: 2px solid #667eea;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.15s;
}

#brush-size::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 3px 8px rgba(102, 126, 234, 0.4);
}

#size-display {
    font-weight: 700;
    font-size: 1.3em;
    color: #667eea;
    display: inline-block;
    min-width: 35px;
    text-align: center;
}

.rotation-display {
    text-align: center;
    padding: 12px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%);
    border-radius: 10px;
    border: 1px solid rgba(102, 126, 234, 0.15);
}

#rotation-angle {
    display: block;
    font-weight: 700;
    font-size: 1.8em;
    color: #667eea;
    margin-bottom: 4px;
}

.rotation-hint {
    font-size: 0.75em;
    color: #6c757d;
    font-weight: 500;
    opacity: 0.8;
}

.mobile-hint {
    display: none;
}

@media (max-width: 768px) {
    .desktop-hint {
        display: none;
    }
    
    .mobile-hint {
        display: inline;
    }
}

.pattern-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.pattern-btn {
    padding: 8px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.pattern-btn:hover {
    transform: translateY(-1px);
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.pattern-btn.active {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
    background: #f8f9ff;
}

.pattern-btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
}

.pattern-preview {
    width: 100%;
    height: 40px;
    border-radius: 4px;
    position: relative;
}

.pattern-preview.solid {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.pattern-preview.transparent {
    background: white;
    border: 3px solid #667eea;
    box-sizing: border-box;
    position: relative;
}

.pattern-preview.transparent::after {
    content: '∅';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    color: #667eea;
    font-weight: bold;
}

.pattern-preview.horizontal {
    background: repeating-linear-gradient(
        0deg,
        #667eea,
        #667eea 4px,
        white 4px,
        white 8px
    );
}

.pattern-preview.vertical {
    background: repeating-linear-gradient(
        90deg,
        #667eea,
        #667eea 4px,
        white 4px,
        white 8px
    );
}

.pattern-preview.diagonal {
    background: repeating-linear-gradient(
        45deg,
        #667eea,
        #667eea 6px,
        white 6px,
        white 12px
    );
}

.pattern-preview.checkerboard {
    background-image: 
        linear-gradient(45deg, #667eea 25%, transparent 25%),
        linear-gradient(-45deg, #667eea 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #667eea 75%),
        linear-gradient(-45deg, transparent 75%, #667eea 75%);
    background-size: 12px 12px;
    background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
    background-color: white;
}

.pattern-preview.dots {
    background-image: radial-gradient(circle, #667eea 25%, transparent 25%);
    background-size: 10px 10px;
    background-color: white;
}

.secondary-color-section {
    margin-top: 12px;
}

.secondary-color-section label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #495057;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mirror-toggle {
    margin-top: 12px;
}

.mirror-toggle .action-btn {
    width: 100%;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.action-btn.is-active {
    border-color: #667eea;
    background: #f1f3ff;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
    color: #4c5bd9;
}

#secondary-color {
    width: 100%;
    height: 40px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-appearance: none;
    appearance: none;
}

#secondary-color:hover {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

#secondary-color::-webkit-color-swatch-wrapper {
    padding: 0;
}

#secondary-color::-webkit-color-swatch {
    border: none;
    border-radius: 6px;
}

#font-selector {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background: white;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23667eea' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    color: #495057;
}

#font-selector:hover {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

#font-selector:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.15);
}

#font-selector option {
    padding: 8px;
}

/* Show each font in its own style in the dropdown */
#font-selector option[value="Arial"] { font-family: Arial; }
#font-selector option[value="Helvetica"] { font-family: Helvetica; }
#font-selector option[value="Times New Roman"] { font-family: "Times New Roman"; }
#font-selector option[value="Georgia"] { font-family: Georgia; }
#font-selector option[value="Courier New"] { font-family: "Courier New"; }
#font-selector option[value="Verdana"] { font-family: Verdana; }
#font-selector option[value="Trebuchet MS"] { font-family: "Trebuchet MS"; }
#font-selector option[value="Impact"] { font-family: Impact; }
#font-selector option[value="Comic Sans MS"] { font-family: "Comic Sans MS"; }
#font-selector option[value="Brush Script MT"] { font-family: "Brush Script MT"; }
#font-selector option[value="Lucida Console"] { font-family: "Lucida Console"; }
#font-selector option[value="Monaco"] { font-family: Monaco; }
#font-selector option[value="Palatino"] { font-family: Palatino; }
#font-selector option[value="Garamond"] { font-family: Garamond; }
#font-selector option[value="Bookman"] { font-family: Bookman; }
#font-selector option[value="Avant Garde"] { font-family: "Avant Garde"; }
#font-selector option[value="Copperplate"] { font-family: Copperplate; }
#font-selector option[value="Papyrus"] { font-family: Papyrus; }
#font-selector option[value="Luminari"] { font-family: Luminari; }
#font-selector option[value="American Typewriter"] { font-family: "American Typewriter"; }

.case-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 12px;
}

.case-btn {
    padding: 10px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    color: #495057;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.case-btn:hover {
    transform: translateY(-1px);
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
    background: #f8f9ff;
}

.case-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    transform: translateY(0);
}

.case-btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
}

.font-preview {
    margin-top: 12px;
    padding: 12px;
    background: white;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    text-align: center;
    font-size: 1.2em;
    font-weight: 600;
    color: #667eea;
    transition: all 0.2s ease;
}

.emoji-categories {
    max-height: 500px;
    overflow-y: auto;
    padding-right: 4px;
}

.emoji-category {
    margin-bottom: 18px;
}

.emoji-category h4 {
    margin-bottom: 10px;
    color: #495057;
    font-size: 0.8em;
    font-weight: 600;
    padding: 8px 10px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%);
    border-radius: 6px;
    border-left: 3px solid #667eea;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.emoji-btn {
    padding: 10px;
    font-size: 1.6em;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    font-weight: 600;
}

/* Special styling for letter/number stamps */
.emoji-btn[data-emoji="A"],
.emoji-btn[data-emoji="B"],
.emoji-btn[data-emoji="C"],
.emoji-btn[data-emoji="D"],
.emoji-btn[data-emoji="E"],
.emoji-btn[data-emoji="F"],
.emoji-btn[data-emoji="G"],
.emoji-btn[data-emoji="H"],
.emoji-btn[data-emoji="I"],
.emoji-btn[data-emoji="J"],
.emoji-btn[data-emoji="K"],
.emoji-btn[data-emoji="L"],
.emoji-btn[data-emoji="M"],
.emoji-btn[data-emoji="N"],
.emoji-btn[data-emoji="O"],
.emoji-btn[data-emoji="P"],
.emoji-btn[data-emoji="Q"],
.emoji-btn[data-emoji="R"],
.emoji-btn[data-emoji="S"],
.emoji-btn[data-emoji="T"],
.emoji-btn[data-emoji="U"],
.emoji-btn[data-emoji="V"],
.emoji-btn[data-emoji="W"],
.emoji-btn[data-emoji="X"],
.emoji-btn[data-emoji="Y"],
.emoji-btn[data-emoji="Z"],
.emoji-btn[data-emoji="0"],
.emoji-btn[data-emoji="1"],
.emoji-btn[data-emoji="2"],
.emoji-btn[data-emoji="3"],
.emoji-btn[data-emoji="4"],
.emoji-btn[data-emoji="5"],
.emoji-btn[data-emoji="6"],
.emoji-btn[data-emoji="7"],
.emoji-btn[data-emoji="8"],
.emoji-btn[data-emoji="9"],
.emoji-btn[data-emoji="!"],
.emoji-btn[data-emoji="?"],
.emoji-btn[data-emoji="&"],
.emoji-btn[data-emoji="@"],
.emoji-btn[data-emoji="#"],
.emoji-btn[data-emoji="$"],
.emoji-btn[data-emoji="%"],
.emoji-btn[data-emoji="*"],
.emoji-btn[data-emoji="+"],
.emoji-btn[data-emoji="-"],
.emoji-btn[data-emoji="="],
.emoji-btn[data-emoji="/"] {
    background: linear-gradient(135deg, #f8f9ff 0%, #e8eeff 100%);
    color: #667eea;
    font-weight: 700;
    font-size: 1.4em;
}

.emoji-btn:hover {
    transform: scale(1.15);
    background: linear-gradient(135deg, #f8f9ff 0%, #fff5f8 100%);
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
    z-index: 1;
}

.emoji-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    transform: scale(1.1);
}

.emoji-btn:active {
    transform: scale(1.05);
    transition: transform 0.1s ease;
}

.emoji-btn.active:active {
    transform: scale(1.0);
}

.effect-btn {
    background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
    border-color: #fdc830;
    color: #5a4a00;
    font-weight: 600;
}

.effect-btn:hover {
    background: linear-gradient(135deg, #ffd700 0%, #fdc830 100%);
    box-shadow: 0 4px 12px rgba(253, 203, 48, 0.3);
}

.effect-btn.active {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
    border-color: #c92a2a;
    color: white;
    box-shadow: 0 4px 12px rgba(238, 90, 111, 0.4);
    transform: scale(1.05);
}

.save-btn {
    width: 100%;
    padding: 14px 16px;
    margin-top: 8px;
    border: 2px solid #10b981;
    border-radius: 8px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.save-btn:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.save-btn:active {
    transform: scale(0.97);
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.4);
}

.clear-btn {
    width: 100%;
    padding: 14px 16px;
    margin-top: 8px;
    border: 2px solid #ef4444;
    border-radius: 8px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.clear-btn:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

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

.help-btn {
    width: 100%;
    padding: 12px 16px;
    margin-top: 8px;
    border: 2px solid #667eea;
    border-radius: 8px;
    background: linear-gradient(135deg, #f8f9ff 0%, #e8eeff 100%);
    color: #667eea;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.help-btn:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

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

.zoom-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.zoom-btn {
    flex: 1;
    padding: 10px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 1.2em;
    font-weight: 600;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    color: #667eea;
}

.zoom-btn:hover {
    transform: translateY(-1px);
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
    background: #f8f9ff;
}

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

#zoom-display {
    font-weight: 700;
    font-size: 1.2em;
    color: #667eea;
    min-width: 60px;
    text-align: center;
}

.save-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 2px solid #e9ecef;
}

.save-section label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #495057;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#export-size-selector,
#canvas-size-selector {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background: white;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23667eea' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    color: #495057;
}

#export-size-selector:hover,
#canvas-size-selector:hover {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

#export-size-selector:focus,
#canvas-size-selector:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.15);
}

/* Custom Context Menu */
.context-menu {
    position: fixed;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.05);
    padding: 0;
    z-index: 10000;
    min-width: 200px;
    max-width: 280px;
    -webkit-user-select: none;
    user-select: none;
    animation: contextMenuFadeIn 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

@keyframes contextMenuFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-5px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.context-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px 12px 0 0;
}

.context-menu-header-title {
    color: white;
    font-weight: 700;
    font-size: 0.9em;
    letter-spacing: 0.5px;
}

.context-menu-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 700;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.context-menu-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.context-menu-close:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.4);
}

.context-menu-section {
    padding: 8px;
}

.context-menu-title {
    padding: 6px 12px;
    font-size: 0.75em;
    font-weight: 700;
    color: #667eea;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.context-menu-item {
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: white;
    text-align: left;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 500;
    color: #212529;
    border-radius: 6px;
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.context-menu-item:hover {
    background: linear-gradient(135deg, #f8f9ff 0%, #e8eeff 100%);
    color: #667eea;
    transform: translateX(4px);
}

.context-menu-item:active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    transform: scale(0.98);
}

.context-menu-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, #e9ecef 20%, #e9ecef 80%, transparent);
    margin: 6px 8px;
}

/* Mobile context menu improvements */
@media (max-width: 768px) {
    .context-menu {
        min-width: 220px;
        max-width: 90vw;
    }
    
    .context-menu-item {
        padding: 14px 18px;
        font-size: 1em;
        min-height: 48px;
    }
    
    .context-menu-title {
        padding: 8px 14px;
        font-size: 0.8em;
    }
}

/* Help Modal */
.help-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10001;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.help-modal-content {
    background: white;
    border-radius: 16px;
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    -webkit-overflow-scrolling: touch;
}

.help-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 16px 16px 0 0;
}

.help-modal-header h2 {
    margin: 0;
    color: white;
    font-size: 1.4em;
    font-weight: 700;
}

.help-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2em;
    font-weight: 700;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.help-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.help-modal-body {
    padding: 24px;
}

.help-section {
    margin-bottom: 24px;
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section h3 {
    margin-bottom: 12px;
    color: #667eea;
    font-size: 1.1em;
    font-weight: 700;
}

.help-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 16px;
    align-items: center;
}

.help-grid span:nth-child(odd) {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.9em;
    text-align: center;
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
}

.help-grid span:nth-child(even) {
    color: #495057;
    font-weight: 500;
}

.help-list {
    color: #495057;
}

.help-list p {
    margin-bottom: 8px;
    line-height: 1.6;
}

.help-list strong {
    color: #667eea;
    font-weight: 700;
}

@media (max-width: 768px) {
    .help-modal-content {
        max-height: 90vh;
        margin: 10px;
    }
    
    .help-modal-header {
        padding: 16px 20px;
    }
    
    .help-modal-header h2 {
        font-size: 1.2em;
    }
    
    .help-modal-body {
        padding: 20px;
    }
}

.canvas-container {
    flex: 1;
    background: linear-gradient(135deg, #fafafa 0%, #f5f5f5 100%);
    border-radius: 12px;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.06);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 600px;
    padding: 20px;
    overflow: auto; /* Allow scrolling when zoomed */
    position: relative;
    /* Prevent overscroll on iOS */
    overscroll-behavior: contain;
    /* Smooth scrolling for zoomed canvas */
    -webkit-overflow-scrolling: touch;
}

#drawing-canvas {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background: white;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.2s ease, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    /* Canvas sizing and zoom handling */
    display: block;
    margin: auto; /* Center when smaller than container */
    max-width: 100%; /* Prevent overflow when not zoomed */
    max-height: 100%;
    width: auto;
    height: auto;
    transform-origin: center center;
    /* Ensure proper sizing */
    object-fit: contain;
}

#drawing-canvas:hover {
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.15);
}

#drawing-canvas.drawing-active {
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.25);
}

/* When zoomed, allow canvas to exceed container */
.canvas-container.zoomed {
    overflow: auto;
    justify-content: flex-start;
    align-items: flex-start;
}

.canvas-container.zoomed #drawing-canvas {
    max-width: none;
    max-height: none;
    margin: 0;
}

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific styles */
    body {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    #drawing-canvas {
        /* Prevent rubber-band scrolling on canvas */
        overscroll-behavior: contain;
    }
    
    input[type="color"] {
        /* Better color picker on iOS */
        -webkit-appearance: none;
        appearance: none;
        border: 2px solid #dee2e6;
        padding: 0;
    }
    
    input[type="range"] {
        /* Better slider appearance on iOS */
        -webkit-appearance: none;
        appearance: none;
    }
}

/* Layer Panel Styles */
.layer-panel {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 280px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    border: 2px solid #e9ecef;
    overflow: hidden;
    transition: all 0.3s ease;
    z-index: 10;
}

.layer-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    cursor: pointer;
    user-select: none;
}

.layer-panel-header h3 {
    margin: 0;
    color: white;
    font-size: 1em;
    font-weight: 600;
}

.layer-toggle-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.layer-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.layer-panel.collapsed .layer-toggle-btn {
    transform: rotate(-90deg);
}

.layer-panel.collapsed .layer-panel-content {
    max-height: 0;
    padding: 0;
}

.layer-panel-content {
    max-height: 400px;
    overflow: hidden;
    transition: all 0.3s ease;
    padding: 12px;
}

.layer-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}

.layer-control-btn {
    padding: 8px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 1.1em;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.layer-control-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
    background: #f8f9ff;
}

.layer-control-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.layers-list {
    max-height: 240px;
    overflow-y: auto;
    margin-bottom: 12px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    background: #f8f9fa;
}

.layer-item {
    display: flex;
    align-items: center;
    padding: 10px;
    margin: 4px;
    background: white;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.layer-item:hover {
    background: #f8f9ff;
    border-color: #667eea;
}

.layer-item.active {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.layer-thumbnail {
    width: 40px;
    height: 30px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    margin-right: 10px;
    background: white;
    flex-shrink: 0;
    image-rendering: pixelated;
}

.layer-info {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.layer-name {
    font-weight: 600;
    font-size: 0.9em;
    color: #212529;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.layer-name-input {
    width: 100%;
    border: 2px solid #667eea !important;
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 0.9em;
    font-weight: 600;
    font-family: inherit;
    background: white;
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.layer-name-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.25);
}

.layer-rename-btn {
    background: none;
    border: none;
    font-size: 1em;
    cursor: pointer;
    padding: 4px 6px;
    margin-left: 4px;
    border-radius: 4px;
    transition: all 0.15s ease;
    opacity: 0.5;
    line-height: 1;
}

.layer-rename-btn:hover {
    background: rgba(102, 126, 234, 0.1);
    opacity: 1;
    transform: scale(1.1);
}

.layer-rename-btn:active {
    transform: scale(0.95);
    background: rgba(102, 126, 234, 0.2);
}

/* Show rename button on hover or touch */
.layer-item:hover .layer-rename-btn,
.layer-item.active .layer-rename-btn {
    opacity: 0.8;
}

@media (max-width: 768px) {
    /* Always show rename button on mobile */
    .layer-rename-btn {
        opacity: 0.7;
        min-width: 32px;
        min-height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

.layer-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.layer-visibility-btn {
    background: none;
    border: none;
    font-size: 1.1em;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.15s ease;
    opacity: 0.6;
}

.layer-visibility-btn:hover {
    background: rgba(102, 126, 234, 0.1);
    opacity: 1;
}

.layer-visibility-btn.visible {
    opacity: 1;
}

.layer-move-btns {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.layer-move-btn {
    background: none;
    border: none;
    font-size: 0.8em;
    cursor: pointer;
    padding: 0 4px;
    border-radius: 3px;
    transition: all 0.15s ease;
    line-height: 1;
    opacity: 0.6;
}

.layer-move-btn:hover:not(:disabled) {
    background: rgba(102, 126, 234, 0.1);
    opacity: 1;
}

.layer-move-btn:disabled {
    opacity: 0.2;
    cursor: not-allowed;
}

.layer-opacity-control {
    padding-top: 8px;
    border-top: 2px solid #e9ecef;
}

.layer-opacity-control label {
    display: block;
    font-size: 0.85em;
    font-weight: 600;
    color: #495057;
    margin-bottom: 6px;
}

#layer-opacity {
    width: calc(100% - 50px);
    margin-right: 8px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(to right, transparent, #667eea);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

#layer-opacity::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: white;
    border: 2px solid #667eea;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.15s;
}

#layer-opacity::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 3px 8px rgba(102, 126, 234, 0.4);
}

#layer-opacity::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: white;
    border: 2px solid #667eea;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.15s;
}

#layer-opacity::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 3px 8px rgba(102, 126, 234, 0.4);
}

#opacity-display {
    font-weight: 700;
    font-size: 0.9em;
    color: #667eea;
    display: inline-block;
    min-width: 42px;
    text-align: right;
}

/* Scrollbar styling */
.toolbar::-webkit-scrollbar,
.emoji-categories::-webkit-scrollbar {
    width: 6px;
}

.toolbar::-webkit-scrollbar-track,
.emoji-categories::-webkit-scrollbar-track {
    background: transparent;
}

.toolbar::-webkit-scrollbar-thumb,
.emoji-categories::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.3);
    border-radius: 3px;
    transition: background 0.2s;
}

.toolbar::-webkit-scrollbar-thumb:hover,
.emoji-categories::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.5);
}

/* Firefox scrollbar */
.toolbar,
.emoji-categories {
    scrollbar-width: thin;
    scrollbar-color: rgba(102, 126, 234, 0.3) transparent;
}

@media (max-width: 1024px) {
    .container {
        max-width: 100%;
    }
    
    header h1 {
        font-size: 2.5em;
    }
    
    .toolbar {
        width: 260px;
    }
    
    /* Adjust sidebar toggle for tablet with 260px toolbar */
    .sidebar-toggle-btn {
        margin-left: calc(260px + 24px);
    }
    
    .main-content.sidebar-collapsed .sidebar-toggle-btn {
        margin-left: 0;
    }
}

@media (max-width: 768px) {
    body {
        padding: 12px;
        padding-top: max(12px, env(safe-area-inset-top));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    
    header h1 {
        font-size: 2em;
    }
    
    header p {
        font-size: 1em;
    }
    
    .main-content {
        flex-direction: column;
        padding: 16px;
        gap: 16px;
    }
    
    .toolbar {
        width: 100%;
        max-height: 350px;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Collapsed toolbar on mobile hides vertically */
    .main-content.sidebar-collapsed .toolbar {
        max-height: 0;
        min-height: 0;
        padding: 0;
        margin: 0;
    }
    
    .canvas-container {
        min-height: 400px;
        min-height: calc(var(--vh, 1vh) * 50);
        padding: 12px;
        /* Better overflow handling on mobile when zoomed */
        overflow-x: auto;
        overflow-y: auto;
    }
    
    #drawing-canvas {
        /* On mobile, respect container width when not zoomed */
        max-width: 100%;
        height: auto;
        /* Maintain aspect ratio */
        object-fit: contain;
    }
    
    /* When zoomed on mobile, allow full canvas size */
    .canvas-container.zoomed #drawing-canvas {
        max-width: none;
        max-height: none;
    }
    
    .emoji-categories {
        max-height: 300px;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Sidebar toggle button on mobile - position at bottom of screen */
    .sidebar-toggle-btn {
        width: 48px;
        height: 48px;
        font-size: 1.2em;
        left: 50%;
        top: auto;
        bottom: 80px;
        transform: translateX(-50%);
        border-radius: 50%;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
        margin-left: 0;
        z-index: 1001;
        /* Ensure button is tappable on iOS */
        pointer-events: auto;
        position: fixed;
    }
    
    .sidebar-toggle-btn:hover {
        width: 48px;
    }
    
    .sidebar-toggle-btn:active {
        transform: translateX(-50%) scale(0.95);
        opacity: 0.8;
    }
    
    .main-content.sidebar-collapsed .sidebar-toggle-btn {
        margin-left: 0;
        transform: translateX(-50%);
    }
    
    .main-content.sidebar-collapsed .sidebar-toggle-btn:active {
        transform: translateX(-50%) scale(0.95);
    }
    
    /* Rotate icon 90 degrees on mobile for up/down instead of left/right */
    .toggle-icon {
        transform: rotate(90deg);
    }
    
    .main-content.sidebar-collapsed .toggle-icon {
        transform: rotate(-90deg);
    }
    
    /* Larger touch targets for mobile */
    .tool-btn, .effect-btn {
        padding: 14px 16px;
        font-size: 1em;
    }
    
    .color-btn {
        height: 48px;
    }
    
    .emoji-btn {
        padding: 12px;
        font-size: 1.8em;
    }
    
    /* Layer panel mobile adjustments */
    .layer-panel {
        width: calc(100% - 24px);
        bottom: 12px;
        right: 12px;
        left: 12px;
        /* Start collapsed on mobile for more canvas space */
        max-height: 56px;
    }
    
    .layer-panel:not(.collapsed) {
        max-height: 400px;
    }
    
    .layers-list {
        max-height: 180px;
        -webkit-overflow-scrolling: touch;
    }
    
    .layer-control-btn {
        font-size: 1em;
        padding: 10px;
    }
    
    /* Larger tap target for layer panel toggle on mobile */
    .layer-panel-header {
        min-height: 48px;
        padding: 14px 16px;
    }
    
    .layer-toggle-btn {
        width: 32px;
        height: 32px;
        font-size: 1em;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.8em;
    }
    
    .main-content {
        padding: 12px;
    }
    
    .toolbar {
        max-height: 300px;
    }
    
    .tool-section {
        padding: 14px;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .canvas-container {
        min-height: 300px;
        padding: 8px;
    }
}

/* Toast notification for mobile feedback */
.toast-notification {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    z-index: 10000;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    opacity: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

.toast-notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Improve touch targets on mobile */
@media (max-width: 768px) {
    .action-btn,
    .layer-control-btn,
    .layer-visibility-btn,
    .layer-move-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .color-btn {
        min-height: 48px;
        min-width: 48px;
    }
    
    .emoji-btn {
        min-height: 48px;
        min-width: 48px;
    }
    
    /* Improve layer item touch targets */
    .layer-item {
        padding: 12px;
        margin: 6px 4px;
    }
    
    /* Better spacing for touch */
    .selection-actions,
    .history-actions {
        gap: 10px;
    }
}

