:root {
  --bg: #F3F5F8;
  --panel: #FFFFFF;
  --ink: #1F2937;
  --muted: #6B7280;
  --border: #E2E6EC;
  --brand: #06C755;
  --brand-ink: #FFFFFF;
  --radius: 14px;
  --chat: #8CABD9;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
[hidden] { display: none !important; }
code { background: #EEF1F5; padding: 1px 5px; border-radius: 4px; font-size: .9em; }

/* ---------- 頂部 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.logo {
  width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-size: 16px;
}
.demo-banner {
  background: #FFF7E0; color: #7A5300; border-bottom: 1px solid #F3DFA2;
  padding: 10px 24px; font-size: 14px;
}

/* ---------- 版面 ---------- */
.editor {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 28px;
  max-width: 1120px; margin: 0 auto; padding: 24px;
}
.preview-col { position: sticky; top: 80px; align-self: start; display: flex; flex-direction: column; gap: 14px; }
@media (max-width: 880px) {
  .editor { grid-template-columns: 1fr; padding: 16px; }
  .preview-col { position: static; order: -1; }
}

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px;
}
.preview-col .panel { margin-bottom: 0; }
.panel h2 { font-size: 16px; margin: 0 0 14px; display: flex; align-items: center; gap: 10px; }
.panel h2 small { font-weight: 400; color: var(--muted); font-size: 13px; }
.panel h3 { margin: 0 0 12px; font-size: 16px; }
.step {
  width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-size: 13px;
}
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
input, textarea {
  display: block; width: 100%; margin-top: 5px; padding: 10px 12px; font: inherit; font-size: 15px;
  color: var(--ink); background: #fff; border: 1px solid var(--border); border-radius: 9px;
}
input:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); border-color: var(--brand); }
textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
.hint { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; line-height: 1.6; }
.center { text-align: center; }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; font: inherit; font-size: 14px; font-weight: 600; color: var(--ink);
  background: #fff; border: 1px solid var(--border); border-radius: 9px; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #F7F8FA; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(.95); }
.btn.big { padding: 14px; font-size: 16px; width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.btn-row.end { justify-content: flex-end; }
.btn-row .btn { flex: 1; }
.btn-row.end .btn { flex: 0 0 auto; }
.icon-btn {
  border: none; background: transparent; color: var(--muted); font-size: 16px; cursor: pointer;
  width: 36px; flex: 0 0 36px; border-radius: 8px;
}
.icon-btn:hover { background: #F1F3F6; color: #DC2626; }

/* ---------- 版型 / 色系 ---------- */
.layout-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.layout-opt {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 8px;
  background: #fff; border: 2px solid var(--border); border-radius: 12px; cursor: pointer; font: inherit;
}
.layout-opt small { color: var(--muted); font-size: 11.5px; }
.layout-opt.active { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 6%, #fff); }
.layout-icon { width: 46px; height: 56px; border-radius: 6px; background: #EEF1F5; position: relative; overflow: hidden; margin-bottom: 4px; }
.layout-icon::before, .layout-icon::after { content: ""; position: absolute; background: #B9C2CF; }
.layout-hero::before { left: 0; right: 0; top: 0; height: 24px; }
.layout-hero::after { left: 6px; right: 14px; top: 30px; height: 5px; border-radius: 3px; box-shadow: 0 9px 0 #D3D9E2; }
.layout-avatar::before { left: 6px; top: 8px; width: 16px; height: 16px; border-radius: 50%; }
.layout-avatar::after { left: 26px; right: 6px; top: 11px; height: 5px; border-radius: 3px; box-shadow: 0 7px 0 #D3D9E2; }
.layout-banner::before { left: 5px; right: 5px; top: 6px; height: 20px; border-radius: 4px; }
.layout-banner::after { left: 8px; right: 14px; top: 34px; height: 5px; border-radius: 3px; box-shadow: 0 9px 0 #D3D9E2; }

.theme-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 10px; }
.swatch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0; padding: 0; border: 2px solid var(--border);
  border-radius: 10px; overflow: hidden; cursor: pointer; background: #fff; font: inherit;
}
.swatch span { height: 26px; }
.swatch small { grid-column: 1 / -1; font-size: 11.5px; padding: 4px 2px; color: var(--ink); }
.swatch.active { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }

/* ---------- 照片 ---------- */
.upload-row { display: flex; gap: 16px; align-items: center; }
.upload-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.upload-actions .hint { flex-basis: 100%; margin: 0; }
.thumb { flex: 0 0 auto; background: #EEF1F5 center / cover no-repeat; border: 1px dashed #C8D0DB; }
.thumb.wide { width: 140px; height: 91px; border-radius: 10px; }
.thumb.round { width: 80px; height: 80px; border-radius: 50%; }
.thumb:not(.empty) { border-style: solid; border-color: transparent; }

/* ---------- 自訂按鈕 ---------- */
.btn-edit { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.btn-edit input { margin: 0; }
.btn-edit input:first-child { flex: 0 0 34%; }

/* ---------- 手機預覽 ---------- */
.phone { border-radius: 22px; overflow: hidden; border: 1px solid var(--border); background: var(--chat); box-shadow: 0 10px 30px rgba(15, 23, 42, .08); }
.phone-bar { background: #2B3A55; color: #fff; padding: 10px 16px; font-size: 13px; font-weight: 600; }
.chat { padding: 18px 14px 22px; min-height: 380px; }
.chat-msg { display: flex; gap: 8px; align-items: flex-start; }
.chat-avatar { width: 34px; height: 34px; flex: 0 0 34px; border-radius: 50%; background: #fff; opacity: .85; }
#preview { flex: 1; min-width: 0; }
.warn { margin: 0; padding: 10px 12px; background: #FEF2F2; color: #B91C1C; border-radius: 10px; font-size: 13px; }

/* ---------- Flex 名片（模擬 LINE 呈現）---------- */
.fx-bubble { width: 100%; max-width: 300px; border-radius: 16px; overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.08); font-size: 14px; line-height: 1.45; }
.fx-hero { aspect-ratio: 20 / 13; background: #DDE3EA; }
.fx-hero img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fx-ph { display: grid; place-items: center; color: #8592A3; font-size: 12px; }
.fx-body { padding: 20px; display: flex; flex-direction: column; gap: 2px; }
.fx-company { font-size: 11px; }
.fx-name { font-size: 20px; font-weight: 700; line-height: 1.3; }
.fx-title { font-size: 13px; }
.fx-headrow { display: flex; align-items: center; gap: 16px; }
.fx-headtext { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.fx-avatar { width: 72px; height: 72px; flex: 0 0 72px; border-radius: 50%; overflow: hidden; background: #DDE3EA; }
.fx-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fx-banner { border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 2px; }
.fx-intro { font-size: 13px; margin-top: 10px; white-space: pre-wrap; }
.fx-sep { border: 0; border-top: 1px solid; margin: 16px 0 0; width: 100%; }
.fx-infos { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.fx-info { display: flex; gap: 12px; font-size: 13px; word-break: break-all; }
.fx-footer { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.fx-btn { border-radius: 8px; padding: 11px; text-align: center; font-weight: 700; font-size: 13px; }
.fx-share { font-size: 11px; text-align: center; margin-top: 6px; }

/* ---------- 結果 ---------- */
.result { border-color: color-mix(in srgb, var(--brand) 50%, var(--border)); }
.qr-wrap { display: grid; place-items: center; }
.qr-wrap img { width: 180px; height: 180px; image-rendering: pixelated; }
.copy-row { display: flex; gap: 8px; margin-top: 5px; }
.copy-row input { margin: 0; font-size: 13px; }
details { margin-top: 14px; font-size: 13px; }
summary { cursor: pointer; color: var(--muted); }
.my-cards { list-style: none; margin: 0; padding: 0; }
.my-cards li { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-top: 1px solid var(--border); font-size: 14px; }
.my-cards li:first-child { border-top: 0; }
.my-cards li.current span:first-child { font-weight: 700; }
.my-cards .links { display: flex; gap: 12px; }
.my-cards a { color: #2563EB; text-decoration: none; font-size: 13px; }

/* ---------- 裁切視窗 ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-box { background: #fff; border-radius: 16px; padding: 20px; width: min(560px, 100%); }
.modal-box h3 { margin: 0 0 12px; }
#cropCanvas { width: 100%; height: auto; display: block; border-radius: 10px; cursor: grab; touch-action: none; }
#cropCanvas:active { cursor: grabbing; }
.zoom-row { display: flex; align-items: center; gap: 12px; margin: 14px 0 0; white-space: nowrap; }
.zoom-row input { margin: 0; padding: 0; border: 0; }

/* ---------- 通知 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0;
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px;
  transition: .25s; pointer-events: none; z-index: 100; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 分享頁 ---------- */
.share-page { background: var(--chat); min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 28px 16px 40px; gap: 18px; }
.share-page .fx-bubble { max-width: 340px; box-shadow: 0 8px 28px rgba(15, 23, 42, .18); }
.share-actions { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 10px; }
.share-actions .btn { width: 100%; padding: 13px; font-size: 15px; }
.share-status { color: #fff; font-size: 15px; margin-top: 30vh; text-align: center; }
.share-status.error { background: #fff; color: #B91C1C; padding: 16px 20px; border-radius: 12px; margin-top: 20vh; }
.share-note { max-width: 340px; font-size: 12.5px; color: #1E3A5F; background: rgba(255,255,255,.7); padding: 10px 12px; border-radius: 10px; }
.make-own { color: #fff; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
