/* Maths 3e: Romeo's practice app.
   The look of his math notebook: cool graph paper, pen-ink blue for actions,
   and his teacher's yellow highlighter on the aligned "=" column of every
   worked solution (also the week's focus and the end-of-session title).
   Phone first: one column, big tap targets, the main action in thumb reach. */

:root {
  --paper: #f3f6fb;
  --sheet: #ffffff;
  --grid: #e0e8f4;
  --grid-strong: #c9d6ea;
  --ink: #142037;
  --ink-2: #44526c;
  --ink-3: #6f7c94;
  --line: #d3dcea;
  --blue: #2856e6;
  --blue-press: #1b3fb8;
  --blue-tint: #e7edff;
  --blue-tint-2: #c9d6ff;
  --on-blue: #ffffff;
  --hl: #ffe04a;
  --hl-col: rgba(255, 220, 60, 0.55);
  --hl-text: #5a4600;
  --green: #0c8655;
  --green-tint: #e0f4ea;
  --red: #c73434;
  --red-tint: #fcebeb;
  --amber: #8a5d00;
  --amber-tint: #fff2d1;
  --flame: #f25d0c;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
  --r-s: 10px;
  --r-m: 14px;
  --r-l: 20px;
  --gutter: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0d1625;
    --sheet: #142037;
    --grid: #1c2a45;
    --grid-strong: #283a5c;
    --ink: #e8eef8;
    --ink-2: #b3bfd4;
    --ink-3: #8a97ae;
    --line: #2a3a59;
    --blue: #7d9cff;
    --blue-press: #5b7ee8;
    --blue-tint: #1b2a4f;
    --blue-tint-2: #2a3d70;
    --on-blue: #0d1625;
    --hl: #e8c83a;
    --hl-col: rgba(232, 200, 58, 0.26);
    --hl-text: #0d1625;
    --green: #46d29b;
    --green-tint: #10352a;
    --red: #ff8080;
    --red-tint: #3b1b24;
    --amber: #f3c24f;
    --amber-tint: #382d10;
    --flame: #ff8a3d;
  }
}

/* ------------------------------------------------------------ base */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
p,
ul,
ol,
dl,
dd {
  margin: 0;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.screen {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) var(--gutter) calc(40px + env(safe-area-inset-bottom));
}

.section-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.005em;
}

.section-sub {
  margin-top: 2px;
  font-size: 0.875rem;
  color: var(--ink-3);
}

.card {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 16px;
}

.badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 750;
  white-space: nowrap;
}

.badge-mastered {
  background: var(--green-tint);
  color: var(--green);
}

/* KaTeX: slightly smaller than its default, and long formulas scroll sideways instead of breaking the page */
.katex {
  font-size: 1.12em;
}

.math-display {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.math-display .katex-display {
  margin: 0.4em 0;
}

/* ------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 20px;
  border: 2px solid transparent;
  border-radius: var(--r-m);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  transition: transform 80ms ease, background-color 120ms ease, box-shadow 80ms ease;
  touch-action: manipulation;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  background: var(--blue);
  color: var(--on-blue);
  box-shadow: 0 3px 0 var(--blue-press);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--blue-press);
}

.btn-secondary {
  background: var(--sheet);
  color: var(--blue);
  border-color: var(--line);
  box-shadow: 0 2px 0 var(--line);
}

.btn-secondary:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: none;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  min-height: 48px;
  font-weight: 600;
}

.btn-ghost:hover {
  text-decoration: underline;
}

.btn-big {
  width: 100%;
  min-height: 62px;
  font-size: 1.22rem;
  border-radius: 18px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--sheet);
  font-size: 1.1rem;
  color: var(--ink-2);
}

/* ------------------------------------------------------------ splash, errors, sync badge */

.splash {
  min-height: 70vh;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  color: var(--ink-2);
}

.splash-late {
  opacity: 0;
  animation: fade-in 400ms ease 9s forwards;
  font-size: 0.9rem;
}

.sync-badge {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  padding: 8px 16px;
  border-radius: 99px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.9rem;
  font-weight: 650;
  box-shadow: 0 6px 20px -8px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.screen-error p {
  margin: 12px 0 20px;
}

/* ------------------------------------------------------------ login */

.screen-login {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: var(--blue);
  color: var(--on-blue);
  font-size: 1.9rem;
  font-weight: 900;
  line-height: 1;
  box-shadow: inset 0 -15px 0 0 rgba(255, 224, 74, 0.9);
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 800;
}

.login-title {
  font-size: 1.6rem;
  font-weight: 800;
}

.pin-dots {
  display: flex;
  gap: 14px;
}

.pin-dots i {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--ink-3);
  transition: background-color 90ms ease, transform 90ms ease;
}

.pin-dots i.is-on {
  background: var(--ink);
  border-color: var(--ink);
  transform: scale(1.08);
}

.pin-dots.is-shaking {
  animation: shake 360ms ease;
}

.login-msg {
  min-height: 1.5em;
  max-width: 320px;
  text-align: center;
  color: var(--red);
  font-weight: 650;
}

.pinpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: min(320px, 100%);
}

.pinpad.is-busy {
  opacity: 0.55;
  pointer-events: none;
}

.pin-key {
  min-height: 66px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--sheet);
  font-size: 1.65rem;
  font-weight: 650;
  box-shadow: 0 2px 0 var(--line);
  touch-action: manipulation;
}

.pin-key:active {
  transform: translateY(2px);
  box-shadow: none;
  background: var(--blue-tint);
}

.pin-key-text {
  font-size: 1rem;
  color: var(--ink-2);
}

/* ------------------------------------------------------------ home */

.home-top {
  padding: 6px 0 14px;
}

.home-date {
  color: var(--ink-3);
  font-size: 0.92rem;
  text-transform: none;
}

.hello {
  font-size: 2.1rem;
  font-weight: 850;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 14px 12px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 16px;
}

.streak-days {
  font-size: 1.55rem;
  font-weight: 850;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.streak-line {
  margin-top: 4px;
  font-size: 0.88rem;
  color: var(--ink-2);
}

.points {
  text-align: right;
}

.points-value {
  font-size: 1.55rem;
  font-weight: 850;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.points-label {
  font-size: 0.88rem;
  color: var(--ink-2);
}

.level {
  grid-column: 1 / -1;
}

.level-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 0.92rem;
}

.level-head span {
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.level-bar {
  display: block;
  height: 12px;
  margin-top: 6px;
  border-radius: 99px;
  background: var(--blue-tint);
  overflow: hidden;
}

.level-bar i {
  display: block;
  height: 100%;
  min-width: 6px;
  border-radius: 99px;
  background: var(--blue);
}

.cta {
  margin: 20px 0 22px;
}

.cta-sub {
  margin-top: 10px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--ink-2);
}

.focus-card {
  margin-bottom: 26px;
}

/* the week's focus is "highlighted", like the teacher marks what matters */
.focus-title {
  display: inline;
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.5;
  background: linear-gradient(transparent 58%, var(--hl-col) 58%);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.focus-note {
  margin-top: 8px;
  color: var(--ink-2);
}

.goal {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.goal-dots {
  display: inline-flex;
  gap: 6px;
}

.goal-dots i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--blue);
}

.goal-dots i.is-done {
  background: var(--blue);
}

.goal-text {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.m-group {
  margin-top: 16px;
}

.m-group-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink-2);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.m-list {
  list-style: none;
  padding: 0;
}

.m-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 2px 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--grid);
}

.m-name {
  font-size: 0.98rem;
}

.m-value {
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.m-row.is-new .m-value {
  font-weight: 500;
  font-style: italic;
  color: var(--ink-3);
}

.m-bar {
  grid-column: 1 / -1;
  display: block;
  height: 8px;
  border-radius: 99px;
  background: var(--grid);
  overflow: hidden;
}

.m-row.is-new .m-bar {
  background: repeating-linear-gradient(90deg, var(--grid) 0 6px, transparent 6px 10px);
}

.m-bar i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: var(--blue);
}

.m-row.is-mastered .m-bar i {
  background: var(--green);
}

.m-row .badge {
  grid-column: 1 / -1;
  justify-self: start;
  margin-top: 4px;
}

.home-foot {
  margin-top: 28px;
  text-align: center;
}

/* ------------------------------------------------------------ diagnostic intro */

.intro-title {
  font-size: 2rem;
  font-weight: 850;
  letter-spacing: -0.02em;
  margin: 18px 0 16px;
}

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

.intro-list li {
  position: relative;
  padding: 12px 14px 12px 44px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
}

.intro-list li::before {
  content: "✓";
  position: absolute;
  left: 14px;
  top: 11px;
  font-weight: 900;
  color: var(--green);
}

.intro-actions {
  display: grid;
  gap: 8px;
  margin-top: 24px;
}

/* ------------------------------------------------------------ question */

.q-top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin: calc(-14px - env(safe-area-inset-top)) calc(-1 * var(--gutter)) 12px;
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.q-count-text {
  display: block;
  font-size: 0.85rem;
  font-weight: 750;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.progress {
  display: block;
  height: 8px;
  margin-top: 4px;
  border-radius: 99px;
  background: var(--blue-tint);
  overflow: hidden;
}

.progress i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: var(--blue);
  transition: width 400ms ease;
}

.q-score {
  padding: 5px 11px;
  border-radius: 99px;
  background: var(--blue-tint);
  color: var(--blue);
  font-size: 0.9rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sheet {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 16px;
}

.q-skill {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--ink-2);
  margin-bottom: 8px;
}

.q-tag {
  padding: 1px 9px;
  border-radius: 99px;
  background: var(--hl);
  color: var(--hl-text);
  font-size: 0.78rem;
  font-weight: 800;
}

.q-prompt {
  font-size: 1.14rem;
  line-height: 1.55;
}

.q-paper {
  margin: 12px 2px 14px;
  font-size: 0.9rem;
  color: var(--ink-2);
}

/* multiple choice: the one-try rule, on its own line under the paper reminder */
.q-paper-note {
  display: block;
  margin-top: 4px;
  font-weight: 700;
  color: var(--ink);
}

.answer-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.88rem;
  font-weight: 750;
  color: var(--ink-2);
}

.answer-field {
  width: 100%;
  min-height: 58px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: var(--r-m);
  background: var(--sheet);
  font-family: var(--mono);
  font-size: 1.3rem;
  letter-spacing: 0.01em;
  -webkit-appearance: none;
  appearance: none;
}

.answer-field:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 4px var(--blue-tint);
}

.answer-field:disabled {
  opacity: 0.75;
  -webkit-text-fill-color: var(--ink);
}

.answer-field::placeholder {
  color: var(--ink-3);
  font-family: var(--font);
  font-size: 1.05rem;
}

.keys {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(42px, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.keys-few {
  grid-template-columns: repeat(2, minmax(0, 88px));
}

.key {
  min-height: 48px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--sheet);
  font-size: 1.2rem;
  font-weight: 650;
  box-shadow: 0 2px 0 var(--line);
  touch-action: manipulation;
}

.key:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: none;
  background: var(--blue-tint);
}

.key:disabled {
  opacity: 0.5;
}

/* variables in math italic, as on paper */
.key-var {
  font-family: KaTeX_Math, "Times New Roman", serif;
  font-style: italic;
  font-weight: 400;
  font-size: 1.35rem;
}

.preview {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--blue-tint);
  overflow-x: auto;
  overflow-y: hidden; /* see .choice-label */
}

.preview-label {
  font-size: 0.88rem;
  color: var(--ink-2);
}

.preview-error {
  background: var(--amber-tint);
}

.preview-error .preview-label {
  color: var(--amber);
  font-weight: 650;
}

.answer-msg {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--amber-tint);
  color: var(--amber);
  font-weight: 650;
}

.sci-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px; /* room for the raised exponent box */
}

.sci-mantissa {
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
}

.sci-times {
  flex: none;
  font-family: KaTeX_Main, "Times New Roman", serif;
  font-size: 1.45rem;
  white-space: nowrap;
}

.sci-power {
  flex: 0 0 4.4em;
  align-self: flex-start;
  margin-top: -12px;
}

.sci-exponent {
  min-height: 48px;
  padding: 6px 10px;
  font-size: 1.15rem;
  text-align: center;
}

.key-sign {
  flex: 0 0 42px;
  min-height: 48px;
}

.choices {
  display: grid;
  gap: 10px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: var(--r-m);
  background: var(--sheet);
  text-align: left;
  font-size: 1.04rem;
  line-height: 1.4;
  transition: border-color 100ms ease, background-color 100ms ease;
  touch-action: manipulation;
}

.choice-mark {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--line);
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--ink-2);
}

/* Long math scrolls sideways. KaTeX boxes stand a few pixels above and below
   the line, so without overflow-y: hidden every option would show a vertical
   scrollbar on a desktop browser; the padding keeps the tallest glyphs whole. */
.choice-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 3px 0;
}

.choice.is-selected {
  border-color: var(--blue);
  background: var(--blue-tint);
}

.choice.is-selected .choice-mark {
  border-color: var(--blue);
  background: var(--blue);
  color: var(--on-blue);
}

.choice:disabled {
  cursor: default;
  opacity: 1;
}

.choice.is-correct {
  border-color: var(--green);
  background: var(--green-tint);
}

.choice.is-correct .choice-mark {
  border-color: var(--green);
  background: var(--green);
  color: var(--sheet);
}

.choice.is-wrong {
  border-color: var(--red);
  background: var(--red-tint);
}

.choice-flag {
  flex: none;
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--ink-2);
}

.q-actions {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 10px;
  margin-top: 16px;
}

.q-dontknow.is-armed {
  border-color: var(--amber);
  background: var(--amber-tint);
  color: var(--amber);
}

.fb {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--r-l);
  border: 2px solid;
  scroll-margin-top: 84px;
}

.fb-title {
  font-size: 1.12rem;
  font-weight: 800;
}

.fb-sub,
.fb-hint {
  margin-top: 6px;
  color: var(--ink-2);
}

.fb-correct {
  background: var(--green-tint);
  border-color: var(--green);
  animation: pop 320ms cubic-bezier(0.2, 1.4, 0.5, 1);
}

.fb-correct .fb-title {
  color: var(--green);
  font-size: 1.35rem;
}

.fb-retry {
  background: var(--amber-tint);
  border-color: var(--amber);
}

.fb-retry .fb-title {
  color: var(--amber);
}

.fb-wrong {
  background: var(--red-tint);
  border-color: var(--red);
}

.fb-wrong .fb-title {
  color: var(--red);
}

.fb-neutral {
  background: var(--blue-tint);
  border-color: var(--blue-tint-2);
}

.q-answer-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  margin: 18px 2px 10px;
  font-size: 1.1rem;
}

.q-answer-label {
  font-weight: 800;
}

.answer-key {
  overflow-x: auto;
  overflow-y: hidden; /* see .choice-label */
  padding: 3px 0;
  max-width: 100%;
}

/* ------------------------------------------------------------ the worked solution */

.demarche {
  margin-top: 6px;
  padding: 14px 12px 16px;
  border: 1px solid var(--grid-strong);
  border-radius: var(--r-l);
  background-color: var(--sheet);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: -1px -1px;
}

.dm-title {
  font-size: 1.02rem;
  font-weight: 850;
  margin: 0 0 10px 2px;
}

.dm-lines {
  --dm-col: 2.3rem;
  position: relative;
  list-style: none;
  margin: 0;
  padding: 4px 0;
}

/* the highlighted column where the "=" signs line up */
.dm-lines::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--dm-col);
  border-radius: 8px;
  background: var(--hl-col);
}

.dm-row {
  position: relative;
  display: grid;
  grid-template-columns: var(--dm-col) minmax(0, 1fr);
  align-items: center;
  min-height: 2.6rem;
}

.dm-rel {
  text-align: center;
  font-size: 1.12rem;
}

.dm-math {
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-left: 4px;
}

.dm-math .katex-display {
  margin: 2px 0;
  text-align: left;
}

.dm-math .katex-display > .katex {
  text-align: left;
}

.dm-why {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-left: var(--dm-col);
  padding: 2px 0 2px 6px;
  font-size: 0.9rem;
}

/* A solution with equations (S15 problems, S1 facts, S7 law rows): left
   member | = | right member, every "=" in one column (teacher-method B.3
   rule 6). The rows share the list's three columns (subgrid; a browser
   without subgrid falls back to the same columns per row). The left column
   takes at most 45% of the width and scrolls past that. The highlight is
   drawn by each row's "=" cell instead of the list's background stripe. */
.dm-lines.dm-eq {
  display: grid;
  grid-template-columns: fit-content(45%) var(--dm-col) minmax(0, 1fr);
}

.dm-lines.dm-eq::before {
  content: none;
}

.dm-eq > .dm-row,
.dm-eq > .dm-why {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: fit-content(45%) var(--dm-col) minmax(0, 1fr);
  grid-template-columns: subgrid;
}

/* fractions on both sides of consecutive equations need a little air; it goes
   in the members' cells, so the "=" cells still meet in one unbroken stripe */
.dm-eq > .dm-row > .dm-left,
.dm-eq > .dm-row > .dm-math {
  padding-top: 3px;
  padding-bottom: 3px;
}

.dm-eq > .dm-why {
  margin-left: 0;
  padding: 0;
  gap: 0;
  align-items: stretch;
}

.dm-eq .dm-rel {
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--hl-col);
}

.dm-eq > :first-child > .dm-rel,
.dm-eq > .dm-head + * > .dm-rel {
  border-radius: 8px 8px 0 0;
}

/* the definition or statement line of a problem, above the columns */
.dm-eq > .dm-head {
  grid-column: 1 / -1;
  display: block;
}

.dm-eq > :last-child > .dm-rel {
  border-radius: 0 0 8px 8px;
}

.dm-left {
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-right: 4px;
}

.dm-left .katex-display {
  margin: 2px 0;
  text-align: right;
}

.dm-left .katex-display > .katex {
  text-align: right;
  /* KaTeX's roots and fractions stick out 2px to the right of the formula's
     box (.vlist-t2's -2px margin). This column is exactly as wide as its
     formulas, so without room for those 2px every left member with a root or
     a fraction would show a small horizontal scrollbar. */
  margin-right: 2px;
}

.dm-why-body {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 2px 0 2px 6px;
}

.dm-arrow {
  flex: none;
  color: var(--blue);
  font-weight: 800;
}

.dm-label {
  padding: 2px 9px;
  border: 1.5px solid var(--blue-tint-2);
  border-radius: 8px;
  background: var(--sheet);
  color: var(--ink-2);
}

.dm-note,
.dm-source {
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--ink-2);
}

.dm-source {
  color: var(--ink-3);
}

/* ------------------------------------------------------------ self-check and next */

.selfcheck {
  margin-top: 16px;
  padding: 14px 16px;
  border: 2px dashed var(--line);
  border-radius: var(--r-l);
  background: var(--sheet);
}

.sc-question {
  font-weight: 750;
}

.sc-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.sc-done {
  color: var(--ink-2);
}

.pill {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 10px;
  border-radius: 99px;
  background: var(--green);
  color: var(--sheet);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.pill-pop {
  animation: pop 320ms cubic-bezier(0.2, 1.4, 0.5, 1);
}

.q-next {
  margin-top: 18px;
}

.q-next .btn {
  width: 100%;
  min-height: 58px;
  font-size: 1.15rem;
}

/* ------------------------------------------------------------ summary */

.screen-summary {
  text-align: center;
}

.sum-title {
  margin: 26px 0 8px;
  font-size: 2.15rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

/* one orchestrated moment: the highlighter swipes under the title */
.hl-swipe {
  padding: 0 4px;
  background-image: linear-gradient(var(--hl-col), var(--hl-col));
  background-repeat: no-repeat;
  background-position: 0 88%;
  background-size: 0% 46%;
  animation: swipe 650ms ease-out 200ms forwards;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.sum-points {
  margin: 14px 0 6px;
  color: var(--blue);
}

.sum-plus,
.sum-points-value {
  font-size: 4.2rem;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.sum-points-label {
  display: block;
  margin-top: 2px;
  font-size: 1rem;
  font-weight: 750;
  color: var(--ink-2);
}

.sum-bonus {
  margin-top: 4px;
  font-size: 0.9rem;
  color: var(--ink-3);
}

.sum-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.stat {
  padding: 12px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  color: var(--ink-2);
  font-size: 0.92rem;
}

.stat-value {
  display: block;
  font-size: 1.45rem;
  font-weight: 850;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.sum-level {
  display: inline-block;
  margin-top: 16px;
  padding: 6px 14px;
  border-radius: 99px;
  background: var(--hl);
  color: var(--hl-text);
  font-weight: 850;
}

.sum-note {
  margin: 16px auto 0;
  max-width: 440px;
  color: var(--ink-2);
}

.sum-note-warn {
  padding: 10px 14px;
  border-radius: var(--r-m);
  background: var(--amber-tint);
  color: var(--amber);
  font-weight: 600;
}

.sum-mastery {
  margin-top: 24px;
  text-align: left;
}

.sm-list {
  list-style: none;
  padding: 0;
  margin-top: 8px;
}

.sm-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--grid);
}

.sm-values {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sm-before {
  color: var(--ink-3);
}

.sm-after {
  font-weight: 800;
}

.sm-sign {
  display: inline-block;
  min-width: 1.4em;
  margin-left: 6px;
  text-align: center;
  font-size: 0.85rem;
}

.sm-up .sm-after,
.sm-up .sm-sign {
  color: var(--green);
}

.sm-down .sm-after,
.sm-down .sm-sign {
  color: var(--red);
}

.sm-new .sm-sign {
  color: var(--blue);
}

.sum-actions {
  margin-top: 28px;
}

.sum-actions .btn {
  width: 100%;
  min-height: 58px;
}

/* ------------------------------------------------------------ parent view */

.screen-parent {
  max-width: 880px;
  font-size: 16px;
}

.p-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 16px;
}

.p-name {
  font-size: 1.9rem;
  font-weight: 850;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.p-muted {
  font-size: 0.9rem;
  color: var(--ink-3);
}

.p-card .p-muted {
  margin-top: 10px;
}

.p-glance {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.p-tile {
  padding: 12px 14px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
}

.p-tile-label {
  font-size: 0.85rem;
  color: var(--ink-2);
}

.p-tile-value {
  margin-top: 2px;
  font-size: 1.45rem;
  font-weight: 850;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.p-tile-sub {
  font-size: 0.82rem;
  color: var(--ink-3);
}

.p-card {
  margin-top: 16px;
  padding: 16px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
}

.p-h2 {
  font-size: 1.1rem;
  font-weight: 850;
  margin-bottom: 10px;
}

.p-focus-skills {
  font-weight: 700;
}

.p-note {
  margin-top: 6px;
}

.p-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.p-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.p-table th,
.p-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--grid);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.p-table thead th {
  font-size: 0.82rem;
  font-weight: 750;
  color: var(--ink-2);
  border-bottom: 1px solid var(--line);
}

.p-table tbody th {
  font-weight: 650;
}

.p-mastery tbody th {
  white-space: normal;
  min-width: 180px;
}

.p-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.p-table tr.is-empty td,
.p-table tr.is-empty th {
  color: var(--ink-3);
}

.p-flag {
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--amber-tint);
  color: var(--amber);
  font-size: 0.78rem;
  font-weight: 800;
}

.p-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 0 8px;
  border-radius: 99px;
  background: var(--green-tint);
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 800;
  vertical-align: 1px;
}

.p-mbar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  width: 96px;
  height: 22px;
  border-radius: 6px;
  background: var(--grid);
  overflow: hidden;
}

.p-mbar-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  background: var(--blue-tint-2);
}

.p-mbar-text {
  position: relative;
  padding: 0 6px;
  font-weight: 750;
}

.trend {
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.trend-up {
  color: var(--green);
}

.trend-down {
  color: var(--red);
}

.trend-flat {
  color: var(--ink-2);
}

.trend-none {
  color: var(--ink-3);
}

.p-tags {
  padding-left: 1.3em;
}

.p-tags li {
  padding: 6px 0;
}

.p-tag-name {
  font-weight: 650;
}

.p-tag-count {
  margin-left: 8px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.p-mistakes {
  list-style: none;
  padding: 0;
}

.p-mistake {
  padding: 14px 0;
  border-top: 1px solid var(--grid);
}

.p-mistake:first-child {
  border-top: none;
  padding-top: 4px;
}

.p-m-meta {
  font-size: 0.85rem;
  color: var(--ink-3);
}

.p-m-prompt {
  margin: 6px 0 8px;
  overflow-x: auto;
  overflow-y: hidden; /* see .choice-label */
  padding: 3px 0;
}

.p-m-answers {
  display: grid;
  gap: 4px;
}

.p-m-answers > div {
  display: grid;
  grid-template-columns: 8.5em minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
}

.p-m-answers dt {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink-2);
}

.p-m-answers dd {
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden; /* see .choice-label */
  padding: 3px 0;
}

.p-text {
  font-family: var(--mono);
  font-size: 0.95rem;
}

.p-then {
  color: var(--ink-3);
}

.p-dk {
  font-style: italic;
  color: var(--ink-2);
}

/* ------------------------------------------------------------ wider screens */

@media (min-width: 640px) {
  .screen {
    padding-top: calc(28px + env(safe-area-inset-top));
  }

  .q-top {
    margin-top: calc(-28px - env(safe-area-inset-top));
  }

  .keys {
    grid-template-columns: repeat(auto-fit, minmax(48px, 64px));
  }
}

/* very narrow phones (320 px): keep everything on screen */
@media (max-width: 360px) {
  body {
    font-size: 16px;
  }

  .hello {
    font-size: 1.8rem;
  }

  .scoreboard {
    grid-template-columns: 1fr;
  }

  .points {
    text-align: left;
  }

  .q-actions {
    grid-template-columns: 1fr;
  }

  .sum-plus,
  .sum-points-value {
    font-size: 3.4rem;
  }
}

/* ------------------------------------------------------------ motion */

@keyframes pop {
  from {
    transform: scale(0.95);
    opacity: 0.4;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes swipe {
  to {
    background-size: 100% 46%;
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  50% { transform: translateX(7px); }
  75% { transform: translateX(-4px); }
}

@keyframes fade-in {
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
