/* theme: data-theme = dark | light, data-accent = orange | blue (set on <html>).
   The UI is warm neutrals only (from the ScatterAI beige + ink) so the colourful
   characters are the loudest thing on screen; one soft orange marks what is on. */
:root {
  --bg: #151413; --panel: #1d1c1a; --panel-2: #282623; --line: #393632;
  --text: #f4efe6; --muted: #a8a196; --stage-bg: #0e0d0c;
  --accent: #f2874f; --accent-ink: #2a1206; --accent-soft: #f2874f2e;
  --danger: #e5484d;
}
:root[data-theme="light"] {
  --bg: #f4edde; --panel: #fbf8f2; --panel-2: #efe7d8; --line: #e2d8c6;
  --text: #161616; --muted: #6e665a; --stage-bg: #e8dfcd;
}
:root[data-accent="navy"] { --accent: #6aa6b9; --accent-ink: #0b1d24; --accent-soft: #6aa6b92b; }
:root[data-theme="light"][data-accent="navy"] { --accent: #1f4e5f; --accent-ink: #ffffff; --accent-soft: #1f4e5f22; }
/* the four MBTI group colours, same as each type's cards (js/characters.js mbtiColor) */
:root[data-accent="nt"] { --accent: #8b6bb8; --accent-ink: #ffffff; --accent-soft: #8b6bb82e; }
:root[data-accent="nf"] { --accent: #3fa37a; --accent-ink: #062217; --accent-soft: #3fa37a2e; }
:root[data-accent="sj"] { --accent: #3f8fc4; --accent-ink: #08192a; --accent-soft: #3f8fc42e; }
:root[data-accent="sp"] { --accent: #e0aa3e; --accent-ink: #2a1c03; --accent-soft: #e0aa3e33; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
#app { display: grid; grid-template-columns: 260px 1fr 260px; height: 100vh; }

.panel { background: var(--panel); border-right: 1px solid var(--line); padding: 14px; overflow-y: auto; }
#right { border-right: 0; border-left: 1px solid var(--line); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 12px; color: var(--muted); font-weight: 600; margin: 16px 0 8px; letter-spacing: .04em; }
.tip { color: var(--muted); font-size: 12px; margin: 10px 0; }
#toolbar, #scenebar, #editbar, .card, .motions, .vslots { user-select: none; }
.tip code { background: var(--panel-2); border-radius: 4px; padding: 0 4px; color: var(--text); }
.check { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 10px; cursor: pointer; }

.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-outline { color: var(--danger); }
.btn.color { display: inline-flex; align-items: center; gap: 6px; }
.btn.color input { width: 22px; height: 18px; border: 0; padding: 0; background: none; cursor: pointer; }

#palette { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 10px; }
.card { text-align: center; position: relative; }
.card .name { font-weight: 700; font-size: 12px; margin: 4px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .name small { color: var(--muted); font-weight: 500; margin-left: 3px; }
.card .acts { display: flex; gap: 4px; justify-content: center; margin-top: 2px; }
.card .acts button { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: transparent; color: var(--muted); border: 1px solid var(--line); cursor: pointer; }
.card .acts button:hover { color: var(--text); border-color: var(--accent); }
/* up to 4 looks as one square of 2x2 */
.quad { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 4px; aspect-ratio: 1; }
.quad.solo { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.quad .vslot { width: 100%; height: 100%; aspect-ratio: auto; min-height: 0; }
/* each type's card wears its own group colour (--tc, set per card) */
.card .vslot:hover { background: var(--tc-soft, var(--accent-soft)); }
.card .vslot.add { border-color: var(--tc, var(--accent)); background: var(--tc-soft, var(--accent-soft)); color: var(--tc, var(--accent)); }
.card .name b { color: var(--tc, inherit); }

#center { display: flex; flex-direction: column; min-width: 0; }
#toolbar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; background: var(--panel); }
#toolbar .label { color: var(--muted); font-size: 12px; }
#toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
#bgPresets { display: flex; gap: 4px; }
.swatch { width: 26px; height: 26px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.on { border-color: var(--accent); }
#status { color: var(--accent); font-size: 12px; margin-left: 6px; }
.theme { display: inline-flex; align-items: center; gap: 4px; }
.dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.dot.on { border-color: var(--text); }

#scenebar, #editbar { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; background: var(--panel); }
#scenebar .label { color: var(--muted); font-size: 12px; }
#sceneTabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; cursor: pointer; font: inherit; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.tab .bgdot { width: 12px; height: 12px; border-radius: 3px; border: 1px solid #fff3; }
.tab .n { opacity: .7; }
.tab.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
#editbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
#selCount { color: var(--muted); font-size: 12px; margin-left: 4px; }
.btn:disabled { opacity: .4; cursor: default; border-color: var(--line); }

.item.picked { outline: calc(2px * var(--inv, 1)) dashed var(--accent); outline-offset: calc(2px * var(--inv, 1)); }
/* tools: pen / eraser draw on #ink, one layer per scene, above characters */
.tools { display: inline-flex; gap: 4px; }
.tool.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
#penOpts { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#penOpts[hidden] { display: none; }
#penColors { display: inline-flex; gap: 3px; }
.pc { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; padding: 0; }
.pc.on { border-color: var(--text); }
#penOpts input[type=range] { width: 90px; accent-color: var(--accent); }
#ink { position: absolute; left: 0; top: 0; width: 1920px; height: 1080px; pointer-events: none; }
#brushRing { position: absolute; pointer-events: none; border-radius: 50%; transform: translate(-50%, -50%);
  border: calc(1.5px * var(--inv, 1)) solid #fff; box-shadow: 0 0 0 calc(1px * var(--inv, 1)) #000; }
#stage.tool-pen, #stage.tool-pen .item, #stage.tool-eraser, #stage.tool-eraser .item { cursor: none; }
#stage.tool-pen #sel, #stage.tool-eraser #sel { display: none; }
#stage.tool-text, #stage.tool-text .item { cursor: text; }
/* typing straight onto the stage: a see-through box with a caret, styled like the text it makes */
#inlineText { position: absolute; z-index: 5; margin: 0; background: transparent; resize: none; overflow: hidden;
  border: calc(1.5px * var(--inv, 1)) dashed var(--accent); border-radius: calc(4px * var(--inv, 1)); outline: none;
  text-align: center; white-space: pre; box-sizing: border-box; caret-color: var(--accent); paint-order: stroke fill; }
#inlineText[hidden] { display: none; }
#textBox textarea { width: 100%; resize: vertical; background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; font: inherit; }
#textBox select { flex: 1; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px; font: inherit; }
#textBox input[type=color] { width: 34px; height: 24px; border: 1px solid var(--line); border-radius: 6px; padding: 0; background: none; }
#marquee { position: absolute; border: calc(2px * var(--inv, 1)) dashed var(--accent); background: var(--accent-soft); pointer-events: none; }

/* one look: a picture, or "+" to upload. No box behind pictures. */
.vslot { aspect-ratio: 1; border-radius: 10px; border: 2px solid transparent; background: transparent; cursor: pointer; padding: 2px;
  display: flex; align-items: center; justify-content: center; color: var(--accent); font-size: 22px; font-weight: 300;
  position: relative; overflow: hidden; }
.vslot img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.vslot:hover { background: var(--accent-soft); }
.vslot.add { border: 2px dashed var(--accent); background: var(--accent-soft); opacity: .75; }
.vslot.add:hover { opacity: 1; }
.vslot.add .t { display: block; font-size: 10px; font-weight: 600; line-height: 1.2; }
.vslot.add.big { flex-direction: column; font-size: 26px; }
.vslot.on { border-color: var(--accent); background: var(--accent-soft); }
.vslot .x { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; line-height: 16px; font-size: 13px; font-weight: 600;
  background: var(--danger); color: #fff; border-radius: 50%; display: none; }
.vslot:hover .x { display: block; }
.vslots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.vslots .vslot { font-size: 18px; }
.vslots .vslot.num { border: 1px solid var(--line); color: var(--text); font-size: 14px; font-weight: 600; }
.vslots .vslot.num.on { border: 2px solid var(--accent); }

#stageWrap { flex: 1; position: relative; overflow: hidden; background: var(--stage-bg); }
#stage { position: absolute; left: 0; top: 0; width: 1920px; height: 1080px; transform-origin: 0 0; overflow: hidden;
  box-shadow: 0 0 0 1px var(--line); touch-action: none; user-select: none; }
#stage.clear { background: repeating-conic-gradient(#2a2a2a 0 25%, #3a3a3a 0 50%) 0 0 / 40px 40px; }
#bg { position: absolute; inset: 0; }
#items { position: absolute; inset: 0; }
.item { position: absolute; cursor: grab; }
.item:active { cursor: grabbing; }
.item canvas { position: absolute; pointer-events: none; }

#sel { position: absolute; pointer-events: none; outline: calc(2px * var(--inv, 1)) dashed var(--accent); }
#sel .h { position: absolute; width: calc(14px * var(--inv, 1)); height: calc(14px * var(--inv, 1));
  background: #fff; border: calc(2px * var(--inv, 1)) solid var(--accent); border-radius: 3px; pointer-events: auto;
  transform: translate(-50%, -50%); }
#sel .h[data-h="nw"] { left: 0; top: 0; cursor: nwse-resize; }
#sel .h[data-h="n"]  { left: 50%; top: 0; cursor: ns-resize; }
#sel .h[data-h="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
#sel .h[data-h="e"]  { left: 100%; top: 50%; cursor: ew-resize; }
#sel .h[data-h="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
#sel .h[data-h="s"]  { left: 50%; top: 100%; cursor: ns-resize; }
#sel .h[data-h="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
#sel .h[data-h="w"]  { left: 0; top: 50%; cursor: ew-resize; }
/* a bigger invisible grab area around each handle */
#sel .h::after { content: ''; position: absolute; inset: calc(-9px * var(--inv, 1)); }
/* ghost: frame invisible but still grabbable; the cursor shows what each spot does */
#sel.ghost { outline-color: transparent; }
#sel.ghost .h, #sel.ghost .rot-stem { opacity: 0; }
#stage.dragging .item.picked { outline-color: transparent; }
.item.on { cursor: move; }
#sel .h.rot { left: 50%; top: calc(-36px * var(--inv, 1)); border-radius: 50%; background: var(--accent);
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M19 12a7 7 0 1 1-2.05-4.95' fill='none' stroke='white' stroke-width='4' stroke-linecap='round'/%3E%3Cpath d='M19 12a7 7 0 1 1-2.05-4.95' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3Cpath d='M20 3v6h-6z' fill='black' stroke='white' stroke-width='1'/%3E%3C/svg%3E") 12 12, grab; }
.check.inline { margin: 0; font-size: 12px; }
#sel .rot-stem { position: absolute; left: 50%; top: calc(-36px * var(--inv, 1)); height: calc(36px * var(--inv, 1));
  border-left: calc(2px * var(--inv, 1)) solid var(--accent); }

.motions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.motions button { padding: 8px 0; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); cursor: pointer; font: inherit; }
.motions button:hover { border-color: var(--accent); }
.motions button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.motions button small { color: var(--muted); font-size: 10px; margin-left: 2px; }
.motions button.on small { color: var(--accent-ink); opacity: .6; }

.field { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 12px; color: var(--muted); }
.field input[type=range] { flex: 1; accent-color: var(--accent); }
.field output { width: 36px; text-align: right; color: var(--text); }
.field.num input { width: 70px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font: inherit; }
.row { display: flex; gap: 6px; margin-top: 8px; }
.row .btn { flex: 1; }
.row .field { margin: 0; flex: 1; }
.keys { padding-left: 0; list-style: none; margin: 0; color: var(--muted); font-size: 12px; }
.keys li { margin: 5px 0; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 11px; color: var(--text); }

/* live mode: only the stage, filling the window */
body.live #left, body.live #right, body.live #toolbar, body.live #scenebar, body.live #editbar { display: none; }
body.live .item.picked { outline: none; }
body.live #app { display: block; }
body.live #center { height: 100vh; }
body.live #stage { box-shadow: none; }
body.live #stage.clear { background: transparent; }
body.live.clear-bg, body.live.clear-bg #stageWrap { background: transparent; }
#liveHint { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); background: #000c; color: #fff;
  padding: 8px 14px; border-radius: 999px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .4s; z-index: 10; }
#liveHint.show { opacity: 1; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 60vh auto; height: auto; }
  .panel { border: 0; }
  #center { height: 60vh; }
}
