* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #e0e0e0;
    min-height: 100vh;
    padding: 10px;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    overflow-x: hidden;
    margin: 0;
    /* Safari/iPad optimizations */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
    position: relative;
    /* Prevent Safari bounce effect */
    overscroll-behavior-y: contain;
}

.toolbar {
    background: white;
    padding: 15px 20px;
    margin-bottom: 10px;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

/* Scrollbar styling for toolbar */
.toolbar::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.toolbar::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.toolbar::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.toolbar::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.toolbar-label {
    font-weight: 600;
    color: #333;
}

.language-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.language-label {
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.language-dropdown {
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 5px;
    background: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: #333;
    min-width: 140px;
}

.language-dropdown:hover {
    border-color: #667eea;
    box-shadow: 0 2px 5px rgba(102, 126, 234, 0.2);
}

.language-dropdown:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.note-palette {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.note-shape {
    width: 50px;
    height: 50px;
    background: #667eea;
    color: white;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: grab;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    user-select: none;
    position: relative;
}

.note-shape[draggable="true"] {
    -webkit-user-drag: element;
}

.note-shape:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    background: #5568d3;
}

.note-shape:active {
    cursor: grabbing;
    transform: scale(0.95);
}

.note-icon {
    font-size: 20px;
    line-height: 1;
}

.note-shape span {
    font-size: 12px;
    font-weight: 600;
    margin-top: 2px;
}

#exportBtn, #clearBtn, #grabModeBtn, #quantizeBtn, #saveBtn, #loadBtn, #undoBtn, #redoBtn, #addStaffBtn, #removeStaffBtn {
    padding: 10px 20px;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    font-size: 14px;
}

.staff-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.control-label {
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.control-select {
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 5px;
    background: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: #333;
    min-width: 120px;
}

.control-select:hover {
    border-color: #667eea;
    box-shadow: 0 2px 5px rgba(102, 126, 234, 0.2);
}

.control-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#addStaffBtn {
    background: #2ecc71;
}

#addStaffBtn:hover {
    background: #27ae60;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(46, 204, 113, 0.3);
}

#removeStaffBtn {
    background: #e67e22;
}

#removeStaffBtn:hover {
    background: #d35400;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(230, 126, 34, 0.3);
}

#saveBtn {
    background: #3498db;
}

#saveBtn:hover {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(52, 152, 219, 0.3);
}

#loadBtn {
    background: #9b59b6;
}

#loadBtn:hover {
    background: #8e44ad;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(155, 89, 182, 0.3);
}

#undoBtn {
    background: #16a085;
}

#undoBtn:hover:not(:disabled) {
    background: #138d75;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(22, 160, 133, 0.3);
}

#undoBtn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

#redoBtn {
    background: #16a085;
}

#redoBtn:hover:not(:disabled) {
    background: #138d75;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(22, 160, 133, 0.3);
}

#redoBtn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

#exportBtn {
    background: #27ae60;
    margin-left: auto;
}

#exportBtn:hover {
    background: #229954;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(39, 174, 96, 0.3);
}

#clearBtn {
    background: #e74c3c;
}

#clearBtn:hover {
    background: #c0392b;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(231, 76, 60, 0.3);
}

#grabModeBtn {
    background: #3498db;
}

#grabModeBtn:hover {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(52, 152, 219, 0.3);
}

#grabModeBtn.active {
    background: #f39c12;
    border: 2px solid #e67e22;
    box-shadow: 0 0 10px rgba(243, 156, 18, 0.5);
}

#quantizeBtn {
    background: #95a5a6;
}

#quantizeBtn:hover {
    background: #7f8c8d;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(149, 165, 166, 0.3);
}

.main-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 0;
    margin-top: 0;
}

.page-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}


.duration-palette {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.duration-shape {
    width: 70px;
    height: 60px;
    background: #9b59b6;
    color: white;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    user-select: none;
}

.duration-shape:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(155, 89, 182, 0.3);
    background: #8e44ad;
}

.duration-shape.selected {
    background: #f39c12;
    border: 3px solid #e67e22;
    box-shadow: 0 0 15px rgba(243, 156, 18, 0.6);
    transform: scale(1.05);
}

.duration-icon {
    font-size: 24px;
    line-height: 1;
    margin-bottom: 4px;
}

.duration-shape span {
    font-size: 11px;
    font-weight: 600;
}

.accidental-palette {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.accidental-shape {
    width: 50px;
    height: 50px;
    background: #34495e;
    color: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    user-select: none;
    font-size: 24px;
    font-weight: bold;
}

.accidental-shape:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(52, 73, 94, 0.3);
    background: #2c3e50;
}

.accidental-shape.selected {
    background: #f39c12;
    border: 3px solid #e67e22;
    box-shadow: 0 0 15px rgba(243, 156, 18, 0.6);
    transform: scale(1.1);
}

.a4-page {
    width: 210mm;
    min-height: 297mm;
    background: white;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    padding: 20mm;
    position: relative;
}

#output {
    width: 100%;
    min-height: 100%;
    position: relative;
    margin-top: 0;
    padding-top: 0;
}

#vex-canvas {
    width: 642px;
    max-width: 100%;
    overflow: visible;
    transform: none !important;
    zoom: 1 !important;
    display: block;
    margin: 0 auto;
    /* Safari/iPad optimizations */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    /* Prevent Safari from scaling canvas */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    /* Ensure canvas is interactive on Safari - CRITICAL */
    pointer-events: auto !important;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    /* Safari: Prevent touch event blocking */
    -webkit-user-drag: none;
    -webkit-appearance: none;
    /* Force Safari to allow touch events */
    cursor: pointer;
}

#output canvas {
    display: block !important;
    width: 642px;
    max-width: 100%;
    height: auto;
    transform: none !important;
    zoom: 1 !important;
    /* Safari/iPad optimizations */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    pointer-events: auto;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.drag-over {
    background-color: #f0f8ff !important;
    border: 2px dashed #667eea !important;
    transition: all 0.2s;
}

#output.drag-over {
    background-color: rgba(102, 126, 234, 0.1) !important;
}

#output canvas {
    cursor: crosshair;
}

#output canvas:hover {
    cursor: crosshair;
}

#output {
    position: relative;
}

/* Tip banner removed */

.note-shape.dragging {
    opacity: 0.5;
    transform: scale(0.9);
}

.note-shape.selected {
    background: #f39c12;
    border: 3px solid #e67e22;
    box-shadow: 0 0 15px rgba(243, 156, 18, 0.6);
    transform: scale(1.1);
}

.toolbar {
    position: sticky;
    top: 0;
    z-index: 100;
    max-height: 50vh;
    overflow-y: auto;
    overflow-x: hidden;
}

@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;
    }
}

/* iPad and Tablet specific optimizations */
@media (min-width: 481px) and (max-width: 1024px) {
    /* Safari/iPad specific fixes */
    #vex-canvas {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        will-change: transform;
    }
    
    .main-container {
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
    }
}

/* Mobile and Tablet Responsive Styles */
@media (max-width: 768px) {
    body {
        padding: 5px;
        /* Safari mobile optimizations */
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: none;
    }
    
    .toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 12px;
        max-height: 40vh;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 10px;
    }
    
    .toolbar-label {
        text-align: center;
        margin-bottom: 5px;
        font-size: 14px;
    }
    
    .duration-palette {
        justify-content: center;
        gap: 8px;
    }
    
    .duration-shape {
        width: 60px;
        height: 55px;
        min-width: 60px;
        min-height: 55px;
    }
    
    .duration-icon {
        font-size: 20px;
    }
    
    .duration-shape span {
        font-size: 10px;
    }
    
    .accidental-shape {
        width: 45px;
        height: 45px;
        font-size: 20px;
    }
    
    .staff-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    
    .control-select {
        width: 100%;
        min-width: auto;
    }
    
    .language-selector {
        flex-direction: column;
        align-items: stretch;
        gap: 5px;
    }
    
    .language-dropdown {
        width: 100%;
        min-width: auto;
    }
    
    #exportBtn, #clearBtn, #grabModeBtn, #quantizeBtn, #saveBtn, #loadBtn, #undoBtn, #redoBtn, #addStaffBtn, #removeStaffBtn {
        padding: 12px 20px;
        font-size: 16px;
        min-height: 44px;
        width: 100%;
        margin: 5px 0;
    }
    
    #exportBtn {
        margin-left: 0;
    }
    
    .a4-page {
        width: 100%;
        max-width: 100%;
        padding: 10mm;
        min-height: auto;
        margin-top: 0;
    }
    
    /* Tip banner removed */
    
    .main-container {
        padding: 0;
        margin-top: 0;
    }
    
    .page-container {
        width: 100%;
        margin-top: 0;
    }
    
    #output {
        margin-top: 0;
        padding-top: 0;
    }
}

@media (max-width: 480px) {
    .toolbar {
        padding: 10px;
        gap: 10px;
        max-height: 35vh;
    }
    
    .duration-palette {
        gap: 6px;
    }
    
    .duration-shape {
        width: 55px;
        height: 50px;
        min-width: 55px;
        min-height: 50px;
    }
    
    .duration-icon {
        font-size: 18px;
    }
    
    .duration-shape span {
        font-size: 9px;
    }
    
    .accidental-shape {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    #exportBtn, #clearBtn, #grabModeBtn, #quantizeBtn, #saveBtn, #loadBtn, #undoBtn, #redoBtn, #addStaffBtn, #removeStaffBtn {
        padding: 14px 18px;
        font-size: 15px;
    }
    
    .a4-page {
        padding: 5mm;
        margin-top: 0;
    }
    
    /* Tip banner removed */
}

/* iPad and Tablet specific optimizations */
@media (min-width: 481px) and (max-width: 1024px) {
    /* Safari/iPad specific fixes */
    #vex-canvas {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        will-change: transform;
        /* Ensure canvas is interactive on Safari iPad */
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    .main-container {
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
        overscroll-behavior: none;
    }
    
    .toolbar {
        flex-wrap: wrap;
        gap: 15px;
        max-height: 45vh;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
    
    .duration-shape {
        width: 65px;
        height: 58px;
        min-width: 65px;
        min-height: 58px;
    }
    
    #exportBtn, #clearBtn, #grabModeBtn, #quantizeBtn, #saveBtn, #loadBtn, #undoBtn, #redoBtn, #addStaffBtn, #removeStaffBtn {
        padding: 11px 18px;
        font-size: 15px;
        min-height: 44px;
    }
    
    .a4-page {
        width: 95%;
        max-width: 95%;
        margin-top: 0;
    }
    
    .main-container {
        margin-top: 0;
    }
    
    #output {
        margin-top: 0;
        padding-top: 0;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .duration-shape:hover {
        transform: none;
    }
    
    .duration-shape:active {
        transform: scale(0.95);
        background: #8e44ad;
    }
    
    #exportBtn:hover, #clearBtn:hover, #grabModeBtn:hover, #quantizeBtn:hover, #saveBtn:hover, #loadBtn:hover, #undoBtn:hover, #redoBtn:hover {
        transform: none;
    }
    
    #exportBtn:active, #clearBtn:active, #grabModeBtn:active, #quantizeBtn:active, #saveBtn:active, #loadBtn:active, #undoBtn:active, #redoBtn:active {
        transform: scale(0.98);
    }
    
    #output canvas {
        touch-action: manipulation;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        pointer-events: auto;
    }
    
    .main-container {
        -webkit-overflow-scrolling: touch;
    }
    
    #output {
        touch-action: manipulation;
        pointer-events: auto;
    }
    
    #output canvas {
        touch-action: manipulation;
        pointer-events: auto;
    }
}
