/* Global styles */
body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    background: #1a1a1a;
    color: #fff;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Main container */
#container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

#canvas-container {
    position: relative;
    border: none;
    overflow: hidden;
    background: #222;
    flex: 1;
}

canvas {
    display: block;
    cursor: crosshair;
}

/* Controls panel */
#controls {
    padding: 5px 10px;
    display: flex;
    gap: 10px;
    background: #333;
    border-bottom: 1px solid #555;
    align-items: center;
    height: 36px;
}

/* Control groups */
.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-group.transport {
    gap: 4px;
}

.control-group.volume-group {
    padding: 0;
}

.control-group.volume-group label {
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.control-group.volume-group input[type="range"] {
    width: 80px;
}

.snap-mode-button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #444;
    border: 1px solid #666;
    border-radius: 4px;
    color: #ccc;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.snap-mode-button:hover {
    background: #555;
    border-color: #777;
}

.snap-mode-button.high-res {
    background: #2a5f3f;
    border-color: #3a7f4f;
    color: #fff;
}

.snap-mode-button.high-res svg rect {
    width: 1px;
}

.control-spacer {
    flex: 1;
    min-width: 20px;
}

.control-group.loop {
    margin-left: 0;
    padding-left: 0;
}


/* Loop range container */
.loop-range-container {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #2a2a2a;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #444;
}

.loop-range-container span {
    color: #aaa;
    font-size: 11px;
}

.loop-range-container span:first-child {
    color: #ccc;
    margin-right: 2px;
}

.loop-range-container input[type="number"] {
    width: 35px;
    background: #1a1a1a;
    border: 1px solid #3a3a3a;
    font-size: 11px;
    color: #fff;
    text-align: center;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 3px;
}

.loop-range-container input[type="number"]:focus {
    outline: none;
    border-color: #555;
    background: #222;
}

/* Button styles */
button {
    padding: 4px 8px;
    background: #333;
    color: #fff;
    border: 1px solid #555;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

/* Transport buttons (play/stop) */
.transport button {
    padding: 4px 6px;
    min-width: 28px;
}

button:hover {
    background: #444;
}

button:active {
    background: #555;
}

button.active {
    background: #4a9eff;
    border-color: #357abd;
}

#loopBtn {
    background: #444;
    border: 1px solid #666;
    padding: 4px 6px;
    min-width: 28px;
}

#loopBtn.active {
    background: #ff8800;
    border-color: #ff8800;
}

button svg {
    pointer-events: none;
}

/* Typography */
h1 {
    margin: 0;
    font-size: 14px;
    padding-right: 10px;
}

/* Form controls */
input[type="range"] {
    width: 100px;
    height: 4px;
    background: #444;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    border-radius: 2px;
    position: relative;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    background: #ff8800;
    cursor: pointer;
    border-radius: 50%;
}

input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: #ff8800;
    cursor: pointer;
    border-radius: 50%;
    border: none;
}

label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #ccc;
}

.checkbox-label {
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

select {
    background: #2a2a2a;
    color: #fff;
    border: 1px solid #444;
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    outline: none;
    height: 26px;
}

select:hover {
    background: #333;
    border-color: #555;
}

/* Menu bar */
#menubar {
    background: #2a2a2a;
    border-bottom: 1px solid #444;
    display: flex;
    user-select: none;
    font-size: 13px;
    height: 24px;
    align-items: center;
}

/* Menu spacer */
.menu-spacer {
    flex: 1;
}

/* Menu instrument selector */
.menu-instrument-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 15px;
    font-size: 12px;
}

.menu-instrument-selector label {
    color: #ccc;
    margin: 0;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.menu-instrument-selector select {
    height: 20px;
    padding: 2px 6px;
    font-size: 11px;
}

.menu-instrument-selector #instrumentColorIndicator {
    width: 14px;
    height: 14px;
    border-width: 1px;
}

.menu-item {
    position: relative;
    padding: 0 12px;
    height: 100%;
    display: flex;
    align-items: center;
    cursor: pointer;
}

.menu-item:hover,
.menu-item.active {
    background: #444;
}

.menu-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: #2a2a2a;
    border: 1px solid #444;
    border-top: none;
    min-width: 200px;
    display: none;
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}


.menu-item.active .menu-dropdown {
    display: block;
}

.menu-option {
    padding: 6px 20px;
    cursor: pointer;
    position: relative;
}

.menu-option:hover:not(.disabled) {
    background: #444;
}

.menu-option.disabled {
    color: #666;
    cursor: not-allowed;
}

.menu-separator {
    height: 1px;
    background: #444;
    margin: 4px 0;
}

.menu-checkbox {
    padding-left: 30px;
}

.menu-check {
    position: absolute;
    left: 8px;
    /* Remove opacity-based hiding since we're using text content */
}

.menu-submenu {
    position: absolute;
    left: 100%;
    top: 0;
    background: #2a2a2a;
    border: 1px solid #444;
    min-width: 200px;
    display: none;
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 1002;
}

.menu-option.has-submenu {
    padding-right: 30px;
    position: relative;
}

/* Show direct submenu when hovering parent */
.menu-option.has-submenu:hover > .menu-submenu {
    display: block !important;
}

/* Ensure nested submenus work */
.menu-submenu .menu-option.has-submenu:hover > .menu-submenu {
    display: block !important;
}

.submenu-arrow {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    color: #999;
    font-family: inherit;
}

.menu-shortcut {
    float: right;
    color: #888;
    margin-left: 20px;
}

/* Pan and velocity bars */
#pan-bar,
#velocity-bar {
    background: #333;
    border-top: 1px solid #555;
    height: 60px;
    position: relative;
}

#pan-container,
#velocity-container {
    width: 100%;
    height: 100%;
    background: #222;
    position: relative;
    overflow: hidden;
}

#panCanvas,
#velocityCanvas {
    display: block;
    cursor: pointer;
}

/* Loop range inputs */
.loop-range-container input[type="number"] {
    outline: none;
    padding: 2px 4px;
}

.loop-range-container input[type="number"]:focus {
    background: #1a1a1a !important;
    border-radius: 2px;
}

/* Hide spin buttons for a cleaner look */
.loop-range-container input[type="number"]::-webkit-outer-spin-button,
.loop-range-container input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.loop-range-container input[type="number"] {
    -moz-appearance: textfield;
}

.loop-range-container .loop-label {
    color: #888;
    font-size: 12px;
}

.loop-range-container .loop-separator {
    color: #666;
}

/* Hover effect for loop container */
.loop-range-container:hover {
    background: #2f2f2f !important;
    border-color: #555 !important;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: #2a2a2a;
    padding: 20px;
    border: 1px solid #555;
    width: 500px;
    max-width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    border-radius: 4px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #444;
}

.modal-title {
    font-size: 16px;
    font-weight: normal;
    color: #fff;
    margin: 0;
}

.modal-close {
    font-size: 24px;
    cursor: pointer;
    color: #999;
    background: none;
    border: none;
    padding: 0;
    width: 30px;
    height: 30px;
}

.modal-close:hover {
    color: #fff;
}

.song-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.song-item {
    padding: 10px;
    cursor: pointer;
    border: 1px solid #444;
    margin-bottom: 5px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.song-item:hover {
    background-color: #3a3a3a;
}

/* Credits */
.credits {
    position: fixed;
    bottom: 10px;
    right: 10px;
    font-size: 12px;
    color: #888;
    text-align: right;
}

.credits a {
    color: #4a9eff;
    text-decoration: none;
}

.credits a:hover {
    text-decoration: underline;
}

/* Notification styles */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background-color: #333;
    color: #fff;
    padding: 15px 20px;
    border-radius: 4px;
    border: 1px solid #555;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    z-index: 1100;
    max-width: 400px;
    animation: slideIn 0.3s ease-out;
}

.notification.error {
    background-color: #5a2020;
    border-color: #aa4444;
}

.notification.info {
    background-color: #204a5a;
    border-color: #4488aa;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

.notification.hiding {
    animation: slideOut 0.3s ease-in;
}


/* Info modal for About and Shortcuts */
.info-modal {
    white-space: normal;
    line-height: 1.6;
    color: #e0e0e0;
    padding: 10px 0;
}

.info-modal h2 {
    font-size: 20px;
    margin-bottom: 10px;
}

.info-modal h3 {
    font-size: 14px;
    color: #4a9eff;
    margin-top: 20px;
    margin-bottom: 10px;
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.info-modal p {
    margin: 10px 0;
}

/* Keyboard shortcuts styling */
.shortcuts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 25px;
    white-space: normal;
}

.shortcut-section {
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 15px;
}

.shortcut-section h3 {
    margin: 0 0 12px 0;
    color: #4a9eff;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.shortcut-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid #333;
}

.shortcut-item:last-child {
    border-bottom: none;
}

.shortcut-key {
    background: #333;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    font-weight: bold;
    border: 1px solid #555;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    white-space: nowrap;
}

.shortcut-desc {
    color: #ccc;
    font-size: 13px;
    margin-left: 10px;
    text-align: right;
}

/* Confirm dialog styles */
.confirm-dialog {
    text-align: center;
}

.confirm-message {
    margin-bottom: 30px;
    font-size: 16px;
}

.confirm-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.confirm-buttons button {
    min-width: 100px;
}

.confirm-buttons .confirm-yes {
    background-color: #d9534f;
    border-color: #d43f3a;
}

.confirm-buttons .confirm-yes:hover {
    background-color: #c9302c;
    border-color: #ac2925;
}

/* Save As dialog styles */
.save-as-dialog {
    padding: 20px 0;
}

.save-as-dialog label {
    display: block;
    margin-bottom: 10px;
    font-size: 14px;
    color: #ccc;
}

.save-as-dialog input[type="text"] {
    width: 100%;
    padding: 10px;
    background: #1a1a1a;
    border: 1px solid #444;
    color: #fff;
    border-radius: 4px;
    font-size: 14px;
    margin-bottom: 20px;
    box-sizing: border-box;
}

.save-as-dialog input[type="text"]:focus {
    outline: none;
    border-color: #4a9eff;
}

.save-as-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.save-as-buttons button {
    min-width: 80px;
}

.save-as-buttons .save-as-confirm {
    background-color: #4a9eff;
    border-color: #357abd;
}

.save-as-buttons .save-as-confirm:hover {
    background-color: #357abd;
    border-color: #28608e;
}

/* Track info modal styles */
.track-info-modal {
    max-width: 600px;
}

#trackInfoContent {
    max-height: 400px;
    overflow-y: auto;
    padding: 10px 0;
}

.track-item {
    display: flex;
    align-items: center;
    padding: 10px;
    margin: 5px 0;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.track-item:hover {
    background: #222;
}

.track-color {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    margin-right: 15px;
    border: 1px solid #444;
}

.track-details {
    flex: 1;
}

.track-name {
    font-weight: bold;
    color: #e0e0e0;
    margin-bottom: 4px;
}

.track-stats {
    font-size: 12px;
    color: #999;
}

.track-controls {
    display: flex;
    gap: 5px;
}

.track-btn {
    padding: 4px 8px;
    font-size: 11px;
    background: #333;
    border: 1px solid #555;
    color: #ccc;
    cursor: pointer;
    border-radius: 3px;
}

.track-btn:hover {
    background: #444;
    color: #fff;
}

.track-btn.active {
    background: #4a9eff;
    border-color: #357abd;
    color: #fff;
}

.track-btn.track-mute.muted {
    background: #d32f2f;
    border-color: #b71c1c;
    color: #fff;
}

.track-btn.track-mute.muted:hover {
    background: #f44336;
    border-color: #d32f2f;
}

/* Mobile styles */
@media (max-width: 768px) {
    /* Increase touch targets */
    button {
        min-height: 44px;
        min-width: 44px;
        font-size: 14px;
    }
    
    select {
        min-height: 44px;
        font-size: 14px;
    }
    
    input[type="number"] {
        min-height: 44px;
        font-size: 14px;
    }
    
    /* Adjust controls layout for mobile */
    #controls {
        flex-wrap: wrap;
        height: auto;
        padding: 10px;
        gap: 10px;
    }
    
    .control-group {
        flex-wrap: wrap;
    }
    
    /* Hide labels on mobile to save space */
    .control-group label {
        display: none;
    }
    
    /* Make modals mobile-friendly */
    .modal-content {
        width: 90%;
        max-width: 90%;
        margin: 20px;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    /* Adjust shortcut dialog for mobile */
    .shortcuts-grid {
        grid-template-columns: 1fr;
    }
    
    /* Piano keys adjustments */
    .piano-key {
        min-width: 60px;
    }
    
    /* Note resize handles for touch */
    .note-resize-handle {
        width: 20px;
        height: 100%;
    }
    
    /* Dropdown menus */
    .dropdown-content {
        min-width: 200px;
        right: 0;
        left: auto;
    }
}

@media (max-width: 480px) {
    /* Even more compact layout for small phones */
    #controls {
        padding: 5px;
    }
    
    button {
        padding: 8px 12px;
    }
    
    .modal-content {
        margin: 10px;
    }
}

/* Touch device optimization */
@media (pointer: coarse) {
    /* Make touch targets larger on mobile */
    .controls button {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
    }
    
    .controls select,
    .controls input[type="number"] {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    /* Larger slider thumb for touch */
    input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
    
    input[type="range"]::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }
    
    /* Prevent accidental touches */
    canvas {
        touch-action: none;
    }
}

/* Hide mobile-only elements on desktop */
.mobile-only {
    display: none;
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    /* Ensure minimum height for critical elements */
    #menubar { min-height: 32px; }
    #controls { min-height: 44px; }
    #velocity-bar { min-height: 40px; }
    #pan-bar { min-height: 40px; }
    
    /* Make menu bar more compact on mobile */
    #menubar {
        height: 32px;
        font-size: 12px;
        flex-wrap: wrap;
    }
    
    .menu-item {
        padding: 0 8px;
        height: 32px;
    }
    
    /* Show all menu items on mobile */
    .menu-item {
        font-size: 11px;
        padding: 0 6px;
    }
    
    /* Make voice selector more compact on mobile */
    .menu-instrument-selector {
        padding: 0 4px;
        height: 32px;
        align-items: center;
    }
    
    .menu-instrument-selector label {
        font-size: 11px;
        margin-right: 4px;
    }
    
    .menu-instrument-selector select {
        height: 24px;
        padding: 2px 4px;
        font-size: 11px;
        min-width: 80px;
    }
    
    .menu-instrument-selector #instrumentColorIndicator {
        width: 8px;
        height: 8px;
        margin-left: 4px;
    }
    
    /* Make controls more compact on mobile */
    #controls {
        flex-wrap: nowrap;
        height: auto;
        padding: 5px;
        gap: 5px;
        overflow-x: auto;
        justify-content: space-between;
    }
    
    /* Float loop control to the right on mobile */
    .control-group.loop {
        margin-left: auto;
        flex-shrink: 0;
    }
    
    /* Hide spacer on mobile */
    .control-spacer {
        display: none;
    }
    
    /* Hide title on mobile to save space */
    h1 {
        display: none;
    }
    
    /* Compact control groups */
    .control-group {
        gap: 4px;
    }
    
    /* Smaller buttons */
    .control-group button {
        padding: 3px 6px;
        font-size: 11px;
        min-width: 32px;
        min-height: 32px;
    }
    
    /* Hide volume label, keep slider */
    .control-group.volume-group label {
        font-size: 0;
    }
    
    .control-group.volume-group input[type="range"] {
        width: 60px;
        margin-left: 0;
    }
    
    /* Smaller loop inputs */
    .loop-range-container {
        padding: 1px 4px;
        font-size: 10px;
    }
    
    .loop-range-container input[type="number"] {
        width: 30px;
        font-size: 10px;
    }
    
    .loop-range-container span {
        font-size: 10px;
    }
    
    /* Make bars more compact on mobile */
    #velocity-bar,
    #pan-bar {
        height: 40px; /* Reduced from 60px */
    }
    
    /* Adjust layout for mobile */
    #container {
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile browsers */
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        overflow: hidden;
    }
    
    #canvas-container {
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }
    
    /* Ensure bars stay visible */
    #velocity-bar,
    #pan-bar {
        flex-shrink: 0; /* Prevent bars from shrinking */
    }
    
    /* Show mobile-only elements */
    .mobile-only {
        display: flex !important;
    }
}