: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);
}
.header-brand { display: flex; align-items: center; gap: 12px; }
.home-button { display: inline-flex; min-height: 36px; align-items: center; padding: 0 14px; border: 1px solid var(--primary); border-radius: 6px; color: #fff; background: var(--primary); font-size: 12px; font-weight: 700; text-decoration: none; }
.home-button:hover { background: #24499f; }
.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; }
.queue-list { display: grid; gap: 6px; }
.queue-item {
  display: block; width: 100%; overflow: hidden; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 6px; background: #fff; color: var(--ink); text-align: left; font-size: 11px;
  text-overflow: ellipsis; white-space: nowrap;
}
.queue-item.active { border-color: var(--primary); background: #f3f6ff; }


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-cost-note { margin: -8px 0 0; color: var(--warning); font-size: 10px; }
.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; }
.cost-confirm-panel { position: relative; z-index: 1; display: flex; width: min(420px, 92vw); align-items: center; flex-direction: column; padding: 28px 30px 24px; border: 1px solid #d9dfd9; border-radius: 12px; background: #fff; box-shadow: 0 24px 70px rgba(0, 0, 0, .28); text-align: center; }
.cost-confirm-icon { display: grid; width: 48px; height: 48px; place-items: center; margin-bottom: 12px; border-radius: 50%; color: #fff; background: var(--primary); font-size: 24px; font-weight: 800; }
.cost-confirm-panel h2 { margin: 0; font-size: 18px; }
.cost-confirm-panel p { margin: 12px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.cost-confirm-panel .cost-amount { margin-top: 5px; color: var(--primary); font-size: 30px; }
.cost-confirm-panel .cost-confirm-hint { margin-top: 3px; font-size: 11px; }
.cost-confirm-panel footer { display: grid; width: 100%; grid-template-columns: 1fr 1.45fr; gap: 9px; padding-top: 21px; }
.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; }
.share-panel { position: relative; z-index: 1; display: flex; width: min(1050px, 94vw); max-height: 92vh; flex-direction: column; padding: 18px; border-radius: 10px; background: #f7f9f6; box-shadow: 0 20px 70px rgba(0, 0, 0, .3); }
.share-panel header, .share-panel footer { display: flex; align-items: center; gap: 10px; }
.share-panel header { justify-content: space-between; padding-bottom: 12px; }
.share-panel h2 { margin: 0; font-size: 15px; }
.share-panel header p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.share-layout { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(0, 2fr); gap: 16px; min-height: 0; overflow: hidden; }
.share-history-column, .share-editor-column { min-width: 0; }
.share-history-column h3, .share-editor-column label { display: block; margin: 0 0 8px; font-size: 12px; font-weight: 700; }
.share-history-list { display: grid; grid-template-columns: repeat(4, minmax(48px, 1fr)); gap: 6px; max-height: 58vh; overflow: auto; }
.share-history-choice { display: grid; gap: 3px; min-width: 0; padding: 3px; border: 1px solid var(--border); border-radius: 5px; background: #fff; text-align: left; }
.share-history-choice.selected { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(44, 105, 78, .15); }
.share-history-choice img { width: 100%; aspect-ratio: 1; object-fit: cover; }
.share-history-choice span { overflow: hidden; color: var(--muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.share-editor-column { display: flex; min-height: 0; flex-direction: column; }
.share-preview { width: 100%; max-height: 38vh; min-height: 120px; margin-bottom: 12px; object-fit: contain; background: var(--soft); }
.share-editor-column textarea { flex: 1; min-height: 180px; width: 100%; resize: vertical; padding: 10px; border: 1px solid var(--border); border-radius: 5px; color: var(--ink); background: #fff; font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
.share-panel footer { padding-top: 12px; }
.share-panel footer span { flex: 1; color: var(--muted); font-size: 11px; }

@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; }
  .share-panel { width: 100%; max-height: 94vh; padding: 10px; }
  .share-layout { grid-template-columns: 1fr; overflow: auto; }
  .share-history-list { grid-template-columns: repeat(6, minmax(42px, 1fr)); max-height: 24vh; }
  .share-preview { max-height: 28vh; }
  .zoom-images { grid-template-columns: 1fr; gap: 12px; }
  .zoom-images img { max-height: 68vh; }
}

.header-tabs {
  min-width: 280px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.free-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #e8f7f0;
  color: #117a52;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
}
.app-header {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  align-items: center;
  max-width: none;
}
.header-brand { justify-self: start; }
.header-tabs { justify-self: center; }
.app-header .home-button { justify-self: end; }

body.program-mode { background: #f5f6f7; }
body.program-mode .app-header { max-width: none; }
.program-tab { min-height: calc(100vh - 58px); background: #f5f6f7; color: #17212b; }
.program-workbench { position: relative; }
.program-commands {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  padding: 12px 24px;
  border-bottom: 1px solid #dce1e5;
  background: #fffffff5;
}
.command-button, .icon-button {
  display: inline-flex;
  height: 38px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
}
.icon-button {
  min-width: 38px;
  padding: 0 12px;
  border: 1px solid #d8dee3;
  background: #fff;
  color: #4f5c67;
  font-size: 13px;
  font-weight: 700;
}
.command-button {
  gap: 7px;
  padding: 0 14px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}
.command-button.secondary { border-color: #d8dee3; background: #fff; color: #34414c; }
.command-button.primary { background: #14795e; color: #fff; }
.command-button.generate {
  height: 48px;
  min-width: 176px;
  padding: 0 24px;
  border-radius: 10px;
  background: linear-gradient(180deg, #1ad196 0%, #0f9f73 100%);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: 0 10px 24px #0f9f7366;
}
.command-button.export { background: #17222c; color: #fff; }
.command-button:hover:not(:disabled), .icon-button:hover:not(:disabled) { transform: translateY(-1px); }
.command-button.primary:hover:not(:disabled) { background: #0d684f; }
.command-button.generate:hover:not(:disabled) {
  background: linear-gradient(180deg, #22e0a4 0%, #0d8a64 100%);
  transform: translateY(-1px) scale(1.03);
}
.command-button.generate:disabled { box-shadow: none; filter: grayscale(.15); }
.command-button.export:hover:not(:disabled) { background: #253440; }
.program-params {
  position: relative;
  display: grid;
  grid-template-columns: auto repeat(5, minmax(130px, 1fr));
  gap: 16px 24px;
  align-items: center;
  padding: 12px 24px;
  border-bottom: 1px solid #dfe3e6;
  background: #eef1f2;
}
.program-params > strong { color: #4d5964; font-size: 11px; text-transform: uppercase; }
.program-params label {
  display: grid;
  min-width: 0;
  grid-template-columns: auto minmax(60px, 1fr) 48px;
  align-items: center;
  gap: 8px;
  color: #5f6b75;
  font-size: 11px;
  font-weight: 700;
}
.program-params input[type=range] { width: 100%; accent-color: #14795e; }
.program-params input[type=color] {
  width: 42px; height: 28px; padding: 2px; border: 1px solid #cbd4da; border-radius: 5px; background: #fff;
}
.program-params output { color: #5d6973; font-size: 11px; text-align: right; font-variant-numeric: tabular-nums; }
.program-progress {
  position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; background: #d8dfe2;
}
.program-progress span { display: block; height: 100%; background: #14a578; }
.program-note {
  max-width: 1760px;
  margin: 0 auto;
  padding: 12px 24px 0;
  color: #7a4a12;
  font-size: 12px;
}
.program-empty {
  display: flex;
  min-height: calc(100vh - 250px);
  max-width: 720px;
  margin: 22px auto;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  border: 1px dashed #bdc6cd;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
.program-empty span { color: #85909a; font-size: 12px; }
.program-gallery {
  display: grid;
  max-width: 1760px;
  margin: 0 auto;
  padding: 22px 24px 48px;
  grid-template-columns: repeat(2, minmax(300px, 1fr));
  gap: 16px;
}
.editor-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid #dfe3e8;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 2px #0f172a0a;
}
.editor-card.has-error { border-color: #f0aaa1; }
.card-header, .editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
}
.card-header { border-bottom: 1px solid #edf0f2; }
.file-meta { min-width: 0; }
.file-meta strong {
  display: block;
  overflow: hidden;
  color: #17212b;
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-meta span { color: #8a949f; font-size: 11px; }
.status-badge {
  flex: none;
  padding: 3px 7px;
  border-radius: 5px;
  background: #eef1f4;
  color: #59636e;
  font-size: 11px;
  font-weight: 700;
}
.status-done { background: #e8f7f0; color: #117a52; }
.status-processing, .status-detecting { background: #eaf2ff; color: #2463a8; }
.status-error { background: #fff0ee; color: #ba3e31; }
.canvas-stage {
  position: relative;
  display: flex;
  min-height: 220px;
  max-height: 520px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    linear-gradient(45deg, #e9ecef 25%, transparent 25%),
    linear-gradient(-45deg, #e9ecef 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e9ecef 75%),
    linear-gradient(-45deg, transparent 75%, #e9ecef 75%),
    #f6f7f8;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}
.canvas-stage canvas {
  display: block;
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  touch-action: none;
}
.canvas-stage.mode-bar:not(.disabled) canvas { cursor: move; }
.canvas-stage.mode-grid:not(.disabled) canvas { cursor: grab; }
.processing-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  background: #fafbfcd1;
  color: #26323e;
  font-size: 13px;
  font-weight: 700;
}
.spinner {
  width: 17px;
  height: 17px;
  border: 2px solid #cfd7df;
  border-top-color: #158064;
  border-radius: 50%;
  animation: program-spin .7s linear infinite;
}
@keyframes program-spin { to { transform: rotate(360deg); } }
.face-count {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 4px 7px;
  border-radius: 5px;
  background: #141d26b8;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
}
.editor-toolbar { border-top: 1px solid #edf0f2; }
.mode-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 154px;
  padding: 2px;
  border-radius: 6px;
  background: #edf0f2;
}
.mode-switch button {
  display: inline-flex;
  height: 30px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #64707b;
  font-size: 12px;
  font-weight: 700;
}
.mode-switch button.active { background: #fff; color: #117a5c; box-shadow: 0 1px 2px #0f172a1a; }
.card-actions, .layer-actions { display: flex; gap: 4px; }
.card-actions button, .layer-actions button {
  display: inline-flex;
  min-width: 31px;
  height: 31px;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #687480;
  font-size: 12px;
  font-weight: 700;
}
.card-actions button:hover:not(:disabled), .layer-actions button:hover:not(:disabled) {
  border-color: #d7dde2;
  background: #f4f6f7;
  color: #14212c;
}
.control-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 9px 12px;
  align-items: end;
  padding: 10px 12px 12px;
  border-top: 1px solid #edf0f2;
  background: #fafbfb;
}
.control-strip label { min-width: 0; }
.control-strip label > span { display: block; margin-bottom: 4px; color: #66727d; font-size: 10px; font-weight: 700; }
.control-strip input[type=range] { display: block; width: 100%; accent-color: #158064; }
.control-strip input[type=color] {
  display: block; width: 42px; height: 26px; padding: 2px; border: 1px solid #cbd4da; border-radius: 5px; background: #fff;
}
.control-strip output { color: #7c8791; font-size: 10px; font-variant-numeric: tabular-nums; }
.control-strip select {
  width: 100%;
  height: 26px;
  border: 1px solid #d5dce2;
  border-radius: 5px;
  background: #fff;
  color: #24313d;
  font-size: 11px;
}
.check-control { align-self: center; display: flex; align-items: center; gap: 6px; }
.check-control span { margin: 0 !important; }
.card-error {
  margin: 0;
  padding: 9px 12px;
  border-top: 1px solid #f6d3ce;
  background: #fff7f5;
  color: #a73a30;
  font-size: 11px;
}
.program-drop-overlay {
  position: fixed;
  z-index: 100;
  inset: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed #19a579;
  border-radius: 8px;
  background: #ecf8f4f0;
  color: #11694f;
  font-size: 18px;
  pointer-events: none;
}
.program-toast {
  position: fixed;
  z-index: 90;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #17212b;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 10px 30px #0f172a33;
}
#program-link-url { width: 100%; height: 38px; margin: 8px 0 16px; padding: 0 11px; }

@media (max-width: 1180px) {
  .app-header { grid-template-columns: 1fr auto; row-gap: 8px; height: auto; padding: 10px 16px; }
  .header-tabs { grid-column: 1 / -1; justify-self: stretch; }
  .program-params { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
  .program-params > strong { grid-column: 1 / -1; }
  .program-gallery { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .program-commands { padding: 10px 12px; }
  .program-params { grid-template-columns: 1fr; padding: 12px; }
  .control-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.guide-page { background: #f5f6f7; }
.guide-page .app-header { grid-template-columns: minmax(0, 1fr) auto; }
.guide-doc {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}
.guide-hero {
  margin-bottom: 28px;
  padding: 22px 24px;
  border: 1px solid #dce1e5;
  border-radius: 10px;
  background: #fff;
}
.guide-kicker {
  margin: 0 0 8px;
  color: #14795e;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.guide-hero h2 { margin: 0 0 8px; font-size: 24px; }
.guide-hero p, .guide-step-copy p, .guide-step-copy li { color: #44515b; line-height: 1.65; }
.guide-step {
  display: grid;
  gap: 14px;
  margin-bottom: 22px;
  padding: 18px;
  border: 1px solid #dce1e5;
  border-radius: 10px;
  background: #fff;
}
.guide-step-copy span {
  display: inline-block;
  margin-bottom: 6px;
  color: #14795e;
  font-size: 12px;
  font-weight: 800;
}
.guide-step-copy h3 { margin: 0 0 8px; font-size: 18px; }
.guide-step-copy ul { margin: 8px 0 0; padding-left: 18px; }
.guide-step figure { margin: 0; }
.guide-step img {
  display: block;
  width: 100%;
  border: 1px solid #e5eaee;
  border-radius: 8px;
  background: #f8f9fa;
}
.guide-step figcaption {
  margin-top: 8px;
  color: #6b7780;
  font-size: 12px;
}
