/* Tutorial pages — a reading layout, deliberately quieter than the landing page.
   Reuses the tokens from site.css; adds only what a long-form doc needs:
   a sticky chapter tree, prose rhythm, and code blocks that can actually run. */

.tut-body { background: var(--bg); }

/* ---------- shell ---------- */
.tut {
  display: grid;
  grid-template-columns: 262px minmax(0, 1fr);
  gap: 0;
  max-width: none;
  margin: 0;
}
@media (min-width: 1400px) {
  .tut { grid-template-columns: 300px minmax(0, 1fr); }
}

/* ---------- left tree ---------- */
.tut-side {
  position: sticky;
  top: 60px;
  align-self: start;
  height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 26px 20px 60px 28px;
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
}
.tut-side__label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}
.tut-tree { display: flex; flex-direction: column; gap: 2px; }
.tut-ch { margin-bottom: 14px; }
.tut-ch__link {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 6px 8px;
  border-radius: 5px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink-dim);
  transition: color 0.14s ease, background 0.14s ease;
}
.tut-ch__link:hover { color: var(--ink); background: var(--surface-2); }
.tut-ch__link[aria-current='true'] { color: var(--ink); }
.tut-ch__link[aria-current='true'] .tut-ch__num { color: var(--accent); }
.tut-ch__num {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--muted);
  min-width: 1.2em;
}
.tut-secs {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 4px 0 0 20px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}
.tut-secs a {
  display: block;
  padding: 4px 8px;
  font-size: 0.825rem;
  color: var(--muted);
  border-radius: 4px;
  line-height: 1.4;
  transition: color 0.14s ease, background 0.14s ease;
}
.tut-secs a:hover { color: var(--ink-dim); background: var(--surface-2); }
.tut-secs a.is-active { color: var(--accent); background: var(--accent-soft); }

/* ---------- main column ---------- */
.tut-main {
  min-width: 0;
  padding: 0 clamp(20px, 4vw, 64px) 140px;
}
.tut-inner { max-width: 730px; margin-inline: auto; }

.tut-hero {
  padding: 64px 0 40px;
  border-bottom: 1px solid var(--line);
}
.tut-hero__eyebrow {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 16px;
}
.tut-hero h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.16;
  letter-spacing: -0.025em;
  font-weight: 600;
  margin-bottom: 18px;
}
.tut-hero__lede {
  font-size: 1.06rem;
  color: var(--ink-dim);
  line-height: 1.7;
  max-width: 58ch;
}
.tut-hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 26px;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
}
.tut-hero__meta b { color: var(--ink-dim); font-weight: 500; }

/* chapter heading */
.tut-h2 {
  font-size: clamp(1.5rem, 2.6vw, 2rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 0 0 10px;
  scroll-margin-top: 84px;
}
.tut-chapter {
  padding-top: 68px;
  border-top: 1px solid var(--line);
  margin-top: 68px;
}
.tut-chapter:first-of-type { border-top: 0; margin-top: 0; }
.tut-chapter__num {
  font-family: var(--mono);
  font-size: 0.76rem;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 12px;
}
.tut-chapter__lede {
  color: var(--ink-dim);
  font-size: 1.01rem;
  line-height: 1.7;
  margin-bottom: 8px;
  max-width: 62ch;
}

.tut-h3 {
  font-size: 1.16rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 52px 0 14px;
  padding-top: 4px;
  scroll-margin-top: 84px;
}
.tut-h3__anchor {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 400;
  margin-left: 8px;
  opacity: 0;
  transition: opacity 0.14s ease;
}
.tut-h3:hover .tut-h3__anchor { opacity: 1; }

/* ---------- prose ---------- */
.tut-prose {
  color: var(--ink-dim);
  line-height: 1.78;
  font-size: 1.005rem;
}
.tut-prose + .tut-prose { margin-top: 16px; }
.tut-prose p + p { margin-top: 15px; }
.tut-prose strong { color: var(--ink); font-weight: 600; }
.tut-prose em { color: var(--ink); font-style: italic; }
.tut-prose a {
  color: var(--accent);
  border-bottom: 1px solid var(--accent-line);
}
.tut-prose a:hover { border-bottom-color: var(--accent); }
.tut-prose ul, .tut-prose ol {
  margin: 15px 0 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.tut-prose ul { list-style: none; padding-left: 4px; }
.tut-prose ul > li { position: relative; padding-left: 20px; }
.tut-prose ul > li::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 0.72em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-line);
}
.tut-prose ol { list-style: decimal; }
.tut-prose ol > li::marker { color: var(--muted); font-family: var(--mono); font-size: 0.85em; }
.tut-prose li { line-height: 1.7; }
.tut-prose code {
  font-family: var(--mono);
  font-size: 0.875em;
  padding: 0.14em 0.4em;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  white-space: nowrap;
}
.tut-prose br { line-height: 2; }

/* ---------- note ---------- */
.tut-note {
  margin: 22px 0;
  padding: 15px 18px 15px 40px;
  background: var(--accent-soft);
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--r) var(--r) 0;
  font-size: 0.94rem;
  line-height: 1.72;
  color: var(--ink-dim);
  position: relative;
}
.tut-note::before {
  content: 'i';
  position: absolute;
  left: 15px;
  top: 15px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--accent-line);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  font-style: italic;
}
.tut-note p + p { margin-top: 10px; }
.tut-note code {
  font-family: var(--mono);
  font-size: 0.87em;
  padding: 0.1em 0.36em;
  border-radius: 3px;
  background: rgba(10, 12, 11, 0.42);
  color: var(--ink);
}
.tut-note strong { color: var(--ink); }

/* ---------- runnable code block ---------- */
.tut-code {
  margin: 20px 0;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--surface);
}
.tut-code__bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 10px 7px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  min-height: 38px;
}
.tut-code__caption {
  font-size: 0.795rem;
  color: var(--muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tut-code__caption:empty { display: none; }
.tut-code__bar:has(.tut-code__caption:empty)::before {
  content: 'Lean 4';
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  flex: 1;
}
.tut-code__run {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px 5px 9px;
  border-radius: 5px;
  font-family: var(--ui);
  font-size: 0.795rem;
  font-weight: 500;
  color: #14100a;
  background: var(--accent);
  transition: filter 0.14s ease, transform 0.1s ease;
}
.tut-code__run:hover { filter: brightness(1.08); }
.tut-code__run:active { transform: translateY(1px); }
.tut-code__run[disabled] { opacity: 0.55; cursor: progress; }
.tut-code__run svg { width: 11px; height: 11px; }
.tut-code__run.is-running svg { animation: tut-spin 0.7s linear infinite; }
@keyframes tut-spin { to { transform: rotate(360deg); } }

.tut-code__body {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  font-family: var(--mono);
  font-size: 0.855rem;
  line-height: 1.72;
}
.tut-code__gutter {
  padding: 13px 10px 13px 14px;
  text-align: right;
  color: var(--muted);
  opacity: 0.5;
  user-select: none;
  border-right: 1px solid var(--line);
  font-size: 0.78rem;
}
.tut-code__pre {
  margin: 0;
  padding: 13px 16px 13px 14px;
  overflow-x: auto;
  tab-size: 2;
  color: var(--ink);
  white-space: pre;
}
.tut-code__pre code { font-family: inherit; font-size: inherit; }

/* token colours — the highlighter emits the same class names as the workbench,
   so scope them to this block and keep one palette across the site */
.tut-code__pre .k { color: #c792ea; }
.tut-code__pre .tac { color: #82d2c8; }
.tut-code__pre .ty { color: #9fc7e8; }
.tut-code__pre .num { color: #e9a64e; }
.tut-code__pre .str { color: #b7cf8a; }
.tut-code__pre .cm { color: #5c6763; font-style: italic; }
.tut-code__pre .cn { color: #d6b98c; }
.tut-code__pre .op { color: #cf9a6a; }

/* output area */
.tut-out {
  border-top: 1px solid var(--line);
  background: #0b0f0e;
  font-family: var(--mono);
  font-size: 0.825rem;
  line-height: 1.68;
}
.tut-out__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  font-size: 0.71rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.tut-out__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}
.tut-out.is-ok .tut-out__dot { background: var(--pass); }
.tut-out.is-ok .tut-out__head { color: var(--pass); }
.tut-out.is-err .tut-out__dot { background: var(--fail); }
.tut-out.is-err .tut-out__head { color: var(--fail); }
.tut-out__ms {
  margin-left: auto;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.75;
  color: var(--muted);
}
.tut-out__pre {
  margin: 0;
  padding: 12px 16px 14px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink-dim);
}
.tut-out.is-err .tut-out__pre { color: #e8a99e; }
.tut-out__diag { padding: 10px 16px 14px; }
.tut-out__diag-item {
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.tut-out__diag-item:last-child { border-bottom: 0; }
.tut-out__diag-where {
  font-size: 0.72rem;
  color: var(--fail);
  margin-bottom: 3px;
}
.tut-out__diag-msg {
  color: #e8a99e;
  white-space: pre-wrap;
  word-break: break-word;
}
.tut-out.is-warn .tut-out__diag-where { color: var(--accent); }
.tut-out.is-warn .tut-out__diag-msg { color: var(--ink-dim); }

.tut-code__edit-hint {
  padding: 8px 14px 10px;
  border-top: 1px solid var(--line);
  font-size: 0.76rem;
  color: var(--muted);
  display: flex;
  gap: 10px;
  align-items: center;
}
.tut-code__edit-hint button {
  color: var(--accent);
  font-size: 0.76rem;
  border-bottom: 1px solid var(--accent-line);
}

/* editable state */
.tut-code__edit {
  flex: none;
  padding: 5px 9px;
  border-radius: 5px;
  font-size: 0.795rem;
  color: var(--ink-dim);
  border: 1px solid var(--line);
  background: transparent;
  transition: color 0.14s ease, border-color 0.14s ease;
}
.tut-code__edit:hover { color: var(--ink); border-color: var(--line-2); }
.tut-code.is-edited .tut-code__bar { background: rgba(233, 166, 78, 0.07); }

.tut-code__ta {
  display: block;
  width: 100%;
  margin: 0;
  padding: 13px 16px;
  border: 0;
  background: #0c100f;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.855rem;
  line-height: 1.72;
  tab-size: 2;
  resize: vertical;
  min-height: 4.6em;
  caret-color: var(--accent);
}
.tut-code__ta:focus { outline: none; background: #0e1211; }

/* ---------- pager ---------- */
.tut-pager {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-top: 70px;
  padding-top: 30px;
  border-top: 1px solid var(--line);
}
.tut-pager a {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  min-width: 0;
  flex: 1;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.tut-pager a:hover { border-color: var(--line-2); background: var(--surface-2); }
.tut-pager span {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.tut-pager b { font-weight: 500; color: var(--ink); font-size: 0.94rem; }
.tut-pager a.is-next { text-align: right; }

/* ---------- mobile ---------- */
.tut-mobile-head { display: none; }
@media (max-width: 900px) {
  .tut { grid-template-columns: minmax(0, 1fr); }
  .tut-side {
    position: fixed;
    inset: 60px 0 auto 0;
    z-index: 45;
    height: auto;
    max-height: calc(100vh - 60px);
    background: var(--bg);
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 18px 20px 26px;
    transform: translateY(-8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s ease;
  }
  .tut-side.is-open { opacity: 1; transform: none; pointer-events: auto; }
  .tut-main { padding: 0 20px 100px; }
  .tut-mobile-head { display: inline-flex; }
  .tut-hero { padding: 40px 0 30px; }
  .tut-code__body { font-size: 0.8rem; }
}
@media (prefers-reduced-motion: reduce) {
  .tut-code__run.is-running svg { animation: none; }
  .tut-side { transition: none; }
}
