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

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --success: #059669;
  --success-hover: #047857;
  --danger: #dc2626;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.07), 0 4px 16px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC',
    'Microsoft JhengHei', 'Noto Sans TC', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 32px 16px 64px;
}

.app {
  max-width: 840px;
  margin: 0 auto;
}

/* ── Header ── */
.header {
  text-align: center;
  margin-bottom: 28px;
}
.header h1 {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.header p {
  color: var(--muted);
  font-size: 0.88rem;
}

/* ── Options Card ── */
.options-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 14px;
}
.option-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-end;
}
.option-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.option-row > .option-group:first-child {
  width: 100%;
}
.option-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
}
.btn-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.toggle-btn {
  padding: 6px 13px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.83rem;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.toggle-btn small {
  font-size: 0.68em;
  opacity: .8;
  margin-left: 2px;
}
.toggle-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.toggle-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
  pointer-events: none;
}
.toggle-btn.tinify-btn { border-color: #f59e0b; color: #b45309; }
.toggle-btn.tinify-btn:hover { border-color: #d97706; background: #fef3c7; }
.toggle-btn.tinify-btn.active { background: #f59e0b; border-color: #f59e0b; color: #fff; }

.tinify-status { display: inline-block; margin-left: 6px; vertical-align: middle; }
.tinify-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  cursor: default;
}
.tinify-dot.ok  { background: var(--success); box-shadow: 0 0 0 2px #d1fae5; }
.tinify-dot.off { background: #94a3b8; }

.tinify-note-text {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 8px 0 2px;
  font-style: italic;
}

.toggle-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.quality-group { flex: 1; min-width: 160px; }
.slider {
  -webkit-appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 4px;
  background: #dde1f0;
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 1px 6px rgba(79,70,229,.45);
  transition: transform .1s;
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.15); }

/* ── Drop Zone ── */
.drop-zone {
  background: var(--card);
  border: 2px dashed #c7d2fe;
  border-radius: var(--radius);
  padding: 52px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  margin-bottom: 14px;
}
.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: #eef2ff;
}
.drop-zone.compact {
  padding: 11px 24px;
}
.drop-zone.compact .drop-icon,
.drop-zone.compact .drop-text,
.drop-zone.compact .drop-hint {
  display: none;
}
.drop-zone.compact .drop-sub {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.drop-icon {
  color: #a5b4fc;
  margin-bottom: 14px;
  transition: color .2s;
}
.drop-zone.drag-over .drop-icon { color: var(--primary); }
.drop-text {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.drop-sub { color: var(--muted); font-size: 0.9rem; margin-bottom: 8px; }
.drop-hint { font-size: 0.78rem; color: #94a3b8; }

/* ── File List ── */
.file-list-section {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 14px;
}
.file-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 20px;
  border-bottom: 1px solid var(--border);
}
.file-count { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.file-list { max-height: 440px; overflow-y: auto; }

.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.file-item:last-child { border-bottom: none; }
.file-item:hover { background: #f8fafc; }

.file-thumb {
  width: 42px;
  height: 42px;
  border-radius: 7px;
  object-fit: cover;
  flex-shrink: 0;
  background: #f1f5f9;
  border: 1px solid var(--border);
}
.file-info { flex: 1; min-width: 0; }
.file-name {
  font-size: 0.86rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  margin-bottom: 4px;
}
.file-sizes {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.79rem;
}
.size-original { color: var(--muted); }
.size-arrow { color: #cbd5e1; }
.size-new { font-weight: 700; }
.size-new.good { color: #059669; }
.size-new.ok   { color: #d97706; }
.size-new.bad  { color: var(--danger); }

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
}
.badge.good { background: #d1fae5; color: #065f46; }
.badge.ok   { background: #fef3c7; color: #92400e; }
.badge.bad  { background: #fee2e2; color: #991b1b; }

.file-status { font-size: 0.78rem; color: var(--muted); flex-shrink: 0; min-width: 40px; text-align: center; }
.file-status.processing { color: var(--primary); }
.file-status.done  { color: var(--success); }
.file-status.error { color: var(--danger); }

.file-dl { flex-shrink: 0; }
.btn-sm {
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  border: none;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background .15s;
}
.btn-sm:hover { background: var(--primary-hover); }

/* Spinner */
.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid #e0e7ff;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .65s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Action Bar ── */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.stats { font-size: 0.86rem; color: var(--muted); }
.stats strong { color: var(--success); font-weight: 700; }
.action-btns { display: flex; gap: 10px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 22px;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--success-hover); }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: inherit;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
  font-family: inherit;
}
.link-btn.danger { color: var(--danger); }

/* ── Responsive ── */
@media (max-width: 600px) {
  .option-row { flex-direction: column; }
  .action-bar { flex-direction: column; align-items: stretch; }
  .action-btns { flex-direction: column; }
  .btn { justify-content: center; }
}
