:root {
  color-scheme: light;
  --bg: #f5f1f8;
  --panel: #ffffff;
  --ink: #21182d;
  --muted: #71667e;
  --line: #e3dbe9;
  --accent: #6d3f91;
  --accent-strong: #51296f;
  --accent-soft: #f0e7f7;
  --peach: #e87855;
  --good: #19704d;
  --good-soft: #eaf6ef;
  --bad: #b13f4d;
  --bad-soft: #fbebed;
  --shadow: 0 18px 50px rgba(60, 35, 78, 0.12);
}

* { box-sizing: border-box; }
html {
  min-height: 100%;
  overflow-y: scroll;
  scrollbar-gutter: stable;
}
body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 76% 2%, rgba(232, 120, 85, 0.12), transparent 29rem),
    radial-gradient(circle at 2% 98%, rgba(109, 63, 145, 0.12), transparent 30rem),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button { border: 1px solid var(--line); border-radius: 10px; background: white; color: var(--ink); cursor: pointer; }
button:hover { border-color: #bfaecb; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(109, 63, 145, 0.22); outline-offset: 2px; }

.app-shell { display: grid; grid-template-columns: 360px minmax(0, 1fr); min-height: 100vh; }
.question-rail {
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
  border-right: 1px solid var(--line); background: rgba(255,255,255,.93); backdrop-filter: blur(14px);
}
.rail-header { display: flex; gap: 14px; align-items: center; padding: 24px 22px 18px; }
.brand-mark {
  display: grid; width: 50px; height: 50px; place-items: center; flex: none;
  border-radius: 15px; background: linear-gradient(145deg, var(--accent), #9d68bd);
  box-shadow: 0 9px 20px rgba(81,41,111,.22); color: white; font-family: Georgia, serif; font-size: 21px; font-weight: 800;
}
.rail-header h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 25px; line-height: 1.05; }
.rail-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.field { display: grid; gap: 6px; padding: 0 22px 14px; }
.field span { color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.field input, .field select { width: 100%; height: 43px; border: 1px solid var(--line); border-radius: 10px; background: #fbf9fc; color: var(--ink); padding: 0 11px; }
.filter-row { display: grid; grid-template-columns: 1.5fr 1fr; }
.filter-row .field:first-child { padding-right: 6px; }
.filter-row .field:last-child { padding-left: 6px; }
.rail-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; padding: 0 22px 13px; }
.rail-actions button { min-height: 38px; padding: 6px; font-size: 12px; font-weight: 750; }
.rail-actions button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }
.rail-meta { display: flex; justify-content: space-between; padding: 0 22px 11px; color: var(--muted); font-size: 12px; font-weight: 700; }
.rail-note { margin: 0 22px 10px; border-left: 3px solid #d7c0e4; padding-left: 9px; color: #887b90; font-size: 11px; line-height: 1.4; }
.question-list { min-height: 0; overflow: auto; margin: 0; padding: 0 12px 22px; list-style: none; scrollbar-width: thin; }
.question-list li { margin: 3px 0; }
.question-list button { display: grid; grid-template-columns: 44px minmax(0,1fr); gap: 8px; width: 100%; border-color: transparent; background: transparent; padding: 9px 10px; text-align: left; }
.question-list button:hover { background: #f7f1fa; }
.question-list button.active { border-color: #dac8e6; background: var(--accent-soft); }
.question-list button.correct .list-number { color: var(--good); }
.question-list button.incorrect .list-number { color: var(--bad); }
.question-list button.review .list-number::after { content: " •"; color: var(--peach); }
.list-number { color: var(--muted); font-size: 12px; font-weight: 850; letter-spacing: .05em; }
.list-text { display: -webkit-box; overflow: hidden; color: #463c50; font-size: 13px; line-height: 1.35; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }
.topbar {
  display: grid; grid-template-columns: auto minmax(90px, 1fr) auto auto auto; gap: 10px; align-items: center;
  min-height: 66px; border-bottom: 1px solid rgba(227,219,233,.86); background: rgba(245,241,248,.72); padding: 12px 18px; backdrop-filter: blur(12px);
}
.compact-button { min-height: 39px; padding: 0 13px; color: #564661; font-size: 13px; font-weight: 750; }
.progress-wrap { height: 10px; overflow: hidden; border-radius: 999px; background: #e7deeb; }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--peach)); transition: width 180ms ease; }
.slide {
  align-self: center; width: min(1040px, calc(100% - 48px)); margin: clamp(18px,4vh,42px) auto 24px;
  border: 1px solid rgba(217,204,226,.9); border-radius: 20px; background: rgba(255,255,255,.96);
  box-shadow: var(--shadow); padding: clamp(24px,4.4vw,52px);
}
.slide-kicker { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; font-weight: 800; }
.question-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.topic-pill { border: 1px solid #dccbe7; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); padding: 6px 10px; }
.review-button { min-height: 31px; border-color: #e2d7e8; border-radius: 999px; padding: 5px 11px; color: #66596f; font-size: 12px; font-weight: 800; }
.review-button.active { border-color: rgba(232,120,85,.65); background: #fff2ec; color: #99462d; }
.source-line { margin-top: 8px; color: #8b7e95; font-size: 12px; font-weight: 650; }
.slide h2 { margin: 22px 0 26px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(27px,3.1vw,43px); line-height: 1.17; font-weight: 700; letter-spacing: -.018em; }
.options { display: grid; gap: 11px; margin: 0; padding: 0; list-style: none; }
.option {
  display: grid; grid-template-columns: 38px minmax(0,1fr); gap: 13px; align-items: start; min-height: 58px;
  border: 1px solid var(--line); border-radius: 13px; background: #fff; padding: 12px 14px; cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}
.option:hover { border-color: #bfaecb; transform: translateY(-1px); }
.option:focus-visible { outline: 3px solid rgba(109,63,145,.22); outline-offset: 2px; }
.option-key { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 10px; background: #f0ebf3; color: var(--muted); font-weight: 850; text-transform: uppercase; }
.option-text { align-self: center; line-height: 1.4; }
.option.correct { border-color: rgba(25,112,77,.5); background: var(--good-soft); }
.option.correct .option-key { background: var(--good); color: white; }
.option.incorrect { border-color: rgba(177,63,77,.52); background: var(--bad-soft); color: #772e39; }
.option.incorrect .option-key { background: var(--bad); color: white; }
.option.incorrect[aria-disabled="true"] { cursor: default; }
.option.incorrect[aria-disabled="true"]:hover { transform: none; }
.option.dimmed { background: #faf7fb; color: #8a7c91; }
.answer-panel { margin-top: 24px; border-left: 5px solid var(--good); border-radius: 14px; background: var(--good-soft); padding: 19px 21px; }
.answer-label { margin: 0 0 5px; color: var(--good); font-size: 12px; font-weight: 900; letter-spacing: .07em; text-transform: uppercase; }
.answer-panel h3 { margin: 0 0 9px; font-size: clamp(20px,2.2vw,29px); }
.answer-panel > p { margin: 0; color: #2e463d; font-size: 16px; line-height: 1.52; }
.answer-panel .source-note { margin-top: 13px; border-top: 1px solid rgba(25,112,77,.17); padding-top: 11px; color: #5c685f; font-size: 14px; font-style: italic; }
.controls { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; margin-top: auto; padding: 16px 18px 21px; }
.controls button { min-height: 49px; padding: 0 19px; font-weight: 780; }
.controls .primary { min-width: min(320px,46vw); border-color: var(--accent); background: var(--accent); color: white; }
.controls .primary:hover { background: var(--accent-strong); }
#revealButton { grid-column: 2; justify-self: center; }
#prevButton, #nextButton {
  position: fixed; z-index: 3; top: 50%; min-width: 110px;
  transform: translateY(-50%); border-color: #d9cee1; background: rgba(255,255,255,.95);
  box-shadow: 0 10px 28px rgba(60,35,78,.13); backdrop-filter: blur(10px);
}
#prevButton { left: max(372px, calc(360px + (100vw - 360px - 1040px) / 2 - 128px)); }
#nextButton { right: max(12px, calc((100vw - 360px - 1040px) / 2 - 128px)); }
.rail-collapsed #prevButton { left: max(12px, calc((100vw - 1040px) / 2 - 128px)); }
.rail-collapsed #nextButton { right: max(12px, calc((100vw - 1040px) / 2 - 128px)); }
.is-presenting #prevButton { left: max(12px, calc((100vw - 1180px) / 2 - 128px)); }
.is-presenting #nextButton { right: max(12px, calc((100vw - 1180px) / 2 - 128px)); }

.is-presenting .question-rail, .rail-collapsed .question-rail { display: none; }
.is-presenting .app-shell, .rail-collapsed .app-shell { grid-template-columns: 1fr; }
.is-presenting .slide { width: min(1180px, calc(100% - 56px)); }

@media (min-width: 921px) and (max-width: 1679px) {
  #prevButton, #nextButton { width: 48px; min-width: 48px; height: 48px; padding: 0; border-radius: 50%; font-size: 0; }
  #prevButton::before { content: "‹"; font-size: 30px; line-height: 1; }
  #nextButton::before { content: "›"; font-size: 30px; line-height: 1; }
  #prevButton { left: max(368px, calc(360px + (100vw - 360px - 1040px) / 2 - 66px)); }
  #nextButton { right: max(8px, calc((100vw - 360px - 1040px) / 2 - 66px)); }
  .rail-collapsed #prevButton { left: max(8px, calc((100vw - 1040px) / 2 - 66px)); }
  .rail-collapsed #nextButton { right: max(8px, calc((100vw - 1040px) / 2 - 66px)); }
  .is-presenting #prevButton { left: max(8px, calc((100vw - 1180px) / 2 - 66px)); }
  .is-presenting #nextButton { right: max(8px, calc((100vw - 1180px) / 2 - 66px)); }
}

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .question-rail { position: fixed; z-index: 5; inset: 0 auto 0 0; width: min(380px,94vw); box-shadow: var(--shadow); transform: translateX(-105%); transition: transform 180ms ease; }
  .rail-open .question-rail { transform: translateX(0); }
  .topbar { grid-template-columns: auto minmax(70px,1fr) auto; }
  #showAllButton, #printButton { display: none; }
  .slide { width: calc(100% - 26px); margin-top: 13px; padding: 21px; border-radius: 16px; }
  .slide h2 { font-size: 26px; }
  .controls { grid-template-columns: 1fr 1fr; }
  .controls .primary { grid-column: 1 / -1; grid-row: 1; min-width: 0; }
  .controls button { width: 100%; }
  #prevButton, #nextButton {
    position: static; width: 100%; min-width: 0; height: auto; transform: none;
    border-radius: 10px; padding: 0 19px; font-size: inherit; box-shadow: none; backdrop-filter: none;
  }
  #prevButton { grid-column: 1; grid-row: 2; }
  #nextButton { grid-column: 2; grid-row: 2; }
}

@media (max-width: 520px) {
  .compact-button { padding: 0 9px; font-size: 12px; }
  .slide { padding: 18px; }
  .slide h2 { margin-top: 17px; font-size: 23px; }
  .option { grid-template-columns: 34px minmax(0,1fr); padding: 11px; }
  .option-key { width: 32px; height: 32px; }
  .question-actions { width: 100%; justify-content: space-between; }
}

@media print {
  body { background: white; }
  .question-rail, .topbar, .controls { display: none !important; }
  .app-shell, .stage { display: block; min-height: auto; }
  .slide { width: 100%; margin: 0; border: 0; box-shadow: none; padding: 0; }
  .answer-panel { display: block !important; }
}
