:root {
  --page: #f3f5f2;
  --surface: #fff;
  --soft: #eef1ed;
  --ink: #202320;
  --muted: #68706a;
  --border: #d5dbd5;
  --primary: #315dc7;
  --green: #18794e;
  --warning: #9a4b0f;
  --danger: #b3261e;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--page); }
body { min-height: 100vh; margin: 0; color: var(--ink); background: var(--page); font-size: 14px; line-height: 1.5; }
button, input, output { font: inherit; letter-spacing: 0; }
button, input, summary, .drop-zone { cursor: pointer; }
button:disabled, input:disabled { cursor: not-allowed; }
button:focus-visible, input:focus-visible, summary:focus-visible, .drop-zone:focus-visible {
  outline: 3px solid rgba(49, 93, 199, .24); outline-offset: 2px;
}
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-header {
  display: flex; height: 58px; align-items: center; justify-content: space-between;
  max-width: 1560px; padding: 0 22px; margin: auto; border-bottom: 1px solid var(--border); background: var(--surface);
}
.app-header::before { position: absolute; z-index: -1; right: 0; left: 0; height: 58px; border-bottom: 1px solid var(--border); background: var(--surface); content: ""; }
h1 { margin: 0; font-size: 17px; }
.local-status { display: flex; align-items: center; gap: 7px; color: #455047; font-size: 12px; font-weight: 600; }
.local-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }

.app-shell { display: grid; grid-template-columns: 304px minmax(0, 1fr); max-width: 1560px; min-height: calc(100vh - 58px); margin: auto; background: var(--surface); }
.controls { display: flex; flex-direction: column; gap: 19px; padding: 20px 18px; border-right: 1px solid var(--border); }
.mode-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; padding: 3px; border: 1px solid var(--border); border-radius: 6px; background: var(--soft); }
.mode-tab { min-height: 38px; border-color: transparent; background: transparent; }
.mode-tab.active { border-color: #cbd2cb; background: var(--surface); }
.controls section { display: grid; gap: 14px; padding-bottom: 19px; border-bottom: 1px solid var(--border); }
.controls h2, .toolbar h2 { margin: 0; font-size: 14px; }

.drop-zone {
  display: flex; min-height: 150px; align-items: center; justify-content: center; flex-direction: column; gap: 8px;
  padding: 16px; border: 1px dashed #adb7ae; border-radius: 6px; color: var(--muted); text-align: center; background: #f8f9f7;
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--primary); background: #edf1fb; }
.drop-zone strong { color: var(--ink); }
.drop-zone span { font-size: 11px; }
.drop-zone b, button {
  min-height: 36px; padding: 7px 12px; border: 1px solid #adb7ae; border-radius: 6px; color: #343a35; background: var(--surface); font-size: 12px; font-weight: 650;
}
.drop-zone b { display: inline-flex; align-items: center; margin-top: 4px; }
.file-info { overflow: hidden; padding: 8px 10px; margin: 0; border-left: 3px solid var(--primary); background: #f7f8f6; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

fieldset { min-width: 0; padding: 0; margin: 0; border: 0; }
legend, .color-row > span:first-child { padding: 0; margin-bottom: 7px; color: #4f5751; font-size: 12px; font-weight: 600; }
.segment { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; min-height: 38px; padding: 3px; border: 1px solid var(--border); border-radius: 6px; background: var(--soft); }
.pencil-intensity { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ai-options { display: grid; gap: 9px; }
.ai-options label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.ai-options small { color: #9a4b0f; font-size: 10px; }
.api-key-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 11px; }
.api-key-row button { min-height: 30px; padding: 4px 8px; font-size: 10px; }
.ai-share-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.share-reward-note { margin: 0; color: var(--warning); font-size: 10px; line-height: 1.4; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment label { display: flex; align-items: center; justify-content: center; padding: 5px 7px; border: 1px solid transparent; border-radius: 4px; color: #59615b; font-size: 12px; font-weight: 600; text-align: center; }
.segment input:checked + label { border-color: #cbd2cb; color: var(--ink); background: var(--surface); }
.segment input:focus-visible + label { outline: 3px solid rgba(49, 93, 199, .24); }

.color-row, .toggle-row { display: flex; min-height: 40px; align-items: center; justify-content: space-between; gap: 12px; }
.color-row > span { display: flex; align-items: center; gap: 8px; }
.color-row > span:first-child { margin: 0; }
input[type="color"] { width: 30px; height: 30px; padding: 2px; border: 1px solid #adb7ae; border-radius: 5px; background: var(--surface); }
.color-row output, .range-row output { color: #59615b; font-family: ui-monospace, monospace; font-size: 11px; }
.toggle-row { cursor: pointer; }
.toggle-row > span { display: flex; flex-direction: column; }
.toggle-row strong { font-size: 12px; }
.toggle-row small { color: var(--muted); font-size: 11px; }
.toggle-row input { position: absolute; opacity: 0; }
.toggle-row i { position: relative; width: 38px; height: 22px; border: 1px solid #aeb6b0; border-radius: 12px; background: #dfe3df; }
.toggle-row i::after { position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; content: ""; transition: transform .14s; }
.toggle-row input:checked + i { border-color: var(--primary); background: var(--primary); }
.toggle-row input:checked + i::after { transform: translateX(16px); }
.toggle-row input:focus-visible + i { outline: 3px solid rgba(49, 93, 199, .24); outline-offset: 2px; }
details { border-top: 1px solid var(--border); }
summary { padding-top: 11px; color: #4f5751; font-size: 12px; font-weight: 650; }
.range-row { display: grid; gap: 6px; padding-top: 10px; color: var(--muted); font-size: 11px; }
.range-row span { display: flex; justify-content: space-between; }
.range-row input { width: 100%; accent-color: var(--primary); }
.dependent.disabled { pointer-events: none; opacity: .42; }

.actions { margin-top: 0; }
.ai-progress { display: grid; gap: 6px; padding-top: 9px; }
.progress-track { height: 8px; overflow: hidden; border-radius: 4px; background: #dfe4df; }
.progress-track i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--primary); transition: width .2s ease; }
.progress-info { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 11px; }
.progress-info output { color: var(--muted); font-size: 10px; text-align: right; }
.primary { width: 100%; border-color: var(--primary); color: #fff; background: var(--primary); }
.primary:hover:not(:disabled) { background: #24499f; }
.primary:disabled { border-color: #e1e5e1; color: #7e8780; background: #e1e5e1; }
#error-message { min-height: 18px; margin: 6px 0 0; color: var(--danger); font-size: 11px; }

.workspace { min-width: 0; padding: 20px 24px 24px; background: var(--page); }
.toolbar { display: flex; min-height: 42px; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.toolbar p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; }
.view-segment { width: 208px; min-height: 36px; }
fieldset:disabled { opacity: .52; }
.box-toggle { display: flex; min-height: 36px; align-items: center; gap: 6px; padding: 0 10px; border: 1px solid #adb7ae; border-radius: 6px; background: #fff; font-size: 12px; font-weight: 600; }
.box-toggle input { accent-color: var(--primary); }
.box-toggle:has(input:disabled), button:disabled { opacity: .52; }

.empty-state { display: flex; min-height: min(68vh, 720px); align-items: center; justify-content: center; flex-direction: column; gap: 6px; border: 1px dashed #adb7ae; border-radius: 6px; color: var(--muted); background: #fff; }
.empty-state strong { color: #454c46; font-size: 13px; }
.empty-state span { font-size: 11px; }
.visual-zone { display: grid; min-height: 420px; place-items: center; padding: 14px; overflow: hidden; border: 1px solid #d0d6d0; border-radius: 6px; background: #e3e7e3; }

.compare-stage { --split: 50%; position: relative; display: inline-block; max-width: 100%; max-height: 68vh; overflow: hidden; line-height: 0; background: #ccd2cc; box-shadow: 0 8px 24px rgba(35, 43, 37, .1); user-select: none; }
.compare-stage > img, .side-stage img { display: block; width: auto; max-width: 100%; height: auto; max-height: 68vh; object-fit: contain; }
.after-layer { position: absolute; z-index: 1; inset: 0; clip-path: inset(0 0 0 var(--split)); }
.after-layer img { width: 100%; height: 100%; object-fit: fill; }
.image-label { position: absolute; z-index: 4; top: 9px; padding: 4px 7px; border-radius: 4px; color: #fff; background: rgba(28, 31, 29, .72); font-size: 11px; font-weight: 650; line-height: 1; }
.image-label.before { left: 9px; }
.image-label.after { right: 9px; }
.divider { position: absolute; z-index: 5; top: 0; bottom: 0; left: var(--split); width: 2px; background: #fff; transform: translateX(-1px); pointer-events: none; }
.divider::after { position: absolute; top: 50%; left: 50%; width: 40px; height: 40px; border: 2px solid #fff; border-radius: 50%; background: #313733; content: "↔"; color: #fff; font: 20px/36px sans-serif; text-align: center; transform: translate(-50%, -50%); }
.compare-range { position: absolute; z-index: 6; inset: 0; width: 100%; height: 100%; padding: 0; margin: 0; opacity: 0; touch-action: pan-y; }
.compare-stage:focus-within { outline: 3px solid rgba(49, 93, 199, .28); outline-offset: 3px; }

.face-boxes { position: absolute; z-index: 3; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.face-boxes rect { fill: none; stroke: #00a67e; stroke-width: 2; vector-effect: non-scaling-stroke; }
.side-stage { display: grid; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.side-stage figure { min-width: 0; margin: 0; text-align: center; }
.side-stage figure > div { position: relative; display: inline-block; max-width: 100%; overflow: hidden; line-height: 0; background: #ccd2cc; }
.side-stage img { max-height: 61vh; }
.side-stage figcaption { margin-top: 7px; color: #4d554f; font-size: 11px; font-weight: 650; }

.zoom-modal { position: fixed; z-index: 30; inset: 0; display: grid; place-items: center; padding: 24px; }
.zoom-backdrop { position: absolute; inset: 0; background: rgba(20, 25, 22, .72); }
.zoom-panel { position: relative; z-index: 1; display: flex; width: min(1500px, 96vw); max-height: 94vh; flex-direction: column; padding: 16px; border-radius: 10px; background: #f7f9f6; box-shadow: 0 20px 70px rgba(0, 0, 0, .3); }
.zoom-panel header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 12px; }
.zoom-panel h2 { margin: 0; font-size: 15px; }
.prompt-panel { position: relative; z-index: 1; display: flex; width: min(1100px, 94vw); min-height: min(680px, 90vh); flex-direction: column; padding: 18px; border-radius: 10px; background: #f7f9f6; box-shadow: 0 20px 70px rgba(0, 0, 0, .3); }
.prompt-panel header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 12px; }
.prompt-panel h2 { margin: 0; font-size: 15px; }
.prompt-panel textarea { flex: 1; width: 100%; min-height: 420px; resize: vertical; padding: 12px; border: 1px solid var(--border); border-radius: 6px; color: var(--ink); background: #fff; font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
.api-key-panel { width: min(560px, 94vw); min-height: auto; }
.api-key-panel > p { color: var(--muted); font-size: 12px; }
.api-key-panel > input { width: 100%; padding: 11px; border: 1px solid var(--border); border-radius: 6px; font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; }
.prompt-panel footer { display: flex; align-items: center; gap: 8px; padding-top: 12px; }
.prompt-panel footer span { flex: 1; }
.zoom-images { display: grid; min-height: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; overflow: auto; }
.zoom-images figure { min-width: 0; margin: 0; text-align: center; }
.zoom-images img { display: block; width: 100%; max-height: 82vh; object-fit: contain; background: #dfe4df; }
.zoom-images figcaption { padding-top: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
body.zoom-open { overflow: hidden; }

.result { display: grid; grid-template-columns: minmax(260px, 1fr) auto; gap: 15px 24px; padding: 17px 2px 0; }
.result-text { display: flex; min-width: 0; align-items: flex-start; gap: 10px; }
.result h3 { margin: 0; font-size: 13px; }
.result p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.badge { flex: 0 0 auto; padding: 3px 7px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.badge.neutral { color: #555d57; background: #e4e9e4; }
.badge.local { color: var(--green); background: #e8f5ee; }
.badge.fallback { color: var(--warning); background: #fff1df; }
.badge.unchanged { color: #24499f; background: #e9eefb; }
.badge.error { color: var(--danger); background: #fcebea; }
.result dl { display: grid; grid-template-columns: repeat(4, minmax(58px, auto)); margin: 0; }
.result dl div { min-width: 64px; padding: 0 13px; border-left: 1px solid var(--border); }
.result dt { color: var(--muted); font-size: 10px; }
.result dd { margin: 2px 0 0; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.result .reason { grid-column: 1 / -1; padding: 8px 10px; margin: 0; border-left: 3px solid var(--warning); color: #714017; background: #fff1df; font-size: 11px; }
.history-panel { padding-top: 18px; margin-top: 18px; border-top: 1px solid var(--border); }
.history-panel header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.history-panel h2 { margin: 0; font-size: 14px; }
.history-panel p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.history-list { display: grid; grid-template-columns: repeat(10, minmax(58px, 1fr)); gap: 8px; padding-top: 12px; }
.history-item { display: grid; gap: 4px; min-width: 0; cursor: pointer; }
.history-item img { width: 100%; aspect-ratio: 1; object-fit: cover; border: 2px solid transparent; border-radius: 4px; background: var(--soft); }
.history-item input { margin: 0; accent-color: var(--primary); }
.history-item input:checked + img { border-color: var(--primary); }
.history-item span { overflow: hidden; color: var(--muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.history-download { min-height: 24px; padding: 3px 5px; border-radius: 4px; font-size: 10px; }
.history-empty { grid-column: 1 / -1; padding: 16px 0; }
.prompt-center-panel { position: relative; z-index: 1; display: flex; width: min(900px, 94vw); max-height: 90vh; flex-direction: column; padding: 18px; border-radius: 10px; background: #f7f9f6; box-shadow: 0 20px 70px rgba(0, 0, 0, .3); }
.prompt-center-panel header, .prompt-center-panel footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.prompt-center-panel header { padding-bottom: 12px; }
.prompt-center-panel h2 { margin: 0; font-size: 15px; }
.prompt-center-panel header p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.prompt-center-list { display: grid; gap: 8px; min-height: 0; overflow: auto; }
.prompt-center-item { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.prompt-center-item img { width: 96px; height: 76px; object-fit: cover; border-radius: 4px; background: var(--soft); }
.prompt-center-summary { min-width: 0; overflow: hidden; padding: 8px; border: 0; color: var(--muted); background: transparent; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.prompt-center-summary:hover { color: var(--ink); background: var(--soft); }
.prompt-center-panel footer { padding-top: 12px; }
.prompt-center-panel footer span { color: var(--muted); font-size: 11px; }
.prompt-center-item img { cursor: zoom-in; }
.shared-image-panel { position: relative; z-index: 1; display: flex; width: min(1200px, 96vw); max-height: 94vh; flex-direction: column; padding: 16px; border-radius: 10px; background: #f7f9f6; box-shadow: 0 20px 70px rgba(0, 0, 0, .3); }
.shared-image-panel header, .shared-image-panel footer { display: flex; align-items: center; gap: 8px; }
.shared-image-panel header { justify-content: space-between; padding-bottom: 10px; }
.shared-image-panel h2 { margin: 0; font-size: 15px; }
.shared-image-stage { display: grid; min-height: 0; place-items: center; overflow: auto; padding: 12px; background: #dfe4df; }
.shared-image-stage img { display: block; width: 100%; max-width: none; height: auto; object-fit: contain; }
.shared-image-panel footer { padding-top: 10px; }
.shared-image-panel footer input { flex: 1; min-width: 100px; accent-color: var(--primary); }
.shared-image-panel footer output { min-width: 42px; color: var(--muted); font-size: 11px; text-align: right; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 282px minmax(0, 1fr); }
  .workspace { padding-right: 16px; padding-left: 16px; }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-actions { flex-wrap: wrap; }
  .result { grid-template-columns: 1fr; }
  .result dl { border-top: 1px solid var(--border); }
  .result dl div { padding-top: 9px; }
}

@media (max-width: 759px) {
  .app-header { height: 54px; padding: 0 16px; }
  .app-header::before { height: 54px; }
  .app-shell { display: block; }
  .controls { padding: 18px 16px 0; border-right: 0; }
  .actions { position: sticky; z-index: 8; bottom: 0; padding: 10px 0; border-top: 1px solid var(--border); background: #fff; }
  #error-message:empty { min-height: 0; margin: 0; }
  .workspace { padding: 18px 12px 24px; }
  .toolbar-actions { display: grid; width: 100%; grid-template-columns: minmax(0, 1fr) auto; }
  .view-segment { width: 100%; }
  #download-button { grid-column: 1 / -1; width: 100%; }
  .visual-zone { min-height: 280px; padding: 8px; }
  .divider::after { width: 44px; height: 44px; line-height: 40px; }
  .side-stage { grid-template-columns: 1fr; gap: 18px; }
  .result { padding-right: 4px; padding-left: 4px; }
  .result dl { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .result dl div { min-width: 0; padding-right: 7px; padding-left: 7px; }
  .history-list { grid-template-columns: repeat(5, minmax(58px, 1fr)); }
  .zoom-modal { padding: 8px; }
  .zoom-panel { width: 100%; max-height: 98vh; padding: 10px; }
  .prompt-panel { width: 100%; min-height: 92vh; padding: 10px; }
  .prompt-panel footer { flex-wrap: wrap; }
  .zoom-images { grid-template-columns: 1fr; gap: 12px; }
  .zoom-images img { max-height: 68vh; }
}
