/* --- Audio Analysis Panel Layout Stabilizers --- */
/* Force vertical stacking for analysis content regardless of upstream CSS */
.harmonic-section .analysis-content,
.melodic-section .analysis-content {
  display: flex !important;
  flex-direction: column !important;
  gap: 4px !important;
}

/* Prevent row height collapse and jumping when content appears/disappears */
.harmonic-section .analysis-content > div,
.melodic-section .analysis-content > div {
  min-height: 16px;
  line-height: 16px;
}

/* Pitch detail rows: keep stable height and visibility area */
.pitch-section .pitch-details #pitch-trend,
.pitch-section .pitch-details #pitch-scale,
.pitch-section .pitch-grid #pitch-frequency,
.pitch-section .pitch-grid #pitch-note-display {
  min-height: 18px;
  line-height: 18px;
}

/* Contour arrows should not wrap unexpectedly */
.melodic-section #contour-display {
  white-space: nowrap;
}

/* Readable colors for extended Harmonic/Melodic metrics */
.harmonic-section .harmonic-metrics,
.melodic-section .melodic-momentum,
.melodic-section .melodic-flags {
  color: #cbd5e1; /* slate-300 */
}
.harmonic-section .harmonic-metrics b,
.melodic-section .melodic-flags b {
  color: #e5e7eb; /* gray-200 */
}

/* Main Layout */
html, body { 
    margin: 0; 
    padding: 0;
    overflow: hidden; 
    background: black; 
    width: 100%; 
    height: 100%; 
    position: fixed;
    top: 0;
    left: 0;
    user-select: none; /* Disable text selection */
    -webkit-user-select: none; /* Safari */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE/Edge */
    /* Also prevent tap highlight color on mobile */
    -webkit-tap-highlight-color: transparent;
}

canvas { 
    display: block; 
    width: 100%; 
    height: 100%; 
    position: fixed;
    top: 0;
    left: 0;
    overflow: hidden;
    /* Ensure transform is from center for more stable movement */
    transform-origin: center center;
}

/* Selector UI */
#selector {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    max-width: 800px;
    width: 90vw;
    max-height: 90vh;
    height: auto;
    overflow: visible; /* Allow mic button to extend beyond bounds */
    display: none; /* hidden by default; shown via JS */
}

/* Preset buttons grid */
.preset-buttons-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin: 20px 0;
}

/* Preset buttons */
.preset-button {
    width: 100%;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 4px;
}

.preset-button:hover {
    background: rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 255, 255, 0.2);
}

.preset-button.active {
    background: rgba(0, 255, 128, 0.2);
    border-color: rgba(0, 255, 128, 0.4);
}

/* Active effects display */
.active-effects-section {
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.active-effects-section h3 {
    color: #aaa;
    margin: 0 0 10px 0;
    font-size: 14px;
}

.active-effects-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.active-effect-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(0, 255, 128, 0.1);
    border: 1px solid rgba(0, 255, 128, 0.2);
    border-radius: 4px;
    color: #fff;
    font-size: 13px;
}

.effect-name {
    font-weight: 500;
}

.effect-state {
    color: rgba(0, 255, 128, 0.8);
    font-size: 12px;
}

/* Control panel improvements */
.control-panel {
    width: 400px;
    max-width: 90vw;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.panel-header h2 {
    margin: 0;
    color: white;
    font-size: 18px;
}

.panel-content {
    padding: 20px;
}

.command-list {
    margin-top: 20px;
}

.command-item {
    display: flex;
    align-items: center;
    padding: 10px;
    margin: 4px 0;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    color: white;
    font-size: 13px;
}

.command-key {
    width: 30px;
    padding: 4px 8px;
    background: rgba(0, 255, 128, 0.2);
    border: 1px solid rgba(0, 255, 128, 0.3);
    border-radius: 4px;
    text-align: center;
    margin-right: 12px;
}

.command-name {
    width: 120px;
    font-weight: 500;
}

.command-description {
    flex: 1;
    color: #aaa;
}

.control-group {
    background: rgba(0, 0, 0, 0.3);
    padding: 10px;
    margin: 10px 0;
    border-radius: 5px;
}

.control-group div {
    margin: 8px 0;
}

input[type="range"] {
    width: 150px;
    margin-left: 10px;
    vertical-align: middle;
}

label {
    display: inline-block;
    width: 100px;
}

.close-button {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.3s ease;
    z-index: 10000; /* ensure it is always above panel content */
}

.close-button:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Help panel container should form a positioning context */
#enhanced-help-panel {
    position: relative;
}

/* Help panel specific close button styling */
#enhanced-help-panel .close-button {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
    border-radius: 4px;
    font-size: 16px;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    position: absolute; /* place in the top-right of the help panel */
    top: 10px;
    right: 10px;
}

#enhanced-help-panel .close-button:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.header-container {
    text-align: center;
    margin: 0;
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.9);
    border-radius: 8px 8px 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.logo-header {
    font-variant: normal;
    letter-spacing: 1px;
    font-size: 24px;
    margin: 0;
    padding: 0;
    color: #fff;
    font-weight: normal;
    color: transparent; /* Makes the text interior transparent */
    -webkit-text-stroke-width: 1px; /* Sets the outline thickness */
    -webkit-text-stroke-color: #fff; /* Sets the outline color */

}

.help-link {
    color: rgba(255, 255, 255, 0.7) !important;
    font-size: 0.85em;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s ease;
    font-family: inherit;
}

.help-link:link,
.help-link:visited,
.help-link:active {
    color: rgba(255, 255, 255, 0.7) !important;
}

.help-link:hover {
    color: #fff !important;
}

/* Audio Reactivity Effects Panel */
.audio-effects-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
}

.audio-effect-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  box-sizing: border-box;
  min-height: 36px; /* Better touch target */
}

.audio-effect-checkbox input[type="checkbox"] {
  cursor: pointer;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.audio-effect-checkbox span {
  user-select: none;
  flex: 1;
  line-height: 1.3;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
  .audio-effects-grid {
    grid-template-columns: 1fr; /* Single column on mobile */
    gap: 6px;
  }
  
  .audio-effect-checkbox {
    font-size: 15px; /* Larger text on mobile */
    padding: 10px 12px; /* Bigger touch targets */
    min-height: 44px; /* iOS recommended touch target */
  }
  
  .audio-effect-checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
  }
}

/* Category-specific styles */
.audio-effect-checkbox.category-core {
  color: #e0f2fe;
  background: rgba(14, 165, 233, 0.08);
  border: 1px solid rgba(14, 165, 233, 0.15);
}

.audio-effect-checkbox.category-core:hover {
  background: rgba(14, 165, 233, 0.15);
}

.audio-effect-checkbox.category-bus {
  color: #fcd34d;
  background: rgba(252, 211, 77, 0.08);
  border: 1px solid rgba(252, 211, 77, 0.15);
}

.audio-effect-checkbox.category-bus:hover {
  background: rgba(252, 211, 77, 0.15);
}

.audio-effect-checkbox.category-smoothing {
  color: #4ecdc4;
  background: rgba(76, 236, 196, 0.1);
  border: 1px solid rgba(76, 236, 196, 0.2);
}

.audio-effect-checkbox.category-smoothing:hover {
  background: rgba(76, 236, 196, 0.18);
}

.audio-effect-checkbox.category-debug {
  color: #94a3b8;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.15);
}

.audio-effect-checkbox.category-debug:hover {
  background: rgba(148, 163, 184, 0.12);
}

/* Global Styles */
.audio-meter {
    display: flex;
    align-items: center;
    margin: 8px 0;
}
.meter-bar {
    flex-grow: 1;
    height: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    margin-left: 10px;
    overflow: hidden;
}
.meter-fill {
    height: 100%;
    width: 0%;
    transition: width 0.1s ease;
}
.bass .meter-fill { background: #ff3366; }
.mids .meter-fill { background: #33ff66; }
.highs .meter-fill { background: #3366ff; }

/* Pulsing animation for high frequency meter */
@keyframes pulse-highlight {
    0% { opacity: 1.0; }
    50% { opacity: 0.85; }
    100% { opacity: 1.0; }
}

/* Controls styling */
.control-button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
}
.control-button:hover {
    background: rgba(255, 255, 255, 0.2);
}
.control-button.active {
    background: rgba(139, 92, 246, 0.2);
    border-color: rgba(139, 92, 246, 0.6);
    color: #8b5cf6;
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.3);
}

/* Unified Audio Control Button */
.audio-control-button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ccc;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    font-size: 14px;
    font-weight: 500;
}

.audio-control-button:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.25);
}

.audio-control-button.active {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, rgba(6, 182, 212, 0.1) 100%);
    border-color: rgba(139, 92, 246, 0.4);
    color: #8b5cf6;
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.2);
}

.audio-control-button.pending {
    background: rgba(255, 170, 0, 0.1);
    border-color: rgba(255, 170, 0, 0.3);
    color: #ffaa00;
}

.audio-icon {
    font-size: 16px;
    opacity: 0.8;
}

.audio-text {
    flex: 1;
    text-align: left;
}

.audio-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(170, 170, 170, 0.5);
    transition: all 0.3s ease;
}

.audio-control-button.active .audio-status-dot {
    background: #8b5cf6;
    box-shadow: 0 0 6px rgba(139, 92, 246, 0.6);
}

.audio-control-button.pending .audio-status-dot {
    background: #ffaa00;
    box-shadow: 0 0 6px rgba(255, 170, 0, 0.6);
}

/* Floating MIDI button */
#floating-midi-button button {
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #5bc0de;
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: bold;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}
#floating-midi-button button:hover {
    background: rgba(0, 0, 0, 0.8);
    border-color: #5bc0de;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

/* Parameter indicators */
#param-indicator, #weight-indicator {
    position: fixed;
    left: 10px;
    background: rgba(0, 0, 0, 0.9);
    color: #00ff00;
    padding: 12px 16px;
    border-radius: 6px;
    font-family: monospace;
    font-size: 20px;
    font-weight: bold;
    transition: opacity 0.3s ease;
    z-index: 1000;
    text-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
    border: 1px solid #00ff00;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
    letter-spacing: 2px;
    opacity: 0;
}
#param-indicator { top: 40px; }
#weight-indicator { top: 100px; }

/* Responsive layout for larger screens */
@media (min-width: 768px) {
    #selector {
        width: 700px;
        max-width: 90vw;
    }
    
    .control-panels-container {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        margin-top: 20px;
    }
    
    .control-group {
        width: 48%;
        box-sizing: border-box;
    }
    
    /* EQ panel desktop layout - two columns */
    .audio-main-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px;
        align-items: start;
    }
    
    .audio-section {
        width: 100%;
    }
}

/* Webkit scrollbar styling */
#selector::-webkit-scrollbar {
    width: 8px;
}

#selector::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

#selector::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

#selector::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

@media (pointer: coarse) {
    canvas {
        touch-action: none; /* Disables all touch actions on touch-enabled devices */
    }
    
    /* Larger close button for mobile */
    .close-button, .floating-close-button {
        width: 44px !important;
        height: 44px !important;
        font-size: 20px !important;
        top: 12px !important;
        right: 12px !important;
        min-width: 44px !important;
        min-height: 44px !important;
    }
    
    /* Selector panel centering on mobile */
    #selector {
        width: min(95vw, 700px) !important;
        max-width: 95vw !important;
        max-height: 95vh !important;
        top: 2.5vh !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        margin: 0 !important;
        padding: 15px !important;
    }
    
    /* Ensure content area scrolls properly on mobile */
    #selector .content-area {
        max-height: calc(95vh - 140px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Make tab content scrollable */
    #selector .tab-content {
        overflow-y: auto !important;
        max-height: inherit !important;
    }
    
    /* EQ panel responsive - single column on mobile */
    .audio-main-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 15px !important;
    }
    
    .audio-section {
        width: 100% !important;
        max-width: none !important;
    }
    
    /* Adjust EQ grid items for mobile */
    .freq-grid {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }
    
    .beat-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }
    
    .effects-grid {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }
    
    .musical-analysis-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }
}

/* Help Panel Command Visuals */
.help-key {
  display: inline-block;
  min-width: 60px;
  padding: 10px 18px;
  background: rgba(0, 255, 0, 0.1);
  border: 2px solid rgba(0, 255, 0, 0.3);
  border-radius: 4px;
  font-weight: bold;
  font-size: 22px;
  text-align: center;
  transition: 0.3s;
  cursor: pointer;
}
.help-key.active {
  background: rgba(0, 255, 0, 0.3) !important;
  border-color: rgba(0, 255, 0, 0.8) !important;
  box-shadow: 0 0 8px rgba(0, 255, 0, 0.4) !important;
}

.help-command-name {
  font-weight: bold;
  color: rgb(0, 255, 0);
  font-size: 22px;
  padding: 10px 18px;
  border-radius: 4px;
  text-align: left;
  margin-bottom: 8px;
  transition: 0.3s;
  background: rgba(0, 255, 0, 0.05);
  border: 1px solid rgba(0, 255, 0, 0.2);
}
.help-command-name.active {
  background: rgba(0, 255, 0, 0.2) !important;
  border: 1px solid rgba(0, 255, 0, 0.6) !important;
  box-shadow: 0 0 8px rgba(0, 255, 0, 0.4) !important;
}

.help-state-button {
  background: rgba(0, 255, 136, 0.1);
  border: 2px solid rgba(0, 255, 136, 0.3);
  border-radius: 4px;
  color: #00ff88;
  font-size: 22px;
  font-weight: bold;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin: 0;
  min-width: 80px;
  text-align: center;
}
.help-state-button.active {
  background: rgba(0, 255, 136, 0.3) !important;
  border: 2px solid rgba(0, 255, 136, 0.8) !important;
  box-shadow: 0 0 8px rgba(0, 255, 136, 0.4) !important;
}

/* Help panel matches selector panel styling */
#enhanced-help-panel {
    /* Styled inline to match selector panel exactly */
    color: white;
}

/* Ensure all text in help panel is readable */
#enhanced-help-panel * {
    color: inherit;
}

#enhanced-help-panel .command-description,
#enhanced-help-panel .command-item,
#enhanced-help-panel p,
#enhanced-help-panel div:not(.help-key):not(.help-command-name):not(.help-state-button) {
    color: #ddd !important;
}

#enhanced-help-panel .command-name {
    color: white !important;
}

/* Help panel tabs styling */
#enhanced-help-panel #help-tabs {
    display: flex !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    margin-bottom: 10px !important;
}

#enhanced-help-panel .help-tab {
    flex: 1 !important;
    text-align: center !important;
    padding: 8px 0 !important;
    cursor: pointer !important;
    border-bottom: 2px solid transparent !important;
    color: rgba(0, 255, 0, 0.7) !important;
    transition: all 0.2s ease !important;
    background: rgba(0, 0, 0, 0.2) !important;
    margin-right: 1px !important;
}

#enhanced-help-panel .help-tab:hover {
    color: rgba(0, 255, 0, 0.9) !important;
    background: rgba(0, 255, 0, 0.1) !important;
}

#enhanced-help-panel .help-tab.active {
    border-bottom: 2px solid #00ff00 !important;
    color: #00ff00 !important;
    font-weight: bold !important;
}

/* Scrollbar styling for help panel - matches selector */
#enhanced-help-panel::-webkit-scrollbar {
    width: 8px;
}

#enhanced-help-panel::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

#enhanced-help-panel::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

#enhanced-help-panel::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.5);
} 