/* ============================================
   FLAC-to-MP3 Converter — Mobile-First Styles
   Dark theme · CSS variables · system-ui
   ============================================ */

:root {
    --bg-primary: #0f0f13;
    --bg-secondary: #1a1a24;
    --bg-card: #1e1e2e;
    --bg-hover: #252538;
    --text-primary: #e4e4ef;
    --text-secondary: #9d9db5;
    --text-muted: #6b6b85;
    --accent: #6c5ce7;
    --accent-light: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.25);
    --accent-border: rgba(108, 92, 231, 0.5);
    --border: #2d2d44;
    --border-light: #3d3d5c;
    --success: #00b894;
    --success-glow: rgba(0, 184, 148, 0.25);
    --error: #e17055;
    --error-glow: rgba(225, 112, 85, 0.25);
    --warning: #fdcb6e;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.5);
    --transition: 0.2s ease;
    --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Focus styles for accessibility */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Skip link */
.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: #fff;
    z-index: 1000;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 var(--radius-sm) 0;
}

.skip-link:focus {
    top: 0;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ===== Layout ===== */
.app {
    max-width: 680px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 2rem;
}

.app-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

/* ===== Upload Zone ===== */
.upload-zone {
    border: 2px dashed var(--border-light);
    border-radius: var(--radius);
    padding: 2.5rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
    position: relative;
    background: var(--bg-secondary);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.upload-zone.dragover {
    border-style: solid;
    transform: scale(1.01);
}

.upload-zone input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.upload-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--accent-glow);
    border: 1px solid var(--accent-border);
}

.upload-icon svg {
    width: 28px;
    height: 28px;
    stroke: var(--accent-light);
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.upload-text {
    font-size: 1.05rem;
    font-weight: 500;
    margin-bottom: 0.35rem;
    color: var(--text-primary);
}

.upload-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.upload-hint strong {
    color: var(--text-secondary);
}

/* ===== File List ===== */
.file-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition);
}

.file-item.success {
    border-color: var(--success);
}

.file-item.error {
    border-color: var(--error);
}

.file-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-glow);
    border-radius: var(--radius-xs);
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent-light);
    font-family: var(--font-mono);
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-size: 0.88rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    display: flex;
    gap: 0.75rem;
    margin-top: 0.15rem;
}

.file-status {
    flex-shrink: 0;
    font-size: 0.78rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.file-status.pending { color: var(--text-muted); }
.file-status.converting { color: var(--accent-light); }
.file-status.done { color: var(--success); }
.file-status.failed { color: var(--error); }

.file-remove {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    font-size: 1rem;
}

.file-remove:hover {
    background: var(--error-glow);
    border-color: var(--error);
    color: var(--error);
}

/* ===== Progress Bar (Waveform Style) ===== */
.progress-container {
    margin-top: 0.5rem;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    transition: width 0.3s ease;
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        90deg,
        transparent 0px,
        transparent 3px,
        rgba(255,255,255,0.15) 3px,
        rgba(255,255,255,0.15) 4px
    );
    animation: waveform-scroll 0.6s linear infinite;
}

@keyframes waveform-scroll {
    from { background-position: 0 0; }
    to { background-position: 8px 0; }
}

.progress-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    text-align: right;
    font-family: var(--font-mono);
}

/* ===== Action Buttons ===== */
.actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.btn {
    flex: 1;
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), transform 0.1s, box-shadow var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #5b4bd6;
    box-shadow: 0 0 20px var(--accent-glow);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover:not(:disabled) {
    background: #00a381;
    box-shadow: 0 0 20px var(--success-glow);
}

.btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ===== Options ===== */
.options-toggle {
    background: none;
    border: none;
    color: var(--accent-light);
    font-family: var(--font);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.5rem 0;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: color var(--transition);
}

.options-toggle:hover { color: var(--accent); }

.options-toggle svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    transition: transform var(--transition);
}

.options-toggle[aria-expanded="true"] svg {
    transform: rotate(180deg);
}

.options-panel {
    display: none;
    padding-top: 1rem;
}

.options-panel.open {
    display: block;
}

.option-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.option-group label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    min-width: 80px;
}

.option-group select,
.option-group input[type="number"] {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.85rem;
}

.option-group select:focus,
.option-group input:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ===== Toast Notifications ===== */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    pointer-events: auto;
    animation: toast-in 0.3s ease;
    max-width: 340px;
    word-break: break-word;
}

.toast.success {
    background: #0d3d30;
    border: 1px solid var(--success);
    color: var(--success);
}

.toast.error {
    background: #3d1f1a;
    border: 1px solid var(--error);
    color: var(--error);
}

.toast.info {
    background: var(--bg-card);
    border: 1px solid var(--accent);
    color: var(--accent-light);
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Footer ===== */
.app-footer {
    margin-top: auto;
    padding-top: 2rem;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.app-footer a {
    color: var(--accent-light);
    text-decoration: none;
}

.app-footer a:hover { text-decoration: underline; }

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.88rem;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 19, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 998;
    backdrop-filter: blur(4px);
}

.loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin-bottom: 1rem;
}

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

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Responsive ===== */
@media (min-width: 480px) {
    .app {
        padding: 2rem 1.5rem 3rem;
    }

    .app-header h1 {
        font-size: 1.85rem;
    }

    .upload-zone {
        padding: 3rem 2rem;
    }
}

@media (min-width: 640px) {
    .app {
        max-width: 720px;
        padding: 2.5rem 2rem 3rem;
    }

    .app-header h1 {
        font-size: 2.1rem;
    }

    .toast-container {
        bottom: 2rem;
        right: 2rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== High contrast / forced-colors ===== */
@media (forced-colors: active) {
    .upload-zone {
        border: 2px dashed ButtonText;
    }

    .btn-primary {
        border: 2px solid ButtonText;
    }

    .progress-fill {
        background: Highlight;
    }
}
