/* 证件照合规生成 · 视觉系统
   方向：办事大厅 / 公文表格的工业实用风。
   纸白底 + 公文墨蓝 + 印章红；发丝线分隔、等宽数字、方形序号；零渐变、零毛玻璃、零投影。 */

:root {
  color-scheme: light;

  --paper: #f4f1ea;
  --card: #fffdf9;
  --ink: #17293c;
  --ink-2: #4a5c6e;
  --ink-3: #6d7d8c;
  --brand: #1b4d7a;
  --brand-deep: #123a5c;
  --brand-tint: #e8eff5;
  --rule: #ddd6c9;
  --rule-strong: #c3b9a8;
  --stamp: #b02a1f;
  --ok: #17663c;
  --warn: #8a5a00;
  --bad: #a32219;

  --radius: 2px;
  --gutter: clamp(1rem, 0.6rem + 1.4vw, 2rem);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-expo: cubic-bezier(0.16, 1, 0.3, 1);

  /* 不下载中文 Web 字体（动辄 5–20MB）：用系统 CJK 栈 + 字重/字距做层次 */
  --font-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
    "Noto Sans CJK SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* 必须显式兜住 hidden：作者样式里的 display:grid/block 会盖掉 UA 的 [hidden]{display:none}，
   结果「未付费的下载按钮」「进度条」会一直露在页面上（实测踩到）。 */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.7;
  overflow-wrap: break-word;
}

h1,
h2,
h3,
p,
ul,
ol,
dl,
figure,
fieldset {
  margin: 0;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

a {
  color: var(--brand);
  text-underline-offset: 3px;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.wrap {
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ---------- 页头 ---------- */

.masthead {
  background: var(--card);
  border-bottom: 1px solid var(--rule);
  padding-block: clamp(2rem, 1.2rem + 3vw, 3.5rem) clamp(1.5rem, 1rem + 2vw, 2.5rem);
}

.masthead-inner {
  display: grid;
  gap: 0.75rem;
  justify-items: start;
}

.wordmark {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  letter-spacing: 0.22em;
  color: var(--brand);
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--brand);
  display: inline-block;
}

.masthead h1 {
  font-size: clamp(1.75rem, 1.15rem + 2.6vw, 2.75rem);
  line-height: 1.25;
  letter-spacing: -0.01em;
  font-weight: 700;
  text-wrap: balance;
  max-width: 22ch;
}

.masthead h1 em {
  font-style: normal;
  color: var(--brand);
  box-shadow: inset 0 -0.35em 0 var(--brand-tint);
}

.lede {
  font-size: clamp(1rem, 0.95rem + 0.3vw, 1.1875rem);
  color: var(--ink-2);
  max-width: 46ch;
}

.assurances {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin-top: 0.5rem;
  font-size: 0.9375rem;
  color: var(--ink-2);
}

.assurances li {
  position: relative;
  padding-left: 1.1rem;
}

.assurances li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.62em;
  width: 0.5rem;
  height: 0.5rem;
  background: var(--brand);
}

/* ---------- 版式 ---------- */

.layout {
  display: grid;
  gap: clamp(1.5rem, 1rem + 2vw, 3rem);
  padding-block: clamp(1.5rem, 1rem + 2vw, 3rem) 4rem;
  align-items: start;
}

/* grid 项的 auto 最小尺寸 = min-content，会把外层轨道顶宽。
   坑：这个"最小尺寸链"会跨层传播 —— 只给最内层（.template-card）加 min-width:0 不够，
   外层 .col-main / .col-side 乃至 .col-side 里的 .panel 都要加，否则 375px 屏上仍会横向溢出
   （实测逐层排查：先修卡片 → 网格不再溢出；再修 .col-side 的子项 → 整页才真正不溢出）。 */
.layout > *,
.steps > *,
.col-side > *,
.plans > *,
.checklist > *,
.field-grid > *,
.template-list > * {
  min-width: 0;
}

@media (min-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.75fr);
  }

  .col-side {
    position: sticky;
    top: 1.5rem;
    display: grid;
    gap: 1rem;
  }
}

.col-side {
  display: grid;
  gap: 1rem;
}

/* ---------- 步骤 ---------- */

.steps {
  display: grid;
}

.step {
  border-top: 1px solid var(--rule);
  padding-block: clamp(1.25rem, 1rem + 1.2vw, 2rem);
}

.step:last-child {
  border-bottom: 1px solid var(--rule);
}

.step h2 {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: clamp(1.0625rem, 1rem + 0.5vw, 1.3125rem);
  font-weight: 700;
  margin-bottom: 0.875rem;
}

.step-index {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--brand);
  background: var(--card);
}

.step-note {
  font-size: 0.9375rem;
  color: var(--ink-3);
  margin-top: 0.75rem;
  max-width: 52ch;
}

/* ---------- 模板卡片 ---------- */

.template-list {
  display: grid;
  /* minmax(min(170px,100%),1fr) + 卡片 min-width:0 缺一不可：
     卡片的 min-content（"国家公务员考试"+「已核对」标签）约 195px，
     grid 的自动最小尺寸不允许 1fr 把轨道压到它以下 —— 375px 屏上会 2 列共 398px，横向溢出 39px（实测）。 */
  grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr));
  gap: 0.5rem;
}

.template-card {
  appearance: none;
  font: inherit;
  text-align: left;
  display: grid;
  gap: 0.25rem;
  padding: 0.875rem 1rem;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.16s var(--ease-out), background-color 0.16s var(--ease-out);
  min-width: 0;
}

.template-card:hover {
  border-color: var(--rule-strong);
}

.template-card[aria-checked="true"] {
  border-color: var(--brand);
  background: var(--brand-tint);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.t-name {
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  min-width: 0;
}

.template-card .t-spec {
  font-size: 0.875rem;
  color: var(--ink-2);
  min-width: 0;
}

.tag {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  padding: 0.1rem 0.35rem;
  border: 1px solid currentColor;
  border-radius: var(--radius);
  color: var(--ok);
}

.tag.unverified {
  color: var(--warn);
}

/* ---------- 上传 ---------- */

.dropzone {
  display: grid;
  gap: 0.35rem;
  justify-items: center;
  text-align: center;
  padding: clamp(1.5rem, 1rem + 2vw, 2.5rem) 1rem;
  border: 1px dashed var(--rule-strong);
  border-radius: var(--radius);
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.16s var(--ease-out), background-color 0.16s var(--ease-out);
}

.dropzone:hover,
.dropzone.is-dragging {
  border-color: var(--brand);
  background: var(--brand-tint);
}

.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.dropzone-title {
  font-weight: 700;
  font-size: 1.0625rem;
}

.dropzone-hint {
  font-size: 0.9375rem;
  color: var(--ink-3);
  max-width: 40ch;
}

.dropzone.has-file {
  border-style: solid;
  border-color: var(--brand);
  background: var(--brand-tint);
}

/* ---------- 裁剪 ---------- */

.crop-stage {
  position: relative;
  display: grid;
  place-items: center;
  background: #e7e1d6;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 220px;
}

#crop-canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  cursor: grab;
}

#crop-canvas:active {
  cursor: grabbing;
}

.crop-placeholder {
  position: absolute;
  inset: auto 0 50%;
  text-align: center;
  font-size: 0.9375rem;
  color: var(--ink-3);
  padding-inline: 1rem;
}

.crop-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.crop-controls label {
  font-size: 0.9375rem;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.crop-controls input[type="range"] {
  flex: 1 1 160px;
  min-width: 120px;
  accent-color: var(--brand);
}

/* ---------- 高级参数 ---------- */

.advanced {
  margin-top: 1rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  padding: 0.75rem 1rem;
}

.advanced > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--brand);
  list-style: none;
}

.advanced > summary::-webkit-details-marker {
  display: none;
}

.advanced > summary::before {
  content: "＋";
  font-family: var(--font-mono);
  margin-right: 0.4rem;
}

.advanced[open] > summary::before {
  content: "－";
}

.custom-flag {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  color: var(--warn);
  border-left: 3px solid var(--warn);
  padding-left: 0.6rem;
}

.field-grid {
  display: grid;
  /* 同 template-list：不加 min() 与 min-width:0 时，输入框的 min-content 会把轨道顶宽导致横向溢出 */
  grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.field-grid label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--ink-2);
  min-width: 0;
}

input[type="number"],
input[type="text"] {
  font: inherit;
  font-family: var(--font-mono);
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  width: 100%;
}

.bg-picker {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-top: 0.75rem;
}

.bg-picker legend {
  font-size: 0.875rem;
  color: var(--ink-2);
  padding-inline: 0.35rem;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.swatch {
  appearance: none;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0;
  position: relative;
}

.swatch[aria-pressed="true"] {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.bg-custom {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  color: var(--ink-2);
}

.bg-custom input[type="color"] {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: none;
  cursor: pointer;
}

/* ---------- 按钮 ---------- */

.btn {
  appearance: none;
  font: inherit;
  font-weight: 600;
  padding: 0.65rem 1.1rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.16s var(--ease-out), border-color 0.16s var(--ease-out),
    transform 0.16s var(--ease-out);
}

.btn:hover:not(:disabled) {
  border-color: var(--ink-2);
  background: #fff;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand-deep);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--brand-deep);
}

.btn.ghost {
  background: transparent;
}

.btn.big {
  width: 100%;
  padding: 0.95rem 1.25rem;
  font-size: 1.0625rem;
}

.action-bar {
  margin-top: 1.5rem;
  display: grid;
  gap: 0.5rem;
}

.action-note {
  font-size: 0.9375rem;
  color: var(--ink-3);
  text-align: center;
}

.progress {
  margin-top: 1rem;
  display: grid;
  gap: 0.5rem;
}

.progress-track {
  height: 6px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--brand);
  transition: width 0.5s var(--ease-out);
}

#progress-text {
  font-size: 0.875rem;
  color: var(--ink-2);
}

/* ---------- 面板与规格表 ---------- */

.panel {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.125rem;
}

.panel-title {
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-2);
  padding-bottom: 0.625rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--rule);
}

.spec-grid > div {
  display: flex;
  /* 允许换行 + 允许收缩：结果面板里的值（295×413px、JPG · 300dpi）比 dt 长，
     窄列下 dd 的 min-content 会顶穿容器右边（实测 dd 右溢 25px、1024px 时整页横向溢出 17px）。
     换行 + dd 的 margin-left:auto 让窄的时候自动变成"标签一行、值一行右对齐"。 */
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.15rem 0.75rem;
  min-width: 0;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--rule);
}

.spec-grid > div:last-child {
  border-bottom: none;
}

.spec-grid dt {
  font-size: 0.9375rem;
  color: var(--ink-3);
  white-space: nowrap;
  min-width: 0;
}

.spec-grid dd {
  font-weight: 600;
  text-align: right;
  margin-left: auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.spec-grid dd .unit {
  font-weight: 400;
  color: var(--ink-3);
}

.swatch-dot {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  border: 1px solid var(--rule-strong);
  border-radius: 1px;
  vertical-align: -0.1em;
  margin-right: 0.35rem;
}

.warnings {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.warnings p {
  font-size: 0.875rem;
  padding-left: 0.6rem;
  border-left: 3px solid var(--warn);
  color: var(--warn);
}

.warnings p.error {
  border-color: var(--bad);
  color: var(--bad);
}

.source-link {
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  color: var(--ink-3);
  line-height: 1.6;
  /* 官方来源 URL 很长，默认换行规则不肯在词内断行，会把规格面板顶宽导致整页横向溢出 */
  overflow-wrap: anywhere;
}

.source-note {
  display: block;
  margin-top: 0.35rem;
  padding-left: 0.6rem;
  border-left: 2px solid var(--rule-strong);
}

/* ---------- 公告位（后台可开关） ---------- */

.announcement {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  align-items: baseline;
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
  background: var(--brand-tint);
  border: 1px solid var(--brand);
  border-left-width: 4px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  line-height: 1.6;
}

.announcement p {
  margin: 0;
  min-width: 0;
}

.announcement a {
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- 设置页的开关 ---------- */

.toggle {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--card);
  cursor: pointer;
  font-size: 0.9375rem;
  line-height: 1.6;
}

.toggle:hover {
  border-color: var(--brand);
}

.toggle input[type="checkbox"] {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.2rem;
  accent-color: var(--brand);
}

.toggle span {
  min-width: 0;
}

/* ---------- 结果 ---------- */

.result-head {
  display: grid;
  grid-template-columns: minmax(0, 128px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.result-head > *,
.result-facts {
  min-width: 0;
}

.result-preview {
  position: relative;
  border: 1px solid var(--rule);
  background: #fff;
}

.result-preview img {
  display: block;
  width: 100%;
  height: auto;
}

.stamp {
  position: absolute;
  right: -0.6rem;
  bottom: 0.6rem;
  transform: rotate(-7deg);
  color: var(--stamp);
  border: 2px double var(--stamp);
  padding: 0.2rem 0.5rem;
  font-weight: 700;
  font-size: 0.875rem;
  letter-spacing: 0.18em;
  background: rgba(255, 253, 249, 0.88);
  animation: stamp-in 0.5s var(--ease-expo) both;
}

@keyframes stamp-in {
  from {
    opacity: 0;
    transform: rotate(-16deg) scale(1.7);
  }
  to {
    opacity: 1;
    transform: rotate(-7deg) scale(1);
  }
}

.checklist {
  display: grid;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.checklist li {
  font-size: 0.875rem;
  color: var(--ink-2);
  padding-left: 1.1rem;
  position: relative;
}

.checklist li::before {
  position: absolute;
  left: 0;
  font-family: var(--font-mono);
}

.checklist li.pass::before {
  content: "✓";
  color: var(--ok);
}

.checklist li.fail::before {
  content: "!";
  color: var(--bad);
}

.plans {
  display: grid;
  gap: 0.5rem;
  margin-top: 1.125rem;
}

/* ---------- 支付方式选择 ---------- */

.pay-chooser {
  margin-top: 1.125rem;
  padding: 0.875rem;
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  background: var(--brand-tint);
}

.pay-chooser-title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--ink-2);
  margin-bottom: 0.6rem;
}

.pay-methods {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(130px, 100%), 1fr));
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.pay-methods > * {
  min-width: 0;
}

.pay-method {
  appearance: none;
  font: inherit;
  font-weight: 600;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--brand);
  cursor: pointer;
  transition: background-color 0.16s var(--ease-out);
}

.pay-method:hover {
  background: var(--brand);
  color: #fff;
}

.plan-btn {
  appearance: none;
  font: inherit;
  display: flex;
  flex-wrap: wrap; /* 窄屏时价格换行，而不是把标签挤穿边框 */
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  text-align: left;
  padding: 0.75rem 0.9rem;
  background: var(--card);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  cursor: pointer;
  min-width: 0;
  transition: border-color 0.16s var(--ease-out), background-color 0.16s var(--ease-out);
}

.plan-btn:hover:not(:disabled) {
  border-color: var(--brand);
  background: var(--brand-tint);
}

.plan-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.plan-btn .p-label {
  font-weight: 700;
}

.plan-btn .p-desc {
  display: block;
  font-size: 0.8125rem;
  color: var(--ink-3);
  font-weight: 400;
}

.plan-btn .p-price {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--brand);
  white-space: nowrap;
}

.pay-status {
  margin-top: 0.75rem;
  font-size: 0.9375rem;
  color: var(--ink-2);
}

.pay-status.error {
  color: var(--bad);
}

.privacy {
  margin-top: 0.875rem;
  font-size: 0.8125rem;
  color: var(--ink-3);
}

#download-btn {
  display: block;
  margin-top: 0.875rem;
  text-align: center;
  text-decoration: none;
}

/* ---------- FAQ ---------- */

.faq {
  margin-top: clamp(1.5rem, 1rem + 2vw, 2.5rem);
}

.faq h2 {
  font-size: 1.125rem;
  padding-bottom: 0.625rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 0.5rem;
}

.faq details {
  border-bottom: 1px solid var(--rule);
  padding-block: 0.75rem;
}

.faq summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9375rem;
}

.faq p {
  margin-top: 0.5rem;
  font-size: 0.9375rem;
  color: var(--ink-2);
}

/* ---------- 页脚 ---------- */

.site-footer {
  border-top: 1px solid var(--rule);
  background: var(--card);
  padding-block: 1.5rem 2.5rem;
  font-size: 0.875rem;
  color: var(--ink-3);
}

.site-footer p {
  max-width: 70ch;
}

.fineprint {
  margin-top: 0.5rem;
}

/* ---------- 小屏 ---------- */

@media (max-width: 420px) {
  body {
    font-size: 0.9688rem;
  }

  .masthead h1 {
    max-width: none;
  }

  .result-head {
    grid-template-columns: minmax(0, 1fr);
  }

  .result-preview {
    max-width: 60%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* oklch 可用时把纸白/墨蓝调到更干净的色域（不支持则用上面的 hex 兜底） */
@supports (color: oklch(50% 0.1 250)) {
  :root {
    --brand-tint: color-mix(in oklab, var(--brand) 10%, white);
  }

  .stamp {
    background: color-mix(in oklab, var(--card) 88%, transparent);
  }
}
