* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Prevent tap highlight on mobile devices */
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%; /* Ensure body takes full height */
    overflow: hidden; /* Prevent body scroll, let specific elements scroll */
    overscroll-behavior-y: contain; /* Disable pull-to-refresh */
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
    color: #e0e0e0;
    min-height: 100vh;
    overflow-x: hidden;
    user-select: none; /* Disable text selection */
    -webkit-user-select: none; /* Disable text selection for Webkit browsers */
    -moz-user-select: none; /* Disable text selection for Mozilla Firefox */
    -ms-user-select: none; /* Disable text selection for Internet Explorer/Edge */
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    display: flex; /* Added for flex layout */
    flex-direction: column; /* Stack header and main vertically */
    min-height: 100vh; /* Ensure container takes full viewport height */
}

.header {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.header-content {
    margin-bottom: 15px;
    display: flex;
    align-items: baseline;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.title {
    font-size: 2.5rem;
    font-weight: 300;
    margin-bottom: 0;
    color: #4a9eff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
    font-size: 1rem;
    color: #a0a0a0;
    margin-bottom: 0;
}

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

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

.header-layout {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1200px;
    margin-bottom: 15px;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.header-right {
    display: flex;
    align-items: center;
}

.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.control-btn {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border: none;
    border-radius: 12px;
    color: #e0e0e0;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 10px 16px;
    transition: all 0.3s ease;
    box-shadow: 
        6px 6px 12px rgba(0, 0, 0, 0.5),
        -6px -6px 12px rgba(255, 255, 255, 0.05);
    outline: none; /* Prevent focus outline */
}

.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: 
        8px 8px 16px rgba(0, 0, 0, 0.6),
        -8px -8px 16px rgba(255, 255, 255, 0.08);
}

.control-btn:active {
    transform: translateY(0);
    box-shadow: 
        inset 3px 3px 6px rgba(0, 0, 0, 0.6),
        inset -3px -3px 6px rgba(255, 255, 255, 0.05);
}

.control-btn.icon-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Smaller help icon override */
#help-btn.control-btn.icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0;
}

.control-btn#record-btn.recording .fa-stop {
    color: #ff6b6b;
}

.control-select {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border: none;
    border-radius: 12px;
    color: #e0e0e0;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 10px 16px;
    transition: all 0.3s ease;
    box-shadow: 
        6px 6px 12px rgba(0, 0, 0, 0.5),
        -6px -6px 12px rgba(255, 255, 255, 0.05);
    min-width: 150px;
    outline: none; /* Prevent focus outline */
}

.control-select:hover {
    transform: translateY(-2px);
    box-shadow: 
        8px 8px 16px rgba(0, 0, 0, 0.6),
        -8px -8px 16px rgba(255, 255, 255, 0.08);
}

.control-select:focus {
    outline: none;
    transform: translateY(-2px);
    box-shadow: 
        8px 8px 16px rgba(0, 0, 0, 0.6),
        -8px -8px 16px rgba(255, 255, 255, 0.08);
}

.control-select option {
    background: #2a2a2a;
    color: #e0e0e0;
    padding: 8px;
}

.octave-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: -20px;
  width: 90%;
}

.octave-btn {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border: none;
    border-radius: 5px;
    color: #e0e0e0;
    cursor: pointer;
    font-size: 1.2rem;
    width: 35px;
    height: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 
        4px 4px 8px rgba(0, 0, 0, 0.5),
        -4px -4px 8px rgba(255, 255, 255, 0.05);
    outline: none;
    font-weight: bold;
}

.octave-btn:hover {
    transform: translateY(-2px);
    box-shadow: 
        6px 6px 12px rgba(0, 0, 0, 0.6),
        -6px -6px 12px rgba(255, 255, 255, 0.08);
}

.octave-btn:active {
    transform: translateY(0);
    box-shadow: 
        inset 2px 2px 4px rgba(0, 0, 0, 0.6),
        inset -2px -2px 4px rgba(255, 255, 255, 0.05);
}

.octave-display {
    font-size: 0.8rem;
    font-weight: 500;
    color: #4a9eff;
    min-width: 50px;
    text-align: center;
}

.volume-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 20px;
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border-radius: 15px;
    box-shadow: 
        inset 2px 2px 4px rgba(0, 0, 0, 0.3),
        inset -2px -2px 4px rgba(255, 255, 255, 0.05);
}

.slider-group {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 15px 20px;
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border-radius: 15px;
    box-shadow: 
        inset 2px 2px 4px rgba(0, 0, 0, 0.3),
        inset -2px -2px 4px rgba(255, 255, 255, 0.05);
    margin-bottom: 20px; /* Add margin between groups */
    position: relative; /* enable absolute-positioned reset icon */
}

.slider-group .reset-icon {
    position: absolute;
    right: 10px;
    bottom: 10px;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.04);
    color: #e0e0e0;
    border: 1px solid rgba(255,255,255,0.03);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.15s ease, transform 0.08s ease;
    z-index: 5;
}

.slider-group .reset-icon:hover {
    background: rgba(255,255,255,0.07);
    transform: translateY(-1px);
}

.slider-group h3 {
    color: #4a9eff;
    font-size: 1.1rem;
    margin-bottom: 10px;
    text-align: center;
    font-weight: 400;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.slider-container label {
    font-size: 0.9rem;
    color: #e0e0e0;
    min-width: 60px; /* Increased min-width for labels */
}

.control-slider {
    width: 80px;
    height: 6px;
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: 
        inset 2px 2px 4px rgba(0, 0, 0, 0.6),
        inset -2px -2px 4px rgba(255, 255, 255, 0.05);
}

.control-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: linear-gradient(145deg, #4a9eff, #3a8eef);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 
        2px 2px 4px rgba(0, 0, 0, 0.4),
        -2px -2px 4px rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
}

.control-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 
        3px 3px 6px rgba(0, 0, 0, 0.5),
        -3px -3px 6px rgba(255, 255, 255, 0.15);
}

.control-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: linear-gradient(145deg, #4a9eff, #3a8eef);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 
        2px 2px 4px rgba(0, 0, 0, 0.4),
        -2px -2px 4px rgba(255, 255, 255, 0.1);
}

#reverb-mix-value,
#compressor-threshold-value,
#compressor-ratio-value,
#compressor-attack-value,
#compressor-release-value,
#amplifier-value,
#adsr-attack-value,
#adsr-decay-value,
#adsr-sustain-value,
#adsr-release-value,
#delay-time-value,
#delay-feedback-value,
#delay-mix-value { 
    font-size: 0.8rem;
    color: #4a9eff; /* Blue color for the value */
    min-width: 35px;
    text-align: right; /* Align value to the right */
}

.main {
    flex: 1; /* Allow main to grow and take available vertical space */
    display: flex; /* Added for flex layout */
    flex-direction: column; /* Stack elements inside main vertically */
    justify-content: center; /* Center keyboard vertically within main */
    align-items: center; /* Center keyboard horizontally within main */
    width: 100%; /* Ensure main takes full width */
}

.keyboard-container {
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden; /* Changed from auto to hidden */
    padding: 20px 0;
}

.keyboard {
    display: flex;
    gap: 2px;
    padding: 20px;
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border-radius: 20px;
    box-shadow: 
        inset 8px 8px 16px rgba(0, 0, 0, 0.6),
        inset -8px -8px 16px rgba(255, 255, 255, 0.05);
}

.key {
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.key.white {
    width: 50px;
    height: 200px;
    background: linear-gradient(145deg, #f0f0f0, #d0d0d0);
    border-radius: 8px;
    box-shadow: 
        4px 4px 8px rgba(0, 0, 0, 0.3),
        -4px -4px 8px rgba(255, 255, 255, 0.7);
}

.key.black {
    width: 30px;
    height: 120px;
    background: linear-gradient(145deg, #3a3a3a, #1a1a1a);
    border-radius: 6px;
    margin-left: -15px;
    margin-right: -15px;
    z-index: 2;
    box-shadow: 
        4px 4px 8px rgba(0, 0, 0, 0.6),
        -4px -4px 8px rgba(255, 255, 255, 0.1);
}

.key:hover {
    /* transform: translateY(-3px); */ /* Removed as per request to prevent movement */
}

.key.active {
    /* transform: translateY(3px); */ /* Removed as per request to prevent movement */
    box-shadow: 
        inset 2px 2px 4px rgba(0, 0, 0, 0.5),
        inset -2px -2px 4px rgba(255, 255, 255, 0.2);
}

.key.white.active {
    background: linear-gradient(145deg, #4a9eff, #3a8eef);
    box-shadow: 
        inset 2px 2px 4px rgba(0, 0, 0, 0.3),
        inset -2px -2px 4px rgba(255, 255, 255, 0.5);
}

.key.black.active {
    background: linear-gradient(145deg, #5a5aff, #4a4aef);
}

.key-label {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    font-weight: 500;
    color: #666;
    pointer-events: none;
}

.key.black .key-label {
    color: #ccc;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border-radius: 20px;
    padding: 30px;
    max-width: 90%;
    max-height: 80%;
    overflow-y: auto;
    box-shadow: 
        20px 20px 40px rgba(0, 0, 0, 0.8),
        -20px -20px 40px rgba(255, 255, 255, 0.05);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 {
    color: #4a9eff;
    font-weight: 300;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    color: #e0e0e0;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    outline: none; /* Prevent focus outline */
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Modal Body for Panels */
.modal-body.modal-panels {
    display: flex;
    flex-wrap: wrap; /* Allow panels to wrap on smaller screens */
    gap: 30px; /* Space between panels */
    justify-content: center; /* Center panels if they don't fill width */
    align-items: flex-start; /* Align panels at the top */
}

.modal-body .panel-left,
.modal-body .panel-right {
    flex: 1; /* Allow panels to grow */
    min-width: 280px; /* Minimum width for each panel before wrapping */
    display: flex;
    flex-direction: column;
    gap: 20px; /* Gap between slider groups within a panel */
}

.mapping-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.mapping-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px;
    background: linear-gradient(145deg, #4a4a4a, #3a3a3a);
    border-radius: 10px;
    box-shadow: 
        inset 2px 2px 4px rgba(0, 0, 0, 0.3),
        inset -2px -2px 4px rgba(255, 255, 255, 0.05);
}

.mapping-label {
    font-weight: 500;
    min-width: 60px;
}

.mapping-select {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    color: #e0e0e0;
    font-size: 0.9rem;
    outline: none; /* Prevent focus outline */
}

.reset-btn {
    background: linear-gradient(145deg, #ff6b6b, #ff5252);
    border: none;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    font-size: 1rem;
    padding: 12px 24px;
    transition: all 0.3s ease;
    box-shadow: 
        6px 6px 12px rgba(0, 0, 0, 0.4),
        -6px -6px 12px rgba(255, 255, 255, 0.1);
    outline: none; /* Prevent focus outline */
}

.reset-btn:hover {
    transform: translateY(-2px);
    box-shadow: 
        8px 8px 16px rgba(0, 0, 0, 0.5),
        -8px -8px 16px rgba(255, 255, 255, 0.15);
}

.keyboard-mapping-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.keyboard-mapping-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    background: linear-gradient(145deg, #4a4a4a, #3a3a3a);
    border-radius: 8px;
    font-size: 0.9rem;
}

.keyboard-key {
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border: none;
    border-radius: 4px;
    color: #4a9eff;
    font-family: monospace;
    font-size: 0.8rem;
    padding: 4px 8px;
    min-width: 30px;
}

.step-sequencer-content {
    max-width: 95%;
    max-height: 85%;
    width: 900px;
}

.sequencer-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.tempo-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tempo-control label {
    font-weight: 500;
    color: #e0e0e0;
}

.pattern-controls {
    display: flex;
    gap: 10px;
}

.pattern-btn {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border: none;
    border-radius: 8px;
    color: #e0e0e0;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 8px 16px;
    transition: all 0.3s ease;
    box-shadow: 
        4px 4px 8px rgba(0, 0, 0, 0.4),
        -4px -4px 8px rgba(255, 255, 255, 0.05);
}

.pattern-btn[data-pattern="32"] {
    display: none;
}

.pattern-btn.active {
    background: linear-gradient(145deg, #4a9eff, #3a8eef);
    box-shadow: 
        inset 2px 2px 4px rgba(0, 0, 0, 0.3),
        inset -2px -2px 4px rgba(255, 255, 255, 0.2);
}

.transport-controls {
    display: flex;
    gap: 10px;
}

.sequencer-grid {
    display: grid;
    gap: 2px;
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border-radius: 12px;
    padding: 15px;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
}

.sequencer-header {
    display: grid;
    gap: 2px;
    align-items: center;
    margin-bottom: 8px;
}

.sequencer-header.grid-8 {
    grid-template-columns: 80px repeat(8, 1fr);
}

.sequencer-header.grid-16 {
    grid-template-columns: 80px repeat(16, 1fr);
}

.header-empty {
    background: transparent;
}

.step-header {
    font-size: 0.7rem;
    color: #a0a0a0;
    text-align: center;
    padding: 4px 2px;
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border-radius: 4px;
    font-weight: 500;
}

.step-header.measure-start {
    background: linear-gradient(145deg, #4a9eff, #3a8eef);
    color: #ffffff;
    font-weight: 600;
}

.sequencer-row {
    display: grid;
    gap: 2px;
    align-items: center;
}

.sequencer-row.even-row {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 6px;
    padding: 2px;
}

/* Add keyboard-style visual markers */
.sequencer-row.white-key {
    background: rgba(240, 240, 240, 0.05);
    border-radius: 6px;
    padding: 2px;
}

.sequencer-row.black-key {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    padding: 2px;
}

.note-label {
    font-size: 0.8rem;
    color: #e0e0e0;
    text-align: center;
    padding: 8px 4px;
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border-radius: 6px;
    font-weight: 500;
    min-width: 80px; /* Fixed width for consistent alignment */
    max-width: 80px; /* Prevent expansion */
    overflow: hidden; /* Hide overflow text */
    text-overflow: ellipsis; /* Show ellipsis for long text */
    white-space: nowrap; /* Prevent text wrapping */
}

.step-button {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(145deg, #4a4a4a, #3a3a3a);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 
        2px 2px 4px rgba(0, 0, 0, 0.4),
        -2px -2px 4px rgba(255, 255, 255, 0.05);
}

.step-button.measure-start {
    border: 2px solid #4a9eff;
}

.step-button:hover {
    transform: scale(1.05);
}

.step-button.active {
    background: linear-gradient(145deg, #4a9eff, #3a8eef);
    box-shadow: 
        inset 2px 2px 4px rgba(0, 0, 0, 0.3),
        inset -2px -2px 4px rgba(255, 255, 255, 0.2);
}

.step-button.current {
    background: linear-gradient(145deg, #ff6b6b, #ff5252);
    animation: pulse 0.3s ease-in-out;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.export-options {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
}

.repetition-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.repetition-controls label {
    font-weight: 500;
    color: #e0e0e0;
}

.export-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.progress-bar {
    width: 200px;
    height: 8px;
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 
        inset 2px 2px 4px rgba(0, 0, 0, 0.6),
        inset -2px -2px 4px rgba(255, 255, 255, 0.05);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(145deg, #4a9eff, #3a8eef);
    width: 0%;
    transition: width 0.3s ease;
}

#export-status {
    font-size: 0.9rem;
    color: #4a9eff;
    text-align: center;
}

@media (max-width: 768px) {
    .step-sequencer-content {
        width: 98%;
        max-width: 98%;
    }
    
    .sequencer-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .tempo-control,
    .pattern-controls,
    .transport-controls {
        justify-content: center;
    }
    
    .sequencer-header.grid-8 {
        grid-template-columns: 60px repeat(8, 1fr);
    }
    
    .sequencer-header.grid-16 {
        grid-template-columns: 60px repeat(16, 1fr);
    }
    
    .sequencer-row.grid-8 {
        grid-template-columns: 60px repeat(8, 1fr);
    }
    
    .sequencer-row.grid-16 {
        grid-template-columns: 60px repeat(16, 1fr);
    }
    
    .sequencer-row.grid-32 {
        grid-template-columns: 60px repeat(32, 1fr);
    }
    
    .step-button {
        width: 25px;
        height: 25px;
        min-width: 20px;
    }
    
    .note-label {
        font-size: 0.7rem;
        padding: 6px 2px;
        min-width: 60px; /* Smaller fixed width for mobile */
        max-width: 60px;
    }
    
    .keyboard-container {
        width: 94%; /* Increase width to 96% available */
        flex: 1; /* Allow keyboard container to take up remaining vertical space in main */
        min-height: 0; /* Important for flex items with content, prevents overflow */
        padding: 10px 0;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow-x: hidden; /* Changed from auto to hidden */
    }
    
    .keyboard {
        padding: 10px;
    }
    
    .key.white {
        width: 45px; /* Increased size */
        height: 180px; /* Increased size */
    }
    
    .key.black {
        width: 30px;
        height: 110px;
        margin-left: -15px;
        margin-right: -15px;
    }

    .key-label {
        font-size: 0.75rem; /* Slightly larger label */
        bottom: 8px; /* Adjusted position */
    }
    
    .volume-controls { /* Keep this specific for header volume */
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 15px;
        justify-content: center;
        width: 200px;
        margin-left: 10px;
        margin-right: 10px;
    }

  #instrument-select {margin-right: 10px;}

    .slider-group { /* General style for slider groups in modals */
        flex-direction: column;
        gap: 8px;
        padding: 10px 15px;
        width: auto;
    }
    
    .slider-container {
        width: auto;
        min-width: 100px;
    }
    
    .control-slider {
        width: 60px;
    }
    
    .modal-content {
        max-width: 98%;
        max-height: 90%;
        padding: 15px;
    }

    /* Landscape mode for modal panels - make them side-by-side */
    .modal-body.modal-panels {
        flex-direction: row; /* Force side-by-side */
        justify-content: space-around; /* Distribute space */
        align-items: flex-start;
        padding: 10px; /* Reduce padding for more space */
    }
    
    .modal-body .panel-left,
    .modal-body .panel-right {
        flex: 1; /* Each panel takes equal space */
        min-width: 45%; /* Ensure they take roughly half width */
        gap: 10px; /* Smaller gap inside panels */
    }
    
    .modal-body .slider-group {
        margin-bottom: 0; /* Remove margin between groups in landscape */
        padding: 10px; /* Smaller padding */
    }
    
    .modal-body .slider-group h3 {
        margin-bottom: 5px; /* Smaller margin for headings */
    }

    .modal-body .slider-container label {
        min-width: 50px; /* Adjust label width for compactness */
        font-size: 0.8rem;
    }

    .modal-body .control-slider {
        width: 80px; /* Make sliders a bit wider in landscape modal */
    }

    #reverb-mix-value,
    #compressor-threshold-value,
    #compressor-ratio-value,
    #compressor-attack-value,
    #compressor-release-value,
    #amplifier-value,
    #adsr-attack-value,
    #adsr-decay-value,
    #adsr-sustain-value,
    #adsr-release-value,
    #delay-time-value,
    #delay-feedback-value,
    #delay-mix-value {
        min-width: 40px; /* Give more space for values */
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    .container {
        padding: 5px;
    }
    
    .header {
        margin-bottom: 15px;
    }
    
    .title {
        font-size: 1.5rem;
        margin-bottom: 5px;
    }
    
    .subtitle {
        font-size: 0.8rem;
        margin-bottom: 10px;
    }
    
    .octave-controls {
        margin-top: 15px;
    }
    
    .controls {
        gap: 8px;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .control-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    
    .control-select {
        padding: 8px 12px;
        font-size: 0.8rem;
        min-width: 120px;
    }
    
    .octave-display {
        font-size: 1rem;
        min-width: 45px;
    }
    
    .keyboard {
        padding: 10px;
    }
    
    .key.white {
        width: 45px; /* Increased size */
        height: 180px;
    }
    
    .key.black {
        width: 30px;
        height: 110px;
        margin-left: -15px;
        margin-right: -15px;
    }

    .key-label {
        font-size: 0.75rem; /* Slightly larger label */
        bottom: 8px; /* Adjusted position */
    }
    
    .volume-controls {
        width: 180px;
    }
    
    .slider-group {
        flex-direction: column;
        gap: 8px;
        padding: 10px 15px;
        width: auto;
    }
    
    .slider-container {
        width: auto;
        min-width: 100px;
    }
    
    .control-slider {
        width: 60px;
    }
    
    .modal-content {
        max-width: 98%;
        max-height: 90%;
        padding: 15px;
    }

    /* Landscape mode for modal panels - make them side-by-side */
    .modal-body.modal-panels {
        flex-direction: row; /* Force side-by-side */
        justify-content: space-around; /* Distribute space */
        align-items: flex-start;
        padding: 10px; /* Reduce padding for more space */
    }
    
    .modal-body .panel-left,
    .modal-body .panel-right {
        flex: 1; /* Each panel takes equal space */
        min-width: 45%; /* Ensure they take roughly half width */
        gap: 10px; /* Smaller gap inside panels */
    }
    
    .modal-body .slider-group {
        margin-bottom: 0; /* Remove margin between groups in landscape */
        padding: 10px; /* Smaller padding */
    }
    
    .modal-body .slider-group h3 {
        margin-bottom: 5px; /* Smaller margin for headings */
    }

    .modal-body .slider-container label {
        min-width: 50px; /* Adjust label width for compactness */
        font-size: 0.8rem;
    }

    .modal-body .control-slider {
        width: 80px; /* Make sliders a bit wider in landscape modal */
    }

    #reverb-mix-value,
    #compressor-threshold-value,
    #compressor-ratio-value,
    #compressor-attack-value,
    #compressor-release-value,
    #amplifier-value,
    #adsr-attack-value,
    #adsr-decay-value,
    #adsr-sustain-value,
    #adsr-release-value,
    #delay-time-value,
    #delay-feedback-value,
    #delay-mix-value {
        min-width: 40px; /* Give more space for values */
    }
    
    .sequencer-controls {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        flex-wrap: nowrap;
        gap: 10px;
    }
    
    .tempo-control,
    .pattern-controls,
    .transport-controls {
        justify-content: center;
        flex-shrink: 0;
    }
    
    .tempo-control {
        min-width: 120px;
    }
    
    .pattern-controls {
        min-width: 120px;
    }
    
    .transport-controls {
        min-width: 200px;
    }
}

@media (max-width: 768px) and (orientation: portrait) {
    .keyboard-container {
        overflow-x: hidden; /* No horizontal scroll */
        overflow-y: auto; /* Allow vertical scroll for the 3 rows */
        height: 100%; /* Take full height to allow scroll */
        padding-bottom: 20px; /* Add some padding at the bottom */
        width: 98%; /* Occupy nearly full width */
    }

    .keyboard {
        display: flex;
        flex-direction: column; /* Stack octave rows vertically */
        gap: 10px; /* Gap between octave rows */
        padding: 10px;
        width: fit-content; /* Adjust width to fit content, centered by parent */
        margin: 0 auto; /* Center the keyboard horizontally */
    }

    .octave-row {
        display: flex;
        gap: 2px; /* Gap between keys within an octave row */
        justify-content: center; /* Center keys within the octave row */
        width: 100%; /* Make each row take full width available within .keyboard */
    }

    .key.white {
        width: 45px; /* Adjust size to fit 7 white keys reasonably per row */
        height: 140px; /* Smaller height for portrait */
    }

    .key.black {
        width: 25px; 
        height: 90px; /* Smaller height for portrait */
        margin-left: -12px;
        margin-right: -12px;
    }

    .key-label {
        font-size: 0.7rem;
        bottom: 5px;
    }

  #instrument-select {margin-right: 10px;}

  .header {margin-bottom: 0px;}

  .volume-controls{width: 90%;}
}

@media screen and (orientation: landscape) and (min-width: 769px) and (max-width: 1000px) {
    .keyboard-container {
        width: 98%;
        overflow-x: auto;
        justify-content: flex-start;
        padding-left: 10px;
        padding-right: 10px;
    }

    .keyboard {
        padding: 10px;
        gap: 2px;
    }

    .key.white {
        width: 45px;
        height: 180px;
    }

    .key.black {
        width: 30px;
        height: 110px;
        margin-left: -15px;
        margin-right: -15px;
    }
}

.octave-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 90%; /* o un ancho fijo si prefieres */
}

.octave-display {
  text-align: center;
  flex-grow: 1;
  display: none;
}

.octave-btn:first-child {
  order: 1;
}

.octave-display {
  order: 2;
}

.octave-btn:last-child {
  order: 3;
}

@media (max-width: 768px) and (orientation: landscape) {
.octave-controls {margin-top:-120px;}
.keyboard-container {margin-top: -120px;}
.volume-controls {width:200px;}
}

.controls {z-index:999;}

@media (max-width: 480px) and (orientation: portrait) {
    /* Ensure advanced modal panels stack cleanly on narrow portrait phones */
    .modal-body.modal-panels {
        flex-direction: column;
        padding: 8px;
        gap: 12px;
        align-items: stretch;
    }
    .modal-body .panel-left,
    .modal-body .panel-right {
        min-width: 0;
        width: 100%;
        padding: 8px;
    }
    .modal-content {
        padding: 12px;
    }
}

/* Help modal spacing: more breathing room between headings and list items */
#help-modal .modal-body h3 {
    margin-top: 10px;
    margin-bottom: 12px;
    line-height: 1.25;
}

#help-modal .modal-body ul {
    margin-bottom: 14px;
    padding-left: 20px;
}

#help-modal .modal-body ul li {
    margin-bottom: 8px;
    line-height: 1.4;
}

/* Record options modal button layout - larger, well spaced and touch friendly */
.record-options-buttons {
    display: flex;
    flex-direction: column;
    gap: 14px; /* Increased gap to avoid accidental taps */
    align-items: stretch;
    width: 100%;
    margin-top: 8px;
}

.record-options-buttons .control-btn {
    padding: 14px 18px; /* Larger tappable area */
    font-size: 1rem;
    border-radius: 12px;
    min-width: 200px;
}

/* Slightly emphasize the primary action visually */
.record-options-buttons #record-new-btn {
    background: linear-gradient(145deg, #4a9eff, #3a8eef);
    color: #fff;
}

.record-options-buttons #record-overdub-btn {
    background: linear-gradient(145deg, #ffb86b, #ff9f3b);
    color: #fff;
}

.record-options-buttons #record-cancel-btn {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    color: #e0e0e0;
}

/* Recording preview modal buttons: green accept, red repeat for clear affordance */
#preview-accept-btn {
    background: linear-gradient(145deg, #3be06f, #2bb858);
    color: #ffffff;
    border: none;
    padding: 12px 18px;
    border-radius: 10px;
    font-weight: 600;
    min-width: 140px;
}

#preview-repeat-btn {
    background: linear-gradient(145deg, #ff6b6b, #ff3b3b);
    color: #ffffff;
    border: none;
    padding: 12px 18px;
    border-radius: 10px;
    font-weight: 600;
    min-width: 140px;
}

/* Ensure both buttons have distinct hover/active styles */
#preview-accept-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(43,184,88,0.18); }
#preview-repeat-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(255,75,75,0.18); }
#preview-accept-btn:active, #preview-repeat-btn:active { transform: translateY(0); box-shadow: none; }

/* Ensure comfortable spacing on very small screens */
@media (max-width: 420px) {
    .record-options-buttons {
        gap: 12px;
    }
    .record-options-buttons .control-btn {
        padding: 12px 14px;
        font-size: 0.95rem;
    }
}