/* CSS Variables for theming */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #475569;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 600px;
    margin: 0 auto;
    padding: 1rem;
}

/* Header */
header {
    text-align: center;
    padding: 1.5rem 0;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.25rem;
}

header .subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Tuner Section */
.tuner-section {
    background: var(--surface);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
}

/* Meter Container */
.meter-container {
    margin-bottom: 1.5rem;
}

.meter-scale {
    position: relative;
}

.scale-marks {
    display: flex;
    justify-content: space-between;
    padding: 0 0.5rem;
    margin-bottom: 0.5rem;
}

.scale-marks .mark {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.scale-marks .mark.center {
    color: var(--success-color);
    font-weight: 600;
}

.meter-bar {
    position: relative;
    height: 60px;
    background: linear-gradient(to right,
        var(--danger-color) 0%,
        var(--warning-color) 25%,
        var(--success-color) 45%,
        var(--success-color) 55%,
        var(--warning-color) 75%,
        var(--danger-color) 100%
    );
    border-radius: 0.5rem;
    overflow: hidden;
}

.meter-center {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--text-primary);
    transform: translateX(-50%);
    z-index: 2;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.meter-needle {
    position: absolute;
    left: 50%;
    top: 5px;
    bottom: 5px;
    width: 4px;
    background: var(--background);
    border-radius: 2px;
    transform: translateX(-50%);
    transition: left 0.1s ease-out;
    z-index: 3;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

.meter-needle::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 10px solid var(--background);
}

.meter-labels {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0.5rem 0;
}

.flat-label, .sharp-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.flat-label {
    color: var(--danger-color);
}

.sharp-label {
    color: var(--danger-color);
}

/* Note Display */
.note-display {
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.detected-note {
    font-size: 5rem;
    font-weight: 700;
    line-height: 1;
    transition: color 0.2s ease;
}

.detected-note.in-tune {
    color: var(--success-color);
    text-shadow: 0 0 20px rgba(34, 197, 94, 0.5);
}

.detected-note.close {
    color: var(--warning-color);
}

.detected-note.off {
    color: var(--danger-color);
}

.octave {
    font-size: 2rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Cents Display */
.cents-display {
    text-align: center;
    margin-bottom: 0.5rem;
}

.cents-value {
    font-size: 2rem;
    font-weight: 600;
    font-family: 'SF Mono', 'Consolas', monospace;
}

.cents-value.positive::before {
    content: '+';
}

.cents-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-left: 0.25rem;
}

/* Frequency Display */
.frequency-display {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

#frequency-value {
    font-family: 'SF Mono', 'Consolas', monospace;
}

/* Tuning Status */
.tuning-status {
    text-align: center;
    padding: 0.75rem;
    background: var(--surface-light);
    border-radius: 0.5rem;
}

.status-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.tuning-status.in-tune {
    background: rgba(34, 197, 94, 0.2);
}

.tuning-status.in-tune .status-text {
    color: var(--success-color);
    font-weight: 600;
}

/* Controls Section */
.controls-section {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn.primary {
    background: var(--primary-color);
    color: white;
    width: 100%;
}

.btn.primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn.primary.active {
    background: var(--danger-color);
}

.btn.secondary {
    background: var(--surface-light);
    color: var(--text-primary);
    padding: 0.625rem 1rem;
}

.btn.secondary:hover {
    background: var(--border-color);
}

.btn.secondary.playing {
    background: var(--primary-color);
}

.btn.small {
    padding: 0.5rem 0.75rem;
    font-size: 1.25rem;
    background: var(--surface-light);
    color: var(--text-primary);
    min-width: 40px;
}

.btn.small:hover {
    background: var(--border-color);
}

.btn-icon {
    font-size: 1rem;
}

/* Reference Section */
.reference-section {
    background: var(--surface);
    border-radius: 0.75rem;
    padding: 1rem;
}

.reference-section h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}

.reference-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.note-select, .octave-select {
    flex: 1;
    padding: 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background: var(--surface-light);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
}

.note-select:focus, .octave-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.reference-frequency {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Calibration Section */
.calibration-section {
    background: var(--surface);
    border-radius: 0.75rem;
    padding: 1rem;
}

.calibration-section h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}

.calibration-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.a4-value {
    font-size: 1.5rem;
    font-weight: 600;
    font-family: 'SF Mono', 'Consolas', monospace;
    min-width: 50px;
    text-align: center;
}

/* Footer */
footer {
    text-align: center;
    padding: 1.5rem 0 1rem;
    margin-top: auto;
}

footer a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    transition: color 0.2s ease;
}

footer a:hover {
    color: var(--primary-color);
}

/* Responsive Design */
@media (max-width: 480px) {
    html {
        font-size: 14px;
    }

    .app-container {
        padding: 0.75rem;
    }

    header h1 {
        font-size: 2rem;
    }

    .detected-note {
        font-size: 4rem;
    }

    .meter-bar {
        height: 50px;
    }

    .tuner-section {
        padding: 1rem;
    }
}

@media (min-width: 768px) {
    .app-container {
        padding: 2rem;
    }

    .tuner-section {
        padding: 2rem;
    }

    .meter-bar {
        height: 70px;
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

.tuning-status.in-tune .status-text {
    animation: pulse 1.5s ease-in-out infinite;
}

/* Dark mode is default, but add light mode support */
@media (prefers-color-scheme: light) {
    :root {
        --background: #f8fafc;
        --surface: #ffffff;
        --surface-light: #f1f5f9;
        --text-primary: #1e293b;
        --text-secondary: #64748b;
        --text-muted: #94a3b8;
        --border-color: #e2e8f0;
        --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    }

    .meter-needle {
        background: var(--text-primary);
    }

    .meter-needle::before {
        border-top-color: var(--text-primary);
    }
}
