:root {
  --bg-page: #f6f8fb;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 10px 25px -5px rgba(15, 23, 42, 0.07), 0 4px 10px -4px rgba(15, 23, 42, 0.04);
}

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

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-badge {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.24);
  flex-shrink: 0;
}

.app-header h1 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.privacy-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: #065f46;
  font-size: 0.82rem;
  font-weight: 600;
}

.privacy-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.2);
}

/* Controls Card */
.controls-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px;
}

@media (max-width: 900px) {
  .controls-grid {
    grid-template-columns: 1fr;
    gap: 18px;
  }
}

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

.control-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 26px;
}

.control-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.optional-tag {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-subtle);
  padding: 1px 6px;
  border-radius: 4px;
}

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

.jpg-bg-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.jpg-bg-wrap input[type="color"] {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  cursor: pointer;
  background: none;
}

/* Segmented Format Selector */
.segmented-group {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr 1fr;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: 10px;
  gap: 4px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}

.seg-btn:hover {
  color: var(--text-main);
}

.seg-btn.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
}

/* Quality Slider */
.quality-badge {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 2px 9px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

.slider-wrap {
  display: flex;
  align-items: center;
  height: 36px;
}

input[type="range"]#qualitySlider {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #dbeafe;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Width Input */
.width-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

#maxWidthInput {
  width: 100%;
  height: 38px;
  padding: 0 32px 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  font-size: 0.88rem;
  color: var(--text-main);
  background: #ffffff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#maxWidthInput:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.clear-input-btn {
  position: absolute;
  right: 8px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clear-input-btn:hover {
  background: #e2e8f0;
  color: var(--text-main);
}

/* Preset Chips */
.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preset-chip {
  border: 1px solid var(--border-color);
  background: #ffffff;
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.preset-chip:hover {
  border-color: #93c5fd;
  color: var(--primary);
}

.preset-chip.active {
  border-color: #93c5fd;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.control-hint {
  margin: 0;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.smart-keep-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  margin-top: 2px;
}

.smart-keep-row input[type="checkbox"] {
  accent-color: var(--primary);
  cursor: pointer;
  margin: 0;
}

/* Dropzone */
.dropzone {
  background: var(--bg-card);
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-lg);
  padding: 36px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 20px;
}

.dropzone.compact {
  padding: 20px 24px;
}

.dropzone.compact .dropzone-content {
  flex-direction: row;
  justify-content: space-between;
  text-align: left;
  gap: 16px;
  flex-wrap: wrap;
}

.dropzone.compact .upload-icon-circle {
  width: 44px;
  height: 44px;
  margin: 0;
}

.dropzone.compact .dropzone-text {
  flex: 1;
  min-width: 220px;
}

.dropzone.compact .dropzone-text h2 {
  font-size: 1rem;
  margin-bottom: 2px;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.drag-active {
  border-color: var(--primary);
  background: #f8fbff;
  outline: none;
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.upload-icon-circle {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dropzone-text h2 {
  margin: 0 0 6px;
  font-size: 1.12rem;
  font-weight: 600;
  color: var(--text-main);
}

.dropzone-text p {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  font-size: 0.75rem;
  font-family: inherit;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

.dropzone-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.22);
}

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

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

.btn-secondary:hover:not(:disabled) {
  border-color: #94a3b8;
  background: var(--bg-subtle);
}

.btn-ghost {
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

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

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

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
  border-radius: 7px;
}

/* Summary Bar */
.summary-bar {
  position: sticky;
  top: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  box-shadow: var(--shadow-md);
  margin-bottom: 16px;
}

.summary-stats {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.stat-divider {
  width: 1px;
  height: 28px;
  background: var(--border-color);
}

.savings-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 700;
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-border);
  font-variant-numeric: tabular-nums;
}

.savings-pill.increase {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn-border);
}

.summary-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Checkerboard background for transparent PNG/WebP previews */
.checkerboard {
  background-color: #f8fafc;
  background-image:
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

/* Image Cards List */
.image-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.image-card {
  display: grid;
  grid-template-columns: 112px minmax(0, 1.5fr) minmax(190px, 1fr) auto;
  align-items: center;
  gap: 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.image-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}

@media (max-width: 780px) {
  .image-card {
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 12px;
  }
  .card-metrics,
  .card-actions {
    grid-column: 1 / -1;
  }
  .card-actions {
    justify-content: flex-end;
  }
}

.thumb-wrap {
  position: relative;
  width: 112px;
  height: 80px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  cursor: pointer;
  flex-shrink: 0;
}

@media (max-width: 780px) {
  .thumb-wrap {
    width: 88px;
    height: 68px;
  }
}

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

.thumb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.56);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.thumb-wrap:hover .thumb-overlay {
  opacity: 1;
}

/* Card File & Format Info */
.card-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.file-name {
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.format-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 0.74rem;
  font-weight: 700;
  background: var(--primary-soft);
  color: var(--primary);
}

.dim-text {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.ratio-bar-track {
  width: 100%;
  max-width: 260px;
  height: 5px;
  border-radius: 999px;
  background: var(--bg-subtle);
  overflow: hidden;
}

.ratio-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--success);
  transition: width 0.25s ease;
}

.ratio-bar-fill.increase {
  background: var(--warn);
}

/* Card Size Comparison Metrics */
.card-metrics {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 780px) {
  .card-metrics {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding-top: 6px;
    border-top: 1px dashed var(--border-color);
  }
}

.size-compare-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.9rem;
}

.orig-size {
  color: var(--text-muted);
  text-decoration: line-through;
  font-size: 0.84rem;
}

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

.out-size {
  font-weight: 700;
  color: var(--text-main);
  font-size: 0.98rem;
}

.delta-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-border);
}

.delta-badge.increase {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn-border);
}

.status-processing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.83rem;
  color: var(--primary);
  font-weight: 600;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #bfdbfe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

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

.status-error {
  font-size: 0.8rem;
  color: var(--danger);
  font-weight: 600;
}

/* Card Actions */
.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-remove-btn {
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.14s ease;
}

.icon-remove-btn:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Full-screen Drag Overlay */
.drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(37, 99, 235, 0.12);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: none;
}

.drag-overlay-box {
  background: #ffffff;
  border: 2px dashed var(--primary);
  border-radius: 20px;
  padding: 40px 56px;
  text-align: center;
  color: var(--primary);
  box-shadow: var(--shadow-md);
}

.drag-overlay-box p {
  margin: 12px 0 4px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.drag-overlay-box span {
  font-size: 0.86rem;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  background: #0f172a;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.25);
}

/* Before / After Comparison Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-panel {
  width: 100%;
  max-width: 940px;
  background: #ffffff;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  max-height: 92vh;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.02rem;
}

.modal-subtitle {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.icon-close-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 1.3rem;
  cursor: pointer;
}

.icon-close-btn:hover {
  background: #e2e8f0;
  color: var(--text-main);
}

.compare-stage {
  position: relative;
  width: 100%;
  height: min(62vh, 540px);
  overflow: hidden;
  user-select: none;
  touch-action: none;
  cursor: ew-resize;
}

.compare-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.before-clip {
  position: absolute;
  inset: 0;
  clip-path: inset(0 50% 0 0);
}

.compare-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  background: #ffffff;
  box-shadow: 0 0 8px rgba(15, 23, 42, 0.45);
  pointer-events: none;
}

.compare-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.compare-handle svg {
  margin: 0 -3px;
}

.compare-tag {
  position: absolute;
  top: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.72);
  color: #ffffff;
  font-size: 0.76rem;
  font-weight: 600;
  pointer-events: none;
}

.tag-before {
  left: 12px;
}

.tag-after {
  right: 12px;
}

.compare-range-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  background: #f8fafc;
}

.modal-meta {
  font-size: 0.84rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
