:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-hover: #f4f4f5;
  --surface-elevated: #ffffff;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-muted: #71717a;
  --text-subtle: #a1a1aa;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.08);
  --accent-text: #ffffff;
  --success: #16a34a;
  --warning-bg: #fef3c7;
  --warning-text: #78350f;
  --error: #dc2626;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, 0.12);
  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0b;
    --surface: #131316;
    --surface-hover: #1f1f23;
    --surface-elevated: #18181c;
    --border: #27272a;
    --border-strong: #3f3f46;
    --text: #fafafa;
    --text-muted: #a1a1aa;
    --text-subtle: #71717a;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-soft: rgba(59, 130, 246, 0.15);
    --accent-text: #ffffff;
    --success: #22c55e;
    --warning-bg: #422006;
    --warning-text: #fde68a;
    --error: #ef4444;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, 0.6);
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
}

.header {
  text-align: center;
  padding: 48px 24px 24px;
}

.header h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.subtitle strong {
  color: var(--text);
  font-weight: 600;
}

.privacy {
  margin: 16px auto 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-muted);
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.18);
  animation: pulse 2.5s ease-in-out infinite;
}

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

.container {
  flex: 1;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 24px;
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#quality-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  background: var(--surface-hover);
  padding: 2px 8px;
  border-radius: 4px;
}

.bg-hint {
  font-size: 11px;
  color: var(--text-subtle);
  font-weight: 400;
}

input[type="color"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
  cursor: pointer;
  padding: 4px;
  font-family: inherit;
}

input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}
input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 4px;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 36px 10px 12px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: border-color var(--transition), background var(--transition);
}

select:hover {
  border-color: var(--border-strong);
}

select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: var(--surface-hover);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
  margin: 8px 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition);
}

input[type="range"]:hover::-webkit-slider-thumb,
input[type="range"]:focus::-webkit-slider-thumb {
  transform: scale(1.15);
}

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 56px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
  margin-bottom: 16px;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.dropzone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.005);
}

.dropzone-icon {
  width: 48px;
  height: 48px;
  color: var(--text-subtle);
  margin: 0 auto 12px;
  display: block;
  transition: color var(--transition);
}

.dropzone:hover .dropzone-icon,
.dropzone.is-dragging .dropzone-icon {
  color: var(--accent);
}

.dropzone-text {
  margin: 0 0 4px;
  font-size: 15px;
  color: var(--text);
}

.dropzone-hint {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}

.link-button:hover {
  color: var(--accent-hover);
}

.warning {
  background: var(--warning-bg);
  color: var(--warning-text);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  margin-bottom: 16px;
}

.actions {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

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

.file-item {
  display: grid;
  grid-template-columns: 56px 1fr auto auto;
  gap: 14px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  transition: border-color var(--transition), box-shadow var(--transition);
  animation: slideIn 200ms ease-out;
}

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

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

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

.file-thumb {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

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

.file-name {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-meta {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.file-savings {
  color: var(--success);
  font-weight: 500;
}

.file-savings.is-negative {
  color: var(--text-subtle);
}

.file-progress {
  height: 3px;
  background: var(--surface-hover);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 4px;
}

.file-progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 200ms ease;
}

.file-item.is-done .file-progress-bar {
  background: var(--success);
}

.file-item.is-error .file-progress-bar {
  background: var(--error);
}

.file-status {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

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

.file-item.is-done .file-status {
  color: var(--success);
}

.file-action {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.file-action:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

.file-download:hover {
  color: var(--accent);
  border-color: var(--accent);
}

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

.footer {
  text-align: center;
  padding: 24px;
  color: var(--text-subtle);
  font-size: 12px;
  font-family: var(--font-mono);
}

@media (max-width: 540px) {
  .header { padding-top: 32px; }
  .container { padding: 16px; }
  .dropzone { padding: 40px 16px; }
  .file-item {
    grid-template-columns: 48px 1fr auto;
  }
  .file-thumb { width: 48px; height: 48px; }
  .file-action { width: 28px; height: 28px; }
}

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