/* =============================================================================
 * Курс System Design — основной CSS
 * Дизайн: минималистичный, тёмная и светлая темы, читаемая типографика.
 * ============================================================================= */

:root {
  --bg:           #f6f7fb;
  --bg-alt:       #eef0f6;
  --surface:      #ffffff;
  --surface-2:    #f3f4f9;
  --surface-3:    #e8eaf2;
  --border:       #e3e6ef;
  --border-soft:  #eef0f6;
  --text:         #1b1f2a;
  --text-soft:    #4b5161;
  --muted:        #7a8094;
  --accent:       #5b6cff;
  --accent-2:     #7b5bff;
  --accent-3:     #ff7a59;
  --success:      #1aa97b;
  --warn:         #f5a524;
  --danger:       #e5484d;
  --shadow-sm:    0 1px 2px rgba(15,23,42,.04), 0 4px 12px rgba(15,23,42,.04);
  --shadow:       0 1px 2px rgba(15,23,42,.04), 0 6px 24px rgba(15,23,42,.06);
  --shadow-lg:    0 2px 4px rgba(15,23,42,.04), 0 16px 48px rgba(15,23,42,.08);
  --radius:       14px;
  --radius-sm:    10px;
  --radius-lg:    22px;
  --code-bg:      #0f1115;
  --code-text:    #e7e9ee;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg:           #0b0d12;
  --bg-alt:       #0f1218;
  --surface:      #13161e;
  --surface-2:    #181c26;
  --surface-3:    #20242f;
  --border:       #262b38;
  --border-soft:  #1c2030;
  --text:         #e7e9ee;
  --text-soft:    #b5bccd;
  --muted:        #7d8499;
  --accent:       #7b8eff;
  --accent-2:     #a48bff;
  --accent-3:     #ff8e75;
  --success:      #2cd193;
  --warn:         #fbbd23;
  --danger:       #ff6369;
  --shadow-sm:    0 1px 2px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.25);
  --shadow:       0 1px 2px rgba(0,0,0,.5), 0 6px 24px rgba(0,0,0,.35);
  --shadow-lg:    0 2px 4px rgba(0,0,0,.5), 0 16px 48px rgba(0,0,0,.45);
  --code-bg:      #0a0d12;
  --code-text:    #d8dde7;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  scroll-behavior: smooth;
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  transition: background .25s ease, color .25s ease;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color .15s ease;
}
a:hover { color: var(--accent-2); }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

code, pre, kbd {
  font-family: var(--mono);
  font-size: 0.92em;
}

code {
  background: var(--surface-2);
  padding: 0.15em 0.45em;
  border-radius: 6px;
  color: var(--accent);
  border: 1px solid var(--border-soft);
}

pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 16px 20px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  line-height: 1.5;
  border: 1px solid var(--border);
}
pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  border: none;
}

/* =============================================================================
 * Layout
 * ============================================================================= */

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.layout--no-sidebar { grid-template-columns: 1fr; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 24px 18px;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border-soft);
}
.sidebar__brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  color: white;
  font-weight: 700;
  font-size: 18px;
}
.sidebar__brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.01em;
}
.sidebar__brand-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.sidebar__group {
  margin-bottom: 22px;
}
.sidebar__group-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: 0 8px 8px;
}
.sidebar__chapter {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text-soft);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
  margin-bottom: 2px;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}
.sidebar__chapter:hover {
  background: var(--surface-2);
  color: var(--text);
}
.sidebar__chapter--active {
  background: linear-gradient(135deg, rgba(91,108,255,.12), rgba(123,91,255,.12));
  color: var(--accent);
  font-weight: 600;
}
.sidebar__chapter-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  display: grid;
  place-items: center;
  font-weight: 600;
}
.sidebar__chapter--active .sidebar__chapter-num {
  background: var(--accent);
  color: white;
}
.sidebar__chapter-title {
  flex: 1;
  line-height: 1.3;
}
.sidebar__chapter-check {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--success);
  opacity: 0;
}
.sidebar__chapter--done .sidebar__chapter-check { opacity: 1; }

.sidebar__progress {
  margin-top: 24px;
  padding: 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
}
.sidebar__progress-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
}
.sidebar__progress-bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.sidebar__progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .4s ease;
}

.main {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(180%) blur(8px);
}
.topbar__crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.topbar__crumbs a { color: var(--text-soft); }
.topbar__crumbs a:hover { color: var(--accent); }
.topbar__crumbs-sep { color: var(--muted); }

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 16px;
  transition: background .15s ease;
}
.theme-toggle:hover { background: var(--surface-3); }
.theme-toggle__sun { display: none; }
.theme-toggle__moon { display: block; }
[data-theme="dark"] .theme-toggle__sun { display: block; }
[data-theme="dark"] .theme-toggle__moon { display: none; }

/* =============================================================================
 * Hero / Index
 * ============================================================================= */

.hero {
  padding: 60px 32px 32px;
  max-width: 900px;
  margin: 0 auto;
}
.hero__eyebrow {
  display: inline-block;
  padding: 5px 12px;
  background: var(--surface-2);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: .04em;
  margin-bottom: 18px;
  border: 1px solid var(--border);
}
.hero__title {
  font-size: clamp(32px, 5vw, 48px);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.1;
  margin: 0 0 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero__subtitle {
  font-size: 17px;
  color: var(--text-soft);
  margin: 0 0 28px;
  line-height: 1.6;
  max-width: 640px;
}
.hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 32px;
}
.hero__meta-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-soft);
}
.hero__meta-item strong { color: var(--text); font-weight: 600; }

.hero__cta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
  border: 1px solid transparent;
}
.btn--primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  box-shadow: var(--shadow-sm);
}
.btn--primary:hover {
  box-shadow: var(--shadow);
  color: white;
  transform: translateY(-1px);
}
.btn--ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn--ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.chapters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 0 32px 60px;
  max-width: 1200px;
  margin: 0 auto;
}
.chapter-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  cursor: pointer;
  transition: all .2s ease;
  position: relative;
  overflow: hidden;
}
.chapter-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: var(--accent);
  opacity: 0;
  transition: opacity .2s ease;
}
.chapter-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}
.chapter-card:hover::before { opacity: 1; }
.chapter-card__book {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 10px;
}
.chapter-card__num {
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  margin-bottom: 8px;
  letter-spacing: -.02em;
}
.chapter-card__title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 8px;
  color: var(--text);
}
.chapter-card__desc {
  font-size: 13px;
  color: var(--text-soft);
  line-height: 1.5;
  margin-bottom: 12px;
}
.chapter-card__meta {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
}
.chapter-card__done-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--success);
  color: white;
  display: grid;
  place-items: center;
  font-size: 12px;
  display: none;
}
.chapter-card--done .chapter-card__done-badge { display: grid; }

/* Books section divider */
.section-divider {
  padding: 32px 32px 8px;
  max-width: 1200px;
  margin: 0 auto;
}
.section-divider h2 {
  font-size: 22px;
  margin: 0 0 6px;
  letter-spacing: -.01em;
}
.section-divider p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* =============================================================================
 * Chapter view
 * ============================================================================= */

.chapter {
  padding: 36px 32px 80px;
  max-width: 900px;
  margin: 0 auto;
}

.scene {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 40px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  animation: scene-in .35s ease;
}
@keyframes scene-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.scene__type {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  background: var(--surface-2);
  color: var(--accent);
  margin-bottom: 16px;
}
.scene__type--quiz { background: rgba(245,165,36,.1); color: var(--warn); }
.scene__title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.015em;
  margin: 0 0 8px;
  line-height: 1.25;
}
.scene__subtitle {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 14px;
}
.scene__body { font-size: 15.5px; line-height: 1.75; color: var(--text-soft); }
.scene__body h1, .scene__body h2, .scene__body h3, .scene__body h4 {
  color: var(--text);
  margin-top: 1.6em;
  margin-bottom: 0.6em;
  letter-spacing: -.01em;
}
.scene__body h1 { font-size: 24px; }
.scene__body h2 { font-size: 20px; }
.scene__body h3 { font-size: 17px; }
.scene__body h4 { font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.scene__body p { margin: 0 0 1em; }
.scene__body ul, .scene__body ol { padding-left: 22px; margin: 0 0 1em; }
.scene__body li { margin-bottom: 0.4em; }
.scene__body blockquote {
  margin: 1em 0;
  padding: 14px 20px;
  border-left: 4px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-soft);
  font-style: italic;
}
.scene__body blockquote p:last-child { margin-bottom: 0; }
.scene__body strong { color: var(--text); font-weight: 700; }
.scene__body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 14px;
}
.scene__body th, .scene__body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.scene__body th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text);
}
.scene__body hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

.callout {
  margin: 18px 0;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 14px;
}
.callout--info { border-left: 4px solid var(--accent); }
.callout--warn { border-left: 4px solid var(--warn); background: rgba(245,165,36,.06); }
.callout--success { border-left: 4px solid var(--success); background: rgba(26,169,123,.06); }
.callout--danger { border-left: 4px solid var(--danger); background: rgba(229,72,77,.06); }
.callout__title {
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* Diagram */
.diagram {
  margin: 20px 0;
  padding: 18px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow-x: auto;
}
.diagram svg { max-width: 100%; height: auto; display: block; margin: 0 auto; }

/* =============================================================================
 * Quiz
 * ============================================================================= */

.quiz-question {
  margin-bottom: 28px;
  padding: 18px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.quiz-question__num {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.quiz-question__text {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text);
  line-height: 1.5;
}
.quiz-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all .15s ease;
  font-size: 14.5px;
  color: var(--text);
}
.quiz-option:hover {
  background: var(--surface-3);
  border-color: var(--accent);
}
.quiz-option__bullet {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
}
.quiz-option--selected {
  border-color: var(--accent);
  background: rgba(91,108,255,.06);
}
.quiz-option--selected .quiz-option__bullet {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}
.quiz-option--correct {
  border-color: var(--success);
  background: rgba(26,169,123,.08);
}
.quiz-option--correct .quiz-option__bullet {
  border-color: var(--success);
  background: var(--success);
  color: white;
}
.quiz-option--wrong {
  border-color: var(--danger);
  background: rgba(229,72,77,.06);
}
.quiz-option--wrong .quiz-option__bullet {
  border-color: var(--danger);
  background: var(--danger);
  color: white;
}

.quiz-explanation {
  margin-top: 14px;
  padding: 14px 18px;
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-soft);
  display: none;
}
.quiz-explanation--visible { display: block; }
.quiz-explanation strong { color: var(--text); }

.quiz-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}
.quiz-result {
  margin-left: auto;
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

/* =============================================================================
 * Scene navigation
 * ============================================================================= */

.scene-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.scene-nav__btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
}
.scene-nav__btn:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}
.scene-nav__btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.scene-nav__complete {
  background: linear-gradient(135deg, var(--success), #16c97f);
  color: white;
  border: none;
}
.scene-nav__complete:hover {
  color: white;
  box-shadow: var(--shadow);
}

.chapter-progress {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.chapter-progress__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--surface-3);
  transition: all .15s ease;
}
.chapter-progress__dot--done { background: var(--success); }
.chapter-progress__dot--current {
  background: var(--accent);
  width: 24px;
  border-radius: 4px;
}

/* =============================================================================
 * Responsive
 * ============================================================================= */

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 100;
    box-shadow: var(--shadow-lg);
  }
  .sidebar--open { transform: translateX(0); }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99;
  }
  .sidebar-backdrop--visible { display: block; }
  .menu-toggle { display: grid !important; }
  .hero { padding: 32px 20px 24px; }
  .chapters-grid { padding: 0 20px 40px; }
  .scene { padding: 24px 20px; }
  .topbar { padding: 12px 16px; }
}
@media (min-width: 901px) {
  .menu-toggle { display: none; }
}

.menu-toggle {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
}

/* =============================================================================
 * Footer
 * ============================================================================= */

.footer {
  padding: 24px 32px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}
.footer a { color: var(--text-soft); }

/* =============================================================================
 * Utility
 * ============================================================================= */

.kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text);
  box-shadow: 0 1px 0 rgba(0,0,0,.1);
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 14px;
}
.loading__spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin-right: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
}
.empty-state__icon { font-size: 48px; margin-bottom: 12px; }
.empty-state__title { font-size: 18px; color: var(--text); font-weight: 600; margin-bottom: 6px; }
