:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6a66;
  --line: #e3dfd6;
  --accent: #e8590c;
  --accent-ink: #ffffff;
  --btn: #1d1d1b;
  --btn-ink: #ffffff;
  --warn: #9a3412;
  --ok: #166534;
  --chip: #f1eee7;
  --radius: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Leelawadee UI", Roboto, sans-serif;
}
button, select, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--card); flex-wrap: wrap; }
.brand { display: flex; gap: 10px; align-items: center; }
.logo { width: 32px; height: 32px; color: var(--accent); }
h1 { font-size: 18px; margin: 0; }
.sub { margin: 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill { background: var(--chip); border-radius: 999px; padding: 4px 10px; font-size: 13px; }
select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--card); }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.center { text-align: center; }

.btn, .ghost, .chip, .tab, .seg button {
  border-radius: 10px; padding: 9px 14px; cursor: pointer; border: 1px solid transparent; min-height: 40px;
}
.btn { background: var(--btn); color: var(--btn-ink); display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.btn:disabled, .chip:disabled, .ghost:disabled { opacity: .45; cursor: not-allowed; }
.ghost { background: transparent; border-color: var(--line); }
.ghost.danger { color: #b91c1c; }
.chip { background: var(--chip); border-color: var(--chip); text-align: left; display: inline-flex; align-items: center; }
.chip.on, .tab.on, .seg button.on { border-color: var(--ink); background: var(--card); font-weight: 600; }
.chip.ex { font-size: 13px; }

.drop { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 40px 16px; border: 2px dashed var(--line); border-radius: var(--radius); cursor: pointer; text-align: center; color: var(--muted); }
.drop strong { color: var(--ink); font-size: 18px; }
.drop svg { width: 40px; height: 40px; color: var(--accent); }
.drop.over { border-color: var(--accent); background: #fff7f0; }

#editor { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.stage-col, .panel { min-width: 0; }
@media (min-width: 960px) { #editor { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; } .panel { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; } }

.tabs { display: flex; gap: 6px; margin-bottom: 8px; overflow-x: auto; }
.tab { background: var(--card); border-color: var(--line); white-space: nowrap; }
.stage { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; min-height: 240px; touch-action: none; }
.checker { background-color: #fff; background-image: linear-gradient(45deg, #e9e6df 25%, transparent 25%), linear-gradient(-45deg, #e9e6df 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e9e6df 75%), linear-gradient(-45deg, transparent 75%, #e9e6df 75%); background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0; }
#view, #maskview { display: block; max-width: 100%; max-height: 72vh; height: auto; }
#view.grab { cursor: grab; }
#maskview { cursor: crosshair; }
.compare { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.compare canvas { max-width: 100%; max-height: 72vh; }
.compare input { position: absolute; left: 0; right: 0; bottom: 12px; width: calc(100% - 32px); margin: 0 16px; pointer-events: auto; }
.tag { position: absolute; top: 8px; background: rgba(29,29,27,.75); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 6px; }
.tag.l { left: 8px; } .tag.r { right: 8px; }
.note { color: var(--muted); font-size: 12px; margin: 6px 0; }

.status { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); margin: 8px 0; flex-wrap: wrap; }
.status.error { border-color: #fca5a5; background: #fef2f2; color: #7f1d1d; }
.status.ok { border-color: #bbf7d0; background: #f0fdf4; color: var(--ok); }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel h3, .history h3 { font-size: 14px; margin: 18px 0 8px; text-transform: none; }
.row { display: flex; gap: 8px; margin: 6px 0; }
.wrap { flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }
.hint.warn { color: var(--warn); }
.hint.ok { color: var(--ok); }
textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px; resize: vertical; background: #fffdf9; }
.slider { display: grid; grid-template-columns: 90px 1fr; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.inline { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 2px; gap: 2px; }
.seg button { background: transparent; min-height: 36px; padding: 6px 10px; }
.mode { display: flex; width: 100%; } .mode button { flex: 1; }
.swatches button { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; padding: 0; }
.swatches button.on { border-color: var(--ink); }
.swatches input[type=color] { width: 40px; height: 34px; border: none; background: none; padding: 0; }
.examples summary { cursor: pointer; color: var(--muted); font-size: 13px; margin: 6px 0; }

.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.strip .item { flex: 0 0 auto; width: 96px; text-align: center; font-size: 11px; color: var(--muted); }
.strip .item img { width: 96px; height: 96px; object-fit: contain; border-radius: 8px; border: 2px solid var(--line); background: #fff; cursor: pointer; display: block; }
.strip .item.on img { border-color: var(--accent); }
.strip.small .item, .strip.small .item img { width: 64px; height: 64px; }
.strip .item button { font-size: 11px; padding: 2px 6px; min-height: 0; margin-top: 2px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.grid .proj { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; background: #fff; }
.grid .proj img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.grid .proj span { display: block; padding: 6px 8px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.lib { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 6px 0; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; max-height: 320px; overflow: auto; }
.lib-grid button { padding: 0; border: 2px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; overflow: hidden; text-align: center; font-size: 11px; color: var(--muted); }
.lib-grid button.on { border-color: var(--accent); }
.lib-grid img { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; display: block; }
.lib-grid span { display: block; padding: 3px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#lib-cat { min-height: 40px; }

/* Panel: numbered, clearly separated blocks */
.panel { background: transparent; border: 0; padding: 0; }
.blk { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.blk-h { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.blk-h h3 { margin: 0 !important; font-size: 15px; }
.num { flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.blk-sub { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 14px 0 6px; }
.btn.wide { width: 100%; }
.needs-cut.off { opacity: .4; pointer-events: none; filter: grayscale(1); }
.ghost.small { font-size: 13px; min-height: 32px; padding: 4px 10px; border: 0; }
#view.grab { cursor: grab; }
#view.grab:active { cursor: grabbing; }
#mode-box { margin-bottom: 12px; }
.angles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ang { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; border: 2px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font-size: 11px; color: var(--ink); line-height: 1.2; }
.ang svg { width: 40px; height: 40px; color: var(--ink); }
.ang.on { border-color: var(--accent); background: #fff7f0; }
.angles.ask .ang { border-color: var(--accent); }
.lib-sep { grid-column: 1 / -1; font-size: 12px; font-weight: 600; color: var(--muted); margin: 8px 0 2px; }
.lib-grid button.other { opacity: .55; }

/* ===== Step-by-step studio (SnapSellGo look) ===================================== */
:root { --bg: #f7f5f1; --line: #eceae5; --accent: #ea7318; --accent2: #c2570a; --accent-soft: #fdebd9; --ink: #1a1a1a; --muted: #9b9690; --sage: #5f8a6a; }
body.framed { background: transparent; }
body.framed .top { background: transparent; border: 0; padding: 4px 16px 0; }
body.framed .brand { visibility: hidden; }
body.framed main { padding-top: 6px; }
h1, .step-h h2 { font-family: Fraunces, Georgia, "Times New Roman", serif; }

.steps { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 10px 10px; margin-bottom: 16px; overflow-x: auto; }
.stp-b { flex: 1 1 0; min-width: 76px; display: flex; flex-direction: column; align-items: center; gap: 6px; background: none; border: 0; cursor: pointer; position: relative; padding: 0 4px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.stp-b:not(:last-child)::after { content: ""; position: absolute; top: 17px; left: calc(50% + 22px); right: calc(-50% + 22px); height: 2px; background: var(--line); }
.stp-b.done:not(:last-child)::after { background: var(--accent); }
.stp-b .n { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); background: #fff; display: grid; place-items: center; font-size: 14px; color: var(--muted); }
.stp-b.cur { color: var(--accent); }
.stp-b.cur .n { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 0 0 4px var(--accent-soft); }
.stp-b.done .n { border-color: var(--accent); color: var(--accent); }
.stp-b.done { color: var(--ink); }
.stp-b:disabled { cursor: not-allowed; opacity: .55; }

.step { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.step-h { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.step-ico { flex: 0 0 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent2); display: grid; place-items: center; }
.step-ico svg { width: 22px; height: 22px; }
.step-h h2 { margin: 0 0 2px; font-size: 20px; font-weight: 600; }
.step-h p { margin: 0; color: var(--muted); font-size: 13px; }
.step-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.btn.next, .magic-btn, .btn.accent { background: var(--accent); color: #fff; }
.btn.next:hover, .magic-btn:hover, .btn.accent:hover { background: var(--accent2); }
.btn.next { min-width: 140px; font-weight: 600; }
.magic-btn { display: flex; gap: 10px; align-items: center; justify-content: center; font-weight: 600; font-size: 16px; min-height: 52px; }
.magic-btn svg { width: 22px; height: 22px; }
.drop { border-color: #f3c9a8; background: #fffaf5; }
.drop svg { color: var(--accent); }
.grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.grid .proj.on { outline: 3px solid var(--accent); }

.stage-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--muted); font-size: 14px; background: #fff; }
.stage-empty svg { width: 56px; height: 56px; color: #e2d8cc; }
.stage { min-height: 360px; }

/* Magic wand while the background is removed */
.magic { position: absolute; inset: 0; overflow: hidden; background: rgba(255, 255, 255, .35); pointer-events: none; }
.magic .sweep { position: absolute; top: 0; bottom: 0; width: 45%; background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .85), rgba(255, 214, 170, .7), transparent); animation: sweep 1.8s ease-in-out infinite; }
.magic .wand { position: absolute; width: 74px; height: 74px; animation: wand 2.4s ease-in-out infinite; filter: drop-shadow(0 4px 8px rgba(0,0,0,.25)); }
.magic .spark { position: absolute; width: 10px; height: 10px; background: #f8c24a; clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); animation: spark 1.6s ease-in-out infinite; }
.magic .s1 { top: 22%; left: 30%; } .magic .s2 { top: 40%; left: 70%; animation-delay: .3s; } .magic .s3 { top: 66%; left: 42%; animation-delay: .6s; }
.magic .s4 { top: 30%; left: 55%; animation-delay: .9s; background: #fff; } .magic .s5 { top: 75%; left: 75%; animation-delay: 1.2s; }
.magic-txt { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); background: rgba(26, 26, 26, .82); color: #fff; padding: 10px 16px; border-radius: 12px; text-align: center; font-size: 13px; display: flex; flex-direction: column; gap: 2px; white-space: nowrap; }
@keyframes sweep { from { left: -50%; } to { left: 110%; } }
@keyframes wand { 0% { left: 12%; top: 18%; transform: rotate(-12deg); } 25% { left: 64%; top: 30%; transform: rotate(10deg); } 50% { left: 40%; top: 58%; transform: rotate(-6deg); } 75% { left: 70%; top: 62%; transform: rotate(12deg); } 100% { left: 12%; top: 18%; transform: rotate(-12deg); } }
@keyframes spark { 0%, 100% { transform: scale(0); opacity: 0; } 50% { transform: scale(1.4) rotate(45deg); opacity: 1; } }
/* ...then the old background wipes away */
.reveal { pointer-events: none; }
.rv-in { position: relative; display: inline-block; line-height: 0; }
.reveal canvas { animation: wipe 1.3s ease-in-out forwards; }
.reveal .wand-line { position: absolute; top: 0; bottom: 0; width: 4px; background: linear-gradient(#fff, #f8c24a, #fff); box-shadow: 0 0 18px 6px rgba(248, 194, 74, .8); animation: line 1.3s ease-in-out forwards; }
@keyframes wipe { from { clip-path: inset(0 0 0 0); } to { clip-path: inset(0 0 0 100%); } }
@keyframes line { from { left: 0; } to { left: 100%; opacity: .2; } }

/* "You can move it" hint */
.move-hint { position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; animation: nudge 1.4s ease-in-out infinite; }
.move-hint svg { width: 54px; height: 54px; filter: drop-shadow(0 3px 8px rgba(0,0,0,.3)); }
.move-hint span { background: rgba(26, 26, 26, .85); color: #fff; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
@keyframes nudge { 0%, 100% { margin-left: -10px; } 50% { margin-left: 10px; } }
@media (prefers-reduced-motion: reduce) { .magic .sweep, .magic .wand, .magic .spark, .move-hint { animation: none; } }
