/* ============================================================
   Три кита веба — таблица стилей
   Структура файла:
   1. Переменные и темы      5. Секции и типографика
   2. Сброс и база           6. Компоненты (код, демо, таблица)
   3. Шапка и навигация      7. Песочница и тест
   4. Первый экран           8. Подвал и адаптив
   ============================================================ */

/* ── 1. Переменные ─────────────────────────────────────────── */
:root {
  --html: #e8622c;
  --css:  #3a8ee0;
  --js:   #ecc72c;

  --bg:        #0e1015;
  --bg-soft:   #151922;
  --bg-card:   #171c26;
  --line:      #262d3a;
  --text:      #e6e9f0;
  --muted:     #9aa4b8;
  --accent:    #6c8cff;
  --code-bg:   #0a0d13;

  --radius: 14px;
  --shadow: 0 18px 45px rgba(0, 0, 0, .45);
  --max: 1080px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, "SF Mono", monospace;
}

[data-theme="light"] {
  --bg:        #f6f7fb;
  --bg-soft:   #ffffff;
  --bg-card:   #ffffff;
  --line:      #e2e6ef;
  --text:      #1a1f2b;
  --muted:     #616b80;
  --accent:    #3b5bdb;
  --code-bg:   #1b202b;
  --shadow: 0 14px 34px rgba(20, 30, 60, .10);
}

/* ── 2. Сброс и база ───────────────────────────────────────── */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 84px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background .3s, color .3s;
}

h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.02em; }
p { margin: 0 0 1em; }
a { color: var(--accent); }

code {
  font-family: var(--mono);
  font-size: .88em;
  background: rgba(127, 148, 200, .14);
  padding: .12em .4em;
  border-radius: 5px;
  white-space: nowrap;
}

em { color: var(--text); font-style: normal; border-bottom: 2px solid var(--accent); }

::selection { background: var(--accent); color: #fff; }

/* Полоса прогресса чтения */
.progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: linear-gradient(90deg, var(--html), var(--js), var(--css));
  z-index: 200;
  transition: width .1s linear;
}

/* ── 3. Шапка ──────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 20px;
  padding: 12px max(20px, calc((100vw - var(--max)) / 2));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; color: var(--text); text-decoration: none;
  white-space: nowrap;
}
.brand-mark {
  font-family: var(--mono);
  background: linear-gradient(135deg, var(--html), var(--js));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  font-size: 20px;
}

.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a {
  color: var(--muted); text-decoration: none;
  padding: 7px 12px; border-radius: 8px;
  font-size: 15px; transition: .18s;
}
.nav a:hover { color: var(--text); background: var(--bg-soft); }
.nav a.is-active { color: var(--text); background: var(--bg-soft); }

.theme-toggle, .burger {
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  font-size: 16px; line-height: 1; transition: .18s;
}
.theme-toggle:hover, .burger:hover { border-color: var(--accent); transform: translateY(-1px); }
.burger { display: none; }

/* ── 4. Первый экран ───────────────────────────────────────── */
.hero {
  max-width: var(--max); margin: 0 auto; padding: 70px 20px 40px;
  position: relative;
}
.hero::before {
  content: ""; position: absolute; inset: -10% 10% auto 10%; height: 320px;
  background: radial-gradient(60% 100% at 50% 0, rgba(108, 140, 255, .20), transparent 70%);
  pointer-events: none; z-index: -1;
}

.eyebrow {
  text-transform: uppercase; letter-spacing: .16em; font-size: 12px;
  color: var(--muted); margin-bottom: 14px;
}
.hero h1 { font-size: clamp(30px, 5.4vw, 56px); font-weight: 800; }
.lead { font-size: clamp(16px, 2vw, 19px); color: var(--muted); max-width: 62ch; }

.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin: 26px 0 50px; }
.btn {
  display: inline-block; padding: 12px 22px; border-radius: 11px;
  text-decoration: none; font-weight: 600; font-size: 16px; transition: .18s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(108, 140, 255, .35); }
.btn-ghost { border: 1px solid var(--line); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); }

/* Три карточки-аналогии */
.analogy { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.analogy-card {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 24px 22px;
  position: relative; overflow: hidden; transition: .22s;
}
.analogy-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--c);
}
.analogy-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--c); }
.analogy-card h3 { font-size: 19px; }
.analogy-card p { color: var(--muted); font-size: 15px; margin-bottom: 14px; }
.analogy-card code { display: block; white-space: pre; overflow-x: auto; background: var(--code-bg); color: #cbd5e1; padding: 9px 11px; }
.analogy-emoji { font-size: 30px; margin-bottom: 8px; }

[data-tech="html"] { --c: var(--html); }
[data-tech="css"]  { --c: var(--css); }
[data-tech="js"]   { --c: var(--js); }

.analogy-note {
  margin-top: 26px; padding: 18px 20px; border-left: 3px solid var(--accent);
  background: var(--bg-soft); border-radius: 0 10px 10px 0; color: var(--muted); font-size: 16px;
}
.analogy-note b { color: var(--text); }

/* ── 5. Секции ─────────────────────────────────────────────── */
.section {
  max-width: var(--max); margin: 0 auto; padding: 60px 20px;
  border-top: 1px solid var(--line);
}
.section-head { margin-bottom: 28px; }
.section h2 { font-size: clamp(26px, 3.6vw, 38px); font-weight: 800; }
.section-sub { color: var(--muted); font-size: 16px; margin: 0; }

.chip {
  display: inline-block; font-size: 12px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--c, var(--accent)); border: 1px solid currentColor;
  padding: 3px 10px; border-radius: 99px; margin-bottom: 14px; opacity: .9;
}

.h3 { font-size: 21px; margin: 38px 0 14px; }
.prose { max-width: 72ch; color: var(--muted); }
.prose b { color: var(--text); }
.prose.small { font-size: 15px; }

.notes { color: var(--muted); max-width: 72ch; padding-left: 20px; }
.notes li { margin-bottom: 7px; }

.callout {
  margin-top: 26px; padding: 18px 20px;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-left: 3px solid var(--c, var(--accent));
  border-radius: 0 10px 10px 0; color: var(--muted); font-size: 15.5px;
}
.callout b { color: var(--text); }

/* Разбор строки кода */
.anatomy {
  display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: center;
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; margin: 26px 0;
}
.anatomy-code {
  font-family: var(--mono); font-size: clamp(14px, 1.8vw, 18px);
  background: var(--code-bg); padding: 18px; border-radius: 10px;
  overflow-x: auto; white-space: nowrap;
}
.t-bracket { color: #64748b; }
.t-tag  { color: var(--html); }
.t-attr { color: var(--js); }
.t-val  { color: #7ee787; }
.t-eq   { color: #64748b; }
.t-text { color: #e6e9f0; }
.t-sel  { color: var(--css); }
.t-prop { color: var(--js); }

.anatomy-legend { list-style: none; margin: 0; padding: 0; font-size: 15px; color: var(--muted); }
.anatomy-legend li { display: flex; align-items: baseline; gap: 9px; margin-bottom: 9px; }
.anatomy-legend b { color: var(--text); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.d-tag  { background: var(--html); }
.d-attr { background: var(--js); }
.d-val  { background: #7ee787; }
.d-text { background: #e6e9f0; }
.d-sel  { background: var(--css); }
.d-prop { background: var(--js); }

/* ── 6. Блок кода ──────────────────────────────────────────── */
.code-block {
  background: var(--code-bg); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; margin: 18px 0;
}
.code-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 14px; background: rgba(255, 255, 255, .04);
  font-family: var(--mono); font-size: 12.5px; color: #94a3b8;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.copy {
  background: transparent; border: 1px solid #3a4356; color: #94a3b8;
  padding: 4px 11px; border-radius: 7px; cursor: pointer; font-size: 12px; transition: .18s;
}
.copy:hover { color: #fff; border-color: #6c8cff; }
.copy.done { color: #7ee787; border-color: #7ee787; }

.code-block pre { margin: 0; padding: 18px; overflow-x: auto; }
.code-block code {
  background: none; padding: 0; white-space: pre;
  font-family: var(--mono); font-size: 14px; line-height: 1.7; color: #cbd5e1;
}

/* Сетка тегов */
.tag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 12px; margin-top: 16px; }
.tag-card {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: 11px; padding: 14px 15px; transition: .18s;
}
.tag-card:hover { border-color: var(--c, var(--accent)); transform: translateY(-2px); }
.tag-card code { display: block; background: none; padding: 0; color: var(--c, var(--accent)); font-size: 14px; margin-bottom: 4px; }
.tag-card span { font-size: 13.5px; color: var(--muted); }

/* Блочная модель */
.boxmodel { margin: 20px 0; font-family: var(--mono); font-size: 12px; }
.bm { padding: 26px 16px 16px; border-radius: 8px; position: relative; }
.bm-tag { position: absolute; top: 6px; left: 12px; opacity: .85; }
.bm-margin  { background: rgba(232, 98, 44, .16); }
.bm-border  { background: rgba(236, 199, 44, .16); }
.bm-padding { background: rgba(58, 142, 224, .16); }
.bm-content {
  background: var(--accent); color: #fff; text-align: center;
  padding: 22px 10px; border-radius: 6px; font-family: var(--font); font-size: 14px;
}

/* Демо-блоки */
.demo {
  margin: 26px 0 0; background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px;
}
.demo-title { font-weight: 600; margin-bottom: 16px; }
.demo-stage {
  display: grid; place-items: center; min-height: 170px;
  background: var(--bg-soft); border-radius: 10px; margin-bottom: 16px; overflow: hidden;
}
.demo-box {
  width: 130px; height: 130px; background: var(--accent); color: #fff;
  display: grid; place-items: center; border-radius: 8px; font-weight: 600;
  transition: all .35s cubic-bezier(.34, 1.4, .64, 1);
}
.demo-controls { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 14px; }
.demo-controls button {
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--text);
  padding: 8px 15px; border-radius: 9px; cursor: pointer; font-size: 14px; transition: .18s;
}
.demo-controls button:hover { border-color: var(--accent); transform: translateY(-1px); }
.demo-controls button.on { border-color: var(--accent); background: rgba(108, 140, 255, .16); }
.demo-controls .reset { margin-left: auto; color: var(--muted); }

.demo-out { background: var(--code-bg); border-radius: 9px; padding: 13px 15px; }
.demo-label { display: block; font-size: 12px; color: #64748b; margin-bottom: 6px; }
.demo-out pre { margin: 0; font-family: var(--mono); font-size: 13.5px; color: #7ee787; white-space: pre-wrap; }

/* Счётчик */
.counter { display: flex; align-items: center; justify-content: center; gap: 18px; padding: 14px 0; }
.counter button {
  width: 54px; height: 54px; font-size: 26px; border-radius: 14px; cursor: pointer;
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--text); transition: .15s;
}
.counter button:hover { border-color: var(--js); color: var(--js); }
.counter button:active { transform: scale(.92); }
.counter output { font-size: 46px; font-weight: 800; min-width: 110px; text-align: center; font-variant-numeric: tabular-nums; }
.demo-hint { text-align: center; color: var(--muted); font-size: 14px; margin: 6px 0 0; }

/* Шаги */
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; max-width: 76ch; }
.steps li {
  counter-increment: s; position: relative; padding: 14px 0 14px 52px;
  border-bottom: 1px solid var(--line); color: var(--muted);
}
.steps li:last-child { border-bottom: none; }
.steps li b { color: var(--text); }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 14px;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg-soft); border: 1px solid var(--line);
  display: grid; place-items: center; font-weight: 700; font-size: 14px; color: var(--accent);
}

/* Таблица */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.cmp { border-collapse: collapse; width: 100%; min-width: 620px; font-size: 15px; }
.cmp th, .cmp td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--line); }
.cmp thead th { background: var(--bg-soft); font-size: 14px; letter-spacing: .04em; }
.cmp tbody tr:last-child td { border-bottom: none; }
.cmp tbody td:first-child { color: var(--muted); font-size: 14px; }
.cmp tbody tr:hover { background: var(--bg-soft); }
.c-html { color: var(--html); }
.c-css  { color: var(--css); }
.c-js   { color: var(--js); }

/* ── 7. Песочница ──────────────────────────────────────────── */
.sandbox {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  height: 430px;
}
.sb-editor, .sb-preview {
  display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: var(--code-bg);
}
.sb-tabs { display: flex; background: rgba(255, 255, 255, .04); border-bottom: 1px solid var(--line); }
.sb-tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: #94a3b8; padding: 11px 18px; cursor: pointer;
  font-family: var(--mono); font-size: 13px; transition: .18s;
}
.sb-tab:hover { color: #fff; }
.sb-tab.is-active { color: #fff; border-bottom-color: var(--accent); }
.sb-reset {
  margin-left: auto; background: none; border: none; color: #94a3b8;
  cursor: pointer; font-size: 17px; padding: 0 16px;
}
.sb-reset:hover { color: #fff; }

.sb-code {
  display: none; flex: 1; width: 100%; resize: none;
  background: var(--code-bg); color: #cbd5e1; border: none; outline: none;
  padding: 16px; font-family: var(--mono); font-size: 13.5px; line-height: 1.65;
  tab-size: 2;
}
.sb-code.is-active { display: block; }

.sb-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: rgba(255, 255, 255, .04);
  border-bottom: 1px solid var(--line); font-size: 12.5px; color: #94a3b8;
}
.sb-dots { display: flex; gap: 5px; }
.sb-dots i { width: 9px; height: 9px; border-radius: 50%; background: #3a4356; }
.sb-dots i:nth-child(1) { background: #ff5f57; }
.sb-dots i:nth-child(2) { background: #febc2e; }
.sb-dots i:nth-child(3) { background: #28c840; }
.sb-preview iframe { flex: 1; width: 100%; border: none; background: #fff; }

/* Тест */
.quiz { display: grid; gap: 16px; }
.q {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 22px;
}
.q-title { font-weight: 600; margin-bottom: 14px; }
.q-title span { color: var(--muted); font-weight: 400; margin-right: 8px; }
.q-options { display: grid; gap: 8px; }
.q-opt {
  text-align: left; background: var(--bg-soft); border: 1px solid var(--line);
  color: var(--text); padding: 11px 15px; border-radius: 10px;
  cursor: pointer; font-size: 15px; font-family: inherit; transition: .16s;
}
.q-opt:hover:not(:disabled) { border-color: var(--accent); transform: translateX(3px); }
.q-opt:disabled { cursor: default; opacity: .75; }
.q-opt.right { border-color: #38b26b; background: rgba(56, 178, 107, .14); opacity: 1; }
.q-opt.wrong { border-color: #e5484d; background: rgba(229, 72, 77, .14); opacity: 1; }
.q-why { margin: 12px 0 0; font-size: 14.5px; color: var(--muted); }

.quiz-result {
  margin-top: 20px; padding: 22px; text-align: center;
  background: var(--bg-card); border: 1px solid var(--accent); border-radius: var(--radius);
}
.quiz-result b { font-size: 24px; }

/* Маршрут */
.road { display: grid; grid-template-columns: repeat(auto-fit, minmax(195px, 1fr)); gap: 14px; }
.road-item {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 18px; transition: .2s;
}
.road-item:hover { transform: translateY(-3px); border-color: var(--accent); }
.road-num {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 14px; margin-bottom: 12px;
}
.road-item h4 { font-size: 16px; margin-bottom: 6px; }
.road-item p { font-size: 14px; color: var(--muted); margin: 0; }

/* ── 8. Подвал, кнопка «наверх», адаптив ───────────────────── */
.footer {
  max-width: var(--max); margin: 0 auto; padding: 40px 20px 70px;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 15px;
}
.footer .small { font-size: 13.5px; opacity: .8; }

.to-top {
  position: fixed; right: 22px; bottom: 22px; width: 44px; height: 44px;
  border-radius: 50%; border: 1px solid var(--line); background: var(--bg-soft);
  color: var(--text); font-size: 18px; cursor: pointer; z-index: 90;
  opacity: 0; pointer-events: none; transition: .25s;
}
.to-top.show { opacity: 1; pointer-events: auto; }
.to-top:hover { border-color: var(--accent); transform: translateY(-3px); }

@media (max-width: 900px) {
  .analogy { grid-template-columns: 1fr; }
  .anatomy { grid-template-columns: 1fr; }
  .sandbox { grid-template-columns: 1fr; height: auto; }
  .sb-editor { height: 320px; }
  .sb-preview { height: 300px; }
}

@media (max-width: 720px) {
  body { font-size: 16px; }
  .burger { display: block; }
  .nav {
    position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; gap: 0;
    background: var(--bg-soft); border-bottom: 1px solid var(--line);
    padding: 8px; display: none;
  }
  .nav.open { display: flex; }
  .hero { padding-top: 44px; }
  .demo-controls .reset { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}
