/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Dark theme (default) */
:root {
  --bg:       #0f172a;
  --bg2:      #1e293b;
  --bg3:      #334155;
  --border:   #334155;
  --text:     #f1f5f9;
  --text2:    #94a3b8;
  --text3:    #64748b;
  --accent:   #6366f1;
  --accent2:  #818cf8;
  --green:    #22c55e;
  --red:      #ef4444;
  --yellow:   #f59e0b;
  --radius:   8px;
  --radius-lg: 12px;
  --shadow:   0 4px 24px rgba(0,0,0,.4);
  --nav-bg:   rgba(15,23,42,.92);
}

/* Light theme */
[data-theme="light"] {
  --bg:       #f8fafc;
  --bg2:      #f1f5f9;
  --bg3:      #e2e8f0;
  --border:   #cbd5e1;
  --text:     #0f172a;
  --text2:    #475569;
  --text3:    #64748b;
  --accent:   #4f46e5;
  --accent2:  #6366f1;
  --green:    #16a34a;
  --red:      #dc2626;
  --yellow:   #d97706;
  --shadow:   0 4px 24px rgba(0,0,0,.1);
  --nav-bg:   rgba(248,250,252,.95);
}

html { font-size: 17px; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent2); }

/* ── Topnav ── */
.topnav {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  height: 54px;
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

/* Theme toggle */
.theme-toggle {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; font-size: 1rem;
  transition: border-color .15s, background .15s;
  color: var(--text2);
}
.theme-toggle:hover { border-color: var(--accent); color: var(--text); }

.nav-brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 1rem;
  color: var(--text);
  flex-shrink: 0;
}
.brand-icon { font-size: 1.3rem; }

.nav-breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: .85rem; color: var(--text2);
  flex: 1;
}
.nav-breadcrumb a { color: var(--text2); }
.nav-breadcrumb a:hover { color: var(--accent2); }
.bc-sep { color: var(--text3); }
.bc-current { color: var(--text); font-weight: 500; }

/* Search bar in topnav */
.nav-search-form {
  flex: 1; max-width: 260px;
  display: flex; align-items: center;
}
.nav-search-input {
  width: 100%;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 12px;
  color: var(--text); font-size: .82rem; outline: none;
  transition: border-color .15s;
}
.nav-search-input:focus { border-color: var(--accent); }
.nav-search-input::placeholder { color: var(--text3); }

.nav-right {
  display: flex; align-items: center; gap: 8px;
  margin-left: auto; flex-shrink: 0;
}
.nav-home-link {
  font-size: .82rem;
  color: var(--text3);
  padding: 4px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.nav-home-link:hover { color: var(--text); border-color: var(--accent); }

/* ── Page content ── */
.page-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

/* ── Home ── */
.home-header { margin-bottom: 40px; }
.home-header h1 { font-size: 2rem; font-weight: 700; margin-bottom: 8px; }
.home-sub { color: var(--text2); max-width: 560px; }

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.topic-card {
  display: flex; align-items: center; gap: 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: border-color .15s, transform .1s;
  position: relative;
  overflow: hidden;
}
.topic-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.tc-icon { font-size: 2rem; flex-shrink: 0; }
.tc-body { flex: 1; min-width: 0; }
.tc-label-row { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.tc-label { font-weight: 600; font-size: 1rem; }
.tc-meta  { font-size: .78rem; color: var(--text3); margin-bottom: 8px; }

.tc-version {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 1px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  text-transform: uppercase;
}
.tc-version--v1       { background: #14532d; color: #86efac; border: 1px solid #166534; }
.tc-version--v1_draft { background: #1e3a5f; color: #93c5fd; border: 1px solid #1d4ed8; }
.tc-version--v0       { background: var(--bg3); color: var(--text3); border: 1px solid var(--border); }

.tc-bar-wrap { background: var(--bg3); border-radius: 4px; height: 5px; overflow: hidden; }
.tc-bar { background: var(--accent); height: 100%; border-radius: 4px; transition: width .3s; }

.tc-badge {
  position: absolute; top: 12px; right: 12px;
  font-size: .72rem; font-weight: 600;
  padding: 2px 7px; border-radius: 99px;
}
.tc-badge.done       { background: rgba(34,197,94,.15); color: var(--green); border: 1px solid rgba(34,197,94,.3); }
.tc-badge.in-progress { background: rgba(99,102,241,.15); color: var(--accent2); border: 1px solid rgba(99,102,241,.3); }

/* ── Course overview ── */
.course-header { margin-bottom: 36px; }
.course-title-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.course-icon { font-size: 2rem; }
.course-title-row h1 { font-size: 1.8rem; font-weight: 700; }

.course-progress-summary { display: flex; align-items: center; gap: 14px; }
.progress-bar-wrap {
  flex: 1; max-width: 340px;
  background: var(--bg3); border-radius: 6px; height: 8px; overflow: hidden;
}
.progress-bar { background: var(--accent); height: 100%; border-radius: 6px; transition: width .4s; }
.progress-label { font-size: .82rem; color: var(--text2); white-space: nowrap; }

.cluster-section { margin-bottom: 36px; }
.cluster-heading {
  font-size: 1rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text2);
  border-left: 3px solid var(--accent);
  padding-left: 10px; margin-bottom: 12px;
}

.lesson-cards { display: flex; flex-direction: column; gap: 6px; }

.lesson-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color .15s;
}
.lesson-card:hover { border-color: var(--accent); }
.lesson-card.completed { border-left: 3px solid var(--green); }
.lesson-card.tier-interesting { border-style: dashed; }
.lesson-card.tier-practical { border-style: solid; }

.lc-index {
  font-size: .75rem; color: var(--text3);
  width: 28px; flex-shrink: 0; text-align: right;
}
.lc-body { flex: 1; min-width: 0; }
.lc-label { font-weight: 500; font-size: .92rem; display: flex; align-items: center; gap: 5px; }
.lc-diagram-badge { font-size: .7rem; color: var(--accent2); opacity: .8; flex-shrink: 0; }
.lc-desc  { font-size: .78rem; color: var(--text3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.lc-status { flex-shrink: 0; }
.status-dot {
  width: 18px; height: 18px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .7rem;
}
.status-dot.done    { background: rgba(34,197,94,.15); color: var(--green); }
.status-dot.pending { background: var(--bg3); }

/* ── Lesson layout ── */
.lesson-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 40px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

@media (max-width: 768px) {
  .lesson-layout { grid-template-columns: 1fr; }
  .lesson-nav { display: flex; flex-wrap: wrap; gap: 8px; }
}

/* ── Lesson nav sidebar ── */
.lesson-nav {
  display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 70px;
  align-self: start;
}

.ln-progress {
  font-size: .76rem; color: var(--text3);
  text-align: center; padding: 6px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg2);
}

.ln-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .82rem; color: var(--text2);
  cursor: pointer; text-align: left;
  transition: border-color .15s, color .15s;
}
.ln-btn:hover { border-color: var(--accent); color: var(--text); }
.ln-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ln-btn.complete-btn { color: var(--text2); justify-content: center; font-weight: 500; }
.ln-btn.complete-btn.is-done { color: var(--green); border-color: rgba(34,197,94,.4); background: rgba(34,197,94,.07); }
.ln-btn.quiz-btn { color: var(--accent2); border-color: rgba(99,102,241,.4); justify-content: space-between; }
.quiz-score-chip {
  font-size: .72rem; padding: 1px 6px;
  background: rgba(99,102,241,.2); border-radius: 99px;
}

.ln-divider { border-top: 1px solid var(--border); margin: 4px 0; }

/* ── Lesson content ── */
.lesson-content { min-width: 0; }

.lesson-header { margin-bottom: 28px; }
.lesson-cluster-tag {
  display: inline-block;
  font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
  padding: 3px 10px; border-radius: 99px;
  border: 1px solid transparent;
  margin-bottom: 10px;
}
.lesson-title { font-size: 1.9rem; font-weight: 700; line-height: 1.25; margin-bottom: 8px; }

.tier-badge {
  display: inline-block; font-size: .72rem; font-weight: 600;
  padding: 2px 8px; border-radius: 4px;
  text-transform: uppercase; letter-spacing: .04em;
}
.tier-badge.tier-core        { background: rgba(99,102,241,.15); color: var(--accent2); }
.tier-badge.tier-practical   { background: rgba(34,197,94,.12);  color: #4ade80; }
.tier-badge.tier-interesting { background: rgba(245,158,11,.12); color: #fbbf24; }

.lesson-desc { margin-bottom: 28px; font-size: 1.02rem; color: var(--text2); line-height: 1.75; }

.lesson-details { margin-bottom: 28px; }
.lesson-details h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 12px; color: var(--text); }
.details-list {
  list-style: none;
  display: flex; flex-direction: column; gap: 8px;
}
.details-list li {
  padding: 10px 14px 10px 20px;
  background: var(--bg2);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
  font-size: .92rem; color: var(--text2); line-height: 1.6;
  position: relative;
}

.lesson-section {
  margin-bottom: 32px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}
.lesson-section:last-of-type { border-bottom: none; }
.lesson-section-title {
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--accent);
  margin-bottom: 10px;
}
.lesson-section-body {
  font-size: 1rem;
  color: var(--text2);
  line-height: 1.75;
  margin-bottom: 14px;
}
.section-points-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.section-points-list li {
  padding: 9px 14px 9px 18px;
  background: var(--bg2);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
  font-size: .91rem;
  color: var(--text2);
  line-height: 1.6;
}

.lesson-relations { margin-bottom: 20px; }
.lesson-relations h3 { font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text3); margin-bottom: 8px; }
.relation-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.rel-chip {
  padding: 4px 12px; border-radius: 99px; font-size: .8rem; font-weight: 500;
  border: 1px solid var(--border);
  transition: border-color .15s;
}
.rel-chip:hover { border-color: var(--accent); color: var(--text); }
.rel-chip.prereq { background: rgba(99,102,241,.08); }
.rel-chip.next   { background: rgba(34,197,94,.08); }

.lesson-links { margin-bottom: 32px; }
.lesson-links h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 12px; }
.links-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.ext-link {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .88rem; color: var(--accent2);
  padding: 6px 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s;
}
.ext-link:hover { border-color: var(--accent2); color: var(--text); }
.link-icon { font-size: .8rem; opacity: .7; }

/* ── Inline Diagrams ── */
.lesson-diagram { margin-bottom: 28px; }
.lesson-diagram h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 12px; }
.diagram-container {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  overflow-x: auto;
  text-align: center;
}
.diagram-container svg { max-width: 100%; height: auto; }

.diagram-section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.diagram-section-header h2 { margin-bottom: 0; }
.btn-diagram-expand {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: var(--radius);
  padding: 4px 12px;
  font-size: .8rem;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-diagram-expand:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Diagram fullscreen modal ── */
.diagram-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.diagram-modal[hidden] { display: none; }
.diagram-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.75); backdrop-filter: blur(4px); }
.diagram-modal-panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 95vw;
  height: 90vh;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.diagram-modal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.diagram-modal-title { font-weight: 600; font-size: .95rem; }
.diagram-modal-controls { display: flex; align-items: center; gap: 6px; }
.btn-dm {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 11px;
  font-size: 1rem;
  line-height: 1.4;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-dm:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-dm-close:hover { background: var(--red); border-color: var(--red); }
.dm-zoom-label { font-size: .8rem; color: var(--text2); min-width: 44px; text-align: center; }
.dm-viewport {
  flex: 1;
  overflow: hidden;
  cursor: grab;
  position: relative;
  user-select: none;
}
.dm-viewport.dragging { cursor: grabbing; }
.dm-inner { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.dm-inner svg { display: block; }

/* ── Notes ── */
.lesson-notes { margin-top: 36px; padding-top: 28px; border-top: 1px solid var(--border); }
.lesson-notes h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 12px; }
#note-editor {
  width: 100%; min-height: 120px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
  color: var(--text); font-family: inherit; font-size: .9rem; line-height: 1.6;
  resize: vertical; outline: none;
  transition: border-color .15s;
}
#note-editor:focus { border-color: var(--accent); }
.note-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.note-status { font-size: .78rem; color: var(--text3); }
.btn-save {
  padding: 7px 18px;
  background: var(--accent); color: white; border: none;
  border-radius: var(--radius); font-size: .85rem; font-weight: 500;
  cursor: pointer; transition: background .15s;
}
.btn-save:hover { background: var(--accent2); }

/* ── Bottom nav ── */
.lesson-bottom-nav {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--border);
  gap: 12px;
}

.btn-nav {
  display: inline-flex; align-items: center;
  padding: 10px 20px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .88rem; color: var(--text2);
  transition: border-color .15s, color .15s;
}
.btn-nav:hover { border-color: var(--accent); color: var(--text); }
.btn-quiz {
  display: inline-flex; align-items: center;
  padding: 10px 24px;
  background: var(--accent); color: white; border: none;
  border-radius: var(--radius); font-size: .88rem; font-weight: 600;
  transition: background .15s;
}
.btn-quiz:hover { background: var(--accent2); color: white; }

/* ── Quiz page ── */
.quiz-page { max-width: 740px; }
.quiz-header { margin-bottom: 28px; }
.quiz-cluster-tag {
  display: inline-block; font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  padding: 3px 10px; border-radius: 99px;
  margin-bottom: 10px;
}
.quiz-header h1 { font-size: 1.7rem; font-weight: 700; margin-bottom: 4px; }
.quiz-sub { font-size: .85rem; color: var(--text3); }

/* Result banner */
.quiz-result-banner {
  border-radius: var(--radius-lg);
  padding: 24px 28px; margin-bottom: 28px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 16px;
}
.quiz-result-banner.pass { background: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.3); }
.quiz-result-banner.fail { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.25); }
.qr-score { font-size: 2rem; font-weight: 700; flex-shrink: 0; }
.qr-label { flex: 1; font-size: .95rem; }
.qr-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-retry { padding: 8px 18px; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); font-size: .85rem; }
.btn-next-lesson { padding: 8px 18px; background: var(--accent); color: white; border-radius: var(--radius); font-size: .85rem; font-weight: 600; }

/* Quiz history */
.quiz-history {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 24px; font-size: .82rem; color: var(--text3);
}
.hist-best { font-weight: 600; color: var(--text2); margin-right: 4px; }
.hist-chip {
  padding: 2px 8px; border-radius: 99px; font-size: .76rem; font-weight: 600;
}
.hist-chip.pass { background: rgba(34,197,94,.12); color: var(--green); }
.hist-chip.fail { background: rgba(239,68,68,.1); color: #f87171; }

/* Question card */
.quiz-question {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 16px;
  display: flex; gap: 16px;
}
.quiz-question.correct   { border-left: 3px solid var(--green); }
.quiz-question.incorrect { border-left: 3px solid var(--red); }

.q-number {
  font-size: .75rem; font-weight: 700; color: var(--accent2);
  flex-shrink: 0; padding-top: 3px; width: 28px; text-align: right;
}
.q-body { flex: 1; min-width: 0; }
.q-text { font-size: .95rem; font-weight: 500; margin-bottom: 14px; line-height: 1.5; }

.q-options { display: flex; flex-direction: column; gap: 8px; }
.q-option {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--bg3);
  border-radius: var(--radius);
  font-size: .88rem; cursor: pointer;
  transition: background .12s;
}
.q-option:has(input:not([disabled])):hover { background: var(--bg3); filter: brightness(1.08); }
.q-option input[type="radio"] { accent-color: var(--accent); }
.q-option.opt-correct  { background: rgba(34,197,94,.15); color: var(--green); }
.q-option.opt-wrong    { background: rgba(239,68,68,.1); color: #f87171; }
.q-options.tf { flex-direction: row; }

.q-open {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  color: var(--text); font-family: inherit; font-size: .9rem; resize: vertical; outline: none;
  transition: border-color .15s;
}
.q-open:focus { border-color: var(--accent); }

.q-feedback {
  margin-top: 12px; padding: 10px 14px;
  border-radius: var(--radius); font-size: .85rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}
.q-feedback.correct   { background: rgba(34,197,94,.1); }
.q-feedback.incorrect { background: rgba(239,68,68,.08); }
.q-verdict { font-weight: 600; }
.q-feedback.correct   .q-verdict { color: var(--green); }
.q-feedback.incorrect .q-verdict { color: #f87171; }
.q-explanation { width: 100%; margin-top: 6px; color: var(--text2); font-size: .83rem; }

.quiz-submit-row { margin-top: 24px; display: flex; justify-content: center; }
.btn-submit {
  padding: 13px 40px;
  background: var(--accent); color: white; border: none;
  border-radius: var(--radius); font-size: .95rem; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.btn-submit:hover { background: var(--accent2); }

.quiz-bottom-nav {
  display: flex; justify-content: space-between; margin-top: 36px;
  padding-top: 24px; border-top: 1px solid var(--border);
}

/* ── Error page ── */
.error-box {
  text-align: center; padding: 80px 24px;
}
.error-code { font-size: 3rem; font-weight: 800; color: var(--text3); margin-bottom: 12px; }
.error-msg  { font-size: 1.1rem; color: var(--text2); margin-bottom: 28px; }

/* ── Exam page ── */
.exam-page { max-width: 800px; }
.exam-header { margin-bottom: 28px; }

.exam-type-badge {
  display: inline-block; font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  padding: 4px 12px; border-radius: 99px; margin-bottom: 12px;
}
.exam-type-badge.intermediate { background: rgba(245,158,11,.15); color: var(--yellow); border: 1px solid rgba(245,158,11,.3); }
.exam-type-badge.final        { background: rgba(99,102,241,.15); color: var(--accent2); border: 1px solid rgba(99,102,241,.3); }

.exam-header h1   { font-size: 1.8rem; font-weight: 700; margin-bottom: 6px; }
.exam-sub         { font-size: .85rem; color: var(--text3); margin-bottom: 8px; }
.exam-desc        { font-size: .9rem; color: var(--text2); max-width: 620px; line-height: 1.6; }

.exam-result-banner {
  border-radius: var(--radius-lg); padding: 24px 28px; margin-bottom: 28px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 16px;
}
.exam-result-banner.pass { background: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.3); }
.exam-result-banner.fail { background: rgba(239,68,68,.1);  border: 1px solid rgba(239,68,68,.25); }
.er-score  { font-size: 2.4rem; font-weight: 800; flex-shrink: 0; }
.er-body   { flex: 1; }
.er-pct    { font-size: 1.1rem; font-weight: 700; }
.er-label  { font-size: .9rem; color: var(--text2); }
.er-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-retry       { padding: 8px 18px; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); font-size: .85rem; }
.btn-back-course { padding: 8px 18px; background: var(--accent); color: white; border-radius: var(--radius); font-size: .85rem; font-weight: 600; }

/* Exam buttons on course overview */
.cluster-exam-row {
  display: flex; justify-content: flex-end;
  margin-top: 8px; margin-bottom: 24px;
}
.btn-cluster-exam {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 16px; font-size: .82rem; font-weight: 600;
  background: rgba(245,158,11,.1); color: var(--yellow);
  border: 1px solid rgba(245,158,11,.3); border-radius: var(--radius);
  transition: background .15s;
}
.btn-cluster-exam:hover { background: rgba(245,158,11,.2); color: var(--yellow); }

.course-final-exam {
  margin-top: 40px; padding: 28px;
  background: var(--bg2); border: 1px solid rgba(99,102,241,.3);
  border-radius: var(--radius-lg); text-align: center;
}
.course-final-exam h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; }
.course-final-exam p  { font-size: .88rem; color: var(--text2); margin-bottom: 18px; }
.btn-final-exam {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 32px; font-size: .95rem; font-weight: 700;
  background: var(--accent); color: white; border-radius: var(--radius);
  transition: background .15s;
}
.btn-final-exam:hover { background: var(--accent2); color: white; }

/* ── Progress page ── */
.progress-page h1 { font-size: 1.9rem; font-weight: 700; margin-bottom: 8px; }
.progress-page .page-sub { color: var(--text2); margin-bottom: 36px; }

.progress-topic {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px 28px; margin-bottom: 20px;
}
.pt-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; flex-wrap: wrap; gap: 10px;
}
.pt-title { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; font-weight: 600; }
.pt-icon  { font-size: 1.4rem; }
.pt-stats  { font-size: .82rem; color: var(--text3); }

.pt-bar-wrap { background: var(--bg3); border-radius: 6px; height: 7px; overflow: hidden; margin-bottom: 16px; }
.pt-bar      { background: var(--accent); height: 100%; border-radius: 6px; transition: width .4s; }

.pt-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn-reset-topic {
  padding: 6px 14px; font-size: .8rem;
  background: transparent; border: 1px solid var(--red);
  color: var(--red); border-radius: var(--radius); cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-reset-topic:hover { background: var(--red); color: white; }

.pt-lessons { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.pt-lesson-chip {
  padding: 3px 10px; font-size: .78rem;
  background: rgba(34,197,94,.1); color: var(--green);
  border: 1px solid rgba(34,197,94,.25); border-radius: 99px;
}

.progress-global-actions {
  display: flex; justify-content: flex-end; margin-bottom: 28px;
}
.btn-reset-all {
  padding: 9px 20px; font-size: .88rem; font-weight: 600;
  background: transparent; border: 1px solid var(--red);
  color: var(--red); border-radius: var(--radius); cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-reset-all:hover { background: var(--red); color: white; }

/* ── Study links (quiz & exam feedback) ── */
.q-study-links {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 10px;
}
.q-study-link {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .8rem; padding: 4px 10px;
  border-radius: var(--radius); border: 1px solid var(--border);
  transition: border-color .15s;
}
.q-study-link.internal { color: var(--accent2); background: rgba(99,102,241,.08); border-color: rgba(99,102,241,.25); }
.q-study-link.internal:hover { border-color: var(--accent2); }
.q-study-link.external { color: var(--text3); }
.q-study-link.external:hover { color: var(--text); border-color: var(--border); }

/* ── Auth pages (login, setup) ── */
.auth-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
}
.auth-brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 1rem;
  margin-bottom: 28px;
}
.auth-brand-icon { font-size: 1.5rem; }
.auth-brand-name { color: var(--text); }
.auth-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 6px; }
.auth-sub   { font-size: .85rem; color: var(--text2); margin-bottom: 20px; }
.auth-error {
  background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3);
  color: #f87171; border-radius: var(--radius);
  padding: 10px 14px; font-size: .85rem; margin-bottom: 16px;
}
.auth-success {
  background: rgba(34,197,94,.1); border: 1px solid rgba(34,197,94,.3);
  color: var(--green); border-radius: var(--radius);
  padding: 10px 14px; font-size: .85rem;
}
.auth-form { display: flex; flex-direction: column; gap: 16px; margin-top: 20px; }
.auth-label { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--text2); }
.auth-input {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px;
  color: var(--text); font-size: .95rem; outline: none;
  transition: border-color .15s;
}
.auth-input:focus { border-color: var(--accent); }
.auth-btn {
  padding: 12px; background: var(--accent); color: white;
  border: none; border-radius: var(--radius);
  font-size: .95rem; font-weight: 600; cursor: pointer;
  transition: background .15s; margin-top: 4px;
}
.auth-btn:hover { background: var(--accent2); }

/* ── Topnav user / logout ── */
.nav-user {
  font-size: .8rem; color: var(--text2);
  padding: 4px 8px; border-radius: var(--radius);
  background: var(--bg2); border: 1px solid var(--border);
}
.nav-logout {
  font-size: .8rem; color: var(--text3);
  padding: 4px 10px; border-radius: var(--radius);
  background: transparent; border: 1px solid var(--border);
  cursor: pointer; transition: color .15s, border-color .15s;
}
.nav-logout:hover { color: var(--red); border-color: var(--red); }

/* ── Admin panel ── */
.admin-section { margin-bottom: 36px; }
.admin-section-title {
  font-size: .88rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text2);
  border-left: 3px solid var(--accent); padding-left: 10px; margin-bottom: 14px;
}
.admin-form-row {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
}
.admin-input {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 9px 12px;
  color: var(--text); font-size: .88rem; outline: none; flex: 1; min-width: 140px;
  transition: border-color .15s;
}
.admin-input:focus { border-color: var(--accent); }
.admin-select { cursor: pointer; flex: 0 0 auto; }
.btn-admin-create {
  padding: 9px 18px; background: var(--accent); color: white;
  border: none; border-radius: var(--radius); font-size: .88rem; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: background .15s;
}
.btn-admin-create:hover { background: var(--accent2); }

.admin-user-list { display: flex; flex-direction: column; gap: 8px; }
.admin-user-row {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.admin-user-info { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.admin-username  { font-weight: 600; font-size: .95rem; }
.admin-role-badge {
  font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 99px;
  text-transform: uppercase; letter-spacing: .05em;
}
.admin-role-badge.role-admin { background: rgba(99,102,241,.15); color: var(--accent2); border: 1px solid rgba(99,102,241,.3); }
.admin-role-badge.role-user  { background: var(--bg3); color: var(--text3); border: 1px solid var(--border); }
.admin-joined    { font-size: .78rem; color: var(--text3); }
.admin-user-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-inline-form  { display: flex; align-items: center; gap: 6px; }
.admin-input-sm {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 10px;
  color: var(--text); font-size: .8rem; outline: none; width: 140px;
  transition: border-color .15s;
}
.admin-input-sm:focus { border-color: var(--accent); }
.btn-admin-sm {
  padding: 6px 12px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .8rem; color: var(--text2); cursor: pointer;
  white-space: nowrap; transition: border-color .15s;
}
.btn-admin-sm:hover { border-color: var(--accent); color: var(--text); }
.btn-admin-delete {
  padding: 6px 12px; background: transparent; border: 1px solid var(--red);
  color: var(--red); border-radius: var(--radius); font-size: .8rem; cursor: pointer;
  white-space: nowrap; transition: background .15s, color .15s;
}
.btn-admin-delete:hover { background: var(--red); color: white; }

/* ── Tags ── */
.tag-pill {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: .72rem; font-weight: 500;
  background: rgba(99,102,241,.1); color: var(--accent2);
  border: 1px solid rgba(99,102,241,.2);
}
.tag-pill-sm {
  display: inline-block; padding: 1px 6px; border-radius: 99px;
  font-size: .68rem; color: var(--text3);
  background: var(--bg3); border: 1px solid var(--border);
}
.lc-tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }

/* Course header graph button */
.btn-view-graph {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 12px; font-size: .8rem; font-weight: 600;
  border: 1px solid var(--accent); color: var(--accent2);
  border-radius: var(--radius); background: rgba(99,102,241,.08);
  transition: background .15s; margin-left: 8px;
}
.btn-view-graph:hover { background: rgba(99,102,241,.18); color: var(--accent2); }

/* Course tag filter bar */
.course-tag-filter {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  margin-top: 14px;
}
.tag-filter-label { font-size: .78rem; color: var(--text3); flex-shrink: 0; }
.tag-filter-btn {
  padding: 3px 10px; border-radius: 99px; font-size: .75rem; font-weight: 500;
  border: 1px solid var(--border); background: var(--bg2); color: var(--text2);
  cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.tag-filter-btn:hover { border-color: var(--accent2); color: var(--text); }
.tag-filter-btn.active { background: var(--accent); border-color: var(--accent); color: white; }

/* Graph button in lesson sidebar */
.ln-btn.graph-btn { color: var(--accent2); border-color: rgba(99,102,241,.35); }
.ln-btn.graph-btn:hover { background: rgba(99,102,241,.1); }

/* ── Search page ── */
.search-header { margin-bottom: 28px; }
.search-title { font-size: 1.5rem; font-weight: 700; }
.search-count { color: var(--accent2); }
.search-empty { padding: 48px 0; color: var(--text2); }
.search-empty p { margin-bottom: 8px; }
.search-hint { font-size: .88rem; color: var(--text3); }
.search-hint a { color: var(--accent2); }
.search-topic-group { margin-bottom: 36px; }
.search-topic-heading {
  display: flex; align-items: center; gap: 8px;
  font-size: 1rem; font-weight: 600; margin-bottom: 12px;
  border-left: 3px solid var(--accent); padding-left: 10px;
}
.search-topic-count {
  font-size: .75rem; padding: 1px 7px; border-radius: 99px;
  background: rgba(99,102,241,.15); color: var(--accent2);
}
.search-results { display: flex; flex-direction: column; gap: 8px; }
.search-result-card {
  display: block; padding: 14px 16px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); transition: border-color .15s;
}
.search-result-card:hover { border-color: var(--accent); }
.src-cluster-tag {
  display: inline-block; font-size: .68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em;
  padding: 2px 8px; border-radius: 99px; margin-bottom: 6px;
}
.src-label { font-size: .95rem; font-weight: 600; margin-bottom: 4px; }
.src-desc  { font-size: .82rem; color: var(--text2); line-height: 1.5; margin-bottom: 6px; }
.src-tags  { display: flex; flex-wrap: wrap; gap: 4px; }

/* ── Term definition links & tooltip ── */
.term-link {
  text-decoration: underline;
  text-decoration-style: dashed;
  text-decoration-color: var(--accent2);
  text-underline-offset: 3px;
  color: inherit;
  cursor: pointer;
}
.term-link:hover { color: var(--accent2); }

.term-tooltip {
  position: fixed;
  max-width: 320px;
  width: max-content;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  z-index: 1000;
  box-shadow: var(--shadow);
  line-height: 1.5;
  animation: tt-in .12s ease;
}
@keyframes tt-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.tt-title {
  font-weight: 600;
  font-size: .95rem;
  color: var(--text);
  margin-bottom: 6px;
}
.tt-desc {
  font-size: .84rem;
  color: var(--text2);
  line-height: 1.6;
  margin-bottom: 10px;
}
.tt-link {
  font-size: .8rem;
  color: var(--accent2);
  text-decoration: none;
}
.tt-link:hover { text-decoration: underline; }
.tt-loading { font-size: .84rem; color: var(--text3); }

/* Mobile: term tooltip as bottom sheet */
@media (max-width: 600px) {
  .term-tooltip {
    position: fixed;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    max-width: 100%;
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 20px 20px 32px;
    animation: tt-slide-up .18s ease;
  }
  @keyframes tt-slide-up {
    from { transform: translateY(30px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }
}

/* ── Responsive ── */

/* Tablet (≤900px) */
@media (max-width: 900px) {
  .lesson-layout {
    grid-template-columns: 190px 1fr;
    gap: 24px;
    padding: 24px 16px 60px;
  }
  .page-content { padding: 24px 16px 60px; }
}

/* Mobile + Tablet (≤768px) */
@media (max-width: 768px) {
  html { font-size: 16px; }

  .topnav { padding: 0 16px; gap: 8px; }
  .nav-search-form { max-width: 160px; }
  .nav-breadcrumb { flex: 1; min-width: 0; overflow: hidden; }
  .bc-current {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    display: inline-block; max-width: 160px; vertical-align: bottom;
  }

  .page-content { padding: 20px 16px 60px; }
  .home-header h1 { font-size: 1.7rem; }

  .topic-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }

  .lesson-layout {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 16px 16px 60px;
  }
  .lesson-nav {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 16px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
  }
  .ln-progress { flex: 0 0 auto; }
  .ln-btn { flex: 1 1 auto; min-width: 110px; justify-content: center; min-height: 44px; }
  .ln-divider { display: none; }

  .lesson-title { font-size: 1.55rem; }

  .quiz-question { padding: 16px; }
  .quiz-result-banner, .exam-result-banner { padding: 18px 20px; }

  .lesson-bottom-nav { flex-wrap: wrap; gap: 10px; }
  .btn-nav, .btn-quiz { flex: 1 1 45%; justify-content: center; min-height: 44px; text-align: center; }

  .course-title-row h1 { font-size: 1.4rem; }

  .progress-topic { padding: 18px 20px; }
  .pt-header { flex-direction: column; align-items: flex-start; gap: 6px; }

  .quiz-page { max-width: 100%; }
  .exam-page { max-width: 100%; }
}

/* Mobile only (≤480px) */
@media (max-width: 480px) {
  html { font-size: 15px; }

  .topnav { padding: 0 12px; height: 50px; gap: 6px; }
  .nav-search-form { max-width: 110px; }
  .brand-name { display: none; }
  .nav-home-link { font-size: .75rem; padding: 4px 8px; }
  .bc-current { max-width: 110px; }
  .nav-breadcrumb { font-size: .78rem; }

  .home-header h1 { font-size: 1.45rem; }
  .topic-grid { grid-template-columns: 1fr; }
  .topic-card { padding: 14px 16px; }

  .lesson-layout { padding: 12px 12px 50px; }
  .ln-btn { font-size: .78rem; padding: 8px 10px; min-height: 44px; }
  .ln-progress { font-size: .72rem; }

  .lesson-title { font-size: 1.3rem; }
  .lesson-cluster-tag { font-size: .68rem; }
  .lesson-desc { font-size: .95rem; }

  .quiz-header h1, .exam-header h1 { font-size: 1.3rem; }
  .quiz-question { flex-direction: column; gap: 6px; padding: 14px; }
  .q-number { text-align: left; width: auto; }
  .q-options.tf { flex-direction: column; }
  .btn-submit { padding: 12px 20px; width: 100%; }
  .quiz-submit-row { margin-top: 16px; }

  .lesson-bottom-nav { flex-direction: column; }
  .btn-nav, .btn-quiz { width: 100%; text-align: center; justify-content: center; min-height: 44px; }

  .diagram-container { padding: 12px; }

  .er-score { font-size: 1.8rem; }
  .qr-score { font-size: 1.8rem; }

  .course-final-exam { padding: 20px 16px; }
  .btn-final-exam { padding: 10px 20px; font-size: .88rem; }

  .progress-global-actions { justify-content: stretch; }
  .btn-reset-all { width: 100%; text-align: center; }
}
