/* ============================================================
   Oluhle's Life Sciences — styles.css
   Mobile-first, system-font, teal-green palette
   ============================================================ */

/* ── Custom properties ───────────────────────────────────────── */
:root {
  --primary:    #0e7c66;
  --primary-dk: #0a5f50;
  --primary-lt: #e6f4f1;
  --ink:        #0f172a;
  --ink-soft:   #475569;
  --bg:         #f8fafc;
  --card:       #ffffff;
  --accent:     #f59e0b;
  --accent-lt:  #fef3c7;
  --success:    #16a34a;
  --success-lt: #dcfce7;
  --error:      #dc2626;
  --error-lt:   #fee2e2;
  --border:     #e2e8f0;
  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 2px 8px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04);
  --shadow-md:  0 4px 16px rgba(0,0,0,.12);
  --font:       -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                "Helvetica Neue", Arial, sans-serif;
  --transition: 180ms ease;
}

/* ── Reset / Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;   /* native only — no Lenis */
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ── Typography ──────────────────────────────────────────────── */
h1 { font-size: clamp(1.5rem, 4vw, 2rem); font-weight: 800; line-height: 1.2; }
h2 { font-size: clamp(1.2rem, 3vw, 1.5rem); font-weight: 700; line-height: 1.3; }
h3 { font-size: 1.05rem; font-weight: 700; color: var(--primary-dk); margin: 1.2rem 0 .4rem; }

p  { margin: .5rem 0 .8rem; color: var(--ink); }
a  { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
strong { font-weight: 700; }
em     { font-style: italic; }

/* ── Layout ──────────────────────────────────────────────────── */
#app {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 16px 80px;
  overflow-x: hidden;
}

/* ── App Header ──────────────────────────────────────────────── */
.app-header {
  background: var(--primary);
  color: #fff;
  text-align: center;
  padding: 28px 16px 24px;
  position: relative;
  /* full-bleed out of the #app padding */
  margin-left: -16px;
  margin-right: -16px;
}

.app-header h1 { color: #fff; font-size: clamp(1.3rem, 4vw, 1.8rem); }
.app-header .tagline { color: rgba(255,255,255,.85); font-size: .9rem; margin-top: 4px; }

/* ── Back bar (sticky, used in Study + Quiz) ─────────────────── */
.back-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  font-weight: 600;
  font-size: .95rem;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  /* full-bleed out of #app padding */
  margin-left: -16px;
  margin-right: -16px;
}

.back-bar .back-btn {
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 34px; height: 34px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition);
}
.back-bar .back-btn:hover  { background: rgba(255,255,255,.35); }
.back-bar .back-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.back-bar .bar-title { flex: 1; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin: 16px 0;
}

/* ── Chapter card on home ────────────────────────────────────── */
.chapter-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 16px 0;
  overflow: hidden;
}

.chapter-card__header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dk) 100%);
  color: #fff;
  padding: 18px 16px;
}

.chapter-card__header h2 { color: #fff; font-size: 1.05rem; }
.chapter-card__header .sub { color: rgba(255,255,255,.8); font-size: .82rem; margin-top: 4px; }

.chapter-card__body { padding: 12px 0; }

/* Full quiz button */
.full-quiz-row {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.full-quiz-row .best-score { font-size: .82rem; color: var(--ink-soft); }

/* ── Topic row ───────────────────────────────────────────────── */
.topic-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.topic-row:last-child { border-bottom: none; }
.topic-row .topic-name { flex: 1; font-weight: 600; font-size: .95rem; min-width: 120px; }
.topic-row .best-score { font-size: .8rem; color: var(--ink-soft); white-space: nowrap; }
.topic-row .btn-group  { display: flex; gap: 6px; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: var(--font);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
  min-height: 44px;   /* accessible tap target */
  text-align: center;
}

.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { opacity: .88; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-lt); }

.btn-accent { background: var(--accent); color: var(--ink); }
.btn-accent:hover { opacity: .88; }

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 2px solid var(--border);
}
.btn-ghost:hover { background: var(--border); }

.btn-sm { padding: 6px 12px; font-size: .82rem; min-height: 36px; }
.btn-full { width: 100%; }

.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Section nav (study view) ────────────────────────────────── */
.section-nav {
  background: var(--primary-lt);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 12px 0;
}

.section-nav p { font-size: .82rem; font-weight: 700; color: var(--primary-dk); margin-bottom: 8px; }
.section-nav ul { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.section-nav ul li a {
  display: inline-block;
  background: var(--card);
  border: 1px solid var(--primary);
  color: var(--primary);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: .82rem;
  font-weight: 600;
  transition: background var(--transition), color var(--transition);
}
.section-nav ul li a:hover { background: var(--primary); color: #fff; text-decoration: none; }

/* ── Note block renderers ─────────────────────────────────────── */
.notes-area { padding-top: 8px; }

.note-para { margin: .4rem 0 .75rem; }

.note-list { padding-left: 1.4rem; margin: .4rem 0 .8rem; }
.note-list li { margin: .3rem 0; }

/* Key terms */
.keyterms-list { margin: .4rem 0 .8rem; display: flex; flex-direction: column; gap: 8px; }

.keyterm-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  align-items: baseline;
  background: var(--accent-lt);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 8px 12px;
}

.keyterm-term {
  font-weight: 700;
  color: #92400e;
  font-size: .9rem;
  white-space: nowrap;
}

.keyterm-def {
  color: var(--ink);
  font-size: .9rem;
}

/* Table */
.table-wrap {
  overflow-x: auto;
  margin: .4rem 0 .8rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.note-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 280px;
  font-size: .88rem;
}

.note-table th {
  background: var(--primary);
  color: #fff;
  text-align: left;
  padding: 10px 12px;
  font-weight: 700;
}

.note-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.note-table tr:last-child td { border-bottom: none; }
.note-table tr:nth-child(even) td { background: var(--bg); }

/* Callouts */
.callout {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: .4rem 0 .8rem;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: .9rem;
  line-height: 1.55;
}

.callout-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }

.callout.tip  { background: #ecfdf5; border-left: 3px solid var(--success); }
.callout.tip .callout-icon::before  { content: "💡"; }

.callout.warn { background: #fff7ed; border-left: 3px solid #f97316; }
.callout.warn .callout-icon::before { content: "⚠️"; }

.callout.note { background: var(--primary-lt); border-left: 3px solid var(--primary); }
.callout.note .callout-icon::before { content: "📌"; }

/* Page-ref thumbnails */
.pageref-block {
  margin: .4rem 0 .8rem;
}

.pageref-thumb {
  display: block;
  max-width: 100%;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition);
  background: var(--border);  /* placeholder colour while loading */
}

.pageref-thumb:hover { box-shadow: var(--shadow-md); transform: scale(1.01); }
.pageref-thumb:focus-visible { outline: 3px solid var(--accent); }

.pageref-caption {
  font-size: .78rem;
  color: var(--ink-soft);
  text-align: center;
  margin-top: 4px;
}

/* ── Lightbox ────────────────────────────────────────────────── */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,.92);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#lightbox.open { display: flex; }

#lightbox img {
  max-width: 100%;
  max-height: calc(100dvh - 100px);
  border-radius: var(--radius-sm);
  object-fit: contain;
  user-select: none;
}

.lightbox-caption {
  color: rgba(255,255,255,.8);
  font-size: .85rem;
  margin-top: 10px;
  text-align: center;
}

.lightbox-controls {
  display: flex;
  gap: 12px;
  margin-top: 14px;
}

.lb-btn {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: background var(--transition);
}

.lb-btn:hover       { background: rgba(255,255,255,.3); }
.lb-btn:focus-visible { outline: 3px solid var(--accent); }
.lb-btn.lb-close    { position: absolute; top: 16px; right: 16px; padding: 8px 12px; font-size: 1.1rem; }

/* ── Quiz view ───────────────────────────────────────────────── */
.quiz-header {
  padding: 14px 0 0;
}

.progress-bar-wrap {
  background: var(--border);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
  margin-bottom: 10px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width .3s ease;
}

.quiz-meta {
  display: flex;
  justify-content: space-between;
  font-size: .82rem;
  color: var(--ink-soft);
  margin-bottom: 14px;
  font-weight: 600;
}

.quiz-score-live {
  background: var(--primary);
  color: #fff;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: .8rem;
}

/* Question card */
.question-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin: 0 0 14px;
}

.question-text {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 16px;
  color: var(--ink);
}

/* MCQ options */
.mcq-options { display: flex; flex-direction: column; gap: 8px; }

.mcq-option {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  text-align: left;
  font-family: var(--font);
  font-size: .92rem;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1.45;
}

.mcq-option:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-lt); }
.mcq-option:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.mcq-option.selected { border-color: var(--primary); background: var(--primary-lt); }
.mcq-option.correct  { border-color: var(--success); background: var(--success-lt); color: #14532d; font-weight: 700; }
.mcq-option.wrong    { border-color: var(--error);   background: var(--error-lt);   color: #7f1d1d; }
.mcq-option:disabled { cursor: default; }

.option-letter {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--border);
  color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-size: .78rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}

.mcq-option.selected .option-letter { background: var(--primary); color: #fff; }
.mcq-option.correct  .option-letter { background: var(--success); color: #fff; }
.mcq-option.wrong    .option-letter { background: var(--error);   color: #fff; }

/* T/F */
.tf-options { display: flex; gap: 10px; }

.tf-btn {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--bg);
  font-family: var(--font);
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
  transition: border-color var(--transition), background var(--transition);
}

.tf-btn:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-lt); }
.tf-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tf-btn.selected { border-color: var(--primary); background: var(--primary-lt); }
.tf-btn.correct  { border-color: var(--success); background: var(--success-lt); color: #14532d; }
.tf-btn.wrong    { border-color: var(--error);   background: var(--error-lt);   color: #7f1d1d; }
.tf-btn:disabled { cursor: default; }

/* Term input */
.term-input-wrap { display: flex; flex-direction: column; gap: 8px; }

.term-input {
  padding: 13px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .95rem;
  color: var(--ink);
  background: var(--bg);
  transition: border-color var(--transition);
}

.term-input:focus { outline: none; border-color: var(--primary); background: #fff; }
.term-input.correct { border-color: var(--success); background: var(--success-lt); }
.term-input.wrong   { border-color: var(--error);   background: var(--error-lt); }
.term-input:disabled { opacity: .7; cursor: default; }

/* Feedback panel */
.feedback-panel {
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-top: 12px;
  font-size: .9rem;
  line-height: 1.55;
  display: none;
}

.feedback-panel.show { display: block; }
.feedback-panel.correct { background: var(--success-lt); border-left: 3px solid var(--success); }
.feedback-panel.wrong   { background: var(--error-lt);   border-left: 3px solid var(--error); }

.feedback-verdict {
  font-weight: 800;
  font-size: 1rem;
  margin-bottom: 6px;
}

.feedback-verdict.correct { color: var(--success); }
.feedback-verdict.wrong   { color: var(--error); }

.feedback-explanation { color: var(--ink); margin-bottom: 6px; }
.feedback-ref { font-size: .8rem; color: var(--ink-soft); font-style: italic; }

/* Quiz action row */
.quiz-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

/* ── Results screen ──────────────────────────────────────────── */
.results-screen { padding-top: 16px; }

.results-score-card {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dk) 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  margin-bottom: 16px;
}

.results-score-card .score-pct {
  font-size: clamp(3rem, 12vw, 4.5rem);
  font-weight: 900;
  line-height: 1;
  display: block;
}

.results-score-card .score-label {
  font-size: .95rem;
  opacity: .85;
  margin-top: 4px;
}

.results-score-card .score-msg {
  margin-top: 12px;
  font-size: 1.05rem;
  font-weight: 600;
  background: rgba(255,255,255,.15);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  display: inline-block;
}

/* Topic breakdown */
.topic-breakdown { margin: 4px 0 16px; }
.topic-breakdown h3 { font-size: .95rem; margin-bottom: 8px; }

.breakdown-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: .88rem;
}
.breakdown-row:last-child { border-bottom: none; }
.breakdown-topic { flex: 1; font-weight: 600; }
.breakdown-score { white-space: nowrap; font-weight: 700; }
.breakdown-score.perfect { color: var(--success); }
.breakdown-score.partial { color: var(--accent); }
.breakdown-score.poor    { color: var(--error); }

/* Review list */
.review-list { margin-top: 8px; }
.review-list h3 { font-size: .95rem; margin-bottom: 10px; }

.review-item {
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.review-item-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  background: var(--card);
}

.review-item.correct .review-item-header { background: var(--success-lt); }
.review-item.wrong   .review-item-header { background: var(--error-lt); }

.review-badge {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  flex-shrink: 0;
  color: #fff;
}

.review-item.correct .review-badge { background: var(--success); }
.review-item.wrong   .review-badge { background: var(--error); }

.review-q-text {
  flex: 1;
  font-size: .88rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
}

.review-item.correct .review-q-text { color: #14532d; opacity: .8; }

.review-chevron { font-size: .8rem; color: var(--ink-soft); flex-shrink: 0; transition: transform var(--transition); }
.review-item.open .review-chevron { transform: rotate(180deg); }

.review-body {
  display: none;
  padding: 10px 14px 12px;
  background: var(--card);
  border-top: 1px solid var(--border);
  font-size: .87rem;
  line-height: 1.5;
}

.review-item.open .review-body { display: block; }
.review-item.wrong .review-body { display: block; }  /* wrong answers always expanded */

.review-answer-line { margin-bottom: 5px; }
.review-answer-line .lbl { font-weight: 700; color: var(--ink-soft); }
.review-answer-line .val-wrong   { color: var(--error); font-weight: 700; }
.review-answer-line .val-correct { color: var(--success); font-weight: 700; }
.review-explanation { color: var(--ink-soft); font-style: italic; margin-top: 6px; }
.review-ref { font-size: .78rem; color: var(--ink-soft); margin-top: 4px; }

/* Results actions */
.results-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 20px 0 10px;
}

/* ── Empty / loading states ──────────────────────────────────── */
.loading-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-soft);
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 14px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--error);
  font-size: .9rem;
}

/* ── Section spacers ─────────────────────────────────────────── */
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }

/* ── Responsive tweaks ───────────────────────────────────────── */
@media (min-width: 500px) {
  #app { padding: 0 20px 80px; }
  .app-header, .back-bar { margin-left: -20px; margin-right: -20px; }

  .topic-row { flex-wrap: nowrap; }

  .keyterm-item {
    grid-template-columns: 130px 1fr;
  }

  .quiz-actions { flex-direction: row; }
  .quiz-actions .btn { flex: 1; }

  .results-actions { flex-direction: row; flex-wrap: wrap; }
  .results-actions .btn { flex: 1; min-width: 150px; }
}

/* ── Focus visible global ─────────────────────────────────────── */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
