/* ============ FE Prep styles ============ */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --border: #dfe3ee;
  --text: #1c2333;
  --text-dim: #5b6478;
  --accent: #4f6df5;
  --accent-soft: #e6ebff;
  --green: #1f9d63;
  --green-soft: #e2f6ec;
  --red: #d64550;
  --red-soft: #fdeaec;
  --amber: #c98a12;
  --amber-soft: #fdf3dd;
  --sidebar-bg: #171d2e;
  --sidebar-text: #b8c0d8;
  --sidebar-active: #232c47;
  --code-bg: #f0f2f8;
  --shadow: 0 1px 3px rgba(20, 25, 45, 0.08), 0 4px 16px rgba(20, 25, 45, 0.06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151f;
    --surface: #1a1f2e;
    --surface-2: #232940;
    --border: #2d3450;
    --text: #e6e9f2;
    --text-dim: #9aa3bd;
    --accent: #7b93ff;
    --accent-soft: #232c4d;
    --green: #3ecf8e;
    --green-soft: #16302a;
    --red: #ff7b85;
    --red-soft: #3a1e24;
    --amber: #eab54e;
    --amber-soft: #34290f;
    --sidebar-bg: #0e1119;
    --sidebar-text: #8f99b5;
    --sidebar-active: #1c2233;
    --code-bg: #10141f;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

#app-shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; cursor: pointer; }
.brand-icon { font-size: 28px; }
.brand-title { font-weight: 700; font-size: 18px; color: #fff; }
.brand-sub { font-size: 11.5px; opacity: .75; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--sidebar-text); text-decoration: none;
  font-size: 14px; font-weight: 500;
}
.nav-link:hover { background: var(--sidebar-active); color: #fff; }
.nav-link.active { background: var(--sidebar-active); color: #fff; }
.nav-icon { width: 20px; text-align: center; }
.nav-sections-label {
  margin: 16px 12px 6px; font-size: 11px; letter-spacing: .08em;
  text-transform: uppercase; opacity: .6;
}
.nav-section-link {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 8px;
  color: var(--sidebar-text); text-decoration: none; font-size: 13px;
}
.nav-section-link:hover { background: var(--sidebar-active); color: #fff; }
.nav-section-num {
  font-size: 11px; background: var(--sidebar-active);
  border-radius: 6px; padding: 1px 6px; flex-shrink: 0;
}
.sidebar-footer { margin-top: auto; padding-top: 20px; }

#mobile-menu-btn {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 60;
  background: var(--sidebar-bg); color: #fff; border: none;
  font-size: 20px; padding: 8px 12px; border-radius: 10px; cursor: pointer;
  box-shadow: var(--shadow);
}

/* ---------- Main ---------- */
#main { flex: 1; padding: 32px clamp(16px, 4vw, 48px); max-width: 1100px; width: 100%; margin: 0 auto; min-width: 0; }
h1 { font-size: 26px; margin: 0 0 6px; }
h2 { font-size: 20px; margin: 28px 0 10px; }
.page-sub { color: var(--text-dim); margin: 0 0 24px; font-size: 14.5px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; margin-bottom: 16px;
}
.card.clickable { cursor: pointer; transition: transform .12s ease, border-color .12s ease; }
.card.clickable:hover { transform: translateY(-2px); border-color: var(--accent); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

.section-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 3px 10px;
  border-radius: 20px; background: var(--accent-soft); color: var(--accent);
}
.muted { color: var(--text-dim); font-size: 13.5px; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: #fff; border: none;
  padding: 10px 18px; border-radius: 10px; font-size: 14.5px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: filter .1s;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.green { background: var(--green); }
.btn.red { background: var(--red); }
.btn.small, .btn-ghost.small { padding: 6px 12px; font-size: 13px; }
.btn-ghost {
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 14px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }

/* ---------- Progress bars ---------- */
.pbar { height: 8px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.pbar > div { height: 100%; background: var(--accent); border-radius: 6px; transition: width .3s; }
.pbar.green > div { background: var(--green); }

/* ---------- Lesson content ---------- */
.lesson-body { font-size: 15.5px; }
.lesson-body h3 { font-size: 18px; margin: 26px 0 8px; }
.lesson-body h4 { font-size: 15.5px; margin: 20px 0 6px; }
.lesson-body p { margin: 10px 0; }
.lesson-body ul, .lesson-body ol { margin: 8px 0; padding-left: 24px; }
.lesson-body li { margin: 4px 0; }
.lesson-body code {
  background: var(--code-bg); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 6px; font-size: 13.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.lesson-body pre {
  background: var(--code-bg); border: 1px solid var(--border);
  padding: 14px 16px; border-radius: 10px; overflow-x: auto;
  font-size: 13.5px; line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.lesson-body pre code { background: none; border: none; padding: 0; }
.lesson-body table { border-collapse: collapse; margin: 12px 0; font-size: 14px; }
.lesson-body th, .lesson-body td { border: 1px solid var(--border); padding: 6px 12px; text-align: left; }
.lesson-body th { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.lesson-body .callout {
  border-left: 4px solid var(--accent); background: var(--accent-soft);
  padding: 10px 16px; border-radius: 0 10px 10px 0; margin: 14px 0;
}
.lesson-body .callout.warn { border-color: var(--amber); background: var(--amber-soft); }
.lesson-body .formula {
  background: var(--surface-2); border: 1px dashed var(--border);
  padding: 10px 16px; border-radius: 10px; margin: 12px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px;
}

/* ---------- Flashcards ---------- */
.flashcard-stage { display: flex; flex-direction: column; align-items: center; gap: 18px; margin-top: 12px; }
.flashcard {
  width: 100%; max-width: 640px; min-height: 300px;
  perspective: 1200px; cursor: pointer;
}
.flashcard-inner {
  position: relative; width: 100%; min-height: 300px;
  transform-style: preserve-3d; transition: transform .45s;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px 32px; text-align: center; overflow-y: auto;
}
.flashcard-face.back { transform: rotateY(180deg); background: var(--surface); }
.flashcard-face .fc-label {
  position: absolute; top: 12px; left: 16px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .1em; color: var(--text-dim);
}
.fc-front-text { font-size: 20px; font-weight: 600; }
.fc-back-text { font-size: 16px; }
.fc-controls { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.fc-counter { font-size: 13.5px; color: var(--text-dim); }

/* ---------- Quiz / Exam ---------- */
.choice {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1.5px solid var(--border); border-radius: 10px;
  padding: 12px 16px; margin: 8px 0; cursor: pointer;
  background: var(--surface); font-size: 15px;
  transition: border-color .1s, background .1s;
}
.choice:hover { border-color: var(--accent); }
.choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.choice.correct { border-color: var(--green); background: var(--green-soft); }
.choice.incorrect { border-color: var(--red); background: var(--red-soft); }
.choice.dim { opacity: .6; }
.choice-letter {
  font-weight: 700; flex-shrink: 0; width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); border-radius: 7px; font-size: 13px;
}
.choice.correct .choice-letter { background: var(--green); color: #fff; }
.choice.incorrect .choice-letter { background: var(--red); color: #fff; }
.q-text { font-size: 16.5px; font-weight: 600; margin: 4px 0 14px; }
.q-text code, .choice code {
  background: var(--code-bg); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em;
}
.q-text pre, .explanation pre {
  background: var(--code-bg); border: 1px solid var(--border);
  padding: 12px 14px; border-radius: 10px; overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px; text-align: left;
}
.explanation {
  margin-top: 14px; padding: 14px 18px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 14.5px;
}
.explanation.good { border-left: 4px solid var(--green); }
.explanation.bad { border-left: 4px solid var(--red); }
.quiz-topbar { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.exam-timer {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 17px; font-weight: 700; padding: 6px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.exam-timer.low { color: var(--red); border-color: var(--red); }
.q-nav { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; }
.q-nav button {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 12.5px; font-weight: 600;
}
.q-nav button.answered { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.q-nav button.current { outline: 2px solid var(--accent); }
.q-nav button.flagged { background: var(--amber-soft); border-color: var(--amber); color: var(--amber); }
.q-nav button.res-right { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.q-nav button.res-wrong { background: var(--red-soft); border-color: var(--red); color: var(--red); }

/* ---------- Results ---------- */
.score-hero { text-align: center; padding: 30px 20px; }
.score-big { font-size: 52px; font-weight: 800; }
.score-big.pass { color: var(--green); }
.score-big.warn { color: var(--amber); }
.score-big.fail { color: var(--red); }
.stat-row { display: flex; gap: 14px; flex-wrap: wrap; margin: 18px 0; }
.stat-tile {
  flex: 1; min-width: 130px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px; text-align: center;
}
.stat-tile .num { font-size: 26px; font-weight: 700; }
.stat-tile .lbl { font-size: 12.5px; color: var(--text-dim); }

.topic-pill {
  display: inline-block; font-size: 11.5px; padding: 2px 9px;
  background: var(--surface-2); border-radius: 12px; color: var(--text-dim); margin-left: 8px;
}
.badge-known { color: var(--green); font-weight: 600; font-size: 13px; }

hr.sep { border: none; border-top: 1px solid var(--border); margin: 22px 0; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  #sidebar {
    position: fixed; z-index: 50; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform .25s ease;
    width: 270px; height: 100vh;
  }
  #sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.4); }
  #mobile-menu-btn { display: block; }
  #main { padding-top: 64px; }
}
