:root {
  --paper: #fbf7ee;
  --paper-2: #f3ecdc;
  --ink: #1d2433;
  --ink-soft: #5a6275;
  --line: #e2d8c3;
  --grid: rgba(70, 110, 170, 0.09);
  --red: #d2402f;
  --red-soft: #fbe3de;
  --green: #1f8a5b;
  --green-soft: #dcf2e6;
  --navy: #22315a;
  --gold: #e8b33c;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--paper);
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 760px;
  height: 100%;
  min-height: 560px;
  max-height: 100vh;
  margin: 0 auto;
  padding: 18px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--navy); color: var(--paper);
  font-family: "Fraunces", serif; font-weight: 800; font-size: 18px;
  font-style: italic;
  transform: rotate(-4deg);
}
.brand-mark sup { font-size: 10px; color: var(--gold); margin-left: 1px; }
.brand-text { font-family: "Fraunces", serif; font-weight: 800; font-size: 18px; letter-spacing: -0.01em; }
.meta { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.step-label { color: var(--ink-soft); font-weight: 600; }
.score-chip {
  background: var(--ink); color: var(--paper);
  padding: 4px 10px; border-radius: 999px; font-weight: 700;
}
.score-chip:empty { display: none; }

/* Progress */
.progress { height: 6px; background: var(--paper-2); border-radius: 999px; overflow: hidden; }
.progress-bar {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--navy), var(--red));
  border-radius: inherit;
  transition: width 0.45s cubic-bezier(.2,.8,.2,1);
}
.dots { list-style: none; display: flex; gap: 6px; margin: 0; padding: 0; justify-content: center; }
.dots li {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  background: #fff; border: 1.5px solid var(--line); color: var(--ink-soft);
  cursor: pointer; transition: all 0.2s;
}
.dots li.current { border-color: var(--ink); color: var(--ink); transform: scale(1.12); }
.dots li.ok { background: var(--green); border-color: var(--green); color: #fff; }
.dots li.miss { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.dots li.locked { cursor: not-allowed; opacity: 0.55; }

/* Card */
.card {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: 0 1px 0 var(--line), 0 18px 40px -24px rgba(29, 36, 51, 0.35);
  animation: rise 0.35s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.eyebrow {
  display: inline-block;
  font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--red); margin-bottom: 6px;
}
.card h1 {
  font-family: "Fraunces", serif; font-weight: 800;
  font-size: clamp(22px, 3.6vw, 28px); line-height: 1.15; letter-spacing: -0.015em;
  margin: 0 0 14px;
}
.prose { font-size: 15px; line-height: 1.65; }
.prose p { margin: 0 0 10px; }
.prose strong { font-weight: 700; }

.katex { font-size: 1.08em; }
.katex-display { margin: 0.6em 0; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* Problem box */
.problem {
  background: var(--paper);
  border: 1.5px dashed #cbbd9f;
  border-radius: 14px;
  padding: 12px 16px;
  margin: 4px 0 16px;
}
.problem.compact { font-size: 14px; }
.problem.compact .katex-display { margin: 0.3em 0; }
.problem-toggle {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 700; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.08em;
}

/* Student scratch */
.scratch {
  position: relative;
  background:
    repeating-linear-gradient(transparent 0 29px, rgba(70,110,170,0.18) 29px 30px),
    #fffdf6;
  border-radius: 6px 14px 14px 6px;
  border-left: 3px solid rgba(210, 64, 47, 0.45);
  padding: 14px 18px 14px 22px;
  margin: 0 0 18px;
  box-shadow: 0 6px 18px -12px rgba(29, 36, 51, 0.4);
  transform: rotate(-0.4deg);
}
.scratch-label {
  font-family: "Caveat", cursive; font-size: 20px; font-weight: 700; color: var(--navy);
  margin-bottom: 2px;
}
.scratch .prose { font-size: 16px; color: #23326b; }
.scratch .stamp {
  position: absolute; right: 14px; top: 10px;
  font-family: "Caveat", cursive; font-weight: 700; font-size: 26px;
  color: var(--red); transform: rotate(8deg);
  border: 2.5px solid var(--red); border-radius: 10px; padding: 0 8px; line-height: 1.2;
  opacity: 0.85;
}

.question { font-weight: 700; font-size: 15.5px; line-height: 1.55; margin: 0 0 12px; }

/* Options */
.options { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.option {
  width: 100%;
  display: flex; gap: 12px; align-items: flex-start;
  text-align: left;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font: inherit; font-size: 14.5px; line-height: 1.55; color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.option:hover:not(:disabled) { border-color: var(--ink); transform: translateX(2px); }
.option:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.option .key {
  flex: none; width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--paper-2); font-weight: 800; font-size: 13px;
}
.option:disabled { cursor: default; }
.option.correct { border-color: var(--green); background: var(--green-soft); }
.option.correct .key { background: var(--green); color: #fff; }
.option.wrong { border-color: var(--red); background: var(--red-soft); }
.option.wrong .key { background: var(--red); color: #fff; }
.option.dim { opacity: 0.5; }

/* Feedback */
.feedback {
  margin-top: 14px;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 14.5px; line-height: 1.6;
  animation: rise 0.3s ease-out;
}
.feedback.ok { background: var(--green-soft); border: 1.5px solid rgba(31,138,91,0.35); }
.feedback.miss { background: #fff6e0; border: 1.5px solid rgba(232,179,60,0.6); }
.feedback-title { font-weight: 800; margin-bottom: 4px; }
.feedback .retry {
  margin-top: 8px; background: none; border: 0; padding: 0;
  font: inherit; font-weight: 700; color: var(--navy); text-decoration: underline; cursor: pointer;
}

/* Outro */
.result {
  display: flex; align-items: center; gap: 16px;
  background: var(--navy); color: var(--paper);
  border-radius: 16px; padding: 16px 18px; margin-bottom: 16px;
}
.result-score { font-family: "Fraunces", serif; font-weight: 800; font-size: 40px; line-height: 1; }
.result-score small { font-size: 18px; opacity: 0.7; }
.result-text { font-size: 14px; line-height: 1.5; }
.result-text strong { color: var(--gold); }

.solution { margin-top: 14px; }
.solution summary {
  cursor: pointer; font-weight: 700; color: var(--navy);
  padding: 10px 14px; border-radius: 12px; background: var(--paper);
  border: 1.5px solid var(--line);
  list-style: none;
}
.solution summary::-webkit-details-marker { display: none; }
.solution summary::before { content: "▸ "; }
.solution[open] summary::before { content: "▾ "; }
.solution ol { margin: 12px 0 0; padding-left: 22px; font-size: 14.5px; line-height: 1.7; }
.solution li { margin-bottom: 6px; }
.solution li::marker { font-weight: 800; color: var(--red); }

/* Nav */
.nav { display: flex; justify-content: space-between; gap: 10px; }
.btn {
  font: inherit; font-weight: 700; font-size: 14.5px;
  padding: 11px 18px; border-radius: 12px; cursor: pointer;
  border: 1.5px solid transparent;
  transition: transform 0.15s, background 0.15s, opacity 0.15s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.primary { background: var(--red); color: #fff; box-shadow: 0 4px 0 #a02e21; }
.btn.primary:hover:not(:disabled) { background: #bf3627; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { background: #fff; }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn.invisible { visibility: hidden; }

@media (max-width: 520px) {
  .shell { padding: 12px 10px; }
  .card { padding: 18px 16px; }
  .brand-text { display: none; }
  .dots li { width: 22px; height: 22px; font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
