@font-face { font-family: GenSen; font-weight: 500; src: url(fonts/GenSenRounded2TW-M.woff) format('woff'); font-display: block; }
@font-face { font-family: GenSen; font-weight: 700; src: url(fonts/GenSenRounded2TW-B.woff) format('woff'); font-display: block; }

:root {
  --bg: #fff8fa; --surface: #ffffff; --ink: #2b2a2c; --muted: #7b7580; --line: #efdfe5;
  --accent: #d48ea8; --accent-ink: #8f4560; --accent-soft: #f7e7ed; --danger: #c0392b; --ok: #3a8a5a;
  --radius: 14px; --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: GenSen, -apple-system, "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; font-size: 16px; line-height: 1.5; }
button, input, select { font: inherit; color: inherit; }
input, select { min-width: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); background: rgba(255,248,250,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.spark { width: 18px; height: 20px; background: var(--accent); clip-path: polygon(50% 0, 58% 42%, 100% 50%, 58% 58%, 50% 100%, 42% 58%, 0 50%, 42% 42%); }
.designbar { margin-left: auto; display: flex; gap: 8px; align-items: center; min-width: 0; }
.designbar select { min-width: 0; max-width: 42vw; height: 38px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 0 10px; }

.btn { height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; list-style: none; }
.btn.small { height: 36px; padding: 0 12px; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; height: 48px; width: 100%; font-size: 17px; }
.btn.primary:disabled { background: #e6d3da; border-color: #e6d3da; color: #fff; cursor: not-allowed; }
.btn:active { transform: translateY(1px); }
summary::-webkit-details-marker { display: none; }
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: 44px; width: 260px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(120,60,80,.15); padding: 6px; display: grid; }
.menu-pop button { text-align: left; background: none; border: 0; padding: 11px 12px; border-radius: 8px; }
.menu-pop button:hover { background: var(--accent-soft); }
.menu-pop .danger { color: var(--danger); }
.menu-pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }

.banner { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: #fff0c8; border-bottom: 1px solid #f0dc9a; font-size: 14px; }
.banner span { flex: 1; }

.layout { display: block; }
.pane { padding: 14px; }
.editor { padding-bottom: 96px; }
.preview { padding-bottom: 110px; }

/* 手機：分頁切換 */
body[data-view="edit"] .preview { display: none; }
body[data-view="preview"] .editor { display: none; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 14px calc(8px + var(--safe-b)); background: rgba(255,255,255,.95); backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
.tabs button { height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; }
.tabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

@media (min-width: 960px) {
  .layout { display: grid; grid-template-columns: minmax(380px, 460px) 1fr; gap: 0; align-items: start; max-width: 1280px; margin: 0 auto; }
  body[data-view] .editor, body[data-view] .preview { display: block; }
  .tabs { display: none; }
  .editor { padding-bottom: 40px; }
  .preview { position: sticky; top: 64px; max-height: calc(100dvh - 64px); overflow: auto; padding-bottom: 24px; }
  .designbar select { max-width: 280px; }
}

/* 表單 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.card h2 { margin: 0 0 10px; font-size: 16px; display: flex; align-items: baseline; gap: 8px; }
.card h2 .count { margin-left: auto; font-size: 13px; color: var(--muted); font-weight: 500; }
.card h2 .count.bad { color: var(--danger); font-weight: 700; }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field > span.lab { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.field input[type=text], .field input[type=url], .field input:not([type]) { height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: #fff; width: 100%; }
.field input:focus, .item input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field .err, .err { color: var(--danger); font-size: 13px; min-height: 0; }
.field.bad input { border-color: var(--danger); }
.hint { font-size: 12.5px; color: var(--muted); }
.count-inline.bad { color: var(--danger); font-weight: 700; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sw { width: 34px; height: 34px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); padding: 0; }
.sw.on { box-shadow: 0 0 0 2px var(--ink); }
input[type=color] { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: #fff; }

.imgbox { display: grid; gap: 8px; }
.focus { position: relative; width: 100%; border-radius: 10px; overflow: hidden; background: #eee; touch-action: none; user-select: none; -webkit-user-select: none; }
.focus img { display: block; width: 100%; height: auto; pointer-events: none; -webkit-user-drag: none; }
.focus .shade { position: absolute; inset: 0; pointer-events: none; }
.focus .win { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(40,20,30,.45); border-radius: 8px; pointer-events: none; }
.focus .dot { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; pointer-events: none; }
.filebtn { position: relative; overflow: hidden; }
.filebtn input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.corner-prev { width: 96px; height: 92px; border-radius: 10px; background: #fff url() center/cover; border: 1px solid var(--line); object-fit: contain; }

.item { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; background: #fffdfd; }
.item-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.item-head b { margin-right: auto; font-size: 14px; }
.ibtn { width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line); background: #fff; padding: 0; font-size: 15px; }
.ibtn:disabled { opacity: .35; }
.ibtn.del { color: var(--danger); }
.item input { height: 42px; border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; width: 100%; background: #fff; }
.item .field { margin-bottom: 8px; }
.sizes { display: grid; gap: 6px; }
.sizerow { display: flex; align-items: center; gap: 6px; }
.sizerow input { width: 78px; text-align: center; }
.sizerow .x { color: var(--muted); }
.sizerow .unit { color: var(--muted); font-size: 14px; margin-right: auto; }
.addbtn { width: 100%; height: 42px; border: 1px dashed var(--accent); background: var(--accent-soft); color: var(--accent-ink); border-radius: 10px; font-weight: 700; }
.addbtn:disabled { opacity: .45; }
.accrow { display: grid; grid-template-columns: minmax(0, 1fr) 62px auto; gap: 6px; align-items: center; margin-bottom: 8px; }
.accrow .btns { display: flex; gap: 4px; }
.accrow input { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; background: #fff; }
.accrow input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* 預覽 */
.seg { display: inline-grid; grid-template-columns: 1fr 1fr; background: var(--accent-soft); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.seg button { height: 38px; padding: 0 16px; border: 0; background: transparent; border-radius: 9px; font-weight: 700; color: var(--accent-ink); }
.seg button.on { background: #fff; box-shadow: 0 1px 4px rgba(120,60,80,.15); }
.stage { display: flex; justify-content: center; background: #f2eaee; border-radius: var(--radius); padding: 12px; }
#canvas { width: 100%; height: auto; background: #fff; box-shadow: 0 4px 18px rgba(80,40,60,.18); max-width: 100%; touch-action: pinch-zoom; }
.note { font-size: 13px; color: var(--muted); margin: 8px 2px; }
.actions { display: grid; gap: 8px; margin-top: 10px; }
.why { background: #fdeceb; border: 1px solid #f3c7c3; color: var(--danger); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.why ul { margin: 4px 0 0; padding-left: 18px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + var(--safe-b)); background: #2b2a2c; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 50; max-width: 90vw; font-size: 14px; }
@media (min-width: 960px) { .toast { bottom: 24px; } }

/* 貼上清單 */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(40,20,30,.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--surface); border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); display: grid; gap: 10px; }
.sheet h3 { margin: 0; font-size: 17px; }
.sheet textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; resize: vertical; min-height: 140px; line-height: 1.6; }
.sheet textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.sheet .prev { font-size: 14px; display: grid; gap: 6px; }
.sheet .prev .pi { background: var(--accent-soft); border-radius: 10px; padding: 8px 10px; }
.sheet .prev .pi b { font-weight: 700; }
.sheet .prev .warn { color: var(--danger); }
.sheet-actions { display: grid; gap: 8px; }
.sheet-actions .btn { width: 100%; height: 46px; }
.sheet-actions .btn.primary { height: 48px; }
@media (min-width: 960px) { .overlay { align-items: center; } .sheet { border-radius: 18px; } }
.pastebtn { width: 100%; height: 42px; border: 1px solid var(--accent); background: #fff; color: var(--accent-ink); border-radius: 10px; font-weight: 700; margin-bottom: 10px; }

.bigtext { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; line-height: 1.6; resize: vertical; background: #fff; font: inherit; }
.bigtext:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.prev { font-size: 14px; display: grid; gap: 6px; margin-top: 8px; }
.prev .pi { background: var(--accent-soft); border-radius: 10px; padding: 8px 10px; }
.prev .warn { color: var(--danger); }
