*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Dark mode (default) ──────────────────────────────────────────────────── */
:root {
  --sidebar-w: 220px;
  --sidebar2-w: 220px;
  --sidebar-mp-w: 180px;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active-bg: #1e3a5f;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #93c5fd;
  --content-bg: #0f172a;
  --text: #cbd5e1;
  --text-muted: #64748b;
  --border: #1e293b;
  --code-bg: #020617;
  --code-text: #e2e8f0;
  --link: #60a5fa;
  --heading: #f1f5f9;
  --inline-code-bg: #1e293b;
  --inline-code-text: #f472b6;
  --quote-bg: #1e293b;
  --quote-border: #475569;
  --quote-text: #94a3b8;
  --box-green-bg: #052e16;
  --box-green-border: #166534;
  --sc-header-bg: #1e293b;
  --sc-header-hover: #243347;
  --quiz-bg: #1e1b4b;
  --quiz-border: #4338ca;
  --quiz-q-bg: #1e293b;
  --quiz-q-border: #312e81;
  --sub-item-color: #94a3b8;
}

/* ── Light mode override ──────────────────────────────────────────────────── */
[data-theme="light"] {
  --content-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --link: #2563eb;
  --heading: #0f172a;
  --inline-code-bg: #f1f5f9;
  --inline-code-text: #be185d;
  --quote-bg: #f8fafc;
  --quote-border: #94a3b8;
  --quote-text: #334155;
  --box-green-bg: #f0fdf4;
  --box-green-border: #86efac;
  --sc-header-bg: #f8fafc;
  --sc-header-hover: #f1f5f9;
  --quiz-bg: #faf5ff;
  --quiz-border: #c4b5fd;
  --quiz-q-bg: #ffffff;
  --quiz-q-border: #ddd6fe;
  --sub-item-color: #475569;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--content-bg);
}

#sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

#sidebar-secondary {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  width: 0;
  height: 100vh;
  background: #111827;
  overflow: hidden;
  z-index: 90;
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(255,255,255,0.05);
  transition: width 0.2s ease;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

#sidebar-secondary.open {
  width: var(--sidebar2-w);
  overflow-y: auto;
}

#sidebar-secondary-header {
  padding: 1.1rem 1rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #94a3b8;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.2);
  flex-shrink: 0;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#nav-secondary { padding: 0.4rem 0; }

#nav-secondary .nav-link { padding-left: 1rem; }

#nav-secondary .nav-link.nav-indented,
#nav-tree .nav-link.nav-indented {
  position: relative;
}
#nav-secondary .nav-link.nav-indented { padding-left: 1.9rem; }
#nav-tree     .nav-link.nav-indented { padding-left: 2.1rem; }

#nav-secondary .nav-link.nav-indented::before,
#nav-tree     .nav-link.nav-indented::before {
  content: '';
  position: absolute;
  top: 0;
  height: calc(50% + 1px);
  border-left: 1px solid #334155;
  border-bottom: 1px solid #334155;
  border-bottom-left-radius: 2px;
}
#nav-secondary .nav-link.nav-indented::before { left: 0.9rem; width: 0.55rem; }
#nav-tree     .nav-link.nav-indented::before { left: 1.1rem; width: 0.55rem; }

#content {
  margin-left: var(--sidebar-w);
  padding: 2.5rem 3.5rem;
  transition: margin-left 0.2s ease, margin-right 0.2s ease;
}

#content.secondary-open {
  margin-left: calc(var(--sidebar-w) + var(--sidebar2-w));
}

#content.mp-open { margin-right: var(--sidebar-mp-w); }

#sidebar-mp {
  position: fixed;
  top: 0;
  right: 0;
  width: 0;
  height: 100vh;
  background: #111827;
  overflow: hidden;
  z-index: 90;
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(255,255,255,0.05);
  transition: width 0.2s ease;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

#sidebar-mp.open {
  width: var(--sidebar-mp-w);
  overflow-y: auto;
}

#nav-mp { padding: 0.75rem 0; }

.mp-sidebar-item {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--sidebar-text);
  cursor: pointer;
  border-left: 3px solid transparent;
  line-height: 1.4;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}
.mp-sidebar-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-active);
}
.mp-sidebar-item.active {
  color: var(--sidebar-active);
  border-left-color: var(--sidebar-active);
  font-weight: 600;
  background: var(--sidebar-active-bg);
}
.mp-sidebar-sub {
  padding-left: 1.75rem;
  font-size: 0.77rem;
  opacity: 0.85;
}
.mp-num {
  flex-shrink: 0;
  opacity: 0.55;
  font-variant-numeric: tabular-nums;
}
.mp-title { flex: 1; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */

#sidebar-header {
  padding: 1.1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.25);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.sidebar-header-btns {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}

#theme-toggle,
#clear-progress {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 5px;
  color: #94a3b8;
  font-size: 0.9rem;
  padding: 0.2rem 0.45rem;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  line-height: 1;
}
#theme-toggle:hover,
#clear-progress:hover { background: rgba(255,255,255,0.15); color: #f1f5f9; }

.course-title {
  color: #f1f5f9;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#nav-tree { padding: 0.4rem 0; }

.nav-item { display: block; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.38rem 1rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.855rem;
  cursor: pointer;
  transition: background 0.12s;
  user-select: none;
  line-height: 1.4;
}

.nav-link:hover { background: var(--sidebar-hover); color: #f1f5f9; }
.nav-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active); font-weight: 600; }

.nav-arrow {
  flex-shrink: 0;
  width: 14px;
  font-size: 0.58rem;
  transition: transform 0.18s;
  opacity: 0.45;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-link.expanded .nav-arrow { transform: rotate(90deg); opacity: 0.7; }

.nav-label { flex: 1; min-width: 0; }

.nav-mp-icon {
  flex-shrink: 0;
  width: 12px;
  height: 12px;
  fill: currentColor;
  opacity: 0.55;
}

.nav-badge {
  flex-shrink: 0;
  font-size: 0.6rem;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.nb-open     { background: #1d4ed8; color: #bfdbfe; }
.nb-question { background: #6d28d9; color: #ddd6fe; }
.nb-submit   { background: #065f46; color: #a7f3d0; }
.nb-click    { background: #92400e; color: #fde68a; }

.nav-children { display: none; }
.nav-children.open { display: block; }

/* depth indentation */
.nav-category {
  display: block;
  padding: 1rem 1rem 0.3rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #475569;
  text-decoration: none;
  transition: color 0.12s;
}
.nav-category:hover { color: #94a3b8; }
.d0 + .d0 > .nav-category { padding-top: 1.25rem; }
.d1 > .nav-link { padding-left: 1rem; font-size: 0.875rem; font-weight: 600; color: #e2e8f0; }
.d2 > .nav-link { padding-left: 1.75rem; }
.d3 > .nav-link { padding-left: 2.5rem;  font-size: 0.82rem; }
.d4 > .nav-link { padding-left: 3.25rem; font-size: 0.8rem; opacity: 0.85; }

/* ── Mobile toggle ────────────────────────────────────────────────────────── */

#menu-toggle {
  display: none;
  position: fixed;
  top: 0.75rem; left: 0.75rem;
  z-index: 200;
  background: var(--sidebar-bg);
  color: #f1f5f9;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.7rem;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* ── Content typography ───────────────────────────────────────────────────── */

#content-inner {
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: 4rem;
}

h1 {
  font-size: 1.9rem;
  color: var(--heading);
  margin-bottom: 1.5rem;
  line-height: 1.25;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border);
}

p { margin: 0.55rem 0; }

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 0.875em;
  background: var(--inline-code-bg);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  color: var(--inline-code-text);
}

/* Inline heading spans */
.it-l { display: block; font-size: 1.3rem;  font-weight: 700; color: var(--heading); margin: 1.75rem 0 0.5rem; }
.it-m { display: block; font-size: 1.1rem;  font-weight: 700; color: var(--heading); margin: 1.4rem  0 0.4rem; }
.it-s { display: block; font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: 1.1rem 0 0.3rem; }

.link-ref { color: var(--link); cursor: help; border-bottom: 1px dashed var(--link); }

/* ── Code block ───────────────────────────────────────────────────────────── */

.code-block {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin: 1rem 0;
  overflow-x: auto;
  font-family: 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.55;
  white-space: pre;
}
.code-block code {
  background: none;
  color: inherit;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

/* ── Quote ────────────────────────────────────────────────────────────────── */

.quote-block {
  background: var(--quote-bg);
  border-left: 4px solid var(--quote-border);
  border-radius: 0 6px 6px 0;
  padding: 0.8rem 1.25rem;
  margin: 1rem 0;
  font-style: italic;
  color: var(--quote-text);
}
.quote-attr { display: block; margin-top: 0.5rem; font-size: 0.875rem; color: var(--text-muted); font-style: normal; }

/* ── Task box ─────────────────────────────────────────────────────────────── */

.box-green {
  background: var(--box-green-bg);
  border: 1px solid var(--box-green-border);
  border-left: 4px solid #22c55e;
  border-radius: 6px;
  padding: 0.8rem 1.1rem;
  margin: 1rem 0;
}

/* ── Lists ────────────────────────────────────────────────────────────────── */

ul, ol { padding-left: 1.6rem; margin: 0.6rem 0; }
li { margin: 0.3rem 0; }

.list-title { font-weight: 700; margin-bottom: 0.3rem; }

.sub-item {
  display: block;
  padding-left: 1.4rem;
  margin-top: 0.15rem;
  color: var(--sub-item-color);
  font-size: 0.93em;
  position: relative;
}
.sub-item::before {
  content: '–';
  position: absolute;
  left: 0.4rem;
  opacity: 0.5;
}

ol.red, ul.red { color: #dc2626; }

/* ── Image ────────────────────────────────────────────────────────────────── */

.course-image { max-width: 100%; border-radius: 6px; margin: 1rem 0; border: 1px solid var(--border); }

/* ── YouTube ──────────────────────────────────────────────────────────────── */

.yt-wrap { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; border-radius: 8px; margin: 1rem 0; }
.yt-wrap iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; }

/* ── Multipage ────────────────────────────────────────────────────────────── */

.multipage { margin: 1rem 0; }

.mp-page-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.5rem 0 0.6rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.mp-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0 0;
  margin-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.mp-btn {
  padding: 0.35rem 1rem;
  background: var(--sidebar-bg);
  color: #f1f5f9;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.12s;
}
.mp-btn:hover:not(:disabled) { background: #1e293b; }
.mp-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.mp-indicator { font-size: 0.85rem; color: var(--text-muted); }

/* ── Section cards (inline sub-sections) ─────────────────────────────────── */

.section-card { border: 1px solid var(--border); border-radius: 8px; margin: 0.8rem 0; overflow: hidden; }

.sc-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  background: var(--sc-header-bg);
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 0.92rem;
  transition: background 0.12s;
}
.sc-header:hover { background: var(--sc-header-hover); }

.sc-arrow { font-size: 0.62rem; color: var(--text-muted); transition: transform 0.18s; flex-shrink: 0; }
.sc-header.open .sc-arrow { transform: rotate(90deg); }

.sc-title { flex: 1; min-width: 0; }

.sc-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  flex-shrink: 0;
}
.sb-open     { background: #dbeafe; color: #1e40af; }
.sb-question { background: #ede9fe; color: #5b21b6; }
.sb-submit   { background: #d1fae5; color: #065f46; }
.sb-click    { background: #fef3c7; color: #92400e; }

.sc-done { font-size: 0.8rem; color: #22c55e; flex-shrink: 0; }

.sc-body { display: none; padding: 1rem 1.25rem; border-top: 1px solid var(--border); }
.sc-body.open { display: block; }

/* ── Quiz block ───────────────────────────────────────────────────────────── */

.quiz-block { background: var(--quiz-bg); border: 1px solid var(--quiz-border); border-radius: 8px; padding: 1rem 1.25rem; margin: 1rem 0; }
.quiz-header { font-size: 0.78rem; font-weight: 700; color: #7c3aed; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.75rem; }

.quiz-q { background: var(--quiz-q-bg); border: 1px solid var(--quiz-q-border); border-radius: 6px; padding: 0.75rem 1rem; margin: 0.5rem 0; }
.quiz-qtype { font-size: 0.72rem; color: #7c3aed; font-weight: 700; margin-bottom: 0.35rem; text-transform: uppercase; letter-spacing: 0.04em; }
.quiz-pts { font-size: 0.72rem; color: var(--text-muted); font-weight: 400; text-transform: none; letter-spacing: 0; margin-left: 0.4em; }

.choices { list-style: none; padding: 0; margin: 0.4rem 0 0; }
.choices li { padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.9rem; margin: 0.15rem 0; }
.c-yes { background: #f0fdf4; color: #166534; }
.c-no  { background: #fef2f2; color: #991b1b; }

/* ── Completion ───────────────────────────────────────────────────────────── */

.nav-done {
  flex-shrink: 0;
  font-size: 0.68rem;
  color: #22c55e;
  font-weight: 700;
  margin-left: 0.25rem;
}

.complete-bar {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.complete-btn {
  padding: 0.45rem 1.25rem;
  background: #16a34a;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background 0.12s;
}
.complete-btn:hover { background: #15803d; }

.complete-done {
  color: #22c55e;
  font-weight: 600;
  font-size: 0.875rem;
}

/* ── Interactive quiz ─────────────────────────────────────────────────────── */

.choices-interactive {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
}

.c-choice {
  padding: 0.3rem 0.75rem;
  border-radius: 5px;
  font-size: 0.9rem;
  margin: 0.2rem 0;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: background 0.1s;
  user-select: none;
}
.c-choice:hover:not(.c-chosen):not(.c-dim) { background: var(--sc-header-hover); }
.c-choice.c-chosen-yes { background: rgba(34,197,94,0.15);  border-color: #22c55e; color: #4ade80; cursor: default; }
.c-choice.c-chosen-no  { background: rgba(239,68,68,0.15);  border-color: #ef4444; color: #f87171; }
.c-choice.c-dim        { opacity: 0.35; cursor: default; }
.c-multi { display: flex; align-items: center; gap: 0.5rem; }
.c-checkbox { accent-color: #7c3aed; width: 1rem; height: 1rem; cursor: pointer; flex-shrink: 0; }

/* ── Order drag list ──────────────────────────────────────────────────────── */

.order-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
}

.order-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  margin: 0.25rem 0;
  background: var(--quiz-q-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: grab;
  user-select: none;
  font-size: 0.9rem;
  transition: background 0.1s, border-color 0.1s, opacity 0.1s;
}
.order-item:active { cursor: grabbing; }
.order-item.dragging { opacity: 0.35; }
.order-item.drag-over-top    { border-top: 2px solid #60a5fa; }
.order-item.drag-over-bottom { border-bottom: 2px solid #60a5fa; }
.order-item.order-correct { background: rgba(34,197,94,0.12); border-color: #22c55e; }
.order-item.order-wrong   { background: rgba(239,68,68,0.12);  border-color: #ef4444; }

.order-handle {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: grab;
}

/* ── Drag-slot question ───────────────────────────────────────────────────── */

.drag-slots {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
}

.drag-slot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.1rem;
  padding: 0.3rem 0.6rem;
  margin: 0.2rem 0;
  border: 1.5px dashed var(--border);
  border-radius: 5px;
  transition: border-color 0.12s, background 0.12s;
}
.drag-slot.drag-hover      { border-color: #60a5fa; background: rgba(96,165,250,0.07); }
.drag-slot.slot-empty-error { border-color: #ef4444; background: rgba(239,68,68,0.07); }
.drag-slot-fixed { border-style: solid; border-color: #22c55e; background: rgba(34,197,94,0.07); }

.slot-num {
  flex-shrink: 0;
  width: 1.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
}
.slot-placeholder { color: var(--text-muted); font-size: 0.85rem; font-style: italic; }
.slot-placeholder.hidden { display: none; }

.drag-slot .drag-item-placed {
  flex: 1;
  font-size: 0.875rem;
  cursor: grab;
  user-select: none;
  padding: 0.05rem 0;
}
.drag-slot .drag-item-placed:active { cursor: grabbing; }
.drag-slot .drag-item-placed.dragging { opacity: 0.35; }
.drag-slot .drag-item-placed.order-correct { color: #4ade80; }
.drag-slot .drag-item-placed.order-wrong   { color: #f87171; }
.drag-slot-fixed .drag-item-placed { cursor: default; color: #4ade80; }

.drag-pool-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin: 0.85rem 0 0.35rem;
}

.drag-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.5rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  min-height: 2.5rem;
}
.drag-pool.drag-hover { border-color: #60a5fa; background: rgba(96,165,250,0.05); }

.drag-item {
  padding: 0.25rem 0.65rem;
  background: var(--sc-header-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.855rem;
  cursor: grab;
  user-select: none;
  transition: opacity 0.1s;
}
.drag-item:active { cursor: grabbing; }
.drag-item.dragging { opacity: 0.35; }

.quiz-ack-btn {
  margin-top: 0.5rem;
  padding: 0.28rem 0.75rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.78rem;
  transition: background 0.12s, color 0.12s;
}
.quiz-ack-btn:hover:not(:disabled) { background: var(--sc-header-hover); color: #e2e8f0; }
.quiz-ack-btn:disabled { color: #22c55e; border-color: #22c55e; cursor: default; }

/* ── Misc ─────────────────────────────────────────────────────────────────── */

.loading { padding: 2rem; color: var(--text-muted); font-size: 0.95rem; }
.error   { color: #dc2626; padding: 1rem; }

/* ── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  #menu-toggle { display: block; }

  #sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,0.4);
  }
  #sidebar.open { transform: translateX(0); }

  #sidebar-secondary { display: none; }

  #content,
  #content.secondary-open { margin-left: 0; padding: 1rem 1.25rem; padding-top: 3.5rem; }
}
