:root {
  color-scheme: light;
  --navy-950: #102334;
  --navy-900: #172c40;
  --navy-800: #24435d;
  --sky-500: #38aee2;
  --sky-100: #e8f6fc;
  --cyan-50: #f2fbff;
  --ink: #203243;
  --muted: #647586;
  --line: #dce5eb;
  --panel: #f6f8fa;
  --green: #2f9960;
  --red: #ca4b50;
  --amber: #d99a2b;
  --shadow: 0 12px 30px rgba(24, 49, 69, 0.08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #eef4f7; color: var(--ink); }
button, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template: 4rem 1fr 4.75rem / 4.5rem minmax(0, 1fr);
  background: white;
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 1rem;
  background: var(--navy-900);
  color: white;
  box-shadow: 0 1px 0 rgba(255,255,255,.12);
  z-index: 4;
}

.brand, .session-meta, .tool-button, .top-actions { display: flex; align-items: center; }
.brand { gap: .65rem; font-weight: 750; letter-spacing: -.01em; }
.brand-mark {
  display: grid; place-items: center; width: 2rem; height: 2rem;
  border: 1px solid rgba(255,255,255,.65); border-radius: .42rem;
  color: var(--sky-500); font-weight: 900;
}
.session-meta { gap: 1rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
.session-title { color: #d6e2ea; text-transform: none; letter-spacing: normal; font-size: .86rem; border: 0; background: transparent; padding: .55rem; border-radius: .35rem; }
.session-title:hover { background: rgba(255,255,255,.08); }
.timer-label { color: #a7bac8; }
.timer { font-variant-numeric: tabular-nums; }
.top-actions { justify-self: end; gap: .25rem; }
.tool-button {
  gap: .8rem; min-height: 2.5rem; color: white; background: transparent;
  border: 0; padding: 0 .55rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em;
}

.question-rail {
  grid-row: 2; display: flex; flex-direction: column; align-items: stretch;
  background: #f4f7f8; border-right: 1px solid var(--line); overflow-y: auto;
}
.question-rail nav { display: grid; gap: .35rem; padding: .35rem .5rem; }
.rail-collapse { border: 0; background: transparent; color: var(--muted); min-height: 2.25rem; }
.nav-question {
  width: 2.55rem; height: 2.55rem; margin: 0 auto; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted); position: relative;
}
.nav-question:hover { background: #e7edf1; }
.nav-question.active { background: var(--green); color: white; font-weight: 800; box-shadow: 0 0 0 4px #dcefe5; }
.nav-question.answered:not(.active)::after {
  content: "✓"; position: absolute; right: -.05rem; bottom: -.05rem; width: 1rem; height: 1rem;
  display: grid; place-items: center; background: var(--green); color: white; border-radius: 999px; font-size: .65rem;
}
.nav-question.flagged::before { content: "•"; color: var(--amber); position: absolute; top: -.18rem; right: .1rem; font-size: 1.4rem; }

.exam-canvas {
  grid-row: 2; padding: clamp(1.4rem, 4vw, 3.5rem) clamp(1.25rem, 6vw, 6.5rem) 3rem;
  overflow-y: auto; min-width: 0;
}
.question-header { display: flex; justify-content: space-between; align-items: start; gap: 1rem; margin-bottom: 1.4rem; }
.eyebrow { margin: 0 0 .4rem; color: var(--sky-500); font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .09em; }
h1 { margin: 0; font-size: 1rem; color: var(--muted); font-weight: 700; }
.flag-button { border: 1px solid var(--line); border-radius: .5rem; padding: .6rem .8rem; color: var(--muted); background: white; }
.flag-button[aria-pressed="true"] { color: #8a5b00; background: #fff7df; border-color: #f2d48d; }
.question-card { max-width: 76rem; }
.stem p { margin: 0 0 .9rem; }
.stem .lead-question { margin-top: 1.15rem; font-weight: 650; }
.stem { font-size: 1.075rem; line-height: 1.72; margin: 0 0 1.4rem; max-width: 74ch; }
.question-figure { margin: 0 0 1.4rem; max-width: min(48rem, 100%); }
.question-figure img { display: block; max-width: 100%; max-height: 32rem; width: auto; border: 1px solid var(--line); border-radius: .6rem; object-fit: contain; background: white; }
.question-figure figcaption { margin-top: .45rem; color: var(--muted); font-size: .76rem; }
mark { background: #ffe66b; color: inherit; border-radius: .1rem; padding: 0 .05em; }
.choices { display: grid; gap: .7rem; max-width: 68rem; }
.choice-wrap { display: grid; grid-template-columns: 1fr 2.7rem; align-items: center; gap: .45rem; }
.choice {
  width: 100%; display: grid; grid-template-columns: 2rem 1fr; align-items: center; gap: .25rem;
  border: 2px solid transparent; border-radius: 999px; background: var(--panel); min-height: 3.3rem;
  padding: .35rem .6rem; color: var(--ink); text-align: left;
}
.choice:hover { border-color: #b7dff0; }
.choice.selected { border-color: var(--sky-500); background: var(--cyan-50); box-shadow: 0 4px 14px rgba(56,174,226,.1); }
.choice.correct { border-color: #80c89e; background: #effaf3; }
.choice.incorrect { border-color: #e19a9d; background: #fff3f3; }
.choice-letter {
  width: 1.8rem; height: 1.8rem; display: grid; place-items: center; border: 1px solid #ccd7de;
  border-radius: 999px; background: white; color: var(--muted); font-weight: 800; font-size: .78rem;
}
.choice-tool { width: 2.55rem; height: 2.55rem; border: 1px solid var(--line); border-radius: 999px; background: white; color: #81909c; font-size: 1rem; }
.choice-tool:hover { border-color: #9fcfe3; color: var(--navy-800); }
.choice-tool:disabled { opacity: .4; cursor: not-allowed; }
.choice.struck .choice-text { text-decoration: line-through; color: #8d9aa4; }
.explanation { margin-top: 1.5rem; border: 1px solid #bfe2f0; border-radius: .85rem; overflow: hidden; box-shadow: var(--shadow); }
.explanation-copy { padding: 1.25rem 1.35rem; background: #f2fbff; }
.explanation h2 { margin: 0 0 .55rem; color: var(--navy-900); font-size: 1.05rem; }
.explanation p { margin: .45rem 0; line-height: 1.58; }
.source-placeholder { padding: 1rem 1.35rem; border-top: 1px solid #cfe8f2; background: white; color: var(--muted); }
.source-slide { padding: 1rem 1.35rem 1.35rem; border-top: 1px solid #cfe8f2; background: white; }
.source-slide p { color: var(--muted); font-size: .82rem; }
.source-slide img { display: block; width: min(100%, 60rem); border: 1px solid var(--line); border-radius: .55rem; box-shadow: var(--shadow); }

.tool-drawer {
  position: fixed; z-index: 6; right: 1rem; top: 4.5rem; width: min(22rem, calc(100vw - 2rem));
  padding: 1.2rem; border: 1px solid var(--line); border-radius: .75rem; background: white; box-shadow: 0 18px 55px rgba(20,43,62,.2);
}
.review-drawer {
  position: fixed; z-index: 7; right: 0; top: 4rem; bottom: 4.75rem; width: min(28rem, 100vw);
  padding: 1.15rem; background: white; border-left: 1px solid var(--line); box-shadow: -16px 0 45px rgba(20,43,62,.18); overflow-y: auto;
}
.drawer-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.drawer-heading h2 { margin: 0; font-size: 1.05rem; }
.drawer-heading button { border: 0; background: transparent; font-size: 1.5rem; color: var(--muted); }
.score-card { margin: 1rem 0; padding: 1rem; border-radius: .75rem; background: var(--navy-900); color: white; }
.score-card strong { display: block; font-size: 2rem; }
.score-card span { color: #c9d6df; font-size: .82rem; }
.review-list { display: grid; gap: .5rem; }
.review-item { display: grid; grid-template-columns: 2.2rem 1fr auto; align-items: center; gap: .65rem; padding: .65rem; border: 1px solid var(--line); border-radius: .55rem; background: white; text-align: left; }
.review-item:hover { border-color: #a8d7e9; }
.review-status { width: 1.75rem; height: 1.75rem; display: grid; place-items: center; border-radius: 999px; background: #eef2f5; color: var(--muted); font-size: .72rem; font-weight: 800; }
.review-status.correct { background: #e2f4e9; color: var(--green); }
.review-status.incorrect { background: #fde9e9; color: var(--red); }
.review-status.unanswered { background: #fff4da; color: #8a5b00; }
.review-item small { color: var(--muted); }

.launch-dialog { width: min(72rem, calc(100vw - 2rem)); max-height: min(52rem, calc(100vh - 2rem)); padding: 0; border: 0; border-radius: 1rem; box-shadow: 0 30px 90px rgba(12,34,50,.3); }
.launch-dialog::backdrop { background: rgba(12,32,47,.7); backdrop-filter: blur(5px); }
.launch-hero { padding: 1.7rem 1.8rem 1.25rem; color: white; background: linear-gradient(125deg, var(--navy-950), var(--navy-800)); }
.launch-hero h2 { margin: .2rem 0 .55rem; font-size: clamp(1.55rem, 4vw, 2.35rem); letter-spacing: -.035em; }
.launch-hero p:last-child { max-width: 65ch; margin: 0; color: #cfdae2; line-height: 1.55; }
.lecture-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .7rem; padding: 1rem; background: #eef4f7; max-height: 34rem; overflow-y: auto; }
.lecture-option { min-height: 7rem; padding: 1rem; border: 1px solid var(--line); border-radius: .7rem; background: white; text-align: left; color: var(--ink); box-shadow: 0 5px 14px rgba(20,43,62,.04); }
.lecture-option:hover { transform: translateY(-1px); border-color: var(--sky-500); box-shadow: var(--shadow); }
.lecture-option strong { display: block; margin-bottom: .45rem; line-height: 1.3; }
.lecture-option span { color: var(--muted); font-size: .78rem; }
.lecture-option.comprehensive { color: white; border-color: var(--navy-800); background: var(--navy-800); }
.lecture-option.comprehensive span { color: #cfdae2; }
.toast { position: fixed; z-index: 10; left: 50%; bottom: 6rem; transform: translateX(-50%); padding: .75rem 1rem; border-radius: .5rem; background: var(--navy-950); color: white; box-shadow: var(--shadow); }
.tool-drawer h2 { margin: 0 0 1rem; font-size: 1rem; }
.tool-drawer button { width: 100%; border: 1px solid var(--line); border-radius: .45rem; background: white; color: var(--ink); padding: .7rem; margin-bottom: .55rem; text-align: left; }
.tool-drawer label { display: block; margin: .7rem 0 .35rem; color: var(--muted); font-size: .82rem; font-weight: 700; }
.tool-drawer textarea { width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: .45rem; padding: .7rem; }
.calculator-row { display: grid; grid-template-columns: 1fr 3rem; gap: .4rem; }
.calculator-row input { min-width: 0; border: 1px solid var(--line); border-radius: .45rem; padding: .65rem; }
.calculator-row button { margin: 0; text-align: center; }
.tool-drawer output { display: block; min-height: 2rem; padding: .4rem .1rem; color: var(--navy-800); font-weight: 800; }

.bottombar {
  grid-column: 1 / -1; display: grid; grid-template-columns: auto minmax(10rem, 1fr) auto; align-items: center; gap: 1.2rem;
  padding: .75rem 1rem; border-top: 1px solid #cde2ea; background: #e9f8fd; z-index: 4;
}
.progress-copy { display: grid; min-width: 10.5rem; }
.progress-copy strong { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.progress-copy span { color: var(--muted); font-size: .76rem; }
.progress-track { height: .4rem; border-radius: 999px; background: #cae4ed; overflow: hidden; }
.progress-track span { display: block; width: 10%; height: 100%; background: var(--sky-500); transition: width .25s ease; }
.footer-actions { display: flex; gap: .7rem; }
.button { border: 0; min-width: 7rem; padding: .78rem 1.1rem; border-radius: .25rem; color: white; font-weight: 750; }
.button.secondary { background: var(--navy-800); }
.button.primary { background: var(--sky-500); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.large-text .stem { font-size: 1.3rem; }
.large-text .choice { font-size: 1.1rem; }

@media (max-width: 760px) {
  .app-shell { grid-template: 3.7rem 1fr 6.5rem / 1fr; }
  .topbar { grid-template-columns: 1fr auto; }
  .session-meta { gap: .4rem; }
  .session-title, .timer-label { display: none; }
  .tool-button { font-size: 0; width: 2.5rem; padding: 0; justify-content: center; }
  .tool-button span { font-size: 1.3rem; }
  .question-rail { display: none; }
  .exam-canvas { grid-column: 1; padding: 1.25rem 1rem 2rem; }
  .bottombar { grid-template-columns: 1fr auto; gap: .65rem; }
  .progress-track { grid-column: 1 / -1; grid-row: 1; }
  .progress-copy { grid-row: 2; min-width: 0; }
  .footer-actions { grid-row: 2; }
  .button { min-width: 5.5rem; }
  .lecture-grid { grid-template-columns: 1fr; }
  .review-drawer { top: 3.7rem; bottom: 6.5rem; }
}
