:root {
  --bg: #f4f5fb;
  --bg-alt: #ffffff;
  --card: #ffffff;
  --border: #e2e4f0;
  --text: #1a1d2b;
  --text-dim: #666d8a;
  --accent: #5a46e8;
  --accent-2: #1fa972;
  --danger: #d13458;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(circle at 20% -10%, rgba(109, 91, 255, 0.18), transparent 45%),
              radial-gradient(circle at 100% 0%, rgba(61, 220, 151, 0.12), transparent 40%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app {
  max-width: 1040px;
  margin: 0 auto;
  padding: 48px 24px 32px;
}

.app-header {
  text-align: center;
  margin-bottom: 28px;
}

.app-header h1 {
  font-size: 1.9rem;
  margin: 0 0 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  color: var(--text-dim);
  margin: 0;
  font-size: 0.95rem;
}

.back-link {
  margin: 0 0 10px;
}

.back-link a {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: rgba(109, 91, 255, 0.06);
}

.dropzone-icon {
  font-size: 2rem;
  margin-bottom: 8px;
  color: var(--accent);
}

.hint {
  color: var(--text-dim);
  font-size: 0.82rem;
  margin: 4px 0 0;
}

.hidden { display: none !important; }

.file-icon { font-size: 2.2rem; margin-bottom: 6px; }

.file-thumb {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: 640px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin: 0 auto 14px;
  object-fit: contain;
  background: var(--bg-alt);
}
.file-name { font-weight: 600; margin: 0; word-break: break-all; }
.file-meta { color: var(--text-dim); font-size: 0.85rem; margin: 4px 0 10px; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: underline;
  padding: 0;
}

.options { margin-top: 24px; display: flex; flex-direction: column; gap: 18px; }

.option-row { display: flex; flex-direction: column; gap: 8px; }

.option-row label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
}

select, input[type="number"] {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.95rem;
}

.mode-toggle {
  display: flex;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
}

.mode-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 9px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}

.mode-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.size-input {
  display: flex;
  gap: 8px;
}

.size-input input { flex: 1; }
.size-input select { width: 90px; }

.primary-btn {
  display: block;
  text-align: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border: none;
  border-radius: 10px;
  padding: 13px 18px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: filter 0.15s ease, transform 0.05s ease;
}

.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:active { transform: scale(0.99); }

.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}

.result {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.compare {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.compare-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.compare-img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
}

.compare-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.result-stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 0.72rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-weight: 700; font-size: 1.05rem; }
.stat-arrow { color: var(--text-dim); font-size: 1.2rem; }
.stat-ratio .stat-value { color: var(--accent-2); }

.status {
  margin-top: 18px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-dim);
}

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

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: -2px;
  animation: spin 0.7s linear infinite;
}

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

.app-footer {
  text-align: center;
  margin-top: 24px;
  color: var(--text-dim);
  font-size: 0.8rem;
}

@media (max-width: 640px) {
  .app { padding: 28px 14px 24px; }
  .card { padding: 20px; }
  .app-header h1 { font-size: 1.5rem; }
  .subtitle { font-size: 0.88rem; }
  .dropzone { padding: 26px 14px; }
  .file-thumb { max-height: 320px; }

  .compare { flex-direction: column; align-items: stretch; }
  .compare-img { max-height: 260px; }

  .result-stats {
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
    row-gap: 12px;
  }
  .stat-arrow { display: none; }

  .size-input { flex-wrap: wrap; }
  .size-input select { width: 100%; }
}

@media (max-width: 400px) {
  .app-header h1 { font-size: 1.3rem; }
  .mode-btn { font-size: 0.8rem; padding: 8px 6px; }
}
