/* Static tutorial pages (tools/build_tutorials.mjs). They load style.css for
   the colour tokens, top bar, cards, lists, code colours and lesson pieces,
   and this file for the reading layout: course contents on the left, the
   article in the middle, "on this page" on the right. */

.tut .lang-btn { display: inline-flex; align-items: center; text-decoration: none; }
.tut .topbar .btn { text-decoration: none; }

/* ---------- three-column reading layout ---------- */
.tut-wrap {
  flex: 1; width: 100%; max-width: 1320px; margin: 0 auto; padding: 24px 24px 56px;
  display: grid; grid-template-columns: 248px minmax(0, 1fr) 210px; grid-template-areas: "side main toc"; gap: 28px; align-items: start;
}
.tut-main { grid-area: main; max-width: none; margin: 0; padding: 0; min-width: 0; }
.tut-side { grid-area: side; }
.tut-toc { grid-area: toc; }
.tut-side, .tut-toc {
  position: sticky; top: calc(var(--top) + 18px); max-height: calc(100vh - var(--top) - 36px); overflow: auto;
  scrollbar-width: thin;
}
.tut-page { flex: 1; width: 100%; max-width: 1160px; margin: 0 auto; padding: 26px 24px 56px; }
@media (max-width: 600px) { .tut-page { padding: 18px 16px 40px; } }

/* breadcrumb */
.tut-crumbs ol { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: .86rem; color: var(--muted); }
.tut-crumbs li { display: inline-flex; align-items: center; gap: 4px; min-width: 0; }
.tut-crumbs a { color: var(--muted); text-decoration: none; }
.tut-crumbs a:hover { color: var(--brand-text); }
.tut-crumbs svg.i { width: 14px; height: 14px; color: var(--faint); }
.tut-crumbs [aria-current] { color: var(--text); font-weight: 550; }

/* ---------- left: course contents ---------- */
.tut-side { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--sh-1); padding: 10px 8px 12px; }
.tut-side-course { display: flex; gap: 10px; align-items: center; padding: 8px 10px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--border); text-decoration: none; }
.tut-side-course b { display: block; font-size: .92rem; line-height: 1.3; }
.tut-side-course small { color: var(--muted); font-size: .78rem; }
.tut-side-course:hover b { color: var(--brand-text); }
.tut-side-stage { padding: 8px 0 2px; }
.tut-side-stage .kicker { padding: 0 10px 4px; font-size: .68rem; text-transform: none; letter-spacing: .02em; }
.tut-side ol { list-style: none; margin: 0; padding: 0; }
.tut-side li a {
  display: flex; gap: 6px; align-items: baseline; padding: 6px 10px; border-radius: var(--radius-sm); text-decoration: none;
  color: var(--muted); font-size: .88rem; line-height: 1.4; position: relative;
}
.tut-side li a .lesson-num { width: 18px; font-size: .76rem; }
.tut-side li a:hover { background: var(--surface-2); color: var(--text); }
.tut-side li a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.tut-side li a[aria-current="page"]::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px; border-radius: 3px; background: var(--brand); }
.tut-side li a[aria-current="page"] .lesson-num { color: var(--brand-text); }
.tut-side-all { display: flex; gap: 6px; align-items: center; margin: 10px 10px 0; padding-top: 10px; border-top: 1px solid var(--border); font-size: .84rem; color: var(--muted); text-decoration: none; }
.tut-side-all:hover { color: var(--brand-text); }
.tut-side-all svg.i { width: 15px; height: 15px; }

/* ---------- right: on this page ---------- */
.tut-toc { padding: 4px 0; }
.tut-toc .kicker { margin: 0 0 8px; }
.tut-toc ol { list-style: none; margin: 0 0 16px; padding: 0; border-left: 2px solid var(--border); }
.tut-toc ol a { display: block; padding: 4px 12px; margin-left: -2px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; font-size: .86rem; }
.tut-toc ol a:hover { color: var(--text); border-left-color: var(--border-strong); }

/* ---------- article ---------- */
.tut-article { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--sh-1); padding: 30px 36px 34px; }
.tut-article { font-size: 1rem; line-height: 1.72; }
.tut-head { margin-bottom: 8px; }
.tut-meta { gap: 8px; margin-bottom: 12px; }
.tut-head h1 { font-size: 1.9rem; margin: 0 0 14px; }
.tut-h1-course { color: var(--muted); font-weight: 500; font-size: .62em; letter-spacing: 0; }
.tut-jump { display: none; }
.tut-article section { padding-top: 6px; scroll-margin-top: calc(var(--top) + 12px); }
.tut-article h2 {
  font-size: 1.28rem; margin: 30px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.tut-article h2::before { content: ""; width: 4px; height: 1.05em; border-radius: 3px; background: var(--brand); flex: none; }
.tut-article h3 { font-size: 1.04rem; }
.tut-article .md code { font-size: .88em; }
.tut-article [id^="example-"], .tut-article [id^="quiz-"], .tut-article tr[id] { scroll-margin-top: calc(var(--top) + 12px); }

/* code with line numbers (traces refer to L1, L2, ...) */
.tut-code {
  display: grid; grid-template-columns: auto minmax(0, 1fr); margin: 10px 0 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--code-bg); overflow: hidden; font-size: .88rem; line-height: 1.6;
}
.tut-code pre { margin: 0; padding: 12px 14px; font-family: var(--mono); }
.tut-gut { background: var(--code-gutter); color: var(--faint); text-align: right; user-select: none; border-right: 1px solid var(--border); padding-right: 10px !important; }
.tut-src { overflow-x: auto; color: var(--code-text); }
.tut-src code { font-family: inherit; }

/* examples */
.tut-example { margin: 14px 0 22px; }
.tut-example .example-head { flex-wrap: wrap; }
.tut-example .example-head h3 { margin: 0; font-size: .98rem; }
.tut-example .example-head .btn { text-decoration: none; }
.tut-example .kicker { margin: 12px 0 4px; }
.tut-out { white-space: pre-wrap; }
.tut-map { margin: 6px 0 10px; padding: 10px; border-radius: var(--radius-sm); background: var(--bg-work); border: 1px solid var(--border); }
.tut-map svg.world { display: block; width: 100%; height: auto; max-height: 220px; margin: 0 auto; }
.tut-trace { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 5px; }
.tut-trace li { display: flex; gap: 10px; align-items: flex-start; padding: 7px 11px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); font-size: .9rem; line-height: 1.55; }
.tut-trace .ln { font-family: var(--mono); font-size: .76rem; color: var(--muted); min-width: 30px; padding: 1px 5px; border-radius: 4px; background: var(--surface-3); text-align: center; flex: none; }
.tut-trace .note { flex: 1; min-width: 0; }
.tut-trace .state { margin-left: auto; font-size: .78rem; color: var(--muted); white-space: pre-wrap; padding-left: 8px; text-align: right; }

/* quiz: the options are shown, the answer folds open */
.tut-quiz { margin: 0 0 14px; }
.tut .option { cursor: default; }
.tut .option:hover { border-color: var(--border); background: var(--surface); }
.tut ol.options { list-style: none; padding: 0; margin: 10px 0 0; }
.tut-answer { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 10px; }
.tut-answer summary { cursor: pointer; font-weight: 600; color: var(--brand-text); font-size: .92rem; width: max-content; }
.tut-answer[open] summary { margin-bottom: 8px; }

/* practice */
.tut-ex-list { list-style: none; padding: 0; margin: 12px 0 16px; display: grid; gap: 10px; }
.tut-ex-list li { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px 4px; background: var(--surface-2); }
.tut-ex-head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.tut-cta {
  display: grid; gap: 12px; padding: 20px 22px; border-radius: var(--radius-lg); margin: 18px 0 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--go);
}
.tut-cta h3 { margin: 0 0 4px; font-size: 1.08rem; }
.tut-cta p { margin: 0; }
.tut-cta .btn { text-decoration: none; }
.tut-cta-note { margin: 0 !important; }

/* terms */
.tut-terms td:first-child, .tut-terms td:nth-child(2) { white-space: nowrap; }
.tut-terms th { white-space: nowrap; }
.tut-terms td:first-child a { font-weight: 600; text-decoration: none; color: var(--brand-text); }
.tut-terms tr:target td { background: var(--s-yellow-soft); }

/* previous / next */
.tut-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
.tut-pg {
  display: flex; gap: 12px; align-items: center; padding: 14px 18px; border-radius: var(--radius-lg); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--sh-1); text-decoration: none; transition: border-color .15s, box-shadow .15s, transform .15s;
}
.tut-pg:hover { border-color: var(--border-strong); box-shadow: var(--sh-2); transform: translateY(-1px); }
.tut-pg small { display: block; color: var(--muted); font-size: .78rem; }
.tut-pg b { display: block; font-weight: 600; }
.tut-pg svg.i { color: var(--muted); width: 20px; height: 20px; }
.tut-pg.next { justify-content: flex-end; text-align: right; }

/* ---------- tutorials home ---------- */
.tut-hero { padding: 30px 32px 26px; margin-bottom: 8px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--sh-1); position: relative; overflow: hidden; }
.tut-hero::before { content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(var(--dots) 1px, transparent 1.4px); background-size: 16px 16px;
  -webkit-mask-image: radial-gradient(520px 300px at 100% 0%, #000, transparent 75%); mask-image: radial-gradient(520px 300px at 100% 0%, #000, transparent 75%); }
.tut-hero > * { position: relative; }
.tut-hero h1 { font-size: 2rem; margin-bottom: 10px; }
.tut-hero .lead { font-size: 1.04rem; max-width: 760px; }
.tut-hero .muted { max-width: 760px; }
.tut-hero .btn { text-decoration: none; }
.tut-courses { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); align-items: start; }
.tut-course { scroll-margin-top: calc(var(--top) + 12px); }
.tut-course-head { display: flex; gap: 12px; align-items: center; text-decoration: none; margin-bottom: 8px; }
.tut-course-head b { display: block; font-size: 1.02rem; }
.tut-course-head small { color: var(--muted); font-size: .8rem; }
.tut-course-head:hover b { color: var(--brand-text); }
.tut-course > p { margin-bottom: 10px; }
.tut-course-list { margin: 0; padding: 10px 0 0 24px; border-top: 1px solid var(--border); font-size: .9rem; line-height: 1.55; }
.tut-course-list li { margin: 3px 0; color: var(--faint); }
.tut-course-list a { color: var(--text); text-decoration: none; }
.tut-course-list a:hover { text-decoration: underline; text-decoration-color: var(--border-strong); }

/* ---------- course page ---------- */
.tut-page .course-side .btn { text-decoration: none; }
.tut-page .list-head h2 { margin: 0; font-size: .98rem; }

/* ---------- glossary ---------- */
.tut-az { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0 8px; }
.tut-az a { min-width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); text-decoration: none; font-weight: 600; font-size: .9rem; }
.tut-az a:hover { border-color: var(--border-strong); background: var(--surface-2); }
.tut-letter { scroll-margin-top: calc(var(--top) + 12px); }
.tut-letter h2 { margin-top: 28px; }
.tut-letter table { background: var(--surface); table-layout: fixed; }
.tut-letter .tut-terms td { white-space: normal; overflow-wrap: anywhere; }
.tut-letter th:nth-child(1) { width: 22%; }
.tut-letter th:nth-child(2) { width: 18%; }
.tut-letter th:nth-child(4) { width: 20%; }
.tut-letter tr { scroll-margin-top: calc(var(--top) + 12px); }

/* ---------- smaller screens ---------- */
@media (max-width: 1180px) {
  .tut-wrap { grid-template-columns: 240px minmax(0, 1fr); grid-template-areas: "side main"; }
  .tut-toc { display: none; }
}
@media (max-width: 860px) {
  .tut-wrap { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "side"; padding: 16px 14px 40px; gap: 18px; }
  .tut-side { position: static; max-height: none; }
  .tut-article { padding: 20px 18px 24px; }
  .tut-head h1 { font-size: 1.55rem; }
  .tut-h1-course { display: block; margin-top: 4px; font-size: .58em; }
  .tut-jump { display: inline-flex; gap: 6px; align-items: center; font-size: .86rem; color: var(--brand-text); text-decoration: none; }
  .tut-jump svg.i { width: 16px; height: 16px; }
  .tut-trace li { flex-wrap: wrap; }
  .tut-trace .state { margin-left: 40px; padding-left: 0; text-align: left; }
  .tut-hero { padding: 22px 18px; }
  .tut-hero h1 { font-size: 1.6rem; }
  .tut-terms { display: block; overflow-x: auto; }
  .tut .topbar .btn.primary { height: 32px; padding: 0 11px; }
  .tut-h1-dot { display: none; }
  body.tut { padding-bottom: 0; }
}
@media (max-width: 520px) {
  .tut-pager { grid-template-columns: 1fr; }
  .tut-pg.next { justify-content: space-between; }
}
