/* Editor chrome. The slide itself is styled by template/cai-slides.css. */
:root {
  --ui-bg: #F4F5F7;
  --ui-panel: #FFFFFF;
  --ui-line: #DDE1E6;
  --ui-text: #1F2A30;
  --ui-muted: #6B777C;
  --ui-accent: #2BA0B0;
  --ui-primary: #004191;
  --ui-hover: #EAF1F7;
}
[hidden] { display: none !important; }
html, body.ed {
  background: var(--ui-bg);
  overflow: hidden;
  color: var(--ui-text);
  font: 14px/1.4 "Fira Sans", "Helvetica Neue", Arial, sans-serif;
}
body.ed { display: flex; flex-direction: column; height: 100vh; }
.ed button { font: inherit; color: inherit; }
.ed input, .ed select, .ed textarea { font: inherit; color: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  flex: none; height: 52px;
  display: flex; align-items: center; gap: 6px;
  padding: 0 12px;
  background: var(--ui-panel);
  border-bottom: 1px solid var(--ui-line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-right: 6px; }
.brand img { height: 26px; }
.tgroup { display: flex; align-items: center; gap: 2px; }
.sep { width: 1px; height: 24px; background: var(--ui-line); margin: 0 6px; }
.spacer { flex: 1; }
.tb {
  height: 32px; padding: 0 10px;
  border: 1px solid transparent; border-radius: 6px;
  background: transparent; cursor: pointer; white-space: nowrap;
}
.tb:hover:not(:disabled) { background: var(--ui-hover); }
.tb:disabled { opacity: .35; cursor: default; }
.tb.ic { min-width: 32px; padding: 0 6px; }
.tb.small { height: 26px; padding: 0 8px; font-size: 13px; }
.tb.primary { background: var(--ui-primary); color: #fff; }
.tb.primary:hover { background: #00346f; }
#deckSel { height: 32px; border: 1px solid var(--ui-line); border-radius: 6px; padding: 0 6px; background: #fff; max-width: 160px; }
.fmt.disabled { opacity: .35; pointer-events: none; }
.status { color: var(--ui-muted); font-size: 13px; margin-right: 6px; white-space: nowrap; }
.status.err { color: #C0392B; }
.mode-badge {
  font-size: 12px; color: #8a5a00; background: #fff4d6; border: 1px solid #f0d58c;
  border-radius: 10px; padding: 2px 8px; margin-right: 6px; cursor: help; white-space: nowrap;
}
.tb.lang { border-color: var(--ui-line); font-size: 13px; }

/* Colour picker (text panel) */
.colorpick { margin: 4px 0 8px; }
.colorpick .row { margin-bottom: 6px; }
.colorpick .row > label:first-child { width: auto; }
.colorpick .row:first-child { justify-content: space-between; }
.colorpick .seg button { padding: 2px 10px; font-size: 13px; }
.cp-swatches { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.cp-swatches .sw { width: 100%; aspect-ratio: 1; padding: 0; border: 0; border-radius: 4px; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
.cp-swatches .sw:hover { transform: scale(1.12); }
.sv { position: relative; height: 120px; margin-top: 8px; border-radius: 6px; cursor: crosshair; touch-action: none; }
.sv::before, .sv::after { content: ""; position: absolute; inset: 0; border-radius: 6px; }
.sv::before { background: linear-gradient(to right, #fff, rgba(255,255,255,0)); }
.sv::after { background: linear-gradient(to top, #000, rgba(0,0,0,0)); }
.sv-knob, .hue-knob {
  position: absolute; z-index: 1; width: 12px; height: 12px;
  border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.45);
  transform: translate(-50%, -50%); pointer-events: none;
}
.hue {
  position: relative; height: 12px; margin-top: 10px; border-radius: 6px; cursor: pointer; touch-action: none;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}
.hue-knob { top: 50%; }
.cp-row { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.cp-preview { flex: none; width: 28px; height: 28px; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
.cp-row .hex {
  flex: 1; min-width: 0; height: 28px; padding: 0 8px;
  border: 1px solid var(--ui-line); border-radius: 6px;
  font-family: "Fira Mono", monospace; font-size: 13px; text-transform: uppercase;
}

/* Menus */
.menu { position: relative; }
.menu-pop {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 50;
  min-width: 190px; padding: 4px;
  background: #fff; border: 1px solid var(--ui-line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.menu-pop.right { left: auto; right: 0; }
.menu.open .menu-pop { display: block; }
.menu-pop button {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px; border: 0; border-radius: 5px; background: none; cursor: pointer; white-space: nowrap;
}
.menu-pop button:hover { background: var(--ui-hover); }
.menu-pop .check { display: inline-block; width: 18px; color: var(--ui-accent); }
.menu-pop .on .check::before { content: "✓"; }

/* ---------- Layout ---------- */
.main { flex: 1; min-height: 0; display: flex; }
.sidebar {
  flex: none; width: 228px;
  display: flex; flex-direction: column;
  background: var(--ui-panel); border-right: 1px solid var(--ui-line);
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 10px 8px 14px; font-weight: 600;
}
.thumbs { flex: 1; overflow-y: auto; padding: 4px 10px 20px; }
.thumb {
  position: relative; display: flex; gap: 6px; align-items: flex-start;
  padding: 6px 4px; border-radius: 8px; cursor: pointer;
}
.thumb:hover { background: var(--ui-hover); }
.thumb .tnum { width: 18px; text-align: right; font-size: 12px; color: var(--ui-muted); padding-top: 2px; }
.thumb .tbox {
  position: relative; width: 176px; height: 99px; overflow: hidden;
  border-radius: 4px; box-shadow: 0 0 0 1px var(--ui-line); background: #fff;
}
.thumb.current .tbox { box-shadow: 0 0 0 3px var(--ui-accent); }
.thumb .tscale { position: absolute; left: 0; top: 0; width: 1600px; height: 900px; transform: scale(.11); transform-origin: 0 0; pointer-events: none; }
.thumb .badge {
  position: absolute; left: 30px; bottom: 10px; z-index: 2;
  font-size: 10px; padding: 1px 5px; border-radius: 3px;
  background: rgba(0,65,145,.85); color: #fff;
}
.thumb .badge.app { background: rgba(107,119,124,.9); }
.thumb .tacts { position: absolute; right: 10px; top: 10px; z-index: 3; display: none; gap: 3px; }
.thumb:hover .tacts { display: flex; }
.thumb .tacts button {
  width: 22px; height: 22px; border: 0; border-radius: 4px; padding: 0;
  background: rgba(255,255,255,.95); box-shadow: 0 1px 3px rgba(0,0,0,.25); cursor: pointer; font-size: 12px;
}
.thumb.drop-before::before, .thumb.drop-after::after {
  content: ""; position: absolute; left: 28px; right: 4px; height: 3px; background: var(--ui-accent); border-radius: 2px;
}
.thumb.drop-before::before { top: -2px; }
.thumb.drop-after::after { bottom: -2px; }
.thumb .video-ph { width: 100%; height: 100%; background: #222; }

/* ---------- Canvas ---------- */
.canvas-area { position: relative; flex: 1; min-width: 0; overflow: hidden; background: #E3E6EA; }
.stage {
  position: absolute; width: 1600px; height: 900px;
  transform-origin: 0 0;
  box-shadow: 0 2px 16px rgba(0,0,0,.18);
  --inv: 1;
}
.stage .slide { display: flex; }
.stage .fragment, .thumb .fragment { visibility: visible; }
.stage .el { cursor: move; }
.stage .el:hover:not(.selected) { outline: calc(1.5px * var(--inv)) dashed rgba(43,160,176,.8); }
.stage .el.selected { outline: calc(2px * var(--inv)) solid var(--ui-accent); }
.stage .el.editing { cursor: text; outline-style: dashed; }
.stage .el-inner[contenteditable="true"] { outline: none; cursor: text; min-height: 1em; }
.stage .el-video video { pointer-events: none; }
.stage .el-image img { pointer-events: none; user-select: none; -webkit-user-drag: none; }
.stage .el.fragment::after {
  content: "逐步"; position: absolute; right: 0; top: 0;
  transform: translateY(-100%);
  font: calc(12px * var(--inv)) "Fira Sans", sans-serif; color: #fff;
  background: var(--ui-accent); padding: 0 calc(4px * var(--inv));
}
.stage [data-field] { outline: none; cursor: text; border-radius: 2px; }
.stage [data-field]:hover { box-shadow: 0 0 0 calc(1.5px * var(--inv)) rgba(43,160,176,.6); }
.stage [data-field]:focus { box-shadow: 0 0 0 calc(2px * var(--inv)) var(--ui-accent); }
.stage [data-field]:empty::before { content: "（空）"; color: #B5BDC0; }
/* canvas labels follow the UI language (i18n.js sets <html lang>) */
html[lang="en"] .stage .el.fragment::after { content: "Step"; }
html[lang="en"] .stage [data-field]:empty::before { content: "(empty)"; }
.stage .frametitle [data-field]:focus { box-shadow: 0 0 0 calc(2px * var(--inv)) #fff; }

.handle {
  position: absolute; z-index: 5;
  width: calc(12px * var(--inv)); height: calc(12px * var(--inv));
  background: #fff; border: calc(2px * var(--inv)) solid var(--ui-accent); border-radius: 2px;
  transform: translate(-50%, -50%);
}
.el.editing .handle { display: none; }
.handle.nw { left: 0; top: 0; cursor: nwse-resize; }
.handle.n  { left: 50%; top: 0; cursor: ns-resize; }
.handle.ne { left: 100%; top: 0; cursor: nesw-resize; }
.handle.e  { left: 100%; top: 50%; cursor: ew-resize; }
.handle.se { left: 100%; top: 100%; cursor: nwse-resize; }
.handle.s  { left: 50%; top: 100%; cursor: ns-resize; }
.handle.sw { left: 0; top: 100%; cursor: nesw-resize; }
.handle.w  { left: 0; top: 50%; cursor: ew-resize; }

.guide { position: absolute; z-index: 20; background: #E8417A; pointer-events: none; }
.guide.v { top: 0; bottom: 0; width: calc(1px * var(--inv)); }
.guide.h { left: 0; right: 0; height: calc(1px * var(--inv)); }

.canvas-note {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  background: rgba(31,42,48,.85); color: #fff; font-size: 12px;
  padding: 4px 10px; border-radius: 12px; white-space: nowrap;
  pointer-events: none;
}
.canvas-note:empty { display: none; }
.drop-hint {
  display: none; position: absolute; inset: 12px;
  border: 3px dashed var(--ui-accent); border-radius: 12px;
  background: rgba(43,160,176,.08);
  align-items: center; justify-content: center;
  font-size: 18px; color: var(--ui-primary); pointer-events: none;
}
.canvas-area.dragging .drop-hint { display: flex; }

/* ---------- Right panel ---------- */
.panel {
  flex: none; width: 272px; overflow-y: auto;
  background: var(--ui-panel); border-left: 1px solid var(--ui-line);
  padding-bottom: 30px;
}
.pg { padding: 14px 14px 12px; border-bottom: 1px solid var(--ui-line); }
.pt {
  font-weight: 600; margin: -4px -6px 6px; padding: 4px 6px; border-radius: 6px;
  display: flex; justify-content: space-between; align-items: baseline;
  cursor: pointer; user-select: none;
}
.pt:hover { background: var(--ui-hover); }
.pt small { font-weight: 400; color: var(--ui-muted); }
.pt-title { display: inline-flex; align-items: center; gap: 6px; }
.chev {
  width: 7px; height: 7px; margin: 0 2px 2px 1px;
  border-right: 1.5px solid var(--ui-muted); border-bottom: 1.5px solid var(--ui-muted);
  transform: rotate(45deg); transition: transform .15s;
}
.pg.folded .chev { transform: rotate(-45deg); margin-bottom: 0; }
.pg.folded .pbody { display: none; }
.pg.folded { padding-bottom: 10px; }
.pg.folded .pt { margin-bottom: -4px; }
.row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.row > label:first-child { width: 64px; flex: none; color: var(--ui-muted); font-size: 13px; }
.row input[type=text], .row input[type=number], .row select {
  flex: 1; min-width: 0; height: 30px; padding: 0 8px;
  border: 1px solid var(--ui-line); border-radius: 6px; background: #fff;
}
.grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; }
.grid4 label { display: flex; align-items: center; gap: 6px; color: var(--ui-muted); font-size: 12px; }
.grid4 input { width: 100%; height: 28px; padding: 0 6px; border: 1px solid var(--ui-line); border-radius: 6px; }
.seg { display: inline-flex; border: 1px solid var(--ui-line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 4px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--ui-line); }
.seg button.on { background: var(--ui-primary); color: #fff; }
.chk { display: flex; align-items: center; gap: 8px; margin: 8px 0; cursor: pointer; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pbtn {
  height: 28px; padding: 0 10px; border: 1px solid var(--ui-line); border-radius: 6px;
  background: #fff; cursor: pointer; font-size: 13px;
}
.pbtn:hover { background: var(--ui-hover); }
.pbtn.danger { color: #C0392B; }
.pbtn.danger:hover { background: #fdecea; border-color: #e6a39b; }
/* sub-section inside a panel group (e.g. element layer order) */
.psub { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--ui-line); }
.psub .chk { margin: 0; }
.psub-title { font-size: 12px; font-weight: 600; color: var(--ui-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.order-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.order-btns .pbtn { width: 100%; }
.hint { color: var(--ui-muted); font-size: 12px; line-height: 1.5; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12px; color: var(--ui-muted); }
.keys kbd { font-family: "Fira Mono", monospace; font-size: 11px; color: var(--ui-text); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #1F2A30; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; max-width: 70vw; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
