:root {
  --bg: #fbf7ef;
  --surface: #fffdf8;
  --surface-2: #f6efe1;
  --text: #231f1a;
  --muted: #766f66;
  --border: #e8ded0;
  --primary: #2d2924;
  --accent: #c2410c;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
  --radius: 8px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(35, 31, 26, 0.04);
  --shadow-md: 0 4px 16px rgba(35, 31, 26, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

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

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

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  width: 38px; height: 38px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  display: grid; place-items: center;
  border-radius: var(--radius);
  letter-spacing: 0.5px;
  font-size: 14px;
}

.brand-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 600;
}

.brand-title { font-size: 17px; font-weight: 700; color: var(--text); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.lang-switcher {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.lang-btn {
  padding: 6px 11px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: transparent;
  transition: all 160ms ease;
  min-width: 36px;
}

.lang-btn:hover { color: var(--text); }

.lang-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(35, 31, 26, 0.18);
}

.topbar-progress { min-width: 220px; }

.progress-label {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.progress-bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #d97706);
  width: 0%;
  transition: width 320ms ease;
}

/* ---- Layout ---- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  align-items: start;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  gap: 24px;
}

/* ---- Sidebar ---- */
.sidebar {
  position: sticky;
  top: 88px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.sidebar-section + .sidebar-section { border-top: 1px solid var(--border); padding-top: 16px; }

.sidebar-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 10px;
}

.overview-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  transition: background 160ms ease;
}

.overview-btn:hover { background: #efe5d2; }

.overview-icon { font-size: 16px; color: var(--accent); }

.lesson-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }

.lesson-btn {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border-radius: var(--radius);
  font-size: 13.5px;
  text-align: left;
  color: var(--text);
  transition: background 160ms ease;
}

.lesson-btn:hover { background: var(--surface-2); }
.lesson-btn.active { background: var(--primary); color: #fff; }
.lesson-btn.active .lesson-num { background: rgba(255,255,255,0.18); color: #fff; }
.lesson-btn.completed .lesson-num { background: var(--success); color: #fff; }

.lesson-num {
  width: 24px; height: 24px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  display: grid; place-items: center;
}

.lesson-btn-title { line-height: 1.3; }

.lesson-check {
  font-size: 13px;
  color: var(--success);
  opacity: 0;
}

.lesson-btn.completed .lesson-check { opacity: 1; }
.lesson-btn.active.completed .lesson-check { color: #86efac; }

.sidebar-hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.sidebar-hint a { color: var(--accent); font-weight: 600; }

/* ---- Reader ---- */
.reader {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  box-shadow: var(--shadow-sm);
}

/* ---- Overview ---- */
.overview-hero {
  background: linear-gradient(135deg, #2d2924 0%, #3a3530 100%);
  color: #fff;
  border: none;
  padding: 36px 36px 32px;
}

.overview-eyebrow {
  font-size: 11px; letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  color: #fcd9b6;
  margin-bottom: 12px;
}

.overview-title {
  font-size: 28px;
  line-height: 1.18;
  font-weight: 800;
  margin-bottom: 12px;
  max-width: 720px;
}

.overview-desc {
  font-size: 14.5px;
  color: #e7dfd1;
  max-width: 720px;
  margin-bottom: 20px;
}

.overview-stats {
  display: flex;
  gap: 28px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-item .stat-num { font-size: 22px; font-weight: 800; }
.stat-item .stat-label { font-size: 12px; color: #cdc4b4; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }

.cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: var(--radius);
  font-size: 14px;
  transition: transform 120ms ease, background 160ms ease;
}

.cta-btn:hover { background: #a8350a; transform: translateY(-1px); }
.cta-btn.secondary { background: var(--surface-2); color: var(--text); }
.cta-btn.secondary:hover { background: #efe5d2; }

.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.overview-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 160ms ease, transform 120ms ease, box-shadow 160ms ease;
  text-align: left;
}

.overview-card:hover {
  border-color: #d4c7b0;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.overview-card .oc-num {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 8px;
}

.overview-card .oc-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
  line-height: 1.3;
}

.overview-card .oc-goal {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

/* ---- Lesson hero ---- */
.lesson-intro { padding-top: 18px; }

.lesson-hero {
  position: relative;
  margin: -24px -28px 20px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
  background: var(--surface-2);
  aspect-ratio: 16 / 9;
  max-height: 360px;
}

.lesson-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.lesson-hero.hero-missing {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 5;
  background: linear-gradient(135deg, var(--surface-2), #efe5d2);
}

.lesson-hero.hero-missing::before {
  content: "Изображение загружается…";
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}


/* ---- Overview thumbnails ---- */
.overview-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.oc-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--surface-2);
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

.oc-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 320ms ease;
}

.overview-card:hover .oc-thumb img { transform: scale(1.04); }

.oc-thumb-missing {
  background: linear-gradient(135deg, var(--surface-2), #efe5d2);
  display: flex; align-items: center; justify-content: center;
}

.oc-thumb-missing::after {
  content: "—";
  color: var(--muted);
  font-size: 24px;
}

.oc-body { padding: 14px 16px 16px; }

/* ---- Lesson reader ---- */
.lesson-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.lesson-eyebrow {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--accent);
}

.lesson-title { font-size: 24px; line-height: 1.2; font-weight: 800; }

.lesson-goal {
  font-size: 14.5px;
  color: var(--muted);
  margin-bottom: 20px;
  padding-left: 14px;
  border-left: 3px solid var(--accent);
}

.section-title {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 14px;
}

/* Objectives */
.objectives-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.objectives-list li {
  display: flex;
  gap: 12px;
  font-size: 14px;
  line-height: 1.55;
}

.objectives-list li::before {
  content: "";
  flex-shrink: 0;
  width: 8px; height: 8px;
  border-radius: 2px;
  background: var(--accent);
  margin-top: 8px;
}

/* Content sections */
.content-section { margin-bottom: 18px; }
.content-section:last-child { margin-bottom: 0; }

.content-section h3 {
  font-size: 15.5px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.content-section p { font-size: 14px; color: #3a342d; line-height: 1.65; }

.content-section ul {
  margin-top: 6px;
  padding-left: 18px;
  font-size: 14px;
  color: #3a342d;
}

.content-section ul li { margin-bottom: 4px; }

/* Route map */
.route-map {
  background: linear-gradient(180deg, #fffdf8 0%, #f7eedb 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
}

.route-map svg { width: 100%; max-width: 560px; height: auto; display: block; margin: 0 auto; }

.route-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--muted);
  justify-content: center;
}

.legend-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

/* Route table */
.route-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13.5px;
}

.route-table th, .route-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.route-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 700;
  background: var(--surface-2);
}

.route-table tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}

.badge.primary { background: #fef3c7; color: #92400e; }
.badge.success { background: #dcfce7; color: var(--success); }
.badge.warn { background: #fed7aa; color: var(--accent); }
.badge.danger { background: #fee2e2; color: var(--danger); }

/* Flashcards */
.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.flashcard {
  perspective: 1200px;
  height: 160px;
  cursor: pointer;
}

.flashcard-inner {
  position: relative;
  width: 100%; height: 100%;
  transition: transform 500ms cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.flashcard-face {
  position: absolute;
  width: 100%; height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13.5px;
}

.flashcard-face.back {
  transform: rotateY(180deg);
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.flashcard-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-weight: 700;
}

.flashcard-face.back .flashcard-label { color: #fcd9b6; }

.flashcard-text { font-weight: 500; line-height: 1.45; }
.flashcard-face.back .flashcard-text { color: #fff; }

.flashcard-hint {
  font-size: 10.5px;
  color: var(--muted);
  text-align: right;
}

.flashcard-face.back .flashcard-hint { color: #cdc4b4; }

/* Quiz */
.quiz-item { margin-bottom: 18px; }
.quiz-item:last-child { margin-bottom: 0; }

.quiz-question {
  font-size: 14.5px;
  font-weight: 600;
  margin-bottom: 10px;
}

.quiz-options { display: flex; flex-direction: column; gap: 8px; }

.quiz-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--text);
  transition: all 160ms ease;
}

.quiz-option:hover:not(:disabled) {
  border-color: #c2b59a;
  background: var(--surface-2);
}

.quiz-option .opt-mark {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  display: grid; place-items: center;
  flex-shrink: 0;
}

.quiz-option.selected { border-color: var(--primary); background: var(--surface-2); }

.quiz-option.correct {
  border-color: var(--success);
  background: #f0fdf4;
}

.quiz-option.correct .opt-mark {
  background: var(--success);
  color: #fff;
}

.quiz-option.wrong {
  border-color: var(--danger);
  background: #fef2f2;
}

.quiz-option.wrong .opt-mark {
  background: var(--danger);
  color: #fff;
}

.quiz-option:disabled { cursor: default; }

.quiz-feedback {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  display: none;
}

.quiz-feedback.show { display: block; }

.quiz-feedback.correct {
  background: #f0fdf4;
  color: var(--success);
  border-left: 3px solid var(--success);
}

.quiz-feedback.wrong {
  background: #fef2f2;
  color: var(--danger);
  border-left: 3px solid var(--danger);
}

/* Sources */
.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.source-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: border-color 160ms ease, transform 120ms ease;
}

.source-card:hover {
  text-decoration: none;
  border-color: #c2b59a;
  transform: translateY(-1px);
}

.source-card .src-icon {
  font-size: 15px;
  color: var(--accent);
  flex-shrink: 0;
}

.source-card .src-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.source-card .src-label {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-card .src-url {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Nav */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.lesson-nav .complete-area { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.nav-btn {
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  transition: all 160ms ease;
}

.nav-btn:hover { border-color: #c2b59a; background: var(--surface-2); }
.nav-btn:disabled { opacity: 0.35; cursor: default; }
.nav-btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.nav-btn.primary:hover { background: #1a1715; }
.nav-btn.done { background: var(--success); color: #fff; border-color: var(--success); }

/* Final review */
.final-review-card {
  background: linear-gradient(135deg, #fffdf8 0%, #f7eedb 100%);
  border: 1px solid #d4c7b0;
}

.callout {
  background: #fff8eb;
  border-left: 3px solid var(--warning);
  padding: 12px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 13.5px;
  color: #5a4a2d;
  margin: 12px 0;
}

.callout.danger {
  background: #fef2f2;
  border-left-color: var(--danger);
  color: #7f1d1d;
}

.callout strong { font-weight: 700; }

.footer {
  padding: 16px 28px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* Responsive */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .sidebar { position: static; max-height: none; }
  .topbar { padding: 12px 16px; gap: 12px; }
  .brand-title { font-size: 15px; }
  .topbar-progress { display: none; }
  .topbar-right { gap: 8px; }
  .lang-btn { padding: 5px 8px; min-width: 30px; font-size: 11px; }
  .card { padding: 18px 20px; }
  .overview-hero { padding: 24px 22px; }
  .overview-title { font-size: 22px; }
  .lesson-hero { margin: -18px -20px 16px; }
}
