:root {
  --appbar: #17233c;
  --blue: #2f5fb8;
  --blue-dark: #244b90;
  --bg: #f4f4f4;
  --card: #ffffff;
  --text: #111111;
  --muted: #666666;
  --border: #dddddd;
  --danger: #b00020;
  --danger-dark: #8c0019;
  --input-bg: #fffaca;
  --library: #eaf0f8;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Arial, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, textarea, select { font: inherit; }
.hidden { display: none !important; }

/* Creator shell */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 72px;
  background: var(--appbar);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,.16);
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  display: inline-block;
  width: fit-content;
  border: 2px solid rgba(255,255,255,.58);
  color: #fff;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: .18rem;
  padding: .45rem .75rem;
  border-radius: 8px;
}
.brand h1 { margin: 0; font-size: 1.25rem; }
.top-actions { display: flex; gap: 9px; flex-wrap: wrap; }

.shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}
.library-pane {
  border-right: 1px solid #d8e0eb;
  background: var(--library);
  padding: 18px;
  overflow: auto;
}
.pane-heading h2 { margin: 0; font-size: 1.08rem; }
.pane-heading p { margin: 5px 0 14px; color: #637083; font-size: .9rem; }
.library-list { display: flex; flex-direction: column; gap: 9px; }
.library-item {
  background: #fff;
  border: 1px solid #d8e0eb;
  border-radius: 11px;
  padding: 12px;
  cursor: pointer;
}
.library-item.active { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(47,95,184,.14); }
.library-title { font-weight: 700; overflow-wrap: anywhere; }
.library-meta { font-size: .8rem; color: #637083; margin-top: 5px; }
.editor-pane { min-width: 0; padding: 24px; background: var(--bg); }
.creator-page { max-width: 1100px; margin: 0 auto; }

/* TOETSbox builder look, recoloured blue */
.card {
  background: var(--card);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  margin-bottom: 20px;
}
.editor-topbar,
.row.between {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}
.editor-topbar { margin-bottom: 22px; }
.editor-topbar h1 { margin: 0; font-size: 1.8rem; }
h2 { margin: 0 0 14px; font-size: 1.35rem; }
h3 { margin: 0; font-size: 1.05rem; }
.muted, .help { color: var(--muted); }
.help { font-size: .9rem; }
.save-status { margin-top: 6px; color: var(--blue-dark); font-size: .9rem; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
button {
  border: 0;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: .95rem;
  cursor: pointer;
  color: var(--text);
  background: #eeeeee;
  font-family: Arial, system-ui, sans-serif;
  font-weight: 400;
}
button:hover { background: #e5e5e5; }
button.primary { background: var(--blue); color: #fff; }
button.primary:hover { background: var(--blue-dark); }
button.secondary { background: #eef3fb; }
button.danger { color: #fff; background: var(--danger); }
button.danger:hover { background: var(--danger-dark); }
button.small { padding: 8px 10px; font-size: .88rem; }
button:disabled { opacity: .6; cursor: not-allowed; }

label { display: block; font-weight: 700; margin-bottom: 6px; }
input, textarea, select {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 1rem;
  font-family: Arial, system-ui, sans-serif;
  background: var(--input-bg);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: 3px solid rgba(47,95,184,.22);
  border-color: var(--blue);
}
.form-grid { display: grid; gap: 16px; }
.two-col { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 16px; }

.block {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  background: #fafafa;
}
.block-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.small-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.version-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 16px; }
.version-tab.active { background: var(--blue); color: white; }
.info-preview {
  white-space: pre-wrap;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px;
  color: #333;
}
.gapfill-row {
  display: grid;
  grid-template-columns: minmax(0,2fr) minmax(160px,1fr) 110px auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 10px;
}
.mcq-top, .open-top {
  display: grid;
  grid-template-columns: minmax(0,1fr) 120px;
  gap: 12px;
  align-items: end;
}
.option-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto auto;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}
.image-top {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(180px,260px);
  gap: 12px;
  align-items: end;
}
.media-preview {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-top: 12px;
  background: #f8f8f8;
}
.media-preview img { display: block; max-width: 100%; max-height: 420px; margin: auto; border-radius: 8px; }
.media-preview audio { width: 100%; }
.media-line { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.media-name { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }

.notice { padding: 10px; border-radius: 9px; margin-bottom: 12px; font-size: .84rem; }
.warning { background: #fff5d8; color: #765000; border: 1px solid #efd68a; }
.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: var(--appbar);
  color: #fff;
  border-radius: 10px;
  padding: 11px 14px;
  box-shadow: 0 8px 25px rgba(0,0,0,.28);
  z-index: 50;
  max-width: 420px;
}

@media (max-width: 1000px) {
  .shell { grid-template-columns: 250px minmax(0,1fr); }
}
@media (max-width: 800px) {
  .app-topbar { position: static; align-items: flex-start; flex-direction: column; }
  .shell { display: block; }
  .library-pane { border-right: 0; border-bottom: 1px solid #d8e0eb; max-height: 280px; }
  .editor-pane { padding: 14px; }
  .two-col, .gapfill-row, .mcq-top, .open-top, .image-top { grid-template-columns: 1fr; }
  .editor-topbar { flex-direction: column; }
  .editor-actions { width: 100%; }
  .editor-actions button, .top-actions button { flex: 1 1 auto; }
  .option-row { grid-template-columns: 1fr; }
}
