/* Quiz play screen and its popups. Loaded after quiz.css; every rule is scoped
   to the play screen or to a popup and uses its own class names (qp-), so the
   pre-quiz and result screens are not affected.

   Layout: two columns on desktop and tablet (level, timer, figures and Exit on
   the left; question and options on the right). On phones the same markup is
   laid out as one flow: header, question, options, timer beside the figures,
   then Exit. A tap on an option is the answer. */

#quiz-screen {
  --qp-ink: #0d1b3e;
  --qp-muted: #5c6b8a;
  --qp-line: #dfe8f6;
  --qp-blue: #1765f2;
  --qp-blue-deep: #0b2f8f;
  --qp-navy: #0a2569;
  --qp-gold: #f8c04a;
  --qp-good: #16a34a;
  --qp-bad: #e5304d;
  color: var(--qp-ink);
}

#quiz-screen,
#quiz-screen :where(p, span, strong, small, em, div),
.qp-pop__box,
.qp-pop__box :where(p, span, strong, small, em, div) {
  font-family: "Inter", "Segoe UI", Roboto, Arial, sans-serif;
}

#quiz-screen :where(h2, h3),
#quiz-screen :where(.qp-opt__key, .qp-fig strong, .qp-level__name, .qp-diff, .qp-topic, #timer),
.qp-pop__box :where(h2, strong) {
  font-family: "Manrope", "Inter", "Segoe UI", Roboto, Arial, sans-serif;
}

#quiz-screen button,
.qp-pop__box button {
  font-family: "Manrope", "Inter", "Segoe UI", Roboto, Arial, sans-serif !important;
  -webkit-tap-highlight-color: transparent;
}

#quiz-screen lucide-icon,
.qp-pop__box lucide-icon {
  display: inline-flex;
  flex: none;
  width: 1.15em;
  height: 1.15em;
}

/* ---------- frame ---------- */
#quiz-screen .qp-shell {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  align-items: start;
  gap: 26px;
}

#quiz-screen .qp-side,
#quiz-screen .qp-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#quiz-screen .qp-side { gap: 20px; }
#quiz-screen .qp-main { gap: 18px; }

/* ---------- level ---------- */
#quiz-screen .qp-level {
  position: relative;
  padding: 22px 24px 24px;
  border-radius: 20px;
  background:
    radial-gradient(circle at 92% 86%, rgba(86, 137, 255, 0.34), transparent 46%),
    linear-gradient(140deg, #0a2569 0%, #0d3299 62%, #1247c7 100%);
  box-shadow: 0 18px 38px rgba(13, 43, 122, 0.28);
  color: #ffffff;
  overflow: hidden;
}

#quiz-screen .qp-level__row {
  display: flex;
  align-items: center;
  gap: 10px;
}

#quiz-screen .qp-level__name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #ffffff;
}

#quiz-screen .qp-level__name lucide-icon {
  width: 30px;
  height: 30px;
  color: var(--qp-gold);
}

#quiz-screen .qp-diff {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  margin-left: auto;
  padding: 0 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd978 0%, #f6b93b 100%);
  color: #4a3200;
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
}

#quiz-screen .qp-level h3 {
  margin: 16px 0 0;
  color: #ffffff;
  font-size: clamp(1.4rem, 2.3vw, 1.85rem);
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

#quiz-screen .qp-level > p {
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.95rem;
}

#quiz-screen .qp-meter {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  color: #ffffff;
  font-size: 0.92rem;
  font-weight: 700;
}

#quiz-screen .qp-meter__track {
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
}

#quiz-screen .qp-meter__fill {
  width: 5%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #35b8ff 0%, #ffffff 100%);
  transition: width 260ms cubic-bezier(.2, .7, .25, 1);
}

#quiz-screen .qp-round {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(16, 52, 130, 0.16);
  color: var(--qp-blue);
  font-size: 1.15rem;
  cursor: pointer;
}

/* The header copies of Back, Sound and the mascot belong to the phone layout. */
#quiz-screen .qp-back,
#quiz-screen .qp-sound--top,
#quiz-screen .qp-level__art {
  display: none;
}

/* ---------- timer ---------- */
#quiz-screen .qp-clock {
  display: grid;
  place-items: center;
  padding: 18px;
  border: 1px solid var(--qp-line);
  border-radius: 20px;
  background:
    radial-gradient(circle at 12% 88%, rgba(250, 204, 110, 0.2), transparent 34%),
    linear-gradient(160deg, #f4f8ff 0%, #ffffff 60%);
  box-shadow: 0 12px 28px rgba(31, 72, 150, 0.08);
}

#quiz-screen .qp-ring {
  --timer-angle: 360deg;
  --timer-accent: var(--qp-blue);
  display: grid;
  place-items: center;
  width: min(100%, 200px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--timer-accent) var(--timer-angle), #e2eaf8 0);
}

#quiz-screen .qp-ring__face {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  width: calc(100% - 22px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px #eef2fa, 0 6px 16px rgba(31, 72, 150, 0.1);
  text-align: center;
}

#quiz-screen .qp-ring__face lucide-icon {
  width: 22px;
  height: 22px;
  color: #5b9bff;
}

#quiz-screen #timer {
  color: var(--qp-navy);
  font-size: clamp(2rem, 4vw, 2.9rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

#quiz-screen .qp-ring__face small {
  max-width: 8.5em;
  color: #2c3d63;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.3;
  text-transform: uppercase;
}

/* ---------- figures ---------- */
#quiz-screen .qp-tally {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--qp-line);
  border-radius: 20px;
  background: #ffffff;
  box-shadow: 0 12px 28px rgba(31, 72, 150, 0.08);
}

#quiz-screen .qp-fig {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 14px 12px;
  border-radius: 14px;
  background: #eef9f3;
}

#quiz-screen .qp-fig--ge { background: #fff7e8; }
#quiz-screen .qp-fig--xp { background: #f1eefc; }
#quiz-screen .qp-fig--run { background: #fff0ee; }

#quiz-screen .qp-fig__ico,
#quiz-screen .qp-fig__coin {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

#quiz-screen .qp-fig__ico {
  background: #22b573;
  color: #ffffff;
  font-size: 1.1rem;
}

#quiz-screen .qp-fig--xp .qp-fig__ico { background: #e2dafb; color: #6d3fe0; }
#quiz-screen .qp-fig--run .qp-fig__ico { background: #ffd9d2; color: #f04a23; }
#quiz-screen .qp-fig__coin { object-fit: contain; border-radius: 0; }

#quiz-screen .qp-fig__text {
  display: grid;
  min-width: 0;
}

#quiz-screen .qp-fig small {
  color: var(--qp-muted);
  font-size: 0.84rem;
}

#quiz-screen .qp-fig strong {
  color: var(--qp-ink);
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

/* ---------- exit ---------- */
#quiz-screen .qp-exit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 60px;
  padding: 0 26px;
  border-radius: 999px;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  transition: background-color 140ms ease, box-shadow 140ms ease, border-color 140ms ease, opacity 140ms ease;
}

#quiz-screen .qp-exit {
  width: 100%;
  border: 2px solid #c9dafb;
  background: #ffffff;
  box-shadow: 0 10px 22px rgba(31, 72, 150, 0.08);
  color: var(--qp-blue);
}

@media (hover: hover) {
  #quiz-screen .qp-exit:hover { border-color: var(--qp-blue); background: #f4f8ff; }
}

#quiz-screen :where(.qp-exit, .qp-round, .qp-opt):focus-visible,
.qp-pop__go:focus-visible {
  outline: 3px solid #8fb6ff;
  outline-offset: 3px;
}

/* ---------- question ---------- */
#quiz-screen .qp-ask {
  position: relative;
  min-height: 228px;
  padding: 24px 250px 28px 28px;
  border: 1px solid var(--qp-line);
  border-radius: 22px;
  /* Distance from the card's right edge to the middle of the mascot. */
  --qp-art-center: 130px;
  background:
    radial-gradient(circle at calc(100% - var(--qp-art-center)) 68%, rgba(150, 194, 255, 0.6), transparent 190px),
    linear-gradient(120deg, #ffffff 0%, #eef5ff 58%, #dbe9ff 100%);
  box-shadow: 0 14px 32px rgba(31, 72, 150, 0.1);
  overflow: hidden;
}

#quiz-screen .qp-ask__top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

#quiz-screen .qp-topic,
#quiz-screen .qp-diff--soft {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin: 0;
  padding: 0 18px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 800;
  text-transform: capitalize;
}

#quiz-screen .qp-topic {
  background: #ffffff;
  box-shadow: 0 6px 14px rgba(31, 72, 150, 0.1);
  color: var(--qp-navy);
}

#quiz-screen .qp-topic lucide-icon { color: var(--qp-blue); }

#quiz-screen .qp-ask .qp-sound {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 2;
  width: 56px;
  height: 56px;
  font-size: 1.3rem;
}

#quiz-screen .qp-sound.is-muted { color: #8b97b3; }

#quiz-screen #question-text {
  position: relative;
  z-index: 1;
  margin: 22px 0 0;
  color: var(--qp-navy);
  font-size: clamp(1.3rem, 2.4vw, 1.9rem);
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

#quiz-screen .qp-ask__art {
  position: absolute;
  right: 92px;
  /* The mascot stands on the card's bottom edge and the edge crops it at the
     chest, so it rises out of the card at any card height. A fade mask is not
     used here: it cut the shadow off along the picture's box and drew a faint
     rectangle around the mascot. */
  bottom: -96px;
  width: 150px;
  height: auto;
  filter: drop-shadow(0 10px 16px rgba(16, 52, 130, 0.2));
  pointer-events: none;
  user-select: none;
}

/* A question that comes with a picture or diagram. */
#quiz-screen .qp-figure {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--qp-line);
  border-radius: 16px;
  background: #ffffff;
}

#quiz-screen .qp-figure[hidden] { display: none; }

#quiz-screen .qp-figure :where(img, svg) {
  display: block;
  max-width: 100%;
  max-height: min(42vh, 320px);
  width: auto;
  height: auto;
  object-fit: contain;
}

/* ---------- options ---------- */
#quiz-screen .qp-opts {
  display: grid;
  gap: 14px;
}

#quiz-screen .qp-opt {
  display: flex;
  align-items: center;
  gap: 22px;
  width: 100%;
  min-height: 78px;
  padding: 12px 26px 12px 28px;
  border: 2px solid #e6ecf7;
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 8px 20px rgba(31, 72, 150, 0.06);
  color: var(--qp-ink);
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

#quiz-screen .qp-opt__key {
  display: grid;
  place-items: center;
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #e7ecf6;
  color: var(--qp-navy);
  font-size: 1.05rem;
  font-weight: 800;
  transition: background-color 140ms ease, color 140ms ease;
}

#quiz-screen .qp-opt__text {
  flex: 1;
  min-width: 0;
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

#quiz-screen .qp-opt__dot {
  position: relative;
  flex: none;
  width: 26px;
  height: 26px;
  border: 2px solid #b9c4d9;
  border-radius: 50%;
  background: #ffffff;
}

@media (hover: hover) {
  #quiz-screen .qp-opt:not(:disabled):hover {
    border-color: #a9c5fb;
    box-shadow: 0 12px 26px rgba(31, 72, 150, 0.12);
  }
}

#quiz-screen .qp-opt.is-picked {
  border-color: var(--qp-blue);
  background: #eef4ff;
  box-shadow: 0 12px 26px rgba(23, 101, 242, 0.14);
}

#quiz-screen .qp-opt.is-picked .qp-opt__key {
  background: linear-gradient(180deg, #2a78ff 0%, #0b4fe0 100%);
  color: #ffffff;
}

#quiz-screen .qp-opt.is-picked .qp-opt__dot { border-color: var(--qp-blue); }

#quiz-screen .qp-opt.is-picked .qp-opt__dot::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: var(--qp-blue);
}

#quiz-screen .qp-opt:disabled { cursor: default; }
#quiz-screen .qp-opt:disabled:not(.is-picked) { opacity: 0.72; }

#quiz-screen .qp-opt.correct {
  border-color: var(--qp-good);
  background: #eafaf0;
}

#quiz-screen .qp-opt.correct .qp-opt__key { background: var(--qp-good); color: #ffffff; }
#quiz-screen .qp-opt.correct .qp-opt__dot { border-color: var(--qp-good); }
#quiz-screen .qp-opt.correct .qp-opt__dot::after { background: var(--qp-good); }

#quiz-screen .qp-opt.incorrect {
  border-color: var(--qp-bad);
  background: #ffeef1;
}

#quiz-screen .qp-opt.incorrect .qp-opt__key { background: var(--qp-bad); color: #ffffff; }
#quiz-screen .qp-opt.incorrect .qp-opt__dot { border-color: var(--qp-bad); }
#quiz-screen .qp-opt.incorrect .qp-opt__dot::after { background: var(--qp-bad); }

/* ---------- tablet ---------- */
@media (max-width: 1024px) {
  #quiz-screen .qp-shell {
    grid-template-columns: minmax(230px, 270px) minmax(0, 1fr);
    gap: 18px;
  }

  #quiz-screen .qp-side { gap: 14px; }
  #quiz-screen .qp-level { padding: 18px; }
  #quiz-screen .qp-level__name lucide-icon { width: 24px; height: 24px; }
  #quiz-screen .qp-diff { min-height: 32px; padding: 0 12px; }
  #quiz-screen .qp-ring { width: min(100%, 160px); }
  #quiz-screen .qp-fig { gap: 8px; padding: 10px 8px; }
  #quiz-screen .qp-fig__ico, #quiz-screen .qp-fig__coin { width: 32px; height: 32px; }
  #quiz-screen .qp-fig strong { font-size: 1.05rem; }
  #quiz-screen .qp-ask { min-height: 200px; padding: 20px 194px 22px 20px; --qp-art-center: 98px; }
  #quiz-screen .qp-ask__art { right: 70px; bottom: -40px; width: 104px; }
  #quiz-screen .qp-ask .qp-sound { top: 14px; right: 14px; width: 46px; height: 46px; }
  #quiz-screen .qp-opt { min-height: 66px; gap: 16px; padding: 10px 18px; }
  #quiz-screen .qp-opt__key { width: 42px; height: 42px; }
  #quiz-screen .qp-exit { min-height: 54px; font-size: 1rem; }
}

/* ---------- phone ---------- */
@media (max-width: 900px) {
  /* The header runs edge to edge, so the page frame gives up its side margin. */
  body#quiz-page:has(#quiz-screen.active) .quiz-main-shell {
    width: 100% !important;
    max-width: 100% !important;
    padding-top: 0 !important;
  }

  #quiz-screen .qp-shell {
    grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr);
    grid-template-areas:
      "level level"
      "ask ask"
      "opts opts"
      "clock tally"
      "exit exit";
    align-items: stretch;
    gap: 12px;
    padding: 0 16px 8px;
  }

  #quiz-screen .qp-side,
  #quiz-screen .qp-main {
    display: contents;
  }

  #quiz-screen .qp-level {
    grid-area: level;
    min-height: calc(124px + clamp(140px, 28vw, 172px));
    margin: 0 -16px;
    padding: 16px 18px 80px;
    border-radius: 0 0 28px 28px;
    background:
      radial-gradient(circle at 80% 70%, rgba(120, 180, 255, 0.55), transparent 46%),
      linear-gradient(170deg, #0a2a86 0%, #1450d8 70%, #3a82f6 100%);
    box-shadow: none;
  }

  #quiz-screen .qp-back,
  #quiz-screen .qp-sound--top {
    display: inline-grid;
    width: 42px;
    height: 42px;
  }

  #quiz-screen .qp-sound--top { margin-left: auto; }

  #quiz-screen .qp-level__name {
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 999px;
    background: rgba(8, 32, 110, 0.5);
    font-size: 0.86rem;
  }

  #quiz-screen .qp-level__name lucide-icon { width: 22px; height: 22px; }

  #quiz-screen .qp-level .qp-diff {
    min-height: 40px;
    margin-left: 0;
    padding: 0 14px;
  }

  #quiz-screen .qp-level h3,
  #quiz-screen .qp-level > p,
  #quiz-screen .qp-meter {
    position: relative;
    z-index: 1;
    max-width: calc(100% - clamp(140px, 28vw, 172px) - 4px);
  }

  #quiz-screen .qp-level h3 { margin-top: 18px; font-size: 1.5rem; }

  /* The mascot stands behind the question card: its head and shoulders show
     above the card's top edge and the card covers the rest, whatever height
     the header grows to. */
  #quiz-screen .qp-level__art {
    position: absolute;
    right: 20px;
    bottom: -8px;
    display: block;
    width: auto;
    height: 208px;
    filter: drop-shadow(0 10px 16px rgba(4, 22, 80, 0.35));
    pointer-events: none;
  }

  #quiz-screen .qp-ask {
    grid-area: ask;
    z-index: 1;
    min-height: 0;
    margin-top: -68px;
    padding: 16px 18px 20px;
    border-radius: 20px;
    background: linear-gradient(140deg, #ffffff 0%, #f3f8ff 70%, #e6f0ff 100%);
  }

  #quiz-screen .qp-ask__art,
  #quiz-screen .qp-ask .qp-sound {
    display: none;
  }

  #quiz-screen .qp-topic,
  #quiz-screen .qp-diff--soft {
    min-height: 36px;
    padding: 0 13px;
    font-size: 0.84rem;
  }

  #quiz-screen #question-text { margin-top: 14px; font-size: 1.3rem; }

  #quiz-screen .qp-opts { grid-area: opts; gap: 10px; }

  #quiz-screen .qp-opt {
    min-height: 62px;
    gap: 14px;
    padding: 9px 16px;
    border-radius: 16px;
  }

  #quiz-screen .qp-opt__key { width: 40px; height: 40px; font-size: 0.98rem; }
  #quiz-screen .qp-opt__text { font-size: 1rem; }
  #quiz-screen .qp-opt__dot { width: 24px; height: 24px; }

  #quiz-screen .qp-clock { grid-area: clock; padding: 10px; border-radius: 18px; }
  #quiz-screen .qp-ring { width: min(100%, 150px); }
  #quiz-screen .qp-ring__face { width: calc(100% - 16px); }
  #quiz-screen .qp-ring__face lucide-icon { width: 18px; height: 18px; }
  #quiz-screen #timer { font-size: 1.9rem; }
  #quiz-screen .qp-ring__face small { font-size: 0.58rem; }

  #quiz-screen .qp-tally {
    grid-area: tally;
    align-content: stretch;
    gap: 8px;
    padding: 8px;
    border-radius: 18px;
  }

  #quiz-screen .qp-fig { gap: 8px; padding: 8px; }
  #quiz-screen .qp-fig__ico, #quiz-screen .qp-fig__coin { width: 34px; height: 34px; font-size: 1rem; }
  #quiz-screen .qp-fig small { font-size: 0.76rem; }
  #quiz-screen .qp-fig strong { font-size: 1.05rem; }

  #quiz-screen .qp-exit {
    grid-area: exit;
    min-height: 54px;
    padding: 0 10px;
    gap: 8px;
    font-size: 0.98rem;
  }

}

@media (max-width: 400px) {
  #quiz-screen .qp-shell { gap: 10px; padding-inline: 12px; }
  #quiz-screen .qp-level { margin-inline: -12px; padding-inline: 14px; }
  #quiz-screen .qp-level__row { gap: 7px; }
  #quiz-screen .qp-back, #quiz-screen .qp-sound--top { width: 38px; height: 38px; }
  #quiz-screen .qp-level__name, #quiz-screen .qp-level .qp-diff { min-height: 36px; padding: 0 10px; font-size: 0.78rem; }
  #quiz-screen .qp-level h3 { font-size: 1.32rem; }
  #quiz-screen #question-text { font-size: 1.16rem; }
  #quiz-screen .qp-fig { flex-direction: column; align-items: flex-start; gap: 4px; padding: 7px; }
  #quiz-screen .qp-fig__ico, #quiz-screen .qp-fig__coin { width: 26px; height: 26px; font-size: 0.82rem; }
  #quiz-screen .qp-fig strong { font-size: 0.98rem; }
  #quiz-screen #timer { font-size: 1.5rem; }
  #quiz-screen .qp-ring__face small { max-width: 7em; font-size: 0.5rem; letter-spacing: 0.02em; }
  #quiz-screen .qp-level__art { right: 12px; height: 186px; }
}

/* =====================================================================
   Popups: correct, wrong, time up, and the exit question.
   The overlay keeps the page's existing "modal" behaviour; only the box
   inside is new. There is deliberately no corner close button.
   ===================================================================== */
.qp-pop {
  --pop-accent: #e5304d;
  --pop-accent-deep: #c81e3c;
  --pop-soft: #ffeef1;
  --pop-wash: #ffd9df;
  --pop-ink: #0d1b3e;
  background: rgba(15, 27, 56, 0.62);
  overflow: hidden;
}

/* While a popup is open the page behind it does not scroll, so the popup is
   the only thing that can move. This looks at the open popup itself: the
   page-level "modal-open" marker can be cleared early by a shared clean-up
   script while the popup is still fading in. */
html:has(body#quiz-page .modal.active) {
  overflow: hidden !important;
}

.qp-pop[data-kind="correct"] {
  --pop-accent: #16a34a;
  --pop-accent-deep: #0f8a3c;
  --pop-soft: #eafaf0;
  --pop-wash: #cdeedb;
  --pop-ink: #0b3d22;
}

.qp-pop[data-kind="timeout"] {
  --pop-accent: #f08c00;
  --pop-accent-deep: #d97706;
  --pop-soft: #fff5e3;
  --pop-wash: #ffe2b0;
}

.qp-pop[data-kind="exit"] {
  --pop-accent: #1765f2;
  --pop-accent-deep: #0b4fe0;
  --pop-soft: #edf4ff;
  --pop-wash: #d3e3ff;
}

.qp-pop__box {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  align-items: center;
  gap: 8px 24px;
  width: min(960px, 100%);
  min-width: 0;
  max-height: calc(100dvh - 24px);
  margin: auto;
  padding: 34px 44px 38px 28px;
  border-radius: 30px;
  background:
    radial-gradient(circle at 16% 62%, var(--pop-wash), transparent 44%),
    radial-gradient(circle at 96% 96%, var(--pop-wash), transparent 34%),
    linear-gradient(180deg, #ffffff 0%, var(--pop-soft) 100%);
  box-shadow: 0 34px 80px rgba(8, 20, 54, 0.4);
  color: var(--pop-ink);
  /* Sized to fit the screen (see the short-screen rules below). If a very
     small screen still needs it, the box scrolls by touch or wheel without
     drawing a bar. */
  overflow: hidden auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.qp-pop__box::-webkit-scrollbar { display: none; }

.qp-pop.active .qp-pop__box {
  animation: qp-pop-in 240ms cubic-bezier(.2, .7, .25, 1) both;
}

@keyframes qp-pop-in {
  from { opacity: 0; transform: translateY(14px) scale(.96); }
  to { opacity: 1; transform: none; }
}

/* Closing: the popup is already closed for the quiz; this only fades it out. */
.modal.is-closing {
  display: flex;
  pointer-events: none;
  animation: qp-pop-out 150ms cubic-bezier(.4, 0, 1, 1) both;
}

@keyframes qp-pop-out {
  to { opacity: 0; }
}

.qp-pop__art {
  display: grid;
  place-items: center;
  align-self: stretch;
  min-width: 0;
}

.qp-pop__art img {
  display: block;
  width: min(100%, 300px);
  height: auto;
  max-height: 360px;
  object-fit: contain;
  background: none;
  /* Each drawing ends at the waist. It fades into the popup's own colour so
     it reads as part of the popup, not a picture laid on top. */
  -webkit-mask-image: linear-gradient(#000 70%, transparent 97%);
  mask-image: linear-gradient(#000 70%, transparent 97%);
  user-select: none;
}

.qp-pop__art {
  position: relative;
  isolation: isolate;
}

/* A soft glow in the popup's colour sits behind the mascot. */
.qp-pop__art::before {
  content: "";
  position: absolute;
  inset: 8% 6% 4%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--pop-accent) 22%, #ffffff), transparent);
}

/* This drawing has stray marks on its left edge and is cut off at the waist. */
.qp-pop__art--tall img {
  width: min(100%, 230px);
  max-height: 330px;
  object-fit: cover;
  object-position: 62% top;
  clip-path: inset(0 0 0 7%);
}

.qp-pop__main {
  display: grid;
  justify-items: center;
  gap: 14px;
  min-width: 0;
  text-align: center;
}

.qp-pop__mark {
  display: grid;
  place-items: center;
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #ffffff66, transparent 42%), var(--pop-accent);
  box-shadow: 0 0 0 12px color-mix(in srgb, var(--pop-accent) 14%, transparent), 0 16px 30px color-mix(in srgb, var(--pop-accent) 40%, transparent);
  color: #ffffff;
}

.qp-pop__mark lucide-icon {
  width: 56px;
  height: 56px;
  stroke-width: 3;
}

.qp-pop__box h2 {
  margin: 10px 0 0;
  color: var(--pop-ink);
  font-size: clamp(1.9rem, 4.6vw, 3rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.qp-pop__box h2 em {
  color: var(--pop-accent);
  font-style: normal;
}

.qp-pop__main > p {
  max-width: 34em;
  margin: 0;
  color: #44516d;
  font-size: 1.08rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

/* Shared typography resets otherwise disable wrapping even inside a narrow
   dialog. Explanations and translated questions must be able to reflow. */
body#quiz-page .qp-pop__box :where(p, h2, h3, strong, span),
body#quiz-page #quiz-screen :where(#question-text, .qp-level h3, .qp-level > p) {
  overflow-wrap: anywhere !important;
  word-break: normal !important;
}

.qp-pop__gains {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
}

.qp-pop__gains[hidden] { display: none; }

.qp-gain {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--pop-accent) 16%, #ffffff);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.8);
  text-align: left;
}

.qp-gain--xp { border-color: #fde2c4; background: #fff8ef; }

.qp-gain img,
.qp-gain__ico {
  flex: none;
  width: 44px;
  height: 44px;
}

.qp-gain__ico {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #ffe8cf;
  color: #f2690d;
  font-size: 1.3rem;
}

.qp-gain > span:last-child { display: grid; min-width: 0; }
.qp-gain small { color: #44516d; font-size: 0.86rem; font-weight: 600; }
.qp-gain strong { color: var(--pop-accent-deep); font-size: 1.5rem; font-weight: 800; line-height: 1.15; }
.qp-gain--xp strong { color: #f2690d; }

.qp-pop__hint {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 18px;
  border: 1px solid color-mix(in srgb, var(--pop-accent) 22%, #ffffff);
  border-radius: 16px;
  background: color-mix(in srgb, var(--pop-accent) 9%, #ffffff);
  text-align: left;
}

.qp-pop__hint-ico {
  display: grid;
  place-items: center;
  flex: none;
  color: var(--pop-accent);
  font-size: 1.9rem;
}

.qp-pop__hint p {
  margin: 0;
  color: #44516d;
  font-size: 1rem;
  line-height: 1.45;
}

.qp-pop__hint strong { color: var(--pop-accent-deep); font-weight: 800; }

.qp-pop__go {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(100%, 420px);
  min-height: 62px;
  margin-top: 6px;
  padding: 0 28px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--pop-accent) 86%, #ffffff) 0%, var(--pop-accent-deep) 100%);
  box-shadow: 0 14px 28px color-mix(in srgb, var(--pop-accent) 38%, transparent);
  color: #ffffff;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
}

.qp-pop__go--plain {
  border: 2px solid #c9dafb;
  background: #ffffff;
  box-shadow: none;
  color: var(--pop-accent-deep);
}

.qp-pop__pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
}

.qp-pop__pair .qp-pop__go { width: 100%; padding: 0 12px; }

/* On wide screens the wrong-answer popup keeps a blue button. */
@media (min-width: 821px) {
  .qp-pop[data-kind="wrong"] .qp-pop__go {
    background: linear-gradient(180deg, #2a78ff 0%, #0b4fe0 100%);
    box-shadow: 0 14px 28px rgba(18, 87, 230, 0.36);
  }
}

@media (max-width: 820px) {
  .qp-pop__box {
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.7fr);
    gap: 12px;
    padding: 20px 18px 24px;
    border-radius: 26px;
  }

  /* The mascot and the mark share the top row; everything else runs below. */
  .qp-pop__main { display: contents; }
  .qp-pop__art { grid-column: 1; grid-row: 1; }
  .qp-pop__art img { max-height: 210px; }
  /* The tall drawing is cropped to head and shoulders by its own shape, so
     the face is never cut off however short the picture has to be. */
  .qp-pop__art--tall img {
    width: auto;
    height: 230px;
    max-height: none;
    aspect-ratio: 262 / 390;
    object-position: center top;
  }

  .qp-pop__mark {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
    justify-self: center;
    width: 86px;
    height: 86px;
    margin-bottom: 0;
  }

  .qp-pop__mark lucide-icon { width: 46px; height: 46px; }

  .qp-pop__box h2,
  .qp-pop__box > .qp-pop__main > p,
  .qp-answer-review,
  .qp-pop__gains,
  .qp-pop__hint,
  .qp-pop__go,
  .qp-pop__pair {
    grid-column: 1 / -1;
    justify-self: center;
  }

  .qp-pop__box h2 { margin-top: 0; text-align: center; }
  .qp-pop__main > p { font-size: 1rem; text-align: center; }
  .qp-pop__hint { padding: 12px 14px; }
  .qp-pop__hint p { font-size: 0.95rem; }
  .qp-pop__hint strong { display: block; }
  .qp-pop__go { min-height: 56px; font-size: 1.05rem; }
  .qp-pop__pair .qp-pop__go { grid-column: auto; }
  .qp-gain { gap: 8px; padding: 10px; }
  .qp-gain img, .qp-gain__ico { width: 36px; height: 36px; }
  .qp-gain strong { font-size: 1.25rem; }
}

/* Short screens: everything tightens so the popup fits without scrolling. */
@media (max-height: 760px) {
  .qp-pop__box { gap: 8px 20px; padding-block: 18px 20px; }
  .qp-pop__main { gap: 10px; }
  .qp-pop__art img { max-height: min(42dvh, 300px); }
  .qp-pop__mark { width: 78px; height: 78px; box-shadow: 0 0 0 8px color-mix(in srgb, var(--pop-accent) 14%, transparent); }
  .qp-pop__mark lucide-icon { width: 42px; height: 42px; }
  .qp-pop__box h2 { margin-top: 2px; font-size: clamp(1.6rem, 4vw, 2.3rem); }
  .qp-pop__main > p, .qp-pop__hint p { font-size: 0.95rem; }
  .qp-pop__hint, .qp-gain { padding: 9px 12px; }
  .qp-pop__go { min-height: 52px; margin-top: 2px; }
}

@media (max-height: 760px) and (max-width: 820px) {
  .qp-pop__art img { max-height: min(24dvh, 170px); }
  .qp-pop__art--tall img { height: min(29dvh, 205px); max-height: none; }
  .qp-pop__mark { margin-bottom: 8px; }
}

@media (max-width: 360px) {
  .qp-pop__box { padding: 16px 12px 18px; }
  .qp-pop__mark { width: 70px; height: 70px; }
  .qp-pop__mark lucide-icon { width: 38px; height: 38px; }
  .qp-pop__gains { gap: 8px; }
  .qp-gain { flex-direction: column; align-items: flex-start; }
}

/* Small phones: the mascot and mark shrink further so even the longest popup
   (a correct answer with a bonus note) fits. */
@media (max-height: 660px) and (max-width: 820px) {
  .qp-pop__box { gap: 6px 12px; padding: 14px 14px 16px; }
  .qp-pop__art img { max-height: min(19dvh, 118px); }
  .qp-pop__art--tall img { height: min(23dvh, 140px); max-height: none; }
  .qp-pop__mark { width: 58px; height: 58px; margin-bottom: 4px; }
  .qp-pop__mark lucide-icon { width: 32px; height: 32px; }
  .qp-pop__box h2 { font-size: 1.45rem; }
  .qp-pop__main > p, .qp-pop__hint p { font-size: 0.88rem; line-height: 1.35; }
  .qp-pop__hint { gap: 10px; padding: 8px 10px; }
  .qp-pop__hint-ico { font-size: 1.4rem; }
  .qp-gain { flex-direction: row; align-items: center; gap: 8px; padding: 6px 10px; }
  .qp-gain img, .qp-gain__ico { width: 30px; height: 30px; font-size: 1rem; }
  .qp-gain small { font-size: 0.74rem; }
  .qp-gain strong { font-size: 1.1rem; }
  .qp-pop__go { min-height: 48px; font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  .qp-pop.active .qp-pop__box { animation: none; }
  .modal.is-closing { display: none; animation: none; }
  #quiz-screen .qp-meter__fill { transition: none; }
}

/* =====================================================================
   Finish pass: the two older popups on the quiz page (level ready / replay
   and rank up) take the same finish as the answer popups: same card shape,
   type, button and colours. Markup and behaviour are unchanged, apart from
   the ready popup losing its corner close button.
   ===================================================================== */
#level-info-modal,
#rankup-modal {
  background: rgba(15, 27, 56, 0.62);
  overflow: hidden;
}

#level-info-modal .modal-content,
#rankup-modal .modal-content {
  position: relative;
  width: min(620px, 100%);
  /* older rules set their own limits with !important */
  max-height: calc(100dvh - 32px) !important;
  margin: auto !important;
  padding: 30px 34px 32px;
  border: 0 !important;
  border-radius: 30px;
  /* an older shared rule paints these cards grey with !important */
  background:
    radial-gradient(circle at 12% 0%, #d3e3ff, transparent 42%),
    radial-gradient(circle at 96% 100%, #d3e3ff, transparent 36%),
    linear-gradient(180deg, #ffffff 0%, #edf4ff 100%) !important;
  box-shadow: 0 34px 80px rgba(8, 20, 54, 0.4);
  color: #0d1b3e;
  text-align: center;
  overflow: hidden auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

#level-info-modal .modal-content::-webkit-scrollbar,
#rankup-modal .modal-content::-webkit-scrollbar { display: none; }

#level-info-modal.active .modal-content,
#rankup-modal.active .modal-content {
  animation: qp-pop-in 240ms cubic-bezier(.2, .7, .25, 1) both;
}

#level-info-modal .modal-content,
#level-info-modal .modal-content :where(p, span, strong, div),
#rankup-modal .modal-content,
#rankup-modal .modal-content :where(p, span, strong, div) {
  font-family: "Inter", "Segoe UI", Roboto, Arial, sans-serif;
}

#level-info-modal .modal-content :where(h2, .hero-kicker, .modal-notice-title, .metric-tile strong),
#rankup-modal .modal-content :where(h2, .hero-kicker, .rankup-track span) {
  font-family: "Manrope", "Inter", "Segoe UI", Roboto, Arial, sans-serif;
}

#level-info-modal .modal-content button,
#rankup-modal .modal-content button {
  font-family: "Manrope", "Inter", "Segoe UI", Roboto, Arial, sans-serif !important;
}

/* kicker pill */
#level-info-modal .hero-kicker,
#rankup-modal .hero-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  min-height: 34px;
  margin: 0 auto;
  padding: 0 16px;
  border-radius: 999px;
  background: #e2ecff;
  color: #1557f5;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#rankup-modal .hero-kicker {
  background: linear-gradient(180deg, #ffe08a 0%, #f6b93b 100%);
  color: #4a3200;
}

#level-info-modal .modal-content h2,
#rankup-modal .modal-content h2 {
  margin: 14px 0 0;
  color: #0d1b3e;
  font-size: clamp(1.7rem, 4.4vw, 2.4rem);
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -0.02em;
}

/* ---------- level ready / replay ---------- */
/* The thinking mascot looks over the top of the card. */
/* Shown as a bust: the top of the drawing, fading out at the chest. */
#level-info-modal .lv-mascot {
  display: block;
  width: 104px;
  height: 150px;
  object-fit: cover;
  object-position: 50% 0;
  margin: -6px auto 8px;
  background: none;
  -webkit-mask-image: linear-gradient(#000 62%, transparent 96%);
  mask-image: linear-gradient(#000 62%, transparent 96%);
  user-select: none;
}

#level-info-modal .modal-ready-copy {
  display: block;
  margin: 12px auto 0;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  color: #44516d;
  font-size: 1.05rem;
  line-height: 1.5;
}

#level-info-modal .modal-ready-copy strong {
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  color: #44516d;
  font-size: inherit;
  font-weight: 500;
  letter-spacing: 0;
}

#level-info-modal .modal-ready-actions {
  display: flex;
  justify-content: center;
  margin: 18px 0 0;
}

#level-info-modal .modal-ready-actions[hidden],
#level-info-modal .modal-notice-panel[hidden],
#level-info-modal .level-details-panel[hidden] { display: none; }

#level-info-modal #start-level-btn,
#rankup-modal #rankup-ok-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(100%, 420px);
  min-height: 60px;
  padding: 0 28px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #2a78ff 0%, #0b4fe0 100%);
  box-shadow: 0 14px 28px rgba(18, 87, 230, 0.36);
  color: #ffffff;
  font-size: 1.08rem;
  font-weight: 800;
  cursor: pointer;
}

#level-info-modal #start-level-btn:disabled { background: #c7d3ea; box-shadow: none; cursor: not-allowed; }

#level-info-modal .modal-notice-panel {
  margin: 20px 0 0;
  padding: 16px 18px;
  border: 1px solid #d6e4fb;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: none;
  text-align: left;
}

#level-info-modal .modal-notice-title {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin: 0 0 10px;
  color: #0a2569;
  font-size: 0.86rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#level-info-modal .modal-notice-list,
#level-info-modal .instruction-list {
  display: grid;
  gap: 10px;
}

#level-info-modal .modal-notice-item,
#level-info-modal .instruction-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
}

#level-info-modal :where(.modal-notice-item, .instruction-item, .modal-notice-title) lucide-icon {
  flex: none;
  width: 1.15em;
  height: 1.15em;
  margin-top: 0.15em;
  color: #1765f2;
}

#level-info-modal :where(.modal-notice-item, .instruction-item) p {
  margin: 0;
  color: #44516d;
  font-size: 0.95rem;
  font-weight: 400 !important;
  line-height: 1.5;
}

/* An older rule sets these lines in a large display face with !important. */
#level-info-modal #modal-notice-rules,
#level-info-modal .instruction-item p {
  color: #44516d !important;
  font-family: "Inter", "Segoe UI", Roboto, Arial, sans-serif !important;
  font-size: 0.95rem !important;
  font-weight: 400 !important;
  line-height: 1.5 !important;
  letter-spacing: 0 !important;
}

#level-info-modal .level-details-panel { margin-top: 18px; text-align: left; }

#level-info-modal .level-info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

#level-info-modal .metric-tile {
  padding: 12px 14px;
  border: 1px solid #d6e4fb;
  border-radius: 14px;
  background: #ffffff;
}

#level-info-modal .metric-tile span { color: #5c6b8a; font-size: 0.82rem; }
#level-info-modal .metric-tile strong { display: block; color: #0d1b3e; font-size: 1.15rem; font-weight: 800; }

/* ---------- rank up ---------- */
#rankup-modal #rankup-copy {
  max-width: 32em;
  margin: 10px auto 0;
  color: #44516d;
  font-size: 1.02rem;
  line-height: 1.5;
}

#rankup-modal .rankup-badge-showcase {
  display: grid;
  justify-items: center;
  gap: 14px;
  margin: 14px 0 20px;
}

#rankup-modal .rankup-track {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 0 22px;
  border: 1px solid #d6e4fb;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(31, 72, 150, 0.1);
  font-size: 1rem;
}

#rankup-modal .rankup-from { color: #5c6b8a; font-weight: 700; }
#rankup-modal .rankup-to { color: #1557f5; font-weight: 800; }
#rankup-modal .rankup-track lucide-icon { color: #f6b93b; }

/* The sparks behind the card use the badge colours. */
#rankup-modal .rankup-burst span {
  width: 10px;
  height: 10px;
  background: linear-gradient(135deg, #ffd45c, #5aa2ff);
}

@media (max-width: 700px) {
  #level-info-modal .modal-content,
  #rankup-modal .modal-content {
    padding: 22px 18px 24px;
    border-radius: 26px;
  }

  #level-info-modal .lv-mascot { width: 90px; height: 130px; }
  #level-info-modal #start-level-btn, #rankup-modal #rankup-ok-btn { min-height: 56px; font-size: 1.02rem; }
  #level-info-modal .modal-notice-panel { padding: 14px; }
  #level-info-modal :where(.modal-notice-item, .instruction-item) p { font-size: 0.9rem; }
}

@media (max-height: 700px) {
  #level-info-modal .lv-mascot { width: 66px; height: 96px; }
  #level-info-modal .modal-content h2, #rankup-modal .modal-content h2 { font-size: 1.6rem; }
  #level-info-modal .modal-notice-panel { margin-top: 14px; padding: 12px 14px; }
  #level-info-modal .modal-notice-list { gap: 6px; }
  #level-info-modal :where(.modal-notice-item, .instruction-item) p { font-size: 0.86rem; line-height: 1.4; }
  #level-info-modal #start-level-btn, #rankup-modal #rankup-ok-btn { min-height: 50px; }
  #rankup-modal .rankup-badge-showcase { margin: 8px 0 14px; gap: 10px; }
}

/* Short phones: the mascot steps aside and the notes tighten so the popup fits. */
@media (max-height: 700px) and (max-width: 700px) {
  #level-info-modal .modal-content, #rankup-modal .modal-content { padding: 16px 14px 16px; }
  #level-info-modal .lv-mascot { display: none; }
  #level-info-modal .modal-content h2, #rankup-modal .modal-content h2 { margin-top: 8px; font-size: 1.45rem; }
  #level-info-modal .modal-ready-copy { margin-top: 6px; font-size: 0.92rem; }
  #level-info-modal .modal-ready-actions { margin-top: 10px; }
  #level-info-modal .modal-notice-panel { margin-top: 10px; padding: 10px 12px; }
  #level-info-modal .modal-notice-title { margin-bottom: 6px; font-size: 0.78rem; }
  #level-info-modal #modal-notice-rules,
  #level-info-modal .instruction-item p,
  #level-info-modal :where(.modal-notice-item, .instruction-item) p { font-size: 0.82rem !important; line-height: 1.35 !important; }
  #rankup-modal #rankup-copy { font-size: 0.92rem; }
  #rankup-modal .rk-stage { height: 160px; }
  #rankup-modal .rk-crest { height: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  #level-info-modal.active .modal-content,
  #rankup-modal.active .modal-content,
  #rankup-modal .rankup-burst span { animation: none; }
}
