/* ============================================================
   Закреплённый дизайн учебных конспектов курса «Информатика».
   Направление: «инженерная тетрадь» — тёплая бумага, клетка,
   синие чернила, двоичная нумерация разделов, битовая лента.
   Подключение на каждой странице курса:
   <link rel="stylesheet" href="style.css">
   ============================================================ */

:root {
  /* --- мир продукта: тетрадь, чернила, пометки --- */
  --paper: #faf8f2;            /* лист тетради */
  --paper-shade: #f2efe6;      /* стол под листом */
  --grid-line: rgba(43, 76, 126, 0.07);   /* клетка тетради */
  --ink: #1e2a3a;              /* основной текст, тёмный графит */
  --ink-strong: #16324f;       /* заголовки, синие чернила */
  --ink-faded: #5d6a79;        /* второстепенный текст */
  --ink-muted: #8b95a1;        /* подписи, метаданные */
  --accent: #2b5d8a;           /* акцент: чернильная ручка */
  --accent-wash: #e8eff6;      /* лёгкая заливка акцента */
  --red-pen: #b3402e;          /* красная ручка преподавателя */
  --red-wash: #f9ece9;
  --green-pen: #3a6b4f;        /* зелёная паста: примеры, «зачтено» */
  --green-wash: #ebf2ed;
  --rule: rgba(30, 42, 58, 0.14);          /* обычная линия */
  --rule-soft: rgba(30, 42, 58, 0.08);     /* едва заметная линия */

  /* --- типографика: базовый размер 17px, шаг ~1.25 --- */
  --font-body: "Segoe UI", "PT Sans", system-ui, sans-serif;
  --font-head: Cambria, Georgia, "Times New Roman", serif;
  --font-mono: "Cascadia Code", Consolas, "Courier New", monospace;

  /* --- сетка: базовый шаг 8px --- */
  --s1: 8px; --s2: 16px; --s3: 24px; --s4: 32px; --s6: 48px;
  --radius: 6px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink);
  background-color: var(--paper-shade);
}

/* ---------- Шапка: чернильная плашка ---------- */
.page-header {
  background: var(--ink-strong);
  color: #f4f1e8;
  padding: var(--s6) var(--s3) var(--s4);
  text-align: center;
}
.page-header .course {
  font-family: var(--font-mono);
  font-size: .78rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: #a8c3dd;
  margin-bottom: var(--s2);
}
.page-header h1 {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 2rem;
  letter-spacing: -0.01em;
  line-height: 1.25;
  max-width: 860px;
  margin: 0 auto;
  text-wrap: balance;
}
.page-header .subtitle {
  margin-top: var(--s2);
  font-size: .95rem;
  color: #c6d4e2;
}
.page-header .subtitle a { color: #a8c3dd; }

/* ---------- Битовая лента (подпись шапки и разделители) ---------- */
.bit-tape {
  display: flex;
  justify-content: center;
  gap: 0;
  margin: var(--s3) 0 0;
  user-select: none;
}
.bit-tape i {
  font-family: var(--font-mono);
  font-style: normal;
  font-size: .72rem;
  line-height: 1;
  padding: 5px 0;
  width: 22px;
  text-align: center;
  color: var(--ink-muted);
  border: 1px solid var(--rule-soft);
  border-left: none;
  background: var(--paper);
}
.bit-tape i:first-child { border-left: 1px solid var(--rule-soft); }
.bit-tape i.on { color: var(--accent); font-weight: 700; background: var(--accent-wash); }
.page-header .bit-tape i {
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.14);
  color: #7f9cb8;
}
.page-header .bit-tape i.on { color: #ffffff; background: rgba(255,255,255,.14); }
.tape-divider { margin: var(--s4) 0 0; }

/* ---------- Каркас страницы ---------- */
.layout {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  gap: var(--s4);
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--s4) var(--s3) 96px;
}
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .toc { position: static !important; max-height: none !important; }
}

/* Лист конспекта: бумага в клетку */
main.sheet {
  min-width: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 24px 24px;
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius);
  padding: var(--s4) 44px var(--s6);
}
@media (max-width: 640px) { main.sheet { padding: var(--s3) var(--s2) var(--s4); } }

/* ---------- Оглавление (поля тетради) ---------- */
.toc {
  position: sticky;
  top: var(--s2);
  align-self: start;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  font-size: .88rem;
  padding: var(--s2) 0;
}
.toc h2 {
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 var(--s1);
  border: none;
  padding: 0;
}
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 2px 0; }
.toc a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 10px;
  color: var(--ink-faded);
  text-decoration: none;
  border-left: 2px solid transparent;
  border-radius: 0 4px 4px 0;
}
.toc a:hover { color: var(--ink-strong); background: var(--accent-wash); border-left-color: var(--accent); }
.toc .bin {
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--accent);
  min-width: 30px;
}

/* ---------- Разделы: двоичная нумерация ---------- */
section { margin: 0 0 var(--s6); }
h2 {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 1.55rem;
  letter-spacing: -0.01em;
  color: var(--ink-strong);
  line-height: 1.3;
  margin: var(--s6) 0 var(--s2);
  padding-bottom: var(--s1);
  border-bottom: 2px solid var(--rule);
  text-wrap: balance;
}
section:first-of-type h2 { margin-top: 0; }
h2 .bin, h3 .bin {
  font-family: var(--font-mono);
  font-size: .68em;
  font-weight: 400;
  color: var(--paper);
  background: var(--accent);
  border-radius: 4px;
  padding: 3px 8px;
  margin-right: 12px;
  vertical-align: 2px;
  letter-spacing: .08em;
}
h3 {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 1.22rem;
  color: var(--ink-strong);
  margin: var(--s4) 0 var(--s2);
}
h4 {
  font-size: 1rem;
  font-weight: 650;
  color: var(--ink-strong);
  margin: var(--s3) 0 var(--s1);
}

p { margin: 0 0 var(--s2); text-align: justify; text-wrap: pretty; }
a { color: var(--accent); }
strong { color: var(--ink-strong); }
ul, ol { padding-left: 26px; margin: 0 0 var(--s2); }
li { margin: 5px 0; }
li::marker { color: var(--accent); }
code {
  font-family: var(--font-mono);
  font-size: .86em;
  background: var(--accent-wash);
  border-radius: 4px;
  padding: 2px 6px;
}

/* Блок кода: листинг на «бумаге», с подписью языка */
pre.code {
  position: relative;
  font-family: var(--font-mono);
  font-size: .88rem;
  line-height: 1.5;
  background: #fff;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: var(--s2) 20px;
  margin: var(--s2) 0 var(--s3);
  overflow-x: auto;
  white-space: pre;
  text-align: left;
}
pre.code[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 6px; right: 12px;
  font-size: .68rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* Подсветка синтаксиса в pre.code (токены расставляет инлайн-JS страницы) */
pre.code .tok-kw  { color: var(--accent); font-weight: 600; }
pre.code .tok-str { color: #9a5a1e; }
pre.code .tok-com { color: #8b8578; font-style: italic; }
pre.code .tok-num { color: #7d4a9e; }
pre.code .tok-pre { color: var(--green-pen); }

/* ---------- Иллюстрации ---------- */
figure { margin: var(--s3) auto; text-align: center; max-width: 700px; }
figure img {
  max-width: 100%;
  height: auto;
  background: #fff;
  padding: var(--s1);
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius);
  outline: 1px solid rgba(0,0,0,.04);
}
figcaption {
  margin-top: var(--s1);
  font-size: .84rem;
  color: var(--ink-muted);
  font-style: italic;
}

/* ---------- Пометки на полях (admonitions) ---------- */
.adm {
  border-left: 3px solid;
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: var(--s2) 20px;
  margin: var(--s3) 0;
}
.adm .adm-title {
  font-family: var(--font-mono);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  margin-bottom: var(--s1);
}
.adm-note    { background: var(--accent-wash); border-color: var(--accent); }
.adm-note    .adm-title { color: var(--accent); }
.adm-warn    { background: var(--red-wash);   border-color: var(--red-pen); }
.adm-warn    .adm-title { color: var(--red-pen); }
.adm-example { background: var(--green-wash); border-color: var(--green-pen); }
.adm-example .adm-title { color: var(--green-pen); }
.adm p:last-child, .adm ul:last-child, .adm ol:last-child { margin-bottom: 0; }
.adm .source {
  display: block;
  text-align: right;
  font-size: .8rem;
  color: var(--ink-muted);
  font-style: italic;
  margin-top: 4px;
}

/* ---------- Формулы (локально, без библиотек) ---------- */
.formula {
  font-family: var(--font-head);
  font-style: italic;
  font-size: 1.3rem;
  text-align: center;
  margin: var(--s3) auto;
  padding: var(--s2) var(--s3);
  background: #fff;
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius);
  overflow-x: auto;
}
.formula sub, .formula sup { font-size: .62em; }

/* ---------- Таблицы ---------- */
table {
  border-collapse: collapse;
  width: 100%;
  margin: var(--s2) 0 var(--s3);
  font-size: .94rem;
  background: #fff;
}
th, td { border: 1px solid var(--rule); padding: 8px 14px; text-align: left; }
th {
  font-family: var(--font-mono);
  font-size: .78rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  background: var(--accent-wash);
  color: var(--ink-strong);
}
td { font-variant-numeric: tabular-nums; }

/* ---------- Лента истории ---------- */
.timeline { list-style: none; padding: 0; margin: var(--s3) 0; position: relative; }
.timeline::before {
  content: "";
  position: absolute;
  left: 92px; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--rule);
}
.timeline li { position: relative; padding: 4px 0 4px 124px; margin-bottom: var(--s2); }
.timeline li::before {
  content: "";
  position: absolute;
  left: 87px; top: 13px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--paper);
  border: 3px solid var(--accent);
}
.timeline .year {
  position: absolute;
  left: 0; top: 4px;
  width: 74px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: .88rem;
  font-weight: 700;
  color: var(--ink-strong);
}

/* ---------- Карточки понятий ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: var(--s2);
  margin: var(--s3) 0;
}
.card {
  background: #fff;
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius);
  padding: var(--s2) 20px;
  transition: transform .25s cubic-bezier(.23,1,.32,1), border-color .25s;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); }
.card h4 { margin: 0 0 6px; }
.card .tag {
  font-family: var(--font-mono);
  font-size: .7rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  display: block;
  margin-bottom: 4px;
}
.card p { font-size: .9rem; color: var(--ink-faded); margin: 0; text-align: left; }

/* ---------- Тренажёры (лабораторный стенд) ---------- */
.trainer {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: var(--s3) var(--s3) var(--s3);
  margin: var(--s3) 0;
}
.trainer > h4 {
  font-family: var(--font-mono);
  font-size: .8rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--green-pen);
  margin: 0 0 var(--s2);
  padding-bottom: var(--s1);
  border-bottom: 1px dashed var(--rule);
}
.trainer .hint { font-size: .88rem; color: var(--ink-faded); text-align: left; }
.trainer input[type="range"] { width: 100%; accent-color: var(--accent); margin: var(--s1) 0; }
.trainer .readout {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  background: var(--paper);
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin: var(--s1) 0 var(--s2);
}
.trainer .readout b { color: var(--accent); font-size: 1.15em; }

.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  font-size: .95rem;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  padding: 10px 22px;
  margin: 4px 8px 4px 0;
  cursor: pointer;
  transition: background .18s, transform .1s;
}
.btn:hover { background: #1f4a72; }
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 2px solid var(--ink-strong); outline-offset: 2px; }
.btn.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.secondary:hover { background: var(--accent-wash); }

/* Полоса-диапазон в игре «угадай число» */
.range-track {
  display: flex;
  height: 30px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  margin: var(--s2) 0;
  background: repeating-linear-gradient(90deg, var(--paper) 0, var(--paper) 23px, var(--rule-soft) 23px, var(--rule-soft) 24px);
}
.range-track .active {
  background: var(--accent);
  opacity: .8;
  transition: margin .45s cubic-bezier(.23,1,.32,1), width .45s cubic-bezier(.23,1,.32,1);
}

/* ---------- Квиз самопроверки ---------- */
.quiz-q {
  background: #fff;
  border: 1px solid var(--rule-soft);
  border-left: 3px solid var(--rule);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: var(--s2) 20px;
  margin: var(--s2) 0;
  transition: border-color .3s, background .3s;
}
.quiz-q .q-text { font-weight: 650; color: var(--ink-strong); margin-bottom: var(--s1); text-align: left; }
.quiz-q label {
  display: block;
  margin: 2px 0;
  padding: 7px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .15s;
}
.quiz-q label:hover { background: var(--accent-wash); }
.quiz-q.correct { border-left-color: var(--green-pen); background: var(--green-wash); }
.quiz-q.wrong   { border-left-color: var(--red-pen);   background: var(--red-wash); }
.quiz-q .verdict { font-size: .85rem; font-weight: 700; margin: var(--s1) 0 0; }
.quiz-q.correct .verdict { color: var(--green-pen); }
.quiz-q.wrong   .verdict { color: var(--red-pen); }
.quiz-result {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.05rem;
  margin-top: var(--s2);
  color: var(--ink-strong);
}

/* ---------- Анимация появления при прокрутке ---------- */
.reveal { opacity: 0; transform: translateY(20px); transition: opacity .6s cubic-bezier(.23,1,.32,1), transform .6s cubic-bezier(.23,1,.32,1); }
.reveal.visible { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
  .range-track .active { transition: none; }
  html { scroll-behavior: auto; }
}

/* ---------- Подвал ---------- */
.page-footer {
  text-align: center;
  color: var(--ink-muted);
  font-size: .84rem;
  padding: var(--s3);
}
.page-footer .bit-tape { margin-bottom: var(--s2); }
