/* ==========================================================================
   IGCSE Combined Science — Biology Revision Site
   Sage Calm palette: slate (#50808E), sage (#84B59F), eucalyptus (#69A297)
   ========================================================================== */

:root {
  --slate: #50808E;
  --slate-dark: #3D6470;
  --sage: #84B59F;
  --eucalyptus: #69A297;
  --sage-pale: #E8F0EC;
  --slate-pale: #F1F6F7;
  --dark: #1F2D3A;
  --body: #2C3E50;
  --muted: #6B7C8C;
  --bg: #FAFBFC;
  --card-bg: #FFFFFF;
  --border: #D9E2E5;
  --accent: #C58B3D;      /* warm accent for highlights */
  --error: #C75B5B;
  --success: #69A297;

  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(31, 45, 58, 0.06);
  --shadow: 0 2px 8px rgba(31, 45, 58, 0.08);
  --shadow-md: 0 4px 16px rgba(31, 45, 58, 0.1);
  --shadow-lg: 0 8px 24px rgba(31, 45, 58, 0.12);

  --font-body: 'Source Sans 3', 'Segoe UI', system-ui, sans-serif;
  --font-heading: 'Source Serif 4', 'Cambria', Georgia, serif;
}

/* ---------- Reset + base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  color: var(--body);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  color: var(--dark);
  line-height: 1.2;
  margin-top: 0;
}
h1 { font-size: 2.15rem; margin-bottom: 0.5em; font-weight: 600; }
h2 { font-size: 1.65rem; margin-bottom: 0.5em; font-weight: 600; }
h3 { font-size: 1.25rem; margin-bottom: 0.4em; font-weight: 600; }
h4 { font-size: 1.05rem; margin-bottom: 0.3em; font-weight: 600; }
p { margin: 0 0 0.75em 0; }

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

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

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--sage);
  outline-offset: 2px;
}

/* ---------- Header ---------- */
.site-header {
  background: linear-gradient(135deg, var(--slate) 0%, var(--slate-dark) 100%);
  color: #fff;
  padding: 10px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.site-title {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1.1;
}

.site-title:hover { color: #fff; text-decoration: none; }

.site-logo {
  width: 120px;
  height: 120px;
  object-fit: contain;
  flex-shrink: 0;
  margin: -20px 0;  /* Let the logo bleed outside the header padding */
}

.site-title-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.site-subtitle {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.7);
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* Navigation */
.site-nav {
  display: flex;
  gap: 2px;
  flex: 1;
  flex-wrap: wrap;
}

.site-nav a {
  color: rgba(255,255,255,0.85);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
  transition: all 0.15s ease;
  text-decoration: none;
}

.site-nav a:hover {
  background: rgba(255,255,255,0.12);
  color: #fff;
  text-decoration: none;
}

.site-nav a.active {
  background: rgba(255,255,255,0.18);
  color: #fff;
}

.site-nav a.nav-secondary {
  color: rgba(255,255,255,0.5);
  font-size: 0.82rem;
  margin-left: auto;
}
.site-nav a.nav-secondary:hover {
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.08);
}

.lang-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.1);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.lang-picker label {
  color: rgba(255,255,255,0.8);
  font-size: 0.82rem;
}
.lang-picker select {
  background: transparent;
  color: #fff;
  border: none;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 2px 4px;
  cursor: pointer;
}
.lang-picker select option {
  background: var(--slate-dark);
  color: #fff;
}

/* Pathway switcher pill (Combined / Triple) */
.pathway-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.1);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.pathway-pill-label {
  color: rgba(255,255,255,0.8);
  font-size: 0.82rem;
}
.pathway-pill select {
  background: transparent;
  color: #fff;
  border: none;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 2px 4px;
  cursor: pointer;
}
.pathway-pill select option {
  background: var(--slate-dark);
  color: #fff;
}

/* Surprise-me button in header */
.surprise-btn {
  background: var(--accent);
  color: #fff;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  cursor: pointer;
}
.surprise-btn:hover {
  background: #A87533;
  transform: translateY(-1px);
}

/* Surprise modal */
.surprise-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade-in 0.18s ease;
}
.surprise-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(31, 45, 58, 0.55);
  backdrop-filter: blur(2px);
}
.surprise-card {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 36px 32px 28px;
  max-width: 540px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: pop-in 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}
.surprise-emoji {
  font-size: 3rem;
  margin-bottom: 8px;
  line-height: 1;
}
.surprise-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: transparent;
  border: none;
  font-size: 1.8rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}
.surprise-close:hover { background: var(--slate-pale); color: var(--dark); }
.surprise-label {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--slate);
  margin-bottom: 6px;
}
.surprise-card h2 {
  margin: 0 0 12px 0;
  color: var(--dark);
  font-size: 1.7rem;
}
.surprise-translation {
  font-size: 1.2rem;
  color: var(--slate);
  margin-bottom: 14px;
  font-weight: 500;
}
.surprise-def {
  color: var(--body);
  line-height: 1.55;
  text-align: left;
  padding: 14px 18px;
  background: var(--slate-pale);
  border-radius: var(--radius);
  margin: 12px 0;
}
.surprise-answer {
  text-align: left;
  margin-top: 14px;
  padding: 12px 16px;
  background: var(--sage-pale);
  border-radius: var(--radius);
}
.surprise-answer summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--slate-dark);
}
.surprise-answer p { margin: 8px 0 0 0; }
.surprise-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap;
}

/* ---------- Main container ---------- */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

.page-header {
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 18px;
}

.breadcrumb {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 8px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

.card-link:hover {
  text-decoration: none;
  color: inherit;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card-icon {
  width: 52px;
  height: 52px;
  background: var(--sage-pale);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  font-size: 1.5rem;
}

.card-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--dark);
  margin: 0 0 6px 0;
}

.card-desc {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0;
}

/* ---------- Grid ---------- */
.grid {
  display: grid;
  gap: 18px;
}

.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  transition: all 0.15s ease;
  text-decoration: none;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--slate);
  color: #fff;
}
.btn-primary:hover {
  background: var(--slate-dark);
  color: #fff;
  text-decoration: none;
}

.btn-secondary {
  background: var(--sage-pale);
  color: var(--slate-dark);
  border-color: var(--sage);
}
.btn-secondary:hover {
  background: var(--sage);
  color: #fff;
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--slate);
  border-color: var(--border);
}
.btn-ghost:hover {
  background: var(--slate-pale);
  color: var(--slate-dark);
  text-decoration: none;
}

.btn-icon {
  padding: 8px 10px;
  line-height: 1;
}

/* ---------- Progress bar ---------- */
.progress-bar {
  height: 8px;
  background: var(--sage-pale);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--sage) 0%, var(--eucalyptus) 100%);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.stat-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.stat {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  min-width: 140px;
  flex: 1;
}
.stat-label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.stat-value {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--dark);
  line-height: 1;
}

/* ---------- Hero (home page) ---------- */
.hero {
  background: linear-gradient(135deg, var(--slate-pale) 0%, var(--sage-pale) 100%);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
}

.hero h1 {
  margin-bottom: 8px;
}

.hero p {
  font-size: 1.05rem;
  color: var(--body);
  max-width: 680px;
  margin-bottom: 18px;
}

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ---------- Translation tooltip ---------- */
.translatable {
  position: relative;
  border-bottom: 1px dotted var(--sage);
  cursor: help;
}

.translation-popup {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  background: var(--dark);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.translatable:hover .translation-popup,
.translatable.show-translation .translation-popup {
  opacity: 1;
  pointer-events: auto;
}

.translation-popup::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 16px;
  border: 6px solid transparent;
  border-bottom-color: var(--dark);
}

.translation-popup[lang="ar"] { direction: rtl; text-align: right; }

/* ---------- Flashcard ---------- */
.flashcard-stage {
  max-width: 640px;
  margin: 0 auto;
  perspective: 1200px;
}

.flashcard {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 44px 32px;
  min-height: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.4s cubic-bezier(0.4, 0.0, 0.2, 1);
  transform-style: preserve-3d;
  position: relative;
}

.flashcard:hover {
  box-shadow: var(--shadow-lg);
}

.flashcard .face {
  backface-visibility: hidden;
  position: absolute;
  inset: 44px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.flashcard .face-back {
  transform: rotateY(180deg);
}

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

.flashcard-term {
  font-family: var(--font-heading);
  font-size: 2.25rem;
  color: var(--dark);
  font-weight: 600;
  margin: 0 0 12px 0;
}

.flashcard-translation {
  font-size: 1.3rem;
  color: var(--slate);
  margin-bottom: 18px;
  font-weight: 500;
}

.flashcard-definition {
  font-size: 1.1rem;
  color: var(--body);
  max-width: 460px;
  line-height: 1.5;
}

.flashcard-hint {
  position: absolute;
  bottom: 18px;
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
}

.flashcard-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 28px;
  gap: 12px;
  flex-wrap: wrap;
}

.flashcard-buttons {
  display: flex;
  gap: 10px;
}

.flashcard-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.recall-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}

.recall-btn {
  padding: 10px 22px;
  border-radius: var(--radius);
  font-weight: 600;
  transition: all 0.15s ease;
}

.recall-btn.again { background: #FDE8E8; color: #8B2E2E; border: 1px solid #E8A0A0; }
.recall-btn.again:hover { background: #F8D5D5; }
.recall-btn.hard { background: #FDF4E3; color: #8B6A1F; border: 1px solid #E5C987; }
.recall-btn.hard:hover { background: #F7E7C3; }
.recall-btn.good { background: var(--sage-pale); color: var(--slate-dark); border: 1px solid var(--sage); }
.recall-btn.good:hover { background: var(--sage); color: #fff; }
.recall-btn.easy { background: #E8F0EC; color: #2D5E3F; border: 1px solid #6EA87E; }
.recall-btn.easy:hover { background: #6EA87E; color: #fff; }

/* ---------- Deck selector ---------- */
.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.deck-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  width: 100%;
  display: block;
}
.deck-card:hover {
  border-color: var(--sage);
  background: var(--slate-pale);
}
.deck-card.selected {
  border-color: var(--slate);
  background: var(--sage-pale);
}
.deck-label {
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.deck-title {
  font-family: var(--font-heading);
  color: var(--dark);
  font-weight: 600;
}
.deck-count {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--slate);
}

/* Mode picker — shown above decks */
.mode-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.mode-card {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: all 0.15s ease;
}
.mode-card:hover {
  border-color: var(--sage);
  background: var(--slate-pale);
}
.mode-card.active {
  border-color: var(--slate);
  background: var(--sage-pale);
  box-shadow: var(--shadow-sm);
}
.mode-emoji {
  font-size: 1.8rem;
  margin-bottom: 6px;
}
.mode-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--dark);
  margin-bottom: 3px;
}
.mode-desc {
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.4;
}

/* Multiple-choice */
.mc-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  box-shadow: var(--shadow);
  max-width: 720px;
  margin: 0 auto;
}
.mc-prompt-label {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 6px;
}
.mc-term-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.mc-term {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 2rem;
  color: var(--dark);
}
.mc-translation {
  color: var(--slate);
  font-size: 1.15rem;
  margin-bottom: 18px;
}
.mc-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}
.mc-option {
  text-align: left;
  background: #fff;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  transition: all 0.15s ease;
  color: var(--body);
}
.mc-option:hover:not(:disabled) {
  border-color: var(--slate);
  background: var(--slate-pale);
}
.mc-option:disabled { cursor: default; opacity: 0.85; }
.mc-option.mc-correct {
  border-color: var(--success);
  background: var(--sage-pale);
  color: var(--slate-dark);
}
.mc-option.mc-incorrect {
  border-color: var(--error);
  background: #FDE8E8;
}
.mc-feedback-box {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-top: 16px;
}
.mc-feedback-box.good { background: var(--sage-pale); border-left: 4px solid var(--success); }
.mc-feedback-box.bad { background: #FDE8E8; border-left: 4px solid var(--error); }

/* ---------- Glossary ---------- */
.glossary-search {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
  background: var(--card-bg);
  margin-bottom: 18px;
}
.glossary-search:focus {
  border-color: var(--slate);
  outline: none;
  box-shadow: 0 0 0 3px rgba(80, 128, 142, 0.15);
}

.glossary-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--body);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { border-color: var(--sage); }
.chip.active {
  background: var(--slate);
  color: #fff;
  border-color: var(--slate);
}

.glossary-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}

.glossary-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.glossary-item:hover {
  border-color: var(--sage);
  box-shadow: var(--shadow-sm);
}

.glossary-term {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--dark);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

.glossary-translation {
  color: var(--slate);
  font-size: 0.92rem;
  margin-bottom: 6px;
  min-height: 1.2em;
}

.glossary-definition {
  font-size: 0.92rem;
  color: var(--body);
  line-height: 1.4;
}

.tts-btn {
  color: var(--slate);
  background: var(--sage-pale);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}
.tts-btn:hover {
  background: var(--sage);
  color: #fff;
}

/* Inline variant for use next to definition text */
.tts-btn-inline {
  width: 22px;
  height: 22px;
  margin-left: 4px;
  background: transparent;
  border: 1px solid var(--border);
  vertical-align: middle;
  padding: 0;
}
.tts-btn-inline:hover {
  background: var(--sage-pale);
  border-color: var(--sage);
  color: var(--slate-dark);
}

/* ---------- Topic page ---------- */
.topic-banner {
  background: linear-gradient(135deg, var(--slate) 0%, var(--eucalyptus) 100%);
  color: #fff;
  padding: 24px;
  border-radius: var(--radius-lg);
  margin-bottom: 22px;
}
.topic-banner h1 { color: #fff; margin-bottom: 6px; }
.topic-banner p { color: rgba(255,255,255,0.9); margin: 0; }

.topic-code {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

/* Topic page sections */
.topic-section {
  margin-bottom: 36px;
  scroll-margin-top: 80px;
}
.section-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--sage-pale);
}
.section-heading h2 {
  margin: 0;
  font-size: 1.55rem;
}
.section-icon {
  width: 40px;
  height: 40px;
  background: var(--sage-pale);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
}

.keypoints-list {
  background: var(--slate-pale);
  border-left: 4px solid var(--slate);
  padding: 18px 22px;
  border-radius: var(--radius);
  list-style: none;
  margin: 0 0 22px 0;
}
.keypoints-list li {
  padding: 6px 0;
  padding-left: 24px;
  position: relative;
  line-height: 1.6;
}
.keypoints-list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--sage);
  font-weight: 700;
}

/* Study/Practise section headings */
.study-header {
  font-family: var(--font-heading);
  font-size: 1.55rem;
  color: var(--dark);
  margin: 28px 0 14px 0;
  padding: 10px 0 10px 14px;
  border-left: 5px solid var(--slate);
  background: linear-gradient(90deg, var(--slate-pale) 0%, transparent 100%);
}

/* Translation tooltips inside text */
.tip {
  display: inline;
  position: relative;
  border-bottom: 1.5px dotted var(--sage);
  cursor: help;
  color: var(--slate-dark);
  font-weight: 500;
}
.tip-bubble {
  display: none;
  position: absolute;
  left: 0;
  top: 100%;
  margin-top: 6px;
  background: var(--dark);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 400;
  line-height: 1.5;
  min-width: 220px;
  max-width: 320px;
  z-index: 500;
  box-shadow: var(--shadow-lg);
  white-space: normal;
}
.tip-bubble::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 14px;
  border: 6px solid transparent;
  border-bottom-color: var(--dark);
}
.tip-bubble strong {
  color: #fff;
  display: block;
  font-size: 1rem;
  margin-bottom: 2px;
}
.tip:hover .tip-bubble,
.tip.open .tip-bubble {
  display: block;
}
/* RTL language tooltips */
.tip-bubble[lang="ar"] { direction: rtl; text-align: right; }

/* Embedded labelled diagrams (on topic page) */
.embedded-diagram {
  margin: 24px 0;
  padding: 18px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-align: center;
}

/* Glossary split into key + other terms */
.glossary-subheading {
  margin: 0 0 8px 0;
  color: var(--slate-dark);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.other-terms-details summary {
  padding: 10px 14px;
  background: var(--slate-pale);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  color: var(--slate-dark);
  font-size: 0.92rem;
  list-style: none;
}
.other-terms-details summary::-webkit-details-marker { display: none; }
.other-terms-details summary::before {
  content: "▶ ";
  font-size: 0.7rem;
  margin-right: 4px;
  color: var(--slate);
  transition: transform 0.15s ease;
  display: inline-block;
}
.other-terms-details[open] summary::before { transform: rotate(90deg); }
.other-terms-details summary:hover { background: var(--sage-pale); }
.embedded-diagram img {
  max-width: 100%;
  max-height: 420px;
  border-radius: var(--radius);
  background: #fff;
}
.embedded-diagram figcaption {
  text-align: left;
  padding-top: 12px;
}
.embedded-diagram figcaption h4 {
  margin: 0 0 8px 0;
  color: var(--dark);
  font-size: 1.1rem;
}

/* Label chip list under a diagram */
.label-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0;
}
.label-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  background: var(--sage-pale);
  border: 1px solid var(--sage);
  border-radius: 20px;
  font-size: 0.88rem;
}
.label-chip .label-num {
  background: var(--slate);
  color: #fff;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.78rem;
}

/* Topic sub-nav (sticky) */
.topic-subnav {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  margin-bottom: 24px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  position: sticky;
  top: 74px;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}
.topic-subnav a {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--body);
  text-decoration: none;
}
.topic-subnav a:hover {
  background: var(--slate-pale);
  color: var(--slate-dark);
  text-decoration: none;
}

/* Diagram thumbnail gallery on topic pages */
.diagram-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.diagram-thumb {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  transition: all 0.15s ease;
  text-decoration: none;
  color: inherit;
  display: block;
}
.diagram-thumb:hover {
  border-color: var(--sage);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
}
.diagram-thumb img {
  max-width: 100%;
  height: 140px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: var(--bg);
}
.diagram-thumb .title {
  font-weight: 600;
  color: var(--dark);
  margin-top: 8px;
  font-size: 0.95rem;
}

/* Compact flashcard / game action buttons */
.action-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

/* ---------- Label-drag game (side-table layout) ---------- */
.label-game-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 1fr);
  gap: 22px;
  align-items: start;
  margin-bottom: 20px;
}
.label-image-wrap img {
  max-width: 100%;
  display: block;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
}
.label-answers {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.label-slot-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.label-slot-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.label-slot-num {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  background: var(--slate);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
}
.label-slot {
  flex: 1;
  min-height: 38px;
  border: 2px dashed var(--muted);
  border-radius: var(--radius-sm);
  background: #fff;
  display: flex;
  align-items: center;
  padding: 6px 12px;
  font-size: 0.95rem;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.label-slot.hover {
  border-color: var(--slate);
  background: var(--sage-pale);
  color: var(--slate-dark);
}
.label-slot.filled {
  border-style: solid;
  border-color: var(--sage);
  color: var(--dark);
  font-weight: 500;
  background: #fff;
}
.label-slot.correct {
  border-color: var(--success);
  background: var(--sage-pale);
}
.label-slot.incorrect {
  border-color: var(--error);
  background: #FDE8E8;
}

@media (max-width: 720px) {
  .label-game-grid { grid-template-columns: 1fr; }
}

/* ---------- Topic page ---------- */ /* (moved up, do not duplicate) */

/* ---------- Self test ---------- */
.quiz-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow);
}

.quiz-question {
  font-size: 1.15rem;
  color: var(--dark);
  font-weight: 500;
  margin-bottom: 16px;
}

.quiz-marks {
  display: inline-block;
  background: var(--slate);
  color: #fff;
  padding: 2px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  margin-left: 8px;
}

.quiz-answer-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
  resize: vertical;
  min-height: 90px;
  margin-bottom: 12px;
}
.quiz-answer-input:focus {
  border-color: var(--slate);
  outline: none;
  box-shadow: 0 0 0 3px rgba(80, 128, 142, 0.15);
}

.quiz-feedback {
  margin-top: 14px;
  padding: 14px 18px;
  border-radius: var(--radius);
  display: none;
}
.quiz-feedback.show { display: block; }
.quiz-feedback.model {
  background: var(--sage-pale);
  border-left: 3px solid var(--sage);
}
.quiz-feedback h4 {
  margin: 0 0 6px 0;
  color: var(--slate-dark);
  font-size: 0.95rem;
}

/* Auto-feedback (mark scheme check) */
.quiz-autofeedback {
  margin-top: 14px;
  padding: 16px 20px;
  border-radius: var(--radius);
  background: var(--slate-pale);
  border-left: 3px solid var(--slate);
}
.autofeedback-header h4 {
  margin: 0 0 4px 0;
  font-size: 1.1rem;
  color: var(--dark);
}
.autofeedback-header p { margin: 0 0 10px 0; }
.mark-points-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.mark-point {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: #fff;
  border: 1px solid var(--border);
  font-size: 0.92rem;
}
.mark-point.earned {
  background: var(--sage-pale);
  border-color: var(--sage);
}
.mark-point.missed {
  background: #FDE8E8;
  border-color: #E8A0A0;
}
.mark-icon {
  font-weight: 700;
  font-size: 1rem;
  width: 20px;
  display: inline-flex;
  justify-content: center;
}
.mark-point.earned .mark-icon { color: var(--success); }
.mark-point.missed .mark-icon { color: var(--error); }
.mark-label {
  flex: 1;
  color: var(--body);
}
.mark-value {
  font-weight: 700;
  color: var(--slate);
  font-size: 0.88rem;
}

/* ---------- Diagram explorer ---------- */
.diagram-container {
  max-width: 100%;
}

.diagram-container img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

.diagram-label-dot {
  position: absolute;
  width: 28px;
  height: 28px;
  background: var(--slate);
  color: #fff;
  border: 2px solid #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transform: translate(-50%, -50%);
  transition: all 0.15s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.diagram-label-dot:hover {
  transform: translate(-50%, -50%) scale(1.15);
  background: var(--sage);
}

.diagram-label-dot.revealed {
  background: var(--sage);
}

.diagram-label-dot.wrong {
  background: var(--error);
  animation: wrong-shake 0.4s;
}

@keyframes wrong-shake {
  0%, 100% { transform: translate(-50%, -50%); }
  25% { transform: translate(-55%, -50%); }
  75% { transform: translate(-45%, -50%); }
}

/* Quiz mode number buttons (in info panel) */
.quiz-num-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.quiz-num-btn {
  width: 48px;
  height: 48px;
  background: #fff;
  color: var(--slate-dark);
  border: 2px solid var(--slate);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}
.quiz-num-btn:hover:not(:disabled) {
  background: var(--slate);
  color: #fff;
  transform: translateY(-2px);
}
.quiz-num-btn:disabled { cursor: default; }
.quiz-num-btn.correct {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.quiz-num-btn.wrong {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}

/* Also used by the old dot-based layout — keep in case referenced */
.diagram-label-dot-clickable { cursor: pointer; }

/* Image wrapper (no longer has overlaid chips — kept for consistent border/radius) */
.diagram-image-wrap {
  display: block;
  background: #fff;
  border-radius: var(--radius);
}
.diagram-image-wrap img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* Rail below the image that holds the numbered magnifier chips */
.diagram-chip-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.diagram-chip-rail:empty {
  display: none;
}

/* Magnifier chip: number + magnifier icon combined (no longer absolute-positioned) */
.diagram-magnifier {
  position: relative;
  height: 34px;
  padding: 0 10px 0 4px;
  background: var(--slate);
  color: #fff;
  border: 2px solid #fff;
  border-radius: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}
.diagram-magnifier .mag-number {
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.92rem;
  font-weight: 700;
  margin-left: 2px;
}
.diagram-magnifier .mag-icon {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
}
.diagram-magnifier:hover {
  background: var(--sage);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.diagram-magnifier.revealed {
  background: var(--sage);
}

.diagram-info-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-top: 16px;
  min-height: 100px;
}
.diagram-info-panel h4 {
  margin: 0 0 4px 0;
  color: var(--dark);
  font-size: 1.15rem;
}
.diagram-info-panel .translation {
  color: var(--slate);
  margin-bottom: 8px;
}

/* ---------- Games ---------- */
.game-label-chip {
  display: inline-block;
  padding: 8px 14px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 4px;
  cursor: grab;
  font-weight: 500;
  transition: all 0.15s ease;
  user-select: none;
}
.game-label-chip:hover {
  border-color: var(--sage);
  background: var(--sage-pale);
}
.game-label-chip.placed {
  background: var(--sage);
  color: #fff;
  border-color: var(--sage);
  cursor: default;
}
.game-label-chip.correct {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.game-label-chip.incorrect {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}

.drop-slot {
  position: absolute;
  width: 140px;
  height: 34px;
  border: 2px dashed var(--muted);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.9);
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--muted);
}
.drop-slot.hover {
  border-color: var(--slate);
  background: var(--sage-pale);
}
.drop-slot.filled {
  border-style: solid;
  border-color: var(--sage);
  color: var(--dark);
  font-weight: 500;
  background: #fff;
}

.match-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.match-item {
  padding: 14px 18px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
}
.match-item:hover { border-color: var(--sage); }
.match-item.selected { background: var(--slate-pale); border-color: var(--slate); }
.match-item.matched { background: var(--sage-pale); border-color: var(--sage); opacity: 0.6; pointer-events: none; }

/* ---------- Progress page ---------- */
.progress-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.progress-table th,
.progress-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.progress-table th {
  background: var(--slate);
  color: #fff;
  font-weight: 600;
}
.progress-table tr:last-child td { border-bottom: none; }

.score-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
}
.score-badge.pass { background: var(--sage-pale); color: var(--slate-dark); }
.score-badge.near { background: #FDF4E3; color: #8B6A1F; }
.score-badge.fail { background: #FDE8E8; color: #8B2E2E; }
.score-badge.untried { background: #ECEEF0; color: var(--muted); }

/* ---------- Utilities ---------- */
.text-muted { color: var(--muted); }
.text-small { font-size: 0.88rem; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 10px; }
.mt-2 { margin-top: 20px; }
.mt-3 { margin-top: 30px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 10px; }
.mb-2 { margin-bottom: 20px; }
.text-center { text-align: center; }

.hidden { display: none !important; }

/* ---------- Test finder (home page) ---------- */
.test-finder-row {
  background: var(--sage-pale);
  border: 1px solid var(--sage);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.test-finder-select {
  flex: 1;
  min-width: 220px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  background: #fff;
}

/* ---------- Home accordion ---------- */
.topic-accordion-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.topic-accordion-item summary {
  padding: 14px 18px;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 14px;
  font-family: inherit;
  list-style: none;
  transition: background 0.15s ease;
}
.topic-accordion-item summary::-webkit-details-marker { display: none; }
.topic-accordion-item summary::marker { content: ""; }
.topic-accordion-item summary::before {
  content: "▶";
  color: var(--slate);
  font-size: 0.7rem;
  transition: transform 0.15s ease;
}
.topic-accordion-item[open] summary::before { transform: rotate(90deg); }
.topic-accordion-item summary:hover { background: var(--slate-pale); }
.topic-badge {
  background: var(--slate);
  color: #fff;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.topic-title-inline {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--dark);
}
.topic-summary-count {
  font-size: 0.85rem;
  color: var(--muted);
}
.topic-progress-inline { white-space: nowrap; }
.topic-accordion-body {
  padding: 4px 18px 18px;
  border-top: 1px solid var(--border);
  background: var(--slate-pale);
}
.topic-actions-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 0;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 8px;
}

/* ---------- Test row (within accordion) ---------- */
.test-list {
  display: flex;
  flex-direction: column;
}
.test-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 6px;
  text-decoration: none;
  color: inherit;
  transition: all 0.15s ease;
}
.test-row:hover {
  border-color: var(--sage);
  text-decoration: none;
  color: inherit;
  transform: translateX(2px);
  box-shadow: var(--shadow-sm);
}
.test-num {
  background: var(--slate);
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.92rem;
  flex-shrink: 0;
}
.test-title {
  font-weight: 500;
  color: var(--dark);
  font-size: 0.95rem;
}
.test-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
}
.test-marks {
  background: var(--slate-pale);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  color: var(--slate-dark);
  font-weight: 600;
}
.test-icon { font-size: 0.95rem; }

@media (max-width: 620px) {
  .topic-accordion-item summary {
    grid-template-columns: auto 1fr;
  }
  .topic-summary-count, .topic-progress-inline {
    grid-column: 1 / -1;
    margin-left: 36px;
  }
  .test-row {
    grid-template-columns: auto 1fr;
  }
  .test-meta {
    grid-column: 1 / -1;
    margin-left: 48px;
  }
}

/* ---------- Test hub page ---------- */
.test-hub-actions {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.glossary-item[data-relevant="true"] {
  border-color: var(--sage);
  background: var(--sage-pale);
}
.relevant-pill {
  background: var(--sage);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-left: 4px;
  text-transform: uppercase;
  vertical-align: middle;
}

/* RTL support for Arabic — applied only to individual Arabic text elements */
/* (Body-wide RTL removed — it was flipping English UI text when Arabic was selected) */
[lang="ar"],
.lang-rtl,
.rtl-lang { direction: rtl; text-align: right; }

/* Global glossary items in Arabic get RTL via lang attribute */
.glossary-card[lang="ar"] .gloss-term,
.glossary-card[lang="ar"] .gloss-def,
.glossary-card[lang="ar"] .gloss-translation { direction: rtl; text-align: right; }

/* Mobile responsive */
@media (max-width: 720px) {
  h1 { font-size: 1.8rem; }
  h2 { font-size: 1.4rem; }
  .container { padding: 20px 16px 60px; }
  .hero { padding: 24px 20px; }
  .flashcard { min-height: 280px; padding: 32px 22px; }
  .flashcard-term { font-size: 1.8rem; }
  .site-nav { width: 100%; order: 10; }
  .site-nav a { padding: 6px 10px; font-size: 0.85rem; }
  .header-inner { gap: 12px; }
}

/* ==================== Topic content sub-sections ==================== */

/* Quick-summary collapsible */
.quick-summary {
  margin-bottom: 20px;
  background: var(--sage-pale);
  border: 1px solid var(--sage);
  border-radius: var(--radius);
  padding: 4px 4px 0 4px;
}
.quick-summary summary {
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  color: var(--slate-dark);
  list-style: none;
  font-size: 0.95rem;
  border-radius: var(--radius-sm);
}
.quick-summary summary::-webkit-details-marker { display: none; }
.quick-summary summary::before {
  content: "▼ ";
  display: inline-block;
  transition: transform 0.15s ease;
  font-size: 0.7rem;
  margin-right: 4px;
}
.quick-summary:not([open]) summary::before { transform: rotate(-90deg); }
.quick-summary summary:hover { background: rgba(255,255,255,0.4); }
.quick-summary .keypoints-list {
  margin: 0;
  border-left: none;
  background: transparent;
}

/* Sub-section */
.topic-sections { display: flex; flex-direction: column; gap: 28px; margin: 20px 0 24px; }
.sub-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
}
.sub-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  flex-wrap: wrap;
}
.sub-section-header h4 {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  color: var(--slate-dark);
  margin: 0;
  flex: 1;
  min-width: 200px;
}
.sub-section-body {
  line-height: 1.65;
  font-size: 1rem;
  color: var(--body);
  white-space: pre-wrap;
}
.sub-section-body strong { color: var(--slate-dark); font-weight: 600; }
.sub-section-body em { color: var(--slate-dark); font-style: italic; }
.sub-section-body.rtl-lang { direction: rtl; text-align: right; }
.sub-section-body .prose-table {
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.95rem;
  white-space: normal;
}
.sub-section-body .prose-table th,
.sub-section-body .prose-table td {
  border: 1px solid var(--slate-pale, #cbd5e1);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}
.sub-section-body .prose-table th {
  background: var(--slate-pale, #f1f5f9);
  font-weight: 600;
  color: var(--slate-dark);
}
.sub-section-body .prose-table tbody tr:nth-child(even) {
  background: rgba(0,0,0,0.02);
}
.sub-section-body.rtl-lang .prose-table th,
.sub-section-body.rtl-lang .prose-table td { text-align: right; }

/* Language pills */
.lang-pills {
  display: inline-flex;
  gap: 2px;
  background: var(--slate-pale);
  padding: 3px;
  border-radius: 20px;
}
.lang-pill {
  background: transparent;
  border: none;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-radius: 16px;
  font-family: inherit;
  transition: all 0.12s ease;
}
.lang-pill:hover {
  background: rgba(255,255,255,0.6);
  color: var(--slate-dark);
}
.lang-pill.active {
  background: var(--slate);
  color: #fff;
}

/* Watch-out callouts */
.watch-outs { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.watch-out {
  background: #FFF7E6;
  border-left: 4px solid #F59E0B;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.watch-out-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  line-height: 1.3;
}
.watch-out-text {
  flex: 1;
  font-size: 0.94rem;
  color: #78350F;
  line-height: 1.55;
}
.watch-out-text strong { color: #78350F; font-weight: 700; }
.watch-out-text.rtl-lang { direction: rtl; text-align: right; }

/* Stretch & challenge box — for Triple Award (0610) Supplement content. 
   Visually distinct from .watch-out: uses the eucalyptus accent rather than 
   amber, and has a header pill that signals "Extended/Supplement". */
.stretch-box {
  background: var(--sage-pale);
  border-left: 4px solid var(--eucalyptus);
  border-radius: var(--radius-sm);
  padding: 14px 16px 12px 16px;
  margin-top: 12px;
}
.stretch-box-head {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--eucalyptus);
  color: #fff;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.stretch-box-text {
  font-size: 0.95rem;
  color: var(--dark);
  line-height: 1.6;
  white-space: pre-wrap;
}
.stretch-box-text strong { color: var(--slate-dark); font-weight: 700; }
.stretch-box-text em { color: var(--eucalyptus); font-style: italic; }
.stretch-box-text.rtl-lang { direction: rtl; text-align: right; }

/* Diagrams sub-heading inside Key Information */
.diagrams-subhead {
  margin: 28px 0 10px 0;
  font-family: var(--font-heading);
  font-size: 1.15rem;
  color: var(--slate-dark);
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}

@media (max-width: 640px) {
  .sub-section { padding: 16px 14px; }
  .sub-section-header { flex-direction: column; align-items: stretch; }
  .lang-pills { align-self: flex-start; }
}

/* Inline teaching images in sub-sections */
.sub-section-image {
  margin: 16px 0 0 0;
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--slate-200);
}
.sub-section-image img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 520px;
  object-fit: contain;
  background: #fff;
}
.sub-section-image figcaption {
  padding: 10px 14px;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  font-style: italic;
  background: var(--slate-50);
  border-top: 1px solid var(--slate-200);
}

/* Single language toggle per sub-section (EN ↔ target language) */
.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--slate-300);
  background: #fff;
  color: var(--slate-dark);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.lang-toggle:hover {
  border-color: var(--sage);
  background: var(--sage-50);
  color: var(--eucalyptus);
}
.lang-toggle.active {
  background: var(--eucalyptus);
  border-color: var(--eucalyptus);
  color: #fff;
}
.lang-toggle-icon { font-size: 0.9rem; line-height: 1; }
.lang-toggle-label { line-height: 1; }

/* AI translation notice (shown once at top of key info when target lang is set) */
.ai-translation-notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 14px;
  background: #FEF3C7;
  border: 1px solid #FCD34D;
  border-radius: 10px;
  margin-bottom: 16px;
}
.ai-notice-icon {
  font-size: 1.3rem;
  line-height: 1.2;
  flex-shrink: 0;
}
.ai-notice-text {
  flex: 1;
  font-size: 0.875rem;
  color: #78350F;
  line-height: 1.45;
}
.ai-notice-text strong { color: #78350F; }
.ai-notice-native {
  margin-top: 4px;
  font-size: 0.85rem;
  color: #92400E;
  opacity: 0.9;
}
.ai-notice-native[lang="ar"] { direction: rtl; text-align: right; }

@media (max-width: 640px) {
  .sub-section-header {
    flex-wrap: wrap;
  }
  .lang-toggle {
    font-size: 0.8rem;
    padding: 5px 10px;
  }
}

/* Syllabus reference badges on topic banner */
.syllabus-refs {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
}
.syllabus-refs-label {
  color: var(--text-muted);
  font-weight: 500;
}
.syllabus-badge {
  display: inline-block;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  color: #fff;
  font-weight: 500;
  white-space: nowrap;
}
@media (max-width: 640px) {
  .syllabus-refs { font-size: 0.75rem; gap: 6px; }
  .syllabus-badge { padding: 3px 8px; }
}

/* Video cards on topic page */
#videos-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  margin-top: 16px;
}
.video-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.video-embed {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 */
  background: #000;
}
.video-embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.video-meta {
  padding: 12px 14px;
}
.video-title {
  font-weight: 600;
  font-size: 0.98rem;
  color: var(--slate-dark);
  line-height: 1.35;
  margin-bottom: 2px;
}
.video-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Click-to-search video cards (when no verified embed ID) */
.video-card-search {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.video-card-search:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(80, 128, 142, 0.15);
  border-color: var(--sage);
}
.video-search-thumb {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 */
  background: linear-gradient(135deg, var(--slate) 0%, var(--eucalyptus) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-search-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
  width: 64px;
  height: 64px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  color: var(--eucalyptus);
  padding-left: 6px; /* visual centre of the ▶ glyph */
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}
.video-search-label {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.video-search-hint {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--eucalyptus);
  font-weight: 500;
}

/* English keyword hints inside translated prose: e.g. 酶 (Enzyme) */
.en-hint {
  color: var(--text-muted);
  font-style: italic;
  font-weight: 400;
  font-size: 0.92em;
  white-space: nowrap;
}
/* In Arabic (RTL) text, the Latin English keeps its own direction */
[lang="ar"] .en-hint,
.rtl-lang .en-hint {
  direction: ltr;
  unicode-bidi: embed;
}

/* ============================================================
   Embedded micro-activities (gap-fills, label-drag)
   ============================================================ */

.activity-host {
  margin: 16px 0 0;
}

.activity-wrap {
  margin-top: 16px;
}

.activity {
  border: 2px solid var(--accent, #5b9bd5);
  border-radius: 8px;
  background: var(--card-bg, #fff);
  overflow: hidden;
}

.activity > summary {
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, rgba(91,155,213,0.08) 0%, rgba(91,155,213,0.02) 100%);
  user-select: none;
}

.activity > summary::-webkit-details-marker { display: none; }

.activity > summary::before {
  content: "▶";
  font-size: 0.8em;
  color: var(--accent, #5b9bd5);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.activity[open] > summary::before {
  transform: rotate(90deg);
}

.activity-icon {
  font-size: 1.1em;
  line-height: 1;
}

.activity-title {
  flex: 1;
  font-weight: 600;
  color: var(--heading, #234);
}

.activity .score-badge {
  font-size: 0.78em;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}
.activity .score-badge.untried { background: #f0f0f0; color: #777; }
.activity .score-badge.pass    { background: #d4f3d4; color: #1a6e1a; }
.activity .score-badge.fail    { background: #fbe5d8; color: #a04400; }

.activity-body {
  padding: 14px 16px 18px;
  border-top: 1px solid var(--border, #e6e6e6);
}

.activity-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.activity-actions .btn.hidden { display: none; }

.activity-feedback {
  margin-top: 10px;
  min-height: 1.4em;
}

.activity-result {
  padding: 8px 12px;
  background: #f7f7f9;
  border-radius: 6px;
  font-size: 0.95em;
}

.activity-result.pass {
  background: #d4f3d4;
  color: #1a6e1a;
  font-weight: 600;
}

.activity-stub {
  padding: 12px;
  color: #888;
  font-style: italic;
}

/* Gap-fill specifics --------------------------------------- */

.gap-fill-text {
  line-height: 1.7;
}

.gap-fill-text p { margin: 0 0 0.7em; }
.gap-fill-text p:last-child { margin-bottom: 0; }

.gap-input {
  display: inline-block;
  min-width: 110px;
  width: auto;
  padding: 3px 8px;
  border: 1.5px solid #b0b8c0;
  border-radius: 4px;
  font-size: 1em;
  font-family: inherit;
  background: #fff;
  vertical-align: baseline;
  margin: 0 2px;
}

.gap-input:focus {
  outline: none;
  border-color: var(--accent, #5b9bd5);
  box-shadow: 0 0 0 2px rgba(91,155,213,0.2);
}

.gap-input.correct {
  background: #d4f3d4;
  border-color: #4caf50;
  color: #1a6e1a;
  font-weight: 600;
}

.gap-input.incorrect {
  background: #fbe5d8;
  border-color: #e08040;
  color: #a04400;
}

.gap-input.revealed {
  background: #fffbe0;
  border-color: #c8a800;
  color: #6b5800;
  font-style: italic;
}

.gap-input:disabled {
  cursor: default;
}

/* Label-drag specifics — reuse existing classes from topic.js */
.activity-label-drag .label-bank,
.activity-label-drag .label-game-grid {
  /* use existing styles for these */
}

/* Word bank for gap-fills ---------------------------------- */

.word-bank {
  background: #f7f9fb;
  border: 1px solid #d8e3eb;
  border-radius: 6px;
  padding: 10px 12px;
  margin: 0 0 14px 0;
}

.word-bank-label {
  font-size: 0.82em;
  color: #5a6c78;
  margin-bottom: 6px;
  font-weight: 500;
}

.word-bank-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.word-bank-chip {
  display: inline-block;
  padding: 5px 12px;
  border: 1.5px solid #b0b8c0;
  border-radius: 14px;
  background: #fff;
  color: #234;
  font-size: 0.92em;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  user-select: none;
}

.word-bank-chip:hover:not(.used) {
  background: var(--accent, #5b9bd5);
  border-color: var(--accent, #5b9bd5);
  color: #fff;
}

.word-bank-chip.used {
  background: #ececec;
  border-color: #d0d0d0;
  color: #aaa;
  cursor: default;
  text-decoration: line-through;
}

.word-bank-chip:focus-visible {
  outline: 2px solid var(--accent, #5b9bd5);
  outline-offset: 2px;
}

/* ============================================================
   Syllabus reference badges, level pills, inline labelled diagrams
   ============================================================ */

.syllabus-refs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 14px;
}

.syllabus-ref {
  display: inline-block;
  padding: 2px 8px;
  background: #eef3f7;
  border: 1px solid #d4dde4;
  border-radius: 10px;
  font-family: 'Source Sans 3', system-ui, sans-serif;
  font-size: 0.78em;
  color: #4a5a66;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.level-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75em;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-left: 8px;
  vertical-align: middle;
  white-space: nowrap;
}

.level-pill.level-core {
  background: #e0f0e0;
  color: #1a6e1a;
  border: 1px solid #b8dab8;
}

.level-pill.level-extended {
  background: #fff2e0;
  color: #a05400;
  border: 1px solid #e8c79f;
}

.level-pill.level-both {
  background: #e6f0fa;
  color: #1a5a8a;
  border: 1px solid #b3d0e8;
}

/* Inline labelled diagram in the prose flow ----------------- */

.inline-labelled-diagram {
  margin: 0 0 16px;
  padding: 0;
  border: 1px solid #e0e4e8;
  border-radius: 8px;
  background: #fafbfc;
  overflow: hidden;
  text-align: center;
}

.inline-labelled-diagram img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  padding: 12px 12px 4px;
  box-sizing: border-box;
}

.inline-labelled-diagram figcaption {
  padding: 8px 12px 12px;
  font-size: 0.85em;
  color: #5a6c78;
  font-style: italic;
  border-top: 1px solid #eaedf0;
  background: #fff;
}

/* Header tweaks so badges sit nicely with the title */
.sub-section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
}

/* Inline figure (infographic / comparison table) — alongside labelled diagrams */
.inline-figure {
  margin: 0 0 16px;
  padding: 0;
  border: 1px solid #e0e4e8;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  text-align: center;
}

.inline-figure img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  padding: 8px;
  box-sizing: border-box;
}

.inline-figure figcaption {
  padding: 8px 12px 12px;
  font-size: 0.85em;
  color: #5a6c78;
  font-style: italic;
  border-top: 1px solid #eaedf0;
  background: #fafbfc;
}
