/* pyway / tutor — единая тема сайта. Цвета — токены на :root, тёмная тема их переопределяет. */

:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1c1e21;
  --text-2: #4a4f57;
  --muted: #737985;
  --border: #e3e0d8;
  --border-strong: #cfcbc0;
  --accent: #0a8fb0;
  --accent-ink: color-mix(in oklab, var(--accent) 78%, black);
  --accent-soft: color-mix(in oklab, var(--accent) 12%, var(--surface));
  --brand: #e2552c;

  --code-bg: #fbfaf7;
  --code-border: #e7e3d9;
  --code-text: #24292f;
  --tok-kw: #a3277a;
  --tok-type: #0f6f8a;
  --tok-fn: #6f42c1;
  --tok-str: #2f7d32;
  --tok-num: #b35900;
  --tok-com: #7b8088;
  --tok-op: #57606a;

  --panic: #d33a2c;
  --panic-bg: color-mix(in oklab, var(--panic) 9%, transparent);
  --compile: #c27c0e;
  --compile-bg: color-mix(in oklab, var(--compile) 11%, transparent);
  --ok: #2f8f4e;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(20 20 10 / 5%), 0 6px 24px -12px rgb(20 20 10 / 18%);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --topbar-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101214;
    --surface: #171a1d;
    --surface-2: #1d2125;
    --text: #e7e9ec;
    --text-2: #b8bdc4;
    --muted: #8b929b;
    --border: #262b30;
    --border-strong: #353b42;
    --accent-ink: color-mix(in oklab, var(--accent) 70%, white);
    --accent-soft: color-mix(in oklab, var(--accent) 16%, var(--surface));
    --brand: #ff7a52;
    --code-bg: #14171a;
    --code-border: #262b30;
    --code-text: #dfe3e8;
    --tok-kw: #ff7ab8;
    --tok-type: #5cc8e6;
    --tok-fn: #c3a6ff;
    --tok-str: #8fd18f;
    --tok-num: #ffb46b;
    --tok-com: #7d858f;
    --tok-op: #a6adb6;
    --panic: #ff6b5e;
    --compile: #f2b440;
    --ok: #5bc77d;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 28px -14px rgb(0 0 0 / 60%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #101214;
  --surface: #171a1d;
  --surface-2: #1d2125;
  --text: #e7e9ec;
  --text-2: #b8bdc4;
  --muted: #8b929b;
  --border: #262b30;
  --border-strong: #353b42;
  --accent-ink: color-mix(in oklab, var(--accent) 70%, white);
  --accent-soft: color-mix(in oklab, var(--accent) 16%, var(--surface));
  --brand: #ff7a52;
  --code-bg: #14171a;
  --code-border: #262b30;
  --code-text: #dfe3e8;
  --tok-kw: #ff7ab8;
  --tok-type: #5cc8e6;
  --tok-fn: #c3a6ff;
  --tok-str: #8fd18f;
  --tok-num: #ffb46b;
  --tok-com: #7d858f;
  --tok-op: #a6adb6;
  --panic: #ff6b5e;
  --compile: #f2b440;
  --ok: #5bc77d;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 28px -14px rgb(0 0 0 / 60%);
  color-scheme: dark;
}

/* --- база --------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 16px); }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 17px/1.7 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
a { color: var(--accent-ink); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.skip { position: absolute; left: -999px; top: 8px; }
.skip:focus { left: 16px; z-index: 100; background: var(--surface); padding: 6px 12px; border-radius: 6px; }

.eyebrow {
  margin: 0 0 10px;
  font: 600 12px/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent-ink);
}

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 500; font-size: 15px;
  text-decoration: none;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--accent); background: var(--accent-soft); }

.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .3s ease; }

/* --- шапка -------------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in oklab, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  height: var(--topbar-h);
  max-width: 1240px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; gap: 12px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; margin-right: auto; }
.brand-mark {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--text); color: var(--bg);
  font: 700 13px/1 var(--mono);
}
.brand-name { font: 600 16px/1 var(--mono); letter-spacing: -.01em; }
.brand-sep { color: var(--brand); margin: 0 1px; }
.icon-btn {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
}
.icon-btn:hover { border-color: var(--border-strong); }
.theme-toggle .i-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: none; }
}
.toc-toggle {
  display: none; align-items: center; gap: 8px;
  height: 36px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 14px; font-weight: 500;
}
.read-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; }
.read-progress span { display: block; height: 100%; width: 0; background: var(--accent); }

/* --- главная ------------------------------------------------------------------- */

.hero { max-width: 1240px; margin: 0 auto; padding: 72px 24px 40px; }
.hero h1 {
  margin: 0; max-width: 16ch;
  font-size: clamp(34px, 5.4vw, 60px); line-height: 1.05; letter-spacing: -.03em; font-weight: 700;
}
.hero-text { max-width: 58ch; margin: 18px 0 0; color: var(--text-2); font-size: 18px; }
.hero-404 { padding-bottom: 96px; }
.hero-404 .btn { margin-top: 28px; }

.filters { max-width: 1240px; margin: 0 auto; padding: 0 24px 20px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 14px;
}
.chip.is-active { background: var(--text); color: var(--bg); border-color: var(--text); }

.cards {
  list-style: none; margin: 0 auto; padding: 0 24px 96px; max-width: 1240px;
  display: grid; gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
}
.card { --accent: #0a8fb0; }
.card[hidden] { display: none; }
.card-link {
  position: relative; height: 100%;
  display: flex; flex-direction: column; gap: 14px;
  padding: 26px 26px 22px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: inherit; text-decoration: none;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform .2s ease, border-color .2s ease;
}
.card-link::before {
  content: ""; position: absolute; inset: 0 0 auto; height: 4px; background: var(--accent);
}
.card-link:hover { transform: translateY(-2px); border-color: color-mix(in oklab, var(--accent) 45%, var(--border)); }
.card-top { display: flex; align-items: center; gap: 10px; }
.topic-badge {
  padding: 4px 10px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent-ink);
  font: 600 13px/1.2 var(--mono);
}
.card-kind { color: var(--muted); font-size: 14px; }
.card-title { margin: 0; font-size: 23px; line-height: 1.25; letter-spacing: -.015em; }
.card-desc { margin: 0; color: var(--text-2); font-size: 16px; line-height: 1.55; }
.card-progress { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.card-progress[hidden] { display: none; }
.card-progress .bar { flex: 1; }
.card-cta { margin-top: auto; padding-top: 6px; font-weight: 600; font-size: 15px; color: var(--accent-ink); }

.meta { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 0; font-size: 14px; }
.meta div { display: flex; gap: 6px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-weight: 500; }

/* --- страница туториала -------------------------------------------------------- */

.tutorial {
  max-width: 1240px; margin: 0 auto; padding: 0 24px;
  display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 56px;
}
.toc { position: relative; }
.toc-inner {
  position: sticky; top: calc(var(--topbar-h) + 24px);
  max-height: calc(100vh - var(--topbar-h) - 48px);
  overflow: auto; padding: 32px 4px 24px 0;
  scrollbar-width: thin;
}
.toc-progress { padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); margin-bottom: 20px; }
.toc-progress-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.toc-progress-count { font-family: var(--mono); color: var(--text); }
.toc-list, .toc-list ol { list-style: none; margin: 0; padding: 0; }
.toc-list > li { margin-bottom: 2px; }
.toc-list a {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 6px 10px; border-radius: 8px;
  color: var(--text-2); text-decoration: none;
  font-size: 14px; line-height: 1.4;
}
.toc-list a:hover { background: var(--surface-2); color: var(--text); }
.toc-list a.is-current { background: var(--accent-soft); color: var(--accent-ink); font-weight: 500; }
.toc-list ol { margin: 2px 0 6px 28px; border-left: 1px solid var(--border); }
.toc-list ol a { padding: 4px 10px; font-size: 13px; border-radius: 0 6px 6px 0; margin-left: -1px; border-left: 2px solid transparent; }
.toc-list ol a.is-current { background: none; border-left-color: var(--accent); }
.toc-list code { font-size: .92em; }
.toc-check {
  flex: none; width: 16px; height: 16px; margin-top: 2px;
  border-radius: 50%; border: 1.5px solid var(--border-strong);
  display: grid; place-items: center;
  transition: background .2s, border-color .2s;
}
.toc-item.is-done .toc-check { background: var(--ok); border-color: var(--ok); }
.toc-item.is-done .toc-check::after {
  content: ""; width: 7px; height: 4px; margin-top: -2px;
  border: solid #fff; border-width: 0 0 2px 2px; transform: rotate(-45deg);
}
.toc-reset {
  margin-top: 18px; padding: 4px 10px; border: 0; background: none;
  color: var(--muted); font-size: 13px; text-decoration: underline; text-underline-offset: 3px;
}
.toc-backdrop { display: none; }

.content { min-width: 0; max-width: 760px; padding: 32px 0 96px; }
.crumbs { display: flex; gap: 8px; font-size: 14px; color: var(--muted); margin-bottom: 28px; }
.crumbs a { color: var(--muted); }
.article-head { padding-bottom: 28px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.article-head h1 { margin: 0; font-size: clamp(32px, 4.6vw, 48px); line-height: 1.1; letter-spacing: -.028em; }
.article-desc { margin: 16px 0 20px; font-size: 19px; color: var(--text-2); line-height: 1.55; }

/* --- типографика статьи --------------------------------------------------------- */

.prose { font-size: 17px; }
.prose > * + * { margin-top: 0; }
.prose p, .prose ul, .prose ol { margin: 0 0 1.05em; }
.prose ul, .prose ol { padding-left: 1.35em; }
.prose li { margin: .3em 0; }
.prose li::marker { color: var(--muted); }
.prose strong { font-weight: 650; }
.prose h2, .prose h3 { position: relative; scroll-margin-top: calc(var(--topbar-h) + 16px); }
.prose h2 { margin: 0 0 18px; font-size: 30px; line-height: 1.2; letter-spacing: -.02em; }
.prose h3 { margin: 40px 0 12px; font-size: 21px; line-height: 1.3; letter-spacing: -.01em; }
.prose .anchor {
  margin-left: 6px; color: var(--border-strong); text-decoration: none; font-weight: 400;
  opacity: 0; transition: opacity .15s;
}
.prose h2:hover .anchor, .prose h3:hover .anchor, .prose .anchor:focus { opacity: 1; }

.prose :not(pre) > code {
  font: 500 .86em/1 var(--mono);
  padding: .18em .4em; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--border);
  overflow-wrap: anywhere;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
/* В таблицах код не рвём: таблица прокручивается по горизонтали. */
.prose td code { white-space: nowrap; overflow-wrap: normal; }

.lead {
  margin: 28px 0 8px; padding: 22px 24px;
  border-radius: var(--radius); background: var(--accent-soft);
  border: 1px solid color-mix(in oklab, var(--accent) 22%, transparent);
  font-size: 18px; line-height: 1.65;
}
.lead p:last-child { margin-bottom: 0; }

.chapter { padding-top: 56px; }
.chapter + .chapter { border-top: 1px solid var(--border); margin-top: 48px; }
.chapter-foot { margin-top: 32px; }
.chapter-done {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 999px;
  border: 1px dashed var(--border-strong); background: transparent;
  font-size: 14px; font-weight: 500; color: var(--text-2);
  transition: all .15s;
}
.chapter-done:hover { border-style: solid; border-color: var(--ok); color: var(--ok); }
.chapter-done .when-done { display: none; }
.chapter.is-done .chapter-done { border-style: solid; border-color: var(--ok); background: color-mix(in oklab, var(--ok) 12%, transparent); color: var(--ok); }
.chapter.is-done .when-todo { display: none; }
.chapter.is-done .when-done { display: inline; }

/* таблицы */
.table-wrap {
  margin: 0 0 1.4em; overflow-x: auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface);
}
.prose table { width: 100%; border-collapse: collapse; font-size: 15px; line-height: 1.5; }
.prose th, .prose td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.prose th { font-size: 13px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.prose tr:last-child td { border-bottom: 0; }
.prose tbody tr:hover td { background: color-mix(in oklab, var(--surface-2) 55%, transparent); }

/* код */
.code {
  margin: 0 0 1.4em;
  border: 1px solid var(--code-border); border-radius: var(--radius-sm);
  background: var(--code-bg); overflow: hidden;
}
.code-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--code-border);
  font: 500 12px/1 var(--mono); color: var(--muted);
}
.code-copy {
  padding: 5px 9px; border-radius: 6px; border: 1px solid transparent; background: none;
  font: 500 12px/1 var(--font); color: var(--muted);
}
.code-copy:hover { border-color: var(--code-border); color: var(--text); background: var(--surface); }
.code-copy.is-copied { color: var(--ok); }
.code pre { margin: 0; padding: 12px 0; overflow-x: auto; }
.code code {
  display: inline-block; min-width: 100%;
  font: 400 14px/1.65 var(--mono); color: var(--code-text);
  font-variant-ligatures: none; tab-size: 4;
}
.code .ln { display: block; min-height: 1.65em; padding: 0 18px; border-left: 3px solid transparent; white-space: pre; }
.code .ln.is-panic { background: var(--panic-bg); border-left-color: var(--panic); }
.code .ln.is-compile, .code .ln.is-vet { background: var(--compile-bg); border-left-color: var(--compile); }
.code .ln.is-panic .c1, .code .ln.is-panic .c { color: var(--panic); }
.code .ln.is-compile .c1, .code .ln.is-vet .c1 { color: var(--compile); }

.code .k, .code .kd, .code .kn, .code .kr, .code .kc { color: var(--tok-kw); }
.code .kt, .code .nc, .code .nb, .code .bp { color: var(--tok-type); }
.code .nf, .code .fm { color: var(--tok-fn); }
.code .s, .code .s1, .code .s2, .code .sb, .code .sc, .code .se, .code .si { color: var(--tok-str); }
.code .m, .code .mi, .code .mf, .code .mh, .code .mo { color: var(--tok-num); }
.code .c, .code .c1, .code .cm, .code .cs { color: var(--tok-com); font-style: italic; }
.code .o, .code .ow { color: var(--tok-op); }
.code .p { color: var(--tok-op); }

/* легенда к меткам в коде */
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: -4px 0 1.2em; font-size: 14px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.legend i { width: 14px; height: 14px; border-radius: 3px; border-left: 3px solid; }
.legend .l-panic { background: var(--panic-bg); border-color: var(--panic); }
.legend .l-compile { background: var(--compile-bg); border-color: var(--compile); }

/* ответ на вопрос самопроверки */
.answer {
  margin: -6px 0 26px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface);
}
.answer summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; font-size: 14px; font-weight: 500; color: var(--accent-ink);
}
.answer summary::-webkit-details-marker { display: none; }
.answer summary::before {
  content: ""; width: 7px; height: 7px; margin: 0 4px 0 2px;
  border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(-45deg);
  transition: transform .15s;
}
.answer[open] summary::before { transform: rotate(45deg); }
.answer[open] summary { border-bottom: 1px solid var(--border); }
.answer-body { padding: 12px 16px 2px; font-size: 16px; }

/* врезки */
.callout { margin: 0 0 1.4em; padding: 14px 18px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); }
.callout-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.callout-tip .callout-title { color: var(--ok); }
.callout-warning { border-color: color-mix(in oklab, var(--compile) 35%, var(--border)); }
.callout-warning .callout-title { color: var(--compile); }
.callout p:last-child { margin-bottom: 0; }

/* задания с чекбоксами */
.prose .contains-task-list { list-style: none; padding-left: 0; }
.prose .task-list-item { position: relative; padding: 12px 14px 12px 44px; margin: 0 0 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.prose .task-list-item-checkbox { position: absolute; left: 14px; top: 16px; width: 18px; height: 18px; margin: 0; accent-color: var(--ok); cursor: pointer; }
.prose .task-list-item.is-checked { color: var(--muted); }

.finish {
  margin-top: 64px; padding: 28px; text-align: center;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.finish-title { margin: 0 0 4px; font-size: 20px; font-weight: 650; }
.finish .btn { margin-top: 12px; }

/* --- подвал ------------------------------------------------------------------- */

.footer { border-top: 1px solid var(--border); }
.footer-inner {
  max-width: 1240px; margin: 0 auto; padding: 22px 24px;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px;
  font-size: 14px; color: var(--text-2);
}

/* --- адаптив ------------------------------------------------------------------- */

@media (max-width: 1000px) {
  .tutorial { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .toc-toggle { display: inline-flex; }
  .toc {
    position: fixed; z-index: 60; top: 0; bottom: 0; left: 0;
    width: min(320px, 86vw);
    background: var(--bg); border-right: 1px solid var(--border);
    transform: translateX(-100%); transition: transform .25s ease;
  }
  .toc.is-open { transform: none; box-shadow: var(--shadow); }
  .toc-inner { position: static; max-height: 100%; height: 100%; padding: 20px 16px; }
  .toc-backdrop { display: block; position: fixed; inset: 0; z-index: 55; background: rgb(0 0 0 / 35%); }
  .toc-backdrop[hidden] { display: none; }
  .content { width: 100%; margin: 0 auto; }
}

@media (max-width: 640px) {
  body { font-size: 16px; }
  .topbar-inner, .hero, .filters, .cards, .tutorial, .footer-inner { padding-left: 16px; padding-right: 16px; }
  .brand-name { display: none; }
  .hero { padding-top: 44px; }
  .card-link { padding: 22px 20px 18px; }
  .prose h2 { font-size: 25px; }
  .prose h3 { font-size: 19px; }
  .lead { padding: 18px; font-size: 17px; }
  .code { margin-left: -16px; margin-right: -16px; border-radius: 0; border-left: 0; border-right: 0; }
  .code code { font-size: 13px; }
  .code .ln { padding: 0 14px; }
  .table-wrap { margin-left: -16px; margin-right: -16px; border-radius: 0; border-left: 0; border-right: 0; }
}

@media print {
  .topbar, .toc, .chapter-foot, .code-copy, .finish, .footer { display: none !important; }
  .tutorial { display: block; }
  .answer { break-inside: avoid; }
}
