/* ============================================
   Интерактивный гайд по ОДУ
   Светлая «бумажная» тема — учебник + интерактив
   ============================================ */

:root {
  /* surfaces */
  --bg:        #f6f1e4;   /* основная кремовая бумага */
  --bg-2:      #ede5d2;   /* sidebar */
  --bg-3:      #e0d6bd;
  --panel:     #fdfaf2;
  --paper:     #fbf6e9;   /* фон холста графика */

  /* text */
  --fg:        #1c1810;
  --fg-mute:   #564f43;
  --fg-faint:  #8b8579;

  /* lines */
  --line:      #d6ceb8;
  --line-2:    #beb39a;

  /* accents (deep, readable on cream) */
  --blue:      #2a5e9e;
  --teal:      #1f8a76;
  --green:     #3d8a4c;
  --yellow:    #c19614;
  --orange:    #b8581f;
  --red:       #a8392c;
  --pink:      #a8407d;
  --purple:    #6b4290;
  --cyan:      #2a8e8e;

  --accent:    var(--orange);

  --serif:     "Source Serif Pro", "EB Garamond", Georgia, "Times New Roman", serif;
  --sans:      "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono:      "JetBrains Mono", "Fira Code", "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--orange); }

/* ---------- layout ---------- */
.app {
  display: grid;
  grid-template-columns: 290px 1fr;
  min-height: 100vh;
}

aside.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  padding: 28px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  font-family: var(--sans);
  font-size: 14px;
}

.sidebar-title {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  padding: 0 24px 6px;
  letter-spacing: 0.01em;
  color: var(--fg);
}

.sidebar-sub {
  padding: 0 24px 22px;
  color: var(--fg-mute);
  font-size: 12.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-section {
  padding: 14px 24px 6px;
  color: var(--fg-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sidebar-link {
  display: block;
  padding: 6px 24px 6px 28px;
  color: var(--fg-mute);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  line-height: 1.45;
  position: relative;
}

.sidebar-link:hover {
  color: var(--fg);
  background: rgba(0,0,0,0.025);
}

.sidebar-link.active {
  color: var(--orange);
  border-left-color: var(--orange);
  background: rgba(184,88,31,0.07);
}

/* dot marker for interactive pages */
.sidebar-link.is-viz {
  padding-left: 40px;
}
.sidebar-link.is-viz::before {
  content: "";
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 2px rgba(31,138,118,0.18);
}
.sidebar-link.is-viz.active::before {
  background: var(--orange);
  box-shadow: 0 0 0 2px rgba(184,88,31,0.2);
}
/* playgrounds — pulsing orange dot */
.sidebar-link.is-viz.is-play::before {
  background: var(--orange);
  box-shadow: 0 0 0 2px rgba(184,88,31,0.18);
  animation: play-pulse 2.4s ease-in-out infinite;
}
.sidebar-link.is-viz.is-play.active::before {
  background: var(--red);
  box-shadow: 0 0 0 2px rgba(168,57,44,0.25);
}
@keyframes play-pulse {
  0%,100% { box-shadow: 0 0 0 2px rgba(184,88,31,0.18); }
  50%     { box-shadow: 0 0 0 4px rgba(184,88,31,0.08); }
}

main.content {
  padding: 60px 5vw 120px;
  max-width: 1040px;
}

/* ---------- typography ---------- */
.eyebrow {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 14px;
  font-weight: 600;
}

h1.page-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 42px;
  line-height: 1.15;
  margin: 0 0 16px;
  letter-spacing: -0.01em;
  color: var(--fg);
}

p.lede {
  color: var(--fg-mute);
  font-size: 19px;
  line-height: 1.55;
  margin: 0 0 36px;
  max-width: 60ch;
}

h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 26px;
  margin: 48px 0 14px;
  letter-spacing: -0.005em;
  color: var(--fg);
}

h3 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 19px;
  margin: 28px 0 8px;
  color: var(--fg);
}

p { margin: 0 0 14px; }

ul, ol { margin: 0 0 14px; padding-left: 22px; }
li { margin: 4px 0; }

hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 36px 0;
}

/* ---------- блоки ---------- */
.box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 22px;
  margin: 18px 0;
}

.box-title {
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg-mute);
  margin-bottom: 8px;
  font-weight: 600;
}

.box.theorem  { border-left: 3px solid var(--blue);   }
.box.theorem  .box-title { color: var(--blue);   }

.box.def      { border-left: 3px solid var(--teal);   }
.box.def      .box-title { color: var(--teal);   }

.box.meaning  { border-left: 3px solid var(--yellow); background: #fbf3d8; }
.box.meaning  .box-title { color: var(--yellow); }

.box.anchor   { border-left: 3px solid var(--orange); }
.box.anchor   .box-title { color: var(--orange); }

.box.trap     { border-left: 3px solid var(--red);    background: #fbe9e4; }
.box.trap     .box-title { color: var(--red);    }

.box.example  { border-left: 3px solid var(--purple); }
.box.example  .box-title { color: var(--purple); }

.box.extra    { border-left: 3px solid var(--fg-faint); opacity: 0.92; }
.box.extra    .box-title { color: var(--fg-mute); }

/* ---------- inline math ---------- */
.katex { font-size: 1.02em; color: var(--fg); }
.katex-display { margin: 14px 0 18px; }

/* ---------- интерактивные виджеты ---------- */
.viz-wrap {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  margin: 22px 0 26px;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  box-shadow: 0 2px 6px rgba(60, 50, 30, 0.04);
}

.viz-wrap.no-controls { grid-template-columns: 1fr; }

.viz-header {
  grid-column: 1 / -1;
  padding: 13px 20px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  font-family: var(--serif);
  font-weight: 600;
  font-size: 16px;
  color: var(--fg);
  line-height: 1.4;
}
.viz-header .formula {
  color: var(--orange);
  font-style: italic;
  font-size: 15px;
  margin-left: 8px;
}

.viz-canvas-host {
  position: relative;
  background: var(--paper);
  height: 500px;
}
@media (max-width: 1100px) {
  .viz-canvas-host { height: 460px; }
}
@media (max-width: 720px) {
  .viz-canvas-host { height: 380px; }
}

.viz-canvas-host canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.viz-title { display: none; }

.viz-legend {
  position: absolute;
  bottom: 14px;
  left: 18px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--fg-mute);
  background: rgba(251, 246, 233, 0.92);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 11px;
  z-index: 2;
  max-width: 70%;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(60, 50, 30, 0.06);
}
.viz-legend.top-right    { top: 12px;    right: 12px;  bottom: auto; left: auto; }
.viz-legend.top-left     { top: 12px;    left: 12px;   bottom: auto; }
.viz-legend.bottom-right { bottom: 12px; right: 12px;  left: auto; }
.viz-legend.bottom-left  { bottom: 12px; left: 12px; }

.viz-legend .legend-title {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-faint);
  font-weight: 600;
  margin: 0 0 6px;
}
.viz-legend .legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--fg);
  line-height: 1.45;
  padding: 1px 0;
  white-space: nowrap;
}
.viz-legend .legend-swatch {
  width: 16px;
  height: 3px;
  border-radius: 2px;
  flex: 0 0 auto;
}
.viz-legend .legend-swatch.dashed {
  height: 0;
  border-top: 2px dashed currentColor;
  background: transparent;
}
.viz-legend .legend-swatch.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}
.viz-legend.chip {
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--fg-mute);
  letter-spacing: 0.01em;
}
.viz-legend.chip.accent { color: var(--orange); }
.viz-legend.chip strong { font-family: var(--sans); font-weight: 600; }

.viz-controls {
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 18px 18px 22px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--fg);
  overflow-y: auto;
}

.viz-controls h4 {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg-mute);
  font-weight: 600;
  margin: 14px 0 8px;
}
.viz-controls h4:first-child { margin-top: 0; }

.ctl { margin: 10px 0 14px; }
.ctl-label {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--fg-mute);
  margin-bottom: 5px;
}
.ctl-label .val {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--orange);
}

.ctl input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 18px;
}
.ctl input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--line-2);
  border-radius: 2px;
}
.ctl input[type="range"]::-moz-range-track {
  height: 3px;
  background: var(--line-2);
  border-radius: 2px;
}
.ctl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--orange);
  border: none;
  margin-top: -5.5px;
  cursor: pointer;
  transition: transform 0.1s;
}
.ctl input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--orange);
  border: none;
  cursor: pointer;
}
.ctl input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

.ctl-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.ctl-btn-group {
  display: grid;
  gap: 4px;
  grid-template-columns: 1fr 1fr;
}
.ctl-btn {
  font-family: var(--sans);
  font-size: 11.5px;
  padding: 7px 8px;
  background: var(--bg);
  color: var(--fg-mute);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  transition: all 0.12s;
  letter-spacing: 0.02em;
}
.ctl-btn:hover { color: var(--fg); border-color: var(--line-2); background: var(--bg-2); }
.ctl-btn.active {
  background: rgba(184,88,31,0.12);
  color: var(--orange);
  border-color: var(--orange);
}

.ctl-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  cursor: pointer;
  color: var(--fg-mute);
  font-size: 12.5px;
}
.ctl-toggle:hover { color: var(--fg); }
.ctl-toggle .pip {
  width: 30px; height: 16px;
  background: var(--bg);
  border-radius: 9px;
  position: relative;
  border: 1px solid var(--line-2);
  transition: background 0.15s;
}
.ctl-toggle .pip::after {
  content: "";
  position: absolute;
  width: 10px; height: 10px;
  background: var(--fg-faint);
  border-radius: 50%;
  top: 2px; left: 3px;
  transition: left 0.15s, background 0.15s;
}
.ctl-toggle.on .pip { background: rgba(184,88,31,0.18); border-color: var(--orange); }
.ctl-toggle.on .pip::after { left: 17px; background: var(--orange); }

.ctl-note {
  font-size: 11.5px;
  color: var(--fg-faint);
  line-height: 1.45;
  margin-top: 6px;
  font-style: italic;
}

/* legend block inside the controls panel — sits OUTSIDE the canvas */
.ctl-legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 0 4px;
}
.ctl-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--fg);
  line-height: 1.4;
}
.ctl-legend-swatch {
  width: 16px;
  height: 3px;
  border-radius: 2px;
  flex: 0 0 auto;
}
.ctl-legend-swatch.dashed {
  height: 0;
  border-top: 2px dashed currentColor;
  background: transparent;
}

/* ---------- TOC landing ---------- */
.toc-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-top: 28px;
}
.toc-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px 22px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  display: block;
  color: inherit;
}
.toc-card:hover {
  border-color: var(--line-2);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(60,50,30,0.06);
  color: inherit;
}
.toc-card .num {
  font-family: var(--mono);
  color: var(--orange);
  font-size: 12px;
  letter-spacing: 0.08em;
}
.toc-card .ttl {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 18px;
  margin-top: 4px;
  color: var(--fg);
}
.toc-card .desc {
  font-size: 13.5px;
  color: var(--fg-mute);
  margin-top: 6px;
  line-height: 1.5;
}

.viz-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 32px 0 0;
}
.viz-grid .toc-card { padding: 14px 16px; }
.viz-grid .toc-card .ttl { font-size: 15px; }
.viz-grid .toc-card .num {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.viz-grid .toc-card .num::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--teal);
}

/* ---------- footer nav ---------- */
.page-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 80px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 13px;
  gap: 12px;
}
.page-nav a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 45%;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  color: inherit;
}
.page-nav a:hover { border-color: var(--orange); color: inherit; }
.page-nav a .dir { color: var(--fg-faint); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; }
.page-nav a .lbl { color: var(--fg); font-weight: 500; }
.page-nav a.prev { margin-right: auto; }
.page-nav a.next { margin-left: auto; text-align: right; align-items: flex-end; }
.page-nav .spacer { flex: 1; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .viz-wrap { grid-template-columns: 1fr; }
  .viz-controls { border-left: none; border-top: 1px solid var(--line); }
}
@media (max-width: 980px) {
  .app { grid-template-columns: 240px 1fr; }
  aside.sidebar { padding: 18px 0; }
  .sidebar-title { font-size: 16px; padding: 0 18px 4px; }
  .sidebar-sub { padding: 0 18px 14px; font-size: 11px; }
  .sidebar-link { padding: 5px 18px 5px 22px; font-size: 13px; }
  .sidebar-link.is-viz { padding-left: 34px; }
  .sidebar-link.is-viz::before { left: 14px; }
  .sidebar-section { padding: 12px 18px 4px; }
  main.content { padding: 40px 4vw 80px; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  aside.sidebar { position: relative; height: auto; max-height: none; }
  main.content { padding: 28px 20px 64px; }
  .toc-grid, .viz-grid { grid-template-columns: 1fr; }
  h1.page-title { font-size: 32px; }
}

/* ---------- pendulum twin layout ---------- */
.viz-wrap.pendulum-twin {
  display: block;
}
.pendulum-twin-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  border-bottom: 1px solid var(--line);
}
.pendulum-twin-grid > .viz-canvas-host {
  border-right: 1px solid var(--line);
  height: 480px;
}
.pendulum-twin-grid > .viz-canvas-host:last-child {
  border-right: none;
}
.pendulum-twin-controls {
  border-left: none !important;
  border-top: none !important;
}
@media (max-width: 900px) {
  .pendulum-twin-grid { grid-template-columns: 1fr; }
  .pendulum-twin-grid > .viz-canvas-host {
    border-right: none;
    border-bottom: 1px solid var(--line);
    height: 380px;
  }
}

/* ---------- inline highlights ---------- */
em.h-blue   { color: var(--blue);   font-style: normal; }
em.h-teal   { color: var(--teal);   font-style: normal; }
em.h-orange { color: var(--orange); font-style: normal; }
em.h-yellow { color: var(--yellow); font-style: normal; }
em.h-red    { color: var(--red);    font-style: normal; }

/* ---------- semester divider ---------- */
.semester-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 8px 0 28px;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--fg-faint);
}
.semester-divider::before, .semester-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* ---------- caption under viz ---------- */
.viz-caption {
  font-family: var(--serif);
  font-size: 14px;
  font-style: italic;
  color: var(--fg-mute);
  margin: -10px 0 26px;
  padding: 0 6px;
}

/* ---------- ParticlePlayground (доп интерактив в главах) ---------- */
.playground {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 22px 0 28px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(60, 50, 30, 0.04);
}
.playground-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  flex-wrap: wrap;
}
.playground .pg-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 14.5px;
  color: var(--fg);
}
.playground .pg-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.playground .pg-btn {
  font-family: var(--sans);
  font-size: 11.5px;
  padding: 5px 12px;
  background: var(--panel);
  color: var(--fg-mute);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.12s;
  letter-spacing: 0.02em;
  font-weight: 500;
}
.playground .pg-btn:hover { color: var(--fg); border-color: var(--line-2); background: var(--bg); }
.playground .pg-btn.on { background: rgba(184,88,31,0.12); color: var(--orange); border-color: var(--orange); }

.playground-canvas {
  position: relative;
  background: var(--paper);
}
.playground-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.playground .pg-hint {
  position: absolute;
  bottom: 10px;
  right: 14px;
  font-family: var(--sans);
  font-size: 11px;
  color: var(--fg-faint);
  background: rgba(251,246,233,0.85);
  border: 1px solid var(--line);
  padding: 3px 8px;
  border-radius: 4px;
  pointer-events: none;
  letter-spacing: 0.04em;
}
.playground-desc {
  padding: 9px 16px 12px;
  font-family: var(--serif);
  font-size: 13.5px;
  font-style: italic;
  color: var(--fg-mute);
  border-top: 1px solid var(--line);
  background: var(--panel);
}

/* ---------- inline viz callout in chapter ---------- */
.viz-callout {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  margin: 18px 0;
  background: rgba(31,138,118,0.07);
  border: 1px solid rgba(31,138,118,0.25);
  border-radius: 10px;
  font-family: var(--sans);
  font-size: 14px;
  text-decoration: none;
  color: var(--fg);
  cursor: pointer;
}
.viz-callout:hover {
  background: rgba(31,138,118,0.12);
  border-color: var(--teal);
  color: var(--fg);
}
.viz-callout::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--teal);
  flex: 0 0 auto;
  box-shadow: 0 0 0 3px rgba(31,138,118,0.15);
}
.viz-callout .label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 600;
  margin-right: 4px;
}
.viz-callout .arrow { margin-left: auto; color: var(--teal); }

/* playground variant — orange */
.viz-callout.play {
  background: rgba(184,88,31,0.07);
  border-color: rgba(184,88,31,0.28);
}
.viz-callout.play:hover {
  background: rgba(184,88,31,0.12);
  border-color: var(--orange);
}
.viz-callout.play::before {
  background: var(--orange);
  box-shadow: 0 0 0 3px rgba(184,88,31,0.15);
  animation: play-pulse 2.4s ease-in-out infinite;
}
.viz-callout.play .label { color: var(--orange); }
.viz-callout.play .arrow { color: var(--orange); }
