:root {
  --paper: #EEF0FB;      /* blue laid paper */
  --card: #FFFFFF;
  --ink: #1D2350;        /* iron-gall ink */
  --ink-2: #4A5285;
  --wax: #D7263D;        /* sealing wax */
  --wax-bg: #FDE3E6;
  --gold: #F2B134;
  --mint: #16865F;
  --mint-bg: #DCF5EC;
  --lilac: #B9B6F2;
  --display: "IM Fell English", Georgia, "Times New Roman", serif;
  --ui: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font: 400 1.0625rem/1.5 var(--ui);
  background-color: var(--paper);
  /* laid lines + chain lines, like handmade paper */
  background-image:
    repeating-linear-gradient(0deg, rgba(29, 35, 80, .035) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(90deg, rgba(29, 35, 80, .05) 0 1px, transparent 1px 92px);
}
[hidden] { display: none !important; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; border-radius: 6px; }
.muted { color: var(--ink-2); }
.small { font-size: .9rem; }

#app {
  max-width: 36rem;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 3rem; padding: .75rem 1.1rem;
  font: 650 1rem/1.2 var(--ui); color: var(--ink); text-decoration: none; text-align: center;
  background: var(--card); border: 2px solid var(--ink); border-radius: 12px;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer; transition: transform .08s ease, box-shadow .08s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn.primary { background: var(--ink); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; }
.btn.small { min-height: 2.5rem; padding: .45rem .8rem; font-size: .92rem; box-shadow: 2px 2px 0 var(--ink); }
.btn.wide { width: 100%; }
.icon-btn {
  width: 2.5rem; height: 2.5rem; flex: none; border-radius: 50%;
  border: 2px solid var(--ink); background: var(--card); color: var(--ink);
  font: 700 1rem/1 var(--ui); cursor: pointer;
}

/* ---------- wax seal ---------- */
.seal {
  position: relative; flex: none;
  width: 8.5rem; height: 8.5rem; padding: 0; border: 0; background: none;
  color: #fff; cursor: pointer;
  transform: rotate(-8deg);
  filter: drop-shadow(3px 4px 0 rgba(29, 35, 80, .85));
  transition: transform .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.seal svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.seal-blob { fill: url(#wax); }
.seal-ring { fill: none; stroke: rgba(80, 0, 16, .35); stroke-width: 2.4; }
.seal-ring2 { fill: none; stroke: rgba(255, 255, 255, .22); stroke-width: 1; }
.seal-text {
  position: relative; display: grid; place-items: center; height: 100%;
  font: 400 1.35rem/1.02 var(--display); text-align: center;
  text-shadow: 0 1px 0 rgba(90, 0, 20, .45);
}
button.seal:hover { transform: rotate(-3deg) scale(1.04); }
button.seal:active { transform: rotate(-8deg) scale(.95); }
.seal.big { width: 11rem; height: 11rem; cursor: default; }
.seal.big .pct { font-size: 3.1rem; line-height: 1; }
.seal.stamp { animation: stamp .55s cubic-bezier(.2, .9, .3, 1.3) both; }
@keyframes stamp {
  0% { transform: scale(1.9) rotate(-24deg); opacity: 0; }
  60% { transform: scale(.94) rotate(-6deg); opacity: 1; }
  100% { transform: scale(1) rotate(-8deg); }
}

/* ---------- home ---------- */
.hero { margin-top: .5rem; }
.hero-year {
  margin: 0;
  font: 400 clamp(6.5rem, 34vw, 10.5rem)/.82 var(--display);
  letter-spacing: -.02em;
  color: var(--ink);
  text-shadow: .05em .035em 0 rgba(215, 38, 61, .88); /* two-colour press, slightly off register */
}
.hero-title { margin: .9rem 0 .5rem; font: 400 2.15rem/1.05 var(--display); }
.hero-sub { margin: 0; max-width: 30rem; color: var(--ink-2); }
.start-row { display: flex; align-items: center; gap: 1.1rem; margin: 1.6rem 0 1.4rem; }
.start-note { margin: 0; font-weight: 600; line-height: 1.35; }
.home-links { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.best { margin: 1.4rem 0 0; color: var(--ink-2); }
.best strong { color: var(--ink); }

/* ---------- test ---------- */
.quizbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: .75rem;
  margin: -8px -16px 0; padding: 8px 16px;
  background: var(--paper);
}
.progress { flex: 1; height: 12px; border: 2px solid var(--ink); border-radius: 999px; background: var(--card); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--gold); border-right: 2px solid var(--ink); transition: width .3s ease; }
.timer { min-width: 3.4rem; text-align: right; font: 700 1rem/1 var(--ui); font-variant-numeric: tabular-nums; }
.timer.late { color: var(--wax); }
.quizmeta { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin: 1rem 0 .15rem; }
.round { font: italic 400 1.15rem/1.2 var(--display); }
.qcount { color: var(--ink-2); font-size: .92rem; white-space: nowrap; }
.streak { min-height: 1.5rem; font-weight: 700; color: var(--wax); font-size: .95rem; }
.card {
  background: var(--card); border: 2px solid var(--ink); border-radius: 18px;
  box-shadow: 4px 4px 0 var(--ink);
}
.qcard { padding: 1.2rem 1.1rem 1.1rem; margin-top: .35rem; }
.q-ask { margin: 0 0 .4rem; color: var(--ink-2); font-size: .95rem; font-weight: 600; }
.q-prompt { margin: 0 0 .9rem; font-size: 1.2rem; line-height: 1.4; font-weight: 600; }
.q-term { margin: .1rem 0 1rem; font: 400 2.3rem/1.05 var(--display); }
.q-tf { margin: 0 0 1rem; font-size: 1.15rem; line-height: 1.45; }
.q-tf b { font: 400 1.35rem/1.1 var(--display); }
.opts { display: grid; gap: .6rem; }
.opt {
  width: 100%; padding: .85rem 1rem; text-align: left;
  font: 550 1.02rem/1.35 var(--ui); color: var(--ink);
  background: var(--card); border: 2px solid var(--ink); border-radius: 12px;
  box-shadow: 2px 2px 0 var(--ink);
  cursor: pointer; transition: transform .08s ease, box-shadow .08s ease, background .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.opts.long .opt { font-size: .96rem; font-weight: 500; }
.opt:not([disabled]):active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.opt[disabled] { cursor: default; }
.opt.correct { background: var(--mint-bg); border-color: var(--mint); box-shadow: 2px 2px 0 var(--mint); }
.opt.wrong { background: var(--wax-bg); border-color: var(--wax); box-shadow: 2px 2px 0 var(--wax); animation: shake .32s ease; }
.opt.dim { opacity: .5; }
.tf-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.tf-row .opt { text-align: center; font-size: 1.1rem; font-weight: 700; }
@keyframes shake {
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

/* match-up */
.match-terms { display: flex; flex-wrap: wrap; gap: .5rem; margin: .4rem 0 1rem; }
.chip, .mterm {
  padding: .5rem .9rem; min-height: 2.6rem;
  font: 650 .98rem/1.2 var(--ui); color: var(--ink);
  background: var(--card); border: 2px solid var(--ink); border-radius: 999px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.match-defs { display: grid; gap: .55rem; }
.mdef {
  width: 100%; padding: .75rem .9rem; text-align: left;
  font: 500 .98rem/1.35 var(--ui); color: var(--ink);
  background: var(--card); border: 2px dashed var(--ink-2); border-radius: 12px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.mterm.sel, .mdef.sel { background: var(--gold); border-color: var(--ink); border-style: solid; }
.mterm.done, .mdef.done { background: var(--mint-bg); border: 2px solid var(--mint); color: var(--mint); cursor: default; }
.mdef.done .pair { display: block; margin-top: .2rem; font-weight: 700; }
.mterm.bad, .mdef.bad { animation: shake .32s ease; border-color: var(--wax); }
.pair { display: none; }

/* typed */
.typed { display: flex; gap: .6rem; }
.typed input {
  flex: 1; min-width: 0; min-height: 3rem; padding: .6rem .8rem;
  font: 600 1.1rem/1.2 var(--ui); color: var(--ink);
  background: var(--card); border: 2px solid var(--ink); border-radius: 12px;
}
.typed input:focus { outline: 3px solid var(--gold); outline-offset: 1px; }
.linkbtn { margin-top: .8rem; padding: .3rem 0; border: 0; background: none; color: var(--ink-2); font: 600 .95rem var(--ui); text-decoration: underline; cursor: pointer; }

/* order */
.slots { list-style: none; margin: .4rem 0 1rem; padding: 0; display: grid; gap: .5rem; counter-reset: slot; }
.slot {
  counter-increment: slot;
  display: flex; align-items: center; gap: .7rem;
  min-height: 3rem; padding: .45rem .7rem;
  border: 2px dashed var(--ink-2); border-radius: 12px; background: rgba(255, 255, 255, .6);
  font-weight: 650;
}
.slot::before { content: counter(slot); font: 400 1.5rem/1 var(--display); color: var(--ink-2); width: 1.2rem; text-align: center; }
.slot.filled { border-style: solid; border-color: var(--ink); background: var(--card); cursor: pointer; }
.slot.right { border-color: var(--mint); background: var(--mint-bg); }
.slot.off { border-color: var(--wax); background: var(--wax-bg); }
.slot .yr { margin-left: auto; color: var(--ink-2); font-weight: 600; }
.pool { display: flex; flex-wrap: wrap; gap: .5rem; }

/* feedback */
.feedback { margin-top: 1rem; padding: .95rem 1.05rem; border: 2px solid; border-radius: 14px; }
.feedback.good { background: var(--mint-bg); border-color: var(--mint); }
.feedback.bad { background: var(--wax-bg); border-color: var(--wax); }
.fb-title { margin: 0; font-weight: 800; font-size: 1.08rem; }
.fb-line { margin: .35rem 0 0; }
.fb-tip { margin: .45rem 0 0; color: var(--ink-2); font-size: .95rem; }
.nextbar {
  position: sticky; bottom: 0; z-index: 4;
  margin: 0 -16px; padding: .9rem 16px calc(.9rem + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(238, 240, 251, 0), var(--paper) 35%);
}

/* ---------- results ---------- */
.res-top { display: flex; flex-direction: column; align-items: flex-start; gap: 1.2rem; margin: 1rem 0 1.4rem; }
@media (min-width: 560px) { .res-top { flex-direction: row; align-items: center; } }
.res-msg { margin: 0 0 .35rem; font: 400 1.75rem/1.1 var(--display); }
.res-words p { margin: 0; }
.misses { margin: 1.4rem 0; padding: 1rem 1.1rem; }
#resMisses:empty { margin-bottom: 1rem; }
.misses h3 { margin: 0 0 .5rem; font: 400 1.4rem/1.2 var(--display); }
.misses ul { margin: 0; padding: 0; list-style: none; display: grid; gap: .6rem; }
.misses li b { display: block; }
.res-actions { display: grid; gap: .7rem; }

/* ---------- flashcards ---------- */
.topbar { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 1rem; }
.topbar h2 { margin: 0; font: 400 2rem/1.1 var(--display); flex: 1; }
.back { font-weight: 700; text-decoration: none; padding: .3rem 0; }
.back::before { content: "\2039  "; }
.chips { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: 1.1rem; }
.chip { min-height: 2.3rem; padding: .35rem .8rem; font-size: .9rem; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; }
.flip { cursor: pointer; border-radius: 18px; -webkit-tap-highlight-color: transparent; }
.flip-card {
  position: relative; min-height: 17rem; padding: 1.4rem 1.3rem 2.6rem;
  display: flex; flex-direction: column; justify-content: center;
  transition: transform .15s ease;
}
.flip-card.squash { transform: scaleX(0); }
.back-side { display: none; }
.flip.flipped .front-side { display: none; }
.flip.flipped .back-side { display: block; }
.flip.flipped .flip-card { background: #FBFBFF; }
.face-cat { color: var(--ink-2); font-weight: 650; font-size: .9rem; }
.face-term { margin: .3rem 0 0; font: 400 clamp(2.2rem, 10vw, 2.9rem)/1.05 var(--display); }
.face-hint { position: absolute; bottom: 1rem; left: 1.3rem; color: var(--ink-2); font-size: .88rem; }
.face-star { position: absolute; top: .9rem; right: 1.1rem; color: var(--gold); font-size: 1.6rem; -webkit-text-stroke: 1px var(--ink); }
.face-def { margin: 0; font-size: 1.18rem; line-height: 1.45; font-weight: 600; }
.face-tip { margin: .8rem 0 0; color: var(--ink-2); font-size: .98rem; }
.fc-pos { text-align: center; color: var(--ink-2); margin: .9rem 0; font-weight: 600; }
.fc-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.fc-nav { display: flex; justify-content: space-between; gap: .5rem; margin-top: .9rem; }

/* ---------- study guide ---------- */
.guide { list-style: none; margin: 0; padding: 0; counter-reset: g; display: grid; gap: .1rem; }
.guide li {
  counter-increment: g; display: grid; grid-template-columns: 2.1rem 1fr; gap: .2rem .6rem;
  padding: .75rem 0; border-bottom: 1px solid rgba(29, 35, 80, .15);
}
.guide li::before { content: counter(g); grid-row: span 2; font: 400 1.35rem/1.2 var(--display); color: var(--wax); text-align: right; }
.guide b { font: 400 1.3rem/1.15 var(--display); }
.guide span { color: var(--ink); }
.docs-h { margin: 2rem 0 .2rem; font: 400 1.6rem/1.2 var(--display); }
.docs { display: grid; gap: 1rem; margin-top: .8rem; }
.doc-img { display: block; width: 100%; height: auto; border: 2px solid var(--ink); border-radius: 12px; box-shadow: 4px 4px 0 var(--ink); background: #fff; }

/* ---------- fx + toast ---------- */
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }
.toast {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); z-index: 70;
  transform: translateX(-50%);
  padding: .6rem 1.1rem; border: 2px solid var(--ink); border-radius: 999px;
  background: var(--gold); color: var(--ink); font-weight: 800; box-shadow: 3px 3px 0 var(--ink);
  animation: pop .3s cubic-bezier(.2, .9, .3, 1.4) both;
  white-space: nowrap;
}
@keyframes pop { from { transform: translateX(-50%) scale(.6); opacity: 0; } }

@media (min-width: 640px) {
  .hero-title { font-size: 2.6rem; }
  .seal { width: 9.5rem; height: 9.5rem; }
  .seal.big { width: 12rem; height: 12rem; }
}

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