/* Button */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: var(--tap);
  padding: 0 var(--s6);
  border: 0;
  border-radius: var(--r-pill);
  font-weight: var(--fw-bold);
  font-size: var(--fs-body);
  cursor: pointer;
  text-decoration: none;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.btn:active {
  transform: translateY(var(--edge));
}
.btn-primary {
  background: var(--sky-700);
  color: #fff;
  box-shadow: 0 var(--edge) 0 var(--sky-800);
}
.btn-primary:active {
  box-shadow: 0 0 0 var(--sky-800);
}
.btn-pink {
  background: var(--pink-700);
  color: #fff;
  box-shadow: 0 var(--edge) 0 #8a1a50;
}
.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--line), 0 var(--edge) 0 var(--line);
}
.btn-ghost {
  background: transparent;
  color: var(--sky-700);
  padding: 0 var(--s4);
}
.btn-lg {
  min-height: 64px;
  font-size: 22px;
}
.btn-block {
  width: 100%;
}
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Card */
.card {
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-raised);
  padding: var(--s5);
}

/* Speech bubble */
.bubble {
  display: flex;
  align-items: center;
  gap: var(--s4);
}
.bubble img {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
}
.bubble p {
  background: var(--surface);
  border-radius: var(--r-md);
  padding: var(--s3) var(--s4);
  box-shadow: var(--shadow-raised);
  position: relative;
}

/* Question */
.question {
  font-size: var(--fs-question);
  font-weight: var(--fw-bold);
  line-height: 1;
  letter-spacing: 0.02em;
  text-align: center;
  white-space: nowrap;
}
.question .times {
  color: var(--navy);
  padding: 0 0.12em;
}
.answer {
  min-width: 3.2ch;
  min-height: 1.25em;
  margin: var(--s4) auto 0;
  padding: var(--s2) var(--s4);
  border-radius: var(--r-sm);
  background: var(--surface);
  box-shadow: inset 0 0 0 3px var(--line);
  font-size: var(--fs-answer);
  font-weight: var(--fw-bold);
  line-height: 1.1;
  text-align: center;
  display: block;
  width: fit-content;
}

/* Timer bar */
.timer {
  height: 8px;
  background: var(--sky-50);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.timer span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--sky-500);
  border-radius: inherit;
  transform-origin: left center;
}
.timer.run span {
  animation: drain linear forwards;
}
@keyframes drain {
  to {
    transform: scaleX(0);
  }
}
/* "Pause motion" in the website's accessibility options shortens every animation.
   The timer bar shows the time left, so it keeps its real length
   (SECONDS_PER_QUESTION in core/rules.js). */
html.tsa-motion .timer.run span {
  animation-duration: 6s !important;
}

/* Progress dots */
.dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.dots i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--line);
}
.dots i.done {
  background: var(--sky-500);
}
.dots i.now {
  background: var(--sun-400);
  transform: scale(1.3);
}

/* Number pad */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, var(--key));
  gap: var(--s3);
  justify-content: center;
}
.numpad button {
  height: var(--key);
  border: 0;
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 32px;
  font-weight: var(--fw-bold);
  box-shadow: inset 0 0 0 2px var(--line), 0 var(--edge) 0 var(--line);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.numpad button:active,
.numpad button.pressed {
  transform: translateY(var(--edge));
  box-shadow: inset 0 0 0 2px var(--line);
}
.numpad .enter {
  background: var(--sky-700);
  color: #fff;
  font-size: 22px;
  box-shadow: 0 var(--edge) 0 var(--sky-800);
}
.numpad .del {
  font-size: 26px;
}
/* The website's accessibility options button sits in a bottom corner, where on a
   phone it would cover the number pad. Hide it while a number pad is on screen;
   the chosen settings stay on. (The native apps don't load the widget.) */
body:has(.numpad) tabsphere-a11y {
  display: none;
}

/* Score ring */
.ring {
  --p: 0;
  width: 180px;
  aspect-ratio: 1;
  border-radius: 50%;
  margin: 0 auto;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--green-700) calc(var(--p) * 1%), var(--sky-50) 0);
}
.ring > div {
  width: 140px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--surface);
  display: grid;
  place-content: center;
  text-align: center;
}
.ring b {
  font-size: 56px;
  line-height: 1;
}
.ring small {
  font-size: var(--fs-small);
  color: var(--ink-soft);
}

/* Fact chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  list-style: none;
  padding: 0;
  margin: 0;
}
.chips li {
  background: var(--amber-50);
  color: var(--amber-700);
  border-radius: var(--r-pill);
  padding: var(--s1) var(--s4);
  font-weight: var(--fw-bold);
}

/* Hints and small print */
.hint {
  font-size: var(--fs-small);
  color: var(--ink-muted);
}

/* Text input */
input[type='text'] {
  font: inherit;
  font-weight: var(--fw-bold);
  min-height: var(--tap);
  width: 100%;
  padding: 0 var(--s4);
  border: 0;
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--line);
}
input[type='text']:focus-visible {
  box-shadow: inset 0 0 0 2px var(--sky-700);
}
label {
  font-weight: var(--fw-bold);
}

/* Practice feedback: kind words, the right answer, never red */
.feedback {
  display: grid;
  gap: var(--s3);
  justify-items: center;
  text-align: center;
  padding: var(--s5);
  border-radius: var(--r-md);
  width: min(100%, 420px);
}
.feedback.right {
  background: var(--green-50);
  color: var(--green-700);
}
.feedback.not-yet {
  background: var(--amber-50);
  color: var(--amber-700);
}
.feedback-title {
  font-size: var(--fs-title);
  font-weight: var(--fw-bold);
}
.feedback-fact {
  font-size: var(--fs-display);
  font-weight: var(--fw-bold);
  color: var(--ink);
  line-height: 1.1;
}
.feedback-note {
  color: var(--ink-soft);
}
.feedback .mark {
  display: inline-grid;
  place-items: center;
  width: 1.4em;
  height: 1.4em;
  border-radius: 50%;
  background: var(--green-700);
  color: #fff;
  font-size: 0.8em;
  vertical-align: 0.1em;
}
:root[data-contrast='high'] .feedback {
  box-shadow: inset 0 0 0 2px #000;
  color: #000;
}
:root[data-contrast='high'] .feedback .mark {
  background: #000;
}

/* Streak */
.streak {
  font-weight: var(--fw-bold);
  color: var(--ink);
  background: var(--sun-100);
  border-radius: var(--r-pill);
  padding: var(--s2) var(--s4);
  justify-self: center;
  width: fit-content;
  margin-inline: auto;
}
.streak-star {
  color: #b07800;
}
:root[data-contrast='high'] .streak {
  box-shadow: inset 0 0 0 2px #000;
}
:root[data-contrast='high'] .streak-star {
  color: #000;
}

/* Celebration: a short burst of stars after practice (fades only if motion is reduced) */
.celebrate {
  position: relative;
}
.big-score {
  font-size: var(--fs-title);
}
.big-score b {
  font-size: var(--fs-display);
}
.burst {
  position: absolute;
  inset: 0 0 auto;
  height: 0;
  pointer-events: none;
}
.burst i {
  position: absolute;
  left: 50%;
  top: 40px;
  width: 14px;
  height: 14px;
  background: var(--sun-400);
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  opacity: 0;
  animation: burst 900ms var(--ease) forwards;
}
.burst i:nth-child(even) {
  background: var(--pink-500);
}
.burst i:nth-child(1) { --x: -140px; --y: -10px; }
.burst i:nth-child(2) { --x: -100px; --y: 40px; animation-delay: 40ms; }
.burst i:nth-child(3) { --x: -60px; --y: -30px; animation-delay: 80ms; }
.burst i:nth-child(4) { --x: -20px; --y: 50px; animation-delay: 20ms; }
.burst i:nth-child(5) { --x: 20px; --y: -40px; animation-delay: 60ms; }
.burst i:nth-child(6) { --x: 60px; --y: 30px; animation-delay: 100ms; }
.burst i:nth-child(7) { --x: 100px; --y: -20px; animation-delay: 30ms; }
.burst i:nth-child(8) { --x: 140px; --y: 20px; animation-delay: 70ms; }
.burst i:nth-child(9) { --x: -120px; --y: 70px; animation-delay: 110ms; }
.burst i:nth-child(10) { --x: 120px; --y: 70px; animation-delay: 50ms; }
@keyframes burst {
  20% {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translate(var(--x), var(--y)) rotate(160deg) scale(1.4);
  }
}
@media (prefers-reduced-motion: reduce) {
  .burst {
    display: none;
  }
}

/* Parental gate */
.gate {
  border: 0;
  border-radius: var(--r-md);
  padding: var(--s5);
  width: min(calc(100% - 2 * var(--s4)), 420px);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-raised);
}
:root[data-contrast='high'] .gate {
  border: 3px solid #000;
}
.gate::backdrop {
  background: rgba(27, 35, 64, 0.55);
}
.gate form {
  display: grid;
  gap: var(--s3);
}
.gate h2 {
  font-size: var(--fs-title);
}
.gate input {
  font-size: var(--fs-title);
  letter-spacing: 0.1em;
  text-align: center;
}
.gate-error:empty {
  display: none;
}
.gate-error {
  color: var(--amber-700);
  font-weight: var(--fw-bold);
}
.gate-actions {
  display: grid;
  gap: var(--s2);
  margin-top: var(--s2);
}

/* Toggles (switches) */
.toggles {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--s2);
}
.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  min-height: var(--tap);
  padding: var(--s2) 0;
  cursor: pointer;
}
.toggle-text {
  display: grid;
}
.toggle small {
  font-size: var(--fs-small);
  font-weight: var(--fw-body);
  color: var(--ink-muted);
}
.toggle input {
  appearance: none;
  flex: none;
  width: 60px;
  height: 36px;
  border-radius: var(--r-pill);
  background: var(--line);
  box-shadow: inset 0 0 0 2px #8a93ad;
  position: relative;
  cursor: pointer;
  margin: 0;
  transition: background var(--t-fast) var(--ease);
}
.toggle input::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform var(--t-fast) var(--ease);
}
.toggle input:checked {
  background: var(--sky-700);
  box-shadow: none;
}
.toggle input:checked::after {
  transform: translateX(24px);
}
:root[data-contrast='high'] .toggle input {
  background: #fff;
  box-shadow: inset 0 0 0 2px #000;
}
:root[data-contrast='high'] .toggle input::after {
  background: #000;
}
:root[data-contrast='high'] .toggle input:checked {
  background: #000;
}
:root[data-contrast='high'] .toggle input:checked::after {
  background: #fff;
}

/* Mastery grid: colour + pattern + symbol for each status */
.m-cell {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1;
  font-weight: var(--fw-bold);
}
.m-new {
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line);
  border: 2px dotted #8a93ad;
  box-shadow: none;
}
.m-learning {
  background: repeating-linear-gradient(135deg, var(--amber-50) 0 4px, #f6d6ad 4px 7px);
  color: var(--amber-700);
}
.m-fast {
  background: var(--sky-50);
  color: var(--sky-700);
  box-shadow: inset 0 0 0 2px var(--sky-500);
}
.m-mastered {
  background: var(--green-700);
  color: #fff;
}
:root[data-contrast='high'] .m-new {
  border-color: #000;
}
:root[data-contrast='high'] .m-learning {
  background: repeating-linear-gradient(135deg, #fff 0 4px, #000 4px 6px);
  color: #000;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff;
}
:root[data-contrast='high'] .m-fast {
  background: #fff;
  color: #000;
  box-shadow: inset 0 0 0 2px #000;
}
:root[data-contrast='high'] .m-mastered {
  background: #000;
  color: #fff;
}
.grid-wrap {
  overflow-x: auto;
}
.mastery-grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 2px;
  table-layout: fixed;
  font-size: 12px;
}
.mastery-grid th {
  font-weight: var(--fw-bold);
  color: var(--ink-soft);
  font-size: 12px;
  padding: 0;
}
.mastery-grid td {
  padding: 0;
}
.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2) var(--s4);
  font-size: var(--fs-small);
}
.legend li {
  display: flex;
  align-items: center;
  gap: var(--s2);
}
.legend .m-cell {
  width: 22px;
  flex: none;
}

/* High contrast: cards keep a visible edge without shadows */
:root[data-contrast='high'] .card {
  box-shadow: inset 0 0 0 2px #000;
}
