:root {
  color-scheme: light dark;
  --bg: #fbfbfd;
  --bg-secondary: #f5f5f7;
  --surface: rgba(255, 255, 255, 0.72);
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;
  --border: rgba(0, 0, 0, 0.08);
  --border-input: rgba(0, 0, 0, 0.12);
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-pressed: #006edb;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.12);
  --radius: 18px;
  --radius-sm: 12px;
  --nav-height: 52px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  --hero-gradient: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 113, 227, 0.08), transparent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-secondary: #1d1d1f;
    --surface: rgba(29, 29, 31, 0.78);
    --text: #f5f5f7;
    --text-secondary: #a1a1a6;
    --text-tertiary: #6e6e73;
    --border: rgba(255, 255, 255, 0.1);
    --border-input: rgba(255, 255, 255, 0.14);
    --accent: #2997ff;
    --accent-hover: #40a3ff;
    --accent-pressed: #1a8cff;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55);
    --hero-gradient: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(41, 151, 255, 0.12), transparent);
  }
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.47059;
  letter-spacing: -0.022em;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Nav ── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  background: var(--surface);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 22px;
  height: 100%;
  display: flex;
  align-items: center;
}

.brand {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text);
  text-decoration: none;
}

.brand-dot {
  margin-left: 4px;
  font-weight: 400;
  color: var(--text-secondary);
}

/* ── Main layout ── */
.main {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 22px 80px;
}

/* ── Hero ── */
.hero {
  text-align: center;
  padding: 48px 0 40px;
  background: var(--hero-gradient);
}

.hero-eyebrow {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero h1 {
  margin: 0 0 16px;
  font-size: clamp(40px, 8vw, 56px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  background: linear-gradient(180deg, var(--text) 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

@media (prefers-color-scheme: dark) {
  .hero h1 {
    background: linear-gradient(180deg, #f5f5f7 0%, #a1a1a6 100%);
    -webkit-background-clip: text;
    background-clip: text;
  }
}

.hero-sub {
  margin: 0 auto;
  max-width: 420px;
  font-size: 19px;
  line-height: 1.4211;
  letter-spacing: 0.012em;
  color: var(--text-secondary);
}

/* ── Form card ── */
.card {
  background: var(--surface);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  display: grid;
  gap: 22px;
  box-shadow: var(--shadow-md);
}

.field {
  display: grid;
  gap: 8px;
}

.field-inline {
  display: grid;
  gap: 6px;
}

label {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-secondary);
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 16px;
  letter-spacing: -0.01em;
  background: var(--bg-secondary);
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--text-tertiary);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15);
}

@media (prefers-color-scheme: dark) {
  input:focus,
  select:focus,
  textarea:focus {
    box-shadow: 0 0 0 4px rgba(41, 151, 255, 0.2);
  }
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.input-wrap {
  position: relative;
}

.input-wrap input {
  padding-right: 46px;
}

.toggle-eye {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.toggle-eye svg {
  width: 20px;
  height: 20px;
}

.toggle-eye:hover {
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  .toggle-eye:hover {
    background: rgba(255, 255, 255, 0.08);
  }
}

.toggle-eye .hidden {
  display: none;
}

/* File upload */
.file-drop {
  position: relative;
  border: 1.5px dashed var(--border-input);
  border-radius: var(--radius-sm);
  padding: 20px;
  text-align: center;
  background: var(--bg-secondary);
  transition: border-color 0.2s ease, background 0.2s ease;
  cursor: pointer;
}

.file-drop:hover {
  border-color: var(--accent);
  background: rgba(0, 113, 227, 0.04);
}

.file-drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  padding: 0;
  border: none;
}

.file-hint {
  font-size: 14px;
  color: var(--text-tertiary);
  pointer-events: none;
}

/* Primary button */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 4px;
  padding: 14px 24px;
  border: none;
  border-radius: 980px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.022em;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 14px rgba(0, 113, 227, 0.25);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.01);
}

.btn-primary:active:not(:disabled) {
  background: var(--accent-pressed);
  transform: scale(0.99);
}

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

.status {
  min-height: 1.4em;
  text-align: center;
  font-size: 14px;
  color: var(--text-tertiary);
}

.status.ok {
  color: var(--accent);
  font-weight: 500;
}

.status.err {
  color: #ff3b30;
}

@media (prefers-color-scheme: dark) {
  .status.err {
    color: #ff6961;
  }
}

/* ── Result ── */
.result {
  display: none;
  margin-top: 48px;
  animation: fadeUp 0.6s cubic-bezier(0.25, 0.1, 0.25, 1) both;
}

.result.show {
  display: block;
}

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

.result-title {
  margin: 0 0 20px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-align: center;
}

.preview-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.result img {
  width: 100%;
  display: block;
  background: var(--bg-secondary);
}

/* Download button – top-right */
.download-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  color: #1d1d1f;
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  text-decoration: none;
  transition: transform 0.2s cubic-bezier(0.25, 0.1, 0.25, 1),
    background 0.2s ease, box-shadow 0.2s ease;
  z-index: 2;
}

.download-btn svg {
  width: 20px;
  height: 20px;
}

.download-btn:hover {
  transform: scale(1.08);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.download-btn:active {
  transform: scale(0.96);
}

@media (prefers-color-scheme: dark) {
  .download-btn {
    background: rgba(50, 50, 52, 0.82);
    color: #f5f5f7;
    border-color: rgba(255, 255, 255, 0.1);
  }

  .download-btn:hover {
    background: rgba(60, 60, 62, 0.95);
  }
}

.meta {
  margin-top: 16px;
  text-align: center;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-tertiary);
}

.meta a {
  color: var(--accent);
  text-decoration: none;
}

.meta a:hover {
  text-decoration: underline;
}

.retention-hint {
  color: var(--text-secondary);
  font-size: 13px;
}

/* ── Reference previews ── */
.ref-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.ref-preview img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* ── Custom size ── */
.custom-size.hidden {
  display: none;
}

.size-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: end;
}

.size-x {
  padding-bottom: 12px;
  color: var(--text-tertiary);
  font-size: 18px;
  font-weight: 300;
}

.hint {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-tertiary);
}

.api-mode {
  text-align: center;
  margin-top: -8px;
}

.size-risk {
  margin: -8px 0 0;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(0, 113, 227, 0.06);
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}

.size-risk.hidden {
  display: none;
}

/* ── Footer ── */
.footer {
  text-align: center;
  padding: 32px 22px 48px;
  border-top: 1px solid var(--border);
}

.footer p {
  margin: 0;
  font-size: 12px;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .hero {
    padding: 32px 0 28px;
  }

  .card {
    padding: 24px 18px;
    gap: 18px;
  }

  .hero-sub {
    font-size: 17px;
  }
}
