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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #222636;
  --border: #2e3248;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-light: rgba(99, 102, 241, 0.12);
  --text: #e2e4f0;
  --text-muted: #7b7fa8;
  --success: #22c55e;
  --error: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px 80px;
}

header {
  text-align: center;
  margin-bottom: 48px;
}

header h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #a5b4fc 0%, #818cf8 50%, #6366f1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
}

header p {
  color: var(--text-muted);
  font-size: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 720px;
}

/* Drop Zone */
#drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 56px 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--surface-2);
  position: relative;
}

#drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}

#drop-zone:hover {
  border-color: var(--accent-hover);
  background: var(--accent-light);
}

#drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  background: var(--accent-light);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drop-icon svg {
  width: 28px;
  height: 28px;
  stroke: var(--accent);
}

.drop-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.drop-sub {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.drop-sub span {
  color: var(--accent-hover);
  font-weight: 500;
}

/* Settings Bar */
#settings-bar {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-top: 24px;
  flex-wrap: wrap;
}

.setting-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 160px;
}

.setting-group label {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-weight: 500;
}

.setting-group select,
.setting-group input[type="range"] {
  flex: 1;
}

select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  cursor: pointer;
  width: 100%;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237b7fa8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

select:focus {
  outline: none;
  border-color: var(--accent);
}

input[type="range"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.range-value {
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 600;
  min-width: 36px;
  text-align: right;
}

/* Convert Button */
#convert-btn {
  width: 100%;
  margin-top: 24px;
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--accent) 0%, #818cf8 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  letter-spacing: 0.01em;
}

#convert-btn:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
}

#convert-btn:active:not(:disabled) {
  transform: translateY(0);
}

#convert-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Progress */
#progress-section {
  margin-top: 32px;
  display: none;
}

#progress-section.visible {
  display: block;
}

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

.progress-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

.progress-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.progress-track {
  height: 6px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, #818cf8 100%);
  border-radius: 99px;
  transition: width 0.3s ease;
  width: 0%;
}

/* Results */
#results-section {
  margin-top: 32px;
  display: none;
}

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

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.results-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.results-meta {
  font-size: 0.83rem;
  color: var(--text-muted);
  margin-top: 2px;
}

#download-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--success);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  white-space: nowrap;
}

#download-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

#download-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

/* Preview Grid */
#preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  max-height: 540px;
  overflow-y: auto;
  padding-right: 4px;
}

#preview-grid::-webkit-scrollbar {
  width: 6px;
}

#preview-grid::-webkit-scrollbar-track {
  background: var(--surface-2);
  border-radius: 99px;
}

#preview-grid::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}

.preview-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s;
}

.preview-item:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.preview-item img {
  width: 100%;
  aspect-ratio: auto;
  display: block;
  object-fit: contain;
  background: #fff;
}

.preview-label {
  padding: 6px 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  border-top: 1px solid var(--border);
  font-weight: 500;
}

/* File info badge */
#file-info {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 16px;
}

#file-info.visible {
  display: flex;
}

#file-info svg {
  width: 20px;
  height: 20px;
  stroke: var(--accent);
  flex-shrink: 0;
}

#file-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#file-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

#clear-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px;
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: color 0.2s;
}

#clear-btn:hover {
  color: var(--error);
}

#clear-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

/* Error */
#error-msg {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  margin-top: 16px;
  font-size: 0.875rem;
  color: #fca5a5;
}

#error-msg.visible {
  display: flex;
}

#error-msg svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  flex-shrink: 0;
}

footer {
  margin-top: 48px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

footer a {
  color: var(--accent-hover);
  text-decoration: none;
}

@media (max-width: 480px) {
  .card {
    padding: 20px;
  }
  #settings-bar {
    flex-direction: column;
    align-items: stretch;
  }
}
