/* =========================================================================
   StackSimplified · AI Labs — global.css
   Plain CSS with custom properties for theming (light/dark).
   ========================================================================= */

:root {
  /* Brand */
  --brand: #4f46e5;
  --brand-2: #06b6d4;
  --brand-grad: linear-gradient(135deg, #4f46e5 0%, #06b6d4 100%);

  /* Light theme (default) */
  --bg: #ffffff;
  --bg-soft: #f6f7fb;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --border: #e6e8ef;
  --text: #0f172a;
  --text-soft: #475569;
  --text-muted: #94a3b8;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);

  /* Layout */
  --maxw: 1120px;
  --radius: 16px;
  --radius-sm: 10px;
  --nav-h: 64px;

  --font-ui: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

:root[data-theme="dark"] {
  --bg: #0b1020;
  --bg-soft: #0f152a;
  --bg-elev: #131a33;
  --surface: #131a33;
  --border: #232c4d;
  --text: #eef2ff;
  --text-soft: #b8c0e0;
  --text-muted: #7c86ad;
  --code-bg: #060a17;
  --code-text: #d5def7;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

a {
  color: inherit;
  text-decoration: none;
}

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------------------------- Nav bar ---------------------------------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}
.brand__logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--brand-grad);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1.1rem;
  box-shadow: var(--shadow);
}
.brand__sub {
  color: var(--text-muted);
  font-weight: 600;
}
.nav__links {
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav__link {
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-soft);
  transition: background 0.15s ease, color 0.15s ease;
}
.nav__link:hover {
  background: var(--bg-soft);
  color: var(--text);
}
.nav__link--active {
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 12%, transparent);
}
.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 1.05rem;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, background 0.15s ease;
}
.theme-toggle:hover {
  transform: translateY(-1px);
  background: var(--bg-soft);
}

/* ---------------------------- Buttons ---------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn--primary {
  background: var(--brand-grad);
  color: #fff;
  box-shadow: var(--shadow);
}
.btn--primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.btn--ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn--ghost:hover {
  background: var(--bg-soft);
}

/* ---------------------------- Hero ------------------------------------- */
.hero {
  padding: 72px 0 40px;
  text-align: center;
}
.hero__badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand) 10%, transparent);
  color: var(--brand);
  font-weight: 600;
  font-size: 0.85rem;
  border: 1px solid color-mix(in srgb, var(--brand) 22%, transparent);
}
.hero__title {
  font-size: clamp(2.2rem, 5vw, 3.6rem);
  line-height: 1.08;
  letter-spacing: -0.03em;
  font-weight: 800;
  margin: 22px 0 16px;
}
.hero__title .grad {
  background: var(--brand-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero__sub {
  max-width: 680px;
  margin: 0 auto 28px;
  font-size: 1.15rem;
  color: var(--text-soft);
}
.hero__cta {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------------------------- Sections --------------------------------- */
.section {
  padding: 48px 0;
}
.section__head {
  text-align: center;
  margin-bottom: 36px;
}
.section__eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--brand);
}
.section__title {
  font-size: clamp(1.6rem, 3vw, 2.3rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 8px 0 10px;
}
.section__desc {
  color: var(--text-soft);
  max-width: 640px;
  margin: 0 auto;
}

/* ---------------------------- Grid & cards ----------------------------- */
.grid {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}
.card__icon {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  background: var(--bg-soft);
}
.card__title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.card__desc {
  color: var(--text-soft);
  font-size: 0.96rem;
  flex: 1;
}
.card__meta {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
}
.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  background: var(--bg-soft);
  color: var(--text-soft);
  border: 1px solid var(--border);
}

/* ---------------------------- Topic detail ----------------------------- */
.crumbs {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 24px 0 6px;
}
.crumbs a:hover {
  color: var(--brand);
}
.topic-hero {
  padding: 20px 0 30px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 30px;
}
.topic-hero__row {
  display: flex;
  gap: 18px;
  align-items: center;
}
.topic-hero__icon {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 2.2rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}
.topic-hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  margin: 0;
  letter-spacing: -0.02em;
}

.module {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 26px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.module__head {
  display: flex;
  gap: 14px;
  align-items: baseline;
}
.module__num {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--brand);
  font-size: 0.9rem;
}
.module__title {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
}
.module__desc {
  color: var(--text-soft);
  margin: 8px 0 14px;
}
.lessons {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}
.lesson {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  font-size: 0.95rem;
  color: var(--text-soft);
}
.lesson__dot {
  color: var(--brand-2);
}

/* ---------------------------- Code block ------------------------------- */
pre.code {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.6;
  margin: 14px 0;
}

/* ---------------------------- Footer ----------------------------------- */
.footer {
  border-top: 1px solid var(--border);
  margin-top: 60px;
  padding: 32px 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.footer__inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

/* ---------------------------- Utilities -------------------------------- */
.stack-count {
  font-variant-numeric: tabular-nums;
}
@media (max-width: 620px) {
  .nav__links .nav__link {
    display: none;
  }
  .nav__links .nav__link--active {
    display: inline-block;
  }
}


/* =========================================================================
   Feedback update: hamburger nav, drawer, content layout, code blocks
   ========================================================================= */

/* ---- Nav right-side controls + hamburger ------------------------------ */
.nav__controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.hamburger {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: grid;
  place-items: center;
  gap: 5px;
  padding: 0;
  transition: background 0.15s ease;
}
.hamburger:hover {
  background: var(--bg-soft);
}
.hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.hamburger--open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.hamburger--open span:nth-child(2) {
  opacity: 0;
}
.hamburger--open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ---- Slide-out drawer -------------------------------------------------- */
.drawer__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 90;
  backdrop-filter: blur(2px);
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(320px, 84vw);
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  padding: 76px 18px 24px;
  overflow-y: auto;
}
.drawer__section {
  margin-bottom: 22px;
}
.drawer__label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0 8px 8px;
}
.drawer__link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: 0.98rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.drawer__link:hover {
  background: var(--bg-soft);
  color: var(--text);
}
.drawer__link--active {
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  color: var(--brand);
}
.drawer__icon {
  font-size: 1.1rem;
  width: 22px;
  text-align: center;
}

/* ---- Code block (copy-friendly, explanation outside the box) ---------- */
.codeblock {
  margin: 16px 0 22px;
}
.codeblock__explain {
  margin: 0 0 10px;
  color: var(--text-soft);
  font-size: 0.98rem;
  line-height: 1.65;
}
.codeblock__box {
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.codeblock__bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #0b1220;
  padding: 9px 14px;
  border-bottom: 1px solid #1e293b;
}
.codeblock__dots {
  display: inline-flex;
  gap: 6px;
}
.codeblock__dots i {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #ef4444;
}
.codeblock__dots i:nth-child(2) {
  background: #f59e0b;
}
.codeblock__dots i:nth-child(3) {
  background: #22c55e;
}
.codeblock__lang {
  color: #94a3b8;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  flex: 1;
}
.codeblock__copy {
  border: 1px solid #334155;
  background: #1e293b;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.codeblock__copy:hover {
  background: #334155;
}
.codeblock__box pre.code {
  margin: 0;
  border-radius: 0;
  border: none;
}

/* ---- Content layout: sidebar + main ----------------------------------- */
.content-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 34px;
  align-items: start;
  padding: 10px 0 20px;
}
/* ---- Table of contents (sidebar) : modules as cards, chapters nested --- */
.toc {
  position: sticky;
  top: calc(var(--nav-h) + 16px);
  align-self: start;
  max-height: calc(100vh - var(--nav-h) - 32px);
  overflow-y: auto;
}
.toc__back {
  display: inline-block;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 12px;
}
.toc__back:hover {
  color: var(--brand);
}
.toc__topic {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  margin-bottom: 14px;
}
.toc__topicicon {
  font-size: 1.15rem;
}

/* Module = a distinct CARD (the "container" — visually heavier). */
.toc-module {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.toc-module--current {
  border-color: color-mix(in srgb, var(--brand) 45%, var(--border));
}
.toc-module__head {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 13px 14px;
  font-family: inherit;
  transition: background 0.15s ease;
}
.toc-module__head:hover {
  background: var(--bg-soft);
}
.toc-module--current .toc-module__head {
  background: color-mix(in srgb, var(--brand) 8%, transparent);
}
.toc-module__badge {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--brand-grad);
  color: #fff;
  font-weight: 800;
  font-size: 0.82rem;
  display: grid;
  place-items: center;
  letter-spacing: -0.02em;
}
.toc-module__meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}
.toc-module__label {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  font-weight: 700;
  color: var(--brand);
}
.toc-module__name {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}
.toc-module__count {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 600;
}
.toc-module__chev {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 1.1rem;
  transition: transform 0.2s ease;
}
.toc-module__chev--open {
  transform: rotate(180deg);
}

/* Chapters = nested, "lighter" sub-items with a connecting rail. */
.toc-chapters {
  list-style: none;
  margin: 0;
  padding: 4px 10px 10px 18px;
  border-top: 1px solid var(--border);
}
.toc-chapter {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  padding: 8px 10px;
  border-radius: 9px;
  border-left: 2px solid var(--border);
  color: var(--text-soft);
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.toc-chapter:hover {
  background: var(--bg-soft);
  color: var(--text);
}
.toc-chapter--active {
  background: color-mix(in srgb, var(--brand) 13%, transparent);
  border-left-color: var(--brand);
  color: var(--brand);
}
.toc-chapter__state {
  flex-shrink: 0;
  width: 14px;
  font-size: 0.7rem;
  line-height: 1.5;
  color: var(--brand);
}
.toc-chapter__state--done {
  color: var(--brand-2);
}
.toc-chapter__num {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 600;
  opacity: 0.7;
  padding-top: 1px;
}
.toc-chapter__title {
  font-size: 0.9rem;
  line-height: 1.4;
  font-weight: 500;
}
.toc-chapter--active .toc-chapter__title {
  font-weight: 700;
}

/* ---- Main pane ---------------------------------------------------------- */
.content-main {
  min-width: 0; /* allow code blocks to scroll instead of stretching layout */
}
.chapter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  margin: 6px 0 18px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.chapter-head__module {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.chapter-head__badge {
  background: var(--brand-grad);
  color: #fff;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 4px 11px;
  border-radius: 999px;
  white-space: nowrap;
}
.chapter-head__modname {
  font-weight: 700;
  color: var(--text);
  font-size: 0.95rem;
}
.chapter-head__kicker {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.content-main__title {
  font-size: clamp(1.7rem, 3.2vw, 2.3rem);
  letter-spacing: -0.02em;
  margin: 4px 0 10px;
  line-height: 1.15;
}
.content-main__blurb {
  color: var(--text-soft);
  font-size: 1.08rem;
  line-height: 1.6;
  margin: 0 0 22px;
  padding-left: 14px;
  border-left: 3px solid color-mix(in srgb, var(--brand) 40%, transparent);
}

/* ---- Progress bar (bottom of chapter) ---------------------------------- */
.content-progressbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 26px 0 4px;
}
.content-progressbar__track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  overflow: hidden;
}
.content-progressbar__fill {
  height: 100%;
  background: var(--brand-grad);
  border-radius: 999px;
  transition: width 0.35s ease;
}
.content-progressbar__label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ---- Prose, lists, callouts ------------------------------------------- */
.prose {
  font-size: 1.02rem;
  line-height: 1.75;
  color: var(--text);
  margin: 0 0 14px;
}
.prose-list {
  margin: 0 0 16px;
  padding-left: 22px;
  line-height: 1.8;
  color: var(--text-soft);
}
.prose-list li {
  margin-bottom: 4px;
}
.callout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: color-mix(in srgb, var(--brand-2) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand-2) 30%, transparent);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 14px 0 20px;
}
.callout__icon {
  font-size: 1.1rem;
}
.callout p {
  margin: 0;
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.6;
}

/* ---- Intro hero panels (first chapter) -------------------------------- */
.intro-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 18px 0 6px;
}
.intro-panel {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.intro-panel__label {
  font-weight: 700;
  margin-bottom: 6px;
}
.intro-panel p {
  margin: 0;
  color: var(--text-soft);
}

/* ---- Chapter prev/next ------------------------------------------------- */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 32px 0 20px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding-top: 22px;
}

/* ---- Responsive: stack the table of contents above the content -------- */
@media (max-width: 860px) {
  .content-layout {
    grid-template-columns: 1fr;
  }
  .toc {
    position: static;
    max-height: none;
    order: 1;
    margin-bottom: 20px;
  }
  .content-main {
    order: 2;
  }
  .intro-grid {
    grid-template-columns: 1fr;
  }
}
