/* ============================================================
   Public lesson pages (/learn/..., written by tools/landing/learn.py).
   Loaded after styles.css, only on those pages.
   ============================================================ */

/* The app's color tokens (frontend/src/index.css). The hand-made lesson figures are painted with
   them (var(--color-base-800), currentColor), so they follow the theme here as they do in the app. */
:root {
  --color-base-950: #06070c;
  --color-base-900: #0a0c14;
  --color-base-850: #0e1119;
  --color-base-800: #12151f;
  --color-base-700: #1a1e2b;
  --color-base-600: #262b3b;
  --color-base-500: #757e9d;
  --color-base-400: #8890a9;
  --color-base-300: #a3abc3;
  --color-base-200: #b8bfd4;
  --color-base-100: #dde1ee;
  --color-base-50: #f4f5fa;
  --color-brand-400: #a5b4fc;
  --color-brand-500: #818cf8;
  --color-brand-600: #6366f1;
  --color-brand-700: #4f46e5;
  --code-bg: #0b0e17;
  --code-text: #dde1ee;
  --inline-code-bg: #12151f;
  --inline-code-text: #a5b4fc;
}

:root[data-theme="light"] {
  --color-base-950: #f6f7fb;
  --color-base-900: #ffffff;
  --color-base-850: #f3f4f8;
  --color-base-800: #eceef4;
  --color-base-700: #dfe2ea;
  --color-base-600: #c8cdd9;
  --color-base-500: #5f667d;
  --color-base-400: #585f74;
  --color-base-300: #454c60;
  --color-base-200: #2f3548;
  --color-base-100: #1d2233;
  --color-base-50: #0e1120;
  --color-brand-400: #4f46e5;
  --color-brand-500: #6366f1;
  --color-brand-600: #4f46e5;
  --color-brand-700: #4338ca;
  --code-bg: #f3f4f8;
  --code-text: #1d2233;
  --inline-code-bg: #eceef4;
  --inline-code-text: #4338ca;
}

/* ---------- Hero ---------- */

.lesson-hero h1 {
  font-size: clamp(2rem, 4.4vw, 3rem);
}

.lesson-hero .hero-lede {
  font-size: 17px;
}

/* ---------- Layout: article + sticky table of contents ---------- */

.lesson-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 56px;
  align-items: start;
  padding-bottom: clamp(2.5rem, 6vw, 4rem);
}

.lesson-article {
  max-width: 780px;
  min-width: 0;
}

.lesson-aside {
  position: sticky;
  top: calc(var(--header-h) + 24px);
  display: grid;
  gap: 18px;
  max-height: calc(100vh - var(--header-h) - 48px);
  overflow-y: auto;
}

.toc ol {
  display: grid;
  gap: 2px;
}

.toc a {
  display: block;
  padding: 5px 10px;
  border-left: 2px solid var(--border);
  color: var(--text-3);
  font-size: 13.5px;
  line-height: 1.45;
}

.toc a:hover {
  border-left-color: var(--brand);
  color: var(--text);
}

.toc-title {
  margin-bottom: 8px;
  color: var(--text-4);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.toc-mobile {
  display: none;
  margin-bottom: 28px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}

.toc-mobile summary {
  cursor: pointer;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
}

.toc-mobile ol {
  margin-top: 10px;
}

.aside-cta {
  padding: 18px;
}

.aside-cta p {
  margin-bottom: 14px;
  color: var(--text-3);
  font-size: 13.5px;
  line-height: 1.6;
}

.aside-cta strong {
  color: var(--text);
}

@media (max-width: 980px) {
  .lesson-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .lesson-aside {
    display: none;
  }

  .toc-mobile {
    display: block;
  }
}

/* ---------- Lesson typography ---------- */

.lesson-content {
  color: var(--text-2);
  font-size: 16.5px;
  line-height: 1.75;
  overflow-wrap: break-word;
}

.lesson-content > * + *,
.lesson-content details > * + * {
  margin-top: 1.05em;
}

.lesson-content h2 {
  margin-top: 2.4em;
  font-size: clamp(1.45rem, 2.6vw, 1.8rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.lesson-content > h2:first-of-type,
.lesson-content > .toc-mobile + h2 {
  margin-top: 0;
}

.lesson-content h3 {
  margin-top: 2em;
  font-size: 1.22rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.3;
}

.lesson-content h4,
.lesson-content h5,
.lesson-content h6 {
  margin-top: 1.6em;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 700;
}

.lesson-content strong {
  color: var(--text);
  font-weight: 650;
}

.lesson-content a {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.lesson-content ul,
.lesson-content ol {
  padding-left: 1.4em;
}

.lesson-content ul {
  list-style: disc;
}

.lesson-content ol {
  list-style: decimal;
}

.lesson-content li + li {
  margin-top: 0.4em;
}

.lesson-content li > ul,
.lesson-content li > ol {
  margin-top: 0.4em;
}

.lesson-content li::marker {
  color: var(--text-4);
}

.lesson-content blockquote {
  margin: 0;
  padding: 2px 0 2px 18px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-3);
}

.lesson-content hr {
  border: 0;
  border-top: 1px solid var(--border);
}

.lesson-content :not(pre) > code {
  padding: 0.12em 0.4em;
  border-radius: 6px;
  background: var(--inline-code-bg);
  color: var(--inline-code-text);
  font-family: var(--font-mono);
  font-size: 0.86em;
}

.lesson-content pre {
  margin-left: 0;
  margin-right: 0;
  padding: 16px 18px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  tab-size: 4;
}

.lesson-content pre code {
  font-family: inherit;
}

/* JetBrains Mono draws <= as one glyph; a lesson about <= vs < needs the characters typed. */
.lesson-content code,
.lesson-content pre {
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.lesson-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
  line-height: 1.55;
}

.lesson-content th,
.lesson-content td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.lesson-content th {
  background: var(--bg-soft);
  color: var(--text);
  font-weight: 650;
  white-space: nowrap;
}

.lesson-content tr:last-child td {
  border-bottom: 0;
}

.lesson-content details {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
}

.lesson-content details > summary {
  cursor: pointer;
  color: var(--brand);
  font-weight: 600;
}

.lesson-content details[open] > summary {
  margin-bottom: 0.6em;
}

/* "Explain simply" - the app's popup, shown inline here. */
.plain-words {
  padding: 12px 16px;
  border-left: 3px solid var(--brand);
  border-radius: 0 12px 12px 0;
  background: var(--brand-soft);
}

.plain-words p {
  color: var(--text-2);
  font-size: 15px;
  line-height: 1.65;
}

.plain-words .plain-words-label {
  margin-bottom: 2px;
  color: var(--brand);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ---------- Java | Python ---------- */

.code-tab + .code-tab {
  margin-top: 12px;
}

.code-tab-label {
  margin-bottom: 6px;
  color: var(--text-4);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
}

.code-tab pre {
  margin-top: 0;
}

.code-tabs-bar {
  display: none;
}

/* With JavaScript (learn.js): one language at a time, with a switcher. */
.code-tabs.is-tabbed .code-tabs-bar {
  display: flex;
  gap: 4px;
  margin-bottom: -1px;
}

.code-tabs.is-tabbed .code-tab-label {
  display: none;
}

.code-tabs.is-tabbed .code-tab + .code-tab {
  margin-top: 0;
}

.code-tabs.is-tabbed .code-tab[hidden] {
  display: none;
}

.code-tabs.is-tabbed pre {
  border-top-left-radius: 0;
}

.code-tabs-bar button {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.code-tabs-bar button[aria-selected="true"] {
  background: var(--code-bg);
  color: var(--text);
  font-weight: 600;
}

/* ---------- Figures and diagrams ---------- */

.lesson-figure,
.diagram {
  margin-left: 0;
  margin-right: 0;
}

.figure-frame,
.diagram-frame {
  overflow-x: auto;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--color-base-900) 40%, transparent);
  color: var(--color-base-200);
}

.figure-frame svg {
  width: 100%;
  min-width: 34rem;
  max-width: 44rem;
  height: auto;
  margin-inline: auto;
}

.lesson-figure figcaption {
  margin-top: 8px;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
}

.diagram-svg {
  margin-inline: auto;
}

.diagram-svg svg {
  width: 100%;
  height: auto;
}

.diagram-light {
  display: none;
}

:root[data-theme="light"] .diagram-dark {
  display: none;
}

:root[data-theme="light"] .diagram-light {
  display: block;
}

.diagram-text figcaption {
  margin-bottom: 6px;
  color: var(--text-4);
  font-size: 12.5px;
}

/* ---------- Calls to action ---------- */

.lesson-cta {
  margin-top: 3em;
  padding: 24px;
}

.lesson-content .lesson-cta h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.lesson-cta p {
  margin-bottom: 16px;
  color: var(--text-2);
  font-size: 15px;
}

/* ---------- Quick revise and practice ---------- */

/* Inside a full-width container, so it lines up with the article above it. */
.lesson-section > * {
  max-width: 780px;
}

.lesson-section > h2 {
  margin-bottom: 8px;
  line-height: 1.2;
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.section-note {
  margin-bottom: 22px;
  color: var(--text-3);
  font-size: 15px;
  line-height: 1.65;
}

.lesson-section > .btn {
  margin-bottom: 28px;
}

.problem-list {
  display: grid;
  gap: 18px;
}

.problem-card {
  padding: 22px 24px;
  min-width: 0;
}

.problem-card header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 14px;
}

.problem-card h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.problem-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.problem-meta .chip {
  font-size: 11px;
}

.chip-pro {
  border-color: color-mix(in srgb, var(--amber) 45%, transparent);
  color: var(--amber);
}

.problem-langs {
  color: var(--text-4);
  font-family: var(--font-mono);
  font-size: 11.5px;
}

.statement {
  font-size: 15.5px;
}

.statement-sub {
  margin: 18px 0 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.problem-teaser {
  color: var(--text-2);
  font-size: 15.5px;
}

.problem-locked {
  margin-top: 10px;
  color: var(--text-3);
  font-size: 14px;
}

.problem-locked a {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.problem-actions {
  margin-top: 18px;
}

.skill-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.skill-pager a {
  display: block;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  transition: border-color 0.2s ease;
}

.skill-pager a:hover {
  border-color: var(--brand);
}

.skill-pager span {
  display: block;
  color: var(--text-4);
  font-size: 12px;
}

.skill-pager strong {
  color: var(--text);
  font-size: 15px;
}

.pager-next {
  grid-column: 2;
  text-align: right;
}

.pager-course {
  margin-top: 18px;
  color: var(--text-3);
  font-size: 14px;
}

.pager-course a {
  color: var(--brand);
}

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

  .pager-next {
    grid-column: 1;
  }

  .problem-card {
    padding: 18px;
  }

  .lesson-content {
    font-size: 16px;
  }
}

/* ---------- Lesson indexes (/learn/, /learn/<course>/) ---------- */

.skill-index {
  padding-bottom: clamp(2.5rem, 6vw, 4rem);
}

.skill-topic + .skill-topic {
  margin-top: 48px;
}

.skill-topic > h2 {
  margin-bottom: 8px;
  font-size: clamp(1.5rem, 3vw, 1.9rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.skill-module + .skill-module {
  margin-top: 26px;
}

.skill-module h3 {
  margin-bottom: 10px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.skill-links {
  display: grid;
  gap: 10px;
}

.skill-links a {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  transition: border-color 0.2s ease;
}

.skill-links a:hover {
  border-color: var(--brand);
}

.skill-links strong {
  display: block;
  color: var(--text);
  font-size: 15.5px;
}

.skill-links span {
  display: block;
  margin-top: 2px;
  color: var(--text-3);
  font-size: 14px;
  line-height: 1.55;
}

.learn-hub {
  padding-bottom: clamp(2.5rem, 6vw, 4rem);
}

.learn-subject {
  padding: 20px 22px;
}

.learn-subject-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 16px;
}

.learn-subject-head h2 {
  font-size: 1.3rem;
  font-weight: 800;
}

.learn-subject-head a:hover,
.learn-hub .module-list a:hover {
  color: var(--brand);
}

.learn-hub .module-list h3 {
  margin-bottom: 6px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 700;
}

/* ---------- Problem pages (/learn/<course>/<skill>/<problem>/) ---------- */

.lesson-hero .hero-lede a,
.problem-card h3 a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 4px;
}

.lesson-hero .hero-lede a:hover,
.problem-card h3 a:hover {
  text-decoration-color: var(--brand);
}

.problem-page .lesson-section > h2 {
  margin-top: 40px;
}

.problem-page .lesson-section > h2:first-child {
  margin-top: 0;
}

.problem-page .lesson-section > h3 {
  margin: 26px 0 10px;
  font-size: 1.05rem;
  font-weight: 700;
}

.problem-page .statement {
  font-size: 16.5px;
}

.grading-notes {
  display: grid;
  gap: 10px;
}

.grading-notes li {
  position: relative;
  padding-left: 20px;
  color: var(--text-2);
  font-size: 15.5px;
  line-height: 1.65;
}

.grading-notes li::before {
  content: "";
  position: absolute;
  top: 0.65em;
  left: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
}

.learn-first {
  margin-top: 18px;
  padding: 22px 24px;
}

.learn-first h2 {
  margin: 2px 0 8px;
  font-size: 1.2rem;
  font-weight: 700;
}

.learn-first h2 a:hover {
  color: var(--brand);
}

.learn-first p:not(.toc-title) {
  margin-bottom: 14px;
  color: var(--text-3);
  font-size: 14.5px;
  line-height: 1.6;
}

.sibling-problems {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.sibling-problems li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-size: 15px;
}

.sibling-problems a:hover {
  color: var(--brand);
}

.problem-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
