:root {
  --bg: #f6ecff;
  --grid: rgba(155, 120, 210, 0.16);
  --ink: #2b1d3a;
  --ink-soft: #7a6690;
  --paper: #fffaf3;
  --pink: #ff7eb6;
  --pink-deep: #ff4f9a;
  --mint: #7ee0c3;
  --sky: #8ec5ff;
  --lilac: #c8a6ff;
  --yellow: #ffe66d;
  --line: 2.5px solid var(--ink);
  --pop: 4px 4px 0 var(--ink);
  --pop-sm: 2px 2px 0 var(--ink);
  --radius: 16px;
  --font: "Chiron GoRound TC", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  --px: "Silkscreen", "Courier New", monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* .btn 等 display 設定會蓋過 hidden 屬性，這裡強制隱藏 */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
}

.px { font-family: var(--px); letter-spacing: 0.04em; }

/* 背景像素星星 */
.sparkles { position: fixed; inset: 0; z-index: -1; pointer-events: none; }
.sparkles i {
  position: absolute; width: 6px; height: 6px; background: var(--c, var(--pink));
  box-shadow: 0 -6px 0 var(--c, var(--pink)), 0 6px 0 var(--c, var(--pink)), -6px 0 0 var(--c, var(--pink)), 6px 0 0 var(--c, var(--pink));
  animation: twinkle 2.4s steps(2) infinite;
}
.sparkles i:nth-child(1) { top: 18%; left: 6%; --c: var(--pink); }
.sparkles i:nth-child(2) { top: 42%; right: 5%; --c: var(--sky); animation-delay: 0.6s; }
.sparkles i:nth-child(3) { top: 70%; left: 4%; --c: var(--yellow); animation-delay: 1.2s; }
.sparkles i:nth-child(4) { top: 88%; right: 10%; --c: var(--lilac); animation-delay: 0.3s; }
.sparkles i:nth-child(5) { top: 30%; left: 92%; --c: var(--mint); animation-delay: 1.6s; }
.sparkles i:nth-child(6) { top: 58%; left: 48%; --c: var(--pink); animation-delay: 0.9s; opacity: 0.5; }
@keyframes twinkle { 50% { opacity: 0.15; } }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  padding: calc(env(safe-area-inset-top) + 12px) 20px 12px;
  background: rgba(246, 236, 255, 0.82);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: var(--line);
}
.topbar-row { display: flex; align-items: center; gap: 12px; max-width: 520px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-cam { width: 34px; height: 30px; stroke: none; image-rendering: pixelated; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 18px; font-weight: 900; letter-spacing: 0.04em; }
.brand-text .px { font-size: 9px; color: var(--ink-soft); }

.stepper {
  list-style: none; margin: 12px auto 0; padding: 0; max-width: 520px;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  counter-reset: step;
}
.stepper li {
  counter-increment: step;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 0; border: 2px solid var(--ink); border-radius: 10px;
  background: var(--paper); font-size: 12px; font-weight: 900; color: var(--ink-soft);
  transition: 0.2s ease;
}
.stepper li::before { content: "0" counter(step); font-family: var(--px); font-size: 10px; }
.stepper li.done { background: var(--mint); color: var(--ink); }
.stepper li.on { background: var(--pink); color: #fff; box-shadow: var(--pop-sm); transform: translate(-1px, -1px); }

/* ---------- Layout ---------- */
main { max-width: 560px; margin: 0 auto; padding: 24px 20px calc(env(safe-area-inset-bottom) + 32px); }
.step { display: none; flex-direction: column; gap: 22px; }
.step.active { display: flex; animation: boot 0.35s steps(5); }
@keyframes boot { from { opacity: 0; transform: translateY(10px); } }

/* 視窗卡片 */
.card {
  background: var(--paper);
  border: var(--line);
  border-radius: var(--radius);
  box-shadow: var(--pop);
  overflow: hidden;
}
.win-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-bottom: var(--line);
  background: var(--pink);
}
.win-bar.mint { background: var(--mint); }
.win-bar.sky { background: var(--sky); }
.win-bar.lilac { background: var(--lilac); }
.win-bar.yellow { background: var(--yellow); }
.win-bar b { font-size: 15px; font-weight: 900; }
.win-tag {
  font-size: 9px; padding: 3px 6px; border-radius: 6px;
  background: rgba(255, 255, 255, 0.7); border: 1.5px solid var(--ink);
}
.win-dots { margin-left: auto; display: flex; gap: 5px; }
.win-dots i { width: 11px; height: 11px; border: 2px solid var(--ink); border-radius: 50%; background: var(--paper); }
.win-dots i:last-child { background: var(--ink); }
.win-body { padding: 20px; }

.hint { margin: 12px 0 0; font-size: 12px; color: var(--ink-soft); }
.hint.center { text-align: center; margin: 0; }

/* ---------- Buttons ---------- */
button { font: inherit; color: inherit; cursor: pointer; }
.btn, .icon-btn, .shutter, .chips button, .tabs button, .seg button, .layout-card, .theme-card, .sticker-grid button, .swatches button {
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}
.btn:active, .icon-btn:active, .chips button:active, .layout-card:active, .theme-card:active,
.sticker-grid button:active, .tabs button:active, .seg button:active {
  transform: translate(2px, 2px) scale(0.965); box-shadow: 0 0 0 var(--ink);
}
.swatches button:active { transform: scale(0.965); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: var(--line); border-radius: 14px; padding: 11px 18px;
  background: var(--paper); font-weight: 900; font-size: 15px;
  box-shadow: var(--pop-sm);
}
.btn .px { font-size: 11px; padding: 3px 6px; border-radius: 6px; background: rgba(255, 255, 255, 0.3); }
.btn.primary { background: var(--pink); color: #fff; }
.btn.ghost { background: #fff; }
.btn.big { width: 100%; padding: 16px; font-size: 17px; border-radius: 18px; box-shadow: var(--pop); }
.btn:disabled { opacity: 0.45; pointer-events: none; box-shadow: none; }

.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: var(--line); border-radius: 12px; background: var(--paper); box-shadow: var(--pop-sm);
}
.icon-btn.round { width: 56px; height: 56px; border-radius: 50%; cursor: pointer; }
.icon-btn svg { width: 22px; height: 22px; }

.field {
  width: 100%; border: var(--line); border-radius: 12px;
  padding: 12px 14px; font: inherit; font-size: 16px; font-weight: 700; color: var(--ink);
  background: #fff; outline: none; box-shadow: inset 2px 2px 0 rgba(43, 29, 58, 0.1);
}
.field:focus { background: #fff6fb; border-color: var(--pink-deep); }

.row { display: flex; align-items: center; gap: 12px; }
.row .field { flex: 1; }

/* ---------- Step 1 ---------- */
.layout-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.layout-card, .theme-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  border: 2px solid var(--ink); border-radius: 12px; padding: 10px 6px;
  background: #fff; font-size: 12px; font-weight: 900; white-space: nowrap;
}
.layout-card { justify-content: space-between; }
.layout-card canvas { max-height: 96px; max-width: 100%; width: auto; height: auto; border-radius: 4px; outline: 2px solid var(--ink); }
.layout-card.on, .theme-card.on { background: var(--yellow); box-shadow: var(--pop-sm); transform: translate(-1px, -1px); }

.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme-card canvas { width: 100%; height: auto; border-radius: 4px; outline: 2px solid var(--ink); }
.theme-grid.compact { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 10px 10px 8px 2px; margin: -10px 0 4px; }
.theme-grid.compact::-webkit-scrollbar { display: none; }
.theme-grid.compact .theme-card { flex: 0 0 68px; }
.theme-grid.compact .theme-card { padding: 4px; font-size: 10px; gap: 4px; border-radius: 10px; }

/* ---------- Step 2：數位相機 ---------- */
.cam {
  border: var(--line); border-radius: 26px; padding: 0 14px 14px;
  background: linear-gradient(180deg, #ffd3e8, #ffb8d9);
  box-shadow: var(--pop);
}
.cam-top { display: flex; align-items: center; gap: 10px; padding: 10px 4px; }
.cam-top .px { font-size: 11px; font-weight: 700; }
.cam-lens {
  margin-left: auto; width: 18px; height: 18px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff 0 18%, var(--sky) 20% 55%, var(--ink) 58%);
  border: 2px solid var(--ink);
}
.led { width: 10px; height: 10px; border-radius: 50%; background: var(--mint); border: 2px solid var(--ink); }
.led.busy { background: #ff3b4e; animation: blink 0.6s steps(2) infinite; }

.stage {
  position: relative; width: 100%; max-height: 52dvh; margin: 0 auto;
  border: var(--line); border-radius: 12px; overflow: hidden; background: #241a30;
  box-shadow: inset 0 0 0 4px #3d2f4d;
}
.stage video { width: 100%; height: 100%; object-fit: cover; display: block; }
.stage video.mirror { transform: scaleX(-1); }
.stage-msg {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 24px;
  text-align: center; color: #fff; font-size: 14px; line-height: 1.7; z-index: 2;
}

.hud { position: absolute; inset: 0; pointer-events: none; color: #fff; text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5); }
.hud-rec { position: absolute; top: 12px; right: 56px; display: flex; align-items: center; gap: 5px; font-size: 11px; }
.hud-rec i { width: 8px; height: 8px; border-radius: 50%; background: #ff3b4e; animation: blink 1s steps(2) infinite; }
.hud-batt {
  position: absolute; top: 12px; right: 14px; display: flex; gap: 2px; padding: 2px;
  border: 1.5px solid #fff; border-radius: 3px;
}
.hud-batt::after { content: ""; position: absolute; right: -4px; top: 3px; width: 2px; height: 5px; background: #fff; }
.hud-batt i { width: 4px; height: 7px; background: var(--mint); }
.hud-clock { position: absolute; left: 14px; bottom: 12px; font-size: 11px; color: #ffb36b; }
.hud-corners i { position: absolute; width: 16px; height: 16px; border: 2px solid rgba(255, 255, 255, 0.8); }
.hud-corners i:nth-child(1) { top: 40px; left: 14px; border-right: 0; border-bottom: 0; }
.hud-corners i:nth-child(2) { top: 40px; right: 14px; border-left: 0; border-bottom: 0; }
.hud-corners i:nth-child(3) { bottom: 32px; left: 14px; border-right: 0; border-top: 0; }
.hud-corners i:nth-child(4) { bottom: 32px; right: 14px; border-left: 0; border-top: 0; }
@keyframes blink { 50% { opacity: 0; } }

.countdown {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-size: 120px; font-weight: 700; color: var(--yellow);
  text-shadow: 6px 6px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink);
}
.countdown.pop { animation: pop 0.9s steps(6) forwards; }
@keyframes pop {
  0% { transform: scale(1.6); opacity: 0; }
  25% { transform: scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: scale(0.85); opacity: 0; }
}
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash 0.45s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }
.shot-badge {
  position: absolute; top: 10px; left: 12px; padding: 4px 10px; border-radius: 8px;
  background: var(--yellow); color: var(--ink); border: 2px solid var(--ink);
  font-size: 12px; font-weight: 900;
}
.shot-badge:empty { display: none; }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 4px 6px 2px; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none; border: 2px solid var(--ink); border-radius: 99px; padding: 8px 15px;
  background: var(--paper); font-size: 14px; font-weight: 900;
}
.chips button.on { background: var(--lilac); box-shadow: var(--pop-sm); transform: translate(-1px, -1px); }

.shutter-row { display: flex; align-items: center; justify-content: center; gap: 36px; }
.shutter {
  width: 84px; height: 84px; border-radius: 50%; border: var(--line); padding: 8px;
  background: var(--paper); box-shadow: 0 5px 0 var(--ink);
}
.shutter:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.shutter span {
  display: block; width: 100%; height: 100%; border-radius: 50%; border: 2.5px solid var(--ink);
  background: radial-gradient(circle at 35% 30%, #ffc2dd 0 20%, var(--pink-deep) 60%);
  transition: 0.2s ease;
}
.shutter.busy span { transform: scale(0.6); border-radius: 10px; }

.thumbs { display: flex; gap: 10px; }
.thumbs button {
  flex: 1; aspect-ratio: var(--cell-ratio, 4 / 3); border: 2px dashed var(--ink-soft);
  border-radius: 10px; background: #fff center / cover no-repeat;
  color: var(--ink-soft); font-family: var(--px); font-size: 14px; padding: 0;
}
.thumbs button.filled { border: 2px solid var(--ink); color: transparent; box-shadow: var(--pop-sm); }
.thumbs button.next { border-color: var(--pink-deep); color: var(--pink-deep); background-color: #fff0f7; animation: nextslot 1.2s steps(2) infinite; }
@keyframes nextslot { 50% { border-color: transparent; } }

/* ---------- Step 3 ---------- */
.canvas-wrap {
  display: grid; place-items: center;
  height: calc(100dvh - 500px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  min-height: 300px;
}
#editCanvas {
  touch-action: none; border-radius: 6px;
  outline: var(--line); box-shadow: 6px 6px 0 var(--ink);
}
.tool-body { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.tabs { display: flex; gap: 6px; }
.tabs button {
  flex: 1; border: 2px solid var(--ink); border-radius: 10px; padding: 7px 0;
  background: #fff; font-size: 14px; font-weight: 900; color: var(--ink-soft);
}
.tabs button.on { background: var(--pink); color: #fff; box-shadow: var(--pop-sm); transform: translate(-1px, -1px); }

.tab-body { display: none; }
.tab-body.on { display: block; }
.tab-body > * + * { margin-top: 12px; }

.sticker-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px;
  max-height: 150px; overflow-y: auto; padding: 2px 4px 4px 2px;
}
.sticker-grid button {
  aspect-ratio: 1; border: 2px solid var(--ink); border-radius: 10px; background: #fff;
  display: grid; place-items: center; padding: 6px;
}
.sticker-grid img { max-width: 100%; max-height: 100%; pointer-events: none; }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatches button { width: 32px; height: 32px; border-radius: 8px; border: 2px solid var(--ink); }
.swatches button.on { box-shadow: var(--pop-sm); transform: translate(-1px, -1px); outline: 2px solid #fff; outline-offset: -5px; }

.seg { display: flex; border: 2px solid var(--ink); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 7px 14px; font-weight: 900; font-size: 13px; color: var(--ink-soft); }
.seg button + button { border-left: 2px solid var(--ink); }
.seg button.on { background: var(--yellow); color: var(--ink); }
input[type="range"] { flex: 1; accent-color: var(--pink-deep); }

.edit-actions .btn { padding: 9px 13px; font-size: 14px; }
.edit-actions .btn.primary { margin-left: auto; padding: 9px 22px; }
.edit-actions svg { width: 16px; height: 16px; }

/* ---------- Step 4：印表機 ---------- */
.printer { position: relative; display: flex; flex-direction: column; align-items: center; }
.printer-paper {
  width: 58%; height: 26px; margin-bottom: -2px;
  border: var(--line); border-bottom: 0; border-radius: 6px 6px 0 0;
  background: repeating-linear-gradient(#fff 0 6px, #efe4f7 6px 7px);
}
.printer-body {
  position: relative; z-index: 2; width: 100%;
  padding: 14px 16px 26px;
  border: var(--line); border-radius: 26px 26px 16px 16px;
  background: linear-gradient(180deg, #ddc8ff, var(--lilac));
  box-shadow: var(--pop);
}
.printer-top { display: flex; align-items: center; gap: 10px; }
.printer-name { font-size: 11px; font-weight: 700; }
.printer-knobs { margin-left: auto; display: flex; gap: 6px; }
.printer-knobs i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); background: var(--yellow); }
.printer-knobs i + i { background: var(--sky); }
.printer-led { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink); background: var(--mint); }
.printing .printer-led { background: #ff3b4e; animation: blink 0.5s steps(2) infinite; }

.printer-lcd {
  display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 8px 12px;
  border: 2px solid var(--ink); border-radius: 10px;
  background: #c8ecd2; color: #1d4a33; font-size: 11px;
  box-shadow: inset 2px 2px 0 rgba(0, 0, 0, 0.12);
}
#printLcd { min-width: 104px; }
.printer-progress { flex: 1; height: 10px; border: 2px solid #1d4a33; border-radius: 3px; overflow: hidden; }
.printer-progress i {
  display: block; height: 100%; width: 0;
  background: repeating-linear-gradient(90deg, #1d4a33 0 6px, transparent 6px 8px);
}

.printer-slot {
  position: absolute; left: 7%; right: 7%; bottom: -8px; z-index: 3;
  height: 16px; border-radius: 8px; background: var(--ink);
  box-shadow: inset 0 4px 0 #000;
}
.printing .printer-body { animation: vibrate 0.14s steps(2) infinite; }
@keyframes vibrate { 50% { transform: translate(1px, -1px); } }

/* 出紙口：上緣當成裁切線，紙一段一段送出來 */
.paper-out {
  position: relative; z-index: 1; width: 100%;
  display: grid; place-items: center; overflow: hidden; padding: 0 12px 14px;
}
#resultImg {
  max-width: 100%; max-height: 56dvh; border-radius: 0 0 4px 4px;
  outline: var(--line); box-shadow: 6px 6px 0 var(--ink);
}
.printing #resultImg { animation: feed var(--print-ms, 3.6s) linear both; }
.done #resultImg { animation: settle 0.45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes feed {
  0% { transform: translateY(-101%); }
  12%, 20% { transform: translateY(-84%); }
  32%, 40% { transform: translateY(-63%); }
  52%, 60% { transform: translateY(-41%); }
  72%, 80% { transform: translateY(-20%); }
  100% { transform: translateY(0); }
}
@keyframes settle { 40% { transform: translateY(8px); } }

/* 印好時從出紙口噴出的像素星星 */
.print-burst { position: absolute; left: 50%; bottom: -2px; z-index: 4; pointer-events: none; }
.print-burst i {
  position: absolute; width: 5px; height: 5px; opacity: 0;
  background: var(--c); box-shadow: 0 -5px 0 var(--c), 0 5px 0 var(--c), -5px 0 0 var(--c), 5px 0 0 var(--c);
}
.done .print-burst i { animation: burst 0.8s cubic-bezier(.2, .8, .3, 1) both; }
.print-burst i:nth-child(1) { --c: var(--pink-deep); --x: -150px; --y: 26px; }
.print-burst i:nth-child(2) { --c: var(--yellow); --x: -110px; --y: 70px; }
.print-burst i:nth-child(3) { --c: var(--sky); --x: -136px; --y: -4px; animation-delay: 0.05s; }
.print-burst i:nth-child(4) { --c: var(--mint); --x: 112px; --y: 66px; }
.print-burst i:nth-child(5) { --c: var(--pink); --x: 150px; --y: 22px; animation-delay: 0.05s; }
.print-burst i:nth-child(6) { --c: #fff; --x: 134px; --y: -6px; animation-delay: 0.1s; }
@keyframes burst {
  0% { opacity: 1; transform: translate(0, 0) scale(0.4); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--x), var(--y)) scale(1.2); }
}

/* 印好之前先藏起按鈕 */
#step-export .export-actions, #saveHint { transition: opacity 0.35s ease, transform 0.35s ease; }
#step-export:not(.done) .export-actions, #step-export:not(.done) #saveHint { opacity: 0; transform: translateY(14px); pointer-events: none; }
.export-actions { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 28px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 12px 18px; border-radius: 12px; border: var(--line);
  background: var(--yellow); color: var(--ink); box-shadow: var(--pop);
  font-size: 14px; font-weight: 900; transition: 0.25s ease; max-width: calc(100% - 40px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 900px) {
  main { max-width: 980px; }
  #step-decorate { display: none; }
  #step-decorate.active { display: grid; grid-template-columns: 1fr 400px; align-items: start; gap: 28px; }
  .canvas-wrap { height: calc(100dvh - 170px); }
  #step-camera.active, #step-setup.active, #step-export.active { max-width: 560px; margin: 0 auto; width: 100%; }
}

/* ---------- 動畫：模板漂浮 + 選取特效 ---------- */
.layout-card, .theme-card { position: relative; }
.layout-card canvas, .theme-card canvas {
  animation: float 3.2s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * -0.55s);
  box-shadow: 0 6px 0 -2px rgba(43, 29, 58, 0.18);
}
.layout-card:nth-child(1), .theme-card:nth-child(1) { --i: 0; }
.layout-card:nth-child(2), .theme-card:nth-child(2) { --i: 1; }
.layout-card:nth-child(3), .theme-card:nth-child(3) { --i: 2; }
.layout-card:nth-child(4), .theme-card:nth-child(4) { --i: 3; }
.theme-card:nth-child(5) { --i: 4; }
.theme-card:nth-child(6) { --i: 5; }
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-5px) rotate(1deg); }
}

/* 選中：彈一下 + 浮更高 + 打勾章 + 閃爍像素星 */
.layout-card.on, .theme-card.on { animation: pick 0.45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pick {
  0% { transform: scale(0.9); }
  60% { transform: scale(1.06) translate(-1px, -1px); }
  100% { transform: translate(-1px, -1px); }
}
.layout-card.on canvas, .theme-card.on canvas {
  animation: float-on 2s ease-in-out infinite;
  box-shadow: 4px 10px 0 -2px rgba(43, 29, 58, 0.28);
}
@keyframes float-on {
  0%, 100% { transform: translateY(-3px) rotate(-2deg) scale(1.03); }
  50% { transform: translateY(-9px) rotate(2deg) scale(1.03); }
}
.layout-card.on::after, .theme-card.on::after {
  content: ""; position: absolute; top: -9px; right: -9px; z-index: 2;
  width: 24px; height: 24px; border-radius: 8px;
  border: 2px solid var(--ink); box-shadow: var(--pop-sm);
  background: var(--pink) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' fill='none' stroke='%23fff' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 18px no-repeat;
  animation: stamp 0.4s cubic-bezier(.3, 1.8, .5, 1) both;
}
@keyframes stamp { from { transform: scale(0) rotate(-40deg); } }
.layout-card.on::before, .theme-card.on::before {
  content: ""; position: absolute; top: 10px; left: 8px; z-index: 2;
  width: 4px; height: 4px; background: var(--pink-deep);
  box-shadow: 0 -4px 0 var(--pink-deep), 0 4px 0 var(--pink-deep), -4px 0 0 var(--pink-deep), 4px 0 0 var(--pink-deep);
  animation: twinkle 0.9s steps(2) infinite;
}
.theme-grid.compact .theme-card.on::after { width: 16px; height: 16px; top: -6px; right: -6px; border-radius: 5px; background-size: 12px; }
.theme-grid.compact .theme-card.on::before { display: none; }
.theme-grid.compact canvas { animation-duration: 3.6s; }

/* 其他選取的小彈跳 */
.chips button.on, .tabs button.on, .seg button.on, .stepper li.on { animation: bump 0.35s cubic-bezier(.3, 1.7, .5, 1); }
.swatches button.on { animation: bump-sw 0.35s cubic-bezier(.3, 1.7, .5, 1); }
@keyframes bump { 0% { transform: scale(0.88); } 100% { transform: translate(-1px, -1px); } }
@keyframes bump-sw { 0% { transform: scale(0.8); } 100% { transform: translate(-1px, -1px); } }

/* 滑鼠移上去：貼圖晃一下、卡片微微抬起 */
@media (hover: hover) {
  .sticker-grid button:hover img { animation: wiggle 0.5s ease-in-out; }
  .layout-card:not(.on):hover, .theme-card:not(.on):hover { transform: translate(-1px, -1px); box-shadow: var(--pop-sm); }
}
@keyframes wiggle { 25% { transform: rotate(-10deg) scale(1.1); } 75% { transform: rotate(8deg) scale(1.1); } }

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

.field-label { display: block; font-size: 13px; font-weight: 900; }
.field-label + .field { margin-top: 6px; }

/* ---------- 首頁 / 教學（與拍貼機本體切換） ---------- */
.view-home, .view-guide { display: none; }
body[data-view="home"] .view-home, body[data-view="guide"] .view-guide { display: flex; }
body:not([data-view="app"]) .topbar, body:not([data-view="app"]) main { display: none; }

.view-home, .view-guide {
  flex-direction: column; gap: 22px; max-width: 520px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 28px) 20px calc(env(safe-area-inset-bottom) + 32px);
  animation: boot 0.35s steps(5);
}

.home-hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding-top: 12px; }
.hero-cam {
  position: relative; width: 168px; height: 168px; display: grid; place-items: center;
  border: var(--line); border-radius: 40px; background: var(--paper); box-shadow: 6px 6px 0 var(--ink);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 21px 21px;
  animation: float 3s ease-in-out infinite;
}
.hero-cam-svg { width: 116px; height: 102px; stroke: none; image-rendering: pixelated; filter: drop-shadow(5px 5px 0 var(--lilac)); }
.hero-flash {
  position: absolute; top: 22px; right: 24px; width: 6px; height: 6px; background: var(--yellow);
  box-shadow: 0 -6px 0 var(--yellow), 0 6px 0 var(--yellow), -6px 0 0 var(--yellow), 6px 0 0 var(--yellow);
  animation: twinkle 1.2s steps(2) infinite;
}
.hero-kicker { margin: 26px 0 6px; font-size: 11px; color: var(--ink-soft); }
.home-hero h1 { margin: 0; font-size: 40px; font-weight: 900; letter-spacing: 0.06em; text-shadow: 3px 3px 0 var(--pink); }
.hero-sub { margin: 12px 0 0; font-size: 15px; line-height: 1.7; color: var(--ink-soft); font-weight: 700; }
.hero-stats { list-style: none; margin: 20px 0 0; padding: 0; display: flex; gap: 8px; }
.hero-stats li {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 64px;
  padding: 8px 6px; border: 2px solid var(--ink); border-radius: 12px; background: #fff;
  font-size: 12px; font-weight: 900; box-shadow: var(--pop-sm);
}
.hero-stats b { font-size: 18px; color: var(--pink-deep); }
.home-note { margin-top: -6px; }

.install-body { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.install-icon { width: 56px; height: 56px; border-radius: 14px; border: 2px solid var(--ink); box-shadow: var(--pop-sm); }
.install-text { flex: 1; min-width: 150px; display: flex; flex-direction: column; gap: 4px; }
.install-text strong { font-size: 15px; font-weight: 900; }
.install-text span { font-size: 12px; color: var(--ink-soft); }
.install-actions { display: flex; gap: 8px; width: 100%; }
.install-actions .btn { flex: 1; }

/* 教學 */
.guide-head { display: flex; align-items: center; gap: 14px; }
.guide-head h2 { margin: 0; font-size: 24px; font-weight: 900; }
.guide-head .px { margin: 2px 0 0; font-size: 10px; color: var(--ink-soft); }
.guide-warn {
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px;
  border: var(--line); border-radius: 14px; background: var(--yellow); box-shadow: var(--pop-sm);
  font-size: 13px; line-height: 1.6;
}
.guide-warn[hidden] { display: none; }
.guide-seg { align-self: stretch; }
.guide-seg button { flex: 1; padding: 10px 0; font-size: 15px; }
.guide-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.guide-steps[hidden] { display: none; }
.guide-steps li {
  display: flex; align-items: center; gap: 14px; padding: 16px;
  border: var(--line); border-radius: 16px; background: var(--paper); box-shadow: var(--pop);
  animation: boot 0.35s steps(5) both;
}
.guide-steps li:nth-child(2) { animation-delay: 0.08s; }
.guide-steps li:nth-child(3) { animation-delay: 0.16s; }
.guide-steps li:nth-child(4) { animation-delay: 0.24s; }
.g-num {
  align-self: flex-start; flex: none; padding: 3px 6px; border-radius: 6px;
  background: var(--pink); color: #fff; border: 2px solid var(--ink); font-size: 10px;
}
.g-icon {
  flex: none; width: 48px; height: 48px; display: grid; place-items: center;
  border: 2px solid var(--ink); border-radius: 12px; background: var(--sky);
}
.g-icon svg { width: 26px; height: 26px; }
.g-icon.g-app { background: none; border: 0; }
.g-icon.g-app img { width: 48px; height: 48px; border-radius: 12px; border: 2px solid var(--ink); }
.guide-steps li div { display: flex; flex-direction: column; gap: 4px; }
.guide-steps b { font-size: 15px; font-weight: 900; }
.guide-steps li div span { font-size: 12px; color: var(--ink-soft); line-height: 1.5; }

.mini-warn {
  margin: 0; width: 100%; padding: 10px 12px; border: 2px solid var(--ink); border-radius: 12px;
  background: var(--yellow); font-size: 12px; font-weight: 700; line-height: 1.6;
}
.mini-warn[hidden] { display: none; }
