:root {
  --bg-primary: #f8f9fc;
  --bg-secondary: #ffffff;
  --bg-elevated: #ffffff;
  --text-primary: #1a1d29;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --accent-primary: #6366f1;
  --accent-secondary: #8b5cf6;
  --accent-hover: #4f46e5;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}

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

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

header {
  background: var(--bg-secondary);
  padding: 2rem 3rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

header h1 {
  font-weight: 700;
  font-size: 1.875rem;
  letter-spacing: -0.025em;
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

header h1 span {
  background: linear-gradient(135deg, var(--accent-secondary) 0%, var(--accent-primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

header p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
  padding-left: 1.5rem;
  border-left: 2px solid var(--border);
}

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 3rem 2rem;
}

/* Drop Zone */
.drop-zone {
  background: var(--bg-secondary);
  border: 2px dashed var(--border);
  border-radius: var(--radius-xl);
  padding: 3.5rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.drop-zone::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.05) 0%, rgba(139, 92, 246, 0.05) 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.drop-zone:hover::before,
.drop-zone.dragover::before {
  opacity: 1;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-lg), 0 0 0 3px rgba(99, 102, 241, 0.1);
  transform: translateY(-2px);
}

.drop-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1.5rem;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  box-shadow: var(--shadow-md);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  z-index: 1;
}

.drop-zone:hover .drop-icon {
  transform: translateY(-4px) scale(1.05);
  box-shadow: var(--shadow-xl);
}

.drop-zone h2 {
  font-weight: 600;
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.drop-zone p {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.drop-zone input {
  display: none;
}

/* Settings */
.settings {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin: 2rem 0;
}

.setting-item {
  background: var(--bg-secondary);
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  transition: all 0.2s ease;
}

.setting-item:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--accent-primary);
}

.setting-item label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  letter-spacing: 0.05em;
}

.setting-item select {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' viewBox='0 0 12 12'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m3 5 3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  transition: all 0.2s ease;
}

.setting-item select:hover {
  border-color: var(--accent-primary);
}

.setting-item select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.range-wrapper {
  display: flex;
  align-items: center;
  gap: 1rem;
}

input[type="range"] {
  -webkit-appearance: none;
  height: 6px;
  background: var(--border-light);
  border-radius: 999px;
  flex: 1;
  cursor: pointer;
  transition: background 0.2s ease;
}

input[type="range"]:hover {
  background: var(--border);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: var(--shadow-md);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.2);
  box-shadow: var(--shadow-md);
}

.range-value {
  font-size: 0.875rem;
  min-width: 3ch;
  color: var(--accent-primary);
  font-weight: 600;
}

/* Action bar */
.action-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

button {
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-weight: 600;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  color: white;
  padding: 0.75rem 1.75rem;
  font-size: 0.875rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.btn-primary::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--accent-hover) 0%, var(--accent-primary) 100%);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.btn-primary:hover:not(:disabled)::before {
  opacity: 1;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary > * {
  position: relative;
  z-index: 1;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  padding: 0.75rem 1.5rem;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--text-primary);
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
}

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

.btn-dl-all {
  background: var(--success);
  color: white;
  padding: 0.75rem 1.75rem;
  font-size: 0.875rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  box-shadow: var(--shadow-md);
}

.btn-dl-all:hover:not(:disabled) {
  background: #059669;
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-dl-all:active:not(:disabled) {
  transform: translateY(0);
}

.btn-dl-all:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: var(--shadow-sm);
}

/* Overall progress */
.overall-progress {
  display: none;
  margin-bottom: 2rem;
  background: var(--bg-secondary);
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.overall-progress.active {
  display: block;
}

.overall-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.overall-track {
  height: 8px;
  background: var(--border-light);
  border-radius: 999px;
  overflow: hidden;
}

.overall-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  transition: width 0.3s ease;
  border-radius: 999px;
}

/* File Queue */
.queue-section {
  margin-bottom: 2rem;
}

.queue-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.queue-header h3 {
  font-weight: 600;
  font-size: 1.125rem;
  color: var(--text-primary);
}

.queue-header span {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
}

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* File Row */
.file-row {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  transition: all 0.2s ease;
  animation: fadeSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  opacity: 0;
  box-shadow: var(--shadow-sm);
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.file-row:hover {
  box-shadow: var(--shadow-md);
}

.file-row.state-converting {
  border-color: var(--warning);
  background: rgba(245, 158, 11, 0.05);
}

.file-row.state-done {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.05);
}

.file-row.state-error {
  border-color: var(--error);
  background: rgba(239, 68, 68, 0.05);
}

.file-row-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.file-row-body {
  min-width: 0;
}

.file-row-name {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.375rem;
  color: var(--text-primary);
}

.file-row-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.125rem;
}

/* Per-file progress bar */
.file-progress-wrap {
  margin-top: 0.625rem;
}

.file-progress-track {
  height: 6px;
  background: var(--border-light);
  border-radius: 999px;
  overflow: hidden;
}

.file-progress-fill {
  height: 100%;
  width: 0%;
  transition: width 0.25s ease;
  background: var(--warning);
  border-radius: 999px;
}

.file-row.state-done .file-progress-fill {
  background: var(--success);
  width: 100% !important;
}

.file-row.state-error .file-progress-fill {
  background: var(--error);
}

.file-progress-label {
  display: flex;
  justify-content: space-between;
  margin-top: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.file-row-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  align-items: center;
}

.status-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  letter-spacing: 0.025em;
}

.badge-loading {
  color: var(--text-muted);
  background: var(--border-light);
}

.badge-waiting {
  color: var(--text-muted);
  background: var(--border-light);
}

.badge-converting {
  color: #92400e;
  background: #fef3c7;
}

.badge-done {
  color: #065f46;
  background: #d1fae5;
}

.badge-error {
  color: #991b1b;
  background: #fee2e2;
}

.btn-remove-file {
  background: transparent;
  color: var(--text-muted);
  font-size: 1.125rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: all 0.2s ease;
}

.btn-remove-file:hover {
  color: var(--error);
  background: rgba(239, 68, 68, 0.1);
}

.btn-dl-file {
  font-size: 0.75rem;
  background: var(--success);
  color: white;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.btn-dl-file:hover {
  background: #059669;
  box-shadow: var(--shadow-md);
}

/* Results */
.results-section {
  display: none;
}

.results-section.visible {
  display: block;
}

.results-section-title {
  font-weight: 600;
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.results-file-group {
  margin-bottom: 3rem;
}

.results-file-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0.75rem 0;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-light);
}

.results-file-header h4 {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
}

.rh-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.results-file-header span {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
}

.btn-dl-group {
  font-size: 0.75rem;
  background: var(--text-primary);
  color: white;
  padding: 0.375rem 0.875rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.btn-dl-group:hover {
  background: var(--accent-primary);
  box-shadow: var(--shadow-md);
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1.25rem;
}

.result-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: fadeSlideIn 0.4s ease forwards;
  opacity: 0;
  box-shadow: var(--shadow-sm);
}

.result-card:hover {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-lg);
  transform: translateY(-4px);
}

.card-thumb {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  display: block;
  background: var(--bg-primary);
  cursor: zoom-in;
  transition: transform 0.3s ease;
}

.result-card:hover .card-thumb {
  transform: scale(1.05);
}

.card-footer {
  padding: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-light);
}

.card-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.btn-dl-single {
  font-size: 0.6875rem;
  background: var(--text-primary);
  color: white;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  font-weight: 600;
  transition: all 0.2s ease;
}

.btn-dl-single:hover {
  background: var(--accent-primary);
  transform: scale(1.05);
}

/* Lightbox */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}

.lightbox.open {
  display: flex;
}

.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  cursor: zoom-out;
}

.lightbox-close {
  position: absolute;
  top: 2rem;
  right: 2rem;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  color: white;
  font-size: 1.5rem;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-md);
  line-height: 1;
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.2s ease;
}

.lightbox-close:hover {
  background: rgba(239, 68, 68, 0.9);
  border-color: rgba(239, 68, 68, 1);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--text-primary);
  color: white;
  padding: 0.875rem 1.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-lg);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  z-index: 1000;
  white-space: nowrap;
  box-shadow: var(--shadow-xl);
  backdrop-filter: blur(10px);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#customRangeItem {
  display: none;
}

.custom-range-input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  background: var(--bg-primary);
  outline: none;
  width: 100%;
  color: var(--text-primary);
  transition: all 0.2s ease;
}

.custom-range-input:hover {
  border-color: var(--accent-primary);
}

.custom-range-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.custom-range-input::placeholder {
  color: var(--text-muted);
}

@media (max-width: 640px) {
  header {
    padding: 1.5rem;
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
  }

  header p {
    border-left: none;
    padding-left: 0;
  }

  main {
    padding: 2rem 1rem;
  }

  .settings {
    grid-template-columns: 1fr;
  }

  .results-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .file-row {
    grid-template-columns: auto 1fr;
  }

  .file-row-actions {
    grid-column: 1/-1;
    justify-content: flex-end;
  }

  .btn-dl-all {
    margin-left: 0;
  }
}
