:root:not([data-theme="dark"]) {
  --ink: #1a3c6e;
  --sky: #4fc3ec;
  --sky-pale: #e8f8fd;
  --paper: #f7f8fa;
  --paper-white: #ffffff;
  --chalk-line: #e2e5ea;
  --pencil: #2b2f36;
  --pencil-soft: #5b6270;
  --eraser: #eef0f3;
  --eraser-dark: #dde1e6;
  --leaf: #1a6e2e;
  --leaf-bg: #d9f7e1;
  --apple: #9c1f1f;
  --apple-bg: #fbdcdc;
  --sun: #7a5b00;
  --sun-bg: #fff3cd;
  --marker: #940729;
  --chalkboard: #1a1f29;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 14px;
  --shadow-card: 0 1px 4px rgba(0, 0, 0, 0.08);
  --shadow-card-lifted: 0 16px 30px rgba(0, 0, 0, 0.22);

  /* Reading words (labels, instructions, UI chrome) get a dyslexia-friendly
     sans-serif; worksheet numbers get a rounded, kid-friendly face. Both
     fall back to plain system fonts if the webfont hasn't loaded. */
  --font-reading:
    "Lexend", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  --font-numbers:
    "Comic Neue", "Comic Sans MS", -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Feed the brand palette into Pico's design tokens instead of
     restyling elements Pico already themes (buttons, inputs, selects,
     checkboxes, fieldsets). */
  --pico-font-family: var(--font-reading);
  --pico-border-radius: var(--radius-sm);
  --pico-spacing: 1rem;

  --pico-background-color: var(--paper);
  --pico-color: var(--pencil);
  --pico-muted-color: var(--pencil-soft);
  --pico-muted-border-color: var(--chalk-line);
  --pico-h1-color: var(--ink);
  --pico-h2-color: var(--ink);

  --pico-primary: var(--ink);
  --pico-primary-background: var(--ink);
  --pico-primary-border: var(--ink);
  --pico-primary-underline: var(--ink);
  --pico-primary-hover: #142f57;
  --pico-primary-hover-background: #142f57;
  --pico-primary-hover-border: #142f57;
  --pico-primary-focus: rgba(79, 195, 236, 0.5);
  --pico-primary-inverse: var(--paper-white);

  --pico-secondary: var(--pencil);
  --pico-secondary-background: var(--eraser);
  --pico-secondary-border: var(--eraser);
  --pico-secondary-hover: var(--pencil);
  --pico-secondary-hover-background: var(--eraser-dark);
  --pico-secondary-hover-border: var(--eraser-dark);
  --pico-secondary-focus: rgba(79, 195, 236, 0.5);
  --pico-secondary-inverse: var(--pencil);

  --pico-form-element-background-color: var(--paper-white);
  --pico-form-element-border-color: var(--chalk-line);
  --pico-form-element-color: var(--pencil);
  --pico-form-element-active-border-color: var(--sky);
  --pico-form-element-focus-color: var(--sky);

  --pico-card-background-color: var(--paper-white);
  --pico-card-border-color: var(--chalk-line);
  --pico-card-box-shadow: var(--shadow-card);

  --pico-tooltip-background-color: var(--chalkboard);
}

/* !important so this always wins against component classes declared later
   that also set `display` (.control-group, .actions-group, etc). */
.hidden {
  display: none !important;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: clamp(10px, 4vw, 24px);
}

.header {
  background: var(--ink);
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px clamp(10px, 4vw, 24px);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.header-icon {
  font-size: 1.6rem;
  line-height: 1;
  flex-shrink: 0;
}

.header h1 {
  margin: 0;
  color: var(--paper-white);
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-title-short {
  display: none;
}

.header p {
  margin: 0;
  color: var(--paper-white);
  font-size: 1.05rem;
}

.header-actions {
  position: relative;
  display: flex;
  flex-shrink: 0;
  gap: 10px;
}

.share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  height: 40px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--chalk-line);
  border-radius: var(--radius-sm);
  background: var(--eraser);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
}

.share-btn:hover {
  background: var(--eraser-dark);
}

.share-toast {
  position: absolute;
  top: 40px;
  right: 0;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--paper-white);
  font-size: 0.8rem;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.share-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 640px) {
  .header-inner {
    padding: 8px clamp(10px, 4vw, 24px);
    gap: 8px;
  }

  .header-title-full {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .header-title-short {
    display: inline;
  }

  .header-actions {
    gap: 6px;
  }

  .share-btn {
    height: 44px;
    min-height: 44px;
    min-width: 44px;
    padding: 0 10px;
    font-size: 0.78rem;
  }
}

.mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--eraser);
  padding: 4px;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
}

.mode-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  min-height: 46px;
  margin: 0;
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: bold;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.mode-tab.active {
  background: var(--ink);
  color: var(--paper-white);
}

.install-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  padding: 12px 14px;
  background: var(--sky-pale);
  border: 1px solid var(--sky);
  border-radius: var(--radius-md);
}

.install-banner-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.install-banner-text {
  flex: 1;
  color: var(--ink);
  font-size: 0.9rem;
}

/* Colors, radius and cursor come from Pico's default (primary) button
   theme; only the compact sizing for this inline banner is custom. */
.install-banner-btn {
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: bold;
}

.install-banner-close {
  flex-shrink: 0;
  padding: 4px 6px;
  font-size: 0.9rem;
  color: var(--pencil-soft);
  background: transparent;
  border: none;
  cursor: pointer;
}

.mode-pill {
  display: inline-block;
  padding: 2px 7px;
  font-size: 0.65rem;
  font-weight: bold;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 1.4;
  border-radius: 999px;
  background: var(--marker);
  color: var(--paper-white);
}

.mode-pill-beta {
  animation: pill-wiggle 4.3s ease-in-out -2.4s infinite;
}

@keyframes pill-wiggle {

  0%,
  30%,
  100% {
    transform: rotate(0deg);
  }

  5% {
    transform: rotate(-10deg);
  }

  10% {
    transform: rotate(9deg);
  }

  15% {
    transform: rotate(-7deg);
  }

  20% {
    transform: rotate(5deg);
  }

  25% {
    transform: rotate(-2deg);
  }
}

@media (prefers-reduced-motion: reduce) {

  .mode-pill-beta {
    animation: none;
  }
}

@media (max-width: 480px) {
  .mode-tabs {
    gap: 2px;
    padding: 3px;
  }

  .mode-tab {
    flex-direction: column;
    gap: 3px;
    min-height: 52px;
    padding: 8px 4px;
    font-size: 0.8rem;
  }

  .tab-icon {
    display: none;
  }

  .mode-pill {
    font-size: 0.55rem;
    padding: 1px 5px;
  }

  .quiz-card {
    padding: 28px 16px;
  }

  .quiz-form {
    flex-direction: column;
    align-items: stretch;
  }

  .quiz-form input[type="number"],
  .quiz-form button {
    width: 100%;
  }

  .flash-stack {
    max-width: 240px;
  }

  .quiz-results button {
    width: 100%;
  }
}

.controls {
  background: var(--paper-white);
  padding: 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  margin-bottom: 30px;
}

body.quiz-complete .controls,
body.flash-complete .controls {
  display: none;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

.controls-advanced {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--chalk-line);
}

/* Pico already themes `details summary` with its own rotating chevron
   (::after) and suppresses the native marker — only override sizing here. */
.controls-advanced-summary {
  min-height: 44px;
  padding: 6px 2px;
  font-weight: bold;
  font-size: 0.95rem;
  color: var(--ink);
}

.controls-advanced-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-top: 12px;
}

.controls-advanced-fields {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.controls-options {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--paper);
  border-left: 3px solid var(--sky);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 8px 0;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: none;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.control-group label,
.control-group legend {
  width: 100%;
  font-weight: bold;
  font-size: 0.95rem;
  color: var(--pencil);
  padding: 0;
}

.legend-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.control-suboption {
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.range-row {
  display: flex;
  gap: 12px;
}

.range-row>div {
  flex: 1;
  min-width: 0;
}

.under-label {
  display: block;
  margin-bottom: 6px;
  color: var(--pencil-soft);
  font-size: 0.9rem;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  min-height: 44px;
  font-size: 1.02rem;
  cursor: pointer;
}

.checkbox-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
}

.checkbox-row .checkbox-group {
  flex: 1;
}

.info-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  box-shadow: none;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-style: normal;
  line-height: 1;
  color: var(--paper-white);
  background: var(--pencil-soft);
  background-color: var(--pencil-soft);
  border-radius: 50%;
  cursor: help;
}

/* Extends the tappable area to ~44px without growing the visual glyph —
   a ::after box is still hit-tested as part of its parent element. */
.info-icon::after {
  content: "";
  position: absolute;
  inset: -13px;
}

.info-tooltip {
  display: none;
  position: absolute;
  bottom: 130%;
  right: 0;
  width: max-content;
  max-width: 220px;
  padding: 6px 8px;
  font-size: 0.78rem;
  font-weight: normal;
  line-height: 1.35;
  color: var(--paper-white);
  background: var(--chalkboard);
  border-radius: var(--radius-sm);
  z-index: 10;
}

.info-icon:hover .info-tooltip,
.info-icon:focus .info-tooltip,
.info-icon.open .info-tooltip {
  display: block;
}

.checkbox-group input[type="checkbox"] {
  flex-shrink: 0;
}

.table-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.table-btn {
  min-height: 44px;
  margin: 0;
  padding: 8px 4px;
  font-size: 1rem;
  font-weight: bold;
  color: var(--ink);
  background: var(--eraser);
  border: 1px solid var(--eraser);
}

.table-btn.selected {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper-white);
  box-shadow: var(--shadow-card);
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--chalk-line);
  justify-content: flex-end;
}

.actions-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* Pico themes buttons via --pico-primary-*/
--pico-secondary-* above,
but doesn"t dim disabled plain buttons the way it dims disabled inputs. */
 button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .actions {
    justify-content: flex-start;
  }

  .actions-group {
    flex-direction: column;
    width: 100%;
  }

  .actions-group button {
    width: 100%;
  }
}

/* Sticky so the primary action is reachable without scrolling past the
   whole (potentially long, Advanced-Options-expanded) controls card. The
   shadow only applies once JS confirms it"s
  actually
  pinned
  over
  content
  (.is-floating)
  —
  otherwise
  it's just sitting in normal flow and a shadow
   would be a stray decoration with nothing underneath it to imply. */
@media (max-width: 680px) {
  .actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    background: var(--paper-white);
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }

  .actions.is-floating {
    box-shadow: 0 -6px 10px -6px rgba(0, 0, 0, 0.12);
  }
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

#worksheet {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 60px 30px;
  background: var(--paper-white);
  padding: 30px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  justify-items: center;
  font-family: var(--font-numbers);
}

.problem {
  width: 100%;
  max-width: 180px;
  margin: 0 auto;
}

/* Algebra equations are a single line of text, unlike the stacked digits
   of the other problem types, so they need wider columns to avoid
   overflowing into neighboring problems once numbers get larger. */
#worksheet:has(.algebra) {
  grid-template-columns: repeat(3, 1fr);
}

.problem.algebra {
  max-width: 320px;
}

@media (max-width: 960px) {
  #worksheet {
    grid-template-columns: repeat(4, 1fr);
    gap: 50px 25px;
  }

  #worksheet:has(.algebra) {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 730px) {
  .controls-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  #worksheet {
    grid-template-columns: repeat(3, 1fr);
    gap: 40px 20px;
  }

  #worksheet:has(.algebra) {
    grid-template-columns: repeat(2, 1fr);
  }

  .control-group label,
  .control-group legend {
    font-size: 1.05rem;
  }

  .control-group select {
    font-size: 1.15rem;
  }
}

@media (max-width: 520px) {
  #worksheet {
    grid-template-columns: repeat(2, 1fr);
    gap: 35px 15px;
  }

  #worksheet:has(.algebra) {
    grid-template-columns: 1fr;
  }
}

.regular {
  text-align: right;
}

.top,
.middle {
  font-size: 26px;
  line-height: 1.6em;
}

.middle {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  margin: 4px 0;
}

.op {
  width: 28px;
  text-align: center;
  margin-right: 8px;
}

.bottom {
  min-width: 80px;
  text-align: right;
}

.division-problem {
  display: flex;
  align-items: flex-start;
  font-size: 26px;
  margin: 24px 0 64px 0;
  padding-bottom: 12px;
}

.divisor {
  padding: 6px 10px 0 0;
  font-weight: 600;
  text-align: right;
  min-width: 28px;
}

.division-symbol {
  position: relative;
  display: inline-block;
  padding-left: 8px;
  min-width: 120px;
}

.division-symbol::before,
.division-symbol::after {
  content: "";
  position: absolute;
  left: 0;
  background: var(--ink);
  z-index: 1;
}

.division-symbol::before {
  top: 0;
  width: calc(100% - 4px);
  height: 3px;
}

.division-symbol::after {
  top: 0;
  width: 4px;
  height: 100%;
}

.dividend {
  position: relative;
  z-index: 2;
  display: inline-block;
  margin-left: -6px;
  padding: 6px 8px 0 6px;
  text-align: left;
  min-width: calc(100% - 6px);
}

.algebra {
  text-align: center;
  font-size: clamp(18px, 5vw, 28px);
  padding: 20px 0;
}

.equation {
  margin-bottom: 25px;
}

.answer-space {
  height: 50px;
  margin-top: 8px;
  border-top: 2px solid var(--ink);
}

.quiz-idle {
  background: var(--paper-white);
  padding: 40px;
  text-align: center;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  color: var(--pencil-soft);
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-weight: bold;
  font-size: 1.15rem;
  color: var(--ink);
  margin-bottom: 16px;
  padding: 0 4px;
}

.quiz-card {
  background: var(--paper-white);
  border-top: 4px solid var(--sky);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 50px 30px;
  text-align: center;
  transition: background-color 0.15s ease;
}

/* Shared by the quiz card and flashcard back face (below). */
.bg-correct {
  background-color: var(--leaf-bg);
}

.bg-incorrect {
  background-color: var(--apple-bg);
}

@keyframes judge-pulse {
  0% {
    transform: scale(1);
  }

  35% {
    transform: scale(1.03);
  }

  100% {
    transform: scale(1);
  }
}

.quiz-card.bg-correct,
.quiz-card.bg-incorrect {
  animation: judge-pulse 0.25s ease;
}

@media (prefers-reduced-motion: reduce) {

  .quiz-card.bg-correct,
  .quiz-card.bg-incorrect {
    animation: none;
  }
}

.quiz-prompt {
  font-family: var(--font-numbers);
  font-size: clamp(1.75rem, 9vw, 2.75rem);
  margin-bottom: clamp(16px, 4vw, 30px);
}

.quiz-prompt.division-problem {
  display: inline-flex;
  font-size: clamp(1.375rem, 8vw, 2.125rem);
  margin: 0 auto clamp(16px, 4vw, 30px) auto;
}

.quiz-prompt.equation {
  font-size: clamp(1.6rem, 8vw, 2.5rem);
  white-space: normal;
}

.regular-prompt {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  text-align: right;
}

.regular-prompt .rp-row {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.2em;
}

.regular-prompt .rp-op {
  min-width: 0.8em;
  text-align: center;
}

.regular-prompt .rp-line {
  border-top: 3px solid var(--ink);
  margin-top: 0.15em;
}

.quiz-form {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.quiz-form input[type="number"] {
  width: 130px;
  min-height: 52px;
  padding: 10px 12px;
  font-size: 1.2rem;
  border: 2px solid var(--chalk-line);
  border-radius: var(--radius-sm);
  text-align: center;
  font-family: var(--font-numbers);
}

.quiz-form button {
  min-height: 52px;
}

.quiz-answer-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.quiz-sign-toggle {
  min-width: 52px;
  padding: 0 14px;
  font-size: 1.3rem;
  font-weight: bold;
}

.quiz-r-label {
  font-weight: bold;
}

.flash-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.flash-backdrop {
  position: absolute;
  inset: 0;
  background: var(--chalkboard);
  opacity: 0.6;
}

.flash-modal {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 420px;
}

.flash-close {
  align-self: flex-end;
  border: none;
  border-radius: 999px;
  background: var(--paper-white);
  color: var(--ink);
  font-weight: bold;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 8px 16px;
  box-shadow: var(--shadow-card);
}

.flash-close:hover,
.flash-close:focus-visible {
  background: var(--eraser);
}

/* Left-aligned above the card stack, matching its 300px width, so the
   pace time sits directly above the card's
  left
  edge.
  A
  solid
  chip
  (like
   .flash-close)
  instead
  of
  bare
  text
  —
  the
  dark
  backdrop
  behind
  the
  modal
  made
  --ink
  text
  nearly
  unreadable
  without
  one.
  */
.flash-pace {
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--paper-white);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  box-shadow: var(--shadow-card);
}

.flash-pace-label {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--pencil-soft);
}

.flash-pace-time {
  font-weight: bold;
  font-size: 1.25rem;
  color: var(--ink);
}

@keyframes flash-pace-shake {

  0%,
  100% {
    transform: translateX(0);
  }

  20% {
    transform: translateX(-3px);
  }

  40% {
    transform: translateX(3px);
  }

  60% {
    transform: translateX(-2px);
  }

  80% {
    transform: translateX(2px);
  }
}

.flash-pace.is-time-up {
  animation: flash-pace-shake 0.4s ease;
}

/* Holds the active card plus, briefly, the outgoing one flying off on top of
   it — the incoming card is always already in place underneath, so there's
   never a frame with no card showing while the outgoing one animates away. */
.flash-stack {
  position: relative;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
}

/* Padding-percentage ratio box instead of `aspect-ratio`: WebKit mishandles
   aspect-ratio combined with a preserve-3d descendant (flip renders flat). */
.flash-stack::before {
  content: "";
  display: block;
  padding-top: 133.333%;
}

.flash-card {
  position: absolute;
  inset: 0;
  padding: 0;
  border: none;
  background: none;
  -webkit-perspective: 1200px;
  perspective: 1200px;
  cursor: pointer;
  touch-action: pan-y;
  transition:
    transform 0.3s ease,
    opacity 0.3s ease;
}

.flash-card.is-dragging {
  transition: none;
}

.flash-card.is-dragging .flash-face {
  box-shadow: var(--shadow-card-lifted);
}

/* Judged and animating off — let taps/swipes pass through to the card
   underneath instead of hitting the one on its way out. */
.flash-card.is-departing {
  pointer-events: none;
}

.flash-card-inner {
  position: absolute;
  inset: 0;
  transition: transform 0.4s ease;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
}

.flash-card.is-flipped .flash-card-inner {
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
}

/* The browser's default focus ring lands on .flash-card, which never
   rotates — only .flash-card-inner does — so it would sit still while the
   card flips underneath it, and its corners don't match --radius-md. Draw
   the ring on the faces instead, which do rotate and already share that
   radius. */
.flash-card:focus {
  outline: none;
}

.flash-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  text-align: center;
  background: var(--paper-white);
  color: var(--ink);
  border-top: 4px solid var(--sky);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.flash-card:focus-visible .flash-face {
  box-shadow:
    0 0 0 3px var(--sky),
    var(--shadow-card);
}

/* Live tint while dragging, driven by --drag-tint/--drag-tint-color set from
   JS on touchmove. Inherits down from .flash-card so it clears automatically
   whenever a card is re-rendered (fresh element, no stale inline props). */
.flash-face-back::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: var(--drag-tint, 0);
  background: var(--drag-tint-color, transparent);
}

.flash-face-back {
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
  transition: background-color 0.15s ease;
}

@keyframes judge-pulse-flipped {
  0% {
    -webkit-transform: rotateY(180deg) scale(1);
    transform: rotateY(180deg) scale(1);
  }

  35% {
    -webkit-transform: rotateY(180deg) scale(1.03);
    transform: rotateY(180deg) scale(1.03);
  }

  100% {
    -webkit-transform: rotateY(180deg) scale(1);
    transform: rotateY(180deg) scale(1);
  }
}

.flash-face-back.bg-correct,
.flash-face-back.bg-incorrect {
  animation: judge-pulse-flipped 0.25s ease;
}

@media (prefers-reduced-motion: reduce) {

  .flash-face-back.bg-correct,
  .flash-face-back.bg-incorrect {
    animation: none;
  }
}

.flash-answer {
  font-family: var(--font-numbers);
  font-size: clamp(2rem, 10vw, 3rem);
  font-weight: bold;
  color: var(--ink);
}

.flash-judge-row {
  display: flex;
  justify-content: center;
  gap: 40px;
}

.flash-judge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  padding: 0;
  border-radius: 50%;
  border: none;
  font-size: 1.6rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: var(--shadow-card);
}

.flash-judge-wrong {
  background: var(--apple-bg);
  color: var(--apple);
}

.flash-judge-right {
  background: var(--leaf-bg);
  color: var(--leaf);
}

@media (max-width: 680px) {

  body.session-active .mode-tabs,
  body.session-active .controls-grid {
    display: none;
  }

  body.session-active .header-inner {
    padding: 10px 16px;
  }

  body.session-active .header {
    margin-bottom: 12px;
  }

  body.session-active .header p {
    display: none;
  }

  body.session-active .controls {
    padding: 12px 16px;
    margin-bottom: 16px;
  }

  body.session-active .actions {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
  }
}

.quiz-results {
  background: var(--paper-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 30px;
  text-align: center;
}

.quiz-results h2 {
  color: var(--ink);
  margin-top: 0;
}

.quiz-avg-pace {
  color: var(--pencil-soft);
  font-size: 0.9rem;
  margin-top: -8px;
}

.quiz-results-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 20px;
}

.quiz-results-actions button {
  min-width: 160px;
}

.grade-letter {
  font-size: 1.4em;
  font-weight: bold;
  padding: 2px 10px;
  border-radius: 6px;
}

.grade-A,
.grade-B {
  background: var(--leaf-bg);
  color: var(--leaf);
}

.grade-C {
  background: var(--sun-bg);
  color: var(--sun);
}

.grade-D,
.grade-F {
  background: var(--apple-bg);
  color: var(--apple);
}

.quiz-advice {
  max-width: 500px;
  margin: 16px auto;
  color: var(--pencil-soft);
}

.quiz-missed {
  text-align: left;
  max-width: 480px;
  margin: 20px auto 2rem;
}

.quiz-missed-table {
  width: 100%;
  margin: 10px 0 0 0;
  border-collapse: collapse;
  font-family: var(--font-numbers);
}

.quiz-missed-table tr:last-child td {
  border-bottom: none;
}

.quiz-missed-table th,
.quiz-missed-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--chalk-line);
  text-align: left;
}

.quiz-missed-table th {
  font-family: var(--font-reading);
  font-size: 0.85em;
  color: var(--pencil-soft);
}

.flash-judge-counts {
  font-size: 0.85em;
  opacity: 0.75;
  white-space: nowrap;
}

@page {
  size: letter portrait;
  margin: 10mm 8mm;
}

@media print {

  .controls,
  .header,
  .actions,
  .mode-tabs,
  #quizArea,
  #flashArea,
  #flashOverlay,
  #installBanner {
    display: none !important;
  }

  body {
    margin: 0;
    background: white;
  }

  .container {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  #worksheet {
    grid-template-columns: repeat(5, 1fr) !important;
    gap: 30px 16px !important;
    padding: 20px 28px !important;
    box-shadow: none !important;
    /* usable page height minus the worksheet's own top/bottom padding;
       a fixed target lets align-content spread rows evenly on page 1
       and still overflow cleanly to page 2 once content exceeds it. */
    min-height: calc(11in - 20mm - 40px) !important;
    align-content: space-evenly !important;
  }

  #worksheet:has(.algebra) {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  #worksheet:has(.algebra),
  #worksheet:has(.division-problem) {
    row-gap: 0 !important;
  }

  .problem {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 8px !important;
    break-inside: avoid;
  }

  .regular .top,
  .regular .middle {
    font-size: 20px !important;
    line-height: 1.4 !important;
  }

  .middle {
    margin: 3px 0 !important;
  }

  .algebra {
    font-size: 18px !important;
    margin: 18px 0 95px 0 !important;
  }

  .division-problem {
    font-size: 20px !important;
    margin: 16px 0 78px 0 !important;
    padding-bottom: 6px !important;
  }

  .answer-space {
    height: 34px !important;
    margin-top: 6px !important;
  }

  /* trailing margin here can force a blank page if it lands near a page break */
  #worksheet .problem:last-child {
    margin-bottom: 0 !important;
  }

  #worksheet .problem:last-child .division-problem {
    margin-bottom: 0 !important;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
