:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #16202c;
  --ink-soft: #4a5765;
  --line: #e1e6ec;
  --navy: #143250;
  --navy-deep: #0f273e;
  --navy-soft: #2d5b86;
  --accent: #1f6feb;
  --accent-dark: #1a5fd0;
  --correct: #1a7f37;
  --correct-bg: #e9f7ee;
  --wrong: #c0392b;
  --wrong-bg: #fdecea;
  --review: #b7791f;
  --review-bg: #fff7e6;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20,30,45,.08), 0 8px 24px rgba(20,30,45,.05);
  --sidebar-w: 290px;
  --maxw: 880px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px; line-height: 1.6; }
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w); flex: none; background: linear-gradient(180deg, var(--navy), var(--navy-deep));
  color: #dce7f1; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 18px 18px 14px; position: sticky; top: 0;
  background: var(--navy); z-index: 1; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { flex: none; width: 42px; height: 42px; border-radius: 11px; background: #fff; color: var(--navy);
  display: grid; place-items: center; font-weight: 800; font-size: 1rem; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.brand strong { display: block; font-size: 1rem; color: #fff; line-height: 1.2; }
.brand span { font-size: .76rem; opacity: .7; }

.sidenav { padding: 8px 10px 30px; }
.nav-group { margin-bottom: 14px; }
.nav-group-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .8px; font-weight: 700;
  color: #8fb0cf; padding: 8px 10px 6px; }
.nav-item { display: block; width: 100%; text-align: left; background: transparent; border: none; color: #dce7f1;
  padding: 9px 12px; border-radius: 9px; cursor: pointer; transition: background .12s, color .12s; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }
.ni-label { display: block; font-weight: 600; font-size: .92rem; }
.ni-sub { display: block; font-size: .76rem; opacity: .72; margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item.active .ni-sub { opacity: .9; }
.nav-topics { margin: 2px 0 6px 12px; border-left: 2px solid rgba(255,255,255,.14); padding-left: 6px; }
.nav-topic { display: block; color: #aec6de; text-decoration: none; font-size: .82rem; padding: 5px 10px; border-radius: 7px;
  border-left: 2px solid transparent; margin-left: -8px; padding-left: 14px; transition: color .12s, background .12s, border-color .12s; }
.nav-topic:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-topic.active { color: #fff; background: rgba(79,157,255,.18); border-left-color: #4f9dff; font-weight: 600; }

.sidebar-scrim { position: fixed; inset: 0; background: rgba(10,20,30,.45); z-index: 35; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 12px 24px; position: sticky; top: 0; z-index: 20; }
.topbar h1 { margin: 0; font-size: 1.05rem; color: var(--navy); font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-toggle { display: none; background: var(--navy); color: #fff; border: none; border-radius: 8px;
  width: 38px; height: 38px; font-size: 1.1rem; cursor: pointer; flex: none; }

main { flex: 1; padding: 24px 0 90px; }
.section-title { font-size: 1.5rem; margin: 6px 0 2px; color: var(--navy); }
.section-sub { color: var(--ink-soft); margin: 0 0 16px; font-size: .95rem; }
.banner { border-radius: 10px; padding: 12px 16px; margin: 0 0 16px; font-size: .92rem; }
.banner.warn { background: var(--review-bg); border: 1px solid #f0d9a8; color: #7a5512; }
.exam-progress { font-weight: 600; color: var(--navy-soft); margin: 0 0 8px; }

.topic { margin-bottom: 34px; scroll-margin-top: 70px; }
.topic > h3 { font-size: 1.18rem; color: var(--navy); border-bottom: 2px solid var(--navy); padding-bottom: 6px; margin: 0 0 14px; }
.exam-questions > h3 { display: none; }

/* ---------- Notes ---------- */
.notes { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.notes h4 { color: var(--navy-soft); margin: 16px 0 6px; font-size: 1.02rem; }
.notes h4:first-child { margin-top: 0; }
.notes p { margin: 8px 0; }
.notes ul, .notes ol { margin: 8px 0; padding-left: 22px; }
.notes li { margin: 4px 0; }
.tablewrap { overflow-x: auto; }
.notes table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: .92rem; min-width: 420px; }
.notes th { background: var(--navy); color: #fff; text-align: left; padding: 8px 10px; font-weight: 600; }
.notes td { border: 1px solid var(--line); padding: 8px 10px; vertical-align: top; }
.notes tr:nth-child(even) td { background: #f4f7fa; }
.callout { background: var(--review-bg); border: 1px solid #f0d9a8; border-left: 4px solid var(--review); padding: 10px 14px; border-radius: 8px; margin: 12px 0; font-size: .95rem; }
.callout.formula { background: #eef3f8; border-color: #cfe0f0; border-left-color: var(--navy-soft); }
.callout .lbl { font-weight: 700; color: var(--review); margin-right: 6px; text-transform: uppercase; font-size: .72rem; letter-spacing: .5px; }
.callout.formula .lbl { color: var(--navy-soft); }

/* ---------- Questions ---------- */
.q { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.q-head { display: flex; align-items: baseline; gap: 8px; }
.q-num { font-weight: 700; color: var(--navy-soft); flex: none; }
.q-stem { font-weight: 600; }
.q-type { display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: var(--accent); background: #eaf2ff; padding: 2px 8px; border-radius: 6px; margin: 8px 0 4px; }
.q-review { display:inline-block; font-size:.68rem; font-weight:700; color: var(--review); background: var(--review-bg); border:1px solid #f0d9a8; padding:2px 8px; border-radius:6px; margin-left:8px; }
.q-img { display: block; max-width: 100%; height: auto; margin: 12px 0; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

.options { list-style: none; margin: 10px 0 0; padding: 0; }
.opt { display: flex; align-items: flex-start; gap: 10px; border: 1.5px solid var(--line); border-radius: 8px; padding: 11px 13px; margin: 8px 0; cursor: pointer; transition: border-color .12s ease, background .12s ease; }
.opt:hover { border-color: var(--navy-soft); }
.opt.selected { border-color: var(--accent); background: #f3f8ff; }
.opt.chosen { border-color: var(--navy-soft); background: #eef3f8; }
.opt.correct { border-color: var(--correct); background: var(--correct-bg); }
.opt.wrong { border-color: var(--wrong); background: var(--wrong-bg); }
.opt.disabled { cursor: default; }
.opt .marker { flex: none; width: 24px; height: 24px; border-radius: 6px; border: 1.5px solid var(--ink-soft); color: var(--ink-soft); display: grid; place-items: center; font-weight: 700; font-size: .8rem; }
.opt.correct .marker { border-color: var(--correct); color: #fff; background: var(--correct); }
.opt.wrong .marker { border-color: var(--wrong); color: #fff; background: var(--wrong); }
.opt.chosen .marker { border-color: var(--navy-soft); color: #fff; background: var(--navy-soft); }

.order-list { list-style: none; margin: 10px 0 0; padding: 0; }
.order-item { display: flex; align-items: center; gap: 12px; border: 1.5px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 8px 0; background: #fff; }
.order-pos { flex: none; width: 26px; height: 26px; border-radius: 6px; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .82rem; }
.order-txt { flex: 1; }
.order-btns { flex: none; display: flex; flex-direction: column; gap: 2px; }
.ob { border: 1px solid var(--line); background: #f3f6fa; color: var(--navy-soft); width: 28px; height: 20px; border-radius: 5px; cursor: pointer; font-size: .6rem; line-height: 1; }
.ob:hover { background: #e6eef6; }
.ob:disabled { opacity: .4; cursor: default; }

.fill-wrap { margin: 12px 0 2px; }
.fill-input { width: 100%; max-width: 320px; font-size: 1rem; font-family: inherit; padding: 11px 13px; border: 1.5px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--surface); }
.fill-input:focus { outline: none; border-color: var(--accent); background: #f3f8ff; }
.fill-input.correct { border-color: var(--correct); background: var(--correct-bg); }
.fill-input.wrong { border-color: var(--wrong); background: var(--wrong-bg); }

.q-actions { margin-top: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn { border: none; border-radius: 8px; padding: 9px 18px; font-size: .92rem; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: #eef2f6; color: var(--ink-soft); }
.btn-ghost:hover { background: #e2e8ef; }
.btn:disabled { opacity: .5; cursor: default; }

.feedback { margin-top: 12px; padding: 11px 14px; border-radius: 8px; font-size: .95rem; display: none; }
.feedback.show { display: block; }
.feedback.ok { background: var(--correct-bg); border: 1px solid #bfe6cb; color: #145a2a; }
.feedback.no { background: var(--wrong-bg); border: 1px solid #f3c2bc; color: #8e2a1f; }
.feedback.neutral { background: #eef3f8; border: 1px solid #cfe0f0; color: #234; }
.feedback .verdict { font-weight: 700; display: block; margin-bottom: 2px; }

/* ---------- Lectures ---------- */
.player { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 22px; }
.player video { display: block; width: 100%; max-height: 62vh; background: #000; }
.player-meta { padding: 14px 18px; }
.player-meta h3 { margin: 0 0 4px; color: var(--navy); font-size: 1.1rem; }
.lec-topic { margin: 0 0 8px; color: var(--ink-soft); font-size: .9rem; }
.lec-hint { margin: 6px 0; font-size: .86rem; color: var(--wrong); }
.lec-hint:empty { display: none; }
.lec-hint code { background: #f4f6f9; padding: 1px 5px; border-radius: 4px; }
.player-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 6px; }
.winplay { margin: 10px 0 0; padding: 12px 14px; background: #eef3f8; border: 1px solid #cfe0f0; border-left: 4px solid var(--navy-soft); border-radius: 8px; font-size: .88rem; color: #234; }
.winplay code { background: #fff; padding: 1px 5px; border-radius: 4px; }
.lec-listhead { color: var(--navy); margin: 8px 0 10px; }
.lec-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.lec-item { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; cursor: pointer; transition: border-color .12s, background .12s; }
.lec-item:hover { border-color: var(--navy-soft); }
.lec-item.active { border-color: var(--accent); background: #f3f8ff; }
.lec-idx { flex: none; width: 28px; height: 28px; border-radius: 7px; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .82rem; }
.lec-name { flex: 1; font-weight: 600; color: var(--ink); }
.lec-name small { display: block; font-weight: 400; color: var(--ink-soft); font-size: .8rem; margin-top: 2px; }
.lec-size { flex: none; color: var(--ink-soft); font-size: .8rem; }
.lec-note { margin-top: 16px; color: var(--ink-soft); font-size: .85rem; }

/* ---------- Score bar ---------- */
.scorebar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -2px 10px rgba(20,30,45,.06); padding: 12px 0; z-index: 15; }
.scorebar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.score-text { font-weight: 600; }
.score-text b { color: var(--navy); }
.bar { flex: 1; height: 9px; background: #e7ecf1; border-radius: 999px; overflow: hidden; max-width: 320px; }
.bar > span { display: block; height: 100%; width: 0; background: var(--correct); transition: width .25s ease; }

.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--ink-soft); }
footer { text-align: center; color: var(--ink-soft); font-size: .82rem; padding: 24px 0 40px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 4px 0 20px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: block; }
  .wrap { padding: 0 18px; }
}
@media (min-width: 861px) { .sidebar-scrim { display: none !important; } }

.nav-item:focus-visible, .nav-topic:focus-visible, .opt:focus-visible, .btn:focus-visible, .lec-item:focus-visible, .menu-toggle:focus-visible {
  outline: 3px solid #9ec5ff; outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto; } }
