  :root {
    color-scheme: light;
    --paper: #F7F9FC;
    --surface: #FFFFFF;
    --ink: #131C2E;
    --ink-soft: #46536B;
    --line: #DDE4EF;
    --accent: #2050D8;          /* Part 1 — Weeks 1-5, the three tools */
    --accent-ink: #1A41AC;
    --teal: #0E8A7B;            /* Part 2 — Weeks 6-11, organising programs */
    --teal-ink: #0B6E63;
    --amber: #B45309;           /* Assessment milestones */
    --red: #C23A3A;             /* No-lab / deadline weeks */
    --java: #A25B12;            /* Java language badge */
    --python: #2D6CA8;          /* Python language badge */
    --shadow: 0 1px 2px rgba(19, 28, 46, 0.05), 0 8px 24px rgba(19, 28, 46, 0.06);

    /* Code colors are independent of the light/dark site theme — see #code-theme-toggle. */
    --code-bg: #0A111E;
    --code-gutter: #111B2D;
    --code-text: #D9E4F5;
    --code-caret: #E8EDF6;
    --code-kw: #7DA2FF;
    --code-str: #6FD3A6;
    --code-fn: #F0B45C;
    --code-cm: #6B7A94;
  }

  :root[data-code-theme="paper"] {
    --code-bg: #E6E9ED;
    --code-gutter: #D6DBE1;
    --code-text: #1B1F24;
    --code-caret: #1B1F24;
    --code-kw: #0A3F8F;
    --code-str: #0E5A22;
    --code-fn: #6F4400;
    --code-cm: #57606A;
  }

  :root[data-code-theme="contrast"] {
    --code-bg: #000000;
    --code-gutter: #161616;
    --code-text: #FFFFFF;
    --code-caret: #FFFFFF;
    --code-kw: #6AB8FF;
    --code-str: #8CFFC1;
    --code-fn: #FFD866;
    --code-cm: #B0BAC9;
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      color-scheme: dark;
      --paper: #0D1420;
      --surface: #151F30;
      --ink: #E8EDF6;
      --ink-soft: #9AA8C0;
      --line: #26324A;
      --accent: #7DA2FF;
      --accent-ink: #A3BDFF;
      --teal: #45C4B0;
      --teal-ink: #6ED6C5;
      --amber: #E0A64B;
      --red: #E57B7B;
      --java: #E0A15C;
      --python: #7FB3E0;
      --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    }
  }

  :root[data-theme="dark"] {
    color-scheme: dark;
    --paper: #0D1420;
    --surface: #151F30;
    --ink: #E8EDF6;
    --ink-soft: #9AA8C0;
    --line: #26324A;
    --accent: #7DA2FF;
    --accent-ink: #A3BDFF;
    --teal: #45C4B0;
    --teal-ink: #6ED6C5;
    --amber: #E0A64B;
    --red: #E57B7B;
    --java: #E0A15C;
    --python: #7FB3E0;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }

  :root[data-theme="light"] { color-scheme: light; }

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

  @media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
  }

  body {
    background: var(--paper);
    color: var(--ink);
    font-family: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
    font-size: 16.5px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    transition: background-color 180ms ease, color 180ms ease;
  }

  .mono { font-family: "IBM Plex Mono", "SF Mono", Consolas, monospace; }

  a { color: var(--accent); }
  a:focus-visible, button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 2px;
  }

  .wrap { max-width: 68rem; margin: 0 auto; padding: 0 1.5rem; }

  /* ── Thanh điều hướng ─────────────────────────── */
  .topbar {
    position: sticky; top: 0; z-index: 50;
    background: color-mix(in srgb, var(--paper) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
  }
  .topbar .wrap {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; height: 3.5rem;
  }
  .wordmark {
    font-family: "IBM Plex Mono", monospace;
    font-weight: 600; font-size: 0.95rem;
    color: var(--ink); text-decoration: none;
    letter-spacing: 0.02em;
  }
  .wordmark b { color: var(--accent); font-weight: 600; }
  .header-tools { display: flex; align-items: center; gap: 1.2rem; margin-left: auto; }
  .topnav { display: flex; gap: 1.4rem; }
  .topnav a {
    color: var(--ink-soft); text-decoration: none;
    font-size: 0.88rem; font-weight: 500;
  }
  .topnav a:hover { color: var(--ink); }
  .display-controls { display: flex; align-items: center; gap: 0.4rem; }
  .control-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    min-height: 2.1rem; padding: 0.35rem 0.65rem;
    border: 1px solid var(--line); border-radius: 8px;
    background: var(--surface); color: var(--ink);
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.73rem; font-weight: 600; line-height: 1;
    cursor: pointer;
    transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease;
  }
  .control-btn:hover {
    border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
    background: color-mix(in srgb, var(--accent) 7%, var(--surface));
  }
  .control-btn .icon { font-size: 0.95rem; line-height: 1; }
  @media (max-width: 720px) { .topnav { display: none; } }
  @media (max-width: 520px) {
    .wordmark .course-name { display: none; }
    .header-tools { gap: 0.5rem; }
    .control-btn { padding-inline: 0.55rem; }
  }

  /* ── Hero ─────────────────────────────────────── */
  .hero { padding: 4.5rem 0 3.5rem; }
  .hero .wrap {
    display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    gap: 3rem; align-items: center;
  }
  @media (max-width: 820px) {
    .hero { padding: 3rem 0 2.5rem; }
    .hero .wrap { grid-template-columns: minmax(0, 1fr); gap: 2.25rem; }
  }
  .eyebrow {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.78rem; font-weight: 500;
    letter-spacing: 0.14em; text-transform: uppercase;
    color: var(--accent);
  }
  .hero h1 {
    font-family: "Archivo", sans-serif;
    font-size: clamp(2.3rem, 5.5vw, 3.4rem);
    font-weight: 800; line-height: 1.08;
    letter-spacing: -0.02em; text-wrap: balance;
    margin: 0.7rem 0 1rem;
  }
  .hero .lede {
    color: var(--ink-soft); max-width: 34rem;
    margin-bottom: 1.5rem;
  }
  .meta-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
  .chip {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.8rem; font-weight: 500;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--line); border-radius: 999px;
    background: var(--surface); color: var(--ink-soft);
    white-space: nowrap;
  }
  .chip strong { color: var(--ink); font-weight: 600; }

  /* Thẻ code */
  .code-card {
    background: var(--code-bg); border-radius: 12px;
    box-shadow: var(--shadow); overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--code-bg) 60%, var(--line));
  }
  .code-card .bar {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }
  .code-card .dot { width: 10px; height: 10px; border-radius: 50%; opacity: 0.9; }
  .code-card .file {
    margin-left: auto;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.75rem; color: var(--code-cm);
  }
  .code-card pre {
    padding: 1.1rem 1.25rem; overflow-x: auto;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.83rem; line-height: 1.75;
    color: var(--code-text);
  }
  .kw { color: var(--code-kw); } .str { color: var(--code-str); }
  .fn { color: var(--code-fn); } .cm { color: var(--code-cm); }

  /* ── Dải thông tin nhanh ──────────────────────── */
  .facts { border-block: 1px solid var(--line); background: var(--surface); }
  .facts .wrap {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 1px; padding: 0;
  }
  @media (max-width: 820px) { .facts .wrap { grid-template-columns: repeat(2, 1fr); } }
  .fact { padding: 1.3rem 1.5rem; border-left: 1px solid var(--line); }
  .fact:first-child { border-left: none; }
  @media (max-width: 820px) { .fact:nth-child(3) { border-left: none; } .fact { border-top: 1px solid var(--line); } .fact:nth-child(-n+2) { border-top: none; } }
  .fact .k {
    font-size: 0.75rem; font-weight: 600;
    letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--ink-soft);
  }
  .fact .v {
    font-family: "IBM Plex Mono", monospace;
    font-size: 1.15rem; font-weight: 600; margin-top: 0.2rem;
  }

  /* ── Khung section chung ──────────────────────── */
  section.block { padding: 4rem 0 1rem; }
  section.block:last-of-type { padding-bottom: 4rem; }
  .sec-head { margin-bottom: 2rem; max-width: 42rem; }
  .sec-head h2 {
    font-family: "Archivo", sans-serif;
    font-size: clamp(1.5rem, 3vw, 1.9rem);
    font-weight: 700; letter-spacing: -0.01em;
    text-wrap: balance; margin-top: 0.5rem;
  }
  .sec-head p { color: var(--ink-soft); margin-top: 0.6rem; }

  /* ── Mục tiêu: hai phần ───────────────────────── */
  .parts { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
  @media (max-width: 720px) { .parts { grid-template-columns: 1fr; } }
  .part {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 12px; padding: 1.6rem 1.7rem;
    box-shadow: var(--shadow);
    border-top: 3px solid var(--part-color, var(--accent));
  }
  .part.p2 { --part-color: var(--teal); }
  .part .tag {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.75rem; font-weight: 600;
    letter-spacing: 0.12em; text-transform: uppercase;
    color: var(--part-color, var(--accent));
  }
  .part h3 {
    font-family: "Archivo", sans-serif;
    font-size: 1.2rem; font-weight: 700;
    margin: 0.45rem 0 0.6rem;
  }
  .part p { color: var(--ink-soft); font-size: 0.95rem; }
  .part ul {
    margin-top: 0.9rem; padding: 0; list-style: none;
    display: flex; flex-wrap: wrap; gap: 0.45rem;
  }
  .part li {
    font-size: 0.82rem; font-weight: 500;
    padding: 0.25rem 0.65rem; border-radius: 999px;
    background: color-mix(in srgb, var(--part-color, var(--accent)) 10%, transparent);
    color: var(--part-color-ink, var(--accent-ink));
  }
  .part.p2 li { --part-color-ink: var(--teal-ink); color: var(--teal-ink); }

  /* ── Chuẩn đầu ra ─────────────────────────────── */
  .outcomes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
  .outcomes.two { grid-template-columns: repeat(2, 1fr); }
  @media (max-width: 900px) { .outcomes { grid-template-columns: 1fr; } }
  .outcome-group {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 12px; padding: 1.5rem 1.6rem; box-shadow: var(--shadow);
  }
  .outcome-group h3 {
    font-family: "Archivo", sans-serif;
    font-size: 1.02rem; font-weight: 700; margin-bottom: 0.9rem;
  }
  .outcome-group ul { list-style: none; display: grid; gap: 0.65rem; }
  .outcome-group li {
    display: grid; grid-template-columns: 1.15rem 1fr; gap: 0.6rem;
    font-size: 0.92rem; color: var(--ink-soft);
  }
  .outcome-group li::before {
    content: "✓";
    font-family: "IBM Plex Mono", monospace;
    font-weight: 600; color: var(--teal);
    line-height: 1.65;
  }

  /* ── Đánh giá ─────────────────────────────────── */
  .grade-bar {
    display: flex; height: 3.1rem; border-radius: 10px;
    overflow: hidden; box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
  }
  .grade-bar .seg {
    display: flex; align-items: center; justify-content: center;
    font-family: "IBM Plex Mono", monospace;
    font-weight: 600; font-size: 0.95rem;
    color: #FFFFFF;
  }
  .seg.s-lab  { flex: 30; background: #2050D8; }
  .seg.s-comp { flex: 25; background: #5B7FE8; }
  .seg.s-proj { flex: 25; background: #12A08F; }
  .seg.s-exam { flex: 20; background: #0B6E63; }
  .grade-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.25rem; }
  @media (max-width: 900px) { .grade-cards { grid-template-columns: repeat(2, 1fr); } }
  @media (max-width: 560px) { .grade-cards { grid-template-columns: 1fr; } }
  .grade-card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 12px; padding: 1.35rem 1.4rem; box-shadow: var(--shadow);
  }
  .grade-card .dot-row { display: flex; align-items: baseline; gap: 0.55rem; }
  .grade-card .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; align-self: center; }
  .dot.c-lab  { background: #2050D8; } .dot.c-comp { background: #5B7FE8; }
  .dot.c-proj { background: #12A08F; } .dot.c-exam { background: #0B6E63; }
  .dot.c-ext  { background: var(--line); border: 1px dashed var(--ink-soft); }
  .grade-card .pct {
    font-family: "IBM Plex Mono", monospace;
    font-size: 1.55rem; font-weight: 600;
    font-variant-numeric: tabular-nums;
  }
  .grade-card h3 { font-size: 0.98rem; font-weight: 600; margin: 0.45rem 0 0.3rem; }
  .grade-card p { font-size: 0.86rem; color: var(--ink-soft); }

  /* ── Lịch học ─────────────────────────────────── */
  .phase-label {
    display: flex; align-items: center; gap: 0.8rem;
    margin: 2.2rem 0 0.9rem;
  }
  .phase-label:first-child { margin-top: 0; }
  .phase-label .name {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.8rem; font-weight: 600;
    letter-spacing: 0.12em; text-transform: uppercase;
    color: var(--phase-c, var(--accent));
    white-space: nowrap;
  }
  .phase-label .rule { height: 1px; flex: 1; background: var(--line); }
  .phase-label.ph2 { --phase-c: var(--teal); }

  .sched { display: grid; gap: 0.5rem; }
  .week {
    display: grid; grid-template-columns: 5.2rem 1fr; gap: 1.1rem;
    align-items: baseline;
    background: var(--surface); border: 1px solid var(--line);
    border-left: 3px solid var(--wk-c, var(--accent));
    border-radius: 10px; padding: 0.85rem 1.2rem;
  }
  .week.ph2 { --wk-c: var(--teal); }
  .week .no {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.8rem; font-weight: 600;
    color: var(--ink-soft); white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
  .week .topic { font-size: 0.95rem; font-weight: 500; }
  .week .sub { display: block; font-size: 0.84rem; font-weight: 400; color: var(--ink-soft); margin-top: 0.1rem; }
  /* A schedule row whose week has a page on this site links from its topic title.
     The underline is tinted with the row's own part colour (--wk-c), so the link
     reads as part of the schedule rather than as loose body-text link. */
  .week .topic a {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, var(--wk-c, var(--accent)) 45%, transparent);
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
  }
  .week .topic a:hover,
  .week .topic a:focus-visible {
    color: var(--wk-c, var(--accent));
    text-decoration-color: var(--wk-c, var(--accent));
  }
  .week.special {
    background: color-mix(in srgb, var(--wk-c) 7%, var(--surface));
    border-color: color-mix(in srgb, var(--wk-c) 30%, var(--line));
  }
  .week.holiday { --wk-c: var(--red); }
  .week.midterm { --wk-c: var(--amber); }
  .badge {
    display: inline-block;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.68rem; font-weight: 600;
    letter-spacing: 0.08em; text-transform: uppercase;
    padding: 0.15rem 0.55rem; border-radius: 999px;
    background: color-mix(in srgb, var(--wk-c) 14%, transparent);
    color: var(--wk-c);
    margin-left: 0.55rem; vertical-align: 0.1em;
  }
  @media (max-width: 560px) {
    .week { grid-template-columns: 1fr; gap: 0.15rem; }
  }
  .sched-note {
    margin-top: 1.4rem; font-size: 0.86rem; color: var(--ink-soft);
    max-width: 46rem;
  }

  /* ── Chân trang ───────────────────────────────── */
  footer {
    border-top: 1px solid var(--line);
    background: var(--surface);
    margin-top: 2rem;
  }
  footer .wrap {
    padding: 2rem 1.5rem;
    display: flex; flex-wrap: wrap; justify-content: space-between;
    gap: 1rem; align-items: baseline;
  }
  footer .brand { font-family: "IBM Plex Mono", monospace; font-size: 0.85rem; font-weight: 600; }
  footer .brand b { color: var(--accent); }
  footer p { font-size: 0.82rem; color: var(--ink-soft); }
  /* ── Learning materials ───────────────────────── */
  .materials-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem; }
  @media (max-width: 720px) { .materials-grid { grid-template-columns: 1fr; } }
  .mat-card {
    display: block; text-decoration: none;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 12px; padding: 1.5rem 1.6rem;
    box-shadow: var(--shadow);
    border-top: 3px solid var(--accent);
  }
  .mat-card:hover { border-color: var(--accent); }
  .mat-card.playground { border-top-color: var(--teal); }
  .mat-card.supp { border-top-style: dashed; }
  .mat-card.supp .mat-num { color: var(--ink-soft); }
  .mat-card .mat-num {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.78rem; font-weight: 600;
    letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--accent);
  }
  .mat-card.playground .mat-num { color: var(--teal); }
  .mat-card h3 {
    font-family: "Archivo", sans-serif;
    font-size: 1.12rem; font-weight: 700;
    color: var(--ink); margin: 0.4rem 0 0.45rem;
  }
  .mat-card p { font-size: 0.92rem; color: var(--ink-soft); margin-bottom: 0.7rem; }
  .mat-card .mat-meta {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.74rem; color: var(--ink-soft);
  }
  /* ── 41039 additions ──────────────────────────── */

  /* Language badges — Java / Python, used on chips, code cards and week rows */
  .lang {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.72rem; font-weight: 600;
    letter-spacing: 0.06em; text-transform: uppercase;
    padding: 0.12rem 0.44rem; border-radius: 4px;
    border: 1px solid currentColor;
    white-space: nowrap;
  }
  .lang.java { color: var(--java); }
  .lang.python { color: var(--python); }

  /* Hero: the two languages, side by side — the point of the subject */
  .code-duo { display: grid; gap: 0.85rem; min-width: 0; }
  .code-card { min-width: 0; }
  .code-duo .code-card { margin: 0; }
  .code-duo .code-card .bar .file { display: flex; align-items: center; gap: 0.5rem; }

  /* Week rows carry which language(s) they use */
  .week .langs { display: inline-flex; gap: 0.3rem; margin-left: 0.5rem; vertical-align: middle; }
  @media (max-width: 560px) { .week .langs { margin-left: 0; } }

  /* Assessment: the optional 0% extension track sits apart from the four graded items */
  .grade-card.optional { border-style: dashed; }
  .grade-card.optional .pct { color: var(--ink-soft); }

  /* A plain note/callout, reused on the homepage and week pages */
  .note {
    border: 1px solid var(--line); border-left: 3px solid var(--accent);
    background: var(--surface); border-radius: 0 10px 10px 0;
    padding: 1rem 1.15rem; box-shadow: var(--shadow);
  }
  .note + .note { margin-top: 0.9rem; }
  .note .tag {
    display: inline-block; font-family: "IBM Plex Mono", monospace;
    font-size: 0.7rem; font-weight: 600; letter-spacing: 0.12em;
    text-transform: uppercase; color: var(--accent); margin-bottom: 0.35rem;
  }
  .note.tip { border-left-color: var(--teal); }
  .note.tip .tag { color: var(--teal); }
  .note.warn { border-left-color: var(--amber); }
  .note.warn .tag { color: var(--amber); }
  .note.danger { border-left-color: var(--red); }
  .note.danger .tag { color: var(--red); }


  :root {
    --green: #1B7F3B;
    --accent-contrast: #FFFFFF;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) { --green: #5BC97E; --accent-contrast: #0D1420; }
  }
  :root[data-theme="dark"] { --green: #5BC97E; --accent-contrast: #0D1420; }

/* ── Concept prose ── */
.concept { margin-bottom: 1.6rem; max-width: 46rem; }
.lesson-panel .concept { max-width: none; margin-bottom: 1.5rem; }
.concept.wide { max-width: none; }
.concept h3 {
  font-size: 1.18rem; font-weight: 700;
  margin-bottom: 0.6rem;
}
.concept h3 .idx {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem; font-weight: 600;
  color: var(--accent); margin-right: 0.5rem;
}
.concept p { color: var(--ink-soft); margin-bottom: 0.7rem; }
.concept p strong, .concept li strong { color: var(--ink); }
.concept ul, .concept ol { margin: 0.2rem 0 0.9rem 1.2rem; color: var(--ink-soft); }
.concept li { margin-bottom: 0.3rem; }
.concept li::marker { color: var(--accent); }
code {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85em;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent-ink);
  padding: 0.1em 0.35em; border-radius: 4px;
}

/* ── Data tables ── */
.tbl-scroll { overflow-x: auto; margin: 1rem 0 1.2rem; }
table.tbl {
  border-collapse: collapse; width: 100%;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; font-size: 0.92rem;
  box-shadow: var(--shadow);
}
table.tbl th {
  text-align: left; font-weight: 600;
  font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-soft);
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
}
table.tbl td {
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
}
table.tbl tr:last-child td { border-bottom: none; }
table.tbl td.mono, table.tbl th.mono { font-family: "IBM Plex Mono", monospace; font-variant-numeric: tabular-nums; }
table.tbl td.ok { color: var(--green); font-weight: 600; }
table.tbl td.bad { color: var(--red); font-weight: 600; }

/* ── Quiz ── */
.quiz-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.8rem;
  position: sticky; top: 3.5rem; z-index: 10;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  padding: 0.7rem 0; margin-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
.quiz-score {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.9rem; font-weight: 600;
  color: var(--ink-soft);
}
.quiz-score .good { color: var(--green); }
.btn {
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  font-size: 0.88rem; font-weight: 600;
  border-radius: 8px; padding: 0.5rem 1rem;
  cursor: pointer; border: 1px solid transparent;
}
.btn.primary { background: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost {
  background: var(--surface); color: var(--ink-soft);
  border-color: var(--line);
}
.btn.ghost:hover { color: var(--ink); border-color: var(--ink-soft); }
.btn.small { font-size: 0.8rem; padding: 0.35rem 0.75rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.quiz-q {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 1.2rem 1.3rem;
  box-shadow: var(--shadow); margin-bottom: 1rem;
}
.quiz-q .qhead {
  display: flex; gap: 0.7rem; align-items: baseline;
  margin-bottom: 0.8rem;
}
.quiz-q .qnum {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem; font-weight: 600;
  color: var(--accent); white-space: nowrap;
}
.quiz-q .qtext { font-weight: 600; font-size: 0.97rem; }
.quiz-q .qtext code { font-weight: 500; }
.quiz-q pre.qcode {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.82rem; line-height: 1.6;
  background: var(--code-bg); color: var(--code-text);
  border-radius: 8px; padding: 0.7rem 0.9rem;
  overflow-x: auto; margin: 0 0 0.8rem;
}
.opts { display: grid; gap: 0.45rem; }
.opt {
  display: flex; gap: 0.6rem; align-items: baseline;
  text-align: left; width: 100%;
  background: var(--paper); color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 0.55rem 0.8rem; cursor: pointer;
  font-size: 0.92rem; font-family: inherit; line-height: 1.5;
}
.opt .key {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem; font-weight: 600; color: var(--ink-soft);
}
.opt:hover { border-color: var(--ink-soft); color: var(--ink); }
.opt[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 9%, var(--surface));
  color: var(--ink);
}
.opt[aria-pressed="true"] .key { color: var(--accent); }
.graded .opt { cursor: default; }
.graded .opt.right {
  border-color: var(--green);
  background: color-mix(in srgb, var(--green) 10%, var(--surface));
  color: var(--ink);
}
.graded .opt.wrong-pick {
  border-color: var(--red);
  background: color-mix(in srgb, var(--red) 9%, var(--surface));
}
.why {
  display: none;
  margin-top: 0.8rem; padding: 0.7rem 0.9rem;
  border-left: 3px solid var(--teal);
  background: color-mix(in srgb, var(--teal) 7%, var(--surface));
  border-radius: 8px;
  font-size: 0.87rem; color: var(--ink-soft);
}
.graded .why { display: block; }
.why strong { color: var(--ink); }

/* ── Prev/next & footer ── */
.pagenav {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 2rem 0 0;
}
.pagenav a {
  text-decoration: none;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 0.8rem 1.1rem;
  color: var(--ink); font-weight: 600; font-size: 0.9rem;
  box-shadow: var(--shadow);
  max-width: 48%;
}
.pagenav a:hover { border-color: var(--accent); }
.pagenav .dir {
  display: block;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-soft); margin-bottom: 0.15rem;
}
footer.site {
  border-top: 1px solid var(--line);
  background: var(--surface);
  margin-top: 3rem;
}
footer.site .wrap {
  padding: 1.8rem 1.5rem;
  display: flex; flex-wrap: wrap; justify-content: space-between;
  gap: 1rem; align-items: baseline;
}
footer.site .brand { font-family: "IBM Plex Mono", monospace; font-size: 0.85rem; font-weight: 600; color: var(--ink); }
footer.site .brand b { color: var(--accent); }
footer.site p { font-size: 0.82rem; color: var(--ink-soft); }


  /* Editor token palette. Like --code-*, these follow the CODE theme button,
     not the site's light/dark setting. */
  :root {
    --code-hl-kw:   #C792EA;
    --code-hl-type: #82AAFF;
    --code-hl-fn:   #FFCB6B;
    --code-hl-str:  #C3E88D;
    --code-hl-chr:  #F78C6C;
    --code-hl-num:  #F78C6C;
    --code-hl-ann:  #FF9E64;
    --code-hl-op:   #89DDFF;
    --code-hl-cm:   #7E8CA8;
  }
  :root[data-code-theme="paper"] {
    --code-hl-kw:   #8A1C88;
    --code-hl-type: #0B5C8F;
    --code-hl-fn:   #6F4400;
    --code-hl-str:  #1F6B24;
    --code-hl-chr:  #8F4A00;
    --code-hl-num:  #8F4A00;
    --code-hl-ann:  #B3261E;
    --code-hl-op:   #24292F;
    --code-hl-cm:   #57606A;
  }
  :root[data-code-theme="contrast"] {
    --code-hl-kw:   #FF8AF0;
    --code-hl-type: #6AB8FF;
    --code-hl-fn:   #FFD866;
    --code-hl-str:  #8CFFC1;
    --code-hl-chr:  #FFA96B;
    --code-hl-num:  #FFA96B;
    --code-hl-ann:  #FFB86C;
    --code-hl-op:   #9BE4FF;
    --code-hl-cm:   #B0BAC9;
  }

/* ── Interactive console (playground + week-page embeds) ── */
.console {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
  margin: 1.2rem 0 1.6rem; overflow: hidden;
  container-type: inline-size;
}
.console-head {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem;
  padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--line);
}
.console-head .title {
  font-family: "Archivo", sans-serif; font-weight: 700;
  font-size: 0.95rem; margin-right: auto;
}
.lang-tabs { display: inline-flex; gap: 0.3rem; }
.lang-tabs button {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; cursor: pointer;
  padding: 0.25rem 0.6rem; border-radius: 6px;
  background: var(--paper); color: var(--ink-soft);
  border: 1px solid var(--line);
}
.lang-tabs button[aria-pressed="true"] {
  border-color: currentColor; background: var(--surface);
}
.lang-tabs button.java[aria-pressed="true"] { color: var(--java); }
.lang-tabs button.python[aria-pressed="true"] { color: var(--python); }

/* ── Code on the left, input/output on the right ──
   A container query (not a viewport media query) because the same console can sit
   full-width on the playground or squeezed into a narrow lecture-card column. */
.console-cols { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: stretch; }
.console-col-io { border-left: 1px solid var(--line); display: flex; flex-direction: column; }
@container (max-width: 760px) {
  .console-cols { grid-template-columns: 1fr; }
  .console-col-io { border-left: 0; }
}

.console-editor, .console-stdin {
  display: block; width: 100%; resize: vertical;
  background: var(--code-bg); color: var(--code-text);
  border: 0; outline: none;
  font-family: "IBM Plex Mono", monospace;
  font-size: calc(0.83rem * var(--code-scale, 1)); line-height: 1.7;
  padding: 0.9rem 1.05rem;
  tab-size: 4;
}
.console-editor { min-height: 11rem; }
.console-stdin {
  min-height: 2.5rem; height: 4rem;
  border-top: 1px solid var(--line);
}
.console-editor:focus-visible, .console-stdin:focus-visible {
  outline: 2px solid var(--accent); outline-offset: -2px;
}
.console-sub {
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-soft);
  padding: 0.5rem 0.9rem 0; background: var(--surface);
  border-top: 1px solid var(--line);
}
.console-sub .hint {
  font-weight: 400; letter-spacing: 0.04em; text-transform: none;
  opacity: 0.7; font-size: 0.68rem;
}
@media (max-width: 560px) { .console-sub .hint { display: none; } }
.console-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem;
  padding: 0.7rem 0.9rem; border-top: 1px solid var(--line);
}
.console-status {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem; color: var(--ink-soft);
}
.console-status .ok { color: var(--green); }
.console-status .bad { color: var(--red); }
.console-out {
  margin: 0; padding: 0.9rem 1.05rem;
  background: var(--code-bg); color: var(--code-text);
  font-family: "IBM Plex Mono", monospace;
  font-size: calc(0.82rem * var(--code-scale, 1)); line-height: 1.65;
  white-space: pre-wrap; word-break: break-word;
  overflow: auto;
  resize: vertical;
  height: 10rem; min-height: 3rem;
  border-top: 1px solid var(--line);
}
.console-out .err { color: #FF9B9B; }
.console-out .muted { color: var(--code-cm); }
.console-out:empty::before {
  content: "Output appears here."; color: var(--code-cm);
}
/* First run pulls a real runtime over the network — say so, do not just hang. */
.console-boot {
  padding: 0.6rem 0.9rem; font-size: 0.82rem;
  color: var(--ink-soft); border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--amber) 8%, var(--surface));
}
.console-boot[hidden] { display: none; }
.preset-row { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0.7rem 0.9rem 0; }
.preset-row button {
  font-family: "IBM Plex Mono", monospace; font-size: 0.74rem;
  padding: 0.22rem 0.55rem; border-radius: 999px; cursor: pointer;
  background: var(--paper); color: var(--ink-soft);
  border: 1px solid var(--line);
}
.preset-row button:hover { color: var(--ink); border-color: var(--ink-soft); }

/* ── Highlighted editor: a <pre> layer sits behind a transparent <textarea> ── */
.editor-shell {
  position: relative;
  min-height: 8rem;
  height: 14rem;
  /* Native grip. The textarea itself cannot be resized any more (it is absolutely
     positioned), so the shell carries the resize affordance instead. */
  resize: vertical;
  overflow: hidden;
  border-top: 1px solid var(--line);
}
.editor-shell { --gutter-w: 2.4rem; }
/* All three layers share every metric that affects where a glyph lands. Only the
   left padding differs: the gutter owns the left strip, the other two start after it. */
.editor-shell .hl-gutter,
.editor-shell .hl-layer,
.editor-shell textarea.code-edit {
  position: absolute; top: 0; bottom: 0;
  margin: 0; height: 100%;
  box-sizing: border-box;
  padding-top: 0.9rem; padding-bottom: 0.9rem;
  border: 0;
  font-family: "IBM Plex Mono", "SF Mono", Consolas, monospace;
  font-size: calc(0.83rem * var(--code-scale, 1));
  font-weight: 500;
  line-height: 1.7;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
  word-spacing: 0;
  letter-spacing: normal;
  font-variant-ligatures: none;
  font-kerning: none;
}
.editor-shell .hl-layer,
.editor-shell textarea.code-edit {
  left: 0; right: 0; width: 100%;
  padding-left: calc(var(--gutter-w) + 0.75rem);
  padding-right: 1.05rem;
}
.editor-shell .hl-gutter {
  left: 0; width: var(--gutter-w);
  padding-right: 0.55rem; padding-left: 0.35rem;
  text-align: right;
  color: var(--code-cm);
  background: var(--code-gutter, color-mix(in srgb, var(--code-bg) 88%, #FFFFFF));
  border-right: 1px solid color-mix(in srgb, var(--code-cm) 35%, transparent);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  z-index: 1;
}
.editor-shell .hl-layer {
  background: var(--code-bg);
  color: var(--code-text);
  pointer-events: none;
  scrollbar-width: none;
}
.editor-shell .hl-layer::-webkit-scrollbar { display: none; }
.editor-shell textarea.code-edit {
  background: transparent;
  color: transparent;
  caret-color: var(--code-caret);
  resize: none;
  outline: none;
}
.editor-shell textarea.code-edit::selection {
  background: color-mix(in srgb, var(--accent) 38%, transparent);
  color: transparent;
}
.editor-shell textarea.code-edit:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.hl-kw   { color: var(--code-hl-kw); font-weight: 600; }   /* IBM Plex Mono keeps the same advance width in every weight */
.hl-type { color: var(--code-hl-type); }
.hl-fn   { color: var(--code-hl-fn); }
.hl-str  { color: var(--code-hl-str); }
.hl-chr  { color: var(--code-hl-chr); }
.hl-num  { color: var(--code-hl-num); }
.hl-ann  { color: var(--code-hl-ann); }
.hl-op   { color: var(--code-hl-op); }
.hl-cm   { color: var(--code-hl-cm); font-style: italic; }

/* Quiz snippets get the same colours, without an editor around them. */
pre.qcode .hl-cm { font-style: italic; }

/* one block per logical line, so a wrapped line keeps a single line number */
.editor-shell .hl-layer .cl { min-height: 1.7em; }
/* soft wrap (default). Both layers must wrap identically: same rules here, and editor.js gives
   the highlight layer the textarea's scrollbar width as extra right padding. */
:root:not([data-code-wrap="off"]) .editor-shell .hl-layer,
:root:not([data-code-wrap="off"]) .editor-shell textarea.code-edit {
  white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: hidden;
}

/* ── Code-window toolbar: A− A+ · Wrap · theme | Undo · Redo · Save… · Open… ── */
.editor-wrap { border-top: 1px solid var(--line); }
.editor-wrap .editor-shell { border-top: 0; }
.editor-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.3rem;
  padding: 0.4rem 0.75rem; background: var(--surface);
}
.ed-btn {
  font-family: "IBM Plex Mono", monospace; font-size: 0.72rem; font-weight: 600;
  color: var(--ink-soft); background: var(--surface);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 0.22rem 0.55rem; cursor: pointer; white-space: nowrap;
}
.ed-btn:hover:not(:disabled) { color: var(--ink); border-color: var(--ink-soft); }
.ed-btn:disabled { opacity: 0.4; cursor: default; }
.ed-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.font-size-group { display: flex; }
.font-size-group .ed-btn:first-child { border-radius: 7px 0 0 7px; }
.font-size-group .ed-btn:last-child { border-radius: 0 7px 7px 0; margin-left: -1px; }
.ed-sep { width: 1px; height: 1.1rem; background: var(--line); margin: 0 0.2rem; }
.ed-note {
  flex: 1 1 auto; min-width: 0; text-align: right; margin-right: 0.3rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: "IBM Plex Mono", monospace; font-size: 0.72rem; color: var(--teal, var(--accent));
}

/* ── Full-screen code window: the whole console / exercise card is lifted over the page ── */
body.code-fullscreen-open { overflow: hidden; }
.code-fullscreen {
  position: fixed; inset: 0.75rem; z-index: 1000; margin: 0; max-width: none;
  display: flex; flex-direction: column; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(8, 12, 22, 0.6), 0 24px 80px rgba(0, 0, 0, 0.45);
}
.code-fullscreen > * { flex: 0 0 auto; }
.code-fullscreen > .editor-wrap { flex: 1 1 auto; min-height: 12rem; display: flex; flex-direction: column; }
.code-fullscreen .editor-shell { flex: 1 1 auto; height: auto; min-height: 6rem; max-height: none; resize: none; }
.code-fullscreen > .console-cols { flex: 1 1 auto; min-height: 0; }
.code-fullscreen .console-col-code { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.code-fullscreen .console-col-code .editor-wrap { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.code-fullscreen .console-col-code .editor-shell { flex: 1 1 auto; height: auto; min-height: 0; max-height: none; resize: none; }
.console.code-fullscreen .console-col-io .console-out { flex: 1 1 auto; height: auto; max-height: none; resize: none; }
.console.code-fullscreen .console-col-io .console-stdin { height: 4.5rem; flex: 0 0 auto; }
@media (max-width: 640px) { .code-fullscreen { inset: 0; border-radius: 0; } }

/* ── Input mode switch and the interactive terminal ── */
.console-io { padding: 0.6rem 0.9rem; border-top: 1px solid var(--line); }
.console-io + .console-sub { border-top: 0; }
.io-mode { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.io-mode button { font-family: "IBM Plex Mono", monospace; font-size: 0.72rem; font-weight: 600; color: var(--ink-soft); background: none; border: 0; padding: 0.28rem 0.65rem; cursor: pointer; }
.io-mode button + button { border-left: 1px solid var(--line); }
.io-mode button[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.io-mode button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.console-sub[hidden], .console-stdin[hidden] { display: none; }
.console-out[data-empty]:empty::before { content: attr(data-empty); }
.console-out .t-in { color: var(--code-kw); font-weight: 600; }
.console-out .t-field { display: inline-block; min-width: 1ch; outline: none; color: var(--code-kw); font-weight: 600; caret-color: var(--code-text); white-space: pre-wrap; }
.console-out.is-terminal { cursor: text; }
.console-out.is-terminal:focus-within { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 60%, transparent); }
.term-hint { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; padding: 0.45rem 0.9rem; font-size: 0.78rem; color: var(--ink-soft); border-top: 1px solid var(--line); }
.term-hint[hidden] { display: none; }
.term-hint kbd { font-family: "IBM Plex Mono", monospace; font-size: 0.72rem; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 0.3rem; background: var(--surface); }
.term-hint button { font-family: "IBM Plex Mono", monospace; font-size: 0.7rem; font-weight: 600; color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 0.15rem 0.45rem; cursor: pointer; }
.term-hint button:hover { color: var(--ink); border-color: var(--ink-soft); }

/* ── Lecture layout: section list on the left, content on the right ── */
.lesson {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 900px) {
  .lesson { grid-template-columns: minmax(0, 1fr); gap: 1.2rem; }
}

.lesson-nav {
  display: flex; flex-direction: column; gap: 0.3rem;
  position: sticky; top: 4.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.35rem;
  box-shadow: var(--shadow);
}
@media (max-width: 900px) {
  /* On a narrow screen the rail becomes a horizontal strip above the content. */
  .lesson-nav {
    position: static;
    flex-direction: row; overflow-x: auto;
    scroll-snap-type: x proximity;
  }
  .lesson-nav .lesson-tab { flex: 0 0 auto; scroll-snap-align: start; }
  .lesson-nav .t-meta { display: none; }
}

.lesson-tab {
  display: flex; align-items: baseline; gap: 0.6rem;
  width: 100%; text-align: left;
  background: none; border: 0;
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  cursor: pointer;
  font-family: inherit; color: var(--ink-soft);
  border-left: 3px solid transparent;
}
.lesson-tab:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); color: var(--ink); }
.lesson-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.lesson-tab[aria-selected="true"] {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-left-color: var(--accent);
  color: var(--ink);
}
.lesson-tab .t-num {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem; font-weight: 600;
  color: var(--accent);
}
.lesson-tab .t-text { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.lesson-tab .t-title {
  font-family: "Archivo", sans-serif; font-weight: 700;
  font-size: 0.92rem; line-height: 1.3;
}
.lesson-tab .t-meta {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem; color: var(--ink-soft);
}

.lesson-content { min-width: 0; }
.lesson-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 1.25rem 1.4rem 1.4rem;
}
.lesson-panel:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lesson-panel > .concept:last-child { margin-bottom: 0; }
@media (max-width: 560px) { .lesson-panel { padding: 1.1rem 1rem 1.3rem; } }

.panel-head {
  display: flex; align-items: baseline; gap: 0.7rem;
  font-family: "Archivo", sans-serif;
  font-size: 1.25rem; font-weight: 700;
  margin-bottom: 0.9rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--line);
}
.panel-head .panel-num {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85rem; font-weight: 600; color: var(--accent);
}

/* Previous / next inside the content pane */
.panel-nav {
  display: flex; justify-content: space-between; gap: 0.6rem;
  margin-top: 1.6rem; padding-top: 1.1rem;
  border-top: 1px solid var(--line);
}
.panel-nav button { min-width: 0; }
.panel-nav .spacer { flex: 1; }

/* ── Figures: comics and photographs ── */
.fig { margin: 0.9rem 0 1rem; text-align: center; }
.fig img {
  max-width: 100%; height: auto;
  max-height: 19rem; width: auto;
  border-radius: 8px;
  background: #FFFFFF;
  padding: 0.4rem;
}
.fig.plain img { background: none; padding: 0; }
.fig figcaption {
  font-size: 0.8rem; color: var(--ink-soft);
  margin-top: 0.5rem; text-align: center;
}
.fig figcaption .credit {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem; color: var(--ink-soft); opacity: 0.85;
  display: block; margin-top: 0.15rem;
}
.fig-narrow img { max-width: 24rem; }
.fig-wide img { max-width: 40rem; }
/* Comics are line art and need their height to stay readable; photographs are
   decorative here and get the tighter cap above. */
.fig.plain img { max-height: 26rem; }

/* Inline SVG diagrams (flowcharts) reuse .fig for the frame and caption, but an
   <svg> needs its own sizing rule — .fig img above does not match it. */
.fig svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.fig-narrow svg { max-width: 24rem; }
.fig-wide svg { max-width: 40rem; }

/* Flowchart symbol shapes (theme-aware: fill/stroke follow light/dark tokens) */
.fc-terminal  { fill: color-mix(in srgb, var(--accent) 12%, var(--surface)); stroke: var(--accent); stroke-width: 1.6; }
.fc-io        { fill: color-mix(in srgb, var(--teal) 12%, var(--surface)); stroke: var(--teal); stroke-width: 1.6; }
.fc-process   { fill: var(--surface); stroke: var(--ink-soft); stroke-width: 1.6; }
.fc-decision  { fill: color-mix(in srgb, var(--amber) 12%, var(--surface)); stroke: var(--amber); stroke-width: 1.6; }
.fc-connector { fill: var(--surface); stroke: var(--ink-soft); stroke-width: 1.6; }
.fc-text  { fill: var(--ink); font-family: "IBM Plex Mono", monospace; font-size: 12px; }
.fc-label { fill: var(--ink-soft); font-family: "IBM Plex Mono", monospace; font-size: 11px; }
.fc-line  { stroke: var(--ink-soft); stroke-width: 1.5; fill: none; }
.fc-arrowhead { fill: var(--ink-soft); }

/* Flowchart symbol reference cards */
.symbols { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1.1rem; margin: 1rem 0 1.4rem; }
.symbol-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow, none);
}
.symbol-card svg { display: block; margin: 0 auto 0.7rem; }
.symbol-card h4 { font-family: "Archivo", sans-serif; font-size: 0.98rem; margin-bottom: 0.25rem; }
.symbol-card p { font-size: 0.85rem; color: var(--ink-soft); margin: 0; }

/* A pull-quote style joke box, matching the deck's */
.joke {
  border: 1px solid color-mix(in srgb, var(--amber) 45%, var(--line));
  border-left: 3px solid var(--amber);
  background: color-mix(in srgb, var(--amber) 7%, var(--surface));
  border-radius: 0 10px 10px 0;
  padding: 0.9rem 1.1rem;
  margin: 1rem 0;
}
.joke p { margin: 0; }
.joke .attrib {
  display: block; margin-top: 0.4rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem; color: var(--ink-soft);
}

/* Quotes carrying the author's photograph. The portrait sits in a left column that spans
   the whole box, so the quote and its attribution stack beside it. Anything that is not
   the photo column goes in column 2 — a quote may hold more than one paragraph. */
.joke.with-photo {
  display: grid; grid-template-columns: auto minmax(0, 1fr);
  column-gap: 1rem; align-items: start;
}
.joke.with-photo > .quote-photos {
  grid-column: 1; grid-row: 1 / span 20;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.joke.with-photo > *:not(.quote-photos) { grid-column: 2; }
.joke .quote-photo {
  display: block; width: 4.8rem; height: 4.8rem;
  object-fit: cover; object-position: center top; border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--amber) 45%, var(--line));
  background: var(--surface);
}
/* two authors on one quote: a little smaller, stacked */
.joke .quote-photos .quote-photo:not(:only-child) { width: 4rem; height: 4rem; }
@media (max-width: 560px) {
  .joke.with-photo { column-gap: 0.75rem; }
  .joke .quote-photo,
  .joke .quote-photos .quote-photo:not(:only-child) { width: 3.4rem; height: 3.4rem; }
}

/* "Did you know?" notes with a picture: text on the left, a square photo and its credit
   on the right. The credit is part of the licence, so it travels with the image. */
.note.with-media {
  display: grid; grid-template-columns: minmax(0, 1fr) 9rem;
  column-gap: 1.1rem; align-items: start;
}
.note.with-media > .note-text { min-width: 0; }
.note.with-media > .note-media { margin: 0; }
.note-media img {
  display: block; width: 100%; height: auto;
  aspect-ratio: 1 / 1; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
}
/* charts and diagrams must not be cropped, and they are drawn in dark ink */
.note-media img.contain { object-fit: contain; background: #FFFFFF; padding: 0.3rem; }
.note-media figcaption {
  margin-top: 0.3rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.63rem; line-height: 1.35; color: var(--ink-soft);
}
@media (max-width: 560px) {
  /* too narrow for two columns: text first, then the picture beside its credit */
  .note.with-media { grid-template-columns: minmax(0, 1fr); row-gap: 0.7rem; }
  .note.with-media > .note-media {
    display: grid; grid-template-columns: 6.5rem minmax(0, 1fr);
    column-gap: 0.7rem; align-items: end;
  }
  .note-media figcaption { margin-top: 0; }
}

/* ── Photographs ──
   `.fig` frames comics (line art on a white pad). A photograph is a different object: it
   fills its frame edge to edge and carries its caption on a bar underneath. */
.photo {
  margin: 0.9rem 0 1.2rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden; box-shadow: var(--shadow);
}
.photo img { display: block; width: 100%; height: auto; }
.photo figcaption {
  padding: 0.6rem 0.9rem 0.7rem;
  font-size: 0.82rem; line-height: 1.5; color: var(--ink-soft);
  border-top: 1px solid var(--line);
}
.photo figcaption strong { color: var(--ink); }
.photo figcaption .credit {
  display: block; margin-top: 0.3rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem; letter-spacing: 0.02em; color: var(--ink-soft); opacity: 0.85;
}
/* A banner opens a section: a wide strip, cropped, never tall enough to push the text away */
.photo.banner { max-width: 46rem; }
.photo.banner img { aspect-ratio: 21 / 8; object-fit: cover; object-position: center 55%; }
.photo.portrait { max-width: 15rem; }
.photo.side { max-width: 20rem; margin-top: 0.3rem; }

/* Prose on the left, a photograph beside it. Below 820px the photo drops under the text. */
.media-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, var(--media-w, 20rem));
  gap: 1.5rem; align-items: start; margin-bottom: 1.2rem;
}
.media-row > * { min-width: 0; }
.media-row > .concept { margin-bottom: 0; }
@media (max-width: 820px) {
  .media-row { grid-template-columns: minmax(0, 1fr); gap: 0.3rem; }
  .photo.banner img { aspect-ratio: 16 / 9; }
  .photo.side { max-width: 26rem; }
}

/* ── Auto-graded exercises ── */
.ex {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 1.4rem;
  overflow: hidden;
}
.ex-head { padding: 1rem 1.1rem 0.6rem; }
.ex-title-row { display: flex; align-items: baseline; gap: 0.6rem; margin-bottom: 0.3rem; }
.ex-title-row h4 {
  font-family: "Archivo", sans-serif; font-size: 1rem; font-weight: 700;
  margin-right: auto;
}
.ex-brief { font-size: 0.9rem; color: var(--ink-soft); margin: 0; }
.ex-brief code { font-size: 0.85em; }
.ex .editor-shell { height: 12rem; }

.ex-tests:not(:empty) { border-top: 1px solid var(--line); padding: 0.7rem 1.1rem 0.9rem; }
.ex-test { border-radius: 8px; padding: 0.5rem 0.7rem; margin-bottom: 0.45rem; }
.ex-test.pass { background: color-mix(in srgb, var(--green) 10%, transparent); }
.ex-test.fail { background: color-mix(in srgb, var(--red) 9%, transparent); }
.ex-test-head { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.badge-res {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em;
  padding: 0.1rem 0.4rem; border-radius: 4px;
}
.ex-test.pass .badge-res { background: var(--green); color: var(--accent-contrast); }
.ex-test.fail .badge-res { background: var(--red); color: #FFFFFF; }
.ex-test-name { font-weight: 600; font-size: 0.88rem; }
.ex-stdin {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem; color: var(--ink-soft); margin-left: auto;
}
.ex-diff { margin-top: 0.5rem; }
.ex-diff-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-soft); margin: 0.35rem 0 0.2rem;
}
.ex-pre {
  margin: 0; padding: 0.5rem 0.7rem; border-radius: 6px;
  background: var(--code-bg); color: var(--code-text);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem; line-height: 1.55;
  white-space: pre-wrap; overflow-x: auto;
}
.ex-pre.err { color: #FF9B9B; }
.ex-solution { border-top: 1px dashed var(--line); padding: 0.7rem 1.1rem 0.9rem; }
.ex-solution summary {
  cursor: pointer; font-size: 0.88rem; font-weight: 600; color: var(--ink-soft);
}
.ex-solution summary:hover { color: var(--ink); }
.ex-solution[open] summary { margin-bottom: 0.5rem; }
.ex-solnote { font-size: 0.82rem; color: var(--ink-soft); margin: 0 0 0.5rem; }

/* ── Team activity ── */
.team-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--teal);
  border-radius: 0 10px 10px 0;
  padding: 1rem 1.2rem;
  margin-bottom: 1rem;
}
.team-card h4 {
  font-family: "Archivo", sans-serif; font-size: 1rem; font-weight: 700;
  margin-bottom: 0.3rem;
}
.team-meta {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem; color: var(--teal); text-transform: uppercase;
  letter-spacing: 0.08em; margin-bottom: 0.4rem;
}
.team-card p, .team-card li { color: var(--ink-soft); font-size: 0.92rem; }
.team-card ol, .team-card ul { margin: 0.4rem 0 0 1.2rem; }
.team-card li { margin-bottom: 0.25rem; }

/* ── Further reading ── */
.read-grid { display: grid; gap: 0.8rem; }
.read-card {
  display: block;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  text-decoration: none;
  color: inherit;
}
.read-card:hover { border-color: var(--accent); }
.read-card .kind {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--teal);
}
.read-card h4 {
  font-family: "Archivo", sans-serif;
  font-size: 0.97rem; font-weight: 700;
  margin: 0.2rem 0 0.25rem;
  color: var(--ink);
}
.read-card p { font-size: 0.87rem; color: var(--ink-soft); margin: 0; }
.read-card .host {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem; color: var(--ink-soft);
  display: block; margin-top: 0.35rem; opacity: 0.85;
}
.read-group-title {
  font-family: "Archivo", sans-serif;
  font-size: 1rem; font-weight: 700;
  margin: 1.4rem 0 0.6rem;
}
.read-group-title:first-of-type { margin-top: 0.4rem; }

/* ── Second nav block under the section rail ── */
.lesson-side { display: flex; flex-direction: column; gap: 0.8rem; position: sticky; top: 4.5rem; }
.lesson-side .lesson-nav { position: static; }
.nav-group-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.66rem; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-soft);
  padding: 0.45rem 0.6rem 0.2rem;
}
.lesson-nav.misc .lesson-tab[aria-selected="true"] {
  background: color-mix(in srgb, var(--teal) 12%, transparent);
  border-left-color: var(--teal);
}
.lesson-nav.misc .lesson-tab .t-num { color: var(--teal); }
@media (max-width: 900px) {
  .lesson-side { position: static; }
  .lesson-side .lesson-nav { flex-direction: row; overflow-x: auto; }
  .nav-group-label { padding: 0.2rem 0.2rem 0; }
}

/* ── Timeline ── */
.timeline { display: grid; gap: 0.1rem; margin: 1rem 0 1.4rem; }
.tl-item {
  display: grid; grid-template-columns: 4.5rem minmax(0, 1fr);
  gap: 1rem; padding: 0.7rem 0;
  border-top: 1px solid var(--line);
}
.tl-item:last-child { border-bottom: 1px solid var(--line); }
.tl-year {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.95rem; font-weight: 600; color: var(--accent);
}
.tl-body h4 {
  font-family: "Archivo", sans-serif; font-size: 0.97rem; font-weight: 700;
  margin-bottom: 0.2rem;
}
.tl-body p { color: var(--ink-soft); font-size: 0.9rem; margin: 0; }
.tl-item.with-img { grid-template-columns: 4.5rem 7rem minmax(0, 1fr); }
.tl-item.with-img img {
  width: 100%; height: auto; max-height: 7rem; object-fit: cover;
  border-radius: 6px; background: #FFFFFF;
}
@media (max-width: 640px) {
  .tl-item, .tl-item.with-img { grid-template-columns: 3.4rem minmax(0, 1fr); gap: 0.7rem; }
  .tl-item.with-img img { display: none; }
}

/* ── Pull quotes ── */
.pullquote {
  border-left: 3px solid var(--teal);
  background: color-mix(in srgb, var(--teal) 6%, var(--surface));
  border-radius: 0 10px 10px 0;
  padding: 1rem 1.2rem;
  margin: 1rem 0;
}
.pullquote blockquote {
  font-size: 1.02rem; line-height: 1.55; color: var(--ink);
  margin: 0 0 0.5rem; font-style: italic;
}
.pullquote .who {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.76rem; color: var(--ink-soft);
}
.pullquote .caveat {
  display: block; margin-top: 0.5rem;
  font-size: 0.82rem; color: var(--ink-soft);
  font-style: normal;
}

/* A misattributed quote shown beside its portrait — the meme format, as the point */
.pullquote.misquote { border-left-color: var(--amber); background: color-mix(in srgb, var(--amber) 6%, var(--surface)); }
.misquote-body { display: grid; grid-template-columns: minmax(0, 1fr) 8.5rem; gap: 1.1rem; align-items: start; }
.misquote-fig { margin: 0; }
.misquote-fig img { width: 100%; height: auto; border-radius: 8px; display: block; }
.misquote-fig figcaption { margin-top: 0.4rem; }
.misquote-fig .credit {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem; line-height: 1.45; color: var(--ink-soft);
}
@media (max-width: 640px) {
  .misquote-body { grid-template-columns: minmax(0, 1fr); }
  .misquote-fig { max-width: 8.5rem; }
}

/* ── Explained code (assets/explain.js) ─────────────
   A read-only example whose marked parts explain themselves on hover, tap or focus. */
.explain {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
  margin: 1.2rem 0 1.6rem; overflow: hidden;
}
.explain-head {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.3rem 0.8rem;
  padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--line);
}
.explain-head .title {
  font-family: "Archivo", sans-serif; font-weight: 700;
  font-size: 0.95rem;
}
.explain-head .lang { margin-right: auto; font-family: "IBM Plex Mono", monospace; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.explain > [hidden] { display: none !important; }
.explain.is-editing { border: 0; background: none; box-shadow: none; overflow: visible; }
.explain.is-editing > .console { margin: 0; }
.explain-stdin { margin-left: auto; font-size: 0.78rem; color: var(--ink-soft); }
.explain-stdin code { font-family: "IBM Plex Mono", monospace; }
.explain-fixed-label { padding-bottom: 0.5rem; }
.explain-hint { font-size: 0.8rem; color: var(--ink-soft); }
.explain-hint .xk-sample {
  text-decoration: underline dotted; text-decoration-thickness: 1.5px; text-underline-offset: 0.25em;
}
.explain-hint .when-touch { display: none; }
@media (hover: none) {
  .explain-hint .when-hover { display: none; }
  .explain-hint .when-touch { display: inline; }
}
.explain-code {
  margin: 0; padding: 0.9rem 1.05rem 0.9rem 0;
  background: var(--code-bg); color: var(--code-text);
  font-family: "IBM Plex Mono", monospace;
  font-size: calc(0.83rem * var(--code-scale, 1)); line-height: 1.85;
  overflow-x: auto; counter-reset: ln; tab-size: 4;
}
.explain-code .cl {
  counter-increment: ln; position: relative;
  padding-left: 3.2em; min-height: 1.85em; white-space: pre;
}
.explain-code .cl::before {
  content: counter(ln); position: absolute; left: 0; width: 2.2em;
  text-align: right; color: var(--code-cm); opacity: 0.75; user-select: none;
}
.explain-code .xk {
  cursor: help; border-radius: 4px;
  text-decoration: underline dotted color-mix(in srgb, var(--code-text) 60%, transparent);
  text-decoration-thickness: 1.5px; text-underline-offset: 0.3em;
  background: color-mix(in srgb, var(--code-hl-kw) 13%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--code-hl-kw) 13%, transparent);
  transition: background-color 120ms ease, box-shadow 120ms ease;
}
.explain-code .xk:hover, .explain-code .xk.is-active, .explain-code .xk.is-linked {
  background: color-mix(in srgb, var(--code-hl-kw) 32%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--code-hl-kw) 32%, transparent);
}
.explain-code .xk:focus { outline: none; }
.explain-code .xk:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.explain .explain-out { height: auto; max-height: 20rem; resize: none; }
.explain .explain-out[hidden] { display: none; }

.explain-all { border-top: 1px solid var(--line); padding: 0.6rem 0.9rem; font-size: 0.9rem; }
.explain-all summary { cursor: pointer; color: var(--ink-soft); font-weight: 600; font-size: 0.85rem; }
.explain-all ol { margin: 0.6rem 0 0.3rem; padding-left: 1.5rem; display: grid; gap: 0.6rem; }
.explain-all li > strong { margin-right: 0.35rem; }
.explain-all li > div { display: inline; }
.explain-ref {
  display: block; font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem; color: var(--ink-soft);
}

/* one tooltip for the page, fixed to the viewport so scrolling code cannot clip it */
.explain-tip {
  position: fixed; top: 0; left: 0; z-index: 1000;
  max-width: min(23rem, calc(100vw - 16px));
  padding: 0.65rem 0.85rem; border-radius: 10px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-top: 3px solid var(--accent);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  font-size: 0.88rem; line-height: 1.5;
}
.explain-tip.above { border-top-width: 1px; border-bottom: 3px solid var(--accent); }
.explain-tip[hidden] { display: none; }
.explain-tip-title {
  display: block; margin-bottom: 0.2rem;
  font-family: "Archivo", sans-serif; color: var(--accent-ink);
}
.explain-tip-title[hidden] { display: none; }
.explain-tip code {
  font-family: "IBM Plex Mono", monospace; font-size: 0.85em;
  background: var(--paper); padding: 0.05em 0.3em; border-radius: 4px;
}
/* code quoted in a note keeps its spaces (output such as "after swap:  x = 1") */
.explain-tip code, .explain-all code { white-space: pre-wrap; }
