:root {
  color-scheme: light;
  --page: #f3f5f1;
  --surface: #ffffff;
  --surface-soft: #f6f7f4;
  --ink: #181c19;
  --muted: #687069;
  --line: #d9ded7;
  --line-strong: #bcc5bb;
  --accent: #b7ee54;
  --accent-hover: #a9df48;
  --danger: #b63c31;
  --danger-soft: #fbecea;
  --success: #24703d;
  --success-soft: #e9f6ed;
  --info: #295f86;
  --shadow: 0 18px 55px rgba(35, 48, 38, 0.09);
  font-family: "Noto Sans SC Variable", "Noto Sans SC", sans-serif;
  font-size: 16px;
  font-weight: 500;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.65;
}

button, input, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled, input:disabled { cursor: not-allowed; opacity: .46; }
button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid #7cae32;
  outline-offset: 3px;
}
[hidden] { display: none !important; }
h1, h2, p, figure { margin: 0; }

.app {
  width: min(1680px, calc(100% - 64px));
  margin: 0 auto;
  padding: 40px 0 44px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 26px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: var(--accent);
  font: 700 12px/1 Consolas, monospace;
}
h1 { font-size: 26px; font-weight: 750; line-height: 1.35; }
.subtitle { margin-top: 3px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.header-note { color: var(--muted); font-size: 13px; text-align: right; }
.service-notice { margin: -10px 0 20px; color: var(--muted); font-size: 13px; }
.key-options { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.error-text { color: var(--danger) !important; }
.compare-label.failed { color: var(--danger); background: var(--danger-soft); }

.workspace {
  display: grid;
  grid-template-columns: 410px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.workspace > *, .compare-tray { min-width: 0; }
.panel { overflow: hidden; border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.panel-heading {
  display: flex;
  min-height: 66px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
}
.panel-heading h2 { font-size: 16px; font-weight: 750; }
.step-tag { color: var(--muted); font: 700 11px/1 Consolas, monospace; }
.control-body { display: grid; gap: 16px; padding: 20px; }
.field { display: grid; gap: 9px; }
.field-heading, .prompt-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.field-label { color: var(--muted); font-size: 15px; font-weight: 750; }
.field-optional, .field-help, .prompt-count { color: var(--muted); font-size: 13px; line-height: 1.7; }

.key-input {
  width: 100%;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: 0;
  padding: 0 14px;
  background: var(--surface);
  color: var(--ink);
  font: 15px/1 Consolas, monospace;
}
.key-input:focus, .prompt-input:focus { border-color: #7cae32; box-shadow: 0 0 0 3px rgba(183, 238, 84, .24); }
.check-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.check-row input { width: 15px; height: 15px; margin: 0; accent-color: var(--ink); }

.drop-zone {
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 22px 14px;
  background: var(--surface-soft);
  text-align: center;
  transition: transform 220ms cubic-bezier(.32, .72, 0, 1), border-color 220ms cubic-bezier(.32, .72, 0, 1), background-color 220ms cubic-bezier(.32, .72, 0, 1);
}
.drop-zone[data-active="true"] { transform: translateY(-2px); border-color: #6f992e; background: #f0f8df; }
.drop-zone[data-locked="true"] { pointer-events: none; }
.drop-title { display: block; margin-bottom: 5px; font-size: 17px; font-weight: 750; }
.drop-copy { display: block; color: var(--muted); font-size: 14px; line-height: 1.7; }
.upload-actions { display: flex; justify-content: center; gap: 10px; margin-top: 16px; }

.button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 0 18px;
  font-size: 15px;
  font-weight: 750;
  white-space: nowrap;
  transition: transform 220ms cubic-bezier(.32, .72, 0, 1), background-color 220ms cubic-bezier(.32, .72, 0, 1);
}
.button:active:not(:disabled) { transform: scale(.98); }
.button-dark { background: var(--ink); color: #fff; }
.button-soft { background: #e8ece6; color: var(--ink); }
.button-primary { width: 100%; min-height: 56px; background: var(--accent); color: #17200e; }
.button-primary:hover:not(:disabled) { background: var(--accent-hover); }
.button-download { min-height: 42px; }
.button-label { cursor: pointer; }

.file-summary {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 88px;
  padding: 10px;
  border-radius: 7px;
  background: var(--surface-soft);
}
.file-summary > div { min-width: 0; }
.file-thumb-button { width: 68px; height: 68px; border-radius: 5px; padding: 0; cursor: zoom-in; }
.file-thumb { display: block; width: 68px; height: 68px; border-radius: 5px; background: #e7eae5; object-fit: cover; }
.file-name { overflow: hidden; font-size: 14px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { margin-top: 4px; color: var(--muted); font-size: 12px; }
.remove-file { width: 40px; height: 40px; border-radius: 6px; background: #e5e9e3; color: var(--muted); font-size: 22px; line-height: 1; }

.task-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.task {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  text-align: left;
}
.task::before { content: ""; width: 14px; height: 14px; flex: 0 0 auto; border: 1px solid var(--line-strong); border-radius: 50%; background: #fff; }
.task[aria-pressed="true"] { border-color: #7cae32; background: #f0f8df; }
.task[aria-pressed="true"]::before { border: 4px solid var(--ink); }
.task:hover { border-color: #7cae32; }

.mode-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mode-option {
  display: flex;
  min-height: 54px;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.mode-option:has(input:checked) { border-color: #7cae32; background: #f0f8df; }
.mode-option input { margin: 0; accent-color: var(--ink); }
.mode-label { display: block; font-size: 14px; font-weight: 750; }
.mode-description { display: block; color: var(--muted); font-size: 11px; line-height: 1.45; }
.option-note { color: var(--muted); font-size: 12px; line-height: 1.65; }

.optional-panel { border: 1px solid var(--line); border-radius: 7px; }
.optional-panel summary {
  display: flex;
  min-height: 54px;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  font-size: 15px;
  font-weight: 750;
  cursor: pointer;
  list-style: none;
}
.optional-panel summary::-webkit-details-marker { display: none; }
.optional-panel summary::after { content: "+"; margin-left: auto; color: var(--muted); font: 22px Consolas, monospace; }
.optional-panel[open] summary { border-bottom: 1px solid var(--line); }
.optional-panel[open] summary::after { content: "−"; }
.optional-panel-body { display: grid; gap: 9px; padding: 14px; }
.prompt-input {
  display: block;
  width: 100%;
  min-height: 130px;
  resize: vertical;
  border: 1px solid transparent;
  border-radius: 6px;
  outline: 0;
  padding: 12px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.8;
  box-shadow: inset 0 1px 3px rgba(35, 48, 38, .06);
}
.prompt-clear, .text-button { min-height: 36px; border-radius: 6px; padding: 4px 10px; background: var(--surface-soft); color: var(--muted); font-size: 12px; font-weight: 650; }

.action-dock { display: grid; gap: 10px; padding: 20px; border-top: 1px solid var(--line); }
.action-dock .button-primary { grid-column: 1 / -1; }
.status { display: flex; min-height: 48px; align-items: center; border-radius: 6px; padding: 11px 14px; background: var(--surface-soft); color: var(--muted); font-size: 13px; line-height: 1.55; overflow-wrap: anywhere; }
.status[data-state="working"] { background: #edf3f8; color: var(--info); }
.status[data-state="success"] { background: var(--success-soft); color: var(--success); }
.status[data-state="error"] { background: var(--danger-soft); color: var(--danger); }

.result-body { padding: 20px; }
.result-panel .panel-heading h2 { min-width: 0; overflow-wrap: anywhere; }
.result-panel .panel-heading { flex-wrap: wrap; }
#downloadButton { flex-shrink: 0; }
#viewerMount { min-height: var(--viewer-placeholder, 0px); }
.segmented { display: flex; flex-wrap: wrap; gap: 3px; padding: 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.segmented button { border-radius: 4px; padding: 7px 10px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 650; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.segmented button:disabled { background: var(--surface-soft); }
.compare-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }

.compare-tray { display: grid; min-height: 0; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #eef1ec; }
.compare-stage { position: relative; width: 100%; max-width: 100%; margin: 0 auto; overflow: hidden; border-radius: 4px; background: #eef1ec; isolation: isolate; touch-action: none; user-select: none; --split: 50%; }
.compare-stage[data-mode="slide"] .before-pane { clip-path: inset(0 calc(100% - var(--split)) 0 0); }
.compare-stage[data-mode="slide"] .after-pane { clip-path: inset(0 0 0 var(--split)); }
.image-pane { position: absolute; inset: 0; overflow: hidden; background: #e8eae4; }
.image-space { position: absolute; inset: 0; transform-origin: center; }
.image-space img { display: block; width: 100%; height: 100%; object-fit: contain; }
.image-pane.solid { background: #e8eae4; }
.checker { background-color: #fff; background-image: conic-gradient(#e8ebe6 25%, transparent 0 50%, #e8ebe6 0 75%, transparent 0); background-size: 20px 20px; }
.image-pane.white { background: #fff; }
.image-pane.gray { background: #676e67; }
.compare-stage[data-mode="pair"] .before-pane { right: 50%; }
.compare-stage[data-mode="pair"] .after-pane { left: 50%; box-shadow: inset 2px 0 0 #fff; }
.compare-stage[data-mode="source"] .after-pane, .compare-stage[data-mode="result"] .before-pane { display: none; }
.compare-label { position: absolute; top: 12px; z-index: 4; padding: 5px 9px; border-radius: 4px; background: #ffffffed; color: var(--ink); font-size: 11px; pointer-events: none; }
.compare-label.before { left: 12px; }
.compare-label.after { right: 12px; }
.compare-stage[data-mode="source"] .compare-label.after, .compare-stage[data-mode="result"] .compare-label.before { display: none; }
.split-handle { position: absolute; top: 0; bottom: 0; left: var(--split); z-index: 5; width: 44px; transform: translateX(-50%); border: 0; background: transparent; cursor: ew-resize; touch-action: none; }
.split-handle::before { content: ""; position: absolute; top: 0; bottom: 0; left: 21px; width: 2px; background: #fff; box-shadow: 0 0 0 1px #344b3426; }
.split-handle span { position: absolute; top: calc(50% - 22px); left: 0; display: grid; width: 44px; height: 44px; place-items: center; border-radius: 50%; background: var(--accent); box-shadow: 0 3px 18px #263e2524; color: var(--ink); }
.split-handle svg { display: block; width: 24px; height: 24px; }
.split-handle:focus-visible { outline: 0; }
.split-handle:focus-visible span { outline: 3px solid #72933f; outline-offset: 3px; }
.compare-stage[data-mode="pair"] .split-handle, .compare-stage[data-mode="source"] .split-handle, .compare-stage[data-mode="result"] .split-handle { display: none; }
.compare-stage[data-zoomed="true"] .image-pane { cursor: grab; }
.compare-stage[data-dragging="true"] .image-pane { cursor: grabbing; }
.compare-stage[aria-busy="true"] { opacity: .5; pointer-events: none; }

.viewer-controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 12px 0 18px; }
.zoom-tools { display: flex; align-items: center; gap: 4px; font-size: 12px; }
.zoom-tools button { min-height: 34px; border-radius: 5px; padding: 4px 10px; background: var(--surface-soft); color: var(--ink); font-size: 12px; }
.zoom-tools output { min-width: 48px; color: var(--muted); text-align: center; }
.zoom-tools { flex-wrap: wrap; }
#expandCompare { background: var(--ink); color: #fff; }
.viewer-open { overflow: hidden; }
.viewer-dialog { width: calc(100vw - 32px); max-width: 1800px; height: calc(100dvh - 32px); max-height: none; padding: 20px; border: 0; border-radius: 12px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.viewer-dialog[open] { display: flex; flex-direction: column; }
.viewer-dialog::backdrop { background: #182019b8; }
.viewer-dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.viewer-dialog-heading h2 { font-size: 16px; }
.viewer-dialog-heading .button { min-height: 38px; font-size: 13px; }
#viewerStatus { display: block; flex: 0 0 auto; max-height: 20dvh; overflow-y: auto; margin-bottom: 12px; }
#expandedViewerMount, .viewer-dialog #imageViewer { display: flex; flex: 1; flex-direction: column; min-width: 0; min-height: 0; }
.viewer-dialog .compare-toolbar, .viewer-dialog .viewer-controls { flex: 0 0 auto; }
.viewer-dialog .compare-tray { --fit-viewer: 1; flex: 1 1 0; min-height: 0; overflow: hidden; }
.viewer-dialog .viewer-controls { margin-bottom: 0; }
.viewer-dialog #expandCompare { display: none; }
.result-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; padding-top: 16px; border-top: 1px solid var(--line); }
.metric { display: grid; gap: 5px; min-width: 0; }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; overflow-wrap: anywhere; font-size: 14px; font-weight: 650; }
.case-credit { margin-top: 14px; color: var(--muted); font-size: 11px; }
.case-credit a { color: inherit; text-underline-offset: 3px; }
.loading-note { margin-top: 12px; color: var(--danger); font-size: 13px; overflow-wrap: anywhere; }
.privacy-note { margin-top: 22px; color: var(--muted); text-align: center; font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

/* Desktop workbench: only settings scroll; primary actions stay outside that area.
   Narrow or very short viewports keep the natural document flow below. */
@media (min-width: 901px) and (min-height: 720px) {
  .app { display: flex; flex-direction: column; height: 100dvh; padding: 20px 0 14px; }
  .app-header { flex: 0 0 auto; margin-bottom: 16px; }
  .service-notice { flex: 0 0 auto; margin: 0 0 12px; }
  .workspace { flex: 1 1 0; min-height: 0; align-items: stretch; }
  .workspace > .panel { display: flex; flex-direction: column; min-height: 0; }
  .panel-heading { flex: 0 0 auto; min-height: 56px; }
  .control-body { flex: 1 1 0; min-height: 0; align-content: start; overflow-y: auto; overscroll-behavior-y: contain; scrollbar-gutter: stable; }
  .action-dock { flex: 0 0 auto; gap: 8px; padding: 16px 20px; }
  .action-dock .status { display: block; max-height: min(120px, 16dvh); overflow-y: auto; }
  .result-body { display: flex; flex: 1 1 0; flex-direction: column; min-height: 0; padding: 16px 20px; }
  #viewerMount, .result-panel #imageViewer { display: flex; flex: 1 1 0; flex-direction: column; min-width: 0; min-height: 0; }
  .result-panel .compare-toolbar, .result-panel .viewer-controls { flex: 0 0 auto; }
  .result-panel .compare-tray { --fit-viewer: 1; flex: 1 1 0; min-height: 0; overflow: hidden; }
  .result-panel .viewer-controls { margin-bottom: 12px; }
  .result-metrics { flex: 0 0 auto; gap: 8px; padding-top: 12px; }
  .case-credit { flex: 0 0 auto; margin-top: 10px; }
  .loading-note { flex: 0 0 auto; max-height: min(100px, 14dvh); overflow-y: auto; }
  .privacy-note { flex: 0 0 auto; margin-top: 12px; }
}

@media (max-width: 1150px) {
  .workspace { grid-template-columns: 350px minmax(0, 1fr); gap: 18px; }
  .app { width: calc(100% - 40px); }
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .app { width: calc(100% - 32px); padding: 24px 0; }
  .app-header { align-items: flex-start; }
  .header-note { display: none; }
}
@media (max-width: 560px) {
  .app { width: calc(100% - 24px); padding: 18px 0; }
  h1 { font-size: 23px; }
  .subtitle { font-size: 12px; }
  .control-body, .result-body { padding: 14px; }
  .panel-heading { min-height: 58px; padding: 12px 16px; }
  .app-header { align-items: flex-start; flex-direction: column; }
  .segmented button { padding: 7px 8px; font-size: 11px; }
  .compare-tray { padding: 8px; }
  .viewer-dialog { width: calc(100vw - 12px); height: calc(100dvh - 12px); padding: 12px; }
  .viewer-dialog .viewer-controls .field-help { display: none; }
  .viewer-dialog .compare-toolbar { gap: 6px; margin-bottom: 8px; }
  .viewer-dialog .segmented button { padding: 5px 6px; }
  .result-metrics { grid-template-columns: 1fr 1fr; }
  .metric strong { font-size: 12px; }
  .task { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }