/* =============================================
   Reset & Base
   ============================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-card-hover: #1f1f38;
  --border: rgba(108, 99, 255, 0.18);
  --border-active: rgba(108, 99, 255, 0.55);
  --accent: #6c63ff;
  --accent-dim: rgba(108, 99, 255, 0.15);
  --accent-hover: #7c74ff;
  --text-primary: #f0f0ff;
  --text-secondary: #9090b8;
  --text-muted: #5c5c88;
  --success: #34d399;
  --warning: #f59e0b;
  --error: #f87171;
  --error-bg: rgba(248, 113, 113, 0.1);
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 32px rgba(0, 0, 0, 0.35);
  --transition: 0.2s ease;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  min-height: 100vh;
  line-height: 1.6;
}

/* =============================================
   Layout
   ============================================= */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main {
  flex: 1;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* =============================================
   Header
   ============================================= */
.header {
  border-bottom: 1px solid var(--border);
  background: rgba(26, 26, 46, 0.8);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logo-text {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.header-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
}

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

.section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 20px;
}

/* =============================================
   Drop Zone
   ============================================= */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 52px 24px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: border-color var(--transition), background var(--transition);
  outline: none;
}

.drop-zone:hover,
.drop-zone:focus-visible {
  border-color: var(--border-active);
  background: var(--accent-dim);
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
  transform: scale(1.005);
}

#fileInput {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.drop-zone-content {
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.drop-icon {
  margin-bottom: 4px;
  transition: transform var(--transition);
}

.drop-zone:hover .drop-icon,
.drop-zone.drag-over .drop-icon {
  transform: translateY(-4px);
}

.drop-primary {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
}

.drop-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

/* =============================================
   File List
   ============================================= */
.file-list {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: rgba(108, 99, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  animation: fadeIn 0.2s ease;
}

.file-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: rgba(108, 99, 255, 0.12);
}

.file-thumb-placeholder {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  flex-shrink: 0;
  background: rgba(108, 99, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
}

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

.file-name {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.file-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
}

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

/* =============================================
   Error Banner
   ============================================= */
.error-banner {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--error-bg);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius-sm);
  font-size: 0.87rem;
  color: var(--error);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  animation: fadeIn 0.2s ease;
}

.error-banner::before {
  content: '⚠';
  flex-shrink: 0;
}

/* =============================================
   Format Buttons
   ============================================= */
.format-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

.format-btn {
  flex: 1;
  padding: 11px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(108, 99, 255, 0.06);
  color: var(--text-secondary);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.03em;
}

.format-btn:hover {
  border-color: var(--border-active);
  color: var(--text-primary);
  background: var(--accent-dim);
}

.format-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.22);
}

/* =============================================
   JPG / AVIF / WebP Options
   ============================================= */
.jpg-options {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeIn 0.2s ease;
}

.option-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.quality-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 28px;
  text-align: right;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.slider-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  flex-shrink: 0;
  width: 28px;
}

.slider-label:last-child {
  text-align: right;
}

.slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 5px;
  border-radius: 4px;
  background: linear-gradient(
    to right,
    var(--accent) var(--pct, 62.5%),
    rgba(108, 99, 255, 0.2) var(--pct, 62.5%)
  );
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.25);
  cursor: pointer;
  transition: box-shadow var(--transition);
}

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.25);
  cursor: pointer;
}

.slider:hover::-webkit-slider-thumb,
.slider:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 5px rgba(108, 99, 255, 0.35);
}

.avif-options {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeIn 0.2s ease;
}

.webp-options {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeIn 0.2s ease;
}
.webp-lossless-note {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 0.84rem;
  color: var(--accent);
  background: rgba(108,99,255,0.08);
  border: 1px solid rgba(108,99,255,0.2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 0;
  animation: fadeIn 0.2s ease;
}

/* =============================================
   Background Color Picker
   ============================================= */
.bg-color-group {
  animation: fadeIn 0.2s ease;
}

.bg-color-notice {
  font-size: 0.84rem;
  color: var(--warning);
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.bg-color-picker {
  display: flex;
  gap: 10px;
}

.color-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(108, 99, 255, 0.06);
  color: var(--text-secondary);
  font-size: 0.87rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.color-btn:hover {
  border-color: var(--border-active);
  color: var(--text-primary);
}

.color-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.color-swatch {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
  display: inline-block;
}

.color-custom-label {
  cursor: pointer;
  position: relative;
}

#customColorInput {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* =============================================
   Convert Button
   ============================================= */
.convert-row {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.convert-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 52px;
  background: var(--accent);
  border: none;
  border-radius: 50px;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition), opacity var(--transition);
  box-shadow: 0 4px 20px rgba(108, 99, 255, 0.4);
}

.convert-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(108, 99, 255, 0.5);
}

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

.convert-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.convert-btn-spinner svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* =============================================
   Progress Section
   ============================================= */
.progress-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.progress-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: rgba(108, 99, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.progress-item-name {
  flex: 1;
  font-size: 0.87rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-item-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

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

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

.progress-bar-wrap {
  width: 80px;
  height: 4px;
  border-radius: 4px;
  background: rgba(108, 99, 255, 0.15);
  overflow: hidden;
  flex-shrink: 0;
}

.progress-bar {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
}

.progress-bar.indeterminate {
  width: 40%;
  animation: indeterminate 1s ease infinite;
}

@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

/* =============================================
   Results Section
   ============================================= */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.results-header .section-title {
  margin-bottom: 0;
}

.download-all-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  background: var(--accent-dim);
  border: 1px solid var(--border-active);
  border-radius: 50px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.download-all-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.results-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.result-card {
  background: rgba(108, 99, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: fadeInUp 0.25s ease;
  transition: border-color var(--transition);
}

.result-card:hover {
  border-color: var(--border-active);
}

.result-thumb-wrap {
  position: relative;
  aspect-ratio: 4/3;
  background: rgba(0,0,0,0.25);
  overflow: hidden;
}

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

.result-badges {
  position: absolute;
  top: 7px;
  left: 7px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
}

.badge-warning {
  background: rgba(245, 158, 11, 0.88);
  color: #1a1200;
}

.result-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.result-filename {
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-download {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--accent-dim);
  border: 1px solid var(--border-active);
  border-radius: 6px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition);
  margin-top: auto;
}

.result-download:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.result-error {
  padding: 10px 14px;
  font-size: 0.82rem;
  color: var(--error);
  background: var(--error-bg);
  border-top: 1px solid rgba(248, 113, 113, 0.2);
}

.result-stats {
  padding: 6px 0;
  border-top: 1px solid rgba(108,99,255,0.15);
  margin: 6px 0 8px;
}
.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.stat-save { font-size: 0.76rem; font-weight: 600; color: var(--success); }
.stat-increase { font-size: 0.76rem; font-weight: 600; color: var(--text-muted); }
.stat-neutral { font-size: 0.76rem; font-weight: 500; color: var(--text-muted); }

/* =============================================
   Footer
   ============================================= */
.footer {
  border-top: 1px solid var(--border);
  padding: 16px 20px;
  text-align: center;
}

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

/* =============================================
   Animations
   ============================================= */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

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

/* =============================================
   Responsive
   ============================================= */
@media (max-width: 600px) {
  .main {
    padding: 16px 14px 40px;
    gap: 14px;
  }

  .card {
    padding: 20px 16px;
  }

  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .header-desc {
    display: none;
  }

  .drop-zone {
    padding: 36px 16px;
  }

  .format-buttons {
    gap: 8px;
  }

  .format-btn {
    padding: 10px 12px;
    font-size: 0.85rem;
  }

  .bg-color-picker {
    flex-wrap: wrap;
  }

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

  .convert-btn {
    padding: 13px 40px;
    font-size: 0.95rem;
  }
}

@media (max-width: 380px) {
  .results-list {
    grid-template-columns: 1fr;
  }
}

/* =============================================
   Turnstile
   ============================================= */

/* Ensure [hidden] always wins over flex display */
[hidden] { display: none !important; }

.turnstile-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.turnstile-hint {
  font-size: 0.75rem;
  color: #888;
  margin: 0;
}
