/* ============================================================================
   Қазіргі қазақ тілі — стильдер
   1. Tokens
   2. Reset
   3. Layout (header, sidebar, main)
   4. Typography
   5. Components (nav, chapter, accordion, tests, progress-popup, drawer)
   6. Icons (iconify)
   7. Static pages (author/glossary/references/answers)
   8. Responsive (<768px)
============================================================================ */

/* 1. TOKENS ---------------------------------------------------------------- */
:root {
  /* Палитра */
  --color-accent: #0e7490;
  --color-accent-hover: #0c5e74;
  --color-accent-soft: #e0f2f7;
  --color-accent-text: #075a73;

  --color-text: #1f2937;
  --color-text-muted: #475569;
  --color-text-dim: #94a3b8;
  --color-text-invert: #f8fafc;

  --color-bg: #f8fafc;
  --color-bg-elevated: #ffffff;
  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e1;

  --color-success: #16a34a;
  --color-success-soft: #dcfce7;
  --color-error: #dc2626;
  --color-error-soft: #fee2e2;

  /* Радиусы */
  --r-sm: 4px;
  --r: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  /* Тени */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 4px 12px rgba(15, 23, 42, .08);
  --shadow-lg: 0 16px 48px rgba(15, 23, 42, .12);

  /* Размеры */
  --sidebar-w: 320px;
  --header-h: 64px;
  --content-max: 760px;
  --container-max: 1280px;

  /* Шрифт */
  --font-sans: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* 2. RESET ----------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-weight: 400;
  line-height: 1.65;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 .5em;
  font-weight: 600;
  line-height: 1.25;
  color: var(--color-text);
}

p, ul, ol { margin: 0 0 1em; }
ul, ol { padding-left: 1.5em; }
li { margin-bottom: .3em; }
li > ul, li > ol { margin-top: .3em; margin-bottom: .3em; }

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

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

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

em { font-style: italic; }
strong { font-weight: 600; }

/* 3. LAYOUT ---------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  background: var(--color-bg-elevated);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex: 1;
  min-width: 0;
}
.brand a { color: inherit; text-decoration: none; }
.brand iconify-icon {
  font-size: 1.75rem;
  color: var(--color-accent);
  flex-shrink: 0;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  min-width: 0;
}
.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-subtitle {
  font-size: .8rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-action {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem .85rem;
  background: var(--color-accent-soft);
  color: var(--color-accent-text);
  border-radius: var(--r);
  font-weight: 600;
  font-size: .9rem;
  transition: background .15s ease;
}
.header-action:hover { background: #c8e7ef; }
.header-action iconify-icon { font-size: 1rem; }

.mobile-menu-toggle {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: var(--r);
  color: var(--color-text);
}
.mobile-menu-toggle:hover { background: var(--color-bg); }
.mobile-menu-toggle iconify-icon { font-size: 1.5rem; }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--header-h));
}

.sidebar {
  background: var(--color-bg-elevated);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  padding: 1.25rem 0;
}

.main {
  min-width: 0;
  padding: 2rem 2.5rem 4rem;
}

.content {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* 4. TYPOGRAPHY ------------------------------------------------------------ */
.content h1 { font-size: 1.875rem; margin-bottom: .75rem; }
.content h2 { font-size: 1.375rem; margin-top: 2rem; }
.content h3 { font-size: 1.125rem; margin-top: 1.5rem; }
.content p { color: var(--color-text); }
.content em { color: var(--color-text); font-style: italic; }

.content ul li::marker { color: var(--color-accent); }
.content ol li::marker { color: var(--color-accent); font-weight: 600; }

/* 5. COMPONENTS ----------------------------------------------------------- */

/* --- Sidebar nav --- */
.nav-section {
  margin-bottom: .25rem;
}
.nav-section-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  padding: .65rem 1.25rem;
  font-weight: 700;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--color-text-muted);
  border-radius: 0;
  text-align: left;
  transition: color .15s ease;
}
.nav-section-header:hover { color: var(--color-text); }
.nav-section-header iconify-icon {
  font-size: 1rem;
  transition: transform .2s ease;
}
.nav-section.open .nav-section-header iconify-icon { transform: rotate(90deg); }

.nav-section-items {
  list-style: none;
  padding: 0;
  margin: 0;
  display: none;
}
.nav-section.open .nav-section-items { display: block; }

.nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem 1.25rem .55rem 2.5rem;
  color: var(--color-text);
  text-decoration: none;
  font-size: .92rem;
  position: relative;
  transition: background .12s ease, color .12s ease;
}
.nav-link:hover {
  background: var(--color-bg);
  text-decoration: none;
  color: var(--color-text);
}
.nav-link.active {
  background: var(--color-accent-soft);
  color: var(--color-accent-text);
  font-weight: 600;
}
.nav-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--color-accent);
}
.nav-link iconify-icon {
  font-size: 1.05rem;
  color: var(--color-accent);
  flex-shrink: 0;
}
.nav-link .nav-link-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-link .nav-check {
  font-size: 1rem;
  color: var(--color-success);
  flex-shrink: 0;
}

/* Top-level links (preface, author, glossary, refs, answers) */
.nav-top-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .65rem 1.25rem;
  color: var(--color-text);
  text-decoration: none;
  font-weight: 600;
  font-size: .95rem;
  transition: background .12s ease;
}
.nav-top-link:hover { background: var(--color-bg); text-decoration: none; }
.nav-top-link.active {
  background: var(--color-accent-soft);
  color: var(--color-accent-text);
}
.nav-top-link iconify-icon {
  font-size: 1.2rem;
  color: var(--color-accent);
  flex-shrink: 0;
}

.nav-divider {
  margin: .75rem 1.25rem;
  border: none;
  border-top: 1px solid var(--color-border);
}

/* --- Chapter --- */
.chapter-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--color-border);
}
.chapter-header iconify-icon {
  font-size: 2.5rem;
  color: var(--color-accent);
  flex-shrink: 0;
  padding-top: .15rem;
}
.chapter-header-text { flex: 1; min-width: 0; }
.chapter-eyebrow {
  display: inline-block;
  font-size: .8rem;
  color: var(--color-accent-text);
  background: var(--color-accent-soft);
  padding: .15rem .55rem;
  border-radius: var(--r-sm);
  font-weight: 600;
  margin-bottom: .5rem;
}
.chapter-title { font-size: 1.75rem; margin: 0; }

.chapter-plan {
  background: var(--color-accent-soft);
  border-left: 3px solid var(--color-accent);
  padding: 1rem 1.25rem 1rem 1rem;
  border-radius: var(--r);
  margin-bottom: 1.75rem;
}
.chapter-plan h2 {
  margin: 0 0 .5rem;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--color-accent-text);
}
.chapter-plan ol {
  margin: 0;
  padding-left: 1.3em;
  color: var(--color-text);
}
.chapter-plan li { margin-bottom: .25rem; }

.chapter-body { color: var(--color-text); }
.chapter-body p { margin-bottom: 1em; }

.chapter-section-title {
  font-size: 1.25rem;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  padding-top: .25rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: .55rem;
}
.chapter-section-title iconify-icon {
  font-size: 1.4rem;
  color: var(--color-accent);
}

.self-check { margin-top: 2rem; }
.self-check ol { padding-left: 1.4em; }
.self-check li { margin-bottom: .55rem; color: var(--color-text); }

/* --- Mark as studied / nav buttons --- */
.chapter-footer {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
  align-items: center;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .55rem 1.1rem;
  border-radius: var(--r);
  font-weight: 600;
  font-size: .95rem;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
  border: 1px solid transparent;
  text-decoration: none;
}
.btn iconify-icon { font-size: 1.05rem; }
.btn-primary {
  background: var(--color-accent);
  color: white;
}
.btn-primary:hover { background: var(--color-accent-hover); color: white; text-decoration: none; }
.btn-secondary {
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg); color: var(--color-text); text-decoration: none; }
.btn-studied {
  background: var(--color-success-soft);
  color: var(--color-success);
  border-color: #86efac;
}
.btn-studied:hover { background: #bbf7d0; color: var(--color-success); text-decoration: none; }

.spacer { flex: 1; }

/* --- Accordion (practicals) --- */
.practicals-section { margin-top: 2.5rem; }
.accordion {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--r);
  margin-bottom: .75rem;
  overflow: hidden;
}
.accordion-header {
  display: flex;
  align-items: center;
  gap: .65rem;
  width: 100%;
  padding: .85rem 1rem;
  font-weight: 600;
  font-size: 1rem;
  text-align: left;
  color: var(--color-text);
  background: var(--color-bg-elevated);
  transition: background .15s ease;
}
.accordion-header:hover { background: var(--color-bg); }
.accordion-header iconify-icon {
  font-size: 1.15rem;
  color: var(--color-accent);
}
.accordion-header .accordion-chevron {
  margin-left: auto;
  transition: transform .2s ease;
  color: var(--color-text-muted);
}
.accordion.open .accordion-header .accordion-chevron { transform: rotate(180deg); }
.accordion-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-accent-soft);
  color: var(--color-accent-text);
  font-size: .85rem;
  font-weight: 700;
  padding: 0 .35rem;
}
.accordion-body {
  display: none;
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid var(--color-border);
}
.accordion.open .accordion-body { display: block; }
.practical-block { margin-bottom: 1.25rem; }
.practical-block:last-child { margin-bottom: 0; }
.practical-label {
  display: block;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
  margin-bottom: .35rem;
  font-weight: 600;
}

/* --- Tests --- */
.tests-section {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 2px solid var(--color-border);
}
.tests-intro {
  display: flex;
  align-items: center;
  gap: .85rem;
  background: var(--color-accent-soft);
  border-radius: var(--r-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}
.tests-intro iconify-icon {
  font-size: 2rem;
  color: var(--color-accent);
  flex-shrink: 0;
}
.tests-intro h2 {
  margin: 0 0 .25rem;
  font-size: 1.1rem;
  color: var(--color-accent-text);
}
.tests-intro p {
  margin: 0;
  color: var(--color-text-muted);
  font-size: .92rem;
}
.tests-intro-buttons {
  margin-left: auto;
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

.test-list { display: none; }
.test-list.open { display: block; }

.test-question {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--r-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}
.test-question-header {
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  margin-bottom: .85rem;
}
.test-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-accent-soft);
  color: var(--color-accent-text);
  font-weight: 700;
  font-size: .9rem;
  flex-shrink: 0;
}
.test-question-text {
  font-weight: 600;
  font-size: 1.02rem;
  line-height: 1.45;
  padding-top: .15rem;
}
.test-options { list-style: none; padding: 0; margin: 0 0 1rem; }
.test-option {
  margin-bottom: .4rem;
}
.test-option label {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  padding: .55rem .75rem;
  border-radius: var(--r);
  cursor: pointer;
  transition: background .15s ease;
  border: 1px solid transparent;
  line-height: 1.45;
}
.test-option label:hover { background: var(--color-bg); }
.test-option input[type="radio"] {
  margin-top: .25rem;
  accent-color: var(--color-accent);
  flex-shrink: 0;
}
.test-option .option-label {
  font-weight: 600;
  color: var(--color-text-muted);
  margin-right: .25rem;
}

.test-question.checked .test-option label { cursor: default; }
.test-question.checked .test-option input { pointer-events: none; }
.test-question.checked .test-option.correct label {
  background: var(--color-success-soft);
  border-color: #86efac;
}
.test-question.checked .test-option.wrong label {
  background: var(--color-error-soft);
  border-color: #fecaca;
}
.test-option .option-mark {
  margin-left: auto;
  font-weight: 600;
  flex-shrink: 0;
  display: none;
}
.test-question.checked .test-option.correct .option-mark {
  display: inline;
  color: var(--color-success);
}
.test-question.checked .test-option.wrong .option-mark {
  display: inline;
  color: var(--color-error);
}

.test-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.test-result {
  display: none;
  font-weight: 600;
  font-size: .92rem;
  padding: .35rem .75rem;
  border-radius: var(--r);
  align-self: center;
}
.test-question.checked .test-result { display: inline-flex; align-items: center; gap: .35rem; }
.test-result.correct { background: var(--color-success-soft); color: var(--color-success); }
.test-result.wrong { background: var(--color-error-soft); color: var(--color-error); }

/* --- Progress popup --- */
.progress-popup {
  position: fixed;
  top: calc(var(--header-h) + 4px);
  right: 1.5rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.25rem 1.5rem;
  min-width: 280px;
  z-index: 60;
}
.progress-popup[hidden] { display: none; }
.progress-popup h3 {
  margin: 0 0 .85rem;
  font-size: 1rem;
  color: var(--color-text);
}
.progress-bar {
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: .25rem;
}
.progress-bar-fill {
  height: 100%;
  background: var(--color-accent);
  transition: width .3s ease;
}
.progress-summary {
  font-size: .9rem;
  color: var(--color-text-muted);
  margin-bottom: 1rem;
}
.progress-summary strong { color: var(--color-text); }
.progress-parts {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}
.progress-parts li {
  display: flex;
  justify-content: space-between;
  padding: .35rem 0;
  font-size: .9rem;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}
.progress-parts li:last-child { border-bottom: none; }
.progress-parts .part-count { color: var(--color-text-muted); font-weight: 600; }

.btn-reset {
  width: 100%;
  padding: .5rem;
  background: var(--color-error-soft);
  color: var(--color-error);
  border-radius: var(--r);
  font-weight: 600;
  font-size: .88rem;
  transition: background .15s ease;
}
.btn-reset:hover { background: #fecaca; }

/* 6. ICONS ---------------------------------------------------------------- */
iconify-icon {
  display: inline-flex;
  align-items: center;
  vertical-align: -.1em;
}

/* 7. STATIC PAGES --------------------------------------------------------- */
.static-page {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}
.static-page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--color-border);
}
.static-page-header iconify-icon {
  font-size: 2.5rem;
  color: var(--color-accent);
}
.static-page-header h1 { font-size: 1.75rem; margin: 0; }

.static-page .back-link {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  margin-bottom: 1.5rem;
  color: var(--color-text-muted);
  font-size: .92rem;
  font-weight: 500;
}
.static-page .back-link:hover { color: var(--color-accent); text-decoration: none; }

/* author */
.author-page-header {
  gap: 1.5rem;
  align-items: flex-start;
}
.author-photo {
  width: 160px;
  height: 200px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  border: 3px solid var(--color-bg-elevated);
  background: var(--color-accent-soft);
}
.author-page-header h1 { font-size: 1.6rem; margin: 0 0 .35rem; }
.author-titles {
  font-size: 1rem;
  color: var(--color-text-muted);
  font-weight: 500;
  margin-top: .35rem;
  line-height: 1.5;
}
.author-bio p { margin-bottom: 1.2em; line-height: 1.75; }
.awards-list {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0 0;
}
.awards-list li {
  position: relative;
  padding: .65rem 1rem .65rem 2.5rem;
  margin-bottom: .5rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--r);
  font-size: .95rem;
}
.awards-list li::before {
  content: "";
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-accent);
}

/* glossary */
.glossary-letter {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-accent);
  margin-top: 1.5rem;
  margin-bottom: .5rem;
  padding-bottom: .25rem;
  border-bottom: 2px solid var(--color-accent-soft);
}
.glossary-list { list-style: none; padding: 0; margin: 0; }
.glossary-list li {
  padding: .65rem 0;
  border-bottom: 1px solid var(--color-border);
  line-height: 1.6;
}
.glossary-list li:last-child { border-bottom: none; }
.glossary-term {
  font-weight: 600;
  color: var(--color-text);
}

/* references */
.references-list {
  counter-reset: refs;
  list-style: none;
  padding: 0;
  margin: 0;
}
.references-list li {
  counter-increment: refs;
  padding: .75rem 0 .75rem 2.5rem;
  position: relative;
  line-height: 1.6;
  border-bottom: 1px solid var(--color-border);
}
.references-list li:last-child { border-bottom: none; }
.references-list li::before {
  content: counter(refs) ".";
  position: absolute;
  left: .25rem;
  top: .75rem;
  font-weight: 700;
  color: var(--color-accent);
  font-size: .95rem;
  min-width: 1.75rem;
  text-align: right;
}

/* answers */
.answers-intro {
  background: var(--color-accent-soft);
  border-radius: var(--r);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  color: var(--color-text-muted);
  font-size: .95rem;
}
.answers-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-bg-elevated);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.answers-table thead {
  background: var(--color-accent-soft);
}
.answers-table th {
  text-align: left;
  padding: .85rem 1rem;
  font-weight: 600;
  color: var(--color-accent-text);
  font-size: .9rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.answers-table td {
  padding: .85rem 1rem;
  border-top: 1px solid var(--color-border);
  vertical-align: top;
  line-height: 1.5;
}
.answers-table .col-num { width: 56px; font-weight: 700; color: var(--color-text-muted); }
.answers-table .col-answer { color: var(--color-success); font-weight: 500; }
.answers-table .col-answer .answer-label {
  font-weight: 700;
  color: var(--color-accent-text);
  margin-right: .35rem;
}

/* Loading / error / empty states */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
  font-size: .95rem;
}
.loading iconify-icon { font-size: 1.25rem; }

.error-box {
  background: var(--color-error-soft);
  border: 1px solid #fecaca;
  border-radius: var(--r);
  padding: 1rem 1.25rem;
  color: var(--color-error);
  margin: 1rem 0;
}
.error-box .error-hint {
  display: block;
  margin-top: .5rem;
  font-size: .9rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

/* 8. RESPONSIVE ----------------------------------------------------------- */
@media (max-width: 1024px) {
  .main { padding: 1.5rem 1.5rem 3rem; }
  :root { --sidebar-w: 280px; }
}

@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    width: min(320px, 85vw);
    height: calc(100vh - var(--header-h));
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 40;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, .4);
    z-index: 35;
  }
  .sidebar-backdrop.open { display: block; }

  .mobile-menu-toggle { display: inline-flex; }

  .site-header { padding: 0 1rem; gap: .5rem; }
  .brand-title { font-size: .95rem; }
  .brand-subtitle { display: none; }

  .main { padding: 1.25rem 1rem 3rem; }
  .chapter-title { font-size: 1.4rem; }
  .chapter-header iconify-icon { font-size: 1.75rem; }

  .progress-popup {
    right: .5rem;
    left: .5rem;
    min-width: 0;
  }

  .tests-intro {
    flex-wrap: wrap;
  }
  .tests-intro-buttons { margin-left: 0; width: 100%; }

  .static-page { padding: 1.5rem 1rem 3rem; }
  .static-page-header h1 { font-size: 1.4rem; }

  .author-page-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1rem;
  }
  .author-photo {
    width: 140px;
    height: 175px;
  }

  .answers-table { font-size: .9rem; }
  .answers-table th, .answers-table td { padding: .65rem .55rem; }
}

@media (max-width: 480px) {
  .chapter-header { flex-direction: column; gap: .5rem; }
  .chapter-header iconify-icon { font-size: 1.5rem; }
  .header-action span:not([data-keep]) { display: none; }
}

/* Utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.fade-in { animation: fadeIn .25s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Tables ── */
.chapter-body table,
.chapter-body .content-table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.25em 0;
  font-size: 0.95em;
  overflow-x: auto;
  display: block;
}
.chapter-body table th,
.chapter-body .content-table th {
  background-color: var(--clr-primary-50, #f0f9ff);
  color: var(--clr-primary-900, #0c4a6e);
  border: 1px solid var(--clr-border, #e2e8f0);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
}
.chapter-body table td,
.chapter-body .content-table td {
  border: 1px solid var(--clr-border, #e2e8f0);
  padding: 10px 14px;
  vertical-align: top;
  line-height: 1.5;
}
.chapter-body table tr:nth-child(even),
.chapter-body .content-table tr:nth-child(even) {
  background-color: var(--clr-surface-alt, #f8fafc);
}
