:root {
  --paper: #f8f2e7;
  --paper-deep: #f1e7d6;
  --card: #fffaf0;
  --line: #e6d9bf;
  --ink: #3c3428;
  --muted: #8a7d66;
  --accent: #c96f4a;
  --accent-deep: #a8623f;
  --gold: #e8b04b;
  --sage: #7a8b6f;
  --lavender: #8f7fb8;
  --ok: #5d9267;
  --bad: #c05a4b;
  --radius: 16px;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--serif);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 12% -6%, rgba(232, 176, 75, 0.16) 0%, rgba(232, 176, 75, 0) 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(201, 111, 74, 0.12) 0%, rgba(201, 111, 74, 0) 55%),
    var(--paper);
  min-height: 100vh;
  line-height: 1.6;
}

.page { max-width: 720px; margin: 0 auto; padding: 0 16px 24px; }

/* Nav */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 4px 6px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.logo { display: inline-flex; }
.brand-name {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent-deep);
  background: rgba(201, 111, 74, 0.12);
  border: 1px solid rgba(201, 111, 74, 0.28);
  padding: 6px 12px;
  border-radius: 999px;
}

/* Hero */
.hero { text-align: center; padding: 40px 8px 26px; }

.kicker {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-deep);
  margin: 0 0 14px;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.2rem, 6vw, 3.2rem);
  line-height: 1.12;
  font-weight: 700;
}

.hero h1 em {
  font-style: italic;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  color: var(--muted);
  font-size: 1.1rem;
  margin: 14px auto 0;
  max-width: 560px;
}

/* Steps */
.steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 26px;
}

.step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px 8px 8px;
  box-shadow: 0 2px 6px rgba(60, 52, 40, 0.06);
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fffaf0;
  font-size: 0.75rem;
  font-weight: 700;
}

.step-arrow { color: var(--gold); font-size: 1.1rem; }

/* Main + cards */
main { margin-top: 4px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: 0 14px 34px rgba(60, 52, 40, 0.1), 0 2px 6px rgba(60, 52, 40, 0.05);
}

.card.quiz { background: #fcf6ea; }

h2 {
  margin: 0 0 10px;
  font-size: 1.35rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

label { display: block; font-weight: 700; margin-bottom: 8px; }

textarea {
  width: 100%;
  resize: vertical;
  font-family: var(--serif);
  font-size: 1rem;
  background: #fffdf7;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  padding: 14px;
  box-shadow: inset 0 1px 3px rgba(60, 52, 40, 0.08);
  transition: border-color 0.2s, box-shadow 0.2s;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 111, 74, 0.18);
}

/* Example chips */
.examples {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.examples-label {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--muted);
}

.chip {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-deep);
  background: linear-gradient(180deg, #fffdf7, #faf0dc);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.chip:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: 0 4px 10px rgba(201, 111, 74, 0.16);
}

/* Actions + buttons */
.actions { display: flex; align-items: center; gap: 16px; margin-top: 16px; flex-wrap: wrap; }

.btn {
  font-family: var(--sans);
  border: none;
  border-radius: 12px;
  padding: 13px 22px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.btn:focus-visible { outline: 3px solid rgba(201, 111, 74, 0.4); outline-offset: 2px; }

.btn.primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-deep));
  color: #fffaf0;
  box-shadow: 0 8px 18px rgba(201, 111, 74, 0.32);
}

.btn.primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(201, 111, 74, 0.4); }

.btn.primary:disabled { opacity: 0.55; cursor: wait; }

.status { margin: 0; color: var(--muted); font-family: var(--sans); font-size: 0.88rem; }

.status.error { color: var(--bad); font-weight: 600; }

.hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 6px; }

/* Spinner */
.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  margin-right: 8px;
  border: 2px solid rgba(255, 250, 240, 0.4);
  border-top-color: #fffaf0;
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Explanation + typing caret */
#explanationText { white-space: pre-wrap; }

.caret {
  display: inline-block;
  width: 7px;
  background: var(--accent);
  border-radius: 2px;
  animation: blink 0.8s step-end infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.source-note {
  color: #8a6420;
  font-size: 0.86rem;
  background: rgba(232, 176, 75, 0.14);
  border-left: 3px solid var(--gold);
  padding: 12px 14px;
  border-radius: 0 10px 10px 0;
  margin: 18px 0 0;
}

/* Flip cards */
.flashcard {
  perspective: 1000px;
  margin: 16px 0;
  cursor: pointer;
  animation: cardIn 0.45s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.flashcard .inner {
  position: relative;
  width: 100%;
  min-height: 190px;
  display: grid;
  grid-template-columns: 1fr;
  transition: transform 0.55s cubic-bezier(0.4, 0.2, 0.2, 1);
  transform-style: preserve-3d;
}

.flashcard.flipped .inner { transform: rotateY(180deg); }

.flashcard .face {
  grid-area: 1 / 1;
  position: relative;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(60, 52, 40, 0.08);
}

.flashcard .front { background: #fffdf7; }

.flashcard .back {
  background: #f3eee1;
  border-color: var(--sage);
  transform: rotateY(180deg);
}

.flashcard .back .correct { color: var(--ok); font-weight: 700; }

.flashcard .q { font-weight: 700; margin-bottom: 12px; font-size: 1.05rem; }

.options { display: flex; flex-direction: column; gap: 8px; width: 100%; }

.option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: #f9f3e4;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.option .key {
  flex: 0 0 22px;
  text-align: center;
  font-family: var(--sans);
  font-weight: 700;
  color: var(--accent-deep);
}

.score { font-family: var(--sans); font-weight: 700; margin-top: 8px; }

.done-card {
  opacity: 0.55;
  filter: saturate(0.7);
}

/* Confetti */
.confetti-piece {
  position: fixed;
  top: -12px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  z-index: 60;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  90% { opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}

footer {
  text-align: center;
  color: var(--muted);
  padding: 20px 16px 36px;
  font-family: var(--sans);
  font-size: 0.82rem;
}

@media (max-width: 520px) {
  .nav { justify-content: center; text-align: center; }
  .hero h1 { font-size: 2rem; }
  .step-arrow { display: none; }
  .steps { gap: 6px; }
}