:root {
  /* Light theme (default for building) */
  --bg: #f3f5f8;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --panel-2: #eef2f6;
  --border: #dbe2e9;
  --text: #1b2632;
  --muted: #5b6a78;
  --accent: #0d9488;
  --accent-2: #0f766e;
  --danger: #dc2626;
  --warn: #b45309;
  --ok: #047857;
  --primary-text: #ffffff;
  --btn-hover: #e8edf2;
  --ok-bg: #e6f5ee;     --ok-border: #b6ddc9;
  --warn-bg: #fbf1e0;   --warn-border: #ecd2a0;
  --quiz-bg: #e2f4f1;   --quiz-border: #b3ddd6;
  --correct-bg: #e6f5ee;
  --danger-bg: #fdeced; --danger-border: #f3c0c0;
  --overlay: rgba(20,28,38,.45);
  --shadow-sm: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.07);
  --shadow-pop: 0 10px 30px rgba(16,24,40,.14);
  --shadow-modal: 0 16px 50px rgba(16,24,40,.20);
  --banner-bg: #e2f4f1;
  --radius: 10px;
  color-scheme: light;
  font-synthesis: none;
}
[data-theme="dark"] {
  --bg: #0f1419;
  --bg-2: #161c24;
  --panel: #1b232d;
  --panel-2: #212c38;
  --border: #2c3845;
  --text: #e6edf3;
  --muted: #8b9bab;
  --accent: #2dd4bf;
  --accent-2: #14b8a6;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #34d399;
  --primary-text: #04201d;
  --btn-hover: #2a3744;
  --ok-bg: #102a20;     --ok-border: #1d4a38;
  --warn-bg: #2e2710;   --warn-border: #4a3c16;
  --quiz-bg: #11302c;   --quiz-border: #1f4f49;
  --correct-bg: #0f211a;
  --danger-bg: #3a2326; --danger-border: #5a2e2e;
  --overlay: rgba(0,0,0,.55);
  --shadow-sm: none;
  --shadow-pop: 0 10px 34px rgba(0,0,0,.5);
  --shadow-modal: 0 16px 50px rgba(0,0,0,.5);
  --banner-bg: #1e2a2a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Inter var", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background .15s ease, color .15s ease;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: .2px; }
.brand .logo { color: var(--accent); font-size: 18px; }
.topbar-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 550;
  border-radius: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  user-select: none;
}
.btn:hover { background: var(--btn-hover); }
.btn-primary { background: var(--accent-2); border-color: var(--accent-2); color: var(--primary-text); }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 9px; font-size: 12.5px; border-radius: 6px; }
.btn-icon { padding: 8px 11px; font-size: 16px; line-height: 1; }
.btn-icon:disabled { opacity: .35; cursor: not-allowed; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn:focus-visible, .tab:focus-visible, .icon-btn:focus-visible, .rt-btn:focus-visible,
.outline-row:focus-visible, .file-name:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ---------- Empty state ---------- */
.empty {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 56px);
  padding: 24px;
}
.empty.dragover .empty-card { border-color: var(--accent); background: var(--panel-2); }
.empty-card {
  max-width: 460px;
  text-align: center;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 44px 36px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, background .15s;
}
.empty-icon { font-size: 40px; color: var(--accent); }
.empty-card h1 { font-size: 20px; margin: 14px 0 8px; }
.empty-card p { color: var(--muted); margin: 0 0 20px; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 2px;
  padding: 0 18px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 56px;
  z-index: 15;
}
.tab {
  font: inherit;
  font-weight: 550;
  background: none;
  border: none;
  color: var(--muted);
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Panels ---------- */
.panel { max-width: 920px; margin: 0 auto; padding: 26px 22px 80px; }
.panel.panel-wide { max-width: 1280px; padding: 14px 18px; }

/* ---------- Build view (outline + single-screen editor) ---------- */
.build-grid {
  display: grid;
  grid-template-columns: var(--outline-w, 340px) 14px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: calc(100vh - 116px);
}
/* Draggable divider that widens/narrows the outline. */
.build-splitter {
  position: relative;
  cursor: col-resize;
  touch-action: none;
  align-self: stretch;
}
.build-splitter::before {
  content: "";
  position: absolute; top: 0; bottom: 0; left: 50%;
  width: 2px; margin-left: -1px;
  background: var(--border); border-radius: 2px;
  transition: background .12s, width .12s;
}
.build-splitter:hover::before, body.col-resizing .build-splitter::before {
  background: var(--accent); width: 4px; margin-left: -2px;
}
body.col-resizing { cursor: col-resize; -webkit-user-select: none; user-select: none; }
.outline {
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.outline-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.outline-count { font-size: 12px; color: var(--muted); font-weight: 600; }
.outline-add { display: flex; gap: 6px; }
.outline-add select { max-width: 150px; padding: 5px 8px; }
.outline-list { padding: 6px; display: flex; flex-direction: column; gap: 2px; }
.outline-add select { max-width: 130px; }
.module-head {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; margin-top: 6px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 7px;
}
.mod-caret { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; padding: 0 2px; }
.mod-title { flex: 1; min-width: 0; font: inherit; font-weight: 600; font-size: 13px;
  background: transparent; border: 1px solid transparent; border-radius: 5px; color: var(--text); padding: 3px 6px; }
.mod-title:hover { border-color: var(--border); }
.mod-title:focus { outline: none; background: var(--bg); border-color: var(--accent-2); }
.mod-count { font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.mod-actions { display: flex; gap: 2px; }
.mod-actions .icon-btn { width: 22px; height: 22px; font-size: 12px; }
.module-body { display: flex; flex-direction: column; gap: 2px; padding-left: 10px; border-left: 1px solid var(--border); margin-left: 8px; }
.module-body[hidden] { display: none; }
.outline-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: 7px; cursor: pointer;
  border-left: 3px solid transparent;
}
.outline-row:hover { background: var(--panel-2); }
.outline-row.selected { background: var(--panel-2); border-left-color: var(--accent); }
.outline-row.flash { animation: flashCard 1.3s ease; }
.row-badge {
  flex: 0 0 auto; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px;
  padding: 2px 6px; border-radius: 5px; background: var(--bg); color: var(--muted); border: 1px solid var(--border);
}
.row-badge.graded { color: var(--ok); border-color: var(--ok-border); background: var(--ok-bg); }
.row-badge.scenario { color: var(--warn); border-color: var(--warn-border); background: var(--warn-bg); }
.row-title { flex: 1; min-width: 0; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .1s; }
.outline-row:hover .row-actions, .outline-row.selected .row-actions { opacity: 1; }
.row-actions .icon-btn { width: 24px; height: 24px; font-size: 12px; }
.drag-handle {
  flex: 0 0 auto; cursor: grab; color: var(--muted); font-size: 14px;
  -webkit-user-select: none; user-select: none; padding: 2px 5px;
  touch-action: none; /* let pointer events drive the drag instead of scroll/select */
}
.drag-handle:active { cursor: grabbing; }
body.dnd-active { -webkit-user-select: none; user-select: none; cursor: grabbing; }
.outline-row.drop-before, .module-head.drop-before { box-shadow: inset 0 2px 0 0 var(--accent); }
.outline-row.drop-after, .module-head.drop-after { box-shadow: inset 0 -2px 0 0 var(--accent); }
.outline .add-bar { margin: 8px; }

.editor-pane { min-height: 0; overflow-y: auto; padding: 2px 10px 60px 2px; }
.editor-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 2px; }
.editor-head h2 { font-size: 18px; margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 860px) {
  .build-grid { grid-template-columns: 1fr; height: auto; }
  .build-splitter { display: none; }
  .outline { max-height: 320px; }
  .editor-pane { overflow: visible; }
}
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 28px 0 12px; }
.section-title:first-child { margin-top: 4px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.card-head h3 { margin: 0; font-size: 15px; }
.badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge.quiz { color: var(--accent); border-color: var(--quiz-border); background: var(--quiz-bg); }
.badge.scenario { color: var(--warn); border-color: var(--warn-border); background: var(--warn-bg); }
.badge.graded { color: var(--ok); border-color: var(--ok-border); background: var(--ok-bg); }

.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field > label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  font: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 10px;
  resize: vertical;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent-2); }
textarea { min-height: 64px; line-height: 1.55; }
textarea.tall { min-height: 110px; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 160px; }

/* options / answers */
.option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: var(--bg);
}
.option.correct { border-color: var(--ok); background: var(--correct-bg); }
.option-main { flex: 1; }
.option input[type="radio"], .option input[type="checkbox"] { margin-top: 9px; accent-color: var(--ok); }
.option .feedback { margin-top: 7px; }
.opt-tag { font-size: 11px; color: var(--ok); font-weight: 600; }

.controls { display: flex; gap: 6px; }
.icon-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
}
.icon-btn:hover { background: var(--btn-hover); }
.icon-btn:disabled { opacity: .3; cursor: not-allowed; }

.summary-bar {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  padding: 14px 18px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
}
.stat { }
.stat .num { font-size: 20px; font-weight: 700; color: var(--accent); }
.stat .lbl { font-size: 12px; color: var(--muted); }

/* file list */
.file-list { display: grid; grid-template-columns: 230px 1fr; gap: 14px; }
.file-names { display: flex; flex-direction: column; gap: 2px; }
.file-name {
  text-align: left;
  font: inherit;
  background: none;
  border: none;
  color: var(--muted);
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-name:hover { background: var(--panel); color: var(--text); }
.file-name.active { background: var(--panel-2); color: var(--accent); }
.file-name.binary { opacity: .5; cursor: default; }
.file-name.dirty::after { content: " ●"; color: var(--warn); }
#fileEditor { width: 100%; min-height: 480px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; line-height: 1.5; white-space: pre; }

/* toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 8px;
  box-shadow: var(--shadow-pop);
  z-index: 40;
  font-weight: 550;
}
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }

/* add-screen / add-question footer */
.add-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 16px;
  margin-top: 8px;
  background: var(--panel-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.add-bar-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }

/* image thumbnail in the uploader */
.img-thumb {
  display: block;
  max-width: 220px;
  max-height: 150px;
  width: auto;
  height: auto;
  border-radius: 7px;
  border: 1px solid var(--border);
  margin: 8px 0;
  background: var(--bg);
}

.empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.restore-bar {
  margin-top: 18px;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid var(--accent-2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 13.5px;
}

/* media overview rows */
.media-row {
  display: flex;
  align-items: center;
  gap: 16px;
}
.media-row .img-thumb { margin: 0; flex: 0 0 auto; max-width: 120px; max-height: 90px; }
.media-meta { flex: 1; min-width: 0; }
.media-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  word-break: break-all;
  margin-bottom: 2px;
}
.media-usage { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.badge.unused { color: var(--warn); border-color: var(--warn-border); background: var(--warn-bg); }

/* blocked-pop-up fallback bar for Preview */
.preview-link-bar {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 92vw;
  background: var(--panel-2);
  border: 1px solid var(--accent-2);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  z-index: 50;
  font-weight: 550;
}

/* rich-text WYSIWYG editor */
.rt-wrap { width: 100%; }
.rt-editable {
  width: 100%;
  min-height: 64px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 10px;
  line-height: 1.55;
  font: inherit;
  overflow-wrap: anywhere;
}
.rt-editable:focus { outline: none; border-color: var(--accent-2); }
.rt-editable a { color: var(--accent); }
.rt-editable ul { margin: 6px 0; padding-left: 22px; }
.rt-editable strong { font-weight: 700; }
.rt-editable em { font-style: italic; }
.rt-toolbar {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}
.rt-btn {
  font: inherit;
  font-size: 12.5px;
  min-width: 28px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.4;
}
.rt-btn:hover { background: var(--btn-hover); border-color: var(--accent-2); }
.rt-btn em { font-style: italic; }

/* accessibility checker */
.a11y-list { display: flex; flex-direction: column; gap: 8px; }
.a11y-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  font-size: 13.5px;
}
.a11y-badge {
  flex: 0 0 auto; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  padding: 2px 8px; border-radius: 20px;
}
.a11y-badge.error { color: var(--danger); background: var(--danger-bg); border: 1px solid var(--danger-border); }
.a11y-badge.warn { color: var(--warn); background: var(--warn-bg); border: 1px solid var(--warn-border); }
.a11y-badge.info { color: var(--accent); background: var(--quiz-bg); border: 1px solid var(--quiz-border); }
.card.flash { animation: flashCard 1.3s ease; }
@keyframes flashCard {
  0%, 100% { box-shadow: var(--shadow-sm); }
  20% { box-shadow: 0 0 0 3px var(--accent); }
}

/* AI generation modal + review banner */
.ai-modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: var(--overlay);
  display: grid; place-items: center; padding: 20px;
}
.ai-modal {
  width: 100%; max-width: 460px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 22px 24px; box-shadow: var(--shadow-modal);
  max-height: 90vh; overflow-y: auto;
}
.ai-modal h2 { margin: 0 0 6px; font-size: 19px; }
.ai-field { margin: 12px 0; }
.ai-field .fld { display: block; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 5px; }
.ai-modal textarea, .ai-modal input[type=text], .ai-modal input[type=number], .ai-modal select {
  width: 100%; font: inherit; background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 7px; padding: 8px 10px;
}
.ai-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.ai-status { margin-top: 14px; font-size: 13.5px; color: var(--muted); }
.ai-status.err { color: var(--danger); }
.ai-review-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 18px; background: var(--banner-bg); border-bottom: 1px solid var(--accent-2);
  color: var(--text); font-weight: 550; font-size: 13.5px;
}

/* hotspot point editor (drag markers onto the image) */
.hotspot-edit-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: crosshair;
  line-height: 0;
}
.hotspot-edit-stage img {
  display: block;
  max-width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}
.hotspot-edit-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--accent-2);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
  cursor: grab;
  touch-action: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  z-index: 2;
}
.hotspot-edit-marker:active { cursor: grabbing; }

.muted-note { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.divider { height: 1px; background: var(--border); margin: 22px 0; border: 0; }
