/* Shared Chapter-by-Chapter Study Guide Stylesheet (Warm Studio Paper)
 * Used across all 8 Subject Study Guides: Biology, Chemistry, Physics,
 * Math Fundamentals, Algebra, Geometry, Trigonometry, and English.
 * Mobile-first & FB/Messenger In-App Browser (360px-414px) safe.
 */
:root {
  --bg-paper: #FAF8F5;
  --bg-paper-2: #F1EDE6;
  --surface: #FFFFFF;
  --border: #E2DDD5;
  --border-strong: #D0C9BD;
  --ink: #0F172A;
  --ink-muted: #475569;
  --ink-soft: #64748B;
  --accent: #1D4ED8;
  --accent-soft: #EFF6FF;
  --accent-border: #BFDBFE;
  --emerald: #059669;
  --emerald-soft: #ECFDF5;
  --emerald-border: #A7F3D0;
  --amber: #B45309;
  --amber-soft: #FFFBEB;
  --amber-border: #FDE68A;
  --rose: #DC2626;
  --rose-soft: #FEF2F2;
  --rose-border: #FECACA;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.06);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  max-width: 100%;
  overflow-x: clip;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--bg-paper);
  background-image: radial-gradient(#E2DDD5 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--ink);
  line-height: 1.62;
  min-height: 100dvh;
  max-width: 100%;
  overflow-x: clip;
}

/* Top Header + 14-Subject Switcher */
.sg-topbar {
  position: relative;
  z-index: 40;
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
  background: rgba(250, 248, 245, 0.96);
  border-bottom: 1px solid var(--border);
}

.sg-topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sg-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.sg-brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--ink);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 800;
}

.sg-brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.sg-nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.sg-nav-link {
  text-decoration: none;
  color: var(--ink-muted);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 8px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.sg-nav-link:hover {
  background: var(--bg-paper-2);
  color: var(--ink);
}

.sg-nav-link.primary {
  background: var(--ink);
  color: #FFFFFF;
}

.sg-nav-link.primary:hover {
  background: #1E293B;
}

/* 10-Pill Subject Switcher (All Guides + 9 Subjects) */
.sg-subject-bar {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  border-top: 1px solid var(--border);
  background: #FFFFFF;
}

.sg-subject-bar-inner {
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  overflow: visible;
}

.sg-subj-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg-paper);
  color: var(--ink-muted);
  transition: all 0.15s;
}

@media (max-width: 768px) {
  .sg-topbar {
    position: static;
  }
  .sg-subject-bar-inner {
    justify-content: flex-start;
    padding: 8px 12px;
    gap: 5px;
  }
  .sg-subj-pill {
    padding: 4px 9px;
    font-size: 0.74rem;
  }
}

.sg-subj-pill:hover {
  border-color: var(--accent-border);
  color: var(--accent);
  background: var(--accent-soft);
}

.sg-subj-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}

.sg-subj-pill.soon {
  opacity: 0.65;
  cursor: default;
  pointer-events: none;
}

.sg-soon-tag {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--bg-paper-2);
  color: var(--ink-soft);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Main Container */
.sg-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 22px 16px 72px;
}

/* Hero Card */
.sg-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}

.sg-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--emerald);
  background: var(--emerald-soft);
  border: 1px solid var(--emerald-border);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.sg-hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.45rem, 3.8vw, 2.05rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.sg-hero-sub {
  margin: 0 0 18px;
  color: var(--ink-muted);
  font-size: 0.96rem;
  max-width: 740px;
}

/* Mastery Progress Strip */
.sg-progress-card {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sg-progress-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.sg-progress-label {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--ink);
}

.sg-progress-stats {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--emerald);
}

.sg-progress-track {
  width: 100%;
  height: 9px;
  background: var(--bg-paper-2);
  border-radius: 999px;
  overflow: hidden;
}

.sg-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #10B981, #059669);
  border-radius: 999px;
  transition: width 0.35s ease;
}

.sg-progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* Chapter Jump Directory */
.sg-toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-sm);
}

.sg-toc-title {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  margin: 0 0 12px;
}

.sg-toc-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

@media (max-width: 640px) {
  .sg-toc-grid { grid-template-columns: 1fr; }
}

.sg-toc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-paper);
  text-decoration: none;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.sg-toc-item:hover {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
}

.sg-toc-left {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.sg-toc-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  font-weight: 700;
  background: #FFFFFF;
  border: 1px solid var(--border);
  color: var(--ink-muted);
  padding: 2px 7px;
  border-radius: 6px;
  flex-shrink: 0;
}

.sg-toc-status {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-soft);
  white-space: nowrap;
}

.sg-toc-item.mastered {
  border-color: var(--emerald-border);
  background: var(--emerald-soft);
}

.sg-toc-item.mastered .sg-toc-status {
  color: var(--emerald);
}

/* Unit Divider */
.sg-unit-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 28px 0 14px;
}

.sg-unit-badge {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  padding: 4px 11px;
  border-radius: 999px;
  white-space: nowrap;
}

.sg-unit-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Chapter Article Card */
.sg-chapter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 22px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  scroll-margin-top: 106px;
}

.sg-chapter-head {
  padding: 18px 20px;
  background: linear-gradient(180deg, #FFFFFF 0%, #FCFBF9 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.sg-ch-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}

.sg-ch-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--ink);
  color: #FFFFFF;
  padding: 2px 8px;
  border-radius: 6px;
}

.sg-ch-meta {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.sg-chapter-head h2 {
  margin: 0;
  font-size: clamp(1.15rem, 2.8vw, 1.38rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.28;
}

.sg-mastery-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-paper);
  color: var(--ink-soft);
  white-space: nowrap;
}

.sg-mastery-pill.mastered {
  background: var(--emerald-soft);
  border-color: var(--emerald-border);
  color: var(--emerald);
}

/* Chapter Summary Content */
.sg-summary {
  padding: 18px 20px 16px;
}

.sg-lead {
  margin: 0 0 14px;
  color: var(--ink-muted);
  font-size: 0.95rem;
}

.sg-key-list {
  margin: 0 0 16px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.sg-key-list li {
  font-size: 0.93rem;
  color: var(--ink);
}

.sg-key-list strong {
  color: var(--ink);
}

/* Responsive Reference Table */
.sg-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 0 0 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  -webkit-overflow-scrolling: touch;
}

.sg-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  background: #FFFFFF;
}

.sg-table th {
  background: var(--bg-paper);
  color: var(--ink);
  font-weight: 700;
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.sg-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #F1EDE6;
  color: var(--ink-muted);
  vertical-align: top;
}

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

/* Mobile-first stacked cards for 3-4 column tables (zero horizontal clipping on phones & narrow panes <= 768px) */
@media (max-width: 768px) {
  .sg-table-wrap {
    overflow-x: visible;
    border: none;
    background: transparent;
  }
  .sg-table,
  .sg-table tbody,
  .sg-table tr,
  .sg-table td {
    display: block;
    width: 100%;
  }
  .sg-table thead {
    display: none;
  }
  .sg-table {
    background: transparent;
  }
  .sg-table tr {
    background: #FFFFFF;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 8px;
  }
  .sg-table tr:last-child {
    margin-bottom: 0;
  }
  .sg-table td {
    padding: 4px 0;
    border-bottom: none;
    white-space: normal;
    word-break: break-word;
    font-size: 0.87rem;
  }
  .sg-table td:first-child {
    font-size: 0.94rem;
    color: var(--ink);
    padding-bottom: 6px;
    margin-bottom: 4px;
    border-bottom: 1px solid #F1EDE6;
  }
  .sg-table td[data-label]:not(:first-child)::before {
    content: attr(data-label) ": ";
    font-weight: 700;
    color: var(--ink);
    font-size: 0.8rem;
  }
}

/* Exam Trap Callout */
.sg-trap {
  background: var(--amber-soft);
  border: 1px solid var(--amber-border);
  border-left: 4px solid #D97706;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 0.88rem;
  color: #78350F;
}

.sg-trap strong {
  color: #92400E;
}

/* Interactive 5-Question Chapter Check Section */
.sg-quiz-box {
  background: var(--bg-paper);
  border-top: 1px solid var(--border);
  padding: 18px 20px 20px;
}

.sg-quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.sg-quiz-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sg-quiz-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--ink);
}

.sg-pool-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: #FFFFFF;
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}

.sg-quiz-score {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  padding: 4px 10px;
  border-radius: 999px;
}

.sg-quiz-score.mastered {
  color: var(--emerald);
  background: var(--emerald-soft);
  border-color: var(--emerald-border);
}

.sg-q-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sg-q-card {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}

.sg-q-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.sg-q-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.sg-diff {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
}

.sg-diff.easy { background: #ECFDF5; color: #047857; }
.sg-diff.medium { background: #EFF6FF; color: #1D4ED8; }
.sg-diff.hard { background: #FEF3C7; color: #B45309; }

.sg-q-text {
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 12px;
  overflow-wrap: anywhere;
}

.sg-q-text svg,
.sg-q-text img {
  max-width: 100%;
  height: auto !important;
}

.sg-opts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

@media (max-width: 640px) {
  .sg-opts { grid-template-columns: 1fr; }
}

.sg-opt-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  text-align: left;
  font-family: inherit;
  font-size: 0.89rem;
  font-weight: 500;
  color: var(--ink);
  background: #F8FAFC;
  border: 1.5px solid #E2E8F0;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s, transform 0.08s;
  line-height: 1.4;
}

.sg-opt-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.sg-opt-btn:disabled { cursor: default; }

.sg-opt-letter {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.sg-opt-btn.correct {
  background: var(--emerald-soft);
  border-color: var(--emerald);
  color: #065F46;
  font-weight: 600;
}

.sg-opt-btn.correct .sg-opt-letter {
  background: var(--emerald);
  border-color: var(--emerald);
  color: #FFFFFF;
}

.sg-opt-btn.wrong {
  background: var(--rose-soft);
  border-color: var(--rose);
  color: #991B1B;
}

.sg-opt-btn.wrong .sg-opt-letter {
  background: var(--rose);
  border-color: var(--rose);
  color: #FFFFFF;
}

.sg-q-footer {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-top: 10px;
}

.sg-exp-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 5px 11px;
  border-radius: 8px;
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s;
}

.sg-exp-toggle:hover {
  background: #DBEAFE;
  border-color: var(--accent);
}

.sg-rationale {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--bg-paper);
  border-left: 3px solid var(--emerald);
  font-size: 0.86rem;
  color: var(--ink-muted);
  display: none;
}

.sg-rationale.show { display: block; }
.sg-rationale.wrong-pick { border-left-color: var(--rose); }

.sg-quiz-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.sg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 9px 16px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid var(--border-strong);
  background: #FFFFFF;
  color: var(--ink);
  transition: all 0.15s;
}

.sg-btn:hover {
  border-color: var(--ink);
  background: var(--bg-paper-2);
}

.sg-btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}

.sg-btn.accent:hover {
  background: #1E40AF;
}

.sg-loading {
  padding: 18px;
  text-align: center;
  font-size: 0.88rem;
  color: var(--ink-soft);
  background: #FFFFFF;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
}

/* KaTeX mobile responsiveness */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}

/* Footer */
/* Full-Chapter Dedicated Lesson Components (Option A: Khan Academy / Bitesize style) */
.sg-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 14px;
}

.sg-breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

.sg-breadcrumb a:hover { text-decoration: underline; }

.sg-objectives {
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 14px;
}

.sg-objectives-title {
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.sg-objectives ul {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.89rem;
  color: var(--ink);
}

.sg-lesson-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.sg-lesson-card h2 {
  margin: 0 0 10px;
  font-size: clamp(1.15rem, 2.8vw, 1.38rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.sg-lesson-card h3 {
  margin: 18px 0 8px;
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ink);
}

.sg-lesson-card p {
  margin: 0 0 12px;
  font-size: 0.95rem;
  color: var(--ink-muted);
}

.sg-lesson-card p:last-child { margin-bottom: 0; }

.sg-callout {
  background: var(--emerald-soft);
  border: 1px solid var(--emerald-border);
  border-left: 4px solid var(--emerald);
  border-radius: 10px;
  padding: 12px 15px;
  margin: 14px 0;
  font-size: 0.9rem;
  color: #065F46;
}

.sg-callout strong { color: #064E3B; }

.sg-diagram-box {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin: 16px 0;
  text-align: center;
}

.sg-diagram-box svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

.sg-diagram-cap {
  margin: 10px 0 0;
  font-size: 0.81rem;
  color: var(--ink-soft);
  text-align: center;
}

.sg-concept-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

@media (max-width: 680px) {
  .sg-concept-grid { grid-template-columns: 1fr; }
}

.sg-concept-tile {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
}

.sg-concept-tile h4 {
  margin: 0 0 6px;
  font-size: 0.93rem;
  font-weight: 800;
  color: var(--ink);
}

.sg-concept-tile p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--ink-muted);
  line-height: 1.55;
}

.sg-worked {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px 17px;
  margin: 14px 0;
}

.sg-worked-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--ink);
  color: #FFFFFF;
  padding: 2px 8px;
  border-radius: 6px;
  margin-bottom: 8px;
}

.sg-worked-q {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 10px;
}

.sg-worked-steps {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.89rem;
  color: var(--ink-muted);
}

.sg-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.sg-syllabus-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sg-syllabus-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-decoration: none;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
}

.sg-syllabus-card:hover:not(.locked) {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.sg-syllabus-card.locked {
  opacity: 0.72;
  cursor: default;
}

.sg-syllabus-body h3 {
  margin: 4px 0 5px;
  font-size: 1.03rem;
  font-weight: 800;
  color: var(--ink);
}

.sg-syllabus-body p {
  margin: 0;
  font-size: 0.87rem;
  color: var(--ink-muted);
  line-height: 1.5;
}

.sg-syllabus-cta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  margin-top: 4px;
}

.sg-syllabus-card.mastered {
  border-color: var(--emerald-border);
  background: linear-gradient(180deg, #FFFFFF 0%, #F4FBF8 100%);
}

@media (max-width: 520px) {
  .sg-lesson-card { padding: 16px 14px; }
  .sg-syllabus-card { flex-direction: column; gap: 10px; padding: 14px; }
}

.sg-footer {
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.sg-footer a {
  color: var(--ink-muted);
  text-decoration: none;
  font-weight: 600;
  margin: 0 8px;
}

.sg-footer a:hover { text-decoration: underline; }

@media (max-width: 520px) {
  .sg-hero, .sg-summary, .sg-quiz-box, .sg-chapter-head { padding-left: 14px; padding-right: 14px; }
  .sg-topbar-inner { padding: 8px 10px; gap: 6px; }
  .sg-brand { font-size: 0.88rem; gap: 6px; }
  .sg-brand-mark { width: 24px; height: 24px; font-size: 0.74rem; border-radius: 6px; }
  .sg-brand-logo { width: 28px; height: 28px; }
  .sg-nav-links { gap: 4px; }
  .sg-nav-link { padding: 5px 7px; font-size: 0.74rem; }
  .sg-subject-bar-inner { padding: 7px 10px; }
}

@media (max-width: 380px) {
  .sg-brand span:last-child { font-size: 0.82rem; }
  .sg-nav-link { padding: 4px 6px; font-size: 0.71rem; }
}

/* Crisp inline stacked KaTeX fractions in lessons */
.sg-hero .katex,
.sg-lesson-card .katex {
  font-size: 1.08em;
  line-height: 1.35;
}

/* Lightweight Click-to-Play YouTube Walkthrough Card */
.sg-video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.sg-video-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.sg-video-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #B91C1C;
  background: #FEF2F2;
  border: 1px solid #FECACA;
  padding: 3px 9px;
  border-radius: 999px;
}

.sg-video-dur {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ink-muted);
}

.sg-video-title {
  margin: 0 0 6px;
  font-size: 1.08rem;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.35;
}

.sg-video-sub {
  margin: 0 0 14px;
  font-size: 0.88rem;
  color: var(--ink-muted);
  line-height: 1.5;
}

.sg-yt-facade {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  background: #0F172A;
  border: 1px solid var(--border);
  cursor: pointer;
  display: block;
  padding: 0;
}

.sg-yt-facade img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease, opacity 0.2s ease;
}

.sg-yt-facade:hover img {
  transform: scale(1.02);
  opacity: 0.92;
}

.sg-yt-facade::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(15,23,42,0.06) 40%, rgba(15,23,42,0.45) 100%);
  pointer-events: none;
}

.sg-yt-facade.playing::after {
  display: none;
}

.sg-yt-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: 66px;
  height: 46px;
  border-radius: 12px;
  background: rgba(220, 38, 38, 0.94);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.35);
  transition: transform 0.18s ease, background 0.18s ease;
}

.sg-yt-facade:hover .sg-yt-play {
  transform: translate(-50%, -50%) scale(1.07);
  background: #DC2626;
}

.sg-yt-play svg {
  width: 24px;
  height: 24px;
  fill: #FFFFFF;
  margin-left: 3px;
}

.sg-yt-facade iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  z-index: 3;
}

.sg-video-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.sg-video-ext {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.sg-video-ext:hover {
  text-decoration: underline;
}

.sg-video-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.7rem;
  font-weight: 700;
  color: #B91C1C;
  background: #FEF2F2;
  border: 1px solid #FECACA;
  padding: 1px 7px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}

@media (max-width: 520px) {
  .sg-video-card { padding: 16px 14px; }
  .sg-yt-play { width: 58px; height: 40px; }
}

/* Responsive SVG support inside Abstract, Spatial & Mechanical quiz cards */
.sg-q-text .abstract-diagram-wrap,
.sg-q-text svg {
  max-width: 100%;
  height: auto !important;
}

.sg-q-text .abstract-diagram-wrap {
  margin-top: 10px;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.sg-opt-text svg,
.sg-opt-text .abstract-choice-svg {
  display: block;
  width: 68px;
  height: 68px;
  max-width: 100%;
}
.sg-lesson-card p,
.sg-lesson-card li,
.sg-lesson-card td {
  line-height: 1.75;
}
.sg-lesson-card .katex .mfrac .frac-line {
  border-bottom-width: 0.06em;
}
