/* Prepnol — quiz play (play.html only; tokens come from app.css) */

/* Top bar — close, title, timer */
.quizbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding: 0 var(--gutter);
  background: var(--md-sys-color-surface);
}

.quizbar a {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--md-sys-shape-corner-full);
  color: var(--md-sys-color-on-surface-variant);
  transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1);
}

.quizbar a:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

.quizbar svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.quizbar h1 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Countdown chip (exam mode) */
.timer {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-high);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.timer svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* Last minute */
.timer.low {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

/* Linear progress */
.progress {
  height: 4px;
  margin: 0 var(--gutter);
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-high);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--md-sys-color-primary);
  transition: width 300ms cubic-bezier(0.2, 0, 0, 1);
}

main {
  flex: 1;
  padding: 20px var(--gutter) 96px; /* clear the fixed bottom nav */
  overflow-x: clip;
}

/* main provides the 8px page gutter — sections inside must not add another */
main section {
  padding: 0;
}

/* display:flex above would otherwise beat the hidden attribute */
.timer[hidden],
.quiznav[hidden] {
  display: none;
}

/* Question card */
.question small {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

.question h2 {
  margin: 8px 0 20px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.55;
}

.question ol {
  list-style: none;
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
}

.question ol button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface);
  font: inherit;
  line-height: 1.45;
  text-align: left;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1),
    border-color 150ms cubic-bezier(0.2, 0, 0, 1);
}

.question ol button span {
  flex: 1;
  min-width: 0; /* formulas must not widen the card — fitMath() shrinks them */
}

.question ol button:hover {
  background: var(--md-sys-color-surface-container-low);
}

/* Option letter */
.question ol b {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container);
  font-size: 12px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
}

.question .selected {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-secondary-container);
}

.question .selected b {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

/* Practice reveal */
.question .correct {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.question .correct b {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.question .wrong {
  border-color: var(--md-sys-color-error);
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.question .wrong b {
  background: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

.question ol button:disabled {
  cursor: default;
}

.question ol button:disabled:hover {
  background: var(--md-sys-color-surface);
}

.question ol button:disabled:is(.correct):hover {
  background: var(--md-sys-color-primary-container);
}

.question ol button:disabled:is(.wrong):hover {
  background: var(--md-sys-color-error-container);
}

/* Explanation (practice + review) — tonal callout */
.explanation {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-size: 13px;
  line-height: 1.6;
}

.explanation b {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.75;
}

.explanation p {
  margin: 0;
}

/* Bottom navigation — Prev / Next */
.quiznav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  gap: 12px;
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  background: var(--md-sys-color-surface);
}

.quiznav .btn {
  flex: 1;
  height: 48px;
}

/* Prev — outlined */
.quiznav .btn:first-child {
  flex: 0 0 auto;
  padding: 0 20px;
  --bg: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  color: var(--md-sys-color-primary);
}

.btn:disabled {
  --bg: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
  border-color: transparent;
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
  cursor: default;
}

.btn:disabled:hover,
.btn:disabled:active {
  background: var(--bg);
}

/* Result — summary card with score ring */
.result {
  text-align: center;
}

.result > div {
  padding: 28px 16px 20px;
  margin-bottom: 16px;
  border-radius: var(--md-sys-shape-corner-extra-large);
  background: var(--md-sys-color-surface-container-low);
}

.result .score {
  position: relative;
  width: 132px;
  margin: 0 auto 16px;
}

.result .score svg {
  display: block;
  width: 100%;
  transform: rotate(-90deg);
}

.result .score circle {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
}

.result .score circle:first-child {
  stroke: var(--md-sys-color-surface-container-high);
}

.result .score circle:last-child {
  stroke: var(--md-sys-color-primary);
  transition: stroke-dashoffset 800ms cubic-bezier(0.05, 0.7, 0.1, 1);
}

.result .score data {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--md-sys-color-primary);
}

.result .score data small {
  font-size: 12px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}

.result h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
}

.result div > p {
  margin: 0;
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
}

/* Stat row — hairline-divided columns inside the card */
.result ul {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 20px 0 0;
  padding: 16px 0 0;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.result li + li {
  border-left: 1px solid var(--md-sys-color-outline-variant);
}

.result li b {
  display: block;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.25;
}

.result li:first-child b {
  color: var(--md-sys-color-primary);
}

.result li:nth-child(2) b {
  color: var(--md-sys-color-error);
}

.result li small {
  font-size: 11px;
  color: var(--md-sys-color-on-surface-variant);
}

.result nav {
  display: grid;
  gap: 10px;
}

.result nav .btn {
  height: 48px;
}

.result nav a:last-child {
  padding: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--md-sys-color-primary);
  text-decoration: none;
}

/* Review answers */
.review {
  margin-top: 28px;
}

.review select {
  flex-shrink: 0;
  height: 36px;
  padding: 0 30px 0 14px;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  appearance: none; /* native arrow floats at the far edge; draw our own */
  background: var(--md-sys-color-surface-container-high)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23404944' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 10px center / 16px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
}

.review ol {
  list-style: none;
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
}

.review ol > li {
  min-width: 0; /* keep long formulas from widening the card */
  padding: 14px;
  border: 1.5px solid transparent;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface-container-lowest);
}

/* The only extra cue on a wrong answer */
.review ol > li.wrong {
  border-color: color-mix(in srgb, var(--md-sys-color-error) 45%, transparent);
}

.review li h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
}

/* Flat option rows — correct in green, the student's wrong pick in red */
.review li ul {
  list-style: none;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.review li ul li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 8px 12px;
  border-radius: var(--md-sys-shape-corner-medium);
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 4%, transparent);
  font-size: 13px;
  line-height: 1.5;
}

.review li ul b {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: var(--md-sys-shape-corner-full);
  background: color-mix(in srgb, var(--md-sys-color-primary) 10%, transparent);
  font-size: 12px;
  font-weight: 700;
  color: var(--md-sys-color-primary);
}

.review li ul span {
  flex: 1;
  min-width: 0;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.review li ul li.correct {
  background: var(--md-sys-color-primary-container);
}

.review li ul li.correct b {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.review li ul li.correct span {
  font-weight: 600;
  color: var(--md-sys-color-on-primary-container);
}

.review li ul li.wrong {
  background: var(--md-sys-color-error-container);
}

.review li ul li.wrong b {
  background: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

.review li ul li.wrong span {
  color: var(--md-sys-color-on-error-container);
}

.review .explanation {
  margin-top: 12px;
  padding: 12px 14px;
}

/* Submit-confirm sheet copy (app.css has no .sheet p any more) */
.sheet > p {
  margin: -8px 0 16px;
  font-size: 14px;
  line-height: 1.55;
  text-align: center;
  color: var(--md-sys-color-on-surface-variant);
}

/* KaTeX sizing — keep formulas on the 14px rhythm and inside the column */
.katex {
  font-size: 1.15em;
}

.katex-display {
  margin: 10px 0;
  overflow: hidden; /* fitMath() in quiz.js shrinks long formulas to the column */
}

/* ---------- Desktop — additive only; mobile styles above are untouched ---------- */

/* Expanded (≥840px): the whole quiz sits on one centered 760px column */
@media (min-width: 840px) {
  .quizbar,
  .quiznav {
    padding-inline: max(var(--gutter), calc(50% - 380px));
  }

  .progress {
    margin-inline: max(var(--gutter), calc(50% - 380px));
  }

  main {
    padding-inline: max(var(--gutter), calc(50% - 380px));
  }

  .question h2 {
    font-size: 18px;
  }

  .result nav {
    max-width: 420px;
    margin-inline: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .progress span,
  .result .score circle:last-child {
    transition: none;
  }
}

/* EN/অ language toggle in the quiz bar */
.langtoggle {
  display: flex;
  flex-shrink: 0;
  height: 32px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-high);
  overflow: hidden;
}

.langtoggle button {
  border: 0;
  background: none;
  padding: 0 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
}

/* Selected state matches .segmented (the medium picker on /login, /account and
   the order form) so the two read as one control, just abbreviated to fit the
   quiz bar. */
.langtoggle button[aria-pressed="true"] {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

/* The pill clips overflow, so the global ring's positive offset would be cut
   off entirely — pull it inside, as every other clipped control here does. */
.langtoggle button:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: -2px;
}

/* Full-screen quiz error / gate states */
.quizgate {
  margin: auto;
  padding: 24px 16px;
  display: grid;
  justify-items: center;
  gap: 12px;
  text-align: center;
  max-width: 48ch;
}

.quizgate p {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
}
