/* AF-Ext Studio — design system from ui-ux-pro-max:
   Soft UI Evolution style · creator pink + engagement orange · slate dark base · IBM Plex Sans Thai.
   Semantic tokens only below; components never use raw hex. */
:root {
  --bg: #f7f5fa; --surface: #ffffff; --surface-2: #f1eef5; --surface-3: #e9e4f0;
  --text: #1e1b2e; --muted: #5b5670; --line: #e4dfec; --line-strong: #cfc8dc;
  --primary: #db2777; --on-primary: #ffffff; --primary-soft: #fce7f3;
  --accent: #ea580c; --on-accent: #ffffff;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --err: #dc2626; --err-soft: #fee2e2;
  --run: #db2777; --ring: #db2777;
  --shadow: 0 1px 2px rgb(30 27 46 / .06), 0 6px 18px rgb(30 27 46 / .07);
  --shadow-lg: 0 10px 40px rgb(30 27 46 / .16);
  --radius: 16px; --radius-sm: 10px;
  --ease: cubic-bezier(.2, .7, .2, 1); --fast: 150ms; --base: 220ms;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020; --surface: #141a2b; --surface-2: #1b2337; --surface-3: #232c43;
    --text: #f8fafc; --muted: #a3acc2; --line: #273049; --line-strong: #39445f;
    --primary: #ec4899; --on-primary: #0b1020; --primary-soft: #3a1830;
    --accent: #fb923c; --on-accent: #0b1020;
    --ok: #4ade80; --ok-soft: #12301f; --warn: #fbbf24; --warn-soft: #33270b; --err: #f87171; --err-soft: #3a1418;
    --run: #f472b6; --ring: #f472b6;
    --shadow: 0 1px 2px rgb(0 0 0 / .35), 0 8px 24px rgb(0 0 0 / .25);
    --shadow-lg: 0 12px 48px rgb(0 0 0 / .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.6 "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button, [data-act], summary, .product, .job, label:has(input[type="checkbox"]) { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: 6px; }
.ico { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.ico.lg { width: 22px; height: 22px; }

/* ---------- top bar + navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px; padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; text-decoration: none; letter-spacing: -.01em; }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; }
.brand span { color: var(--primary); }
#nav { display: flex; gap: 4px; flex: 1; }
#nav a { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; text-decoration: none; padding: 6px 14px;
  border-radius: 999px; color: var(--muted); font-weight: 500; transition: background var(--fast) var(--ease), color var(--fast) var(--ease); }
#nav a:hover { background: var(--surface-2); color: var(--text); }
#nav a.active { background: var(--primary-soft); color: var(--primary); }
.agent { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.agent i { width: 8px; height: 8px; border-radius: 50%; background: var(--err); }
.agent.on i { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 22%, transparent); }
@media (max-width: 720px) {
  /* backdrop-filter would make the fixed bottom nav position relative to the top bar */
  .topbar { backdrop-filter: none; background: var(--bg); padding: 10px 16px; }
  #nav { position: fixed; bottom: 0; left: 0; right: 0; justify-content: space-around; gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); box-shadow: var(--shadow-lg); }
  #nav a { flex-direction: column; gap: 2px; min-width: 56px; min-height: 52px; padding: 6px 4px; font-size: 12px; border-radius: 12px; justify-content: center; }
  #nav a.active { background: none; }
  #nav a.active .ico { stroke-width: 2.4; }
  .agent { margin-left: auto; padding: 4px 10px; font-size: 12px; }
}

/* ---------- layout ---------- */
main { max-width: 1160px; margin: 0 auto; padding: 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
@media (max-width: 720px) { main { padding: 14px; gap: 14px; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: grid; gap: 14px; align-content: start; min-width: 0; box-shadow: var(--shadow); }
@media (max-width: 720px) { .card { padding: 16px; } }
.card h2 { margin: 0; font-size: 18px; line-height: 1.4; font-weight: 600; }
.card h3 { margin: 4px 0 0; font-size: 15px; font-weight: 600; }
.step { display: flex; gap: 12px; align-items: center; }
.step b { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--primary); background: var(--primary-soft); padding: 2px 10px; border-radius: 999px; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.cols { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }

/* ---------- forms ---------- */
input, select, textarea { width: 100%; min-height: 44px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px;
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease); }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
textarea { resize: vertical; min-height: 84px; }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--primary); flex: none; }
label.field { display: grid; gap: 6px; font-size: 14px; font-weight: 500; color: var(--text); }
label.field .hint { font-weight: 400; font-size: 13px; }
details > summary { font-weight: 500; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 18px;
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; font-weight: 500; white-space: nowrap; text-decoration: none;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease); }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary, .btn.accent { background: var(--primary); color: var(--on-primary); border-color: transparent; font-weight: 600;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 35%, transparent); }
.btn.primary:hover, .btn.accent:hover { background: color-mix(in srgb, var(--primary) 88%, #000); }
.btn.small { min-height: 36px; padding: 4px 14px; font-size: 14px; }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.link { display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; padding: 4px 0; color: var(--muted); text-decoration: none; font-size: 14px; }
.link:hover { color: var(--text); text-decoration: underline; }
@media (max-width: 720px) { .btn { white-space: normal; } .btn.small { min-height: 44px; } }

/* ---------- choice controls ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px;
  padding: 6px 16px; font-size: 14px; transition: all var(--fast) var(--ease); }
.chip:hover { border-color: var(--line-strong); }
.chip.on, .style.on, .swatch.on { background: var(--primary-soft); border-color: var(--primary); color: var(--text); font-weight: 600; }
.chip.on::before { content: "✓"; color: var(--primary); font-weight: 700; }
/* user-added chip: label button + remove button inside one pill */
.chip.custom { padding: 0 4px 0 0; gap: 0; border-style: dashed; }
.chip.custom.on { border-style: solid; padding-left: 12px; }
.chip.custom > button { background: none; border: 0; min-height: 38px; padding: 6px 6px 6px 16px; font: inherit; color: inherit; }
.chip.custom.on > button:first-child { padding-left: 4px; }
.chip.custom .x { display: grid; place-items: center; width: 30px; height: 30px; min-height: 0; padding: 0; border-radius: 50%; color: var(--muted); }
.chip.custom .x:hover { background: var(--err-soft); color: var(--err); }
.chip.custom .x .ico { width: 14px; height: 14px; }
.add-chip { max-width: 560px; }
/* user-added tone: swatch with its own select + remove buttons */
.swatch.custom { position: relative; padding: 0; border-style: dashed; }
.swatch.custom.on { border-style: solid; }
.swatch.custom > button:first-child { width: 100%; background: none; border: 0; padding: 12px 6px; font: inherit; color: inherit; }
.swatch.custom .x { position: absolute; top: 4px; right: 4px; display: grid; place-items: center; width: 26px; height: 26px; padding: 0; border: 0;
  border-radius: 50%; background: var(--surface); color: var(--muted); }
.swatch.custom .x:hover { background: var(--err-soft); color: var(--err); }
.swatch.custom .x .ico { width: 13px; height: 13px; }
.color-pick { width: 52px; min-height: 40px; height: 40px; padding: 4px; flex: none; cursor: pointer; }
.add-chip input { min-height: 40px; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.swatch { border: 1px solid var(--line); background: var(--surface-2); border-radius: 14px; padding: 12px 6px; text-align: center; font-size: 13px; transition: all var(--fast) var(--ease); }
.swatch i { display: block; width: 36px; height: 36px; border-radius: 50%; margin: 0 auto 8px; border: 1px solid var(--line-strong); box-shadow: inset 0 -3px 6px rgb(0 0 0 / .08); }
.styles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.style { display: flex; flex-direction: column; justify-content: flex-start; gap: 2px; text-align: left; border: 1px solid var(--line); background: var(--surface-2); border-radius: 14px; padding: 12px 14px; transition: all var(--fast) var(--ease); }
.style:hover, .swatch:hover { border-color: var(--line-strong); }
.style b { display: block; font-weight: 600; }
.style span { color: var(--muted); font-size: 13px; line-height: 1.5; }
@media (max-width: 720px) { .styles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); } }
.stepper { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.stepper button { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--surface); font-size: 20px; box-shadow: var(--shadow); }
.stepper b { font-size: 20px; min-width: 36px; text-align: center; }

/* ---------- products ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
@media (max-width: 720px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.product { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: grid; align-content: start;
  transition: transform var(--base) var(--ease), box-shadow var(--base) var(--ease), border-color var(--fast) var(--ease); }
.product:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.product.on { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); }
.product img { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--surface-2); }
.product .body { padding: 10px 12px 12px; display: grid; gap: 4px; }
.product input { position: absolute; top: 10px; left: 10px; width: 22px; height: 22px; }
.name { font-weight: 600; line-height: 1.45; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.price { font-weight: 700; color: var(--primary); }

/* ---------- status ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.error { background: var(--err-soft); color: var(--err); border-color: transparent; }
.badge.storyboard, .badge.needs-manual, .badge.warn, .badge.scheduled { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.running, .badge.generating, .badge.scripting, .badge.composing { background: var(--primary-soft); color: var(--run); border-color: transparent; }
.badge.running::before, .badge.generating::before, .badge.scripting::before, .badge.composing::before { animation: blink 1.2s ease-in-out infinite; }
.err { display: flex; gap: 8px; align-items: flex-start; color: var(--err); background: var(--err-soft); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.warn { color: var(--warn); font-size: 14px; }
.progress { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); }
.spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--run) 30%, transparent); border-top-color: var(--run); animation: spin .8s linear infinite; flex: none; }

/* ---------- sticky selection bar ---------- */
.bar { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 10; display: flex; gap: 10px; align-items: center; padding: 8px 8px 8px 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow-lg); }
@media (min-width: 721px) { .bar { bottom: 16px; } }

/* ---------- jobs list ---------- */
.job { display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; text-decoration: none; padding: 12px; border-radius: 14px;
  transition: background var(--fast) var(--ease); }
.job + .job { border-top: 1px solid var(--line); }
.job:hover { background: var(--surface-2); }
.job img { width: 64px; height: 86px; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.dots { display: flex; gap: 4px; margin-top: 6px; }
.dots i { width: 22px; height: 5px; border-radius: 3px; background: var(--line-strong); }
.dots i.done { background: var(--ok); } .dots i.running { background: var(--run); animation: blink 1.2s ease-in-out infinite; } .dots i.error { background: var(--err); }

/* ---------- scene cards (9:16, like Flow tool cards) ---------- */
.scenes { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); }
@media (max-width: 720px) { .scenes { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.scene { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: grid; gap: 10px; align-content: start; }
.thumb { position: relative; aspect-ratio: 9 / 16; border-radius: 12px; overflow: hidden; background: #000; outline: 2px solid transparent; outline-offset: -2px; }
.thumb > video, .thumb > img { width: 100%; height: 100%; object-fit: cover; display: block; max-height: none; border-radius: 0; }
.thumb img.ghost { opacity: .35; filter: blur(3px) grayscale(.3); }
.thumb.running { outline-color: var(--run); }
.thumb.error { outline-color: var(--err); }
.thumb .tag { position: absolute; top: 8px; left: 8px; background: rgb(0 0 0 / .62); color: #fff; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 8px; backdrop-filter: blur(4px); }
.thumb .state { position: absolute; top: 8px; right: 8px; }
.thumb .state .badge { background: rgb(0 0 0 / .62); color: #fff; backdrop-filter: blur(4px); }
.thumb .state .badge.done { color: #86efac; } .thumb .state .badge.error { color: #fca5a5; } .thumb .state .badge.running { color: #f9a8d4; }
.thumb .ovl { position: absolute; left: 8%; right: 8%; text-align: center; color: #fff; font-weight: 600; font-size: 13px; line-height: 1.4;
  background: rgb(0 0 0 / .42); border-radius: 8px; padding: 4px 8px; pointer-events: none; }
.thumb.running .ovl { display: none; }
/* centred spinner while the scene's image or video is being made (or waiting in the queue) */
.thumb-spin { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; pointer-events: none;
  color: #fff; font-size: 13px; font-weight: 600; text-shadow: 0 1px 4px rgb(0 0 0 / .6); background: rgb(0 0 0 / .28); }
.thumb:has(.thumb-spin) .layers { display: none; }
.spin.lg { width: 46px; height: 46px; border-width: 4px; border-color: rgb(255 255 255 / .25); border-top-color: var(--run); }
.thumb .ovl.top { top: 12%; } .thumb .ovl.center { top: 46%; } .thumb .ovl.bottom { top: 66%; }
.thumb .live { position: absolute; inset: auto 0 0 0; padding: 12px; display: grid; gap: 6px; color: #fff; font-size: 12px; line-height: 1.45;
  background: linear-gradient(transparent, rgb(0 0 0 / .88)); }
.thumb .live .timer { font-size: 20px; font-weight: 700; color: #f9a8d4; font-variant-numeric: tabular-nums; }
.bar-anim { height: 4px; border-radius: 4px; background: linear-gradient(90deg, transparent, var(--run), transparent); background-size: 200% 100%; animation: slide 1.4s linear infinite; }
.scene-actions { display: grid; gap: 6px; }
video, img.preview { width: 100%; max-height: 72vh; border-radius: 14px; background: #000; object-fit: contain; display: block; }
.final { display: grid; gap: 20px; grid-template-columns: minmax(0, 340px) 1fr; align-items: start; }
@media (max-width: 720px) { .final { grid-template-columns: 1fr; } }
.usps { margin: 0; padding-left: 22px; display: grid; gap: 4px; }

/* ---------- pipeline timeline ---------- */
.timeline { display: flex; align-items: flex-start; overflow-x: auto; padding: 8px 2px 4px; scrollbar-width: thin; }
.tl-step { display: grid; justify-items: center; gap: 4px; min-width: 78px; text-align: center; font-size: 12px; color: var(--muted); }
.tl-step i { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--surface); display: grid; place-items: center; font-style: normal; font-weight: 700; font-size: 14px; }
.tl-step b { color: var(--text); font-size: 13px; font-weight: 600; white-space: nowrap; }
.tl-step span { min-height: 1.3em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tl-step.done i { background: var(--ok); border-color: var(--ok); color: #fff; }
.tl-step.done i::after { content: "✓"; }
.tl-step.running i, .tl-step.wait i { border-color: var(--run); box-shadow: 0 0 0 5px color-mix(in srgb, var(--run) 20%, transparent); }
.tl-step.running i::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--run); animation: blink 1.2s ease-in-out infinite; }
.tl-step.wait i { border-color: var(--warn); box-shadow: 0 0 0 5px color-mix(in srgb, var(--warn) 20%, transparent); }
.tl-step.wait i::after { content: "!"; color: var(--warn); }
.tl-step.running span { color: var(--run); font-weight: 600; }
.tl-step.wait span { color: var(--warn); font-weight: 600; }
.tl-step.error i { background: var(--err); border-color: var(--err); color: #fff; }
.tl-step.error i::after { content: "!"; }
.tl-line { flex: 1; min-width: 18px; height: 2px; background: var(--line-strong); margin-top: 15px; border-radius: 2px; }

/* ---------- misc ---------- */
#toast { position: fixed; left: 50%; transform: translate(-50%, 12px); bottom: calc(96px + env(safe-area-inset-bottom)); max-width: min(92vw, 520px); padding: 12px 18px;
  border-radius: 14px; background: var(--text); color: var(--bg); white-space: pre-wrap; opacity: 0; pointer-events: none; z-index: 50; box-shadow: var(--shadow-lg);
  transition: opacity var(--base) var(--ease), transform var(--base) var(--ease); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--err); color: #fff; }
.empty { display: grid; justify-items: center; gap: 10px; color: var(--muted); text-align: center; padding: 36px 0; }
.empty .ico { width: 36px; height: 36px; opacity: .6; }
.login { max-width: 440px; margin: 10vh auto; }
code { background: var(--surface-2); border: 1px solid var(--line); padding: 2px 8px; border-radius: 6px; font-size: 13px; overflow-wrap: anywhere; }

@keyframes slide { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes blink { 50% { opacity: .35; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .product:hover { transform: none; }
}

/* ---------- text layers (shared by scene cards and the editor) ---------- */
@font-face { font-family: 'Mali-Bold'; src: url('/fonts/Mali-Bold.ttf'); font-display: swap; }
@font-face { font-family: 'Mali-SemiBold'; src: url('/fonts/Mali-SemiBold.ttf'); font-display: swap; }
@font-face { font-family: 'Sriracha-Regular'; src: url('/fonts/Sriracha-Regular.ttf'); font-display: swap; }
@font-face { font-family: 'Itim-Regular'; src: url('/fonts/Itim-Regular.ttf'); font-display: swap; }
@font-face { font-family: 'Kodchasan-Bold'; src: url('/fonts/Kodchasan-Bold.ttf'); font-display: swap; }
@font-face { font-family: 'Mitr-SemiBold'; src: url('/fonts/Mitr-SemiBold.ttf'); font-display: swap; }
@font-face { font-family: 'Kanit-Bold'; src: url('/fonts/Kanit-Bold.ttf'); font-display: swap; }
@font-face { font-family: 'Kanit-Medium'; src: url('/fonts/Kanit-Medium.ttf'); font-display: swap; }
@font-face { font-family: 'Prompt-ExtraBold'; src: url('/fonts/Prompt-ExtraBold.ttf'); font-display: swap; }
@font-face { font-family: 'Pattaya-Regular'; src: url('/fonts/Pattaya-Regular.ttf'); font-display: swap; }
@font-face { font-family: 'Charm-Bold'; src: url('/fonts/Charm-Bold.ttf'); font-display: swap; }
@font-face { font-family: 'Chonburi-Regular'; src: url('/fonts/Chonburi-Regular.ttf'); font-display: swap; }

.thumb { container-type: inline-size; }
.thumb .layers { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.thumb.running .layers { display: none; }
.layer { position: absolute; transform: translate(-50%, -50%); font-size: calc(var(--s) * 100cqw); line-height: 1.18; white-space: pre;
  text-align: center; user-select: none; touch-action: none; }
.layer > span, .layer .l-loop { display: inline-block; }
.layer.sh { text-shadow: 0 .05em .09em rgb(0 0 0 / .38); }
.layer.ol { -webkit-text-stroke: .07em rgb(0 0 0 / .85); paint-order: stroke fill; }
.layer.bx > .l-in { background: rgb(0 0 0 / .45); padding: .12em .32em; border-radius: .18em; }

/* entrance + loop motion (only while previewing) — mirrors the ffmpeg expressions */
.playing .l-in { animation-fill-mode: both; animation-timing-function: cubic-bezier(.2, .7, .2, 1); }
.playing .a-fadeUp { animation-name: inFadeUp; } .playing .a-fade { animation-name: inFade; }
.playing .a-pop { animation-name: inPop; animation-timing-function: linear; } .playing .a-zoomIn { animation-name: inZoom; }
.playing .a-slideLeft { animation-name: inSlideL; } .playing .a-slideRight { animation-name: inSlideR; }
.playing .a-drop { animation-name: inDrop; animation-timing-function: linear; }
.playing .a-none { animation-name: inNone; animation-timing-function: steps(1, end); }
.playing .lp-float { animation: loopFloat 2.86s ease-in-out infinite; } .playing .lp-twinkle { animation: loopTwinkle 1.57s ease-in-out infinite; }
.playing .lp-pulse { animation: loopPulse 1.26s ease-in-out infinite; } .playing .lp-sway { animation: loopSway 3.14s ease-in-out infinite; }
@keyframes inFadeUp { from { opacity: 0; transform: translateY(.35em); } to { opacity: 1; transform: none; } }
@keyframes inFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes inPop { 0% { opacity: 0; transform: scale(.05); } 15% { opacity: 1; } 40% { transform: scale(1.22); } 65% { transform: scale(.93); } 85% { transform: scale(1.04); } 100% { transform: scale(1); } }
@keyframes inZoom { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: scale(1); } }
@keyframes inSlideL { from { opacity: 0; transform: translateX(-40cqw); } to { opacity: 1; transform: none; } }
@keyframes inSlideR { from { opacity: 0; transform: translateX(40cqw); } to { opacity: 1; transform: none; } }
@keyframes inDrop { 0% { opacity: 0; transform: translateY(-21cqw); } 20% { opacity: 1; } 55% { transform: translateY(3cqw); } 78% { transform: translateY(-1cqw); } 100% { transform: none; } }
@keyframes inNone { from { opacity: 0; } to { opacity: 1; } }
@keyframes loopFloat { 50% { transform: translateY(-1cqw); } }
@keyframes loopTwinkle { 50% { opacity: .44; } }
@keyframes loopPulse { 50% { transform: scale(1.05); } }
@keyframes loopSway { 50% { transform: translateX(.8cqw); } }

/* ---------- Canva-style editor ---------- */
.ed-backdrop { position: fixed; inset: 0; z-index: 100; background: rgb(0 0 0 / .6); display: grid; place-items: center; padding: 16px; }
.ed { width: min(1100px, 100%); max-height: calc(100vh - 32px); display: grid; grid-template-rows: auto 1fr; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden; }
.ed-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.ed-body { display: grid; grid-template-columns: minmax(0, 380px) 1fr; gap: 20px; padding: 16px; overflow: auto; min-height: 0; }
.ed-stage-wrap { display: grid; gap: 8px; align-content: start; }
.ed-stage { position: relative; aspect-ratio: 9 / 16; border-radius: 14px; overflow: hidden; background: #000; touch-action: none; }
.ed-stage > video, .ed-stage > img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ed-stage .layers { pointer-events: auto; }
.ed-stage .layer { cursor: grab; padding: .05em .1em; border-radius: 6px; outline: 1px dashed transparent; }
.ed-stage .layer:hover { outline-color: rgb(255 255 255 / .5); }
.ed-stage .layer.sel { outline: 2px dashed #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / .4); }
.ed-stage .layer:active { cursor: grabbing; }
.guide-v { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; border-left: 1px dashed var(--primary); opacity: 0; pointer-events: none; z-index: 2; }
.ed-stage.snap-x .guide-v { opacity: 1; }
.ed-panel { display: grid; gap: 12px; align-content: start; min-width: 0; }
.ed-section { margin: 8px 0 0; padding-top: 12px; border-top: 1px solid var(--line); font-size: 15px; }
.field-label { font-size: 14px; font-weight: 500; }
.fonts { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.font-btn { display: grid; gap: 2px; padding: 8px 10px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; font-size: 20px; line-height: 1.2; text-align: left; color: var(--text); }
.font-btn small { font: 12px/1.3 "IBM Plex Sans Thai", sans-serif; color: var(--muted); }
.font-btn.on { border-color: var(--primary); background: var(--primary-soft); }
.stickers { display: flex; flex-wrap: wrap; gap: 6px; }
.stickers button { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font: 22px/1 "Segoe UI Symbol", sans-serif; color: var(--text); }
.stickers button.on { border-color: var(--primary); background: var(--primary-soft); }
.sticker-pick { position: relative; }
.sticker-pick > summary { list-style: none; }
.sticker-pick > summary::-webkit-details-marker { display: none; }
.sticker-pick[open] .stickers { position: absolute; z-index: 5; top: calc(100% + 6px); left: 0; width: 290px; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg); }
.color-dot { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--line-strong); padding: 0; }
.color-dot.on { outline: 2px solid var(--primary); outline-offset: 2px; }
input[type="range"] { min-height: 0; padding: 0; accent-color: var(--primary); background: none; border: 0; }
@media (max-width: 760px) {
  .ed-backdrop { padding: 0; }
  .ed { max-height: 100vh; height: 100vh; border-radius: 0; }
  .ed-body { grid-template-columns: 1fr; padding: 12px; }
  .ed-stage { width: min(100%, calc(52vh * 9 / 16)); margin: 0 auto; }
  .ed-head > b { flex-basis: 100%; }
  .ed-head > .grow { display: none; }
  .ed-head .btn { flex: 1; white-space: nowrap; }
}
.model-pick { align-items: center; }
.model-pick .chip small { font-weight: 400; margin-left: 4px; }

/* Remote target is shared by new-work actions; existing jobs retain their target. */
.target-control { box-shadow: none; }
.target-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.target-control select { width: 100%; min-width: 0; }
.target-control .hint { margin-bottom: 0; overflow-wrap: anywhere; }
.target-control .field { max-width: 640px; }
.badge.cancelled { color: var(--muted); background: var(--surface-2); }
