:root {
  --bg: #f5f0e6;
  --paper: #fffdf8;
  --ink: #2f2619;
  --ink-2: #6f6353;
  --line: #e2d8c5;
  --gold: #a9853f;
  --gold-d: #8a6a2c;
  --gold-soft: #f0e6cf;
  --danger: #b3402f;
  --ok: #3f7a52;
  --bleed: #b9773a;
  --trim: #4a4a4a;
  --safe: #8fa3a8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 40, 10, .08), 0 8px 24px rgba(60, 40, 10, .08);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }

/* ───── 按鈕 ───── */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  padding: 9px 16px; border-radius: 999px; cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--gold); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.primary:hover { background: var(--gold-d); border-color: var(--gold-d); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.danger-text { color: var(--danger); }
.icon-btn {
  appearance: none; border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%;
  cursor: pointer; font-size: 17px; color: var(--ink-2); flex: none;
}
.icon-btn:hover { background: var(--gold-soft); color: var(--ink); }
.badge { display: inline-block; margin-left: 6px; padding: 0 8px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 11px; }

/* ───── 頁首 ───── */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px max(16px, env(safe-area-inset-left)) 14px max(16px, env(safe-area-inset-right));
  background: rgba(245, 240, 230, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark { width: 40px; height: 40px; color: var(--gold); flex: none; }
.brand h1 { font-size: 19px; letter-spacing: .04em; font-weight: 600; }
.brand p { font-size: 12.5px; color: var(--ink-2); }
.top-actions { display: flex; gap: 8px; }

main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 80px; }
.count { color: var(--ink-2); font-size: 13px; margin-bottom: 14px; }

/* ───── 作品牆 ───── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 26px 20px; }
.card { text-align: center; min-width: 0; }
.card.fresh .disc { animation: pop .7s ease; }
@keyframes pop { 0% { transform: scale(.85); opacity: 0; } 60% { transform: scale(1.04); } 100% { transform: none; opacity: 1; } }
.disc-wrap { position: relative; width: 100%; max-width: 260px; margin: 0 auto; }
.disc {
  position: relative; display: block; width: 100%; aspect-ratio: 1; border-radius: 50%; overflow: hidden;
  background: var(--paper); box-shadow: var(--shadow); border: 0; padding: 0; cursor: pointer;
}
/* 圖檔是含出血的 116mm，畫面上只露出 110mm 的完成尺寸 */
.disc img { position: absolute; left: 50%; top: 50%; width: calc(100% * 116 / 110); height: calc(100% * 116 / 110); transform: translate(-50%, -50%); display: block; }
.disc.big { cursor: default; }
.disc-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-2); font-size: 13px; border: 1.5px dashed var(--line); border-radius: 50%; }
.flipper { perspective: 900px; }
.flipper .disc { transition: transform .5s; transform-style: preserve-3d; overflow: visible; background: none; box-shadow: none; }
.flipper .face { position: absolute; inset: 0; border-radius: 50%; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: var(--paper); box-shadow: var(--shadow); }
.flipper .face.back { transform: rotateY(180deg); }
.flipper.flipped .disc { transform: rotateY(180deg); }
.flip-btn {
  position: absolute; right: 4%; bottom: 4%; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--paper); cursor: pointer; font-size: 15px; color: var(--gold-d);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .12);
}
.card h3 { margin-top: 12px; font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.by { color: var(--ink-2); font-size: 13.5px; overflow-wrap: anywhere; }
.card .actions { margin-top: 10px; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }

.empty { text-align: center; padding: 60px 16px; color: var(--ink-2); }
.empty-disc { width: 150px; height: 150px; border-radius: 50%; border: 2px dashed var(--gold); margin: 0 auto 20px; opacity: .6; }
.empty h2 { color: var(--ink); font-size: 20px; margin-bottom: 6px; }
.empty .btn { margin-top: 18px; }

/* ───── 全螢幕編輯器 ───── */
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; }
.sheet-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--paper);
  padding-top: max(8px, env(safe-area-inset-top));
}
.sheet-title { font-weight: 600; flex: 1; }
.sheet-nav { display: flex; gap: 8px; margin-left: auto; }
.steps { list-style: none; display: flex; gap: 4px; margin: 0; padding: 0; flex: 1; min-width: 0; font-size: 13px; color: var(--ink-2); overflow: hidden; }
.steps li { padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.steps li.on { background: var(--gold-soft); color: var(--ink); font-weight: 600; }
.steps li b { font-weight: inherit; margin-right: 4px; color: var(--gold-d); }
.sheet-body { flex: 1; min-height: 0; position: relative; }
.step { position: absolute; inset: 0; display: flex; flex-direction: column; }
.hint { color: var(--ink-2); font-size: 13px; }
.hint.center { text-align: center; margin-top: 10px; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; }

/* 掃描校正 */
.scan-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 26px; background: #2b2620; touch-action: none; }
.scan-box { position: relative; }
.scan-box canvas#scanCanvas { display: block; width: 100%; height: 100%; }
#scanOverlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#scanShade { fill: rgba(20, 15, 8, .55); }
#scanPoly { fill: none; stroke: #ffd77a; stroke-width: 2; vector-effect: non-scaling-stroke; }
.handle {
  position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%;
  touch-action: none; cursor: grab; display: grid; place-items: center;
}
.handle::after { content: ""; width: 20px; height: 20px; border-radius: 50%; background: rgba(255, 215, 122, .35); border: 2.5px solid #ffd77a; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, .5); }
.handle.drag { cursor: grabbing; }
.handle.drag::after { background: transparent; }
#loupe { position: absolute; width: 132px; height: 132px; margin: -66px 0 0 -66px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 4px 16px rgba(0, 0, 0, .5); pointer-events: none; z-index: 3; }
.step-foot { padding: 12px 16px max(12px, env(safe-area-inset-bottom)); background: var(--paper); border-top: 1px solid var(--line); display: flex; gap: 12px 20px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.step-foot .hint { flex: 1 1 300px; }

/* 左右分欄（裁切、資訊、背面） */
.split { flex-direction: row; }
.split-main { flex: 1; min-width: 0; padding: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: auto; }
.panel { width: 360px; flex: none; background: var(--paper); border-left: 1px solid var(--line); padding: 18px 18px 40px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.panel h3 { font-size: 13px; letter-spacing: .08em; color: var(--gold-d); margin-top: 8px; }
.panel h3:first-child { margin-top: 0; }

.frame { position: relative; width: min(100%, calc(100dvh - 240px), 620px); aspect-ratio: 1; background: #fff; box-shadow: var(--shadow); touch-action: none; user-select: none; -webkit-user-select: none; flex: none; }
#cropStage { cursor: grab; }
#cropStage.drag { cursor: grabbing; }
.frame canvas, .frame #beSvg, .frame #beSvg svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.guides { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.g-out { fill: rgba(245, 240, 230, .9); }
.g-ring { fill: rgba(255, 255, 255, .28); }
.g-halo { fill: none; stroke: rgba(255, 255, 255, .85); stroke-width: .9; }
.g-bleed { fill: none; stroke: var(--bleed); stroke-width: .4; }
.g-trim { fill: none; stroke: var(--trim); stroke-width: .4; }
.g-safe { fill: none; stroke: var(--safe); stroke-width: .4; stroke-dasharray: 1.8 1.3; }
.g-safe-halo { fill: none; stroke: rgba(255, 255, 255, .8); stroke-width: .9; stroke-dasharray: 1.8 1.3; }

.legend { display: flex; gap: 6px 18px; flex-wrap: wrap; justify-content: center; margin-top: 12px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 22px; height: 0; border-top: 2px solid; }
.lg-bleed { border-color: var(--bleed); }
.lg-trim { border-color: var(--trim); }
.lg-safe { border-color: var(--safe); border-top-style: dashed; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 10px; min-height: 26px; }
.chip { font-size: 12.5px; padding: 2px 10px; border-radius: 999px; background: #ebe4d5; color: var(--ink-2); }
.chip.ok { background: #e2efe5; color: var(--ok); }
.chip.warn { background: #f8e3d6; color: var(--danger); }
.chip:empty { display: none; }

.row { display: grid; grid-template-columns: 52px 1fr 42px; align-items: center; gap: 10px; font-size: 13.5px; }
.row output { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 12.5px; }
input[type=range] { width: 100%; accent-color: var(--gold); height: 28px; margin: 0; }
.toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13.5px; }
.toggles .toggle { border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; }
.toggles .toggle:has(input:checked) { background: var(--gold-soft); border-color: var(--gold); }
.toggles .toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle.block { align-items: flex-start; }
.toggle.block input { margin-top: 5px; accent-color: var(--gold); }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; font-weight: 600; }
.field small { color: var(--ink-2); font-size: 12.5px; }
.field input, .field textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; font-size: 16px; width: 100%;
}
.field textarea { resize: vertical; line-height: 1.7; text-align: center; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--gold); outline-offset: -1px; border-color: var(--gold); }

.disc-preview { width: min(100%, calc(100dvh - 260px), 460px); aspect-ratio: 1; border-radius: 50%; overflow: hidden; box-shadow: var(--shadow); position: relative; background: #fff; flex: none; }
.disc-preview canvas { position: absolute; left: 50%; top: 50%; width: calc(100% * 116 / 110); height: calc(100% * 116 / 110); transform: translate(-50%, -50%); }

.tabs { display: flex; background: #ebe4d5; border-radius: 999px; padding: 3px; }
.tab { flex: 1; border: 0; background: transparent; padding: 7px 10px; border-radius: 999px; cursor: pointer; font-size: 13.5px; color: var(--ink-2); }
.tab.on { background: var(--paper); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }

/* ───── 對話框 ───── */
.dlg { border: 0; border-radius: var(--radius); padding: 24px; width: min(440px, calc(100vw - 32px)); background: var(--paper); color: var(--ink); box-shadow: 0 20px 60px rgba(30, 20, 5, .3); }
.dlg.wide { width: min(760px, calc(100vw - 32px)); text-align: center; }
.dlg::backdrop { background: rgba(40, 30, 15, .5); }
.dlg h2 { font-size: 19px; margin-bottom: 10px; overflow-wrap: anywhere; }
.dlg form { display: flex; flex-direction: column; gap: 14px; }
.dlg-x { position: absolute; right: 10px; top: 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px 12px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-size: 12.5px; color: var(--gold-d); padding: 0 6px; letter-spacing: .08em; }
.radio { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-size: 14px; }
.radio input { margin-top: 5px; accent-color: var(--gold); }
.radio b { font-weight: 600; }
.detail-faces { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 14px 0 18px; }
.detail-faces figure { margin: 0; }
.detail-faces figcaption { margin-top: 8px; font-size: 12.5px; color: var(--ink-2); }
.detail-actions { margin-top: 16px; display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ───── 忙碌 / 提示 ───── */
.busy { position: fixed; inset: 0; z-index: 50; background: rgba(245, 240, 230, .86); display: grid; place-content: center; justify-items: center; gap: 14px; text-align: center; padding: 20px; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 3px solid var(--gold-soft); border-top-color: var(--gold); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; max-width: calc(100vw - 32px); text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast.err { background: var(--danger); }

/* ───── 手機 ───── */
@media (max-width: 820px) {
  .split { flex-direction: column; overflow: auto; }
  .split-main { flex: none; padding: 14px 14px 10px; overflow: visible; }
  .panel { width: auto; border-left: 0; border-top: 1px solid var(--line); overflow: visible; flex: none; }
  .frame { width: min(100%, 52dvh); }
  /* 手機調色時，圖片固定在上方，滑桿在下面捲動 */
  #stepCrop .split-main { position: sticky; top: 0; z-index: 2; background: var(--bg); border-bottom: 1px solid var(--line); }
  #stepCrop .frame { width: min(100%, 40dvh); }
  #stepCrop .panel { border-top: 0; }
  .disc-preview { width: min(72%, 40dvh); }
  .steps li:not(.on) span { display: none; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 22px 12px; }
  .top-actions .btn { padding: 8px 12px; font-size: 14px; }
  .scan-stage { padding: 24px 22px; }
  .detail-faces { gap: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.pane { display: flex; flex-direction: column; gap: 12px; }
.frame #beImg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* 裁切步驟的簽名提醒 */
.callout { margin-top: 10px; padding: 7px 14px; border-radius: 10px; background: #fbefd2; border: 1px solid #e3c98a; color: #6b4e14; font-size: 13px; text-align: center; max-width: 620px; }
.callout b { font-weight: 700; color: #5a3d08; }
@media (max-width: 820px) { .callout { padding: 5px 12px; } .callout span { display: none; } }

/* 印刷規格檢查（300 dpi / CMYK） */
.spec { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; background: #fff; }
.spec.bad { border-color: #e2a892; background: #fdf6f1; }
.spec.shake { animation: shake .45s; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.spec-row { display: flex; align-items: center; gap: 10px; }
.spec-icon { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-size: 13px; font-weight: 700; color: #fff; background: var(--danger); }
.spec-icon::before { content: "!"; }
.spec-row.ok .spec-icon { background: var(--ok); }
.spec-row.ok .spec-icon::before { content: "✓"; }
.spec-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.4; }
.spec-text b { font-size: 13.5px; font-weight: 600; }
.spec-text small { font-size: 12px; color: var(--ink-2); }
.spec-row:not(.ok) .spec-text small { color: var(--danger); }
.spec-row.ok .btn { display: none; }
.spec-status { font-size: 12.5px; font-weight: 600; color: var(--ok); }
.spec.bad .spec-status { color: var(--danger); }
#edNext.blocked { opacity: .5; }

/* 上傳截止日 */
.brand .deadline { display: inline-block; margin-top: 4px; padding: 1px 10px; border-radius: 999px; background: #fbefd2; border: 1px solid #e3c98a; color: #6b4e14; font-size: 12.5px; font-weight: 600; }

/* 背面內文字數 */
#beCount.over { color: var(--danger); font-weight: 600; }

/* ───── 作品清單與完成度 ───── */
.checklist { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 20px; }
.checklist summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; }
.checklist summary::-webkit-details-marker { display: none; }
.checklist summary::after { content: "收合"; margin-left: auto; font-size: 12.5px; color: var(--ink-2); }
.checklist:not([open]) summary::after { content: "展開清單"; }
.cl-title { font-weight: 600; font-size: 16px; }
.cl-count { font-size: 13.5px; color: var(--gold-d); font-weight: 600; font-variant-numeric: tabular-nums; }
.progress { order: 3; flex: 1 0 100%; height: 10px; border-radius: 999px; background: #ebe4d5; overflow: hidden; display: block; }
.progress-bar { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--gold); transition: width .5s ease; }
.cl-items { list-style: none; margin: 14px 0 10px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 6px 10px; }
.cl-item { width: 100%; display: flex; align-items: center; gap: 9px; padding: 7px 10px; border: 1px solid transparent; border-radius: 10px; background: transparent; cursor: pointer; text-align: left; font-size: 14.5px; }
.cl-item:hover { background: var(--gold-soft); border-color: var(--line); }
.cl-box { flex: none; width: 19px; height: 19px; border-radius: 5px; border: 1.5px solid #b9ad97; background: #fff; display: grid; place-items: center; font-style: normal; font-size: 13px; line-height: 1; color: #fff; }
.cl-item.done .cl-box { background: var(--ok); border-color: var(--ok); }
.cl-item.done .cl-box::before { content: "✓"; }
.cl-item.done { color: var(--ink-2); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.field select { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; font-size: 16px; width: 100%; color: var(--ink); }
.field select:focus { outline: 2px solid var(--gold); outline-offset: -1px; border-color: var(--gold); }
@media (max-width: 820px) { .cl-items { grid-template-columns: repeat(2, 1fr); gap: 2px 6px; } .cl-item { padding: 6px 6px; font-size: 14px; } }
