:root {
  --bg: #FBF7F2;
  --surface: #FFFFFF;
  --surface-2: #F4EEE7;
  --ink: #1F2328;
  --ink-2: #5B616B;
  --line: #E8E0D6;
  --accent: #FF6B57;
  --accent-ink: #FFFFFF;
  --focus: #2F80ED;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(31, 35, 40, .04), 0 8px 24px rgba(31, 35, 40, .06);
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171B;
    --surface: #1E2126;
    --surface-2: #272B31;
    --ink: #ECEEF1;
    --ink-2: #A3AAB4;
    --line: #30353C;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }

button, input, select { font: inherit; color: inherit; }

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

/* ---------- Header ---------- */
.site-header {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 20px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  justify-content: space-between;
}

.brand { display: flex; gap: 14px; align-items: center; }
.brand-mark { width: 44px; height: 44px; flex: none; }
.bm-bg { fill: var(--accent); }
.bm-check { stroke: var(--accent); }

h1 { font-size: 22px; font-weight: 900; letter-spacing: .02em; }
.tagline { color: var(--ink-2); font-size: 14px; }

.privacy {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 999px;
}
.privacy .dot { width: 8px; height: 8px; border-radius: 50%; background: #12B886; }

/* ---------- Layout ---------- */
.layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 20px 32px;
  display: grid;
  grid-template-columns: minmax(0, 440px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.preview-panel {
  position: sticky;
  top: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.controls { display: flex; flex-direction: column; gap: 16px; }

.card { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 14px; }

.card h2 {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.step {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  background: var(--ink);
  color: var(--bg);
}

/* ---------- Preview ---------- */
.stage {
  position: relative;
  border-radius: 12px;
  background:
    conic-gradient(var(--surface-2) 25%, transparent 0 50%, var(--surface-2) 0 75%, transparent 0) 0 0 / 20px 20px,
    var(--surface);
  padding: 16px;
}

.avatar-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 6px;
  transition: border-radius .25s ease;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .14);
}
.avatar-frame.is-circle { border-radius: 50%; }
.avatar-frame:not(.is-circle)::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, .85);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .15);
  pointer-events: none;
}

#preview {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#preview.dragging { cursor: grabbing; }
#preview.empty { cursor: pointer; }

.drop-hint {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  border-radius: 12px;
  border: 2px dashed var(--accent);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  font-weight: 700;
  color: var(--accent);
}
.stage.drag-over .drop-hint { display: grid; }

.zoom-row { display: flex; align-items: center; gap: 12px; }
.zoom-label { font-size: 14px; color: var(--ink-2); flex: none; }
input[type="range"] { flex: 1; accent-color: var(--accent); }

.hint { font-size: 13px; color: var(--ink-2); }
.hint.warn { color: #D9480F; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions .btn:only-child { grid-column: 1 / -1; }
#shareBtn:not([hidden]) { grid-column: 1 / -1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { border-color: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn[disabled] { opacity: .5; cursor: progress; }

.link-btn {
  align-self: flex-start;
  background: none;
  border: 0;
  padding: 2px 0;
  color: var(--ink-2);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font-size: 13px;
}
.link-btn:hover { color: var(--ink); }
.link-btn[disabled] { opacity: .4; cursor: default; }

/* LINE friend list mock */
.mock { border-top: 1px solid var(--line); padding-top: 14px; }
.mock-title { font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.mock-row { display: flex; align-items: center; gap: 12px; }
.mock-avatar { width: 56px; height: 56px; border-radius: 50%; flex: none; background: var(--surface-2); }
.mock-text { display: flex; flex-direction: column; min-width: 0; }
.mock-text strong { font-size: 15px; }
.mock-text span { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Controls ---------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 22px 16px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone.drag-over { border-color: var(--accent); }
.dropzone svg { width: 30px; height: 30px; fill: none; stroke: var(--ink-2); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.dz-main { font-weight: 700; }
.dz-sub { font-size: 12px; color: var(--ink-2); }

.presets { display: flex; flex-direction: column; gap: 8px; }
.preset-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.preset {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink-2);
}
.preset img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid transparent;
  box-shadow: 0 0 0 1px var(--line);
  transition: border-color .15s ease, transform .1s ease;
}
.preset:hover img { transform: scale(1.04); }
.preset[aria-pressed="true"] img { border-color: var(--accent); box-shadow: none; }
.preset[aria-pressed="true"] { color: var(--ink); font-weight: 700; }

@media (max-width: 480px) {
  .preset-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 0 8px; }
}

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  padding: 6px 14px;
  border-radius: 9px;
  font-size: 14px;
  cursor: pointer;
  color: var(--ink-2);
}
.segmented input:checked + span { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.segmented input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 14px;
  cursor: pointer;
}
.chip:hover { border-color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--ink-2); display: flex; justify-content: space-between; }
.counter { font-size: 12px; }

input[type="text"], input[type="date"], select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 16px; /* 避免 iOS 自動放大 */
}
input[type="text"]:focus, input[type="date"]:focus, select:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

.checks { display: flex; flex-wrap: wrap; gap: 8px 20px; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

.styles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.style-opt { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; }
.style-opt input { position: absolute; opacity: 0; pointer-events: none; }
.style-opt canvas {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid transparent;
  box-shadow: 0 0 0 1px var(--line);
  transition: border-color .15s ease;
}
.style-opt span { font-size: 13px; color: var(--ink-2); }
.style-opt input:checked ~ canvas { border-color: var(--accent); box-shadow: none; }
.style-opt input:checked ~ span { color: var(--ink); font-weight: 700; }
.style-opt input:focus-visible ~ canvas { outline: 2px solid var(--focus); outline-offset: 2px; }

.field-label .link-btn { align-self: auto; padding: 0; font-size: 12px; }
.scales { display: flex; flex-direction: column; gap: 6px; }
.scale-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) 44px; align-items: center; gap: 10px; font-size: 14px; }
.scale-row output { font-size: 13px; color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.swatch {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
  padding: 0;
}
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--ink); }
.swatch-custom {
  position: relative;
  width: 34px; height: 34px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--line);
  background: conic-gradient(#FF6B57, #F5A524, #12B886, #2F80ED, #845EF7, #E64980, #FF6B57);
  cursor: pointer;
}
.swatch-custom.active { box-shadow: 0 0 0 2px var(--ink); }
.swatch-custom input { position: absolute; inset: -8px; width: 50px; height: 50px; opacity: 0; cursor: pointer; }

/* ---------- Footer & toast ---------- */
.site-footer { text-align: center; padding: 8px 20px 40px; font-size: 12px; color: var(--ink-2); display: flex; flex-direction: column; gap: 4px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
  .stage { max-width: 420px; width: 100%; margin: 0 auto; }
}

@media (max-width: 480px) {
  .site-header { padding: 20px 16px 8px; }
  .layout { padding: 8px 16px 24px; gap: 16px; }
  .preview-panel, .card { padding: 16px; }
  .styles { gap: 8px; }
  .style-opt span { font-size: 12px; }
  .segmented span { padding: 6px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
