:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-subtle: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-ring: rgba(37, 99, 235, 0.22);
  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #b45309;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 24px -4px rgba(15, 23, 42, 0.07), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

body {
  display: flex;
  flex-direction: column;
  position: relative;
}

.bg-decoration {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(600px circle at 12% 8%, rgba(37, 99, 235, 0.07), transparent 60%),
    radial-gradient(520px circle at 88% 12%, rgba(99, 102, 241, 0.06), transparent 60%);
}

.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(248, 250, 252, 0.86);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(226, 232, 240, 0.85);
}

.header-inner {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.brand-text {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand-text h1 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand-badge {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(37, 99, 235, 0.16);
}

.dev-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
  white-space: nowrap;
}

.dev-link:hover {
  color: var(--primary);
  border-color: rgba(37, 99, 235, 0.35);
  background: var(--primary-soft);
  transform: translateY(-1px);
}

.dev-link .external-icon {
  opacity: 0.65;
}

/* Main Layout */
.main-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-top: 22px;
  padding-bottom: 40px;
}

.privacy-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: var(--radius-md);
  background: var(--success-bg);
  border: 1px solid rgba(5, 150, 105, 0.22);
  color: #065f46;
  font-size: 0.86rem;
}

.privacy-banner svg {
  flex-shrink: 0;
  color: var(--success);
}

.top-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 20px;
  align-items: stretch;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-md);
  min-width: 0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

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

/* Dropzone */
.upload-card {
  display: flex;
  flex-direction: column;
}

.dropzone {
  position: relative;
  flex: 1;
  min-height: 220px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 18px;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

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

.dropzone.drag-over {
  border-color: var(--primary);
  background: #dbeafe;
  box-shadow: 0 0 0 4px var(--primary-ring);
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.dropzone-icon {
  width: 58px;
  height: 58px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

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

.dropzone-title span {
  color: var(--primary);
}

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

/* Options */
.options-grid {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.control-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.control-label {
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.control-value {
  font-size: 0.8rem;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text);
  background: var(--surface-subtle);
  padding: 2px 8px;
  border-radius: 6px;
}

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

/* Segmented Control */
.segmented-control {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  background: var(--surface-subtle);
  padding: 4px;
  border-radius: var(--radius-md);
}

.seg-btn {
  padding: 7px 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

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

.seg-btn.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  border-color: rgba(37, 99, 235, 0.15);
  box-shadow: var(--shadow-sm);
}

/* Range Input */
.range-input {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

.range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.25);
  transition: transform 0.12s ease;
}

.range-input::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

.range-input::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.25);
}

.preset-pills {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.pill-btn {
  padding: 5px 8px;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.pill-btn.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.field-desc {
  margin: 0;
  font-size: 0.78rem;
  color: var(--warning);
  background: var(--warning-bg);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}

.size-inputs-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.input-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

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

.num-input {
  width: 100%;
  padding: 8px 11px;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.num-input:focus {
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

/* Summary Bar */
.summary-bar {
  padding: 16px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

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

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

.summary-item strong {
  font-size: 1rem;
  font-family: var(--font-mono);
  color: var(--text);
}

.ratio-good {
  color: var(--success) !important;
}

.ratio-warn {
  color: var(--warning) !important;
}

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

/* Empty List */
.empty-list {
  text-align: center;
  padding: 40px 20px;
}

.empty-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-title {
  margin: 0 0 6px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.empty-desc {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

/* Image Cards Grid */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 18px;
}

.img-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
}

.img-thumb-wrap {
  position: relative;
  height: 180px;
  background-color: #f8fafc;
  background-image:
    linear-gradient(45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1f5f9 75%),
    linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

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

.img-format-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.74);
  color: #ffffff;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  font-weight: 600;
}

.img-ratio-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-family: var(--font-mono);
  font-weight: 700;
}

.img-ratio-badge.saved {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(5, 150, 105, 0.25);
}

.img-ratio-badge.grew {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(180, 83, 9, 0.25);
}

.img-compare-hint {
  position: absolute;
  bottom: 8px;
  right: 10px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.68);
  color: #ffffff;
  font-size: 0.72rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.img-thumb-wrap:hover .img-compare-hint {
  opacity: 1;
}

.img-card-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.img-name {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.img-metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  background: var(--bg);
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.78rem;
}

.metric-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.metric-val {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text);
}

.img-card-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

.img-card-actions .btn-primary {
  flex: 1;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
  white-space: nowrap;
}

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

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

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

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

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

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

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

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

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

.btn-link {
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  padding: 2px 4px;
}

.btn-link:hover {
  text-decoration: underline;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 960px;
  max-height: 90vh;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
}

.modal-close {
  border: none;
  background: var(--surface-subtle);
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

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

.modal-body {
  padding: 18px 20px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  overflow-y: auto;
}

.compare-pane {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.compare-label strong {
  font-family: var(--font-mono);
  color: var(--text);
}

.compare-img-wrap {
  min-height: 240px;
  max-height: 55vh;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  overflow: hidden;
}

.compare-img-wrap img {
  max-width: 100%;
  max-height: 50vh;
  object-fit: contain;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.72);
  margin-top: auto;
}

.footer-inner {
  padding-top: 18px;
  padding-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.footer-note {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.footer-dev-link {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.15s ease;
}

.footer-dev-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  padding: 10px 18px;
  border-radius: 999px;
  background: #0f172a;
  color: #ffffff;
  font-size: 0.86rem;
  font-weight: 500;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 860px) {
  .top-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .dropzone {
    min-height: 170px;
  }

  .modal-body {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 560px) {
  .container {
    padding: 0 14px;
  }

  .card {
    padding: 16px;
  }

  .brand-badge {
    display: none;
  }

  .segmented-control {
    grid-template-columns: repeat(2, 1fr);
  }

  .size-inputs-row {
    grid-template-columns: 1fr;
  }

  .summary-actions {
    width: 100%;
  }

  .summary-actions .btn {
    flex: 1;
  }

  .image-grid {
    grid-template-columns: 1fr;
  }

  .footer-inner {
    flex-direction: column;
    align-items: flex-start;
  }
}
