/* 色值取向参考冷白与雾灰绿工作台，红蓝只用于实际照片底色。 */
:root {
  color-scheme: light;
  --page: #f5f8f8;
  --surface: #fff;
  --rail: #edf3f1;
  --panel: #fafcfb;
  --line: #d7e1e0;
  --faint: #e5eceb;
  --ink: #142731;
  --muted: #526875;
  --green: #176348;
  --green-deep: #104d38;
  --green-wash: #e4eee9;
  --focus: #227354;
  --error: #82372d;
  --error-bg: #faf0ec;
  --radius: 12px;
  font-family: "Segoe UI", "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  line-height: 1.55;
  color: var(--ink);
  background: var(--page);
}

/* 全站基础、工作台容器和常用按钮。 */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button, select, input[type="range"], input[type="color"] { cursor: pointer; }
button:disabled, input:disabled { cursor: not-allowed; }
[hidden] { display: none !important; }
a { color: var(--green); }
h1, h2, h3, p, fieldset { margin: 0; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, canvas:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
.shell { width: min(1184px, calc(100% - 64px)); margin-inline: auto; }
.page { padding-bottom: 24px; }
.icon-definitions { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 19px; height: 19px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px; padding: 7px 14px; border: 1px solid transparent; border-radius: 8px; text-decoration: none; font-size: 14px; font-weight: 650; line-height: 1.4; }
.button-quiet { background: var(--surface); border-color: var(--line); color: var(--ink); }
.button-quiet:hover:not(:disabled) { border-color: #9bb3a7; background: var(--rail); }
.button-primary { background: var(--green); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--green-deep); }
.button:disabled { background: #edf1ef; border-color: #e0e7e3; color: #566762; }
.small { min-height: 36px; padding: 5px 10px; font-size: 13px; }

/* 首屏标题和一体式双栏工作台。 */
.intro { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding-block: 37px 25px; }
h1 { margin-top: 7px; font-size: clamp(32px, 4vw, 48px); letter-spacing: -.045em; line-height: 1.2; font-weight: 760; }
.lede { margin-top: 8px; color: var(--muted); font-size: 15px; }
.privacy-badge { display: flex; align-items: center; gap: 11px; padding: 9px 14px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; white-space: nowrap; }
.privacy-badge .icon { color: var(--green); width: 23px; height: 23px; }
.privacy-badge strong, .privacy-badge span { display: block; }
.privacy-badge strong { font-size: 13px; }
.privacy-badge span { font-size: 12px; color: var(--muted); }
.workspace { overflow: clip; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
/* 工作台从照片预览和参数面板开始。 */
.workspace-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(350px, 408px); }
.preview-panel, .settings-panel { min-width: 0; padding: 20px 24px 22px; }
.settings-panel { background: var(--panel); border-left: 1px solid var(--line); }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 15px; }
.panel-heading h2 { font-size: 19px; line-height: 1.4; font-weight: 720; }
.panel-heading p { margin-top: 3px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
/* 换图按钮的文字在窄屏也保持完整。 */
#change-photo { flex: none; white-space: nowrap; }

/* 可裁切画布、空态和原图对比控件。 */
.stage { min-height: 392px; display: grid; align-items: center; justify-items: center; padding: 16px; background: #f1f6f4; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.stage:not(.has-photo) { border-style: dashed; border-color: #a9bdb5; }
.stage.drag-over { border-color: var(--green); background: #e1efe9; }
.empty-state { text-align: center; padding: 14px 6px; }
.empty-picture { display: block; margin: 0 auto 6px; }
.empty-state h3 { font-size: 21px; letter-spacing: -.02em; }
.empty-state p { color: var(--muted); font-size: 14px; margin-top: 3px; }
/* 单个上传按钮沿用空态的居中对齐。 */
#choose-photo { margin-top: 16px; }
.empty-state .file-hint { margin-top: 12px; font-size: 12px; }
.canvas-wrap { display: grid; max-width: 100%; }
.canvas-wrap canvas { display: block; max-width: 100%; height: auto; width: auto; max-height: 420px; background: repeating-conic-gradient(#e6edeb 0% 25%, #fafcfb 0% 50%) 0 0 / 16px 16px; box-shadow: 0 0 0 1px #c7d4d0; }
.canvas-wrap canvas.picking { cursor: crosshair; }
.preview-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; justify-content: space-between; margin-top: 12px; }
.segments { display: inline-flex; padding: 3px; border-radius: 7px; background: var(--rail); }
.segments button { min-height: 35px; border: 1px solid transparent; border-radius: 5px; padding: 3px 11px; background: none; color: var(--muted); font-size: 13px; }
.segments button[aria-pressed="true"] { color: var(--green-deep); background: var(--surface); border-color: var(--line); font-weight: 650; }
input[type="range"] { accent-color: var(--green); }
.tolerance-row { font-size: 13px; color: var(--muted); }
.tolerance-row input { flex: 1; min-width: 60px; }
.tolerance-row output { min-width: 42px; text-align: center; font-variant-numeric: tabular-nums; }
.under-stage { margin-top: 14px; font-size: 12px; color: var(--muted); }

/* 参数使用原生输入和明确标签；每组参数间以细线分隔。 */
.setting-block { min-inline-size: 0; padding: 6px 0 14px; border: 0; }
.setting-block legend { width: 100%; padding: 10px 0 0; border-top: 1px solid var(--faint); font-size: 14px; font-weight: 720; }
.setting-block legend span { margin-right: 8px; color: var(--green); font-size: 11px; font-variant-numeric: tabular-nums; }
.field { display: grid; min-width: 0; gap: 4px; font-size: 12px; color: var(--muted); }
.field-grid { display: grid; gap: 8px; }
.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field select, .field input:not([type="color"]) { width: 100%; min-width: 0; min-height: 38px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--ink); font-size: 14px; }
.field input::placeholder { color: #617480; }
/* 规格、分辨率和像素结果在窄屏仍有独立空间。 */
#size-section > .field-grid { align-items: start; margin-top: 8px; }
#size-section :is(input, select), #format { min-height: 44px; }
#size-hint { display: flex; align-items: center; min-height: 44px; font-size: 14px; font-variant-numeric: tabular-nums; color: var(--ink); }
.helper { margin-top: 7px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.swatches { display: flex; flex-wrap: wrap; gap: 5px; }
.swatches button { display: inline-flex; align-items: center; gap: 4px; min-height: 36px; border: 1px solid var(--line); border-radius: 7px; padding: 3px 6px; background: var(--surface); font-size: 12px; }
.swatches button[aria-pressed="true"] { background: var(--green-wash); border-color: #8cb29e; color: var(--green-deep); font-weight: 650; }
.chip { display: inline-block; width: 13px; height: 13px; border: 1px solid #849896; border-radius: 50%; }
.chip-keep { background: linear-gradient(135deg, #fff 43%, #738681 44% 54%, #fff 55%); }
.chip-white { background: #fff; }
.chip-blue { background: #438edb; border-color: #438edb; }
.chip-red { background: #d42536; border-color: #d42536; }
.chip-custom { background: conic-gradient(#438edb, #d42536, #efce65, #438edb); }
.color-field { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.color-field input { padding: 3px; width: 46px; height: 34px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.tolerance-row { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.sample-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.limits { margin-top: 7px; }
/* 单张照片的导出状态和按钮。 */
.export-panel { border-top: 1px solid var(--line); padding-top: 11px; }
.result-meta { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 3px 12px; font-size: 13px; }
.result-meta span { color: var(--muted); font-variant-numeric: tabular-nums; }
.notice { margin-top: 8px; padding: 7px 9px; font-size: 13px; border-radius: 6px; color: var(--green-deep); background: var(--green-wash); overflow-wrap: anywhere; }
.notice[data-tone="error"] { color: var(--error); background: var(--error-bg); }
.export-actions { display: grid; margin-top: 10px; }

/* 手机将照片设置放在预览下方。 */
@media (max-width: 820px) {
  .shell { width: calc(100% - 32px); }
  .workspace-grid { grid-template-columns: minmax(0, 1fr); }
  .settings-panel { border-left: 0; border-top: 1px solid var(--line); }
  .stage { min-height: 310px; }
  .canvas-wrap canvas { max-height: 375px; }
}
@media (max-width: 520px) {
  .shell { width: calc(100% - 24px); }
  .intro { display: block; padding-block: 21px 15px; }
  .lede { font-size: 14px; }
  .privacy-badge { display: inline-flex; margin-top: 10px; padding: 4px 8px; gap: 5px; background: var(--green-wash); border-color: transparent; }
  .privacy-badge .icon { width: 17px; height: 17px; }
  .privacy-badge strong, .privacy-badge span { display: inline; }
  .privacy-badge span { margin-left: 6px; }
  .preview-panel, .settings-panel { padding: 13px 12px 16px; }
  .panel-heading { margin-bottom: 9px; }
  .stage { min-height: 284px; padding: 10px; }
  .canvas-wrap canvas { max-height: 320px; }
  .empty-picture { width: 88px; height: 96px; }
  .empty-state { padding: 8px 0; }
  .empty-state h3 { font-size: 19px; }
  /* 手机空态压缩上传按钮与提示之间的距离。 */
  #choose-photo { margin-top: 10px; }
  .field input, .field select { font-size: 16px !important; }
}
/* 快选、小屏保存栏与可拖动的裁剪框共用当前照片。 */
.quick-row { display: flex; flex-wrap: wrap; gap: 5px; }
.quick-row button, .swatches button { min-height: 42px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); font-size: 13px; }
.quick-row button[aria-pressed="true"], [data-more][aria-expanded="true"], #crop-toggle[aria-pressed="true"] { color: var(--green-deep); border-color: #89ac9c; background: var(--green-wash); }
.more-panel { margin-block: 8px 0; padding: 10px; background: var(--rail); border-radius: 8px; }
.under-stage:empty { display: none; }
.preview-toolbar { justify-content: start; gap: 5px; }
.preview-toolbar .segments { margin-right: auto; }
.stage.has-photo { --photo-height: 400px; min-height: 0; height: calc(var(--photo-height) + 34px); }
.canvas-wrap { position: relative; overflow: hidden; width: min(100%, calc(var(--photo-height) * var(--photo-ratio, 1))); }
.canvas-wrap canvas { width: 100%; max-height: none; touch-action: pan-y; }
/* 只有固定取景框接管拖动，框外可以翻页。 */
#crop-box { position: absolute; border: 2px solid var(--green); box-shadow: 0 0 0 150vmax #14272288; touch-action: none; cursor: move; }
#crop-box:focus-visible { outline: 2px solid white; outline-offset: -4px; }
#crop-box:active { cursor: grabbing; }
/* 同比例的整张照片不需要移动，手机手指仍可在照片上滚动。 */
#crop-box.full-frame { pointer-events: none; }
@media (max-width: 820px) {
  /* 单列工作台在选图前也可直接设置尺寸、底色和大小。 */
  .workspace-grid { display: block; }
  body.has-photo .page { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
  body.has-photo .preview-panel { position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 1px solid var(--line); }
  /* 自定义像素或更多设置展开时，让预览随页面滚动。 */
  body.has-photo .workspace-grid:has(.setting-block:not([hidden]) :is(.more-panel, #custom-size):not([hidden])) .preview-panel { position: static; }
  html:has(body.has-photo) { scroll-padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
  .stage.has-photo { --photo-height: clamp(125px, 27dvh, 270px); height: calc(var(--photo-height) + 12px); padding: 5px; }
  .preview-toolbar { margin-top: 6px; }
  .preview-toolbar .small, .segments button { min-height: 40px; }
  .preview-toolbar .small { padding-inline: 7px; }
  .preview-panel .panel-heading { margin-bottom: 6px; }
  body.has-photo .intro { display: flex; align-items: center; padding-block: 10px; }
  body.has-photo .intro h1 { margin: 0; font-size: 23px; }
  body.has-photo .intro .lede, body.has-photo .privacy-badge span { display: none; }
  body.has-photo .privacy-badge { margin: 0; }
  .settings-panel .panel-heading { display: none; }
  .settings-panel { padding-top: 8px; border-top: 0; }
  .setting-block { padding: 2px 0 8px; }
  .setting-block legend { padding-top: 5px; border: 0; }
  /* 保存栏在页面滚动时始终可操作。 */
  .export-panel { position: fixed; z-index: 3; bottom: 0; inset-inline: 0; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px; padding: 8px max(12px, calc((100vw - 740px)/2)) calc(8px + env(safe-area-inset-bottom)); background: var(--surface); }
  .export-panel .result-meta { display: grid; gap: 0; }
  .export-panel .export-actions { grid-column: 2; grid-row: 1 / span 2; margin: 0; }
  .export-panel .notice { grid-column: 1; margin: 0; padding: 0; background: transparent; font-size: 12px; }
  .export-panel .button { min-height: 44px; }
}
@media (max-width: 520px) {
  /* 窄屏的照片规格独占一行，避免预览标题和换图按钮把规格挤成多行。 */
  body.has-photo .preview-panel .panel-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 6px; }
  body.has-photo .preview-panel .panel-heading > div:first-child { display: contents; }
  body.has-photo #change-photo { grid-row: 1; grid-column: 2; }
  body.has-photo #photo-info { grid-column: 1 / -1; margin-top: 0; }
}
@media (max-width: 380px) {
  .preview-toolbar .segments button { padding-inline: 6px; }
  .quick-row button, .swatches button { padding-inline: 7px; }
}
@media (max-height: 700px) and (max-width: 820px) {
  /* 限高视口优先让设置完整露出，预览继续随手势滚动。 */
  body.has-photo .preview-panel { position: static; }
}

/* 中文：标题右侧显示活动数字，保持窄屏预览区宽度。 */
.intro-side { display: grid; justify-items: end; gap: 6px; }
.presence-display { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 820px) {
  .intro-side { justify-items: start; }
  body.has-photo .intro-side { justify-items: end; }
}
