/* ─── DARK MODE (Default) ─── */
:root {
  --bg:           #09090b;
  --surface:      #111113;
  --card:         #18181b;
  --border:       #27272a;
  --border-light: #3f3f46;
  --text:         #fafafa;
  --muted:        #a1a1aa;
  --dim:          #52525b;
  --accent:       #6366f1;
  --accent2:      #818cf8;
  --accent3:      #a5b4fc;
  --green:        #22c55e;
  --amber:        #f59e0b;
  --coral:        #f97316;
  --pink:         #ec4899;
  --teal:         #14b8a6;
  --shadow:       0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:    0 4px 12px rgba(0,0,0,0.5);
  --topbar-height: 48px;
}

/* ─── LIGHT MODE ─── */
.light, [data-theme="light"] {
  --bg:           #fafaf9;
  --surface:      #f4f4f5;
  --card:         #ffffff;
  --border:       #e4e4e7;
  --border-light: #d4d4d8;
  --text:         #09090b;
  --muted:        #52525b;
  --dim:          #a1a1aa;
  --shadow:       0 1px 3px rgba(0,0,0,0.06);
  --shadow-md:    0 4px 12px rgba(0,0,0,0.08);
  --green-text:   #15803d;
  --amber-text:   #b45309;
}

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

html { font-size: 15px; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background-color 0.2s ease, color 0.2s ease;
  overflow-x: hidden;
}

/* ─── TOPBAR ─── */
.site-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.topbar-inner {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 20px;
  gap: 16px;
  max-width: 100%;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  flex-shrink: 0;
}

.topbar-logo-mark {
  width: 26px;
  height: 26px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: .02em;
  flex-shrink: 0;
}

.topbar-logo-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  overflow: hidden;
}

.topbar-bc-link {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color .15s;
}

.topbar-bc-link:hover { color: var(--text); }

.topbar-bc-sep {
  font-size: 12px;
  color: var(--dim);
}

.topbar-bc-current {
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  transition: border-color .15s, color .15s;
  flex-shrink: 0;
}

.topbar-theme-toggle:hover { border-color: var(--border-light); color: var(--text); }

.icon-light { display: none; }
.icon-dark  { display: inline; }
.light .icon-dark  { display: none; }
.light .icon-light { display: inline; }

.topbar-request {
  font-size: 12px;
  color: var(--accent2);
  text-decoration: none;
  white-space: nowrap;
  padding: 5px 10px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}

.topbar-request:hover { background: rgba(99,102,241,.1); color: var(--accent3); }

/* ─── APP LAYOUT ─── */
.app-layout {
  display: flex;
  height: calc(100vh - var(--topbar-height));
  margin-top: var(--topbar-height);
  overflow: hidden;
}

/* ─── SIDEBAR ─── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: calc(100vh - var(--topbar-height));
  position: sticky;
  top: var(--topbar-height);
}

.sidebar-label {
  padding: 14px 16px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--dim);
  flex-shrink: 0;
}

#toc-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 0 8px;
}

#toc-nav::-webkit-scrollbar { width: 3px; }
#toc-nav::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }
#toc-nav::-webkit-scrollbar-track { background: transparent; }

/* TOC Items */
.toc-item { border-bottom: 1px solid transparent; }

a.toc-header {
  text-decoration: none;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background .12s, color .12s;
  border-left: 2px solid transparent;
}

a.toc-header:hover {
  background: rgba(255,255,255,.04);
  color: var(--text);
}

.light a.toc-header:hover { background: rgba(0,0,0,.04); }

a.toc-header.active {
  color: var(--accent2);
  border-left-color: var(--accent);
  background: rgba(99,102,241,.08);
}

.toc-icon { font-size: 14px; flex-shrink: 0; width: 18px; }
.toc-label { flex: 1; }
.toc-chevron { font-size: 9px; color: var(--dim); transition: transform .2s; margin-left: 4px; }
.toc-item.open > a.toc-header .toc-chevron { transform: rotate(90deg); }

/* Subtopics */
.toc-subs {
  overflow: hidden;
  max-height: 0;
  transition: max-height .25s ease;
}

.toc-item.open .toc-subs { max-height: 1200px; }

a.toc-sub {
  text-decoration: none;
  color: inherit;
  display: flex;
  align-items: center;
  padding: 5px 14px 5px 40px;
  font-size: 12px;
  color: var(--dim);
  cursor: pointer;
  transition: background .12s, color .12s;
  border-left: 2px solid transparent;
  margin-left: 0;
}

a.toc-sub:hover {
  background: rgba(255,255,255,.03);
  color: var(--muted);
}

.light a.toc-sub:hover { background: rgba(0,0,0,.03); }

a.toc-sub.active {
  color: var(--accent2);
  border-left-color: var(--accent);
  background: rgba(99,102,241,.06);
  font-weight: 500;
}

/* Sidebar footer / progress */
.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--dim);
  margin-bottom: 5px;
}

.progress-bar {
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width .4s ease;
}

/* ─── MAIN CONTENT ─── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 48px 64px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 900px) {
  .main-content { padding: 24px 20px 48px; }
}

.main-header {
  margin-bottom: 4px;
}

.breadcrumb {
  font-size: 12px;
  color: var(--dim);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.breadcrumb .bc-active { color: var(--muted); }

/* ─── CONTENT TYPOGRAPHY ─── */
.content-container {
  padding-top: 8px;
}

.content-container h1 {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.2;
}

.content-container h2 {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text);
  margin: 32px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.content-container h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin: 22px 0 8px;
}

.content-container h4 {
  font-size: .95rem;
  font-weight: 600;
  color: var(--muted);
  margin: 16px 0 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: .8rem;
}

.body-text {
  font-size: .95rem;
  color: var(--muted);
  line-height: 1.75;
  margin-bottom: 14px;
}

/* ─── DIFFICULTY BADGE ─── */
.difficulty-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  margin-bottom: 20px;
  border: 1px solid;
}

.difficulty-badge.beginner {
  background: rgba(34,197,94,.1);
  border-color: rgba(34,197,94,.3);
  color: var(--green);
}

.difficulty-badge.intermediate {
  background: rgba(245,158,11,.1);
  border-color: rgba(245,158,11,.3);
  color: var(--amber);
}

.difficulty-badge.advanced {
  background: rgba(249,115,22,.1);
  border-color: rgba(249,115,22,.3);
  color: var(--coral);
}

/* ─── CODE BLOCKS ─── */
.code-block {
  background: #18181b;
  border: 1px solid #27272a;
  border-radius: 8px;
  margin: 16px 0;
  overflow: hidden;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

.light .code-block { background: #18181b; border-color: #27272a; }

.code-header {
  background: #111113;
  border-bottom: 1px solid #27272a;
  padding: 6px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.light .code-header { background: #111113; border-color: #27272a; }

.code-lang {
  font-size: 11px;
  font-weight: 600;
  color: #a1a1aa;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.code-block pre {
  padding: 16px 20px;
  overflow-x: auto;
  margin: 0;
}

.code-block code {
  font-size: .84rem;
  color: #fafafa;
  line-height: 1.7;
  font-family: inherit;
  white-space: pre;
}

.light .code-block code { color: #fafafa; }

/* ─── INFO / WARNING CALLOUTS ─── */
.callout {
  border-radius: 8px;
  padding: 14px 16px;
  margin: 16px 0;
  border-left: 3px solid;
  font-size: .9rem;
}

.callout-tip   { background: rgba(34,197,94,.07); border-color: var(--green); }
.callout-warn  { background: rgba(245,158,11,.07); border-color: var(--amber); }
.callout-info  { background: rgba(99,102,241,.07); border-color: var(--accent); }
.callout-error { background: rgba(249,115,22,.07); border-color: var(--coral); }

.callout-title {
  font-weight: 700;
  font-size: .8rem;
  letter-spacing: .05em;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.callout-tip   .callout-title { color: var(--green); }
.callout-warn  .callout-title { color: var(--amber); }
.callout-info  .callout-title { color: var(--accent2); }
.callout-error .callout-title { color: var(--coral); }

/* ─── TABLES ─── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: .875rem;
}

.data-table th {
  background: var(--card);
  padding: 10px 14px;
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--dim);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  vertical-align: top;
}

.data-table tr:hover td { background: rgba(255,255,255,.02); }
.light .data-table tr:hover td { background: rgba(0,0,0,.02); }

/* ─── CARDS ─── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.info-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-size: .875rem;
}

.info-card h4 {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  text-transform: none;
  letter-spacing: 0;
}

.info-card p { color: var(--muted); font-size: .84rem; line-height: 1.6; }

/* ─── TABS ─── */
.tab-group { margin: 20px 0; }

.tab-bar {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--dim);
  font-size: .85rem;
  font-weight: 500;
  padding: 8px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}

.tab-btn.active {
  color: var(--accent2);
  border-bottom-color: var(--accent);
}

.tab-btn:hover { color: var(--muted); }

.tab-panel { display: none; padding-top: 16px; }
.tab-panel.active { display: block; }

/* ─── ACCORDION ─── */
.accordion { margin: 12px 0; }

.accordion-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  overflow: hidden;
}

.accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  background: var(--card);
  font-size: .9rem;
  font-weight: 500;
  color: var(--text);
  user-select: none;
  transition: background .15s;
}

.accordion-header:hover { background: var(--surface); }

.accordion-icon {
  font-size: 12px;
  color: var(--dim);
  transition: transform .2s;
  flex-shrink: 0;
}

.accordion-item.open .accordion-icon { transform: rotate(180deg); }

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s ease;
}

.accordion-item.open .accordion-body { max-height: 2000px; }

.accordion-content {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  font-size: .9rem;
  color: var(--muted);
  line-height: 1.7;
}

/* ─── QUIZ ─── */
.quiz-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  margin: 32px 0;
  padding-bottom: 16px;
}

.quiz-section h3 {
  margin: 0 0 16px;
  font-size: 1rem;
  color: var(--text);
  border: none;
  padding: 0;
}

.quiz-q {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
}

.quiz-q-text {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.quiz-options { display: flex; flex-direction: column; gap: 6px; }

.quiz-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: .875rem;
  color: var(--muted);
  transition: border-color .15s, background .15s;
  background: var(--surface);
}

.quiz-option:hover:not(.locked) { border-color: var(--accent); color: var(--text); }

.quiz-option.correct { border-color: var(--green); background: rgba(34,197,94,.08); color: var(--text); }
.quiz-option.wrong   { border-color: var(--coral); background: rgba(249,115,22,.08); color: var(--text); }
.quiz-option.locked  { cursor: default; pointer-events: none; }

.quiz-letter {
  font-weight: 700;
  font-size: .8rem;
  color: var(--dim);
  flex-shrink: 0;
  margin-top: 1px;
}

.quiz-explanation {
  margin-top: 10px;
  font-size: .84rem;
  color: var(--muted);
  background: var(--surface);
  border-left: 3px solid var(--accent);
  padding: 8px 12px;
  border-radius: 0 6px 6px 0;
  display: none;
}

/* ─── INTERVIEW SECTION ─── */
.interview-section {
  margin: 32px 0;
  padding-bottom: 16px;
}

.interview-section > h3 {
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 14px;
}

/* ─── SUBTOPIC NAV ─── */
.subtopic-nav {
  margin-top: 36px;
  padding: 14px 0 10px;
  border-top: 1px solid var(--border);
}

.subtopic-nav-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 8px;
}

.subtopic-nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.subtopic-nav-link {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  text-decoration: none;
  transition: color .15s, border-color .15s;
}

.subtopic-nav-link:hover { color: var(--text); border-color: var(--accent); }

.subtopic-nav-link.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(99,102,241,.07);
  font-weight: 500;
  pointer-events: none;
}

/* ─── PREV / NEXT FOOTER ─── */
.topic-nav-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}

.topic-nav-prev, .topic-nav-next {
  font-size: 13px;
  color: var(--accent2);
  text-decoration: none;
  transition: color .15s;
}

.topic-nav-prev:hover, .topic-nav-next:hover { color: var(--accent3); }

/* ─── DIAGRAM / ASCII ─── */
.diagram {
  background: #18181b;
  border: 1px solid #27272a;
  border-radius: 8px;
  padding: 20px 24px;
  margin: 16px 0;
  overflow-x: auto;
}

.light .diagram { background: #18181b; border-color: #27272a; }

.diagram pre {
  color: #a1a1aa;
  font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
  font-size: .82rem;
  line-height: 1.5;
  white-space: pre;
  margin: 0;
}

/* ─── STEP LIST ─── */
.step-list { list-style: none; padding: 0; margin: 14px 0; }

.step-list li {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
  color: var(--muted);
}

.step-list li:last-child { border-bottom: none; }

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ─── INLINE CODE ─── */
code:not([class]) {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
  font-size: .82rem;
  color: var(--accent3);
}

/* ─── HIGHLIGHT LIST ─── */
ul.check-list { list-style: none; padding: 0; margin: 10px 0; }
ul.check-list li { padding: 4px 0 4px 22px; position: relative; font-size: .9rem; color: var(--muted); }
ul.check-list li::before { content: '✓'; position: absolute; left: 0; color: var(--green); font-weight: 700; }

/* ─── MOBILE ─── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -260px;
    top: var(--topbar-height);
    z-index: 90;
    transition: left .25s ease;
    height: calc(100vh - var(--topbar-height));
  }

  .sidebar.open { left: 0; }

  .app-layout { flex-direction: column; }

  .main-content {
    padding: 20px 16px 48px;
    max-width: 100%;
  }

  .topbar-bc-link, .topbar-bc-sep { display: none; }
  .topbar-bc-link:last-of-type { display: inline; }
}

/* ─── MISC ─── */
strong { color: var(--text); font-weight: 600; }

ul, ol { padding-left: 22px; color: var(--muted); font-size: .9rem; }
ul li, ol li { margin-bottom: 5px; line-height: 1.65; }

.section-intro {
  font-size: .95rem;
  color: var(--muted);
  margin-bottom: 20px;
  padding: 14px 16px;
  background: var(--card);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  line-height: 1.7;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 14px 0;
}

@media (max-width: 640px) { .two-col { grid-template-columns: 1fr; } }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(99,102,241,.12);
  color: var(--accent3);
  border: 1px solid rgba(99,102,241,.25);
  margin: 2px;
}
