:root {
  --bg: #101418; --panel: #1a2027; --panel2: #222a33; --line: #2c3640;
  --text: #e8edf2; --muted: #8b98a5; --accent: #08aaa1; --accent2: #f0a63c;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, system-ui, sans-serif;
}
header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; border-bottom: 1px solid var(--line);
}
header h1 { font-size: 16px; margin: 0; letter-spacing: .04em; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
button {
  background: var(--accent); color: #fff; border: 0; border-radius: 6px;
  padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button:disabled { opacity: .5; cursor: default; }
input, select {
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 5px; padding: 5px 7px; font: inherit;
}
input[type=color] { padding: 1px; width: 40px; height: 26px; }

/* ===== DataCharter ColorPalette picker (ported) ================= */
.color-palette-picker { position: relative; }
.color-swatch-btn {
  width: 36px; height: 36px; padding: 4px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel2); cursor: pointer; transition: border-color .12s;
}
.color-swatch-btn:hover { border-color: var(--accent); }
.swatch-preview { display: block; width: 100%; height: 100%; border-radius: 2px; }
.color-palette-dropdown {
  display: none; position: absolute; top: 100%; left: 0; z-index: 1000;
  min-width: 220px; padding: 12px; margin-top: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.color-palette-dropdown.open { display: block; }
.color-picker-close {
  position: absolute; top: 8px; right: 8px; background: none; border: none;
  font-size: 20px; color: var(--muted); cursor: pointer; line-height: 1; padding: 0;
}
.color-picker-close:hover { color: var(--text); }
.palette-section { margin-bottom: 12px; }
.palette-section:last-child { margin-bottom: 0; }
.palette-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  color: var(--muted); margin-bottom: 8px;
}
.palette-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.color-option {
  width: 32px; height: 32px; padding: 3px; background: none;
  border: 2px solid transparent; border-radius: 6px; cursor: pointer; transition: all .12s;
}
.color-option:hover { transform: scale(1.1); }
.color-option.selected { border-color: var(--text); }
.color-option span { display: block; width: 100%; height: 100%; border-radius: 2px; }
.variants-section {
  padding: 8px; background: var(--panel2); border-radius: 6px; margin-bottom: 12px;
}
.variants-grid { display: flex; gap: 4px; }
.shade-option {
  flex: 1; height: 28px; padding: 2px; background: none;
  border: 2px solid transparent; border-radius: 6px; cursor: pointer; transition: all .12s;
}
.shade-option:hover { transform: scale(1.05); }
.shade-option.selected { border-color: var(--text); }
.shade-option span { display: block; width: 100%; height: 100%; border-radius: 2px; }
.custom-color-row { display: flex; gap: 8px; align-items: center; }
.custom-color-input {
  width: 36px; height: 36px; padding: 0;
  border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
}
.hex-input {
  flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 13px; font-family: monospace;
}
.opacity-section { padding-top: 8px; }
.opacity-row { display: flex; gap: 8px; align-items: center; }
.opacity-slider {
  flex: 1; height: 6px; -webkit-appearance: none; appearance: none;
  background: linear-gradient(to right, transparent, var(--accent));
  border-radius: 3px; cursor: pointer;
}
.opacity-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; background: var(--panel);
  border: 2px solid var(--accent); border-radius: 50%; cursor: pointer;
}
.opacity-slider::-moz-range-thumb {
  width: 14px; height: 14px; background: var(--panel);
  border: 2px solid var(--accent); border-radius: 50%; cursor: pointer;
}
/* numeric spinner paired with the opacity slider */
.opacity-value {
  width: 52px; padding: 3px 4px; font-size: 12px; text-align: right;
  color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 5px;
}
.opacity-suffix { font-size: 11px; color: var(--muted); }
/* The dropdown is a descendant of .style-form; these keep its own controls
   from being resized by the generic .style-form input[type=...] rules. */
.color-palette-dropdown input[type=range].opacity-slider { flex: 1; width: auto; }
.color-palette-dropdown input[type=number].opacity-value { width: 52px; }
.color-palette-dropdown input[type=text].hex-input { flex: 1; width: auto; max-width: none; }
.color-palette-dropdown input[type=color].custom-color-input { width: 36px; }
/* Inline variant used inside the style forms */
.color-palette-picker--inline { display: inline-block; vertical-align: middle; }
.color-palette-picker--inline .color-swatch-btn { width: 40px; height: 26px; padding: 3px; }
input[type=range] { padding: 0; }
code { background: var(--panel2); padding: 0 4px; border-radius: 3px; }

/* upload */
#uploadScreen { max-width: 640px; margin: 40px auto; padding: 0 16px; }
.dropzone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 40px;
  text-align: center; background: var(--panel);
}
.dropzone.drag { border-color: var(--accent); }
#projectList { margin-top: 24px; }
.proj-item {
  display: flex; gap: 10px; align-items: center; padding: 10px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  margin-bottom: 8px; cursor: pointer;
}
.proj-item:hover { border-color: var(--accent); }

/* editor — video | draggable divider | right rail. The rail width is a CSS
   variable so the divider can resize it (persisted to localStorage). */
.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 16px var(--rail-w, 380px); gap: 0;
  padding: 14px 18px; align-items: start;
}
/* draggable gutter between the video and the rail */
.col-divider {
  grid-column: 2; align-self: stretch; position: relative;
  cursor: col-resize; touch-action: none;
}
.col-divider::before {
  content: ""; position: absolute; left: 50%; top: 0; bottom: 0;
  width: 2px; margin-left: -1px; border-radius: 2px; background: var(--line);
  transition: background .12s;
}
.col-divider:hover::before, .col-divider.dragging::before {
  background: var(--accent); width: 3px; margin-left: -1.5px;
}
/* The right rail is a fixed-height column pinned beside the video. The verb
   tabs and the Text/Style sub-tabs stay put at the top; only the pane below
   them scrolls, so scrolling happens *within* the current tab. */
.right {
  position: sticky; top: 14px;
  height: calc(100vh - 28px);
  display: flex; flex-direction: column; min-height: 0;
}
#videoWrap { position: relative; background: #000; border-radius: 8px; overflow: hidden; }
#video { display: block; width: 100%; }
#overlay { position: absolute; inset: 0; pointer-events: none; visibility: hidden; }

/* overlay elements (geometry set inline by preview.js) */
.toc-header { position: absolute; font-weight: 600; white-space: nowrap; }
.toc-row { position: absolute; }
.toc-face { position: absolute; inset: 0; display: flex; }
.toc-numbox {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
  font-weight: 600; height: 100%;
}
.toc-bar { flex: 1; display: flex; align-items: center; height: 100%; }
.toc-bar span { font-weight: 600; display: block; }
.toc-buildcard { position: absolute; inset: 0; overflow: hidden; }
.toc-chaptercard { position: absolute; inset: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center; }
.toc-defcard { position: absolute; left: 0; right: 0; overflow: visible;
  display: flex; flex-direction: column; align-items: center;
  justify-content: flex-end; }
.toc-def-term { white-space: nowrap; }
.toc-def-text { text-align: center; }
/* uploaded chart / image overlay (geometry set inline by preview.js).
   pointer-events:auto re-enables interaction inside the none-by-default overlay
   so charts can be dragged/resized on the video frame. */
.toc-chart-bg { position: absolute; pointer-events: auto; cursor: move; }
.toc-chartimg { position: absolute; display: block; pointer-events: auto; cursor: move; }
.toc-chart-handle { position: absolute; width: 14px; height: 14px;
  margin: -7px 0 0 -7px; box-sizing: border-box; border-radius: 3px;
  background: var(--accent); border: 2px solid #fff; pointer-events: auto;
  cursor: nwse-resize; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
/* snap guides shown while dragging a chart onto a frame edge / centre / 100% */
.chart-guides { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.chart-guides[hidden] { display: none; }
.chart-guide { position: absolute; background: var(--accent);
  box-shadow: 0 0 4px var(--accent); }
.chart-guide.v { top: 0; bottom: 0; width: 2px; margin-left: -1px; }
.chart-guide.h { left: 0; right: 0; height: 2px; margin-top: -1px; }
.dot.def { background: #ffffff; border: 1px solid #666; }
.dot.chart { background: #b39ddb; }

#timelineWrap { margin-top: 8px; }
#timeline { width: 100%; height: 140px; display: block; background: var(--panel);
  border-radius: 8px; cursor: crosshair; }
.timeline-legend { display: flex; gap: 18px; margin: 4px 2px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.dot.intro { background: var(--accent); }
.dot.start { background: var(--accent2); border-radius: 2px; transform: rotate(45deg); }
.dot.build { background: #d7a214; border-radius: 2px; }
.dot.card { background: #c9d4dd; }

.transport { display: flex; gap: 6px; margin-top: 8px; align-items: center; }
.transport button { background: var(--panel2); border: 1px solid var(--line); font-weight: 500; }
#btnPlay { width: 44px; }

#transcriptPanel { margin-top: 12px; }
.scroll { max-height: 220px; overflow-y: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 0; }
.tr-line { padding: 3px 12px; cursor: pointer; display: flex; gap: 10px; }
.tr-line:hover { background: var(--panel2); }
.tr-line.current { background: #123c3a; }
.tr-line .ts { color: var(--muted); flex: 0 0 52px; font-variant-numeric: tabular-nums; }
.tr-event { border-left: 3px solid; font-size: 12px; font-weight: 500;
  background: rgba(255,255,255,.03); margin: 2px 0; }
.tr-event .ts { color: inherit; opacity: .7; }

.panel { background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.panel-title { font-weight: 600; margin-bottom: 10px; }
.panel-title.collapsible { cursor: pointer; user-select: none; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* right-rail list entries — each is its own inset card so adjacent entries read
   as distinct blocks (not a run-together list split by a hairline), and the
   lighter input fields pop against the darker card ground */
.entry-card {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px; margin-bottom: 8px;
}
.entry-card:hover { border-color: #3a4652; }
.entry-card:last-child { margin-bottom: 0; }

/* ===== shared element-row grammar ====================================
   Chapters, build-list items, cards and definitions are all lists of timed
   elements, so they share ONE row grammar: a number + primary text input +
   delete on the first line, then a compact, labelled "times" line and any
   secondary lines (definition, confidence, title meter) stacked beneath.
   `.entry-card.el-row` = a standalone element that is its own card (TOC /
   cards / defs); a bare `.el-row` = one item inside a build-list group. */
.el-row {
  display: grid; grid-template-columns: 20px 1fr auto; gap: 6px 8px;
  align-items: center;
}
/* build-group items are plain rows inside one group card, split by hairlines
   rather than each being their own card */
.entry-card > .el-row { padding: 7px 0; }
.entry-card > .el-row + .el-row { border-top: 1px solid var(--line); }
.el-row .row-actions { display: flex; gap: 4px; align-items: center; }
.el-row .num { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.el-row input.title { width: 100%; }
.el-row .def-line { grid-column: 2 / 4; width: 100%; }
.el-row .times { grid-column: 2 / 4; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.el-row .times label { font-size: 12px; color: var(--muted); }
.el-row input.time { width: 74px; font-variant-numeric: tabular-nums; }
.el-row input.hold { width: 56px; }
.el-row .at { padding: 4px 7px; background: var(--panel2); border: 1px solid var(--line); }
.el-row .conf { font-size: 11px; color: var(--muted); grid-column: 2 / 4; }
.el-row .title-meter { grid-column: 2 / 4; font-size: 11px; color: var(--muted);
  margin-top: -2px; }
.el-row .title-meter.ok { color: var(--accent); }
.el-row .title-meter.warn { color: var(--accent2); }
.el-row .title-meter:empty { display: none; }

/* delete ✕ — muted until hovered, everywhere it appears */
.del { background: transparent; border: 0; color: var(--muted); font-size: 15px; padding: 2px 6px; }
.del:hover { color: #f66; filter: none; }

/* build-list group: several timed items under one titled card */
.el-group-head { display: flex; gap: 8px; align-items: center; margin-bottom: 2px; }
.el-group-head strong { font-size: 13px; }
.el-group .add-item { margin-top: 8px; }

/* chart (uploaded image) rows reuse the shared `.el-row` grammar — including
   its labelled `.times` line — but lead with an image thumbnail + static name
   label instead of the number + text input the other types carry */
.chart-row { grid-template-columns: 66px 1fr auto; }
.chart-thumb { width: 66px; height: 42px; object-fit: contain; background: #fff;
  border: 1px solid var(--line); border-radius: 4px; }
.chart-body { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.chart-name { font-size: 13px; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }

.row-btns { display: flex; gap: 8px; margin-top: 10px; }

/* element rows scrub the video on click (see rowSeek in app.js) — the pointer
   hints it; the inputs/buttons inside keep their own cursors */
.seekable { cursor: pointer; }

/* verb tabs — the right rail is organized by action; stays fixed at the top
   of the rail while the pane below scrolls */
#verbTabs { display: flex; flex-wrap: wrap; gap: 5px; flex: 0 0 auto;
  background: var(--bg); padding: 8px 0 10px; }
#verbTabs button {
  flex: 1 1 auto; min-width: 0; background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted); font-weight: 600; font-size: 12.5px; padding: 9px 5px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  gap: 5px; white-space: nowrap;
}
#verbTabs button:hover { border-color: var(--accent); color: var(--text); }
#verbTabs button.active { background: var(--accent); border-color: var(--accent);
  color: #fff; }
#verbTabs .count { background: rgba(255,255,255,.16); border-radius: 9px;
  font-size: 11px; padding: 1px 7px; min-width: 10px; }
#verbTabs .count:empty { display: none; }
#verbTabs button:not(.active) .count { background: var(--panel2); }
/* the active tab fills the rail and is itself a column: fixed sub-tabs + a
   scrolling pane */
.verb-tab { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.verb-tab[hidden] { display: none; }

/* per-section text / style sub-tabs — a tab strip, not chip buttons; pinned
   above the scrolling pane */
.subtabs { display: flex; gap: 4px; margin-bottom: 14px; flex: 0 0 auto;
  border-bottom: 1px solid var(--line); }
.subtabs .subtab { flex: 0 0 auto; background: none; border: 0;
  border-bottom: 2px solid transparent; border-radius: 0; margin-bottom: -1px;
  color: var(--muted); font-weight: 600; font-size: 13px; padding: 8px 16px; }
.subtabs .subtab:hover { background: none; filter: none; color: var(--text); }
.subtabs .subtab.active { color: var(--text); border-bottom-color: var(--accent); }
/* only the pane scrolls — this is the downward scroll within each tab */
.sub-pane { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding-right: 6px; }
.sub-pane[hidden] { display: none; }

/* style panel heading with a live example of the element being edited */
.panel-title.style-head { display: flex; align-items: center;
  justify-content: space-between; gap: 10px; }
.style-eg { position: relative; width: 150px; aspect-ratio: 16 / 9; flex: 0 0 auto;
  background: #31383f; border: 1px solid var(--line); border-radius: 6px;
  overflow: hidden; }

/* grouped style fields */
.style-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 700; margin: 14px 0 2px; padding-bottom: 4px;
  border-bottom: 1px solid var(--line); }
.style-group:first-child { margin-top: 2px; }

/* per-type style forms */
.style-pick { width: 100%; margin-bottom: 4px; }
.style-form label.srow { display: flex; align-items: center;
  justify-content: space-between; gap: 10px; margin: 9px 0; font-size: 13px; }
.style-form label.srow span { color: var(--muted); }
.style-form input[type=number] { width: 84px; }
.style-form input[type=range] { width: 150px; }
.style-form input[type=text], .style-form select { width: 200px; max-width: 55%; }

/* settings modal tabs + defaults example */
#settingsTabs { display: flex; gap: 6px; margin: 4px 0 12px; }
#settingsTabs button {
  flex: 1; background: var(--panel2); border: 1px solid var(--line);
  color: var(--muted); font-size: 12px; font-weight: 600; padding: 7px 4px;
  border-radius: 6px;
}
#settingsTabs button:hover { border-color: var(--accent); color: var(--text); }
#settingsTabs button.active { border-color: var(--accent); color: var(--text);
  background: rgba(8,170,161,.14); }
#defaultsDemo {
  position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden;
  background: #31383f; border: 1px solid var(--line); border-radius: 8px;
  margin-bottom: 10px;
}

/* chapters fork */
.fork-btns { display: flex; flex-direction: column; gap: 10px; margin: 10px 0 4px; }
button.fork {
  text-align: left; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; padding: 13px 15px; color: var(--text); line-height: 1.5;
}
button.fork:hover { border-color: var(--accent); }

/* export popover (header) */
#exportWrap { position: relative; }
#exportPopover {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 60;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; width: min(360px, 92vw); text-align: left;
  box-shadow: 0 10px 34px rgba(0,0,0,.55);
}
#exportPopover[hidden] { display: none; }
#exportPopover { width: min(400px, 94vw); }
.exp-intro { font-size: 12px; color: var(--muted); margin: 0 0 12px; line-height: 1.5; }
.exp-group {
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--accent); margin: 14px 0 2px; padding-top: 10px;
  border-top: 1px solid var(--line);
}
.exp-group:first-of-type { border-top: 0; padding-top: 0; }
.exp-resnote { font-size: 12px; line-height: 1.5; margin: 10px 0 4px; }
.exp-resnote.warn {
  color: var(--text); background: rgba(215,162,20,.12);
  border: 1px solid var(--gold, #D7A214); border-radius: 8px; padding: 8px 10px;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin-bottom: 8px; }
.grid2 label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
label.stack { display: block; margin-bottom: 8px; }
label.stack input[type=text], label.stack select, label.stack input[type=number] { width: 100%; margin-top: 3px; }
label.stack input[type=range] { width: 100%; }
label.check { display: flex; gap: 9px; margin: 10px 0; align-items: flex-start; cursor: pointer; }

/* definition pills */
#defPills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.def-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel2); border: 1px solid var(--accent);
  border-radius: 14px; padding: 4px 10px; font-size: 12px; cursor: default;
}
.def-pill .pill-x { cursor: pointer; color: var(--muted); font-weight: 700; }
.def-pill .pill-x:hover { color: #f66; }
.def-pill .pill-t { color: var(--muted); font-variant-numeric: tabular-nums; }

/* AI suggestion modal + variant dropdowns */
#suggestModal, #aiSettingsModal { position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 50; }
#suggestModal[hidden], #aiSettingsModal[hidden] { display: none; }
#aiSettingsModal textarea {
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 5px; padding: 6px 8px; font: 12px/1.45 ui-monospace, Consolas, monospace;
  width: 100%; margin-top: 3px; resize: vertical;
}
#aiSettingsModal .scroll { padding-right: 6px; }
#aiSettingsModal .row-btns { align-items: center; }
.modal-box { background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px; width: min(680px, 92vw); }
.structure {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px;
  margin: 8px 10px; cursor: pointer; background: var(--panel2);
}
.structure:hover { border-color: var(--accent); }
.structure h5 { margin: 0 0 2px; font-size: 14px; }
.structure .rationale { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.structure ol { margin: 0; padding-left: 22px; }
.structure li { padding: 1px 0; }
.el-row .variants-btn { background: var(--panel2); border: 1px solid var(--line);
  padding: 4px 7px; }
.variant-menu { position: absolute; z-index: 40; background: var(--panel);
  border: 1px solid var(--accent); border-radius: 8px; padding: 4px 0;
  box-shadow: 0 6px 24px rgba(0,0,0,.5); max-width: 360px; }
.variant-menu div { padding: 5px 12px; cursor: pointer; }
.variant-menu div:hover { background: var(--panel2); }

#exportStatus { margin-top: 10px; font-size: 13px; }
.progress { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
a.dl { color: var(--accent); font-weight: 600; }

/* "AI is thinking" live indicator — an animated three-dot pulse shown beside a
   long Claude call so a 15–60s wait never reads as frozen. */
.ai-pulse { display: inline-flex; gap: 3px; vertical-align: middle; margin-left: 2px; }
.ai-pulse i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
  display: inline-block; animation: ai-pulse 1.1s ease-in-out infinite;
}
.ai-pulse i:nth-child(2) { animation-delay: .18s; }
.ai-pulse i:nth-child(3) { animation-delay: .36s; }
@keyframes ai-pulse { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.ai-elapsed { font-variant-numeric: tabular-nums; opacity: .85; }
