:root {
  --bg: #f4f3ef; --panel: #fff; --ink: #1a1a1a; --muted: #6b6b6b;
  --line: #e0ded7; --accent: #b5322b; --accent2: #2b5bb5;
  --chat-w: 360px;
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
button {
  font: inherit; cursor: pointer; border: 1px solid var(--line);
  background: #fff; border-radius: 6px; padding: 5px 10px; color: var(--ink);
}
button:hover { background: #f0efea; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: #9c2a24; }
button:disabled { opacity: .5; cursor: default; }
.spacer { flex: 1; }

#app { display: flex; height: 100vh; }

/* ---- chat ---- */
#chat {
  width: var(--chat-w); min-width: 300px; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line);
}
.chat-head { padding: 12px 16px; font-weight: 600; border-bottom: 1px solid var(--line); }
#chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 9px 12px; border-radius: 12px; white-space: normal; }
.msg.user { align-self: flex-end; background: var(--accent2); color: #fff; border-bottom-right-radius: 3px; }
.msg.assistant { align-self: flex-start; background: #f0efea; border-bottom-left-radius: 3px; }
.msg code { background: rgba(0,0,0,.08); padding: 1px 4px; border-radius: 4px; font-size: .9em; }
.chat-input-row { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
#chat-input { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: inherit; }

/* ---- work area ---- */
#work { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#controls-pane {
  background: var(--panel); border-bottom: 1px solid var(--line);
  max-height: 42%; display: flex; flex-direction: column;
}
.pane-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.gen-status { color: var(--muted); font-weight: 400; font-size: 13px; }
.controls-grid {
  padding: 12px 16px; overflow-y: auto;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 18px; align-content: start;
}
.ctrl { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.ctrl.full { grid-column: 1 / -1; }
.ctrl-label { color: var(--muted); font-size: 12px; }
.ctrl input[type=text], .ctrl input[type=number], .ctrl select {
  font: inherit; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; background: #fff; width: 100%;
}
.ctrl-check { flex-direction: row; align-items: center; gap: 6px; grid-column: 1 / -1; }
.ctrl-check input { margin: 0; }

/* ---- preview ---- */
#preview { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#pv-toolbar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.pv-title { font-weight: 600; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#pv-counter { color: var(--muted); min-width: 56px; text-align: center; }
.deck-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.deck-toggle button { border: none; border-radius: 0; padding: 4px 10px; font-size: 12px; }
.deck-toggle button.active { background: var(--accent); color: #fff; }
.present-btn { border-color: var(--accent2); color: var(--accent2); }

#pv-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 18px; min-height: 0; overflow: hidden; }
#pv-strip { display: flex; gap: 8px; padding: 10px 14px; overflow-x: auto; border-top: 1px solid var(--line); background: #ececE6; }
.thumb { position: relative; border: 2px solid transparent; border-radius: 4px; flex: 0 0 auto; cursor: pointer; background: #fff; }
.thumb.active { border-color: var(--accent); }
.thumb-n { position: absolute; left: 3px; bottom: 2px; font-size: 10px; color: var(--muted); background: rgba(255,255,255,.8); padding: 0 3px; border-radius: 3px; }

/* ---- slide stage (design-pixel space, CSS-scaled) ---- */
.stage-wrap { position: relative; box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.stage { position: absolute; top: 0; left: 0; transform-origin: top left; overflow: hidden; }
.el { overflow: hidden; }
.el-text ul { margin: 0; padding-left: 1.1em; }
.el-text li { margin: .28em 0; }
.el-figure img { width: 100%; height: 100%; object-fit: contain; }
.el-demo iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.el-demo.demo-placeholder { display: flex; align-items: center; justify-content: center; background: #eef1f6; color: var(--accent2); border: 1px dashed #b8c4dd; font-size: 20px; }
.el.equation { display: flex; align-items: center; }
[data-locked] { pointer-events: none; }

/* ---- present overlay ---- */
.present-overlay { position: fixed; inset: 0; background: #111; display: flex; align-items: center; justify-content: center; z-index: 1000; }
.present-stage { position: relative; }
