/* Bluebook-alike chrome. Sans for UI, serif for question content. White bands
   separated from the work area by the Bluebook "torn ticket" zigzag rules. */

:root {
  --band: #ffffff;
  --ink: #1e1e1e;
  --ink-soft: #4a4a4a;
  --line: #767676;
  --blue: #2c4bce;
  --blue-dark: #17389c;
  --navy: #1b2a63;
  --focus: #e08b1e;
  --green: #1a7f37;
  --red: #c0392b;
  --sans: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Source Serif Pro", "Georgia", "Times New Roman", serif;
  --qfont: 17px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--sans);
  color: var(--ink);
  background: #fff;
}

button { font: inherit; color: inherit; cursor: pointer; }
img { max-width: 100%; }

/* ---------- typed-out content ---------- */

/* Figures are SVGs redrawn from the source data (never PDF crops). */
.figwrap { text-align: center; margin: 16px 0; }
.figwrap img.fig { display: inline-block; max-width: 100%; height: auto; }
.figwrap .fignote {
  font-family: var(--serif); font-size: 14px; color: var(--ink-soft);
  margin-top: 4px; font-style: italic;
}
.fig-missing { color: var(--red); font-family: var(--sans); font-size: 13px; }

/* Display math on its own line */
.dmath { margin: 14px 0; overflow-x: auto; overflow-y: hidden; }
.dmath .katex-display { margin: 0; text-align: left; }
.dmath .katex-display > .katex { text-align: left; }

/* KaTeX sits slightly small against Source Serif */
.stem .katex, .ctext .katex, .rationale .katex, .prompt .katex { font-size: 1.05em; }

/* Data tables, College Board style */
.qtable-wrap { margin: 16px 0; overflow-x: auto; }
.qtable {
  border-collapse: collapse; margin: 0 auto;
  font-family: var(--serif); font-size: 16px;
}
.qtable caption {
  caption-side: top; font-weight: 700; padding-bottom: 6px; font-size: 16px;
}
.qtable th, .qtable td {
  border: 1.5px solid var(--ink); padding: 6px 18px; text-align: center;
}
.qtable th { font-weight: 700; background: #f4f4f4; }

.tex-error { background: #ffe4e4; padding: 0 4px; }

.app { display: flex; flex-direction: column; height: 100%; }

/* ---------- dashed section rules ---------- */

/* Bluebook separates the chrome from the work area with a dashed rule whose
   dashes carry occasional colour accents. Drawn as a repeating tile so the
   pattern stays put regardless of viewport width. */
.hdr, .ftr { position: relative; }
.hdr::after, .ftr::before {
  content: ""; position: absolute; left: 0; right: 0; height: 3px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='132' height='3'%3E%3Crect x='0' width='14' height='3' fill='%233f3f3f'/%3E%3Crect x='22' width='14' height='3' fill='%233f3f3f'/%3E%3Crect x='44' width='14' height='3' fill='%23e0b52c'/%3E%3Crect x='66' width='14' height='3' fill='%233f3f3f'/%3E%3Crect x='88' width='14' height='3' fill='%234b8fd4'/%3E%3Crect x='110' width='14' height='3' fill='%233f3f3f'/%3E%3C/svg%3E") repeat-x;
  z-index: 6; pointer-events: none;
}
.hdr::after { bottom: -3px; }
.ftr::before { top: -3px; }

/* ---------- header ---------- */

.hdr {
  background: var(--band);
  padding: 12px 26px 8px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  flex: none;
}
.hdr h1 { font-size: 20px; margin: 0 0 2px; font-weight: 700; letter-spacing: -.2px; }
.hdr .directions {
  background: none; border: 0; padding: 2px 0;
  font-size: 15px; display: inline-flex; align-items: center; gap: 6px;
}
.hdr .directions:hover { text-decoration: underline; }
.hdr .directions > span, .nav-pill > span, .mark-btn > span,
.gcell .pin, .gcell .flag, .legend span > span { display: inline-flex; width: 16px; }
.hdr .directions > span svg, .nav-pill > span svg { width: 16px; height: 16px; }

.timer { text-align: center; }
.timer .clock { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.timer .clock.hidden-time { letter-spacing: 2px; }
.timer .low { color: var(--red); }
.hide-btn {
  margin-top: 3px; background: #fff; border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 16px; font-size: 13px;
}
.hide-btn:hover { background: #f3f4f8; }

.tools { display: flex; justify-content: flex-end; gap: 24px; padding: 10px 0 0; }
.tool {
  background: none; border: 0; display: flex; flex-direction: column;
  align-items: center; gap: 2px; font-size: 12px; padding: 2px 4px;
}
.tool svg { width: 22px; height: 22px; }
.tool:hover span { text-decoration: underline; }
.tool.on span { font-weight: 700; }
.battery {
  position: absolute; top: 4px; right: 12px;
  font-size: 11px; display: flex; align-items: center; gap: 4px; color: #333;
}

/* ---------- exam body ---------- */

.body { flex: 1; min-height: 0; display: flex; justify-content: center; overflow: auto; padding-top: 8px; }
.stage {
  width: 100%; max-width: 1180px; display: flex; gap: 0;
  padding: 24px 46px 40px;
}
.stage.single { max-width: 820px; }
.pane { min-width: 0; flex: 1; }
.pane.left { padding-right: 34px; }
.pane.right { padding-left: 34px; }

.qhead {
  display: flex; align-items: center; gap: 12px;
  background: #f1f1f1; border-bottom: 2px dashed var(--ink);
  padding: 0 8px 0 0; margin-bottom: 18px;
}
.qnum {
  width: 34px; height: 34px; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 17px; flex: none;
}
.mark-btn {
  background: none; border: 0; display: inline-flex; align-items: center;
  gap: 7px; font-size: 15px; padding: 6px 4px;
}
.mark-btn svg { width: 17px; height: 17px; }
.mark-btn.on svg { fill: var(--red); stroke: var(--red); }
.mark-btn:hover { text-decoration: underline; }
.abc-btn {
  margin-left: auto; background: var(--blue); color: #fff; border: 0;
  border-radius: 5px; padding: 4px 8px; font-size: 13px; font-weight: 700;
  letter-spacing: .5px; display: inline-flex; align-items: center;
}
.abc-btn.off { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.abc-btn s { text-decoration: line-through; }

.stem, .passage { font-family: var(--serif); font-size: var(--qfont); line-height: 1.55; }
.stem p, .passage p { margin: 0 0 13px; }
.stem p:last-child { margin-bottom: 0; }
.prompt { font-family: var(--serif); font-size: var(--qfont); line-height: 1.55; margin: 20px 0 18px; }

/* ---------- answer choices ---------- */

.choices { list-style: none; margin: 18px 0 0; padding: 0; }
.choice-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.choice {
  position: relative;
  flex: 1; display: flex; align-items: center; gap: 14px; text-align: left;
  background: #fff; border: 1px solid var(--line); border-radius: 9px;
  padding: 11px 16px; min-height: 52px; width: 100%;
}
.choice:hover { border-color: var(--ink); }
.choice .letter {
  width: 27px; height: 27px; border: 1.5px solid var(--ink); border-radius: 50%;
  display: grid; place-items: center; font-size: 14px; flex: none;
  font-family: var(--serif);
}
.choice .ctext { font-family: var(--serif); font-size: var(--qfont); line-height: 1.5; }
.choice .ctext p { margin: 0; }
.choice .ctext .figwrap { margin: 4px 0; text-align: left; }
.choice.selected { border: 2px solid var(--blue); padding: 10px 15px; }
.choice.selected .letter { background: var(--blue); border-color: var(--blue); color: #fff; }
/* Bluebook crosses the whole card out with a line, not just the text */
.choice.crossed { opacity: .55; }
.choice.crossed::after {
  content: ""; position: absolute; left: 8px; right: 8px; top: 50%;
  border-top: 2px solid var(--ink);
}

.cross-btn {
  width: 28px; height: 28px; border-radius: 50%; background: none;
  border: 1.5px solid var(--ink); font-size: 13px; flex: none;
  display: grid; place-items: center; font-family: var(--serif);
  position: relative;
}
.cross-btn.hidden { display: none; }
.cross-btn s { text-decoration: none; }
.cross-btn:not(.undo)::after {
  content: ""; position: absolute; left: -3px; right: -3px; top: 50%;
  border-top: 1.5px solid var(--ink);
}
.cross-btn.undo { width: auto; border: 0; border-radius: 0; font-size: 13px;
  font-family: var(--sans); text-decoration: underline; padding: 0 4px; }

/* student-produced response */
.spr { margin-top: 6px; }
.spr .preview {
  font-family: var(--serif); font-size: 16px; color: var(--ink-soft);
  margin-bottom: 8px; min-height: 22px;
}
.spr input {
  font-family: var(--serif); font-size: 18px; padding: 10px 14px;
  border: 1px solid var(--ink); border-radius: 4px; width: 260px;
}
.spr input:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.spr .hint { font-size: 13px; color: var(--ink-soft); margin-top: 10px; max-width: 460px; }

/* ---------- footer ---------- */

.ftr {
  background: var(--band); padding: 14px 34px; flex: none;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
}
.ftr .who { font-size: 17px; font-weight: 600; }
.nav-pill {
  background: var(--ink); color: #fff; border: 0; border-radius: 999px;
  padding: 11px 24px; font-size: 16px; font-weight: 700;
  display: inline-flex; align-items: center; gap: 10px;
}
.ftr .acts { display: flex; justify-content: flex-end; gap: 12px; }
.btn-primary {
  background: var(--blue); color: #fff; border: 0; border-radius: 999px;
  padding: 12px 30px; font-size: 16px; font-weight: 700;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-ghost {
  background: none; color: var(--blue); border: 2px solid var(--blue);
  border-radius: 999px; padding: 10px 26px; font-size: 15px; font-weight: 700;
}
.btn-ghost:hover { background: #eef2fd; }

/* ---------- popovers ---------- */

.pop {
  position: fixed; background: #fff; border-radius: 8px; z-index: 60;
  box-shadow: 0 6px 26px rgba(0,0,0,.28);
}
.pop.nav-pop { width: 580px; padding: 18px 22px 22px; }
.pop.nav-pop h2 { text-align: center; font-size: 19px; margin: 0 0 14px; }
.legend {
  display: flex; justify-content: center; gap: 30px; font-size: 14px;
  border-bottom: 1px solid #d3d3d3; padding-bottom: 12px; margin-bottom: 16px;
}
.legend > span { display: inline-flex; align-items: center; gap: 7px; }
.grid { display: flex; flex-wrap: wrap; gap: 14px 18px; justify-content: center; }
.review-wrap { max-width: 540px; margin: 0 auto; }
.gcell { position: relative; }
.gcell .pin { position: absolute; top: -15px; left: 50%; transform: translateX(-50%); }
.gcell button {
  width: 34px; height: 34px; border: 2px dashed var(--line); background: #fff;
  color: var(--blue); font-weight: 700; font-size: 16px; border-radius: 3px;
}
.gcell button.answered { background: var(--blue); border: 2px solid var(--blue); color: #fff; }
.gcell button.current { text-decoration: underline; }
.gcell .flag { position: absolute; top: -7px; right: -7px; color: var(--red); }
.nav-pop .go { display: block; margin: 20px auto 0; }
.pop .arrow {
  position: absolute; bottom: -11px; left: 50%; transform: translateX(-50%);
  border-left: 12px solid transparent; border-right: 12px solid transparent;
  border-top: 12px solid #fff;
}

.pop.menu { padding: 8px 0; width: 290px; }
.pop.menu button {
  width: 100%; background: none; border: 0; text-align: left;
  padding: 13px 20px; font-size: 17px; display: flex; align-items: center; gap: 16px;
}
.pop.menu button:hover { background: #f0f2f8; }
.pop.menu button > span:first-child { width: 24px; flex: none; }
.pop.menu button svg { width: 22px; height: 22px; }
.pop.menu button:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }

/* selection popover lives on <body>, fixed, so it can never leak into the
   saved question markup */
.hl-pop {
  position: fixed; z-index: 90; background: #fff; border-radius: 999px;
  box-shadow: 0 4px 18px rgba(0,0,0,.3); padding: 7px 12px;
  display: flex; align-items: center; gap: 12px;
}
.hl-pop .swatch { width: 27px; height: 27px; border-radius: 50%; border: 1px solid #bbb; }
.hl-pop .swatch.on { outline: 2px solid var(--focus); }
.hl-pop .sep { width: 1px; height: 22px; background: #ccc; }
.hl-pop button { background: none; border: 0; padding: 2px; display: inline-flex; }
mark.hl { padding: 1px 0; border-radius: 2px; background: transparent; color: inherit; }
mark.hl.yellow { background: #ffe14d; }
mark.hl.blue { background: #b9dcfb; }
mark.hl.pink { background: #f8c8e0; }
mark.hl.underline { text-decoration: underline 2px var(--ink); }

.backdrop { position: fixed; inset: 0; z-index: 50; }

.modal-wrap {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 80;
  display: grid; place-items: center; padding: 20px;
}
.modal {
  background: #fff; border-radius: 10px; padding: 26px 30px; max-width: 720px;
  width: 100%; max-height: 88vh; overflow: auto;
}
.modal h2 { margin: 0 0 14px; font-size: 22px; }
.modal .row { display: flex; gap: 12px; justify-content: flex-end; margin-top: 22px; }
.modal.wide { max-width: 1000px; }
.modal iframe { width: 100%; height: 62vh; border: 1px solid #ccc; border-radius: 6px; }

/* ---------- floating tool windows (calculator / reference) ---------- */

.tool-win {
  position: fixed; z-index: 75; background: #fff; border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,.35); display: flex; flex-direction: column;
  resize: both; overflow: hidden;
  min-width: 360px; min-height: 260px;
}
.tool-win.collapsed { resize: none; min-height: 0; height: auto !important; }
.tool-win.collapsed .win-body { display: none; }
.tool-win.hidden { display: none; }
.win-bar {
  background: var(--navy); color: #fff; padding: 8px 14px; cursor: grab;
  display: flex; align-items: center; gap: 10px; user-select: none; flex: none;
}
.win-bar:active { cursor: grabbing; }
.win-bar .title { font-weight: 700; font-size: 14px; flex: 1; }
.win-bar button {
  background: none; border: 0; color: #fff; width: 26px; height: 26px;
  border-radius: 5px; display: grid; place-items: center; font-size: 15px;
}
.win-bar button:hover { background: rgba(255,255,255,.18); }
.win-body { flex: 1; min-height: 0; display: flex; }
.win-body iframe { width: 100%; height: 100%; border: 0; flex: 1; }
.win-body .win-scroll { overflow: auto; padding: 18px 22px; width: 100%; }
.tool-win.dragging iframe { pointer-events: none; }

/* reference sheet */
.refsheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; }
.refsheet figure { margin: 0; text-align: center; font-family: var(--serif); font-size: 15px; }
.refsheet figcaption { margin-top: 6px; font-size: 13px; color: var(--ink-soft); font-family: var(--sans); }
.refnote { font-family: var(--serif); font-size: 15px; margin-top: 18px; line-height: 1.6; }
