:root {
  color-scheme: light;
  --paper: #f4f6f5;
  --surface: #ffffff;
  --surface-alt: #eaefed;
  --ink: #1c2422;
  --muted: #68736f;
  --line: #d7dfdc;
  --teal: #2f6f68;
  --teal-dark: #245a54;
  --teal-soft: #dceae7;
  --red: #a13f4b;
  --red-soft: #f6e6e8;
  --shadow: 0 12px 32px rgba(26, 40, 36, 0.08);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--paper); font-size: 16px; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
[hidden] { display: none !important; }

.screen { min-height: 100vh; }
.login-screen { display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(100%, 380px); }
.login-panel h1 { margin: 18px 0 6px; font-size: 30px; letter-spacing: 0; }
.login-panel .muted { margin: 0 0 28px; }
.brand-mark { width: 56px; height: 56px; display: grid; place-items: center; color: var(--surface); background: var(--teal); border-radius: 8px; }
.brand-mark svg { width: 30px; height: 30px; }
label { display: block; margin-bottom: 8px; font-weight: 650; }
.password-field { position: relative; }
.password-field input { width: 100%; height: 52px; padding: 0 52px 0 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); outline: none; }
.password-field input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(47, 111, 104, 0.14); }
.password-field .icon-button { position: absolute; right: 4px; top: 4px; }
.form-error { min-height: 24px; margin: 8px 0 12px; color: var(--red); font-size: 16px; }

.app-header { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, 0.96); }
.header-inner { width: min(100%, 960px); height: 60px; margin: auto; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 760; }
.brand svg { width: 24px; height: 24px; color: var(--teal); }
.icon-button { width: 44px; height: 44px; padding: 0; display: inline-grid; place-items: center; border: 0; border-radius: 8px; background: transparent; cursor: pointer; }
.icon-button:hover { background: var(--surface-alt); }
.icon-button svg { width: 21px; height: 21px; }
.icon-button.danger { color: var(--red); }

.app-main { width: min(100%, 960px); margin: 0 auto; padding: 20px 16px 116px; }
.workspace { width: min(100%, 720px); margin: 0 auto; }
.state-panel { width: 100%; }
.upload-zone { width: 100%; min-height: min(66vh, 540px); padding: 32px 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; border: 1px dashed #9dafaa; border-radius: 8px; color: var(--ink); background: var(--surface); cursor: pointer; }
.upload-zone:hover { border-color: var(--teal); background: #f9fbfa; }
.upload-zone strong { font-size: 21px; }
.upload-zone > span:last-child { color: var(--muted); font-size: 16px; line-height: 1.5; text-align: center; }
.upload-icon { width: 64px; height: 64px; display: grid; place-items: center; border-radius: 8px; color: var(--teal); background: var(--teal-soft); }
.upload-icon svg { width: 30px; height: 30px; }

.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.section-heading h1, .processing-panel h1, .error-panel h1 { margin: 4px 0 0; font-size: 24px; letter-spacing: 0; }
.eyebrow { color: var(--teal); font-size: 16px; font-weight: 750; }
.eyebrow.success { color: #2e7861; }
.text-button { min-height: 44px; padding: 0 10px; display: inline-flex; align-items: center; gap: 7px; border: 0; border-radius: 8px; color: var(--teal); background: transparent; cursor: pointer; }
.text-button:hover { background: var(--teal-soft); }
.text-button svg { width: 18px; }
.photo-frame { width: 100%; aspect-ratio: 4 / 3; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #202523; }
.photo-frame img { width: 100%; height: 100%; object-fit: contain; }

.toggle-row { min-height: 68px; margin: 14px 0 0; padding: 12px 14px; display: flex; align-items: center; gap: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }
.toggle-copy { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.toggle-copy small { color: var(--muted); font-size: 16px; font-weight: 400; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 48px; height: 28px; padding: 3px; flex: 0 0 auto; border-radius: 999px; background: #b8c2bf; transition: background 160ms ease; }
.switch::after { content: ""; width: 22px; height: 22px; display: block; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform 160ms ease; }
.toggle-row input:checked + .switch { background: var(--teal); }
.toggle-row input:checked + .switch::after { transform: translateX(20px); }
.toggle-row input:focus-visible + .switch { outline: 3px solid rgba(47, 111, 104, 0.2); }
.notice { display: flex; align-items: flex-start; gap: 8px; margin: 14px 2px 0; color: var(--muted); font-size: 16px; }
.notice svg { width: 18px; flex: 0 0 auto; color: var(--teal); }

.processing-panel, .error-panel { min-height: min(66vh, 540px); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.processing-visual, .error-icon { width: 72px; height: 72px; margin-bottom: 24px; display: grid; place-items: center; border-radius: 8px; background: var(--teal-soft); color: var(--teal); }
.processing-visual svg, .error-icon svg { width: 34px; height: 34px; }
.processing-visual svg { animation: breathe 1.8s ease-in-out infinite; }
.error-icon { color: var(--red); background: var(--red-soft); }
.processing-panel .muted, .error-panel .muted { margin: 10px 0 18px; }
.elapsed { display: inline-flex; align-items: center; gap: 7px; padding: 8px 11px; border-radius: 8px; color: var(--muted); background: var(--surface-alt); font-size: 16px; }
.elapsed svg { width: 16px; }
.muted { color: var(--muted); }

.compare { position: relative; width: 100%; aspect-ratio: 4 / 3; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #202523; touch-action: pan-y; }
.compare-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.after-layer { position: absolute; inset: 0; overflow: hidden; clip-path: inset(0 calc(100% - var(--compare)) 0 0); }
.compare-handle { position: absolute; top: 0; bottom: 0; left: var(--compare); width: 2px; transform: translateX(-1px); background: white; box-shadow: 0 0 0 1px rgba(0,0,0,.25); pointer-events: none; }
.compare-handle svg { position: absolute; top: 50%; left: 50%; width: 38px; height: 38px; padding: 8px; transform: translate(-50%, -50%); border-radius: 50%; color: var(--ink); background: white; box-shadow: 0 3px 10px rgba(0,0,0,.2); }
.compare input[type="range"] { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize; }
.compare-label { position: absolute; top: 10px; padding: 5px 8px; border-radius: 6px; color: white; background: rgba(18, 25, 23, .72); font-size: 16px; font-weight: 700; pointer-events: none; }
.compare-label.before { left: 10px; }
.compare-label.after { right: 10px; }
.result-actions { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 14px; }

.primary-button, .secondary-button { min-height: 50px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; border-radius: 8px; font-weight: 720; text-decoration: none; cursor: pointer; }
.primary-button { border: 1px solid var(--teal); color: white; background: var(--teal); }
.primary-button:hover { background: var(--teal-dark); }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: var(--surface); }
.secondary-button:hover { background: var(--surface-alt); }
.primary-button svg, .secondary-button svg { width: 20px; height: 20px; }
.primary-button.full { width: 100%; }
.primary-button:disabled { opacity: .55; cursor: not-allowed; }

.sticky-action { position: fixed; left: 0; right: 0; bottom: 0; z-index: 18; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255,255,255,.97); }
.sticky-action .primary-button { max-width: 720px; margin: 0 auto; }

.history-section { width: min(100%, 720px); margin: 34px auto 0; padding-top: 24px; border-top: 1px solid var(--line); }
.history-heading { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.history-heading h2 { margin: 0; font-size: 18px; }
.history-heading span { color: var(--muted); font-size: 16px; }
.history-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.history-item { position: relative; aspect-ratio: 1; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }
.history-item img { width: 100%; height: 100%; object-fit: cover; }
.history-item span { position: absolute; right: 6px; bottom: 6px; padding: 4px 6px; border-radius: 5px; color: white; background: rgba(18,25,23,.72); font-size: 16px; }
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 40; max-width: calc(100% - 32px); padding: 10px 14px; transform: translateX(-50%); border-radius: 8px; color: white; background: #26312e; box-shadow: var(--shadow); }

@keyframes breathe { 0%, 100% { transform: scale(.92); opacity: .72; } 50% { transform: scale(1.08); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; } }
@media (min-width: 680px) {
  .app-main { padding-top: 34px; }
  .result-actions { grid-template-columns: 1.4fr 1fr; }
  .history-list { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sticky-action { background: transparent; border-top: 0; pointer-events: none; }
  .sticky-action .primary-button { max-width: 688px; box-shadow: var(--shadow); pointer-events: auto; }
}
