/* ═══════════════════════════════════════════════════════════
   FLAC Downloader — Premium Dark UI
   ═══════════════════════════════════════════════════════════ */

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

:root {
  --bg-primary: #06060e;
  --bg-secondary: #0c0c1d;
  --bg-card: rgba(15, 15, 35, 0.7);
  --bg-card-hover: rgba(20, 20, 45, 0.8);
  --border-color: rgba(16, 185, 129, 0.15);
  --border-glow: rgba(16, 185, 129, 0.3);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-1: #10b981;
  --accent-2: #34d399;
  --accent-3: #6ee7b7;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Inter', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Background */
.bg-decoration { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.orb {
  position: absolute; border-radius: 50%; filter: blur(120px); opacity: 0.15;
  animation: orbFloat 20s ease-in-out infinite;
}
.orb-1 { width: 600px; height: 600px; background: var(--accent-1); top: -200px; left: -100px; }
.orb-2 { width: 500px; height: 500px; background: var(--accent-2); bottom: -150px; right: -100px; animation-delay: -7s; }
.orb-3 { width: 400px; height: 400px; background: var(--accent-3); top: 40%; left: 50%; animation-delay: -14s; }

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -40px) scale(1.05); }
  66% { transform: translate(-20px, 30px) scale(0.95); }
}

.grid-pattern {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(16,185,129,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16,185,129,0.03) 1px, transparent 1px);
  background-size: 60px 60px;
}

/* Layout */
.app-container {
  position: relative; z-index: 1;
  max-width: 720px; margin: 0 auto;
  padding: 24px 20px 40px;
  min-height: 100vh;
  display: flex; flex-direction: column; gap: 24px;
}

/* Glass Card */
.glass-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  padding: 28px;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.glass-card:hover {
  border-color: var(--border-glow);
  box-shadow: 0 0 30px rgba(16,185,129,0.06);
}

/* Header */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0;
}
.logo-section { display: flex; align-items: center; gap: 14px; }
.logo-icon svg { width: 44px; height: 44px; filter: drop-shadow(0 0 12px rgba(16,185,129,0.4)); }
.logo-text h1 { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.02em; background: linear-gradient(135deg, var(--text-primary), var(--accent-1)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.logo-subtitle { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; letter-spacing: 0.05em; text-transform: uppercase; }

.header-status {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 20px;
  background: rgba(34,197,94,0.08); border: 1px solid rgba(34,197,94,0.15);
  font-size: 0.78rem; color: var(--success); font-weight: 500;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); animation: pulse 2s ease-in-out infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* Input Section */
.input-header { margin-bottom: 20px; }
.input-header h2 { font-size: 1.15rem; font-weight: 700; margin-bottom: 4px; }
.input-header p { font-size: 0.82rem; color: var(--text-secondary); }

.url-input-wrapper {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,0.3); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); padding: 4px 6px; transition: border-color 0.3s, box-shadow 0.3s;
}
.url-input-wrapper:focus-within {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(16,185,129,0.1), 0 0 20px rgba(16,185,129,0.05);
}
.input-icon { padding: 8px; color: var(--text-muted); flex-shrink: 0; }

#urlInput {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text-primary); font-family: var(--mono);
  font-size: 0.85rem; padding: 10px 4px;
  min-width: 0;
}
#urlInput::placeholder { color: var(--text-muted); font-family: var(--font); }

/* Search Dropdown */
.search-dropdown {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); backdrop-filter: blur(24px);
  max-height: 320px; overflow-y: auto; z-index: 100;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  animation: slideIn 0.2s ease;
}
.search-dropdown.hidden { display: none; }
.search-dropdown::-webkit-scrollbar { width: 6px; }
.search-dropdown::-webkit-scrollbar-thumb { background: rgba(16,185,129,0.3); border-radius: 3px; }

.search-results-list { list-style: none; display: flex; flex-direction: column; padding: 6px; gap: 2px; }
.search-item {
  display: flex; align-items: center; gap: 12px; padding: 10px;
  border-radius: 8px; cursor: pointer; transition: all 0.2s;
}
.search-item:hover { background: rgba(16,185,129,0.12); }
.search-item-cover {
  width: 44px; height: 44px; border-radius: 6px; object-fit: cover;
  background: rgba(255,255,255,0.05); flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.search-item-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.search-item-title { font-size: 0.88rem; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-item-artist { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-item-service {
  padding: 2px 8px; border-radius: 10px; font-size: 0.65rem; font-weight: 600;
  background: rgba(52,211,153,0.1); color: var(--accent-2); margin-left: auto; flex-shrink: 0;
}
.search-loading { padding: 16px; text-align: center; color: var(--text-muted); font-size: 0.85rem; display: flex; align-items: center; justify-content: center; gap: 8px; }
.search-loading::after {
  content: ''; width: 14px; height: 14px;
  border: 2px solid rgba(16,185,129,0.3); border-top-color: var(--accent-1);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}

.paste-btn, .download-btn {
  border: none; cursor: pointer; border-radius: 8px;
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font); font-weight: 600; font-size: 0.82rem;
  transition: all 0.2s; flex-shrink: 0;
}
.paste-btn {
  padding: 10px; background: rgba(16,185,129,0.1); color: var(--accent-1);
}
.paste-btn:hover { background: rgba(16,185,129,0.2); }

.download-btn {
  padding: 10px 18px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  color: white;
}
.download-btn:disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(0.5); }
.download-btn:not(:disabled):hover { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(16,185,129,0.3); }

/* Service Badge */
.service-badge-wrapper { margin-top: 14px; }
.service-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 20px;
  font-size: 0.78rem; font-weight: 500;
  background: rgba(16,185,129,0.08); border: 1px solid rgba(16,185,129,0.15);
  color: var(--accent-1);
  animation: slideIn 0.3s ease;
}
.service-badge.tidal { background: rgba(0,255,176,0.06); border-color: rgba(0,255,176,0.15); color: #00ffb0; }
.service-badge.qobuz { background: rgba(52,211,153,0.06); border-color: rgba(52,211,153,0.15); color: var(--accent-2); }
.service-track-id { font-family: var(--mono); opacity: 0.7; }

@keyframes slideIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* Quality Selector */
.quality-selector { margin-top: 16px; }
.quality-selector label { font-size: 0.8rem; color: var(--text-secondary); font-weight: 500; display: block; margin-bottom: 8px; }
.quality-options { display: flex; gap: 8px; }
.quality-btn {
  flex: 1; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-color); background: rgba(0,0,0,0.2);
  color: var(--text-secondary); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: var(--font); transition: all 0.2s;
}
.quality-btn:hover { border-color: var(--border-glow); background: rgba(16,185,129,0.05); }
.quality-btn.active {
  border-color: var(--accent-1); background: rgba(16,185,129,0.1);
  color: var(--text-primary); box-shadow: 0 0 16px rgba(16,185,129,0.1);
}
.quality-icon { font-size: 1.1rem; }
.quality-label { font-size: 0.82rem; font-weight: 600; }
.quality-desc { font-size: 0.68rem; opacity: 0.6; }

/* Download Progress */
.download-card { border-color: rgba(16,185,129,0.25); }
.download-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; gap: 12px; }
.download-info h3 { font-size: 1rem; font-weight: 700; }
.download-subtitle { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; font-family: var(--mono); }

.download-status-badge {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 16px; font-size: 0.72rem; font-weight: 600;
  background: rgba(16,185,129,0.1); color: var(--accent-1); white-space: nowrap;
}
.download-status-badge.completed { background: rgba(34,197,94,0.1); color: var(--success); }
.download-status-badge.failed { background: rgba(239,68,68,0.1); color: var(--error); }

.pulse-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.5s ease-in-out infinite; }

.progress-container { margin-bottom: 16px; }
.progress-bar {
  height: 6px; background: rgba(255,255,255,0.05);
  border-radius: 3px; overflow: hidden; position: relative;
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent-1), var(--accent-2));
  border-radius: 3px; transition: width 0.4s ease;
  position: relative;
}
.progress-glow {
  position: absolute; top: -4px; bottom: -4px; left: 0; width: 0%;
  background: linear-gradient(90deg, transparent, rgba(16,185,129,0.15));
  border-radius: 6px; filter: blur(4px); transition: width 0.4s ease;
}
.progress-info {
  display: flex; justify-content: space-between;
  margin-top: 8px; font-size: 0.75rem; color: var(--text-muted); font-family: var(--mono);
}

/* Download Actions */
.download-actions { display: flex; gap: 10px; margin-top: 4px; }
.action-btn {
  flex: 1; padding: 10px 16px; border-radius: var(--radius-sm);
  border: none; cursor: pointer; font-family: var(--font);
  font-weight: 600; font-size: 0.82rem;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all 0.2s;
}
.action-btn.primary {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  color: white;
}
.action-btn.primary:hover { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(16,185,129,0.3); }
.action-btn.secondary {
  background: rgba(16,185,129,0.08); border: 1px solid var(--border-color);
  color: var(--text-secondary);
}
.action-btn.secondary:hover { background: rgba(16,185,129,0.12); color: var(--text-primary); }

/* History */
.history-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;
}
.history-header h3 { display: flex; align-items: center; gap: 8px; font-size: 0.95rem; font-weight: 700; }
.clear-history-btn {
  padding: 6px; border-radius: 8px; border: none; cursor: pointer;
  background: rgba(239,68,68,0.08); color: var(--error); transition: all 0.2s;
}
.clear-history-btn:hover { background: rgba(239,68,68,0.15); }

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

.history-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.2); border: 1px solid rgba(255,255,255,0.03);
  transition: background 0.2s;
}
.history-item:hover { background: rgba(0,0,0,0.3); }

.history-item-info { flex: 1; min-width: 0; }
.history-item-name { font-size: 0.82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item-meta { font-size: 0.7rem; color: var(--text-muted); font-family: var(--mono); margin-top: 2px; }

.history-item-badge {
  padding: 3px 10px; border-radius: 12px; font-size: 0.68rem; font-weight: 600; white-space: nowrap;
}
.history-item-badge.completed { background: rgba(34,197,94,0.1); color: var(--success); }
.history-item-badge.failed { background: rgba(239,68,68,0.1); color: var(--error); }
.history-item-badge.downloading { background: rgba(16,185,129,0.1); color: var(--accent-1); }

.history-item-actions { display: flex; gap: 4px; }
.history-dl-btn {
  padding: 5px 10px; border-radius: 6px; border: none; cursor: pointer;
  background: rgba(16,185,129,0.1); color: var(--accent-1);
  font-size: 0.72rem; font-weight: 600; transition: all 0.2s;
}
.history-dl-btn:hover { background: rgba(16,185,129,0.2); }

/* Toast */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 0.82rem; font-weight: 500;
  backdrop-filter: blur(12px); border: 1px solid;
  animation: toastIn 0.3s ease;
  max-width: 360px;
}
.toast.success { background: rgba(34,197,94,0.12); border-color: rgba(34,197,94,0.2); color: var(--success); }
.toast.error { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.2); color: var(--error); }
.toast.info { background: rgba(16,185,129,0.12); border-color: rgba(16,185,129,0.2); color: var(--accent-1); }

@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

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

/* Loading spinner for download button */
.download-btn.loading span { display: none; }
.download-btn.loading::after {
  content: ''; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: white;
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state { text-align: center; padding: 24px; color: var(--text-muted); font-size: 0.82rem; }

/* Responsive */
@media (max-width: 640px) {
  .app-container { padding: 16px 14px 32px; }
  .glass-card { padding: 20px; }
  .url-input-wrapper { flex-wrap: wrap; }
  #urlInput { font-size: 0.8rem; }
  .download-btn span { display: none; }
  .quality-options { flex-direction: column; }
  .download-header { flex-direction: column; }
  .download-actions { flex-direction: column; }
  .app-header { flex-direction: column; gap: 10px; align-items: flex-start; }
}
