/* The Mistake Lab — shared styles. See STYLE.md for the rationale behind every token. */

:root {
  --paper: #f8f4e8;
  --sheet: #fffdf6;
  --inset: #f1ecdd;
  --ink: #1c2230;
  --ink-soft: #545b69;
  --pen: #2449a0;
  --pen-ink: #ffffff;
  --red: #c8322a;
  --green: #1d7f46;
  --marker: #f4c430;
  --amber: #b9770e;
  --amber-fill: #f6c35b;
  --line: #ddd5c0;
  --grid: rgb(36 73 160 / 0.075);
  --margin: rgb(200 50 42 / 0.35);
  --shadow: 0 1px 0 rgb(0 0 0 / 0.04), 0 6px 20px -8px rgb(60 40 0 / 0.18);
  --ok-bg: #e6f4ea;
  --bad-bg: #fbe9e7;
  --hint-bg: #fff4cc;

  --font-display: "Bricolage Grotesque", "Trebuchet MS", sans-serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", sans-serif;
  --font-hand: "Kalam", "Comic Sans MS", cursive;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.6rem;
  --step-3: clamp(1.9rem, 6vw, 2.6rem);
  --radius: 14px;
  --gutter: clamp(16px, 4vw, 28px);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #16211c;
  --sheet: #1e2c26;
  --inset: #263830;
  --ink: #eef2ea;
  --ink-soft: #a9b6ad;
  --pen: #94b8ff;
  --pen-ink: #0f1a2e;
  --red: #ff8f85;
  --green: #7edc9e;
  --marker: #ffd166;
  --amber: #ffcf70;
  --amber-fill: #c98f22;
  --line: #33463c;
  --grid: rgb(255 255 255 / 0.04);
  --margin: rgb(255 143 133 / 0.25);
  --shadow: 0 6px 24px -10px rgb(0 0 0 / 0.6);
  --ok-bg: #1f3d2b;
  --bad-bg: #432421;
  --hint-bg: #3d3519;
  color-scheme: dark;
}

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

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

/* Author display rules (e.g. .choices { display: grid }) would otherwise override the hidden attribute. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--ink);
  font: 400 var(--step-0) / 1.55 var(--font-body);
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  line-height: 1.15;
  text-wrap: balance;
  margin: 0 0 0.5em;
}

h1 {
  font-size: var(--step-3);
  font-weight: 800;
  letter-spacing: -0.02em;
}

h2 {
  font-size: var(--step-2);
  font-weight: 800;
}

h3 {
  font-size: var(--step-1);
  font-weight: 700;
}

p {
  margin: 0 0 0.8em;
  text-wrap: pretty;
}

a {
  color: var(--pen);
}

:focus-visible {
  outline: 3px solid var(--marker);
  outline-offset: 2px;
  border-radius: 6px;
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.muted {
  color: var(--ink-soft);
}

.hand {
  font-family: var(--font-hand);
}

.hl {
  background: linear-gradient(transparent 55%, color-mix(in srgb, var(--marker) 55%, transparent) 55%);
  padding: 0 0.1em;
}

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

/* ---------- Header ---------- */

.lab-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px var(--gutter);
  max-width: 760px;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 800 1.1rem var(--font-display);
  color: var(--ink);
  text-decoration: none;
  margin-right: auto;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font: 700 1.2rem var(--font-hand);
  transform: rotate(-6deg);
}

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

/* ---------- Stepper ---------- */

.stepper {
  display: flex;
  gap: 4px;
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  counter-reset: step;
}

.stepper li {
  flex: 1;
  min-width: 0;
}

.stepper button {
  width: 100%;
  min-height: 48px;
  padding: 6px 2px 4px;
  border: 0;
  border-bottom: 4px solid var(--line);
  background: none;
  color: var(--ink-soft);
  font: 700 0.75rem var(--font-body);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stepper button .bi {
  font-size: 1.1rem;
}

.stepper button[aria-current="step"] {
  color: var(--pen);
  border-color: var(--pen);
}

.stepper button.done {
  color: var(--green);
  border-color: var(--green);
}

.stepper button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- Sheet (notebook page) ---------- */

.sheet {
  position: relative;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 18px 22px 30px;
  margin-bottom: 18px;
}

.sheet::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 18px;
  width: 2px;
  background: var(--margin);
}

.sheet > :last-child {
  margin-bottom: 0;
}

.step-label {
  display: inline-block;
  font: 700 0.8rem var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--red);
  margin-bottom: 4px;
}

section[data-step] {
  display: none;
}

section[data-step].active {
  display: block;
}

.reveal > * {
  animation: rise 0.5s both cubic-bezier(0.2, 0.7, 0.2, 1);
  animation-delay: calc(var(--i, 0) * 90ms);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

/* ---------- Speech + characters ---------- */

.speech {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 4px 0 16px;
}

.speech .character {
  flex: none;
  width: 76px;
  height: 76px;
}

.bubble {
  position: relative;
  flex: 1;
  background: var(--inset);
  border: 2px solid var(--ink);
  border-radius: 18px 18px 18px 4px;
  padding: 10px 14px;
  font: 400 1.15rem / 1.35 var(--font-hand);
  min-height: 3em;
}

.bubble strong {
  font-weight: 700;
}

.speech.claim .bubble .say-math {
  color: var(--red);
  font-weight: 700;
  white-space: nowrap;
}

.character .blink {
  animation: blink 4s infinite;
  transform-origin: center;
  transform-box: fill-box;
}

.character.talking .mouth {
  animation: talk 0.25s infinite alternate;
  transform-origin: center;
  transform-box: fill-box;
}

.character .bob {
  animation: bob 2.6s ease-in-out infinite;
}

@keyframes blink {
  0%,
  92%,
  100% {
    transform: scaleY(1);
  }
  95% {
    transform: scaleY(0.1);
  }
}

@keyframes talk {
  to {
    transform: scaleY(0.35);
  }
}

@keyframes bob {
  50% {
    transform: translateY(-3px);
  }
}

/* ---------- Fractions ---------- */

.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 1.05;
  font-weight: 700;
  margin: 0 0.15em;
}

.frac > b:first-child {
  border-bottom: 2px solid currentColor;
  padding: 0 0.15em;
}

.frac > b {
  font-weight: inherit;
}

.math {
  font-weight: 700;
  font-size: 1.15em;
  white-space: nowrap;
}

/* ---------- Choices & inputs ---------- */

.choices {
  display: grid;
  gap: 8px;
  margin: 10px 0 14px;
  border: 0;
  padding: 0;
}

.choices legend {
  font-weight: 700;
  margin-bottom: 8px;
  padding: 0;
}

.choices.row {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

/* Block (not flex) so inline fractions flow with the text; the radio is positioned in the left padding. */
.choices label {
  display: block;
  position: relative;
  min-height: 48px;
  padding: 10px 14px 10px 44px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--sheet);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.choices input {
  accent-color: var(--pen);
  width: 20px;
  height: 20px;
  margin: 0;
  position: absolute;
  left: 14px;
  top: 50%;
  translate: 0 -50%;
}

.choices label:has(input:checked) {
  border-color: var(--pen);
  background: color-mix(in srgb, var(--pen) 9%, var(--sheet));
}

.choices label:has(input:focus-visible) {
  outline: 3px solid var(--marker);
  outline-offset: 2px;
}

.choices label.right {
  border-color: var(--green);
}

.choices label.wrong {
  border-color: var(--red);
}

.confidence legend {
  font-size: 0.95rem;
}

input[type="number"],
input[type="text"],
textarea {
  font: 700 1.2rem var(--font-body);
  color: var(--ink);
  background: var(--sheet);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 48px;
  width: 6.5em;
}

textarea {
  width: 100%;
  font: 400 1.05rem / 1.4 var(--font-hand);
  min-height: 90px;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--pen);
  outline: none;
}

.frac-input {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  vertical-align: middle;
}

.frac-input input {
  width: 4.2em;
  text-align: center;
}

.frac-input hr {
  width: 100%;
  border: 0;
  border-top: 3px solid var(--ink);
  margin: 0;
}

.answer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--pen);
  height: 32px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--sheet);
  color: var(--ink);
  font: 700 1rem var(--font-body);
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 3px 0 var(--ink);
}

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--ink);
}

.btn.primary {
  background: var(--pen);
  border-color: var(--pen);
  color: var(--pen-ink);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--pen) 55%, #000);
}

.btn.ghost {
  border-color: var(--line);
  box-shadow: none;
}

.btn.small {
  min-height: 40px;
  padding: 6px 12px;
  font-size: 0.9rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.next-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

/* ---------- Feedback ---------- */

.feedback {
  margin: 12px 0 0;
  padding: 10px 14px 10px 44px;
  border-radius: 12px;
  position: relative;
  animation: rise 0.3s both;
}

.feedback:empty {
  display: none;
}

.feedback::before {
  position: absolute;
  left: 12px;
  top: 6px;
  font: 700 1.5rem var(--font-hand);
}

.feedback.ok {
  background: var(--ok-bg);
}

.feedback.ok::before {
  content: "✓";
  color: var(--green);
}

.feedback.bad {
  background: var(--bad-bg);
}

.feedback.bad::before {
  content: "✗";
  color: var(--red);
}

.feedback.hint {
  background: var(--hint-bg);
}

.feedback.hint::before {
  content: "?";
  color: var(--amber);
}

.feedback .pen {
  font-family: var(--font-hand);
  font-size: 1.1em;
}

/* ---------- Claims (true/false) ---------- */

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

.claims li {
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--sheet);
}

.claims .claim-text {
  margin-bottom: 8px;
}

.claims .tf {
  display: flex;
  gap: 8px;
}

.claims .tf label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  border: 2px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}

.claims .tf input {
  accent-color: var(--pen);
}

.claims .tf label:has(input:checked) {
  border-color: var(--pen);
}

.claims li.right {
  border-color: var(--green);
}

.claims li.wrong {
  border-color: var(--red);
}

.claims .why {
  margin-top: 8px;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

/* ---------- Quiz ---------- */

.quiz-item {
  border-top: 2px dashed var(--line);
  padding: 16px 0 6px;
}

.quiz-item:first-of-type {
  border-top: 0;
  padding-top: 4px;
}

.quiz-item .q-num {
  font: 700 1.1rem var(--font-hand);
  color: var(--red);
  margin-right: 4px;
}

.quiz-item .badge {
  float: right;
  font: 700 1.3rem var(--font-hand);
}

.score-big {
  font: 800 2.6rem var(--font-display);
  line-height: 1;
}

/* ---------- Missions ---------- */

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

.missions li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--inset);
}

.missions li .bi {
  font-size: 1.2rem;
  color: var(--ink-soft);
  flex: none;
}

.missions li.done .bi {
  color: var(--green);
}

.missions li.done .bi::before {
  content: "\f26a";
}

.missions li .found {
  display: block;
  font: 700 1rem var(--font-hand);
  color: var(--green);
}

/* ---------- Report card ---------- */

.report {
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--inset);
}

.report dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 10px 0;
}

.report dt {
  color: var(--ink-soft);
}

.report dd {
  margin: 0;
  font-weight: 700;
}

.report .stamp {
  display: inline-block;
  border: 3px solid var(--green);
  color: var(--green);
  border-radius: 10px;
  padding: 2px 12px;
  font: 700 1.3rem var(--font-hand);
  transform: rotate(-4deg);
}

/* ---------- Utility layout ---------- */

.split {
  display: grid;
  gap: 14px;
}

@media (min-width: 640px) {
  .split {
    grid-template-columns: 1fr 1fr;
  }
}

.callout {
  border-left: 4px solid var(--marker);
  background: var(--hint-bg);
  padding: 10px 14px;
  border-radius: 0 12px 12px 0;
  margin: 12px 0;
}

.site-footer {
  padding: 24px var(--gutter) 40px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.pop {
  animation: pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1);
}

@keyframes pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
}

.shake {
  animation: shake 0.4s;
}

@keyframes shake {
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}

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