/* The tutorials (site/tutorials/). Loaded after style.css and built from its
   tokens: a tutorial is a page of the same paper, set for reading top to
   bottom. Nothing here is used by index.html. */

.doc-wrap { padding-top: clamp(28px, 4vw, 52px); padding-bottom: clamp(64px, 9vw, 120px); }

/* ---------- three-column editorial shell (enhanced via site.js) ---------- */
.doc-shell {
  max-width: 1460px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  align-items: start;
}
.doc-shell > .doc-wrap {
  max-width: none;
  width: 100%;
  margin: 0;
  padding-inline: clamp(22px, 3.6vw, 56px);
}

/* Focus reading mode: hide global shelf & outline, center the paper column */
body.focus-mode .doc-shell { grid-template-columns: minmax(0, 1fr); max-width: 980px; }
body.focus-mode .shelf-rail { display: none; }
body.focus-mode .doc-cols { grid-template-columns: minmax(0, 1fr); }
body.focus-mode .toc { display: none; }
body.focus-mode .doc-head,
body.focus-mode .doc-meta-row,
body.focus-mode .prose,
body.focus-mode .pager { max-width: 50rem; margin-inline: auto; }
body.focus-mode .top-shelf-btn { display: inline-flex; }

/* ---------- left global tutorial shelf rail ---------- */
.shelf-rail {
  position: sticky;
  top: var(--top);
  height: calc(100vh - var(--top));
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 65%, var(--sunken));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 12;
}
.shelf-rail-head {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.shelf-rail-top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.shelf-rail-title {
  font: 600 .72rem/1 var(--mono); letter-spacing: .12em; color: var(--ink-3);
  text-decoration: none;
}
.shelf-rail-title:hover { color: var(--accent); }
.shelf-rail-close {
  display: none; appearance: none; background: none; border: 0; color: var(--ink-2);
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer; font-size: 1rem;
  align-items: center; justify-content: center;
}
.shelf-rail-close:hover { background: var(--sunken); color: var(--ink); }
.shelf-rail-filter {
  width: 100%; border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface); color: var(--ink);
  font: .8rem/1.4 var(--sans); padding: 6px 9px;
  outline: none; transition: border-color .15s ease;
}
.shelf-rail-filter::placeholder { color: var(--ink-3); }
.shelf-rail-filter::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.shelf-rail-filter:focus { border-color: var(--accent); }

.shelf-rail-body {
  flex: 1; overflow-y: auto; padding: 10px 10px 24px;
  scrollbar-width: thin;
}
.shelf-rail-group + .shelf-rail-group { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.shelf-rail-group[hidden] { display: none; }
.shelf-rail-group h3 {
  font: 600 .7rem/1.2 var(--mono); letter-spacing: .12em; color: var(--ink-3);
  padding: 0 8px 6px; display: flex; align-items: center; gap: 6px;
}
.shelf-rail-group h3 b { color: var(--accent); font-weight: 600; }
.shelf-rail-item {
  display: grid; grid-template-columns: 1.85rem minmax(0, 1fr); gap: 4px; align-items: baseline;
  padding: 6px 8px; border-radius: 7px; text-decoration: none;
  font-size: .82rem; line-height: 1.45; color: var(--ink-2);
  border-left: 2px solid transparent;
  transition: background-color .12s ease, color .12s ease;
}
.shelf-rail-item[hidden] { display: none; }
.shelf-rail-item:hover { background: color-mix(in srgb, var(--surface) 75%, transparent); color: var(--ink); }
.shelf-rail-item[aria-current="page"] {
  background: var(--surface); color: var(--ink); font-weight: 650;
  border-left-color: var(--accent);
  border-radius: 0 7px 7px 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
.shelf-rail-item span:first-child {
  font: 600 .72rem/1.4 var(--mono); color: var(--ink-3);
  font-variant-numeric: lining-nums tabular-nums;
}
.shelf-rail-item[aria-current="page"] span:first-child { color: var(--accent); }
.shelf-rail-empty { padding: 16px 8px; font-size: .8rem; color: var(--ink-3); text-align: center; }

.shelf-backdrop {
  position: fixed; inset: 0; background: var(--backdrop); z-index: 24;
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.shelf-backdrop.open { opacity: 1; pointer-events: auto; }

/* ---------- where this page is + focus toggle ---------- */
.doc-meta-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 60rem;
}
.crumbs { font: .8rem/1.6 var(--mono); color: var(--ink-3); letter-spacing: .04em; }
.crumbs a { text-decoration: none; color: var(--ink-2); }
.crumbs a:hover { color: var(--accent); }
.crumbs span { margin-inline: .5em; }

.focus-btn {
  appearance: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 7px;
  border: 1px solid var(--line); background: transparent;
  font: 600 .76rem/1 var(--sans); color: var(--ink-2);
  transition: border-color .15s ease, color .15s ease, background-color .15s ease;
}
.focus-btn:hover { border-color: var(--line-strong); color: var(--ink); background: var(--surface); }
.focus-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ---------- title block ---------- */
.doc-head { margin-top: clamp(22px, 3.5vw, 42px); max-width: 60rem; }
.doc-head .kicker { margin-bottom: 16px; }
.doc h1 { font-size: clamp(2rem, 4.4vw, 3.35rem); line-height: 1.2; margin-left: 0; max-width: 18em; }
.doc-head .lead { margin-top: 20px; max-width: 41em; color: var(--ink-2); font-size: clamp(1rem, 1.3vw, 1.12rem); line-height: 1.88; }
.facts { margin: clamp(26px, 4vw, 40px) 0 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 2px solid var(--ink); }
.facts div { padding: 14px 20px 0 0; }
.facts div + div { padding-left: 20px; border-left: 1px solid var(--line); }
.facts dt { font: 600 .72rem/1 var(--mono); letter-spacing: .14em; color: var(--accent); }
.facts dd { margin: 9px 0 0; font-size: .89rem; line-height: 1.7; color: var(--ink-2); }

/* ---------- contents beside the text ---------- */
/* Without JS: classic 2-column (toc left, prose right). With JS (.is-tutorial): prose center, toc right! */
.doc-cols { margin-top: clamp(36px, 5vw, 64px); display: grid; grid-template-columns: 216px minmax(0, 1fr); gap: clamp(28px, 4.5vw, 68px); align-items: start; }
body.is-tutorial .doc-cols { grid-template-columns: minmax(0, 52rem) 232px; gap: clamp(28px, 3.6vw, 56px); }
body.is-tutorial .doc-cols > .prose { grid-column: 1; grid-row: 1; }
body.is-tutorial .doc-cols > .toc { grid-column: 2; grid-row: 1; }
body.is-tutorial .doc-head,
body.is-tutorial .doc-meta-row,
body.is-tutorial .pager { max-width: 52rem; }

.toc {
  position: sticky; top: calc(var(--top) + 28px);
  border-top: 1px solid var(--line-strong);
  font-size: .85rem; line-height: 1.48;
  max-height: calc(100vh - var(--top) - 52px); overflow-y: auto;
  scrollbar-width: thin;
}
.toc-head {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 12px 0 8px;
}
.toc h2 { font: 600 .72rem/1 var(--mono); letter-spacing: .14em; color: var(--ink-3); padding: 14px 0 8px; max-width: none; }
.toc-head h2 { padding: 0; }
.toc-tabs { display: inline-flex; gap: 2px; background: var(--sunken); padding: 2px; border-radius: 6px; flex: none; }
.toc-tabs button {
  appearance: none; background: none; border: 0; border-radius: 5px;
  padding: 3px 7px; font: 600 .7rem/1.2 var(--sans); color: var(--ink-3); cursor: pointer;
  white-space: nowrap;
}
.toc-tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); }
.toc-toggle { display: none; }

.toc ol { counter-reset: toc; }
.toc li { counter-increment: toc; border-bottom: 1px solid var(--line); }
.toc a {
  display: grid; grid-template-columns: 1.5em minmax(0, 1fr); gap: 6px;
  padding: 8px 6px 8px 8px; text-decoration: none; color: var(--ink-2);
  border-left: 2px solid transparent; margin-left: -1px;
  transition: color .14s ease, border-color .14s ease, background-color .14s ease;
}
.toc a::before { content: counter(toc); font: italic 700 .95em/1.5 var(--serif); color: var(--accent); font-variant-numeric: lining-nums tabular-nums; }
.toc a:hover { color: var(--ink); }
.toc a.active {
  color: var(--ink); font-weight: 600;
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 50%, transparent);
}
.toc li.plain { counter-increment: none; }
.toc li.plain a::before { content: ""; }

/* Figure index panel inside .toc */
.toc-figs { list-style: none; }
.toc-figs[hidden], .toc ol[hidden] { display: none; }
.toc-figs li { counter-increment: none; border-bottom: 1px solid var(--line); }
.toc-figs a {
  display: grid; grid-template-columns: 2.6em minmax(0, 1fr); gap: 6px;
  padding: 8px 4px 8px 6px; font-size: .8rem; line-height: 1.45;
  color: var(--ink-2); text-decoration: none; border-left: 2px solid transparent;
}
.toc-figs a::before { content: none; }
.toc-figs a b { font: 600 .72rem/1.45 var(--mono); color: var(--accent); white-space: nowrap; }
.toc-figs a:hover { color: var(--ink); border-left-color: var(--accent); }

/* ---------- the text ---------- */
.prose { max-width: 52rem; min-width: 0; }
.prose > section + section { margin-top: clamp(48px, 7vw, 80px); padding-top: clamp(36px, 5vw, 56px); border-top: 1px solid var(--line-strong); }
.prose h2 {
  position: relative;
  font-size: clamp(1.45rem, 2.5vw, 1.92rem); line-height: 1.35; max-width: none;
  display: flex; align-items: baseline; gap: .55em;
}
.prose h2 i { font: italic 700 1em/1 var(--serif); color: var(--accent); flex: none; font-variant-numeric: lining-nums tabular-nums; }
.prose h3 { position: relative; font: 900 1.16rem/1.45 var(--serif); margin-top: 34px; display: flex; align-items: baseline; gap: .4em; flex-wrap: wrap; }
.prose h2 .anchor-btn, .prose h3 .anchor-btn {
  margin-left: 2px; align-self: center;
}
.prose h2:hover .anchor-btn, .prose h3:hover .anchor-btn { opacity: 1; }

.prose p, .prose ul, .prose ol, .prose dl { max-width: 41em; }
.prose p { margin-top: 14px; }
.prose h2 + p { margin-top: 18px; }
.prose ul, .prose ol { margin-top: 12px; }
.prose li { padding: 4px 0 4px 1.5em; position: relative; }
.prose ul > li::before { content: "–"; position: absolute; left: .1em; color: var(--ink-3); }
.prose ol { counter-reset: item; }
.prose ol > li { counter-increment: item; padding-left: 2em; }
.prose ol > li::before { content: counter(item); position: absolute; left: 0; top: .5em; width: 1.5em; font: 600 .78rem/1.8 var(--mono); color: var(--accent); text-align: center; background: var(--accent-soft); border-radius: 5px; }
.prose li > ul, .prose li > ol { margin-top: 4px; }
.prose a { text-decoration-color: var(--accent); }
.prose strong { font-weight: 650; }

.prose .shot { margin-top: 28px; }
.prose .shot + p, .prose .shot + ul, .prose .shot + ol { margin-top: 26px; }
.prose .shot.narrow { max-width: 34rem; }
.prose .code { margin-top: 20px; }
.prose .code + p { margin-top: 22px; }

/* What the person typed or the assistant said, word for word. */
.prose blockquote { margin-top: 16px; max-width: 41em; padding: 12px 18px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 9px 9px 0; font-size: .95rem; line-height: 1.8; color: var(--ink-2); }
.prose blockquote p { margin-top: 0; }
.prose blockquote p + p { margin-top: 8px; }
.prose blockquote cite { display: block; margin-bottom: 4px; font: 600 .72rem/1.6 var(--mono); letter-spacing: .12em; font-style: normal; color: var(--accent); }

/* A remark beside the steps. */
.note { margin-top: 20px; max-width: 41em; padding: 14px 18px 15px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--sunken); font-size: .92rem; line-height: 1.75; color: var(--ink-2); }
.note > b:first-child { display: block; font: 600 .72rem/1 var(--mono); letter-spacing: .14em; color: var(--accent); margin-bottom: 8px; }
.note p { margin-top: 8px; }
.note.warn { background: var(--warn-bg); border-color: transparent; color: var(--ink); }
.note.warn > b:first-child { color: var(--warn); }

.prose table { margin-top: 20px; width: 100%; border-collapse: collapse; font-size: .9rem; line-height: 1.6; font-variant-numeric: lining-nums tabular-nums; }
.prose caption { caption-side: top; text-align: left; font-size: .86rem; color: var(--ink-2); padding-bottom: 10px; }
.prose caption b { font-family: var(--serif); color: var(--ink); }
.prose thead th { text-align: left; font: 600 .76rem/1.6 var(--sans); letter-spacing: .04em; color: var(--ink-3); padding: 8px 18px 8px 0; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.prose tbody tr { border-bottom: 1px solid var(--line); }
.prose tbody tr:last-child { border-bottom-color: var(--line-strong); }
.prose td, .prose tbody th { padding: 9px 18px 9px 0; vertical-align: top; text-align: left; font-weight: 400; }
.prose tbody th { font-weight: 600; white-space: nowrap; }
.prose td:last-child, .prose th:last-child { padding-right: 0; }
.prose td { color: var(--ink-2); }
.scroll { overflow-x: auto; }

/* ---------- the end of a tutorial ---------- */
.recap h2 { font-size: 1.3rem; }
.pager { margin-top: clamp(48px, 7vw, 80px); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.pager a { display: block; padding: 18px 22px 20px; border: 1px solid var(--line-strong); border-radius: 12px; text-decoration: none; background: var(--surface); transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease; }
.pager a:hover { color: inherit; border-color: var(--accent); box-shadow: 0 4px 16px -6px rgba(106, 76, 198, .18); }
.pager a:active { transform: translateY(1px); }
.pager small { display: block; font: 600 .72rem/1 var(--mono); letter-spacing: .14em; color: var(--accent); margin-bottom: 10px; }
.pager strong { font: 900 1.12rem/1.45 var(--serif); }
.pager .next { text-align: right; grid-column: 2; }

/* ---------- the list of tutorials (tutorials/index.html) ---------- */
.shelf-toolbar {
  margin-top: clamp(32px, 5vw, 52px);
  padding: 14px 0;
  border-top: 1px solid var(--line-strong);
  display: flex; flex-direction: column; gap: 12px;
}
.shelf-toolbar-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
}
.shelf-search-wrap {
  position: relative; flex: 1 1 260px; max-width: 400px;
}
.shelf-search-wrap svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--ink-3); pointer-events: none;
}
.shelf-filter-input {
  width: 100%; height: 38px; padding: 0 34px 0 34px;
  border: 1px solid var(--line-strong); border-radius: 9px;
  background: var(--surface); color: var(--ink);
  font: .9rem/1.4 var(--sans); outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.shelf-filter-input::placeholder { color: var(--ink-3); }
.shelf-filter-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.shelf-filter-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.shelf-filter-clear {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
  appearance: none; border: 0; background: var(--sunken); color: var(--ink-2);
  width: 22px; height: 22px; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; font-size: .85rem;
}
.shelf-filter-clear[hidden] { display: none; }

.shelf-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.shelf-chips button {
  appearance: none; cursor: pointer;
  font: 600 .8rem/1.3 var(--sans); color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; display: inline-flex; align-items: baseline; gap: 5px;
  transition: border-color .15s ease, color .15s ease, background-color .15s ease;
}
.shelf-chips button small { font: 500 .7rem/1 var(--mono); color: var(--ink-3); }
.shelf-chips button:hover { border-color: var(--line-strong); color: var(--ink); }
.shelf-chips button[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
}
.shelf-chips button[aria-pressed="true"] small { color: color-mix(in srgb, var(--on-accent) 78%, transparent); }

.shelf-status {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  font: .82rem/1.5 var(--sans); color: var(--ink-3);
}
.shelf-status[hidden] { display: none; }
.shelf-status button {
  appearance: none; background: none; border: 0; padding: 0;
  color: var(--accent); font: 600 .82rem/1.5 var(--sans); cursor: pointer;
}
.shelf-status button:hover { text-decoration: underline; }
.shelf-empty {
  padding: 40px 20px; text-align: center;
  border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong);
  color: var(--ink-2);
}
.shelf-empty[hidden] { display: none; }
.shelf-empty button {
  margin-top: 14px;
}

.shelf { margin-top: clamp(40px, 6vw, 72px); }
.shelf-toolbar + .shelf { margin-top: 8px; }
.shelf-part { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); border-top: 1px solid var(--line-strong); padding-block: clamp(24px, 3.5vw, 40px); }
.shelf-part[hidden] { display: none; }
.shelf-part > h2 { font: 700 1.25rem/1.4 var(--serif); letter-spacing: .3em; }
:lang(en) .shelf-part > h2 { letter-spacing: .02em; }
.shelf-part > h2 small { display: block; font: 600 .76rem/1 var(--mono); color: var(--accent); letter-spacing: .08em; margin-bottom: 12px; }
.entry {
  display: grid; grid-template-columns: 3.6rem minmax(0, 1fr) minmax(0, 15rem);
  column-gap: clamp(16px, 3vw, 40px);
  padding: 18px 12px; margin-inline: -12px;
  text-decoration: none; border-radius: 10px;
  transition: background-color .14s ease;
}
.entry[hidden] { display: none; }
.entry + .entry { border-top: 1px solid var(--line); border-radius: 0; }
.entry:hover { color: inherit; background: color-mix(in srgb, var(--surface) 70%, transparent); }
.entry .num { font-size: clamp(1.7rem, 3vw, 2.3rem); }
.entry h3 { font: 900 clamp(1.16rem, 2vw, 1.4rem)/1.4 var(--serif); transition: color .15s ease; }
.entry:hover h3 { color: var(--accent); }
.entry p { margin-top: 8px; font-size: .94rem; color: var(--ink-2); max-width: 36em; }
.entry dl { margin: 0; font-size: .82rem; line-height: 1.7; color: var(--ink-2); padding-top: .4rem; }
.entry dt { font: 600 .7rem/1 var(--mono); letter-spacing: .14em; color: var(--accent); margin-top: 10px; }
.entry dt:first-child { margin-top: 0; }
.entry dd { margin: 5px 0 0; }

/* ---------- responsive breakpoints ---------- */
@media (max-width: 1259px) {
  .doc-shell { grid-template-columns: minmax(0, 1fr); }
  .top-shelf-btn { display: inline-flex; }
  .shelf-rail {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(310px, 86vw); height: 100dvh;
    z-index: 30; background: var(--paper); border-right: 1px solid var(--line-strong);
    box-shadow: var(--shadow-lg);
    transform: translateX(-104%);
    transition: transform .22s cubic-bezier(.3, 0, .2, 1);
  }
  .shelf-rail.open { transform: translateX(0); }
  .shelf-rail-close { display: inline-flex; }
  body.is-tutorial .doc-cols { grid-template-columns: minmax(0, 1fr) 210px; }
}

@media (max-width: 1040px) {
  .entry { grid-template-columns: 3.2rem minmax(0, 1fr); }
  .entry dl { grid-column: 2; display: flex; flex-wrap: wrap; gap: 4px 24px; padding-top: 10px; }
  .entry dt { margin-top: 0; }
  .entry dd { margin-top: 0; }
  .entry dl > div { display: flex; gap: 8px; align-items: baseline; }
}

@media (max-width: 960px) {
  .doc-cols, body.is-tutorial .doc-cols { grid-template-columns: minmax(0, 1fr); gap: 28px; }
  body.is-tutorial .doc-cols > .toc { grid-column: 1; grid-row: 1; }
  body.is-tutorial .doc-cols > .prose { grid-column: 1; grid-row: 2; }
  .focus-btn { display: none; }
  .toc {
    position: static; max-height: none;
    border: 1px solid var(--line-strong); border-radius: 10px;
    background: var(--surface); padding: 0 16px;
  }
  .toc-head { padding: 12px 0; }
  .toc-toggle {
    display: inline-flex; align-items: center; gap: 6px;
    appearance: none; background: none; border: 0; padding: 0; cursor: pointer;
    font: 600 .78rem/1.2 var(--mono); letter-spacing: .08em; color: var(--ink-2);
  }
  .toc.collapsed ol, .toc.collapsed .toc-figs, .toc.collapsed .toc-tabs { display: none; }
  .toc:not(.collapsed) ol, .toc:not(.collapsed) .toc-figs { padding-bottom: 10px; }
  .toc li:last-child { border-bottom: 0; }
  .shelf-part { grid-template-columns: minmax(0, 1fr); }
  .shelf-part > h2 { letter-spacing: .2em; margin-bottom: 8px; }
  .shelf-part > h2 small { display: inline; margin-right: 12px; }
}

@media (max-width: 600px) {
  .facts { grid-template-columns: minmax(0, 1fr); }
  .facts div, .facts div + div { padding: 12px 0; border-left: 0; }
  .facts div + div { border-top: 1px solid var(--line); }
  .pager { grid-template-columns: minmax(0, 1fr); }
  .pager .next { grid-column: 1; }
  .prose td, .prose tbody th, .prose thead th { padding-right: 12px; }
  .entry { margin-inline: 0; padding-inline: 0; }
}
