/* Colours come from the course decks: UCAS blue, the crest's green, dark code panels. */
@font-face { font-family: Plex; src: url(fonts/plex-arabic-400.woff2) format("woff2"); font-weight: 400; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Plex; src: url(fonts/plex-arabic-600.woff2) format("woff2"); font-weight: 600; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Plex; src: url(fonts/plex-arabic-700.woff2) format("woff2"); font-weight: 700; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Plex; src: url(fonts/plex-latin-400.woff2) format("woff2"); font-weight: 400; font-display: swap; unicode-range: U+0000-02FF, U+2000-206F, U+20AC, U+2190-21FF; }
@font-face { font-family: Plex; src: url(fonts/plex-latin-600.woff2) format("woff2"); font-weight: 600; font-display: swap; unicode-range: U+0000-02FF, U+2000-206F, U+20AC, U+2190-21FF; }
@font-face { font-family: Plex; src: url(fonts/plex-latin-700.woff2) format("woff2"); font-weight: 700; font-display: swap; unicode-range: U+0000-02FF, U+2000-206F, U+20AC, U+2190-21FF; }
@font-face { font-family: Mono; src: url(fonts/mono-400.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: Mono; src: url(fonts/mono-700.woff2) format("woff2"); font-weight: 700; font-display: swap; }

:root {
  color-scheme: light;
  --sans: Plex, "Segoe UI", Tahoma, system-ui, sans-serif;
  --mono: Mono, Plex, Consolas, Menlo, monospace;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --ink: #18222f;
  --muted: #5b6878;
  --line: #d9e0e9;
  --blue: #1565b0;
  --navy: #0b3a75;
  --green: #4c9a2a;
  --green-soft: #eaf5e1;
  --amber: #a85f00;
  --amber-soft: #fdf1df;
  --red: #c0392b;
  --red-soft: #fce9e6;
  --blue-soft: #e6f0fa;
  --code-bg: #1b2430;
  --code-ink: #e6edf3;
  --focus: #1565b0;
  --radius: 10px;
  --logo-bg: transparent;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #10161e;
    --surface: #18212c;
    --surface-2: #212c39;
    --ink: #e6edf3;
    --muted: #9dabbb;
    --line: #2f3c4c;
    --blue: #6cb0f0;
    --navy: #a9cdf2;
    --green: #8fd061;
    --green-soft: #1e2f17;
    --amber: #f0b05c;
    --amber-soft: #352610;
    --red: #ff8a7a;
    --red-soft: #3a1c18;
    --blue-soft: #16283c;
    --code-bg: #0d131a;
    --focus: #6cb0f0;
    --logo-bg: #fff;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #10161e;
  --surface: #18212c;
  --surface-2: #212c39;
  --ink: #e6edf3;
  --muted: #9dabbb;
  --line: #2f3c4c;
  --blue: #6cb0f0;
  --navy: #a9cdf2;
  --green: #8fd061;
  --green-soft: #1e2f17;
  --amber: #f0b05c;
  --amber-soft: #352610;
  --red: #ff8a7a;
  --red-soft: #3a1c18;
  --blue-soft: #16283c;
  --code-bg: #0d131a;
  --focus: #6cb0f0;
  --logo-bg: #fff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 17px/1.75 var(--sans); overflow-wrap: anywhere; }
a { color: var(--blue); }
h1, h2, h3, h4 { color: var(--navy); line-height: 1.35; font-weight: 700; }
h1 { font-size: clamp(1.8rem, 5vw, 2.7rem); margin: .2em 0; }
h2 { font-size: clamp(1.3rem, 3.2vw, 1.7rem); margin: 0 0 .6em; }
h4 { font-size: 1.08rem; margin: 0 0 .5em; }
p { margin: 0 0 1em; }
ul, ol { padding-inline-start: 1.5em; margin: 0 0 1em; }
li { margin-bottom: .35em; }
/* Beginners type what they see: <= must not be drawn as one glyph. */
code, pre, .cm-content, .console-input { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
code { font: .9em var(--mono); background: var(--surface-2); padding: .1em .35em; border-radius: 4px; direction: ltr; unicode-bidi: isolate; }
pre { margin: 0; font-family: var(--mono); }
small, .muted { color: var(--muted); }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; inset-inline-start: -999px; }
.skip:focus { inset-inline-start: 8px; top: 8px; z-index: 30; background: var(--surface); padding: 8px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; gap: 12px; align-items: center; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--navy); text-decoration: none; white-space: nowrap; }
.brand img { height: 36px; width: auto; background: var(--logo-bg); border-radius: 6px; padding: 1px; }
.topbar nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.topbar nav a { padding: 6px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; white-space: nowrap; font-size: .94rem; }
.topbar nav a:hover { background: var(--surface-2); }
.topbar nav a[aria-current] { background: var(--blue-soft); color: var(--blue); font-weight: 600; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.icon, .lang { background: none; border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 3px 10px; text-decoration: none; cursor: pointer; font-size: .9rem; white-space: nowrap; }

main { display: block; max-width: 920px; margin: 0 auto; padding: 20px 16px 48px; outline: none; }
body.wide main { max-width: 1240px; }
.foot { border-top: 1px solid var(--line); padding: 18px 16px 30px; text-align: center; font-size: .9rem; }
.foot p { margin: 0 0 .3em; }

/* Home */
.hero { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; align-items: center; padding: 18px 0 32px; }
.subtitle { color: var(--muted); font-size: 1.12em; }
.eyebrow { color: var(--green); font-weight: 600; font-size: .92rem; margin: 0; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 0; }
.button { display: inline-block; padding: 9px 20px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; font-weight: 600; }
.button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
:root[data-theme="dark"] .button.primary { color: #0b1a2c; }
.hero-lab { min-width: 0; }
.map-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.overall { color: var(--muted); margin: 0; }
.provenance { font-size: .88rem; margin-top: 14px; }
.lessons { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.lesson { margin: 0; }
.lesson a { display: grid; grid-template-columns: 42px 1fr 76px; gap: 12px; align-items: center; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: inherit; text-decoration: none; }
.lesson a:hover { border-color: var(--blue); }
.num { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--blue-soft); color: var(--blue); font-weight: 700; }
.lesson.complete .num { background: var(--green-soft); color: var(--green); }
.lesson-body { display: grid; min-width: 0; }
.lesson-body small { font-size: .88rem; line-height: 1.5; }
.lesson-progress { height: 6px; border-radius: 3px; background: linear-gradient(to var(--end, right), var(--green) var(--p, 0%), var(--surface-2) var(--p, 0%)); }
[dir="rtl"] .lesson-progress { --end: left; }

/* Lecture */
.lecture-head { padding-bottom: 20px; }
.credits { color: var(--muted); font-size: .92rem; }
.lecture-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.lecture-tools button { background: var(--surface); border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 4px 14px; cursor: pointer; }
.toggle { display: inline-flex; gap: 6px; align-items: center; font-size: .94rem; color: var(--muted); }
.objectives { background: var(--surface); border: 1px solid var(--line); border-inline-start: 4px solid var(--green); border-radius: var(--radius); padding: 14px 18px 4px; margin-bottom: 12px; }
.objectives h2 { font-size: 1.02rem; }
.toc { margin-bottom: 8px; }
.toc summary { cursor: pointer; color: var(--blue); font-weight: 600; }
.slide { padding: 26px 0; border-top: 1px solid var(--line); }
.slide.lecture-head { border-top: 0; padding-top: 6px; }
.part-label { color: var(--green); font-weight: 700; font-size: .95rem; margin-bottom: .2em; }
.pagers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-top: 24px; border-top: 1px solid var(--line); }
.pager { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; text-decoration: none; font-weight: 600; }
.pager small { display: block; font-weight: 400; }
.pager[rel="next"] { text-align: end; grid-column: 2; }

.callout { border-inline-start: 4px solid var(--blue); background: var(--blue-soft); border-radius: 8px; padding: 10px 16px; margin: 0 0 1em; }
.callout-title { display: block; }
.callout.tip { border-color: var(--green); background: var(--green-soft); }
.callout.warn { border-color: var(--amber); background: var(--amber-soft); }
.callout.activity { border-color: #7b57c2; background: color-mix(in srgb, #7b57c2 12%, var(--surface)); }
.callout.teacher { display: none; border-color: var(--muted); background: var(--surface-2); }
[data-teacher] .callout.teacher { display: block; }

.cards { display: grid; gap: 10px; margin-bottom: 1em; }
.cards.n2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cards.n3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cards.n4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.card p { margin: .3em 0 0; font-size: .95rem; color: var(--muted); }
.card .code { margin-top: .5em; font-size: .85rem; }
.steps { list-style: none; counter-reset: s; padding: 0; display: grid; gap: 8px; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 34px 1fr; column-gap: 12px; margin: 0; }
.steps li::before { content: counter(s); grid-row: span 2; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--navy); color: var(--surface); font-weight: 700; }
.steps span { color: var(--muted); font-size: .95rem; grid-column: 2; }
.table-wrap { overflow-x: auto; margin-bottom: 1em; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { padding: 8px 12px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); color: var(--navy); }
tr:last-child td { border-bottom: 0; }

/* Code */
.code { background: var(--code-bg); color: var(--code-ink); padding: 12px 14px; border-radius: var(--radius); overflow-x: auto; font: 15px/1.6 var(--mono); text-align: left; }
.code code { background: none; padding: 0; font: inherit; }
.code i { font-style: normal; }
.code .k { color: #ff7b72; } .code .s { color: #a5d6ff; } .code .s b { color: #ffcb6b; font-weight: 700; }
.code .c { color: #8b98a8; } .code .n { color: #79c0ff; } .code .t { color: #7ee787; }
.fragment { margin: 0 0 1em; }
figcaption { color: var(--muted); font-size: .9rem; margin-top: .3em; }
.file-name { font: .85rem var(--mono); color: var(--muted); margin-top: .5em; }
.tag { display: block; font: 600 .78rem var(--sans); color: var(--muted); margin-bottom: 2px; }
.output-static, .compile-error { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin-top: 8px; text-align: left; }
.output-static pre { white-space: pre-wrap; }
.compile-error { border-color: var(--red); background: var(--red-soft); color: var(--red); margin-bottom: 8px; }
.compile-error code { background: none; }
.io-sample { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.io-sample > div { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; text-align: left; }

/* Activities */
.lab, .predict, .quiz, .fixit, .exercise { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 1.2em; }
.exercise { border-inline-start: 4px solid var(--blue); }
.fixit { border-inline-start: 4px solid var(--red); }
.predict, .quiz { border-inline-start: 4px solid #7b57c2; }
.is-done { border-inline-start-color: var(--green); }
.is-done > h4::after { content: " ✓"; color: var(--green); }
.options { display: grid; gap: 8px; margin: 10px 0; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.option { text-align: start; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; color: inherit; cursor: pointer; }
.option:hover:not(:disabled) { border-color: var(--blue); }
.option pre { white-space: pre-wrap; }
.option.right { background: var(--green-soft); border-color: var(--green); }
.option.wrong { background: var(--red-soft); border-color: var(--red); }
.option:disabled { cursor: default; }
.why { background: var(--green-soft); border-radius: 8px; padding: 8px 12px; margin-top: 8px; }
details > summary { cursor: pointer; color: var(--blue); font-weight: 600; }
details.reveal, details.hint { margin-top: 10px; }
details[open] > summary { margin-bottom: 6px; }

/* Lab */
.lab-host { min-width: 0; }
.editor-box { border-radius: 8px; overflow: hidden; min-height: 40px; background: var(--code-bg); text-align: left; }
.editor-box > .code { border-radius: 0; font-size: var(--code-size, 15px); line-height: 1.6; }
.lab-toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.btn { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 5px 14px; cursor: pointer; font-size: .94rem; font-weight: 600; min-height: 38px; }
.btn:hover:not(:disabled) { border-color: var(--blue); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.run { background: var(--green); border-color: var(--green); color: #fff; }
.btn.stop { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: none; font-weight: 400; }
.btn.small { padding: 3px 10px; min-height: 34px; font-size: .88rem; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.run, :root:not([data-theme="light"]) .btn.stop { color: #0d131a; } }
:root[data-theme="dark"] .btn.run, :root[data-theme="dark"] .btn.stop { color: #0d131a; }
.lab-status { font-size: .9rem; color: var(--muted); margin-inline-start: 4px; }
.lab-status[data-tone="good"] { color: var(--green); }
.lab-status[data-tone="bad"] { color: var(--red); }
.lab-status[data-tone="warn"] { color: var(--amber); }
.console { margin-top: 8px; background: var(--code-bg); color: var(--code-ink); border-radius: 8px; overflow: hidden; }
.console-out { padding: 10px 12px; min-height: 2.6em; max-height: 340px; overflow: auto; white-space: pre-wrap; font: 14.5px/1.55 var(--mono); text-align: left; unicode-bidi: plaintext; }
.console-out .e { color: #ff9e92; } .console-out .i { color: #7ee787; } .console-out .n { color: #8b98a8; }
.console-input-row { display: flex; gap: 8px; align-items: center; padding: 6px 12px; border-top: 1px solid #2f3c4c; color: #7ee787; font-family: var(--mono); }
.console-input { flex: 1; min-width: 0; background: #0d131a; color: var(--code-ink); border: 1px solid #2f3c4c; border-radius: 6px; padding: 6px 8px; font: 16px var(--mono); }
.console-input::placeholder { font-family: var(--sans); }
.console-help { background: var(--amber-soft); border-radius: 8px; padding: 8px 12px; margin-top: 8px; font-size: .95rem; }
.console-help p { margin: 0 0 .3em; }
.test-results { list-style: none; padding: 0; margin: 8px 0 0; }
.test-results li { padding: 6px 10px; border-radius: 8px; margin-bottom: 4px; }
.test-results .pass { background: var(--green-soft); color: var(--green); }
.test-results .fail { background: var(--red-soft); }
.diff { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; margin-top: 6px; }
.diff pre { background: var(--surface); padding: 6px 8px; border-radius: 6px; white-space: pre-wrap; text-align: left; }
.file-tabs { display: flex; gap: 2px; overflow-x: auto; margin-bottom: 4px; text-align: left; }
.file-tab { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 3px 10px; font: .84rem var(--mono); cursor: pointer; white-space: nowrap; }
.file-tab[aria-selected="true"] { background: var(--code-bg); color: var(--code-ink); }

/* Debugger: variables as the named boxes the lectures draw. */
.debug-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; padding: 6px; background: var(--green-soft); border-radius: 8px; }
.vars { margin-top: 8px; display: grid; gap: 6px; text-align: left; }
.frame { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; }
.frame:not(.current) { opacity: .75; }
.frame-title { font: 600 .85rem var(--mono); margin-bottom: 4px; }
.boxes { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 1em; }
.vars .boxes { margin-bottom: 4px; }
.box { display: grid; justify-items: center; min-width: 74px; }
.box-name { font: 600 .85rem var(--mono); color: var(--navy); }
.box-value { font: 700 1rem var(--mono); background: var(--surface); border: 2px solid var(--blue); border-radius: 8px; padding: 4px 12px; max-width: 280px; overflow-wrap: anywhere; text-align: center; min-height: 2.1em; min-width: 100%; }
.box-type { font: .72rem var(--mono); color: var(--muted); }
.box.changed .box-value { border-color: #e6a23c; background: var(--amber-soft); animation: pop .35s ease-out; }
.box.fresh .box-value { border-color: var(--green); background: var(--green-soft); }
@keyframes pop { 50% { transform: scale(1.08); } }
@media (prefers-reduced-motion: reduce) { .box.changed .box-value { animation: none; } }

/* IDE */
.ide-head h1 { margin-bottom: 0; }
.ide-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.ide-bar select { font: inherit; min-height: 34px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; max-width: 100%; }
.ide-stage { --editor-max: 56vh; }
.ide-tip { font-size: .88rem; margin-top: 8px; }

/* Review */
.review-banner { background: var(--amber-soft); border: 1px solid var(--amber); padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.review-banner button { margin-inline-start: 10px; }
.verify-log { font: .82rem var(--mono); white-space: pre-wrap; max-height: 260px; overflow: auto; text-align: left; }

/* Docs pages */
.doc pre { background: var(--code-bg); color: var(--code-ink); padding: 12px 14px; border-radius: 8px; overflow-x: auto; font-size: .88rem; text-align: left; }

/* Presenting on a projector */
.presenting { --code-size: 20px; font-size: 22px; }
.presenting .topbar, .presenting .foot, .presenting .pagers, .presenting .lecture-tools, .presenting .toc { display: none; }
.presenting main { max-width: 1280px; padding-top: 12px; padding-bottom: 70px; }
.presenting .slide { display: none; border: 0; padding: 0; }
.presenting .slide.on-stage { display: block; }
.presenting .code { font-size: 20px; }
.present-bar { position: fixed; inset-block-end: 12px; inset-inline-end: 12px; z-index: 40; display: flex; gap: 8px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; font-size: 16px; }
.present-bar button { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; padding: 2px 12px; }

@media (max-width: 760px) {
  body { font-size: 16.5px; }
  .topbar { flex-wrap: wrap; padding: 6px 12px; }
  .topbar nav { order: 3; flex-basis: 100%; }
  .brand img { height: 30px; }
  .top-actions { margin-inline-start: auto; }
  .hero { grid-template-columns: minmax(0, 1fr); gap: 16px; padding-top: 6px; }
  .cards.n2, .cards.n3, .cards.n4, .io-sample { grid-template-columns: minmax(0, 1fr); }
  .diff { grid-auto-flow: row; }
  .lesson a { grid-template-columns: 38px minmax(0, 1fr); }
  .lesson-progress { grid-column: 1 / -1; }
  .code { font-size: 13.5px; }
  :root { --code-size: 14px; }
  .btn { min-height: 44px; }
  .pagers { grid-template-columns: minmax(0, 1fr); }
  .pager[rel="next"] { grid-column: 1; }
}

@media print {
  body { background: #fff; color: #000; font-size: 11.5pt; }
  .topbar, .foot, .lecture-tools, .lab-toolbar, .debug-bar, .vars, .console, .pagers, .toc, .console-input-row, .review-banner { display: none !important; }
  .slide { break-inside: auto; border-color: #bbb; }
  .code, .editor-box, .cm-editor { background: #f4f4f4 !important; color: #000 !important; }
  .code i { color: #000 !important; }
  details { display: block; }
  details > * { display: block !important; }
  .lab, .predict, .quiz, .fixit, .exercise, .card, .callout { break-inside: avoid; }
}
