/* ============================================================
   CFA Study Notes Stylesheet — Preparoo Design System
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'BDO Grotesk VF', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.92rem;
  line-height: 1.75;
  color: #334155;
  background: #ffffff;
  margin: 0;
  padding: 0;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Typography --- */
h1, h2, h3, h4 {
  font-family: 'BDO Grotesk VF', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #0d2442;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.02em;
  margin-top: 2em;
  margin-bottom: 0.5em;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  border: none;
  padding-bottom: 0;
  margin-top: 2.5em;
  position: relative;
}
h1::after {
  content: '';
  display: block;
  width: 40px;
  height: 3px;
  background: #0d2442;
  border-radius: 2px;
  margin-top: 0.5em;
}

h2 {
  font-size: 1.2rem;
  font-weight: 600;
  border: none;
  padding-bottom: 0;
  margin-top: 2em;
  color: #0d2442;
}

h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #1a3a5c;
  letter-spacing: -0.01em;
}

h4 {
  font-size: 0.85rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

p {
  margin-top: 0;
  margin-bottom: 0.85em;
  color: #334155;
}

strong {
  color: #0d2442;
  font-weight: 600;
}

em {
  color: #475569;
  font-style: italic;
}

hr {
  border: none;
  border-top: 1px solid #e2e8f0;
  margin: 2.5em 0;
}

ul, ol {
  margin: 0.5em 0 1em 0;
  padding-left: 1.5em;
}

li {
  margin-bottom: 0.35em;
  color: #334155;
}
li::marker {
  color: #0d2442;
}

li > ul,
li > ol {
  margin-top: 0.2em;
  margin-bottom: 0.2em;
}

/* --- Title Page --- */
.title-page {
  background: linear-gradient(135deg, #0d2442 0%, #1a3a5c 100%);
  color: #ffffff;
  padding: 3rem 2rem;
  text-align: center;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.title-content {
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.title-content h1 {
  color: #ffffff;
  font-size: 1.75rem;
  font-weight: 600;
  border: none;
  padding-bottom: 0;
  margin-top: 0;
  margin-bottom: 0.4em;
  letter-spacing: -0.03em;
}
.title-content h1::after {
  display: none;
}

.title-rule {
  width: 40px;
  height: 3px;
  background: rgba(255,255,255,0.3);
  margin: 0.6rem auto;
  border: none;
  border-radius: 2px;
}

.subtitle {
  font-size: 1rem;
  color: rgba(255,255,255,0.6);
  margin-bottom: 0.3em;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.title-year {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0;
}

.bottom-accent {
  display: none;
}


/* --- Reading Wrapper --- */
.reading {
  max-width: 680px;
  margin: 0 auto;
  padding: 2rem 2rem 4rem;
  text-align: justify;
}


.topic-name {
  display: none;
}

.reading-label {
  font-size: 0.72rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.25em;
  padding-bottom: 0;
  border-bottom: none;
}

/* First h1 inside .reading (chapter title) */
.reading > h1:first-of-type {
  margin-top: 0.25em;
  font-size: 1.65rem;
  letter-spacing: -0.03em;
}

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1.25em 0 1.5em;
  font-size: 0.82rem;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
}

thead {
  background: #0d2442;
  color: #ffffff;
}

thead th {
  padding: 0.65em 0.85em;
  text-align: left;
  font-weight: 600;
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: none;
}

tbody tr {
  transition: background 0.15s;
}

tbody tr:nth-child(odd) {
  background: #f8fafc;
}

tbody tr:nth-child(even) {
  background: #ffffff;
}

tbody tr:hover {
  background: #eef3f9;
}

td {
  padding: 0.55em 0.85em;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
  color: #334155;
}

tbody tr:last-child td {
  border-bottom: none;
}

th {
  padding: 0.55em 0.85em;
}

/* --- Callouts --- */
.callout {
  border: 1px solid #e2e8f0;
  border-left: 4px solid #94a3b8;
  background: #f8fafc;
  border-radius: 0 12px 12px 0;
  padding: 1em 1.15em;
  margin: 1.25em 0;
  font-size: 0.86rem;
  line-height: 1.65;
}

.callout-key-insight {
  border-color: #dbeafe;
  border-left-color: #0d2442;
  background: #f0f4fa;
}

.callout-remember {
  border-color: #dbeafe;
  border-left-color: #0d2442;
  background: #f0f4fa;
}

.callout-watch-out {
  border-color: #fef3c7;
  border-left-color: #d97706;
  background: #fffbeb;
}

.callout-default {
  border-color: #e2e8f0;
  border-left-color: #94a3b8;
  background: #f8fafc;
}

.callout-tag {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.2em 0.6em;
  border-radius: 100px;
  margin-bottom: 0.4em;
  color: #ffffff;
}

.callout-key-insight .callout-tag,
.callout-remember .callout-tag {
  background: #0d2442;
}

.callout-watch-out .callout-tag {
  background: #d97706;
}

.callout-default .callout-tag {
  background: #94a3b8;
}

.callout p {
  color: #334155;
}

.callout p:last-child,
.callout ul:last-child,
.callout ol:last-child {
  margin-bottom: 0;
}

/* --- Formulas --- */
.formula-text {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  font-size: 0.95rem;
  font-weight: 500;
  color: #0d2442;
  margin: 1.25em 0;
  padding: 1em 1.25em;
  flex-wrap: wrap;
}

.formula-text-multiline {
  display: grid;
  grid-template-columns: auto auto auto;
  gap: 0.45em 0.5em;
  justify-content: center;
  align-items: baseline;
  font-size: 0.95rem;
  font-weight: 500;
  color: #0d2442;
  margin: 1.25em 0;
  padding: 1em 1.25em;
}

.formula-text-multiline .formula-lhs {
  grid-column: 1;
  text-align: right;
}
.formula-text-multiline .formula-eq,
.formula-text-multiline .formula-op {
  grid-column: 2;
  text-align: center;
}
.formula-text-multiline .formula-rhs,
.formula-text-multiline .formula-term {
  grid-column: 3;
  text-align: left;
}

.formula-line {
  display: flex;
  align-items: center;
  gap: 0.45em;
}

.formula-lhs {
  font-style: italic;
}

.formula-eq {
  color: #64748b;
  font-weight: 400;
}

.formula-rhs {
  color: #1a2b3c;
}

.formula-op {
  color: #64748b;
  font-weight: 400;
}

/* --- Inline Fractions --- */
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  font-size: 0.85em;
  margin: 0 0.15em;
}

.frac-num {
  border-bottom: 1.5px solid #0d2442;
  padding-bottom: 1px;
  text-align: center;
  line-height: 1.3;
}

.frac-den {
  padding-top: 1px;
  text-align: center;
  line-height: 1.3;
}

/* --- Display Math --- */
.display-math {
  display: block;
  text-align: center;
  font-size: 1rem;
  color: #0d2442;
  margin: 1.25em auto;
  padding: 0.75em 1.25em;
  overflow-x: auto;
}

/* Collapse display-math that only contains a broken file:/// image */
.display-math:has(> img[src^="file:///"]:only-child) {
  display: none;
}

/* --- Inline Math --- */
.math-inline {
  font-style: italic;
  color: #0d2442;
  font-size: 0.92em;
}

/* --- Where / Definition Lists --- */
.where-list {
  margin: 0.5em 0 1em 1em;
  font-size: 0.84rem;
  color: #475569;
}

.where-list dt,
.where-list .where-term {
  font-weight: 600;
  color: #0d2442;
  display: inline;
}

.where-list dd,
.where-list .where-def {
  display: inline;
  margin-left: 0.25em;
}

.where-list > * {
  display: block;
  margin-bottom: 0.2em;
}

/* --- Figures & Diagrams --- */
figure {
  margin: 1.5em 0;
  text-align: center;
}

figure img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

/* Hide images that fail to load (broken file:/// paths) */
figure img[src^="file:///"],
img[src^="file:///"] {
  display: none;
}

figure img:not([src]),
figure img[src=""] {
  display: none;
}

.diagram {
  margin: 1.5em 0;
  text-align: center;
}

.diagram.full-width {
  width: 100%;
  overflow-x: auto;
}

.diagram img {
  max-width: 100%;
  height: auto;
}

.diagram img[src^="file:///"],
.diagram img:not([src]),
.diagram img[src=""] {
  display: none;
}

.figure-label {
  font-size: 0.72rem;
  color: #94a3b8;
  font-style: normal;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.5em;
  text-align: center;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* --- Clickable Images --- */
figure img,
.diagram img {
  cursor: zoom-in;
  transition: opacity 0.15s;
}
figure img:hover,
.diagram img:hover {
  opacity: 0.85;
}

/* --- Image Lightbox Overlay --- */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  cursor: zoom-out;
}
.lightbox-overlay.is-open {
  opacity: 1;
  visibility: visible;
}
.lightbox-img-wrap {
  position: relative;
  max-width: 92vw;
  max-height: 92vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}
.lightbox-img-wrap img {
  max-width: 90vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: 8px;
  transition: transform 0.3s ease;
  transform-origin: center center;
  cursor: grab;
}
.lightbox-img-wrap img.is-zoomed {
  max-width: none;
  max-height: none;
  cursor: grab;
}
.lightbox-close {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10000;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.25);
}
.lightbox-zoom-hint {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.5);
  font-weight: 500;
  letter-spacing: 0.04em;
  pointer-events: none;
  transition: opacity 0.3s;
}

/* ============================================================
   Interactive Components
   ============================================================ */

/* --- Interactive Checklist --- */
.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.6rem 0.65rem;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
  border-radius: 8px;
  margin: 0 -0.65rem;
}
.checklist-item:hover {
  background: #f8fafc;
}
.checklist-item:last-child {
  border-bottom: none;
}
.checklist-item .cl-checkbox {
  width: 20px;
  height: 20px;
  min-width: 20px;
  border: 2px solid #cbd5e1;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.checklist-item .cl-checkbox svg {
  display: none;
  width: 12px;
  height: 12px;
}
.checklist-item.is-checked .cl-checkbox {
  background: #0d2442;
  border-color: #0d2442;
}
.checklist-item.is-checked .cl-checkbox svg {
  display: block;
}
.checklist-item.is-checked .cl-text {
  color: #94a3b8;
  text-decoration: line-through;
  text-decoration-color: #cbd5e1;
}
.checklist-item .cl-text {
  flex: 1;
  transition: color 0.2s;
  line-height: 1.5;
}

/* --- Interactive MCQ --- */
.mcq-block {
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 1.35rem;
  margin: 1.25rem 0;
  background: #fff;
  transition: box-shadow 0.2s;
}
.mcq-block:hover {
  box-shadow: 0 4px 16px rgba(13,36,66,0.06);
}
.mcq-block .mcq-question {
  font-weight: 500;
  color: #0d2442;
  margin-bottom: 0.85rem;
  line-height: 1.65;
}
.mcq-block .mcq-question strong:first-child {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  min-width: 24px;
  border-radius: 50%;
  background: #0d2442;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  margin-right: 0.5rem;
  vertical-align: middle;
}
.mcq-options {
  list-style: none;
  padding: 0;
  margin: 0 0 0.5rem;
}
.mcq-option {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.4rem;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  font-size: 0.86rem;
  line-height: 1.5;
}
.mcq-option:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
}
.mcq-option .mcq-letter {
  width: 26px;
  height: 26px;
  min-width: 26px;
  border-radius: 50%;
  border: 1.5px solid #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #64748b;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.mcq-option .mcq-option-text {
  flex: 1;
  padding-top: 2px;
}
.mcq-option.is-selected {
  border-color: #0d2442;
  background: #f0f4fa;
}
.mcq-option.is-selected .mcq-letter {
  background: #0d2442;
  border-color: #0d2442;
  color: #fff;
}
.mcq-option.is-correct {
  border-color: #10b981;
  background: #ecfdf5;
}
.mcq-option.is-correct .mcq-letter {
  background: #10b981;
  border-color: #10b981;
  color: #fff;
}
.mcq-option.is-wrong {
  border-color: #ef4444;
  background: #fef2f2;
}
.mcq-option.is-wrong .mcq-letter {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}
.mcq-option.is-disabled {
  pointer-events: none;
  opacity: 0.7;
}
.mcq-option.is-correct.is-disabled,
.mcq-option.is-wrong.is-disabled {
  opacity: 1;
}
.mcq-feedback {
  display: none;
  margin-top: 0.85rem;
  padding: 0.85rem 1.1rem;
  border-radius: 10px;
  font-size: 0.84rem;
  line-height: 1.65;
}
.mcq-feedback.is-visible {
  display: block;
}
.mcq-feedback.is-correct-feedback {
  background: #ecfdf5;
  border-left: 4px solid #10b981;
}
.mcq-feedback.is-wrong-feedback {
  background: #fef2f2;
  border-left: 4px solid #ef4444;
}
.mcq-feedback p {
  margin: 0.25em 0;
}
.mcq-feedback p:first-child {
  font-weight: 600;
  color: #0d2442;
}
.mcq-show-answer {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.5rem;
  padding: 0.4rem 0.9rem;
  background: none;
  border: 1.5px solid #e2e8f0;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.mcq-show-answer:hover {
  border-color: #cbd5e1;
  color: #0d2442;
  background: #f8fafc;
}
.mcq-show-answer.is-hidden {
  display: none;
}

/* ===== INDEX / TOC OVERLAY ===== */
.idx-btn {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 900;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 34px;
  padding: 0 0.85rem;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #0d2442;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: all 0.15s;
}
.idx-btn:hover { background: #f8fafc; box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.idx-btn svg { flex-shrink: 0; }

.idx-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 950;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.idx-overlay.is-open { display: block; }

.idx-panel {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 951;
  width: 280px;
  max-width: 80vw;
  height: 100%;
  background: #fff;
  box-shadow: 4px 0 20px rgba(0,0,0,0.1);
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.idx-panel.is-open { transform: translateX(0); }

.idx-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  flex-shrink: 0;
}
.idx-panel-label {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #94a3b8;
}
.idx-panel-close {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: #f8fafc;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all 0.15s;
}
.idx-panel-close:hover { background: #f1f5f9; color: #0d2442; }

.idx-panel-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0.4rem 0;
}
.idx-panel-body::-webkit-scrollbar { width: 3px; }
.idx-panel-body::-webkit-scrollbar-track { background: transparent; }
.idx-panel-body::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 3px; }

.idx-list { list-style: none; margin: 0; padding: 0 0 4.5rem; }

.idx-link {
  display: block;
  padding: 0.4rem 1rem;
  font-size: 0.78rem;
  line-height: 1.4;
  color: #64748b;
  text-decoration: none;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all 0.12s;
}
.idx-link:hover { color: #0d2442; background: #f8fafc; }
.idx-link.is-active {
  color: #0d2442;
  font-weight: 600;
  border-left-color: #0d2442;
  background: #f0f4fa;
}
.idx-link.is-h3 { padding-left: 1.75rem; font-size: 0.73rem; color: #94a3b8; }
.idx-link.is-h3.is-active { color: #0d2442; }

/* ── Mobile overrides ── */
@media (max-width: 640px) {
  .reading {
    text-align: left;
    padding: 1.25rem 1rem 3rem;
  }
  .formula-text {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 0.85rem;
    padding: 0.75em 1em;
    white-space: nowrap;
  }
  .formula-text-multiline {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 0.82rem;
    padding: 0.75em 1em;
  }
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0;
  }
  thead, tbody {
    display: revert;
  }
}
