/* Self-hosted fonts (latin subset) so the calm typography renders reliably
   offline, e.g. on a flaky school-lab connection. Both families are variable,
   so one woff2 per family covers every weight. Sourced from Google Fonts. */
@font-face {
  font-family: 'Fraunces'; font-style: normal; font-weight: 500 600;
  font-display: swap; src: url(../fonts/fraunces-500.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter'; font-style: normal; font-weight: 400 600;
  font-display: swap; src: url(../fonts/inter-400.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #2c322f;
  --ink-soft: #5f6b64;
  --sage: #4a7c6f;
  --sage-dark: #3a6358;
  --sage-soft: #e4efe9;
  --terra: #c4673e;
  --terra-soft: #f6e6dd;
  --gold: #d8a657;
  --line: #e6e3db;
  --good: #4a7c6f;
  --bad: #c0503a;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(44, 50, 47, 0.06), 0 8px 30px rgba(44, 50, 47, 0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  max-width: 760px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 9px; }
.logo {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  background: var(--sage); color: #fff;
  border-radius: 9px; font-weight: 700; font-size: 18px;
}
.brand-name { font-family: "Fraunces", serif; font-weight: 600; font-size: 19px; }
/* Quiet tagline beside the wordmark: "I can", the meaning of Anyalo.
   Smaller and muted so it sits with the brand without competing. */
.brand-tag { font-size: 13px; font-weight: 400; color: var(--ink-soft); }

.icon-btn {
  border: 1px solid var(--line); background: var(--card);
  width: 38px; height: 38px; border-radius: 10px;
  font-size: 17px; cursor: pointer; color: var(--ink-soft);
  transition: background .15s;
}
.icon-btn:hover { background: var(--sage-soft); }

.app { max-width: 760px; margin: 0 auto; padding: 8px 18px 64px; }
.loading { text-align: center; color: var(--ink-soft); padding: 60px 0; }

/* Cards & headings */
.screen-head { margin: 10px 2px 20px; }
.screen-head h1 {
  font-family: "Fraunces", serif; font-weight: 600;
  font-size: clamp(24px, 6vw, 32px); line-height: 1.15;
}
.screen-head p { color: var(--ink-soft); margin-top: 6px; font-size: 15px; }
.eyebrow {
  text-transform: uppercase; letter-spacing: .08em;
  font-size: 12px; font-weight: 600; color: var(--terra);
  margin-bottom: 6px;
}

/* Grade / topic tiles */
.tiles { display: grid; gap: 12px; }
.tile {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
  cursor: pointer; text-align: left; width: 100%;
  box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
}
.tile:hover:not(.locked) { transform: translateY(-1px); border-color: var(--sage); }
.tile.locked { opacity: .55; cursor: not-allowed; box-shadow: none; }
.tile-icon {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 11px;
  background: var(--sage-soft); font-size: 22px; flex-shrink: 0;
}
.tile.done .tile-icon { background: var(--sage); color: #fff; }
.tile-body { flex: 1; min-width: 0; }
.tile-title { font-weight: 600; font-size: 16px; }
.tile-sub { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.tile-mark { font-size: 20px; color: var(--ink-soft); }
.tile.done .tile-mark { color: var(--sage); }

/* "Continue" card: one-tap re-entry into her current topic. Sage-tinted so it
   reads as the obvious next action, set apart from the neutral grade tiles. */
.continue-card {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  cursor: pointer; background: var(--sage-soft); border: 1px solid #cfe3db;
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px;
  box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
}
.continue-card:hover { transform: translateY(-1px); border-color: var(--sage); }
.cont-icon {
  display: grid; place-items: center; flex-shrink: 0;
  width: 44px; height: 44px; border-radius: 11px;
  background: var(--sage); color: #fff; font-size: 22px;
}
.cont-body { flex: 1; min-width: 0; }
.cont-label {
  display: block; font-size: 11.5px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--sage-dark);
}
.cont-topic { display: block; font-weight: 600; font-size: 17px; margin-top: 1px; color: var(--ink); }
.cont-meta { display: block; font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.cont-arrow { font-size: 26px; line-height: 1; color: var(--sage); flex-shrink: 0; }

.bar { height: 7px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 9px; }
.bar > span { display: block; height: 100%; background: var(--sage); border-radius: 99px; transition: width .4s; }

/* Buttons */
.btn {
  display: inline-block; border: none; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 15px;
  padding: 13px 20px; border-radius: 12px;
  background: var(--sage); color: #fff; transition: background .15s;
}
.btn:hover { background: var(--sage-dark); }
.btn-soft { background: var(--sage-soft); color: var(--sage-dark); }
.btn-soft:hover { background: #d4e6dd; }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn-ghost:hover { background: #f0eee8; }
.btn-danger { background: var(--terra-soft); color: var(--terra); }
.btn-danger:hover { background: #f0d6c8; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.back-link {
  background: none; border: none; cursor: pointer; font: inherit;
  color: var(--ink-soft); padding: 6px 0; margin-bottom: 6px; font-size: 14px;
}
.back-link:hover { color: var(--sage); }

/* The climb (home screen journey view) */
.climb-wrap {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 16px 10px; margin-bottom: 16px;
}
.climb { display: block; width: 100%; height: auto; max-width: 460px; margin: 0 auto; }
.climb-cap {
  text-align: center; font-size: 13.5px; color: var(--ink-soft);
  margin-top: 6px;
}
/* the "you are here" marker rises into place each time she lands on home */
.climb-marker { animation: climb-rise .6s cubic-bezier(.2,.8,.3,1) both; }
@keyframes climb-rise {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* "Why this matters" hook above the first question (adapts per grade) */
.why-hook {
  background: var(--gold-soft, #f6edd9); border: 1px solid #e7d4a6;
  border-radius: 12px; padding: 11px 15px; margin-bottom: 12px;
  font-size: 14px; color: #7a5a1e; line-height: 1.45;
}

/* Quiz */
.qcard {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.qmeta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.qmeta .count { color: var(--ink-soft); font-size: 13px; font-weight: 500; }
.qmeta .chip {
  background: var(--sage-soft); color: var(--sage-dark);
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 99px;
}
.qtext { font-size: 18px; font-weight: 500; margin-bottom: 16px; }
.opts { display: grid; gap: 10px; }
.opt {
  text-align: left; background: var(--card); border: 1.5px solid var(--line);
  border-radius: 12px; padding: 13px 15px; cursor: pointer; font: inherit;
  font-size: 15px; transition: border-color .12s, background .12s;
}
.opt:hover:not(:disabled) { border-color: var(--sage); }
.opt.chosen { border-color: var(--sage); background: var(--sage-soft); }
.opt.correct { border-color: var(--good); background: var(--sage-soft); }
.opt.wrong { border-color: var(--bad); background: var(--terra-soft); }
.opt:disabled { cursor: default; }

.explain {
  margin-top: 14px; padding: 13px 15px; border-radius: 12px;
  background: var(--sage-soft); font-size: 14px; color: var(--sage-dark);
}
.explain.miss { background: var(--terra-soft); color: var(--terra); }
/* small Polepole guiding the per-question feedback */
.explain .fb-main { display: flex; gap: 10px; align-items: flex-start; }
.explain .fb-mascot { flex: 0 0 auto; }
.explain .fb-mascot .tortoise { width: 46px; height: auto; display: block; animation: none; }
.explain .fb-said { flex: 1 1 auto; }
.explain .fb-head { display: block; font-weight: 700; font-size: 15px; }
.explain .fb-head b { font-weight: 700; }
.explain.good .fb-head b { color: var(--sage-dark); }
.explain.miss .fb-head b { color: var(--bad); }
.explain .fb-why { display: block; margin-top: 4px; color: var(--ink-soft); }

/* "See the picture" toggle + inline diagram in the instant feedback */
.fb-pic-toggle {
  margin-top: 10px; padding: 5px 12px; font: inherit; font-size: 13px;
  font-weight: 600; cursor: pointer; border-radius: 99px;
  background: var(--card); color: var(--ink); border: 1.5px solid var(--line);
}
.fb-pic-toggle:hover { border-color: var(--sage); }
.fb-diagram { margin-top: 10px; background: var(--card); }
.fb-diagram figcaption { color: var(--ink-soft); }

/* Notes / reading screen */
.notes {
  background: var(--card); border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius); padding: 20px 22px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.notes h3 { font-family: "Fraunces", serif; font-size: 19px; margin-bottom: 8px; }

/* Targeted review: the specific questions she missed */
.miss-list { display: grid; gap: 12px; margin-bottom: 16px; }
.miss-item {
  background: var(--card); border: 1px solid var(--line);
  border-left: 4px solid var(--terra); border-radius: 12px;
  padding: 14px 16px; box-shadow: var(--shadow);
}
.miss-q { font-weight: 600; font-size: 15px; margin-bottom: 7px; }
.miss-ans { font-size: 14px; margin-bottom: 4px; color: var(--ink); }
.miss-ans b { color: var(--sage-dark); }
.miss-why { font-size: 14px; color: var(--ink-soft); }

/* Polepole the tortoise: extra help after a few stalls on the same topic (#4) */
.tortoise-help {
  display: flex; gap: 28px; align-items: flex-start;
  background: var(--sage-soft); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px;
}
.tortoise-wrap { flex: 0 0 auto; width: 96px; text-align: center; }
.tortoise { width: 96px; height: auto; display: block; }
.tortoise-name {
  display: block; font-weight: 700; font-size: 12px;
  color: var(--sage-dark); margin-top: 2px; letter-spacing: .02em;
}
/* a real cartoon-book speech balloon: white, thick dark outline, curved tail */
.tortoise-bubble {
  position: relative; flex: 1 1 auto;
  background: #fff; border: 3px solid var(--ink);
  border-radius: 24px; padding: 16px 18px;
  box-shadow: 3px 4px 0 rgba(44, 50, 47, 0.16);
  animation: bubble-pop .28s cubic-bezier(.2, 1.25, .4, 1) both;
}
@keyframes bubble-pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
/* curved, tapering comic tail that sits in the gap, pointing at Polepole */
.bubble-tail {
  position: absolute; left: -26px; top: 18px;
  width: 32px; height: 42px; overflow: visible;
}
.bubble-lead { font-size: 14.5px; color: var(--ink-soft); margin: 0; }
.slow-help-body { margin-top: 10px; font-size: 15px; color: var(--ink); line-height: 1.6; }
.slow-help-body.loading { color: var(--ink-soft); font-style: italic; }
.bubble-p { margin: 0 0 10px; }
.bubble-p:last-child { margin-bottom: 0; }
/* a gentle, slow bob so Polepole feels alive (calm, not bouncy) */
.tortoise { animation: tortoise-bob 3.2s ease-in-out infinite; }
@keyframes tortoise-bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@media (max-width: 480px) {
  .tortoise-help { flex-direction: column; align-items: center; }
  .tortoise-bubble::before, .tortoise-bubble::after { display: none; }
}

/* Topic diagram on the review screen */
.diagram {
  margin: 4px 0 14px;
  padding: 14px 14px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.diagram .dia {
  display: block;
  width: 100%;
  height: auto;
  max-width: 440px;
  margin: 0 auto;
  font-family: "Inter", system-ui, sans-serif;
}
.diagram figcaption {
  margin-top: 8px;
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.45;
}
.notes p { color: var(--ink-soft); font-size: 15px; margin-bottom: 8px; }
.notes ul { margin: 8px 0 4px 18px; color: var(--ink-soft); font-size: 15px; }
.notes li { margin-bottom: 5px; }

/* Result */
.result { text-align: center; padding: 14px 4px; margin-bottom: 16px; }
.result .big { font-family: "Fraunces", serif; font-size: 52px; line-height: 1; }
.result .big.pass { color: var(--sage); }
.result .big.fail { color: var(--terra); }
.result h2 { font-family: "Fraunces", serif; font-size: 24px; margin: 12px 0 6px; }
.result p { color: var(--ink-soft); }
.result .recap {
  background: var(--sage-soft); color: var(--sage-dark);
  font-weight: 600; font-size: 15px;
  border-radius: 12px; padding: 12px 16px; margin: 10px auto 12px; max-width: 380px;
}
/* cheering Polepole on the celebration screen */
.result-mascot { display: grid; place-items: center; margin-bottom: 2px; }
.result-mascot .tortoise { width: 92px; height: auto; }
.result-mascot .tortoise-name { margin-top: 0; }
.confetti { font-size: 40px; margin-bottom: 4px; animation: pop-in .5s cubic-bezier(.2,1.3,.4,1) both; }
.result .big { animation: rise-in .5s ease-out .1s both; }
.result .recap { animation: rise-in .45s ease-out .25s both; }
@keyframes pop-in { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes rise-in { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Settings panel */
.panel {
  position: fixed; inset: 0; background: rgba(44,50,47,.4);
  display: grid; place-items: center; padding: 18px; z-index: 50;
}
.panel.hidden { display: none; }
.panel-card {
  background: var(--card); border-radius: 18px; padding: 24px;
  width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto;
}
.panel-card h2 { font-family: "Fraunces", serif; margin-bottom: 16px; }
.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field .hint { font-weight: 400; font-size: 13px; color: var(--ink-soft); margin: 0 0 8px; }
.field input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 13px; font: inherit; font-size: 14px; background: var(--bg);
}
.panel-card .btn { width: 100%; margin-top: 8px; }
/* stack the two login inputs with a little breathing room */
#signedOut input + input { margin-top: 8px; }
.field .msg { min-height: 1em; margin-top: 8px; color: var(--terra); }

/* sign-in gate (welcome screen) */
.signin-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px; max-width: 420px;
}
.signin-card input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; font: inherit; font-size: 15px; background: var(--bg);
  margin-bottom: 10px;
}
.signin-card .btn { width: 100%; margin-top: 2px; }
.signin-card .msg { min-height: 1em; margin-top: 10px; color: var(--terra); }

/* Log in / I'm new toggle */
.seg {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 16px;
  background: var(--bg); border-radius: 12px;
}
.seg-btn {
  flex: 1; padding: 9px 10px; font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; border: none; border-radius: 9px;
  background: transparent; color: var(--ink-soft);
}
.seg-btn.active { background: var(--card); color: var(--sage-dark); box-shadow: var(--shadow); }

.hidden { display: none; }

/* Progress note: a real, printable Certificate of Achievement.
   A formal double frame (sage outer, gold inner) with corner flourishes,
   a ribboned gold seal, and two signature lines. */
.cert-wrap { max-width: 560px; position: relative; }
/* Always-visible close affordance, sitting in the card's top-right padding */
.cert-x {
  position: absolute; top: 10px; right: 12px; z-index: 2;
  width: 32px; height: 32px; padding: 0; border: none; border-radius: 50%;
  background: rgba(44, 50, 47, .06); color: var(--ink-soft);
  font-size: 22px; line-height: 1; cursor: pointer;
  display: grid; place-items: center;
}
.cert-x:hover { background: rgba(44, 50, 47, .12); color: var(--ink); }
.cert-card {
  background:
    radial-gradient(120% 90% at 50% 0%, #fffdf6 0%, #fbf7ec 100%);
  border: 3px double var(--sage);
  border-radius: 4px; padding: 34px 40px 30px; text-align: center;
  position: relative;
  box-shadow: 0 10px 30px rgba(58, 99, 88, .14);
}
/* Inner gold frame */
.cert-card::after {
  content: ""; position: absolute; inset: 10px; border: 1.5px solid var(--gold);
  border-radius: 2px; pointer-events: none;
}
/* Small gold diamonds where the frame corners meet */
.cert-corner {
  position: absolute; width: 9px; height: 9px; background: var(--gold);
  transform: rotate(45deg); box-shadow: 0 0 0 2px #fbf7ec; z-index: 1;
}
.cert-corner.tl { left: 6px; top: 6px; }
.cert-corner.tr { right: 6px; top: 6px; }
.cert-corner.bl { left: 6px; bottom: 6px; }
.cert-corner.br { right: 6px; bottom: 6px; }

.cert-eyebrow {
  color: var(--terra); font-size: 11.5px; font-weight: 700;
  letter-spacing: .16em; text-transform: uppercase;
}
.cert-title {
  font-family: "Fraunces", serif; font-size: 30px; font-weight: 600;
  margin: 8px 0 0; color: var(--sage-dark); letter-spacing: .01em;
}
.cert-rule {
  width: 84px; height: 2px; margin: 12px auto 16px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.cert-line { color: var(--ink-soft); font-size: 13.5px; letter-spacing: .03em; }
.cert-name {
  font-family: "Fraunces", serif; font-size: 32px; font-weight: 600;
  font-style: italic; margin: 8px auto 14px; color: var(--ink);
  display: inline-block; padding: 0 22px 6px; max-width: 100%;
  overflow-wrap: anywhere; border-bottom: 1.5px solid var(--gold);
}
.cert-body { font-size: 15px; line-height: 1.5; color: var(--ink); margin: 0 auto; max-width: 400px; }
.cert-sub { font-size: 13px; color: var(--ink-soft); margin: 10px auto 0; }
.cert-seal-wrap { margin: 16px auto 4px; }
.cert-seal { width: 96px; height: auto; display: block; margin: 0 auto; }
.cert-foot {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 40px; margin-top: 18px;
}
.cert-sign {
  flex: 1; font-family: "Fraunces", serif; font-size: 15px; color: var(--ink);
}
.cert-sign-line { border-top: 1.5px solid var(--ink-soft); margin-bottom: 6px; }
.cert-sign-cap {
  font-family: inherit; font-size: 11px; font-weight: 400; font-style: normal;
  letter-spacing: .04em; color: var(--ink-soft); text-transform: uppercase;
}
.cert-sign:not(:first-child) .cert-sign-cap { text-transform: none; letter-spacing: 0; }

/* When printing, the certificate becomes the whole page (a clean A4 PDF).
   We keep everything in normal flow (no position:fixed, which browsers repeat
   on every printed page) and remove all non-cert content so it fits one page. */
@media print {
  @page { size: A4 landscape; margin: 14mm; }
  html, body { background: #fff !important; height: auto !important; overflow: visible !important; }

  /* Drop every top-level section except the certificate overlay out of flow */
  body > *:not(#certPanel) { display: none !important; }

  /* Un-modal the overlay: no dim backdrop, no centering grid, no z-stacking */
  #certPanel {
    position: static !important; display: block !important;
    inset: auto !important; padding: 0 !important; background: none !important;
  }
  /* Shed the card chrome so the cert sits directly on the page */
  #certPanel .panel-card {
    max-width: none !important; max-height: none !important; width: auto !important;
    padding: 0 !important; background: none !important; overflow: visible !important;
  }
  /* The action buttons and close ✕ aren't part of the printed certificate */
  #certPanel .btn-row, #certPanel .cert-x { display: none !important; }

  #cert {
    width: 100%; max-width: 720px; margin: 0 auto; box-shadow: none !important;
    break-inside: avoid; page-break-inside: avoid;
  }
}

@media (max-width: 480px) {
  .qcard, .panel-card { padding: 18px; }
  .qtext { font-size: 17px; }

  /* Certificate: shrink the generous desktop padding/type so it fits a phone,
     and keep the two signature lines side-by-side but closer together. */
  .cert-card { padding: 24px 20px 22px; }
  .cert-title { font-size: 23px; }
  .cert-name { font-size: 26px; }
  .cert-body { font-size: 14px; }
  .cert-foot { gap: 16px; }
  .cert-sign { font-size: 13px; }
  .cert-sign-cap { font-size: 10px; }
}

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