/* Education section. Loads after css/style.css and adds only what the tutorial
   needs: a three-column lesson layout, code cards, callouts and the exercise
   and progress widgets. Every colour below is either an existing token or a new
   one defined here for the same black ground.

   New tokens, and why they exist:
   --edu-width   the site's 1024px --width cannot hold sidebar + prose + rail
   --mono        the site had no monospace stack; code needs one
   --accent-text a lighter --accent for small text such as step numbers
   --syn-*       syntax colours, all 4.5:1+ against --code-bg
   --ok/--bad    exercise pass and fail states */

:root {
  --edu-width: 1200px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;

  --accent-text: #FFFFFF;
  --code-bg: #070708;

  --syn-keyword: #B4ACFF;
  --syn-string: #A9C58A;
  --syn-number: #D6B37A;
  --syn-builtin: #94BBD6;
  --syn-comment: var(--muted);

  --ok: #7FCF97;
  --ok-soft: rgba(127, 207, 151, 0.12);
  --bad: #F08C86;
  --bad-soft: rgba(240, 140, 134, 0.12);
}

/* ---------- shell ---------- */

.edu-wrap { max-width: var(--edu-width); margin: 0 auto; padding-inline: 24px; }

.crumbs { padding-top: 28px; font-size: 13px; color: var(--muted); }
.crumbs ol { display: flex; flex-wrap: wrap; gap: 8px; }
.crumbs li + li::before { content: "/"; margin-right: 8px; color: var(--line-strong); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); text-decoration: underline; }
.crumbs [aria-current="page"] { color: var(--text); }

.edu-layout { display: grid; gap: 40px; margin-top: 24px; align-items: start; }

@media (min-width: 820px) {
  .edu-layout { grid-template-columns: 240px minmax(0, 1fr); gap: 44px; }
}
@media (min-width: 1200px) {
  .edu-layout { grid-template-columns: 250px minmax(0, 1fr) 190px; gap: 48px; }
}

/* ---------- sidebar ---------- */

/* A <details> so the mobile drawer works with no JS at all. It ships open;
   below 820px the enhancement script closes it on load. */
.edu-side { min-width: 0; }
.edu-side > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 16px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--pill); font-size: 15px;
}
.edu-side > summary::-webkit-details-marker { display: none; }
.edu-side > summary::after { content: "\203A"; transform: rotate(90deg); color: var(--muted); }
.edu-side[open] > summary::after { transform: rotate(-90deg); }
.edu-side > summary:hover { background: var(--panel-hover); }

.edu-side__inner { padding-top: 18px; }

@media (min-width: 820px) {
  .edu-side > summary { display: none; }
  .edu-side { position: sticky; top: 80px; max-height: calc(100vh - 104px); overflow: auto; }
  .edu-side__inner { padding-top: 0; }
}

.edu-side__head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  font-size: 14px; color: var(--muted);
  padding-bottom: 12px; border-bottom: 1px solid var(--line-soft);
}
.edu-side__group { margin-top: 18px; }
.edu-side__title {
  font-size: 11px; font-weight: 500; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 6px;
}

/* .chapter-list comes from style.css; these are the additions the tutorial
   needs on top of it. */
.chapter-list .tick {
  margin-left: auto; color: var(--ok); font-size: 13px; opacity: 0;
}
.chapter-list a.is-done .tick { opacity: 1; }
.chapter-list a { align-items: baseline; }

/* ---------- right rail ---------- */

.edu-rail { display: none; }
@media (min-width: 1200px) {
  .edu-rail {
    display: block; position: sticky; top: 80px;
    max-height: calc(100vh - 104px); overflow: auto;
    font-size: 14px;
  }
}
.edu-rail__head { color: var(--muted); padding-bottom: 10px; border-bottom: 1px solid var(--line-soft); }
.edu-rail__list { margin-top: 10px; display: grid; gap: 2px; }
.edu-rail__list a {
  display: block; padding: 5px 10px; margin-left: -10px;
  border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; line-height: 1.4;
}
.edu-rail__list a:hover { background: var(--panel); color: var(--text); }
.edu-rail__list a.is-active { color: var(--text); background: var(--panel); }

/* ---------- lesson body ---------- */

.edu-main { min-width: 0; }
.edu-main > .label { display: flex; gap: 12px; align-items: baseline; }
.edu-main h1 { margin-top: 10px; }

.prose { margin-top: 32px; max-width: 68ch; }
.prose h2 {
  margin-top: 40px; padding-top: 28px;
  border-top: 1px solid var(--line-soft);
}
.prose > h2:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.prose h3 { margin-top: 26px; }
.prose p { margin-top: 12px; }
/* Running text in the reading face; headings, code and widgets stay in Geist. */
.prose > p, .prose > ul > li, .prose > ol > li {
  font-family: var(--serif); font-size: 19px; line-height: 1.7;
  color: var(--paper); hyphens: none; overflow-wrap: break-word;
}
.prose a {
  color: var(--text); text-decoration: underline;
  text-decoration-color: var(--line-strong); text-underline-offset: 3px;
  transition: text-decoration-color .15s var(--ease);
}
.prose a:hover { text-decoration-color: var(--text); }

/* Inline code only. Scoped by parent so it never reaches the <code> inside a
   code card's <pre>, which carries its own syntax colours. */
.prose :not(pre) > code {
  font-family: var(--mono); font-size: 0.85em;
  background: rgba(255, 255, 255, 0.08); color: var(--text);
  padding: 1px 5px; border-radius: var(--radius-sm);
}

.lesson__steps { display: grid; gap: 10px; margin-top: 16px; counter-reset: step; }
.lesson__steps li { padding-left: 26px; position: relative; }
.lesson__steps li::before {
  counter-increment: step; content: counter(step) ".";
  position: absolute; left: 0; color: var(--accent-text); font-size: 14px;
}

.table-scroll { overflow-x: auto; margin-top: 18px; }
.lesson__table { width: 100%; border-collapse: collapse; font-size: 15px; }
.lesson__table th, .lesson__table td {
  text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
.lesson__table th { font-weight: 600; font-size: 14px; color: var(--muted); }
.lesson__table tr:last-child td { border-bottom: 0; }

/* ---------- callouts ---------- */

.callout {
  margin-top: 20px; padding: 16px 18px;
  background: var(--panel); border: 1px solid var(--line);
  border-left: 2px solid var(--muted);
  border-radius: var(--radius-sm);
}
.callout__label {
  font-size: 11px; font-weight: 500; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 6px;
}
.callout p + p { margin-top: 0; }
.callout--tip { border-left-color: var(--ok); }
.callout--tip .callout__label { color: var(--ok); }
.callout--gotcha { border-left-color: var(--bad); }
.callout--gotcha .callout__label { color: var(--bad); }
.callout--note { border-left-color: var(--accent); }
.callout--note .callout__label { color: var(--accent-text); }

/* ---------- code cards ---------- */

.code {
  margin: 24px 0 0; padding: 0;
  background: var(--code-bg); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.code__head {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px 8px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.code__lang { font-size: 13px; color: var(--muted); }
/* No opacity here: --muted is exactly at the 4.5:1 contrast bar, and dimming
   it any further fails. */
.code__note { font-size: 13px; color: var(--muted); }
.code__tools { margin-left: auto; display: flex; gap: 4px; }
.code__btn {
  padding: 5px 12px; border-radius: var(--pill);
  border: 1px solid transparent; font-size: 14px; color: var(--muted);
  cursor: pointer; transition: background-color .15s ease, color .15s ease;
}
.code__btn:hover { background: var(--panel-hover); color: var(--text); }
.code__btn[data-act="run"] { color: var(--text); border-color: var(--line-strong); background: var(--panel); }
.code__btn[data-act="run"]:hover { background: var(--panel-hover); }
.code__btn:disabled { opacity: .4; cursor: not-allowed; }
.code__btn[hidden] { display: none; }

.code pre, .code textarea {
  font-family: var(--mono); font-size: 14px; line-height: 1.6;
  tab-size: 4;
}
.code__pre {
  margin: 0; padding: 16px; overflow-x: auto;
  white-space: pre; color: var(--text);
}

/* The editor is a transparent textarea sitting exactly on top of a highlighted
   <pre>. Both must share every metric or the caret drifts. */
.editor { position: relative; }
.editor__view {
  margin: 0; padding: 16px; overflow-x: auto;
  white-space: pre; pointer-events: none;
}
.editor__input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  margin: 0; padding: 16px; border: 0; resize: none; overflow: hidden;
  background: transparent; color: transparent; caret-color: var(--text);
  white-space: pre; overflow-wrap: normal;
  font-family: var(--mono); font-size: 14px; line-height: 1.6; tab-size: 4;
}
.editor__input::selection { background: var(--accent-soft); color: transparent; }
.editor__input:focus { outline: none; }
.editor:focus-within { box-shadow: inset 0 0 0 2px var(--text); }

.code__out {
  border-top: 1px solid var(--line-soft);
  padding: 12px 16px 14px;
  background: var(--panel);
}
.code__out-label {
  font-size: 13px; color: var(--muted); margin-bottom: 6px;
  display: flex; align-items: center; gap: 8px;
}
.code__out pre {
  margin: 0; white-space: pre-wrap; overflow-wrap: anywhere;
  font-family: var(--mono); font-size: 14px; line-height: 1.6;
}
.code__out.is-error .code__out-label { color: var(--bad); }
.code__out.is-error pre { color: var(--bad); }
.code__out[hidden] { display: none; }

.code__ask { display: flex; gap: 8px; margin-top: 10px; }
.code__ask input {
  flex: 1; min-width: 0; font: inherit; font-family: var(--mono); font-size: 14px;
  padding: 7px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}

/* syntax */
.tok-keyword { color: var(--syn-keyword); }
.tok-string  { color: var(--syn-string); }
.tok-number  { color: var(--syn-number); }
.tok-builtin { color: var(--syn-builtin); }
.tok-comment { color: var(--syn-comment); font-style: italic; }

/* ---------- runtime banner ---------- */

.runtime {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--muted);
}
.runtime__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--line); flex: none;
}
.runtime.is-loading .runtime__dot { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.runtime.is-ready .runtime__dot { background: var(--ok); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* ---------- test yourself ---------- */

.selftest {
  margin-top: 40px; padding: 24px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.selftest__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.selftest__q { margin-top: 18px; }
.selftest__q + .selftest__q { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line-soft); }
.selftest .options { margin-top: 14px; }
/* Same lock as a chosen quiz answer, in pass and fail colours: a check on the
   right answer, a cross on a wrong pick. */
.selftest .option.is-right { border-color: var(--ok); background: var(--ok-soft); box-shadow: inset 0 0 0 1px var(--ok); }
.selftest .option.is-wrong {
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.6' stroke-linecap='round'%3E%3Cpath d='M6.5 6.5 L17.5 17.5 M17.5 6.5 L6.5 17.5'/%3E%3C/svg%3E");
  border-color: var(--bad); background: var(--bad-soft); box-shadow: inset 0 0 0 1px var(--bad);
}
.selftest .option.is-right::after,
.selftest .option.is-wrong::after { opacity: 1; animation: xi-pop 300ms cubic-bezier(0.22, 0.61, 0.36, 1) both; }
.selftest .option.is-right::after { background: var(--ok); }
.selftest .option.is-wrong::after { background: var(--bad); }
.selftest__note {
  margin-top: 12px; font-size: 15px; color: var(--muted);
  padding-left: 14px; border-left: 2px solid var(--line);
}
.selftest__answer { margin-top: 12px; }
.selftest__answer > summary {
  list-style: none; cursor: pointer;
  font-size: 14px; color: var(--muted); display: inline-flex; gap: 6px;
}
.selftest__answer > summary::-webkit-details-marker { display: none; }
.selftest__answer > summary::after { content: "\203A"; }
.selftest__answer[open] > summary { color: var(--text); }
.selftest__answer > summary:hover { color: var(--text); text-decoration: underline; }

/* ---------- exercises ---------- */

.task {
  margin-top: 20px; padding: 22px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.task.is-passed { border-color: var(--ok); }
.task__head { display: flex; align-items: baseline; gap: 12px; }
.task__n { font-size: 14px; color: var(--muted); }
.task__status { margin-left: auto; font-size: 14px; color: var(--ok); }
.task__status[hidden] { display: none; }
.task__prompt { margin-top: 10px; }
.task .code { background: var(--code-bg); }
.task__foot { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 16px; }
.task__reveal {
  margin-top: 14px; font-size: 15px; color: var(--muted);
  padding-left: 14px; border-left: 2px solid var(--line);
}
.task__reveal[hidden] { display: none; }
.task__result { font-size: 15px; }
.task__result.is-pass { color: var(--ok); }
.task__result.is-fail { color: var(--bad); }

/* ---------- progress ---------- */

.track { margin-top: 28px; max-width: 660px; }
.track__row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 14px; color: var(--muted); }
.track__bar { height: 2px; background: var(--line); margin-top: 10px; }
.track__fill { height: 2px; background: var(--accent); transition: width .25s var(--ease); }

/* ---------- section index ---------- */

.sections { margin-top: 44px; display: grid; gap: 40px; }
.section__head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding-bottom: 12px; border-bottom: 1px solid var(--line-soft);
}
.section__list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 2px 24px; margin-top: 12px; }
.section__list a {
  display: flex; gap: 10px; align-items: baseline;
  padding: 8px 10px; margin-left: -10px; border-radius: var(--radius-sm);
  font-size: 15px; color: var(--muted); text-decoration: none;
}
.section__list a:hover { background: var(--panel); color: var(--text); }
.section__list .tick { margin-left: auto; color: var(--ok); font-size: 13px; opacity: 0; }
.section__list a.is-done .tick { opacity: 1; }
.section__list .n { color: var(--muted); font-size: 13px; min-width: 20px; }

/* ---------- search ---------- */

.search { margin-top: 24px; max-width: 520px; }
.search input {
  width: 100%; font: inherit; padding: 11px 16px;
  border-radius: var(--pill); border: 1px solid var(--line);
  background: transparent; color: var(--text);
  transition: border-color .15s var(--ease);
}
.search input:hover, .search input:focus { border-color: var(--line-strong); }
.search input::placeholder { color: var(--muted); }
.search__out { margin-top: 12px; display: grid; gap: 2px; }
.search__out a {
  display: block; padding: 10px 12px; margin-left: -12px;
  border-radius: var(--radius-sm); text-decoration: none;
}
.search__out a:hover { background: var(--panel); }
.search__out .t { font-size: 15px; }
.search__out .s { font-size: 14px; color: var(--muted); }
.search__empty { margin-top: 12px; font-size: 15px; color: var(--muted); }

/* ---------- prev / next ---------- */

.edu-nav {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px;
  margin-top: 48px; padding-top: 28px; border-top: 1px solid var(--line-soft);
}
.edu-nav .btn { max-width: 100%; }

.next-card {
  display: block; margin-top: 32px; padding: 22px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); text-decoration: none;
  transition: background-color .15s ease, border-color .15s ease;
}
.next-card:hover { background: var(--panel-hover); border-color: var(--muted); }
.next-card .label { display: block; }
.next-card h2 { margin-top: 6px; }
.next-card p { margin-top: 6px; font-size: 15px; color: var(--muted); }

/* A compact prev/next that sticks to the bottom on small screens only. */
@media (max-width: 819px) {
  .edu-sticky {
    position: sticky; bottom: 0; z-index: 5;
    display: flex; gap: 10px; margin-top: 32px;
    padding: 10px 0 12px;
    background: linear-gradient(to top, var(--bg) 70%, transparent);
  }
  .edu-sticky .btn { flex: 1; text-align: center; padding-inline: 12px; }
}
@media (min-width: 820px) { .edu-sticky { display: none; } }

/* ---------- compiler page ---------- */

.compiler { margin-top: 24px; }
.compiler .code { margin-top: 18px; }
.compiler .editor__view, .compiler .editor__input { min-height: 46vh; }
.compiler__foot { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; margin-top: 18px; }

/* ---------- small screens ---------- */

@media (max-width: 560px) {
  .edu-wrap { padding-inline: 20px; }
  .crumbs { padding-top: 20px; }
  .code__head { flex-wrap: wrap; }
  .code__tools { margin-left: 0; width: 100%; }
  .selftest, .task { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .runtime.is-loading .runtime__dot { animation: none; }
}

/* ---------- reference ---------- */

.ref-signature {
  background: var(--code-bg); border: 1px solid var(--line);
  border-radius: var(--radius-sm); margin-top: 14px;
}
.section__list--dense { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.section__list--dense a { font-family: var(--mono); font-size: 14px; }
.section__list a.is-hidden { display: none; }

/* ---------- javascript runner ---------- */

/* With JS off every file in an example is shown, each with its label. The
   runtime turns them into tabs and hides the labels. */
.code__file-label {
  font-size: 13px; color: var(--muted);
  padding: 8px 16px 0;
}
.code--tabbed .code__file-label { display: none; }
/* A single-file example is already named in the card header. */
.code__file:only-child .code__file-label { display: none; }
.code__file[hidden] { display: none; }
.code__file + .code__file { border-top: 1px solid var(--line-soft); }
.code--tabbed .code__file + .code__file { border-top: 0; }

.files {
  display: flex; gap: 2px; padding: 8px 10px 0 12px;
  border-bottom: 1px solid var(--line-soft);
}
.files__tab {
  padding: 6px 12px; border: 0; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: none; color: var(--muted); font: inherit; font-size: 14px; cursor: pointer;
}
.files__tab:hover { color: var(--text); }
.files__tab[aria-selected="true"] {
  color: var(--text); background: var(--panel);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.out__head {
  display: flex; align-items: center; gap: 2px;
  padding: 8px 12px 0;
  border-bottom: 1px solid var(--line-soft);
}
.out__tab {
  padding: 6px 12px; border: 0; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: none; color: var(--muted); font: inherit; font-size: 14px; cursor: pointer;
}
.out__tab:hover { color: var(--text); }
.out__tab[aria-selected="true"] {
  color: var(--text); background: var(--panel);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.out__status { margin-left: auto; font-size: 13px; color: var(--muted); }

.out__pane { padding: 12px 16px 14px; background: var(--panel); }
.out__pane[hidden] { display: none; }
.out__pane--result { padding: 0; }

.result__frame {
  display: block; width: 100%; height: 190px; border: 0;
  background: #FFFFFF;
}

.out__pane--console pre {
  margin: 0; white-space: pre-wrap; overflow-wrap: anywhere;
  font-family: var(--mono); font-size: 14px; line-height: 1.6;
  max-height: 260px; overflow: auto;
}
.out__line { display: block; }
.out__line--error { color: var(--bad); }
.out__line--warn { color: var(--syn-number); }
.out__line--info { color: var(--syn-builtin); }
