:root {
  --bg: #0c0e14;
  --bg-card: #141820;
  --bg-elevated: #1a1f2b;
  --border: #252b3b;
  --text: #e8ecf4;
  --text-muted: #8b95a8;
  --accent: #4f8cff;
  --accent-hover: #3a7aef;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(79, 140, 255, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(52, 211, 153, 0.06), transparent);
  pointer-events: none;
  z-index: -1;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 32px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 16px rgba(79, 140, 255, 0.35);
}

.header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
  white-space: nowrap;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: #222838; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-elevated);
  color: var(--text);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.3);
}
.btn-danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.25); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
}
.btn-icon:hover { background: var(--bg-elevated); color: var(--text); }

/* Download panel */
.download-panel {
  padding: 20px;
  margin-bottom: 24px;
}

.url-input-group {
  display: flex;
  gap: 10px;
}

.url-input-group input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.url-input-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.15);
}

.url-input-group input::placeholder { color: var(--text-muted); }

.options-row {
  display: flex;
  gap: 16px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.option-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 160px;
}

.option-field span {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.option-field select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.option-field select:focus { border-color: var(--accent); }

.option-field small {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.hidden { display: none !important; }

/* Probe result */
.probe-result {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.probe-header {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.probe-thumb {
  width: 120px;
  height: 68px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.probe-info h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.probe-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.probe-formats {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.probe-loading,
.probe-error {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.probe-error { color: var(--danger); }

.available-formats {
  margin-top: 12px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.formats-heading {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.formats-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.format-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.format-chip:hover,
.format-chip:focus {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.08);
  outline: none;
}

.format-chip strong {
  font-size: 0.85rem;
  font-weight: 600;
}

.format-chip span {
  color: var(--text-muted);
}

/* Downloads list */
.downloads-section { flex: 1; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.section-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.downloads-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state p { margin-top: 12px; font-size: 0.9rem; }

.download-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  align-items: center;
  transition: border-color 0.15s;
}

.download-item:hover { border-color: #333d52; }

.download-item-ready {
  border-color: rgba(52, 211, 153, 0.45);
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.12);
}

.resolution-tag {
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(79, 140, 255, 0.12);
  color: var(--accent);
  font-weight: 600;
}

.download-item-info { min-width: 0; }

.download-item-title {
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.download-item-url {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.download-item-meta {
  display: flex;
  gap: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.download-item-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.progress-bar-wrap {
  grid-column: 1 / -1;
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #7c5cff);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.download-error {
  grid-column: 1 / -1;
  font-size: 0.78rem;
  color: var(--danger);
  background: rgba(248, 113, 113, 0.08);
  padding: 8px 10px;
  border-radius: 6px;
}

/* Status badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-queued { background: rgba(139, 149, 168, 0.15); color: var(--text-muted); }
.status-downloading { background: rgba(79, 140, 255, 0.15); color: var(--accent); }
.status-processing { background: rgba(251, 191, 36, 0.15); color: var(--warning); }
.status-completed { background: rgba(52, 211, 153, 0.15); color: var(--success); }
.status-failed { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.status-cancelled { background: rgba(139, 149, 168, 0.1); color: var(--text-muted); }

.status-ffmpeg-ok { background: rgba(52, 211, 153, 0.12); color: var(--success); }
.status-ffmpeg-missing { background: rgba(251, 191, 36, 0.12); color: var(--warning); }

/* Footer */
.footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-note {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Modal */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 520px;
  width: calc(100% - 40px);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.modal-content {
  padding: 24px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h2 { font-size: 1.1rem; }

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-field span {
  font-size: 0.82rem;
  font-weight: 500;
}

.form-field input,
.form-field select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

.form-field input:focus,
.form-field select:focus { border-color: var(--accent); }

.form-field small {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.form-row-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  cursor: pointer;
}

.checkbox-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  animation: slideIn 0.25s ease;
  max-width: 360px;
}

.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--accent); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 640px) {
  .url-input-group { flex-direction: column; }
  .header { flex-direction: column; align-items: flex-start; }
  .header-actions { width: 100%; }
  .header-actions .btn { flex: 1; justify-content: center; }
  .download-item {
    grid-template-columns: 1fr;
  }
  .download-item-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .btn-save-device {
    flex: 1;
    justify-content: center;
  }
  .toast-container {
    left: 16px;
    right: 16px;
    bottom: 16px;
  }
  .toast { max-width: none; }
}