/* CSS Custom Properties - Dieter Rams Inspired Engineering Design */
:root {
    /* Precision Engineering Colors - Inspired by Braun/Teenage Engineering */
    --bg-primary: #0a0b0f;
    --bg-secondary: #151619;
    --bg-tertiary: #1d1e23;
    --bg-elevated: #24252b;
    --bg-control: #2a2b32;
    
    /* Typography Colors - High contrast for precision */
    --text-primary: #ffffff;
    --text-secondary: #d4d4d8;
    --text-muted: #a1a1aa;
    --text-accent: #f97316;
    
    /* Technical Grid Lines */
    --grid-line: #27272a;
    --grid-accent: #3f3f46;
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.15);
    
    /* Frequency Gradient Colors - Deep Red to Violet */
    --freq-red: #8b0000;
    --freq-orange-red: #dc2626;
    --freq-orange: #ea580c;
    --freq-yellow: #eab308;
    --freq-green: #059669;
    --freq-blue-green: #0891b2;
    --freq-blue: #2563eb;
    --freq-indigo: #4338ca;
    --freq-violet: #7c3aed;
    
    /* Engineering Accent Colors */
    --accent-primary: #f97316;
    --accent-secondary: #10b981;
    --accent-warning: #eab308;
    --accent-danger: #dc2626;
    --accent-info: #0ea5e9;
    
    /* Technical Shadows - Subtle and precise */
    --shadow-inset: inset 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-raised: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-floating: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-deep: 0 8px 32px rgba(0, 0, 0, 0.4);
    
    /* Precision Transitions */
    --transition-precise: 0.12s cubic-bezier(0.23, 1, 0.32, 1);
    --transition-smooth: 0.2s cubic-bezier(0.23, 1, 0.32, 1);
    --transition-mechanical: 0.08s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    
    /* Technical Spacing */
    --spacing-micro: 2px;
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 12px;
    --spacing-lg: 16px;
    --spacing-xl: 24px;
    --spacing-xxl: 32px;
    
    /* Grid System */
    --grid-unit: 8px;
    --radius-sm: 2px;
    --radius-md: 4px;
    --radius-lg: 6px;
}

/* Light Theme Override - Clean Engineering */
[data-theme="light"] {
    --bg-primary: #fafafa;
    --bg-secondary: #f4f4f5;
    --bg-tertiary: #e4e4e7;
    --bg-elevated: #ffffff;
    --bg-control: #f1f5f9;
    
    --text-primary: #18181b;
    --text-secondary: #3f3f46;
    --text-muted: #71717a;
    --text-accent: #ea580c;
    
    --grid-line: #e4e4e7;
    --grid-accent: #d4d4d8;
    --border-subtle: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.15);
}

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

body {
    font-family: 'Inter', 'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, monospace;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.4;
    overflow-x: hidden;
    min-height: 100vh;
    font-weight: 400;
    letter-spacing: -0.01em;
}

/* Container and Layout */
.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: var(--spacing-xl);
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    gap: var(--spacing-xl);
    background: var(--bg-primary);
}

/* Header Styles - Minimalist Engineering */
.header {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: var(--spacing-lg) var(--spacing-xl);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-raised);
    position: relative;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
    opacity: 0.6;
}

.title {
    font-size: 1.75rem;
    font-weight: 500;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.02em;
    text-transform: uppercase;
    font-family: 'Inter', monospace;
}

.title::after {
    content: ' / FM-1';
    color: var(--text-accent);
    font-weight: 300;
    font-size: 0.875rem;
    margin-left: var(--spacing-sm);
}

.subtitle {
    display: none;
}

.header-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.header-info::before {
    content: 'v1.0.0';
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--bg-control);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}


/* Button Styles - Technical/Industrial */
.btn {
    padding: var(--spacing-md) var(--spacing-lg);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-mechanical);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    white-space: nowrap;
    font-family: monospace;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    position: relative;
    overflow: hidden;
    background: var(--bg-control);
    color: var(--text-secondary);
    box-shadow: var(--shadow-inset);
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 1px;
    background: var(--accent-primary);
    transition: left var(--transition-precise);
}

.btn:hover::before {
    left: 0;
}

.btn:hover {
    color: var(--text-primary);
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-raised);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-inset);
}

.btn-primary {
    background: var(--accent-primary);
    color: var(--bg-primary);
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-raised);
}

.btn-primary::before {
    background: var(--bg-primary);
}

.btn-primary:hover {
    background: #ea580c;
    box-shadow: var(--shadow-floating);
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border-color: var(--border-strong);
}

.btn-copy {
    background: var(--accent-secondary);
    color: var(--bg-primary);
    border-color: var(--accent-secondary);
    font-size: 0.6875rem;
    padding: var(--spacing-sm) var(--spacing-md);
}

/* Legend Panel - Technical Reference */
.legend-panel {
    padding: var(--spacing-xl);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-raised);
    position: relative;
}

.legend-title {
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: var(--spacing-lg);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-family: monospace;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.legend-title::before {
    content: '◼';
    color: var(--accent-primary);
    font-size: 0.5rem;
}

.spectrum-gradient {
    height: 40px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: linear-gradient(
        90deg, 
        hsl(0, 85%, 45%),     /* Deep Red */
        hsl(30, 85%, 45%),    /* Orange-Red */
        hsl(45, 85%, 45%),    /* Orange */
        hsl(60, 85%, 45%),    /* Yellow */
        hsl(120, 85%, 45%),   /* Green */
        hsl(200, 85%, 45%),   /* Blue-Green */
        hsl(240, 85%, 45%),   /* Blue */
        hsl(270, 85%, 45%),   /* Indigo */
        hsl(280, 85%, 45%)    /* Violet */
    );
    box-shadow: var(--shadow-inset);
    margin-bottom: var(--spacing-lg);
    position: relative;
}

.spectrum-gradient::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
    opacity: 0.6;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.spectrum-labels {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: var(--spacing-xs);
    text-align: center;
}

.spectrum-label {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-muted);
    font-family: monospace;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Main Content */
.main-content {
    flex: 1;
}


/* Frequency Table - Technical Grid System */
.frequency-table-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-raised);
    overflow: hidden;
    position: relative;
}

.frequency-table-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary), var(--accent-primary));
    opacity: 0.8;
}

.frequency-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.75rem;
    font-family: monospace;
    table-layout: fixed;
}

.frequency-table thead {
    background: var(--bg-control);
    position: sticky;
    top: 0;
    z-index: 10;
}

.frequency-table th {
    padding: var(--spacing-md) var(--spacing-sm);
    text-align: center;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--grid-accent);
    border-right: 1px solid var(--grid-line);
    position: relative;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 0.6875rem;
    background: var(--bg-control);
}

.frequency-table th:last-child {
    border-right: none;
}

.octave-header {
    background: var(--bg-elevated);
    position: sticky;
    left: 0;
    z-index: 11;
    min-width: 60px;
    border-right: 2px solid var(--grid-accent);
    font-weight: 600;
    color: var(--text-primary);
}

.note-header {
    min-width: 80px;
    position: relative;
}

.note-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 1px;
    background: var(--accent-primary);
    opacity: 0.5;
}

.frequency-table tbody tr {
    transition: background-color var(--transition-precise);
    border-bottom: 1px solid var(--grid-line);
}

.frequency-table tbody tr:hover {
    background: rgba(249, 115, 22, 0.02);
}

.frequency-table td {
    padding: var(--spacing-xs);
    text-align: center;
    border-right: 1px solid var(--grid-line);
    position: relative;
    height: 60px;
}

.frequency-table td:last-child {
    border-right: none;
}

.octave-cell {
    font-weight: 600;
    background: var(--bg-elevated);
    position: sticky;
    left: 0;
    z-index: 9;
    border-right: 2px solid var(--grid-accent);
    color: var(--text-primary);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.frequency-cell {
    cursor: pointer;
    font-weight: 500;
    border-radius: var(--radius-sm);
    margin: var(--spacing-micro);
    height: calc(100% - 4px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: var(--spacing-xs);
    transition: all var(--transition-mechanical);
    position: relative;
    overflow: hidden;
    border: 1px solid transparent;
}

.frequency-cell::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(255, 255, 255, 0.2);
    opacity: 0;
    transition: opacity var(--transition-precise);
}

.frequency-cell:hover::before {
    opacity: 1;
}

.frequency-cell:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-floating);
    z-index: 5;
    border-color: rgba(255, 255, 255, 0.1);
}

.frequency-cell.active {
    transform: scale(1.05);
    box-shadow: var(--shadow-deep);
    z-index: 6;
    border-color: var(--accent-primary);
}

.frequency-cell.active::before {
    background: var(--accent-primary);
    opacity: 1;
}

/* Frequency Gradient Colors - Applied via JavaScript */
.frequency-cell {
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.note-name {
    font-size: 0.75rem;
    font-weight: 600;
    font-family: monospace;
    letter-spacing: 0.05em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.frequency-value {
    font-size: 0.6875rem;
    opacity: 0.85;
    font-family: monospace;
    font-weight: 400;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Info Panel - Technical Display */
.info-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-raised);
    padding: var(--spacing-xl);
    position: relative;
}

.info-panel::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-secondary));
    opacity: 0.6;
}

.info-title {
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: var(--spacing-lg);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-family: monospace;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.info-title::before {
    content: '▣';
    color: var(--accent-secondary);
    font-size: 0.5rem;
}

.info-content {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    padding: var(--spacing-md);
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    position: relative;
    overflow: hidden;
}

.info-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--grid-accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform var(--transition-precise);
}

.info-item:hover::before {
    transform: scaleX(1);
}

.info-label {
    font-size: 0.6875rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-family: monospace;
}

.info-value {
    font-size: 0.875rem;
    color: var(--text-primary);
    font-weight: 600;
    font-family: monospace;
    letter-spacing: 0.05em;
}

/* Tooltip - Technical Information Display */
.tooltip {
    position: absolute;
    z-index: 1000;
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-deep);
    border: 1px solid var(--border-strong);
    font-size: 0.75rem;
    font-family: monospace;
    pointer-events: none;
    opacity: 0;
    transform: translateY(8px);
    transition: all var(--transition-precise);
    max-width: 280px;
    white-space: nowrap;
    letter-spacing: 0.05em;
}

.tooltip::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--accent-primary);
    opacity: 0.6;
}

.tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Loading Overlay - Technical Boot Sequence */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-primary);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-smooth);
}

.loading-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 2px solid var(--grid-line);
    border-top: 2px solid var(--accent-primary);
    border-radius: 2px;
    animation: technical-spin 1.2s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
    margin-bottom: var(--spacing-xl);
    position: relative;
}

.loading-spinner::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: var(--accent-primary);
    border-radius: 1px;
    animation: pulse 0.8s ease-in-out infinite;
}

.loading-text {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: monospace;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

@keyframes technical-spin {
    0% { transform: rotate(0deg); }
    25% { transform: rotate(90deg); border-radius: 50%; }
    50% { transform: rotate(180deg); border-radius: 2px; }
    75% { transform: rotate(270deg); border-radius: 50%; }
    100% { transform: rotate(360deg); border-radius: 2px; }
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 0.3; transform: translate(-50%, -50%) scale(0.8); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
        gap: 1rem;
    }
    
    .title {
        font-size: 2rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    .controls-panel {
        grid-template-columns: 1fr;
        padding: 1rem;
    }
    
    .control-buttons {
        flex-direction: column;
    }
    
    .btn {
        justify-content: center;
    }
    
    .legend-items {
        justify-content: center;
    }
    
    .legend-item {
        flex: 1;
        min-width: 0;
    }
    
    .piano-keyboard {
        padding: 1rem;
        justify-content: flex-start;
    }
    
    .piano-key.white {
        width: 35px;
        height: 90px;
    }
    
    .piano-key.black {
        width: 25px;
        height: 58px;
    }
    
    .frequency-table {
        font-size: 0.75rem;
    }
    
    .frequency-table th,
    .frequency-table td {
        padding: 0.5rem 0.25rem;
    }
    
    .frequency-cell {
        min-height: 50px;
    }
    
    .info-content {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .frequency-table th,
    .frequency-table td {
        padding: 0.4rem 0.2rem;
    }
    
    .note-header {
        min-width: 70px;
    }
    
    .octave-header {
        min-width: 60px;
    }
    
    .frequency-cell {
        min-height: 45px;
    }
    
    .note-name {
        font-size: 0.7rem;
    }
    
    .frequency-value {
        font-size: 0.6rem;
    }
}

/* Accessibility Improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.frequency-cell:focus,
.piano-key:focus,
.btn:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-primary: #ffffff;
        --border-secondary: #ffffff;
    }
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-secondary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}