/* Question deck: one card at a time, sitting directly on the page. */

.deck__stage {
  touch-action: pan-y;
  /* Clip the entering card's slide so it never widens the page, while the
     padding keeps focus rings at the card edges visible. */
  overflow-x: clip;
  margin-inline: -8px;
  padding-inline: 8px;
}

/* Card */

.qcard__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.qcard__heading {
  min-width: 0;
}

.qcard__section {
  margin: 0;
  font-size: var(--t-s);
  line-height: 1.4;
  color: var(--graphite);
  font-variant-numeric: tabular-nums;
}

.qcard__title {
  margin: 0.2rem 0 0;
  font-size: var(--t-l);
  font-weight: 600;
  line-height: 1.15;
}

.qcard__question,
.qcard__missing {
  margin: 0;
  font-size: var(--t-l);
  line-height: 1.55;
  overflow-wrap: break-word;
}

.qcard__question {
  white-space: pre-line;
}

/* Difficulty: three bars filled up to the level, with a text label. */

.difficulty {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.difficulty__bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
}

.difficulty__bar {
  width: 8px;
  height: 14px;
  background: var(--rule);
}

.difficulty__bar--on {
  background: var(--ink);
}

.difficulty__label {
  font-size: var(--t-xs);
  font-weight: 500;
  color: var(--graphite);
}

@media (forced-colors: active) {
  .difficulty__bar {
    border: 1px solid CanvasText;
    background: Canvas;
  }

  .difficulty__bar--on {
    background: CanvasText;
  }
}

/* Answer: a yellow panel hidden under a solid black slab. The slab is
   inset: 0 of the wrapper, and the wrapper is as tall as the panel, so long
   answers stay fully covered. */

.answer {
  position: relative;
  margin-top: 1.75rem;
  min-height: 7.5rem;
}

.answer__body {
  box-sizing: border-box;
  min-height: 7.5rem;
  padding: 1.1rem 1.25rem;
  background: var(--highlight-soft);
  border-left: 4px solid var(--highlight);
  border-radius: var(--r-box);
}

.answer__label {
  margin: 0 0 0.35rem;
  font-size: var(--t-xs);
  font-weight: 500;
  color: var(--graphite);
}

.answer__text {
  margin: 0;
  font-size: var(--t-l);
  line-height: 1.55;
  white-space: pre-line;
  overflow-wrap: break-word;
}

.answer__cover {
  position: absolute;
  inset: 0;
  min-height: 7.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--ink);
  border-radius: var(--r-slab);
  clip-path: inset(0 0 0 0);
}

.answer__cover[hidden] {
  display: none;
}

.answer__cover--lifting {
  pointer-events: none;
  animation: answer-lift 260ms cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}

@keyframes answer-lift {
  from {
    clip-path: inset(0 0 0 0);
  }
  to {
    clip-path: inset(0 0 100% 0);
  }
}

.answer__reveal {
  min-height: 44px;
  padding: 0.6rem 1.25rem;
  font: inherit;
  font-size: var(--t-s);
  font-weight: 500;
  color: var(--ink);
  background: var(--paper);
  border: 0;
  border-radius: var(--r-control);
  cursor: pointer;
}

.answer__reveal:hover {
  background: var(--highlight-soft);
}

.answer__reveal:focus-visible {
  outline: 3px solid var(--highlight);
  outline-offset: 3px;
}

.answer__actions {
  margin-top: 0.5rem;
}

.answer__actions .answer__hide {
  padding-inline: 0;
}

/* Figures: shown at their natural pixel size (the scans are about three
   times print size), capped by the column and the viewport height. When the
   size is known, --fig-w and --fig-ratio fix the box before the file loads. */

.figure {
  margin: 0.75rem 0 1rem;
}

.figure__zoom {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 0;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 0;
  cursor: zoom-in;
}

.figure__img {
  display: block;
  box-sizing: border-box;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(65vh, 34rem);
}

.figure__img[width][height] {
  width: min(var(--fig-w), calc(min(65vh, 34rem) * var(--fig-ratio)));
}

/* On the yellow panel a white figure reads as a clipping. */
.answer .figure__img {
  border: 1px solid var(--rule);
}

/* Lightbox: the figure fitted to the viewport, up to twice its size. Tall figures
   keep a readable minimum width and the dialog scrolls instead of shrinking them. */

.lightbox {
  box-sizing: border-box;
  max-width: none;
  max-height: calc(100dvh - 2rem);
  padding: 0 0.5rem 0.5rem;
  overflow: auto;
  overscroll-behavior: contain;
  color: var(--ink);
  background: var(--paper);
  border: 0;
  border-radius: var(--r-box);
}

.lightbox::backdrop {
  background: color-mix(in srgb, var(--ink) 85%, transparent);
}

.lightbox__bar {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: flex-end;
  padding-top: 0.5rem;
  margin-bottom: 0.5rem;
  background: var(--paper);
}

.lightbox__img {
  display: block;
  margin-inline: auto;
  width: auto;
  height: auto;
  max-width: calc(100vw - 3rem);
  object-fit: contain;
  cursor: zoom-out;
}

.lightbox__img[width][height] {
  width: min(
    calc(var(--fig-w) * 2),
    calc(100vw - 3rem),
    max(calc((100dvh - 5rem) * var(--fig-ratio)), min(calc(100vw - 3rem), 40rem))
  );
}

/* Math. Wide display equations scroll sideways rather than overflow. */

.qcard mjx-container[jax][display="true"] {
  margin: 0.75em 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-block: 0.1em;
}

/* Navigation */

.deck__nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.75rem;
}

.deck__nav .btn {
  min-width: 6.5rem;
}

.deck__pos {
  margin: 0;
  font-size: var(--t-s);
  color: var(--graphite);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

@media (max-width: 399.98px) {
  .deck__nav {
    gap: 0.5rem;
  }

  .deck__nav .btn {
    min-width: 0;
    padding-inline: 0.8rem;
  }
}

/* Changing questions: the new card slides in from the direction of travel. */

.qcard--enter-next {
  animation: qcard-enter-next 180ms cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
}

.qcard--enter-prev {
  animation: qcard-enter-prev 180ms cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
}

@keyframes qcard-enter-next {
  from {
    transform: translateX(24px);
    opacity: 0;
  }
}

@keyframes qcard-enter-prev {
  from {
    transform: translateX(-24px);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .answer__cover--lifting,
  .qcard--enter-next,
  .qcard--enter-prev {
    animation: none;
  }
}
