/* ============================================================
   Bluebook-style test-taker UI — 800prep design system
   ------------------------------------------------------------
   The in-test chrome stays CLEAN AND CLINICAL: white surfaces,
   high contrast, no aurora / grain / graph-paper inside the test.
   Tokens, radii (8 controls / 12 cards), tinted layered shadows
   and type come from base.css.
   Every class name here is load-bearing for test-engine.js.
   ============================================================ */

.test-body { height: 100vh; overflow: hidden; background: var(--surface); }
#test-root { display: flex; flex-direction: column; height: 100vh; }

/* ---------- Header ---------- */
.test-header {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 20px;
  border-bottom: 2px dashed var(--hairline);
  background: var(--surface);
}
.th-left { display: flex; flex-direction: column; gap: 2px; }
.th-module { font-weight: 600; font-size: 15px; letter-spacing: -.012em; color: var(--ink); }
.th-link {
  background: none; border: none; cursor: pointer; padding: 0;
  font-family: inherit; font-size: 13px; color: var(--ink-2);
  transition: color .15s var(--ease);
}
.th-link:hover { color: var(--signal); }

.th-center { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.th-timer {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
  font-size: 22px; font-weight: 700; letter-spacing: -.01em; color: var(--ink);
}
.th-timerbtn {
  background: none; border: none; cursor: pointer; padding: 0;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--signal);
  transition: color .15s var(--ease);
}
.th-timerbtn:hover { color: var(--signal-2); }

.th-right { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.th-tool {
  border: none; border-radius: var(--r);
  padding: 8px 13px; background: var(--surface); color: var(--ink);
  box-shadow: var(--ring-hair), var(--shadow-sm);
  cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 600;
  transition: box-shadow .15s var(--ease), color .15s var(--ease);
}
.th-tool:hover { color: var(--signal); box-shadow: 0 0 0 1px rgba(26,109,240,.35), var(--shadow-card); }

/* ---------- Content ---------- */
.test-content { flex: 1; overflow-y: auto; background: var(--surface); }
.q-wrap { max-width: 720px; margin: 0 auto; padding: 28px 20px 88px; }

.q-bar {
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 10px; margin-bottom: 24px;
}
.q-num {
  background: var(--ink); color: var(--white);
  width: 28px; height: 28px; display: grid; place-items: center;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
  font-size: 14px; border-radius: var(--r-xs); flex-shrink: 0;
}
.q-mark {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 500; color: var(--ink-2);
  transition: color .15s var(--ease);
}
.q-mark:hover { color: var(--ink); }
.q-mark.is-marked { color: var(--flag); }
.q-mark.is-marked .q-flag { color: var(--flag); }
.q-flag { font-size: 16px; line-height: 1; }
.q-spacer { flex: 1; }

.q-elim {
  border: none; border-radius: var(--r-sm); padding: 5px 10px;
  background: var(--surface); box-shadow: var(--ring-hair);
  cursor: pointer;
  transition: box-shadow .15s var(--ease), background-color .15s var(--ease);
}
.q-elim:hover { box-shadow: 0 0 0 1px rgba(26,109,240,.35); }
.q-elim-abc {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13px; text-decoration: line-through; color: var(--ink-2);
}
.q-elim.is-on { background: var(--ink); box-shadow: none; }
.q-elim.is-on .q-elim-abc { color: var(--white); }

.q-domain {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .11em; color: var(--signal);
}
.q-passage { font-size: 17px; line-height: 1.7; margin: 12px 0 20px; padding: 16px 18px; border-radius: 10px; background: var(--surface-2); box-shadow: var(--ring-hair); color: var(--ink); }
.q-stem { font-size: 19px; line-height: 1.6; margin: 10px 0 26px; color: var(--ink); }
.q-body { color: var(--ink); }

/* ---------- Choices ---------- */
.choices { display: flex; flex-direction: column; gap: 12px; }
.choice { display: flex; align-items: stretch; gap: 8px; }
.choice-main {
  flex: 1; display: flex; align-items: center; gap: 14px;
  border: none; border-radius: var(--r);
  padding: 14px 16px; text-align: left;
  background: var(--surface); color: var(--ink);
  box-shadow: var(--ring-hair), var(--shadow-sm);
  cursor: pointer; font-family: inherit; font-size: 16px; line-height: 1.5;
  transition: box-shadow .15s var(--ease), background-color .15s var(--ease);
}
.choice-main:hover { box-shadow: 0 0 0 1px rgba(26,109,240,.4), var(--shadow-card); }
.choice.is-selected .choice-main {
  background: var(--signal-soft);
  box-shadow: 0 0 0 2px var(--signal), var(--shadow-card);
}
.choice-text { flex: 1; }
.choice-letter {
  width: 26px; height: 26px; border: 1.5px solid var(--ink-2);
  border-radius: 50%; display: grid; place-items: center;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-variant-numeric: tabular-nums;
  font-size: 14px; color: var(--ink); flex-shrink: 0;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease);
}
.choice.is-selected .choice-letter { background: var(--signal); border-color: var(--signal); color: var(--white); }
.choice.is-crossed .choice-main { opacity: .45; text-decoration: line-through; }
.choice-cross {
  border: none; border-radius: var(--r-sm); padding: 0 10px;
  background: var(--surface); color: var(--ink-2);
  box-shadow: var(--ring-hair);
  cursor: pointer;
  font-family: 'Plus Jakarta Sans', sans-serif; font-size: 12px; min-width: 44px;
  transition: box-shadow .15s var(--ease), color .15s var(--ease);
}
.choice-cross:hover { color: var(--ink); box-shadow: 0 0 0 1px rgba(18,24,31,.2); }

/* ---------- Grid-in ---------- */
.grid-in { margin-top: 10px; }
.grid-label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.grid-input {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
  font-size: 20px; border: none; border-radius: var(--r);
  background: var(--surface); color: var(--ink);
  box-shadow: var(--ring-hair), var(--shadow-sm);
  padding: 12px 16px; width: 240px; max-width: 100%;
  transition: box-shadow .15s var(--ease);
}
.grid-input::placeholder { color: var(--ink-3); }
.grid-input:focus { outline: none; box-shadow: 0 0 0 1px var(--signal), 0 0 0 4px rgba(26,109,240,.14); }
.grid-hint { font-size: 13px; color: var(--ink-2); margin-top: 8px; }

/* ---------- Footer ---------- */
.test-footer {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 20px;
  border-top: 1px solid var(--hairline); background: var(--surface-2);
}
.tf-name {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-variant-numeric: tabular-nums;
  font-size: 13px; color: var(--ink-2); min-width: 60px;
}
.tf-palette {
  background: var(--ink); color: var(--white); border: none;
  border-radius: var(--r); padding: 10px 16px;
  font-family: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color .15s var(--ease), box-shadow .15s var(--ease);
}
.tf-palette:hover { background: #000; box-shadow: var(--shadow-card); }
.tf-nav { display: flex; gap: 10px; min-width: 60px; justify-content: flex-end; }
.tf-btn {
  border: none; border-radius: var(--r); padding: 11px 22px;
  background: var(--surface); color: var(--ink);
  box-shadow: var(--ring-hair), var(--shadow-sm);
  font-family: inherit; font-weight: 600; font-size: 14px; line-height: 1; cursor: pointer;
  transition: background-color .15s var(--ease), box-shadow .15s var(--ease),
              color .15s var(--ease), transform .15s var(--ease);
}
.tf-btn:hover { color: var(--signal); box-shadow: 0 0 0 1px rgba(26,109,240,.35), var(--shadow-card); }
.tf-primary { background: var(--signal); color: var(--white); box-shadow: var(--shadow-sm); }
.tf-primary:hover { background: var(--signal-2); color: var(--white); box-shadow: var(--shadow-card); }
.tf-primary:active { transform: scale(.985); }
.tf-btn:disabled { opacity: .4; cursor: not-allowed; }
.tf-btn:disabled:hover { transform: none; box-shadow: var(--ring-hair), var(--shadow-sm); color: var(--ink); }
.tf-primary:disabled:hover { background: var(--signal); color: var(--white); box-shadow: var(--shadow-sm); }
.tf-big { padding: 15px 32px; border-radius: var(--r); font-size: 16px; }

/* ---------- Palette popover ---------- */
.palette-pop {
  position: fixed; bottom: 82px; left: 50%; transform: translateX(-50%);
  width: min(520px, 92vw);
  background: var(--surface); border: none; border-radius: var(--r-lg);
  box-shadow: var(--ring-hair), var(--shadow-pop);
  padding: 18px; z-index: 60;
}
.palette-pop.hidden { display: none; }
.pal-head {
  font-weight: 600; text-align: center; color: var(--ink);
  border-bottom: 1px solid var(--hairline); padding-bottom: 10px; margin-bottom: 12px;
}
.pal-legend, .rev-legend {
  display: flex; gap: 16px; justify-content: center;
  font-size: 12px; color: var(--ink-2); margin-bottom: 14px; flex-wrap: wrap;
}
.dot { width: 11px; height: 11px; display: inline-block; border-radius: var(--r-xs); margin-right: 5px; vertical-align: middle; }
.dot-current { background: var(--signal); }
.dot-unanswered { border: 1px dashed var(--ink-3); background: var(--surface); }
.dot-marked { background: var(--flag); }
.dot-answered { background: var(--ink); }

.pal-grid, .rev-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 8px; }
.pal-cell, .rev-cell {
  position: relative; aspect-ratio: 1;
  border-radius: var(--r-sm);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
  border: 1px solid var(--hairline); background: var(--surface);
  cursor: pointer; font-size: 14px; color: var(--ink);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.pal-cell:hover, .rev-cell:hover { border-color: var(--signal); }
.pal-answered, .rev-answered { background: var(--ink); color: var(--white); border-color: var(--ink); }
.pal-unanswered, .rev-unanswered { border-style: dashed; }
.pal-marked, .rev-marked { border-color: var(--flag); border-width: 2px; }
.pal-current { box-shadow: 0 0 0 2px var(--signal); }
.rev-flag { position: absolute; top: -7px; right: -4px; color: var(--flag); font-size: 13px; }
.pal-review {
  margin-top: 16px; width: 100%;
  border: none; border-radius: var(--r); padding: 11px;
  background: var(--surface); color: var(--signal);
  box-shadow: 0 0 0 1px rgba(26,109,240,.35);
  font-family: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background-color .15s var(--ease), box-shadow .15s var(--ease);
}
.pal-review:hover { background: var(--signal-soft); box-shadow: 0 0 0 1px var(--signal); }

/* ---------- Review screen ---------- */
.review-wrap { max-width: 640px; margin: 0 auto; padding: 48px 20px 88px; text-align: center; }
.review-title {
  font-family: 'Poppins', Georgia, serif;
  font-optical-sizing: auto;
  font-size: clamp(1.6rem, 2.6vw, 2.25rem); line-height: 1.12;
  letter-spacing: -.026em; font-weight: 500; color: var(--ink);
}
.review-sub { color: var(--ink-2); margin: 10px 0 26px; }
.review-actions { margin-top: 30px; }

/* ---------- Reference sheet modal ---------- */
.ref-overlay {
  position: fixed; inset: 0; background: rgba(16,23,32,.55);
  display: flex; align-items: center; justify-content: center; z-index: 70; padding: 20px;
}
.ref-overlay.hidden { display: none; }
.ref-card {
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--ring-hair), var(--shadow-pop);
  max-width: 760px; width: 100%; max-height: 86vh; overflow-y: auto; padding: 28px;
}
.ref-close {
  float: right; border: none; background: var(--surface); color: var(--ink-2);
  box-shadow: var(--ring-hair);
  border-radius: var(--r-sm); width: 34px; height: 34px; cursor: pointer; font-size: 18px;
  transition: color .15s var(--ease), box-shadow .15s var(--ease);
}
.ref-close:hover { color: var(--ink); box-shadow: 0 0 0 1px rgba(18,24,31,.2); }

/* ---------- Desmos calculator panel ---------- */
.calc-panel {
  position: fixed; top: 72px; right: 16px;
  width: min(460px, 94vw); height: min(60vh, 520px);
  background: var(--surface); border: none; border-radius: var(--r-lg);
  box-shadow: var(--ring-hair), var(--shadow-pop);
  z-index: 55; display: flex; flex-direction: column; overflow: hidden;
}
.calc-panel.hidden { display: none; }
.calc-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; background: var(--night); color: var(--white);
  font-size: 12px; letter-spacing: .08em; text-transform: uppercase;
  font-family: 'Plus Jakarta Sans', sans-serif;
}
.calc-close { background: none; border: none; color: rgba(255,255,255,.75); cursor: pointer; font-size: 18px; line-height: 1; transition: color .15s var(--ease); }
.calc-close:hover { color: var(--white); }
#calc { flex: 1; }
.calc-fallback { padding: 20px; font-size: 14px; color: var(--ink-2); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .test-header { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .th-center { order: 3; width: 100%; flex-direction: row; align-items: center; gap: 10px; justify-content: center; }
  .th-tool { padding: 6px 9px; font-size: 12px; }
  .test-footer { padding: 10px 12px; }
  .tf-btn { padding: 10px 16px; }
  .q-stem { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  .th-link, .th-timerbtn, .th-tool, .q-mark, .q-elim, .choice-main, .choice-letter,
  .choice-cross, .grid-input, .tf-palette, .tf-btn, .pal-cell, .rev-cell,
  .pal-review, .ref-close, .calc-close { transition: none; }
  .tf-primary:active { transform: none; }
}
