/* ============================================================
   Machine Learning A to Z — components.css
   Chapter layout + reusable content components:
   nav, header, objectives, stability badges, callouts, code,
   formulas, figures, tables, hands-on projects, solutions,
   takeaways, quiz.
   ============================================================ */

/* ---------- 1. Chapter layout ---------- */

.chapter-container {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 24px 60px;
}

.section-anchor {
  scroll-margin-top: 84px;
}

/* ---------- 2. Chapter nav (top & bottom) ---------- */

.chapter-nav-top,
.chapter-nav-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
}

.chapter-nav-top {
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.chapter-nav-bottom {
  border-top: 1px solid var(--border);
  margin-top: 56px;
}

.chapter-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  background: var(--surface);
  max-width: 42%;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.chapter-nav-link:hover {
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
}

.chapter-nav-link .nav-dir {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-light);
}

.chapter-nav-link.next {
  margin-left: auto;
  text-align: right;
}

.chapter-nav-link.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.chapter-nav-home {
  color: var(--text-light);
  font-size: 0.88rem;
  font-weight: 500;
  padding: 6px 12px;
}

.chapter-nav-home:hover {
  color: var(--primary);
}

/* ---------- 3. Chapter header ---------- */

.chapter-header {
  background: var(--hero-grad);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 38px 36px 34px;
  margin: 20px 0 36px;
  box-shadow: var(--shadow-sm);
}

.chapter-part-label {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 10px;
}

.chapter-header h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 800;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}

.chapter-summary {
  color: var(--text-light);
  font-size: 1rem;
  max-width: 65ch;
  margin-bottom: 18px;
}

.chapter-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.meta-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-light);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
}

.meta-badge .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--text-light);
}

.meta-badge.stability-core .dot { background: var(--accent); }
.meta-badge.stability-stable .dot { background: var(--primary); }
.meta-badge.stability-volatile .dot { background: var(--warning); }

/* ---------- 4. Learning objectives ---------- */

.learning-objectives {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 22px 26px;
  margin-bottom: 40px;
}

.learning-objectives h2 {
  font-size: 1.05rem;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.learning-objectives ul {
  margin: 0;
  padding-left: 4px;
  list-style: none;
}

.learning-objectives li {
  position: relative;
  padding-left: 28px;
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.learning-objectives li:last-child {
  margin-bottom: 0;
}

.learning-objectives li::before {
  content: '✔';
  position: absolute;
  left: 2px;
  color: var(--accent);
  font-size: 0.85rem;
}

/* ---------- 5. Content sections ---------- */

.content-section {
  margin-bottom: 48px;
}

.content-section > h2 {
  font-size: 1.45rem;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.content-section h3 {
  font-size: 1.12rem;
  margin-top: 28px;
}

.content-section h4 {
  font-size: 1rem;
  color: var(--text);
  margin-top: 22px;
}

/* ---------- 6. Stability badges ---------- */

.stability-badge {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 4px 13px;
  margin-bottom: 16px;
  letter-spacing: 0.02em;
}

.stability-badge.stable-badge {
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--primary) 38%, transparent);
}

.stability-badge.volatile-badge {
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warning) 38%, transparent);
}

.stability-badge.review-due {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}

/* ---------- 7. Callouts ---------- */

.callout {
  display: flex;
  gap: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 16px 18px;
  margin: 22px 0;
  font-size: 0.94rem;
}

.callout-icon {
  font-size: 1.2rem;
  line-height: 1.6;
  flex-shrink: 0;
}

.callout-content p:last-child {
  margin-bottom: 0;
}

.callout-note {
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
  border-left: 4px solid var(--primary);
}

.callout-tip {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border-left: 4px solid var(--accent);
}

.callout-warning {
  background: color-mix(in srgb, var(--warning) 9%, var(--surface));
  border-left: 4px solid var(--warning);
}

.callout-realworld {
  background: color-mix(in srgb, var(--danger) 7%, var(--surface));
  border-left: 4px solid var(--danger);
}

/* ---------- 8. Code blocks ---------- */

pre[class*='language-'],
pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  overflow-x: auto;
  font-size: 0.87rem;
  line-height: 1.65;
  margin: 18px 0;
  tab-size: 4;
}

pre code {
  background: none;
  padding: 0;
  border: none;
  color: var(--text);
}

:not(pre) > code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-size: 0.85em;
  color: var(--accent-light);
}

/* Code block caption */
.code-caption {
  text-align: right;
  font-size: 0.78rem;
  color: var(--text-light);
  margin: -12px 0 18px;
}

/* Prism light-theme token overrides (base theme is prism-tomorrow/dark) */
html[data-theme='light'] .token.comment,
html[data-theme='light'] .token.prolog,
html[data-theme='light'] .token.doctype,
html[data-theme='light'] .token.cdata { color: #8a94a6; }

html[data-theme='light'] .token.punctuation { color: #546074; }

html[data-theme='light'] .token.property,
html[data-theme='light'] .token.tag,
html[data-theme='light'] .token.boolean,
html[data-theme='light'] .token.number,
html[data-theme='light'] .token.constant,
html[data-theme='light'] .token.symbol { color: #c2255c; }

html[data-theme='light'] .token.selector,
html[data-theme='light'] .token.attr-name,
html[data-theme='light'] .token.string,
html[data-theme='light'] .token.char,
html[data-theme='light'] .token.builtin,
html[data-theme='light'] .token.inserted { color: #0b7285; }

html[data-theme='light'] .token.operator,
html[data-theme='light'] .token.entity,
html[data-theme='light'] .token.url { color: #5f3dc4; }

html[data-theme='light'] .token.atrule,
html[data-theme='light'] .token.attr-value,
html[data-theme='light'] .token.keyword { color: #3b5bdb; }

html[data-theme='light'] .token.function,
html[data-theme='light'] .token.class-name { color: #7048e8; }

html[data-theme='light'] .token.regex,
html[data-theme='light'] .token.important,
html[data-theme='light'] .token.variable { color: #e8590c; }

/* ---------- 9. Formulas (display math without MathJax) ---------- */

.formula-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 24px;
  margin: 20px 0;
  text-align: center;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.12rem;
  overflow-x: auto;
}

.formula-block .var {
  font-style: italic;
}

.formula-block sub,
.formula-block sup {
  font-size: 0.68em;
}

.formula-where {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-top: 10px;
  font-family: inherit;
  text-align: left;
}

.formula-where ul {
  margin: 6px 0 0;
  padding-left: 20px;
}

/* ---------- 10. Figures ---------- */

.figure {
  margin: 24px 0;
  text-align: center;
}

.figure img {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  max-width: 100%;
}

.figure-caption {
  font-size: 0.82rem;
  color: var(--text-light);
  margin-top: 10px;
  font-style: italic;
}

/* ---------- 11. Tables inside chapters ---------- */

.table-wrap {
  margin: 22px 0;
}

.styled-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 480px;
}

.styled-table th {
  background: var(--surface-2);
  color: var(--text-light);
  text-align: left;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.styled-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

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

/* ---------- 12. Hands-on project ---------- */

.hands-on-project {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px 32px;
  margin: 52px 0;
}

.hands-on-project > h2 {
  font-size: 1.35rem;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.project-difficulty {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warning) 35%, transparent);
  border-radius: 999px;
  padding: 2px 10px;
  vertical-align: middle;
  margin-left: 8px;
}

.project-brief {
  border-left: 4px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin: 16px 0;
  font-size: 0.95rem;
}

.project-brief p:last-child {
  margin-bottom: 0;
}

.project-steps h3 {
  font-size: 1rem;
  margin-bottom: 10px;
}

.project-steps ol,
.project-steps ul {
  margin: 0 0 8px;
  padding-left: 24px;
}

.project-steps li {
  margin-bottom: 8px;
  font-size: 0.94rem;
}

/* ---------- 13. Solution toggle ---------- */

.solution-toggle {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  margin-top: 20px;
  background: var(--bg);
}

.solution-toggle summary {
  cursor: pointer;
  padding: 14px 18px;
  font-weight: 600;
  color: var(--primary);
  font-size: 0.95rem;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.solution-toggle summary::-webkit-details-marker {
  display: none;
}

.solution-toggle summary::before {
  content: '▸';
  font-size: 0.85rem;
  transition: transform 0.2s ease;
}

.solution-toggle[open] summary::before {
  transform: rotate(90deg);
}

.solution-toggle summary:hover {
  color: var(--primary-light);
}

.solution-content {
  padding: 4px 22px 20px;
  border-top: 1px dashed var(--border);
}

/* ---------- 14. Key takeaways ---------- */

.key-takeaways {
  margin: 52px 0;
}

.key-takeaways h2 {
  font-size: 1.35rem;
  margin-bottom: 18px;
}

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

.takeaway-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.2s ease;
}

.takeaway-card:hover {
  border-color: var(--accent);
}

.takeaway-number {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font-weight: 800;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.takeaway-card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text);
}

/* ---------- 15. Quiz ---------- */

.chapter-quiz {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px 32px;
  margin: 52px 0;
}

.chapter-quiz > h2 {
  font-size: 1.35rem;
  margin-bottom: 4px;
}

.quiz-instructions {
  color: var(--text-light);
  font-size: 0.88rem;
  margin-bottom: 22px;
}

.quiz-question {
  padding: 18px 0 14px;
  border-bottom: 1px solid var(--border);
}

.quiz-question:last-of-type {
  border-bottom: none;
}

.question-text {
  font-weight: 600;
  margin-bottom: 12px;
  font-size: 0.97rem;
}

.question-text .q-num {
  color: var(--primary);
  margin-right: 6px;
}

.quiz-options {
  display: grid;
  gap: 8px;
}

.quiz-option {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  transition: border-color 0.15s ease, background 0.15s ease;
  margin: 0;
}

.quiz-option:hover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 6%, transparent);
}

.quiz-option input[type='radio'] {
  accent-color: var(--primary);
  flex-shrink: 0;
}

.quiz-option.is-correct-option {
  border-color: var(--success);
  background: color-mix(in srgb, var(--success) 10%, transparent);
}

.quiz-option.was-selected {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
}

.quiz-option.was-selected.is-correct-option {
  border-color: var(--success);
  background: color-mix(in srgb, var(--success) 10%, transparent);
}

.quiz-feedback {
  margin-top: 10px;
  font-size: 0.86rem;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
}

.quiz-feedback.correct {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--success) 30%, transparent);
}

.quiz-feedback.incorrect {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
}

.quiz-submit-row {
  margin-top: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.quiz-submit-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 28px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.quiz-submit-btn:hover {
  background: var(--primary-light);
  transform: translateY(-1px);
}

.quiz-score {
  margin-top: 18px;
  padding: 16px 20px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
  font-size: 1rem;
}

.quiz-score strong {
  color: var(--primary);
  font-size: 1.15rem;
}

/* ---------- 16. In-chapter table of contents ---------- */

.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 24px;
  margin-bottom: 44px;
}

.toc h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-light);
  margin-bottom: 10px;
}

.toc ol {
  margin: 0;
  padding-left: 22px;
  columns: 2;
  column-gap: 36px;
}

.toc li {
  font-size: 0.9rem;
  margin-bottom: 6px;
  break-inside: avoid;
}

.toc a {
  color: var(--text);
}

.toc a:hover {
  color: var(--primary);
}

/* ---------- 17. Term definitions ---------- */

.term-def {
  font-weight: 700;
  color: var(--accent);
}

/* ---------- 18. Responsive ---------- */

@media (max-width: 640px) {
  .chapter-header {
    padding: 26px 22px;
  }

  .hands-on-project,
  .chapter-quiz {
    padding: 22px 18px;
  }

  .toc ol {
    columns: 1;
  }

  .chapter-nav-link {
    max-width: 46%;
    font-size: 0.82rem;
    padding: 8px 10px;
  }
}
