/* =============================================================
   Курс «Программирование на C++» — базовые стили
   ============================================================= */

:root {
  --bg:          #f4f7fc;
  --surface:     #ffffff;
  --surface-2:   #eaf0f8;
  --text:        #0f1729;
  --muted:       #5a6b86;
  --accent:      #0d6efd;
  --accent-soft: #dbe7ff;
  --accent-2:    #6f42c1;
  --border:      #dde4ee;
  --ok:          #16a34a;
  --ok-soft:     #d7f3e0;
  --warn:        #d97706;
  --warn-soft:   #fdf1d6;
  --err:         #dc2626;
  --err-soft:    #fde0e0;

  /* Для визуализаций */
  --bar-default: #4f8ef7;
  --bar-compare: #f0a11b;
  --bar-swap:    #e8513d;
  --bar-sorted:  #3eb268;

  --radius:      14px;
  --radius-sm:   9px;
  --shadow:      0 12px 28px -18px rgba(15, 23, 41, .5);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --t: .22s ease;
}

[data-theme="dark"] {
  --bg:          #080e1a;
  --surface:     #0f1729;
  --surface-2:   #16203a;
  --text:        #e6eefc;
  --muted:       #8ea0bd;
  --accent:      #60a5fa;
  --accent-soft: #17243d;
  --accent-2:    #a78bfa;
  --border:      #1f2c46;
  --ok-soft:     #0f2e1e;
  --warn-soft:   #382708;
  --err-soft:    #3a1414;
  --shadow:      0 12px 28px -18px rgba(0, 0, 0, .95);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  transition: background var(--t), color var(--t);
}

h1, h2, h3, h4 { margin: 0 0 .55em; line-height: 1.25; font-weight: 700; letter-spacing: -.02em; }
h1 { font-size: clamp(1.7rem, 1.1rem + 2.4vw, 2.4rem); }
h2 { font-size: clamp(1.25rem, 1.1rem + .9vw, 1.6rem); }
h3 { font-size: 1.08rem; }
p  { margin: 0 0 1em; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, kbd {
  font-family: var(--mono); font-size: .88em;
  background: var(--surface-2); padding: .12em .42em; border-radius: 5px;
}
kbd { border: 1px solid var(--border); padding: .1em .4em; }

img, svg, iframe { max-width: 100%; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.container { width: min(1180px, 100%); margin-inline: auto; padding: 0 20px; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 2000;
  background: var(--accent); color: #fff; padding: .7rem 1.1rem; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

/* ---------- Nav ---------- */
.navbar {
  position: sticky; top: 0; z-index: 900;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 64px; }
.logo { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.02rem; color: var(--text); letter-spacing: -.03em; }
.logo:hover { text-decoration: none; }
.logo-mark {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: .74rem; font-weight: 800; font-family: var(--mono); letter-spacing: -.02em;
}
.logo-text span { color: var(--accent); }

.nav-links { display: flex; align-items: center; gap: 1.4rem; list-style: none; margin: 0; padding: 0; }
.nav-links a { color: var(--muted); font-size: .92rem; font-weight: 500; padding: .35rem 0; border-bottom: 2px solid transparent; transition: var(--t); }
.nav-links a:hover { color: var(--text); text-decoration: none; }
.nav-links a.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.nav-actions { display: flex; align-items: center; gap: .5rem; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font-size: 1rem; cursor: pointer; transition: var(--t);
}
.icon-btn:hover { border-color: var(--accent); }

.nav-toggle {
  display: none; flex-direction: column; justify-content: center; gap: 4px;
  width: 38px; height: 38px; padding: 0 9px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); cursor: pointer;
}
.nav-toggle span { display: block; height: 2px; background: var(--text); border-radius: 2px; transition: var(--t); }
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ---------- Hero ---------- */
.hero {
  background:
    radial-gradient(900px 400px at 12% -10%, rgba(96, 165, 250, .35), transparent 60%),
    radial-gradient(700px 350px at 95% 10%, rgba(167, 139, 250, .28), transparent 60%),
    linear-gradient(135deg, #1e3a8a 0%, #0b1220 100%);
  color: #fff; padding: clamp(3rem, 8vw, 5rem) 0;
}
.hero h1 { color: #fff; max-width: 52ch; }
.hero .lead { font-size: 1.08rem; color: #c7d2e5; max-width: 160ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: 1.5rem; }
.hero-stats {
  display: flex; flex-wrap: wrap; gap: 1.5rem; margin-top: 2rem;
  padding-top: 1.5rem; border-top: 1px solid rgba(255,255,255,.15);
}
.hero-stat strong { display: block; font-size: 1.7rem; line-height: 1; font-weight: 800; color: #fff; }
.hero-stat span { font-size: .82rem; color: #b1c0d9; text-transform: uppercase; letter-spacing: .08em; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .7rem 1.3rem; border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; font: inherit; font-weight: 600; font-size: .93rem;
  cursor: pointer; transition: var(--t); text-decoration: none;
}
.btn:hover { background: color-mix(in srgb, var(--accent) 85%, #000); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--accent); }
.hero .btn-ghost { color: #fff; border-color: rgba(255,255,255,.35); }
.hero .btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-sm { padding: .42rem .8rem; font-size: .83rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Sections ---------- */
.section { padding: clamp(2rem, 4.5vw, 3.4rem) 0; }
.section-head { max-width: 72ch; margin-bottom: 1.6rem; }
.section-head p { color: var(--muted); margin: 0; }

.page-head {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 2rem 0 1.8rem;
}
.breadcrumb { font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--accent); }
.page-head .lead { color: var(--muted); max-width: 74ch; margin: 0; }

.badges { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: 1rem; }
.badge {
  display: inline-block; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  padding: .26rem .58rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.badge.ok   { background: var(--ok-soft);   color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err  { background: var(--err-soft);  color: var(--err); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1.6rem;
  border-bottom: 1px solid var(--border); padding-bottom: .6rem;
}
.tab-btn {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  font: inherit; font-size: .92rem; font-weight: 600;
  padding: .55rem 1rem; border-radius: var(--radius-sm);
  cursor: pointer; transition: var(--t);
}
.tab-btn:hover { color: var(--text); background: var(--surface-2); }
.tab-btn.is-active { color: var(--accent); background: var(--accent-soft); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Lab listing ---------- */
.lab-list { display: grid; gap: .7rem; }
.lab-item {
  display: grid; grid-template-columns: 62px 1fr auto; align-items: start; gap: 1rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .95rem 1.1rem; transition: var(--t);
}
.lab-item:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); box-shadow: var(--shadow); }
.lab-num {
  display: grid; place-items: center; width: 50px; height: 50px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: .9rem; font-family: var(--mono);
}
.lab-item h3 { margin: 0 0 .2rem; font-size: 1.02rem; }
.lab-item .topic-list { margin: .3rem 0 0; padding-left: 1.1rem; color: var(--muted); font-size: .87rem; }
.lab-item .topic-list li { margin-bottom: .15rem; }
.lab-item .lab-actions { display: flex; flex-direction: column; align-items: flex-end; gap: .4rem; }

/* ---------- Cards ---------- */
.grid { display: grid; gap: 1.1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.card {
  position: relative; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.3rem; transition: var(--t);
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.card h3 { margin-bottom: .35rem; }
.card p { color: var(--muted); font-size: .92rem; margin-bottom: 1rem; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-top: auto; padding-top: .85rem; border-top: 1px solid var(--border); }
.card-icon { font-size: 1.5rem; margin-bottom: .6rem; }

/* ---------- Progress ---------- */
.progress-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 1.5rem; }
.progress-track { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: .6rem; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width .35s ease; }
.progress-label { font-size: .85rem; color: var(--muted); margin: .55rem 0 0; }

/* ---------- Panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.3rem; margin-bottom: 1.3rem; }
.panel > h2 { margin-top: 0; }

.demo-split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.demo-pane { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .5rem .85rem; font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--border); }

/* ---------- Forms ---------- */
.field { margin-bottom: .9rem; }
.field label { display: block; font-size: .86rem; font-weight: 600; margin-bottom: .28rem; }
.field .hint { font-size: .76rem; color: var(--muted); }

input[type="text"], input[type="email"], input[type="number"], input[type="search"], select, textarea {
  width: 100%; padding: .6rem .78rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: .93rem; outline: none; transition: var(--t);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

.controls { display: grid; gap: .7rem; }
.control-row { display: grid; grid-template-columns: 180px 1fr; align-items: center; gap: .8rem; }
.control-row label { font-size: .84rem; font-weight: 600; color: var(--muted); margin: 0; }
.control-row output { font-family: var(--mono); font-size: .8rem; color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 17px; height: 17px; }
.checkline { display: inline-flex; align-items: center; gap: .5rem; font-size: .88rem; }

/* ---------- Code blocks ---------- */
.code-block { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 1.2rem; background: var(--surface); }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .42rem .8rem .42rem 1rem; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: .74rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.copy-btn { border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--muted); font: inherit; font-size: .72rem; font-weight: 600; padding: .26rem .6rem; cursor: pointer; transition: var(--t); }
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.copy-btn.is-ok { color: var(--ok); border-color: var(--ok); }
.code-block pre { margin: 0; padding: 1rem; overflow-x: auto; font-family: var(--mono); font-size: .83rem; line-height: 1.65; }
.code-block pre code { background: none; padding: 0; font-size: inherit; }

/* ---------- Notes / tasks ---------- */
.note { border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: .85rem 1.05rem; margin-bottom: 1.1rem; font-size: .92rem; }
.note.warn { border-color: var(--warn); background: var(--warn-soft); }
.note.err  { border-color: var(--err);  background: var(--err-soft); }
.note.ok   { border-color: var(--ok);   background: var(--ok-soft); }
.note :last-child { margin-bottom: 0; }

.task { border: 1px dashed color-mix(in srgb, var(--accent) 45%, var(--border)); border-radius: var(--radius); padding: 1.1rem 1.2rem; background: var(--surface); }
.task h2, .task h3 { margin-top: 0; }
.task ol, .task ul { padding-left: 1.2rem; margin: 0; }
.task li { margin-bottom: .35rem; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; margin-bottom: 1.2rem; }
table { width: 100%; border-collapse: collapse; font-size: .89rem; }
th, td { padding: .55rem .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
tbody tr:hover { background: var(--surface-2); }

/* ---------- Output ---------- */
.output {
  margin: 0; padding: 1rem; max-height: 340px; overflow: auto;
  font-family: var(--mono); font-size: .82rem; line-height: 1.6;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  white-space: pre-wrap; word-break: break-word;
}

/* ---------- Визуализации (для демо) ---------- */
.viz-stage {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.2rem; overflow-x: auto;
}
.bars-wrap {
  display: flex; align-items: flex-end; justify-content: center;
  gap: 4px; min-height: 240px; height: 260px;
}
.bar {
  flex: 1; max-width: 42px;
  background: var(--bar-default);
  border-radius: 5px 5px 0 0; position: relative;
  transition: height .25s ease, background-color .2s ease;
}
.bar.is-compare { background: var(--bar-compare); }
.bar.is-swap    { background: var(--bar-swap); }
.bar.is-sorted  { background: var(--bar-sorted); }
.bar span {
  position: absolute; bottom: -22px; left: 0; right: 0;
  text-align: center; font-size: .72rem; color: var(--muted); font-family: var(--mono);
}
.cells-wrap { display: flex; gap: 6px; flex-wrap: wrap; }
.cell {
  min-width: 46px; padding: .5rem .6rem; text-align: center;
  font-family: var(--mono); font-size: .9rem; font-weight: 600;
  border: 2px solid var(--border); border-radius: 8px; background: var(--surface);
  transition: var(--t);
}
.cell.is-active  { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.cell.is-remove  { border-color: var(--err);    background: var(--err-soft);    color: var(--err); }
.cell.is-insert  { border-color: var(--ok);     background: var(--ok-soft);     color: var(--ok); }
.cell.is-match   { border-color: var(--warn);   background: var(--warn-soft);   color: var(--warn); }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .7rem; margin: 1rem 0; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .7rem .9rem; }
.metric-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.metric-value { font-size: 1.4rem; font-weight: 800; font-family: var(--mono); margin-top: .15rem; }

/* ---------- SVG (для деревьев/списков) ---------- */
.viz-svg { width: 100%; display: block; }
.viz-svg .node-rect { fill: var(--surface); stroke: var(--accent); stroke-width: 2; rx: 8; }
.viz-svg .node-text { font-family: var(--mono); font-size: 14px; font-weight: 700; fill: var(--text); }
.viz-svg .edge { stroke: var(--muted); stroke-width: 1.8; fill: none; }
.viz-svg .edge.highlight { stroke: var(--accent); stroke-width: 2.5; }
.viz-svg .node-rect.highlight { fill: var(--accent-soft); stroke-width: 3; }
.viz-svg .node-rect.found { fill: var(--ok-soft); stroke: var(--ok); stroke-width: 3; }

/* ---------- Lesson nav ---------- */
.lesson-nav {
  display: flex; flex-wrap: wrap; gap: .8rem; justify-content: space-between;
  margin: 2.2rem 0 1rem; padding-top: 1.4rem; border-top: 1px solid var(--border);
}
.lesson-nav a {
  flex: 1 1 220px; padding: .85rem 1.05rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); transition: var(--t);
}
.lesson-nav a:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.lesson-nav small { display: block; color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; }
.lesson-nav strong { display: block; color: var(--text); font-size: .94rem; }
.lesson-nav .next { text-align: right; }

/* ---------- Footer ---------- */
.footer { margin-top: 2.8rem; padding: 1.8rem 0; background: #0b1220; color: #94a3b8; font-size: .88rem; }
.footer a { color: #e2e8f0; }
.footer-inner { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: center; }
.footer p { margin: 0; }

/* ---------- Utility ---------- */
.muted { color: var(--muted); }
.center { text-align: center; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0 !important; }
.hidden { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .demo-split { grid-template-columns: 1fr; }
  .lab-item { grid-template-columns: 50px 1fr; }
  .lab-item .lab-actions { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; }
}

@media (max-width: 860px) {
  .nav-toggle { display: flex; }
  .nav-links {
    position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: .5rem 20px 1rem; display: none;
  }
  .nav-links.is-open { display: flex; }
  .nav-links a { display: block; padding: .7rem 0; border-bottom: 1px solid var(--border); }
  .nav-links a.is-active { border-bottom-color: var(--border); }
  .control-row { grid-template-columns: 1fr; gap: .25rem; }
  .lesson-nav .next { text-align: left; }
  .bars-wrap { height: 180px; min-height: 180px; }
  .bar span { font-size: .62rem; bottom: -18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  html { scroll-behavior: auto; }
}