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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Avenir Next", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #87c5f0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app, #app canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 14px;
  right: 14px;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 20;
}

#coin-counter {
  --hud-scale: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
  transform: scale(var(--hud-scale));
  transform-origin: right center;
}

#coin-icon {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.7));
}

#coin-count {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 42px;
}
.sprite-digit {
  background-repeat: no-repeat;
  display: inline-block;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
}

/* ---------- Score (top center) ---------- */
#score-counter {
  --hud-scale: 1;
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) scale(var(--hud-scale));
  transform-origin: center center;
  z-index: 20;
  display: flex;
  align-items: center;
  height: 48px;
  transition: transform 0.45s cubic-bezier(0.34, 1.7, 0.4, 1);
}
#score-count {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  min-height: 42px;
}
#score-counter.pop { animation: scorePop 0.3s ease; }
#score-counter.beating {
  animation: none;
  transform: translateX(-50%) scale(calc(var(--hud-scale) * 2));
}

#coin-counter.pop { animation: coinPop 0.3s ease; }

/* ---------- Star counter (top left) ---------- */
#star-counter {
  --hud-scale: 1;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 48px;
  transform: scale(var(--hud-scale));
  transform-origin: left center;
}
#star-icon {
  width: 40px;
  height: 40px;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.7));
}
#star-count {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 42px;
}
#star-counter.star-pop { animation: starPop 0.55s ease; }
@keyframes starPop {
  0% { transform: scale(var(--hud-scale)); }
  45% { transform: scale(calc(var(--hud-scale) * 2)); }
  100% { transform: scale(var(--hud-scale)); }
}

/* spinning star collect — fixed overlay, sprite centered on (left, top) */
#star-fly {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  z-index: 140;
  pointer-events: none;
  opacity: 0;
}
#star-fly-sprite {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  background-repeat: no-repeat;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,0.45));
  will-change: transform, width, height, background-position;
}
@keyframes coinPop {
  0% { transform: scale(var(--hud-scale)); }
  50% { transform: scale(calc(var(--hud-scale) * 1.25)); }
  100% { transform: scale(var(--hud-scale)); }
}
@keyframes scorePop {
  0% { transform: translateX(-50%) scale(var(--hud-scale)); }
  50% { transform: translateX(-50%) scale(calc(var(--hud-scale) * 1.25)); }
  100% { transform: translateX(-50%) scale(var(--hud-scale)); }
}
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* phone: shrink SCORE + coin count */
@media (max-width: 767px) {
  #score-counter { --hud-scale: 0.7; }
  #coin-counter { --hud-scale: 0.7; }
}

/* desktop: enlarge stars + SCORE + coin count */
@media (min-width: 768px) {
  #star-counter { --hud-scale: 1.4; }
  #score-counter { --hud-scale: 1.4; }
  #coin-counter { --hud-scale: 1.4; }
}

#sound-btn {
  background: rgba(20, 32, 48, 0.55);
  backdrop-filter: blur(6px);
  border: none;
  border-radius: 999px;
  padding: 0;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#sound-btn img {
  width: 22px;
  height: 22px;
  display: block;
}
#sound-btn:active { transform: scale(0.95); }

/* ---------- Banner ---------- */
#banner {
  position: fixed;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 32, 48, 0.7);
  backdrop-filter: blur(8px);
  color: #ffd24a;
  font-size: clamp(22px, 5vw, 40px);
  font-weight: 800;
  padding: 18px 36px;
  border-radius: 18px;
  border: 3px solid #ffd24a;
  z-index: 30;
  text-align: center;
  animation: bannerIn 0.5s ease;
}
@keyframes bannerIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-30px) scale(0.8); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* ---------- Hint ---------- */
#hint {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  background: rgba(20, 32, 48, 0.45);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 10;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* ---------- Mobile joystick ---------- */
#joystick {
  position: fixed;
  left: 26px;
  bottom: 26px;
  z-index: 25;
}

#joystick-base {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(4px);
  position: relative;
}

#joystick-knob {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, #c9d6e8);
  border: 2px solid rgba(255,255,255,0.8);
  box-shadow: 0 3px 8px rgba(0,0,0,0.3);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#jump-btn {
  position: fixed;
  right: 30px;
  bottom: 40px;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  z-index: 25;
  font-size: 18px;
  font-weight: 800;
  color: #7a4d00;
  background: radial-gradient(circle at 35% 30%, #ffe9a3, #ffc93c 60%, #eda800);
  border: 3px solid rgba(255,255,255,0.75);
  box-shadow: 0 5px 14px rgba(0,0,0,0.35);
  cursor: pointer;
}
#jump-btn:active { transform: scale(0.92); }

/* ---------- Start overlay ---------- */
#start-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 24, 40, 0.45);
  backdrop-filter: blur(5px);
}

#start-card {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 24px;
  padding: 36px 44px;
  text-align: center;
  max-width: min(420px, 88vw);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}

#start-card h1 {
  font-size: clamp(26px, 6vw, 36px);
  color: #1d3557;
  margin-bottom: 8px;
}

.subtitle {
  color: #457b9d;
  margin-bottom: 22px;
  font-size: 15px;
}

#loading-wrap { margin-bottom: 20px; }

#loading-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #dde7f0;
  overflow: hidden;
  margin-bottom: 8px;
}

#loading-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd24a, #ff9f1c);
  transition: width 0.2s ease;
}

#loading-text {
  font-size: 13px;
  color: #6b7f95;
}

#start-btn {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #2ec4b6, #189a8f);
  border: none;
  border-radius: 999px;
  padding: 14px 52px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(24, 154, 143, 0.45);
  transition: transform 0.1s ease;
}
#start-btn:disabled {
  background: #a9bfc9;
  box-shadow: none;
  cursor: wait;
}
#start-btn:not(:disabled):hover { transform: scale(1.05); }
#start-btn:not(:disabled):active { transform: scale(0.97); }

.controls-note {
  margin-top: 18px;
  font-size: 12.5px;
  line-height: 1.7;
  color: #8aa0b4;
}

@keyframes talkPulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.08); }
}
@keyframes okPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* ---------- Drive button ---------- */
#drive-btn {
  position: fixed;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 26;
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #48dbfb, #0abde3);
  border: 3px solid rgba(255,255,255,0.85);
  border-radius: 999px;
  padding: 14px 34px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(10, 189, 227, 0.55);
  animation: talkPulse 1.1s ease-in-out infinite;
}
#drive-btn.exit {
  background: linear-gradient(180deg, #ff8f5e, #ff6b35);
  box-shadow: 0 6px 18px rgba(255, 107, 53, 0.55);
  animation: none;
}
#drive-btn:active { transform: translateX(-50%) scale(0.94); animation: none; }

/* ---------- Quiz overlay ---------- */
#quiz-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-start; /* card hugs the top, just under the HUD */
  justify-content: center;
  padding-top: 76px; /* never covers score / coins / sound icon */
  background: transparent; /* keep the 3D world clear and bright */
  backdrop-filter: none;
  pointer-events: none; /* HUD (sound button) stays clickable */
  overscroll-behavior: none;
  touch-action: none; /* block finger-drag / rubber-band scroll on mobile */
}

#quiz-card, #quiz-result {
  width: min(1080px, 93vw);
  max-height: 92vh;
  overflow: hidden; /* no finger-drag / scroll on quiz UI; also clips confetti */
  overscroll-behavior: none;
  touch-action: none;
  background: linear-gradient(160deg, #fffdf5 0%, #fff3fb 100%);
  border-radius: 28px;
  border: 1px solid #ffd24a;
  padding: 26px 28px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.4);
  text-align: center;
  animation: cardIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: auto;
  position: relative; /* anchor for confetti canvas */
}
#quiz-card {
  /* mobile: fixed 740px; cap = viewport - 76px top HUD - 24px bottom gap */
  height: min(740px, calc(100dvh - 76px - 24px));
  max-height: calc(100dvh - 76px - 24px);
  background: linear-gradient(180deg, rgba(0,0,120,0.6) 0%, rgba(255,243,100,0.1) 100%);
  padding-bottom: 88px; /* room for 解說 / 下一題 / 睇結果 at the bottom */
}
/* while leave-confirm is open: quiz card (and all its buttons) can't be pressed */
#quiz-overlay.confirm-open #quiz-card {
  pointer-events: none;
}
/* desktop browsers: taller card (mobile keeps the 740px above) */
@media (min-width: 768px) {
  #quiz-card {
    height: min(980px, calc(100dvh - 76px - 24px));
  }
}

/* hide mobile controls + keep world clean while quizzing */
body.quiz-mode #joystick, body.quiz-mode #jump-btn { display: none !important; }
body.quiz-mode {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

/* gray circular X button, top-right of the card */
#quiz-close-btn {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 8px; /* square with slightly rounded corners */
  border: 3px solid #9aa4b0;
  background: rgba(255,255,255,0.75);
  color: #9aa4b0;
  font-size: 17px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
#quiz-close-btn:hover {
  transform: scale(1.1);
  border-color: #ff8f1f; /* orange frame on hover */
  color: #ff8f1f;
}

#quiz-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  margin-bottom: 8px;
}

/* leave-quiz confirm: full-viewport gray overlay, dialog centered on screen */
#quiz-confirm {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(70, 74, 82, 0.55); /* gray dim layer over whole quiz */
  border-radius: 0;
  pointer-events: auto;
  touch-action: none;
}
#quiz-confirm-box {
  background: #fff;
  border: 3px solid #ffd24a;
  border-radius: 20px;
  padding: 22px 28px 24px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.35);
  animation: cardIn 0.25s ease;
  pointer-events: auto;
  max-width: min(360px, 88vw);
}
#quiz-confirm-text {
  font-size: clamp(17px, 4vw, 21px);
  font-weight: 800;
  color: #2d3a4a;
  margin-bottom: 16px;
}
#quiz-confirm-row { display: flex; gap: 14px; justify-content: center; }
#quiz-confirm-row button {
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  padding: 9px 34px;
  cursor: pointer;
  color: #fff;
}
#quiz-confirm-yes { /* not the default — gray */
  background: linear-gradient(180deg, #b7bec7, #9aa4b0);
  box-shadow: 0 3px 0 #79828d;
}
#quiz-confirm-no { /* the default — orange */
  background: linear-gradient(180deg, #ffb13d, #ff8f1f);
  box-shadow: 0 3px 0 #d96f00, 0 6px 16px rgba(255, 143, 31, 0.45);
  outline: 3px solid rgba(255, 177, 61, 0.55);
  animation: okPulse 1.6s infinite;
}
#quiz-confirm-row button:active { transform: translateY(2px); box-shadow: none; }

/* tick / x marks hanging off the right side of answer buttons */
.quiz-opt .mark {
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  height: 150%; /* taller than the answer box */
  width: auto;
  z-index: 2;
  pointer-events: none;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.3));
  animation: markPop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes markPop {
  from { transform: translateY(-50%) scale(0); }
  to { transform: translateY(-50%) scale(1); }
}

/* big reaction characters as card background, behind the text */
.quiz-expr {
  position: absolute;
  z-index: 0;
  pointer-events: none;
  background-repeat: no-repeat;
  opacity: 0.92;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15));
  transform-origin: bottom center; /* sway pivots from bottom-middle */
}
.quiz-expr.expr-alive {
  animation:
    exprPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both,
    exprSway 2.4s ease-in-out 0.5s infinite;
}
@keyframes exprPop {
  0%   { transform: scale(0.55) rotate(0deg); }
  55%  { transform: scale(1.18) rotate(0deg); } /* brief overshoot */
  100% { transform: scale(1) rotate(0deg); }
}
@keyframes exprSway {
  0%, 100% { transform: rotate(-5deg); }
  50%      { transform: rotate(5deg); }
}
/* ===== Desktop browser: character X / Y positions ===== */
#quiz-girl {
  left: 172px;    /* X: distance from LEFT  (↑ = move right) */
  bottom: -10px;      /* Y: distance from BOTTOM (↑ = move up) */
}
#quiz-cat {
  right: 172px;   /* X: distance from RIGHT (↑ = move left) */
  bottom: -10px;      /* Y: distance from BOTTOM (↑ = move up) */
}
#quiz-card > *:not(.quiz-expr):not(.quiz-confetti) { position: relative; z-index: 1; }

/* confetti canvas stays inside the dialog; overflow:hidden on the card clips it */
#quiz-card > canvas.quiz-confetti,
#quiz-result > canvas.quiz-confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
  border-radius: inherit;
}

/* ===== Mobile browser (≤560px): character X / Y positions ===== */
@media (max-width: 560px) {
  #quiz-girl {
    left: -120px; /* X: distance from LEFT  (↑ = move right) */
    bottom: -10px;    /* Y: distance from BOTTOM (↑ = move up) */
  }
  #quiz-cat {
    right: -60px; /* X: distance from RIGHT (↑ = move left) */
    bottom: -10px;    /* Y: distance from BOTTOM (↑ = move up) */
  }
  .quiz-expr.expr-alive {
    animation:
      exprPopMobile 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both,
      exprSwayMobile 2.4s ease-in-out 0.5s infinite;
  }
  @keyframes exprPopMobile {
    0%   { transform: scale(0.4) rotate(0deg); }
    55%  { transform: scale(0.85) rotate(0deg); }
    100% { transform: scale(0.72) rotate(0deg); }
  }
  @keyframes exprSwayMobile {
    0%, 100% { transform: scale(0.72) rotate(-5deg); }
    50%      { transform: scale(0.72) rotate(5deg); }
  }
}
/* ---------- Cat dialogues (kitten + Bubu speech bubbles) ---------- */
.cat-name {
  background: #ffb3c2;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  border-radius: 999px;
  padding: 2px 14px;
  margin-top: -22px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
}
.cat-text {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.45;
}
.cat-ok-btn {
  background: linear-gradient(180deg, #ff8fab, #ff6d94);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 800;
  font-family: inherit;
  padding: 8px 30px;
  cursor: pointer;
  box-shadow: 0 3px 0 #d94f78;
  animation: okPulse 1.6s infinite;
}
.cat-ok-btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

/* shared world-anchored speech bubble shell */
#npc-dialog,
#kitten-dialog {
  position: fixed;
  inset: 0;
  z-index: 24;
  pointer-events: none;
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0;
  max-width: none;
  transform: none;
  animation: none;
  display: block;
}
#npc-bubble,
#kitten-bubble {
  position: absolute;
  left: 0;
  top: 0;
  /* leave room below for the speech-tail triangle */
  transform: translate(-50%, calc(-100% - 22px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.96);
  color: #4a3b31;
  border-radius: 22px;
  padding: 18px 26px 20px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  max-width: min(92vw, 520px);
  min-width: min(78vw, 320px);
  text-align: center;
  pointer-events: none;
  animation: speechBubbleIn 0.25s ease;
}
@keyframes speechBubbleIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
#npc-bubble::before,
#npc-bubble::after,
#kitten-bubble::before,
#kitten-bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
}
#npc-bubble::after,
#kitten-bubble::after {
  bottom: -20px;
  transform: translateX(-50%);
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-top: 20px solid;
}
#npc-bubble::before,
#kitten-bubble::before {
  bottom: -15px;
  transform: translateX(-50%);
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 16px solid rgba(255, 255, 255, 0.96);
  z-index: 1;
}
#npc-bubble .cat-name,
#kitten-bubble .cat-name {
  font-size: clamp(18px, 4vw, 24px);
  font-weight: 900;
  padding: 6px 22px;
  margin-top: -32px;
}
#npc-bubble .cat-text,
#kitten-bubble .cat-text {
  font-size: clamp(20px, 4.6vw, 28px);
  font-weight: 800;
  line-height: 1.5;
}
#npc-ok-btn,
#kitten-ok-btn {
  position: relative;
  left: auto;
  top: auto;
  transform: none;
  pointer-events: auto;
  font-size: clamp(18px, 4vw, 22px);
  padding: 12px 40px;
  margin-top: 4px;
  animation: speechOkPulse 1.6s infinite;
}
@keyframes speechOkPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
#npc-ok-btn:active,
#kitten-ok-btn:active {
  transform: translateY(2px) scale(1);
  box-shadow: none;
  animation: none;
}

/* Bubu — purple */
#npc-bubble { border: 3px solid #b39dfb; }
#npc-bubble::after { border-top-color: #b39dfb; }
#npc-bubble .cat-name { background: #a78bfa; }
#npc-ok-btn {
  background: linear-gradient(180deg, #b39dfb, #8b5cf6);
  box-shadow: 0 4px 0 #6d3fd4;
}

/* Kitten — pink */
#kitten-bubble { border: 3px solid #ffb3c2; }
#kitten-bubble::after { border-top-color: #ffb3c2; }
#kitten-bubble .cat-name { background: #ff8fab; }
#kitten-ok-btn {
  background: linear-gradient(180deg, #ff8fab, #ff6d94);
  box-shadow: 0 4px 0 #d94f78;
}

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

#quiz-header {
  text-align: left;
  margin-bottom: 14px;
}

#quiz-title {
  font-size: clamp(24px, 5vw, 32px);
  font-weight: 900;
  color: #ffe9a0; /* light yellow — change this to retint the title */
  -webkit-text-fill-color: #ffe9a0;
  background: none;
  text-shadow: none;
  filter: none;
  margin-bottom: 0;
  text-align: left;
  line-height: 1.1;
}

#quiz-qnum {
  display: inline-block;
  background: #ff9f1a;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  border-radius: 999px;
  padding: 5px 16px;
  margin-bottom: 0;
  text-align: left;
}

#quiz-question {
  font-size: clamp(24px, 5vw, 32px);
  font-weight: 900;
  color: #ffffff;
  line-height: 1.5;
  margin-bottom: 12px;
  text-align: left;
  text-shadow: 0 2px 0 rgba(0,0,0,0.55), 0 4px 10px rgba(0,0,0,0.55), 0 8px 22px rgba(0,0,0,0.45);
}

/* ----- countdown energy bar under the question ----- */
#quiz-timer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  position: relative;
}
#quiz-timer-bar {
  flex: 1 1 auto;
  position: relative;
  min-width: 0;
}
#quiz-perfect {
  position: absolute;
  right: 0;
  top: 0;
  transform: translateY(calc(-100% - 4px)); /* top-right of the energy bar */
  transform-origin: right bottom; /* grow leftward so it stays on the bar's right edge */
  z-index: 4;
  padding: 0;
  border: none;
  background: transparent;
  color: #ffffff;
  font-size: clamp(16px, 3.6vw, 22px);
  font-weight: 900;
  white-space: nowrap;
  pointer-events: none;
  max-width: 100%;
  text-align: right;
  text-shadow:
    0 2px 0 #000,
    0 3px 8px rgba(0,0,0,0.75),
    0 0 8px var(--timer-glow, #1e90ff),
    0 0 16px var(--timer-glow, #1e90ff);
  animation: perfectPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  transition: transform 0.45s cubic-bezier(0.34, 1.7, 0.4, 1);
}
#quiz-perfect.beating {
  animation: none;
  /* +50% size while counting; origin right keeps it aligned to the bar */
  transform: translateY(calc(-100% - 4px)) scale(1.5);
}
@keyframes perfectPop {
  from { transform: translateY(calc(-100% - 4px)) scale(0.6); opacity: 0; }
  to   { transform: translateY(calc(-100% - 4px)) scale(1); opacity: 1; }
}

/* score popup on the correct answer (top-right) — green glow cloud */
.quiz-pts {
  position: absolute;
  top: -10px;
  right: 10px;
  z-index: 4;
  font-size: clamp(20px, 4.2vw, 28px);
  font-weight: 900;
  color: #ffffff;
  text-shadow:
    0 2px 0 #000,
    0 3px 6px rgba(0,0,0,0.85),
    0 0 8px rgba(60, 220, 100, 0.95),
    0 0 18px rgba(40, 200, 80, 0.9),
    0 0 32px rgba(30, 180, 70, 0.75);
  pointer-events: none;
  white-space: nowrap;
  transform-origin: center center;
  animation: ptsPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  transition: transform 0.45s cubic-bezier(0.34, 1.7, 0.4, 1);
  /* soft green light cloud behind the number */
  filter: drop-shadow(0 0 6px rgba(50, 220, 90, 0.95))
          drop-shadow(0 0 16px rgba(40, 200, 80, 0.7));
}
.quiz-pts::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 140%;
  height: 180%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(
    ellipse at center,
    rgba(90, 255, 140, 0.55) 0%,
    rgba(50, 220, 100, 0.28) 45%,
    rgba(40, 180, 80, 0) 72%
  );
  z-index: -1;
  pointer-events: none;
  animation: ptsGlowPulse 1.4s ease-in-out infinite;
}
.quiz-pts.beating {
  animation: none;
  transform: scale(2); /* +100% size while counting */
}
.quiz-pts.beating::before {
  width: 160%;
  height: 200%;
  background: radial-gradient(
    ellipse at center,
    rgba(100, 255, 150, 0.65) 0%,
    rgba(50, 220, 100, 0.35) 45%,
    rgba(40, 180, 80, 0) 72%
  );
}
@keyframes ptsPop {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
@keyframes ptsGlowPulse {
  0%, 100% { opacity: 0.85; transform: translate(-50%, -50%) scale(1); }
  50%      { opacity: 1;    transform: translate(-50%, -50%) scale(1.12); }
}
#quiz-timer-icon {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  background: #ffffff;
  -webkit-mask: url('assets/timer.png') center / contain no-repeat;
  mask: url('assets/timer.png') center / contain no-repeat;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.45));
}
#quiz-timer-track {
  width: 100%;
  height: 16px;
  border-radius: 999px;
  border: 1px solid #ffffff;
  background: rgba(0, 0, 0, 0.28);
  overflow: hidden;
  box-sizing: border-box;
  /* glow color follows the fill (set via --timer-glow) */
  box-shadow: 0 0 8px var(--timer-glow, #1e90ff), 0 0 18px var(--timer-glow, #1e90ff);
  transition: box-shadow 0.25s ease;
}
#quiz-timer-fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  transform-origin: left center;
  background: linear-gradient(90deg, #5ec8ff, #1e90ff 55%, #0b6fd4);
  transition: width 0.05s linear, background 0.25s ease;
}
#quiz-timer.t-blue  { --timer-glow: #1e90ff; }
#quiz-timer.t-blue  #quiz-timer-fill {
  background: linear-gradient(90deg, #7ad4ff, #1e90ff 55%, #0b6fd4);
}
#quiz-timer.t-green { --timer-glow: #20bf6b; }
#quiz-timer.t-green #quiz-timer-fill {
  background: linear-gradient(90deg, #6eef9f, #20bf6b 55%, #128a4a);
}
#quiz-timer.t-yellow { --timer-glow: #f7b731; }
#quiz-timer.t-yellow #quiz-timer-fill {
  background: linear-gradient(90deg, #ffe066, #f7b731 55%, #d99400);
}
#quiz-timer.t-orange { --timer-glow: #ff9f1a; }
#quiz-timer.t-orange #quiz-timer-fill {
  background: linear-gradient(90deg, #ffc56e, #ff9f1a 55%, #e07800);
}
#quiz-timer.t-red   { --timer-glow: #ff3b3b; }
#quiz-timer.t-red   #quiz-timer-fill {
  background: linear-gradient(90deg, #ff7a7a, #ff3b3b 55%, #d41212);
}
#quiz-timer.t-flash #quiz-timer-track {
  animation: timerFlash 0.45s ease-in-out infinite;
}
@keyframes timerFlash {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px var(--timer-glow), 0 0 18px var(--timer-glow); }
  50%      { opacity: 0.35; box-shadow: 0 0 14px var(--timer-glow), 0 0 28px var(--timer-glow); }
}

#quiz-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 6px;
}

.quiz-opt {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  font-size: clamp(19px, 4.4vw, 26px);
  font-weight: 900;
  color: #ffffff;
  text-shadow: 0 2px 0 rgba(0,0,0,0.55), 0 4px 10px rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 18px;
  padding: 13px 18px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.12);
  /* button background is 20% via the translucent c0-c3 gradients below,
     so the white text + letter badges stay at full opacity */
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.15s ease;
}
.quiz-opt:hover:not(:disabled),
.quiz-opt.selected:not(:disabled) {
  transform: scale(1.01);
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
  border-color: #ff9f1a; /* orange frame — same for A/B/C/D */
}
.quiz-opt:disabled { cursor: default; }

.quiz-opt .opt-letter {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ff9f1a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
  opacity: 1;
}

.quiz-opt.c0 { background: linear-gradient(90deg, rgba(0,0,100,0.3), rgba(255,215,110,0.1)); }
.quiz-opt.c1 { background: linear-gradient(90deg, rgba(0,0,100,0.3), rgba(156,236,150,0.1)); }
.quiz-opt.c2 { background: linear-gradient(90deg, rgba(0,0,100,0.3), rgba(255,179,212,0.1)); }
.quiz-opt.c3 { background: linear-gradient(90deg, rgba(0,0,100,0.3), rgba(163,209,255,0.1)); }

/* vibrant letter badges — one vivid colour per option */
.quiz-opt.c0 .opt-letter { background: #ff9f1a; }
.quiz-opt.c1 .opt-letter { background: #20bf6b; }
.quiz-opt.c2 .opt-letter { background: #ff4d94; }
.quiz-opt.c3 .opt-letter { background: #1e90ff; }

.quiz-opt.correct {
  background: linear-gradient(90deg, rgba(0,255,0,0.5) , rgba(0,200,0,0)) !important;
  color: #fff;
  animation: correctPulse 0.6s ease;
}
.quiz-opt.correct .opt-letter { background: #0a8f4d; color:#fff ; }
@keyframes correctPulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.quiz-opt.wrong {
  background: linear-gradient(90deg, rgba(255,20,20,0.5), rgba(255,0,0,0.1)) !important;
  color: #fff;
  animation: shake 0.45s ease;
}
.quiz-opt.wrong .opt-letter { background: #d63031; color: #fff; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-9px); }
  40% { transform: translateX(9px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

.quiz-opt.dim { opacity: 0.45; filter: grayscale(0.4); }

#quiz-feedback {
  margin-top: 14px;
  border-radius: 16px;
  padding: 13px 16px;
  font-size: clamp(15px, 3.4vw, 18px);
  font-weight: 700;
  line-height: 1.55;
  animation: feedbackIn 0.35s ease;
}
@keyframes feedbackIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
#quiz-feedback.good { background: #d8ffd8; color: #0a8f4d; border: 2px solid #2ed573; }
#quiz-feedback.bad { background: #ffe3e3; color: #c0392b; border: 2px solid #ff6b6b; }

/* 解說 / 下一題 / 睇結果 — inside the quiz card, bottom-center with padding */
#quiz-card > #quiz-explain-btn,
#quiz-card > #quiz-next-btn {
  position: absolute;
  bottom: 28px; /* padding from the card's bottom edge */
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: inline-block;
  margin: 0;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: clamp(20px, 4.6vw, 26px);
  font-weight: 900;
  padding: 14px 52px;
  cursor: pointer;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,0.4), 0 3px 8px rgba(0,0,0,0.45);
  background: linear-gradient(180deg, #ffb13d, #ff8f1f);
  box-shadow: 0 5px 0 #d96f00, 0 12px 24px rgba(255, 143, 31, 0.5);
  /* must keep translateX(-50%) in the pulse, or left:50% looks shifted right */
  animation: quizBtnPulse 1.4s infinite;
  pointer-events: auto;
}
#quiz-card > #quiz-explain-btn:active,
#quiz-card > #quiz-next-btn:active {
  transform: translateX(-50%) translateY(3px);
  box-shadow: 0 2px 0 #d96f00, 0 4px 10px rgba(255, 143, 31, 0.35);
  animation: none;
}
@keyframes quizBtnPulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50%      { transform: translateX(-50%) scale(1.08); }
}
#quiz-expl {
  margin-top: 14px;
  margin-bottom: 72px; /* leave room so content isn't covered by the bottom button */
  border-radius: 16px;
  padding: 14px 18px;
  font-size: clamp(20px, 6.8vw, 24px);
  font-weight: 700;
  line-height: 1.65;
  background: #e8f2ff;
  color: #24435e;
  border: 2px solid #5fa8ff;
  text-align: left;
  animation: feedbackIn 0.35s ease;
}

/* ---------- Quiz result ---------- */
#result-title {
  font-size: clamp(26px, 6vw, 36px);
  font-weight: 900;
  color: #5f27cd;
  margin-bottom: 10px;
}

#result-stars {
  font-size: 52px;
  letter-spacing: 8px;
  margin-bottom: 12px;
  min-height: 70px;
}
#result-stars .star {
  display: inline-block;
  color: #dfe6ee;
  transform: scale(1);
}
#result-stars .star.lit {
  color: #ffd24a;
  text-shadow: 0 0 14px rgba(255, 210, 74, 0.9), 0 3px 0 #d99a12;
  animation: starPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes starPop {
  from { transform: scale(0) rotate(-40deg); }
  to { transform: scale(1) rotate(0); }
}

#result-msg {
  font-size: clamp(17px, 4vw, 21px);
  font-weight: 800;
  color: #2d3a4a;
  margin-bottom: 22px;
  line-height: 1.5;
}

#result-btns {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}
#result-btns button {
  font-size: 18px;
  font-weight: 800;
  border: none;
  border-radius: 999px;
  padding: 13px 32px;
  cursor: pointer;
  transition: transform 0.1s ease;
}
#result-btns button:active { transform: scale(0.95); }
#quiz-again {
  color: #fff;
  background: linear-gradient(180deg, #ff9f1c, #f97e00);
  box-shadow: 0 6px 16px rgba(249, 126, 0, 0.45);
}
#quiz-close {
  color: #fff;
  background: linear-gradient(180deg, #2ec4b6, #189a8f);
  box-shadow: 0 6px 16px rgba(24, 154, 143, 0.45);
}
