/* ═══════════════════════════════════════════════════════════════
   components.css — Reusable UI components for Emma's games.

   Depends on: core.css (for @keyframes and base vars),
               theme-*.css (for all --theme-* variable values).

   All colour values in this file use --theme-* variables.
   The only exceptions are the four answer-button colours (A–D),
   the feedback overlay correct/wrong backgrounds, and --correct /
   --wrong from core.css — these are universal across all games.

   Tablet / touch sizing:
     • min-height: 44px on all interactive elements
     • 3-column stage-card grid collapses to 1-column at ≤640px
     • Answer button grid collapses to 1-column at ≤480px
═══════════════════════════════════════════════════════════════ */

/* ── HOME BUTTON ───────────────────────────────────────────────
   Injected into <body> by game-shell.js on initGame().
   Fixed, centred at the top so it overlays all screens.
────────────────────────────────────────────────────────────── */
.home-btn {
  position:        fixed;
  top:             0.75rem;
  left:            50%;
  transform:       translateX(-50%);
  z-index:         10;
  display:         flex;
  align-items:     center;
  gap:             0.35rem;
  font-family:     var(--theme-font-body);
  font-weight:     800;
  font-size:       0.88rem;
  padding:         0.5rem 1.2rem;
  min-height:      44px;
  min-width:       44px;
  background:      rgba(0,0,0,0.45);
  color:           var(--theme-accent-light);
  border:          1.5px solid var(--theme-border);
  border-radius:   50px;
  text-decoration: none;
  backdrop-filter: blur(6px);
  transition:      background 0.2s, border-color 0.2s, color 0.2s;
  white-space:     nowrap;
}
.home-btn:hover {
  background:   rgba(0,0,0,0.65);
  border-color: var(--theme-accent);
  color:        var(--theme-highlight);
}

/* ══════════════════════════════════════════════════════════════
   WELCOME SCREEN
══════════════════════════════════════════════════════════════ */

.game-character {
  font-size:      clamp(4rem, 12vw, 7rem);
  display:        block;
  margin-bottom:  0.4rem;
  animation:      characterBounce 2s ease-in-out infinite;
  filter:         drop-shadow(0 0 20px rgba(255,180,0,0.6));
}

.game-title {
  font-family:     var(--theme-font-display);
  font-size:       clamp(2.2rem, 7vw, 4.5rem);
  letter-spacing:  3px;
  color:           var(--theme-highlight);
  line-height:     1;
  /* text-shadow set per theme — theme-*.css overrides .game-title */
}

.game-subtitle {
  font-size:    1.1rem;
  font-weight:  700;
  color:        var(--theme-accent-light);
  margin-top:   0.4rem;
}

/* ── Stage cards grid ── */
.stage-cards-grid {
  display:               grid;
  grid-template-columns: repeat(3, 1fr);
  gap:                   1rem;
  width:                 100%;
  max-width:             880px;
  margin:                1.2rem 0 0.5rem;
}
@media (max-width: 640px) {
  .stage-cards-grid {
    grid-template-columns: 1fr;
    max-width:             360px;
  }
}

.stage-card {
  background:       var(--theme-card-bg);
  border:           2.5px solid var(--theme-border);
  border-radius:    22px;
  padding:          1.5rem 1rem 1.2rem;
  cursor:           pointer;
  transition:       transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  text-align:       center;
  position:         relative;
  backdrop-filter:  blur(6px);
  /* border colours / hover glows set per theme (s1 / s2 / s3 selectors) */
}
.stage-card:hover { transform: translateY(-8px); }

/* "⭐ START HERE!" ribbon on the first stage card */
.rec-badge {
  position:      absolute;
  top:           -13px;
  left:          50%;
  transform:     translateX(-50%);
  background:    linear-gradient(135deg, var(--theme-accent), var(--theme-accent-dark));
  color:         #fff;
  font-family:   var(--theme-font-display);
  font-size:     0.72rem;
  letter-spacing: 1.5px;
  padding:       0.2rem 0.9rem;
  border-radius: 20px;
  white-space:   nowrap;
  box-shadow:    0 3px 10px rgba(0,0,0,0.3);
}

.stage-card-emoji {
  font-size:     2.8rem;
  display:       block;
  margin-bottom: 0.25rem;
  filter:        drop-shadow(0 0 8px rgba(255,215,0,0.4));
}
.stage-card-label {
  font-family:    var(--theme-font-display);
  font-size:      0.72rem;
  letter-spacing: 2px;
  color:          var(--theme-text-dim);
  text-transform: uppercase;
  display:        block;
}
.stage-card-name {
  font-family:    var(--theme-font-display);
  font-size:      1.4rem;
  letter-spacing: 2px;
  color:          var(--theme-highlight);
  display:        block;
  margin:         0.15rem 0;
}
.stage-card-stars {
  font-size:     1rem;
  display:       block;
  margin:        0.15rem 0 0.5rem;
  color:         var(--theme-text);
}
.stage-card-desc {
  font-size:     0.78rem;
  font-weight:   700;
  color:         var(--theme-text-dim);
  line-height:   1.45;
  margin-bottom: 0.7rem;
  min-height:    2.8rem;
}
.stage-card-best {
  font-family:    var(--theme-font-display);
  font-size:      0.85rem;
  letter-spacing: 1px;
  color:          rgba(255,215,0,0.55);
  display:        block;
  margin-bottom:  0.8rem;
}

/* Play Stage N! button inside each card */
.btn-stage {
  font-family:   var(--theme-font-body);
  font-weight:   800;
  font-size:     0.95rem;
  padding:       0.7rem 1.2rem;
  min-height:    44px;
  border:        none;
  border-radius: 50px;
  cursor:        pointer;
  width:         100%;
  color:         #fff;
  letter-spacing: 0.3px;
  transition:    transform 0.15s, filter 0.15s;
  /* Gradient set per theme (.btn-stage.s1 / .s2 / .s3) */
}
.btn-stage:hover  { transform: scale(1.04); filter: brightness(1.1); }
.btn-stage:active { transform: scale(1); }

.welcome-footer {
  font-size:  0.82rem;
  opacity:    0.5;
  margin-top: 0.5rem;
  color:      var(--theme-text);
}

/* ══════════════════════════════════════════════════════════════
   QUIZ SCREEN — PROGRESS BAR
══════════════════════════════════════════════════════════════ */
.progress-container {
  display:     flex;
  align-items: center;
  gap:         0.6rem;
  width:       100%;
  max-width:   700px;
  margin-bottom: 0.7rem;
}
.level-badge-small {
  font-family:   var(--theme-font-display);
  font-size:     0.82rem;
  letter-spacing: 1px;
  background:    rgba(255,140,0,0.18);
  border:        1px solid var(--theme-border-active);
  border-radius: 10px;
  padding:       0.15rem 0.65rem;
  color:         var(--theme-accent-light);
  white-space:   nowrap;
  flex-shrink:   0;
}
.progress-bar-bg {
  flex:          1;
  height:        10px;
  background:    var(--theme-panel-bg);
  border-radius: 5px;
  overflow:      hidden;
}
.progress-bar-fill {
  height:        100%;
  background:    linear-gradient(90deg, var(--theme-accent), var(--theme-highlight));
  border-radius: 5px;
  transition:    width 0.4s ease;
}
.progress-label {
  font-size:   0.8rem;
  font-weight: 700;
  color:       var(--theme-text-dim);
  white-space: nowrap;
}

/* ── HUD (score / lives / streak / multiplier) ── */
.hud {
  display:         flex;
  justify-content: space-between;
  align-items:     center;
  width:           100%;
  max-width:       700px;
  margin-bottom:   0.8rem;
  gap:             0.5rem;
  flex-wrap:       wrap;
}
.hud-block {
  background:    var(--theme-panel-bg);
  border:        1.5px solid var(--theme-border);
  border-radius: 14px;
  padding:       0.5rem 0.9rem;
  min-width:     70px;
  text-align:    center;
}
.hud-label {
  font-size:      0.6rem;
  font-weight:    700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color:          var(--theme-text-dim);
  display:        block;
}
.hud-value {
  font-family:    var(--theme-font-display);
  font-size:      1.5rem;
  letter-spacing: 1px;
  color:          var(--theme-highlight);
  display:        block;
  line-height:    1;
}
.hud-lives,
.hud-streak { font-size: 1.4rem; }

/* ── TIMER BAR ── */
.timer-container {
  width:         100%;
  max-width:     700px;
  margin-bottom: 1rem;
}
.timer-bar-bg {
  width:         100%;
  height:        14px;
  background:    var(--theme-panel-bg);
  border-radius: 7px;
  overflow:      hidden;
  border:        1.5px solid var(--theme-border);
}
.timer-bar-fill {
  height:     100%;
  background: linear-gradient(90deg, var(--theme-accent), var(--theme-highlight));
  border-radius: 7px;
  transition: width 0.1s linear, background 0.5s;
  width:      100%;
}
.timer-bar-fill.danger {
  background: linear-gradient(90deg, var(--wrong), #ff5722);
}

/* ── QUESTION CARD ── */
.question-card {
  background:       var(--theme-card-bg);
  border:           2.5px solid var(--theme-border);
  border-radius:    24px;
  padding:          1.5rem 1.8rem;
  max-width:        700px;
  width:            100%;
  margin-bottom:    1.2rem;
  backdrop-filter:  blur(8px);
  box-shadow:       0 8px 32px rgba(0,0,0,0.5),
                    inset 0 1px 0 rgba(255,255,255,0.05);
}
.question-number {
  font-size:      0.7rem;
  font-weight:    700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color:          var(--theme-accent);
  margin-bottom:  0.5rem;
  display:        block;
}
.question-category {
  display:        inline-block;
  border-radius:  20px;
  padding:        0.2rem 0.8rem;
  font-size:      0.72rem;
  font-weight:    700;
  margin-bottom:  0.8rem;
  letter-spacing: 0.5px;
  /* background / border / color set per theme (.question-category in theme-*.css) */
}
.question-display {
  font-size:   clamp(1.05rem, 3vw, 1.3rem);
  font-weight: 800;
  color:       var(--theme-text);
  line-height: 1.4;
}

/* ── ANSWER BUTTONS (A / B / C / D) ── */
.answers-grid {
  display:               grid;
  grid-template-columns: 1fr 1fr;
  gap:                   0.75rem;
  width:                 100%;
  max-width:             700px;
}
@media (max-width: 480px) {
  .answers-grid { grid-template-columns: 1fr; }
}

.answer-btn {
  font-family:   var(--theme-font-body);
  font-weight:   800;
  font-size:     clamp(0.88rem, 2.5vw, 1.02rem);
  padding:       1rem 1.2rem;
  min-height:    44px;
  border:        none;
  border-radius: 18px;
  cursor:        pointer;
  text-align:    left;
  line-height:   1.35;
  transition:    transform 0.15s, filter 0.15s;
  color:         #fff;
  box-shadow:    0 5px 0 rgba(0,0,0,0.4), 0 8px 15px rgba(0,0,0,0.3);
  border-bottom: 4px solid rgba(0,0,0,0.25);
  display:       flex;
  align-items:   center;
}
/* Fixed 4-colour palette for A–D options — same across all games */
.answer-btn[data-idx="0"] { background: linear-gradient(135deg,#7b52c1,#5e3b9e); }
.answer-btn[data-idx="1"] { background: linear-gradient(135deg,#2e7d52,#1b5e3a); }
.answer-btn[data-idx="2"] { background: linear-gradient(135deg,#c0392b,#96211b); }
.answer-btn[data-idx="3"] { background: linear-gradient(135deg,#1565c0,#0d3f7a); }

.answer-btn:hover:not(:disabled)  { transform: translateY(-3px); filter: brightness(1.1); }
.answer-btn:active:not(:disabled) { transform: translateY(0); box-shadow: 0 2px 0 rgba(0,0,0,0.4); }
.answer-btn:disabled               { cursor: default; filter: brightness(0.75); }

/* State classes applied by game-shell.js */
.answer-btn.correct {
  animation:  correctPop 0.5s ease-out forwards;
  background: linear-gradient(135deg,#4caf50,#2e7d32) !important;
  box-shadow: 0 0 30px rgba(76,175,80,0.6) !important;
}
.answer-btn.wrong {
  animation:  wrongShake 0.5s ease-out forwards;
  background: linear-gradient(135deg,#e53935,#b71c1c) !important;
}
.answer-btn.reveal {
  animation:  revealCorrect 0.5s 0.2s ease-out forwards;
  background: linear-gradient(135deg,#4caf50,#2e7d32) !important;
}

.answer-letter {
  display:       inline-flex;
  align-items:   center;
  justify-content: center;
  width:         26px;
  height:        26px;
  min-width:     26px;
  background:    rgba(255,255,255,0.2);
  border-radius: 50%;
  font-size:     0.8rem;
  font-weight:   900;
  margin-right:  0.45rem;
}
.ans-text { flex: 1; }

/* ══════════════════════════════════════════════════════════════
   FEEDBACK OVERLAY
══════════════════════════════════════════════════════════════ */
.feedback-overlay {
  position:        fixed;
  inset:           0;
  z-index:         100;
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  padding:         1.5rem;
  opacity:         0;
  pointer-events:  none;
  transition:      opacity 0.3s;
}
.feedback-overlay.show {
  opacity:        1;
  pointer-events: all;
}
.feedback-overlay.correct-bg { background: rgba(0,80,0,0.88);   backdrop-filter: blur(4px); }
.feedback-overlay.wrong-bg   { background: rgba(120,0,0,0.88);  backdrop-filter: blur(4px); }

.feedback-emoji {
  font-size:     clamp(5rem, 14vw, 8rem);
  animation:     feedbackBounce 0.5s cubic-bezier(0.175,0.885,0.32,1.275);
  margin-bottom: 0.4rem;
}
.feedback-title {
  font-family:    var(--theme-font-display);
  font-size:      clamp(2rem, 7vw, 3.5rem);
  letter-spacing: 3px;
  color:          #fff;
  text-shadow:    2px 2px 0 rgba(0,0,0,0.4);
  margin-bottom:  0.3rem;
}
.feedback-points {
  font-family:    var(--theme-font-display);
  font-size:      clamp(1.4rem, 5vw, 2rem);
  color:          var(--theme-highlight);
  letter-spacing: 2px;
  margin-bottom:  0.8rem;
  animation:      pointsPop 0.4s 0.1s cubic-bezier(0.175,0.885,0.32,1.275) both;
}
.feedback-fact {
  background:    rgba(255,255,255,0.12);
  border-radius: 16px;
  padding:       1rem 1.4rem;
  max-width:     480px;
  font-size:     1rem;
  font-weight:   700;
  line-height:   1.5;
  color:         #fff;
  animation:     factSlide 0.4s 0.2s ease-out both;
}
.feedback-fact-label {
  font-size:      0.68rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  opacity:        0.65;
  display:        block;
  margin-bottom:  0.3rem;
}
.feedback-continue {
  margin-top: 1.2rem;
  font-size:  0.85rem;
  opacity:    0.65;
  animation:  pulse 1.5s ease-in-out infinite;
  color:      #fff;
}

/* ══════════════════════════════════════════════════════════════
   FLOATING SCORE POPUP + STREAK BONUS BADGE
══════════════════════════════════════════════════════════════ */
.score-popup {
  position:      fixed;
  font-family:   var(--theme-font-display);
  font-size:     2rem;
  color:         var(--theme-highlight);
  text-shadow:   2px 2px 0 rgba(0,0,0,0.5);
  pointer-events: none;
  z-index:       200;
  animation:     scoreFloat 1.2s ease-out forwards;
}
.bonus-badge {
  position:   fixed;
  top:        50%;
  left:       50%;
  transform:  translate(-50%,-50%);
  z-index:    150;
  font-family: var(--theme-font-display);
  font-size:  2.8rem;
  color:      var(--theme-highlight);
  text-shadow: 3px 3px 0 var(--theme-btn-shadow),
               0 0 30px gold;
  animation:  bonusPop 1.5s ease-out forwards;
  pointer-events: none;
  text-align: center;
}

/* ══════════════════════════════════════════════════════════════
   END SCREEN
══════════════════════════════════════════════════════════════ */
.medal-display {
  font-size:     clamp(4rem, 12vw, 6rem);
  animation:     medalSpin 1s cubic-bezier(0.175,0.885,0.32,1.275) both;
  margin-bottom: 0.3rem;
  filter:        drop-shadow(0 0 20px rgba(255,215,0,0.7));
}
.end-screen-title {
  font-family:    var(--theme-font-display);
  font-size:      2rem;
  color:          var(--theme-highlight);
  letter-spacing: 2px;
  margin-bottom:  0.3rem;
  text-shadow:    2px 2px 0 var(--theme-title-shadow);
}
.end-card {
  background:      var(--theme-card-bg);
  border:          3px solid rgba(255,215,0,0.4);
  border-radius:   28px;
  padding:         2rem 2.5rem;
  max-width:       540px;
  width:           100%;
  backdrop-filter: blur(12px);
  box-shadow:      0 20px 60px rgba(0,0,0,0.6);
}
.level-completed-badge {
  font-family:    var(--theme-font-display);
  font-size:      1rem;
  letter-spacing: 1px;
  color:          var(--theme-text-dim);
  display:        block;
  margin-bottom:  0.4rem;
}
.stars-row {
  display:         flex;
  justify-content: center;
  gap:             0.3rem;
  margin:          0.8rem 0;
  font-size:       2.8rem;
}
.star {
  display:   inline-block;
  opacity:   0;
  transform: scale(0) rotate(-30deg);
  filter:    drop-shadow(0 0 10px gold);
}
.star.lit { animation: starPop 0.5s cubic-bezier(0.175,0.885,0.32,1.275) forwards; }

.final-score {
  font-family:    var(--theme-font-display);
  font-size:      clamp(3rem, 10vw, 5rem);
  color:          var(--theme-highlight);
  letter-spacing: 3px;
  text-shadow:    3px 3px 0 var(--theme-btn-shadow),
                  0 0 30px rgba(255,215,0,0.5);
  line-height:    1;
}
.final-score-label {
  font-size: 0.85rem;
  opacity:   0.55;
  margin:    0.2rem 0;
  color:     var(--theme-text);
}
.new-record {
  font-family:    var(--theme-font-display);
  font-size:      1.3rem;
  letter-spacing: 2px;
  color:          #fff;
  background:     linear-gradient(135deg, var(--theme-accent), var(--theme-accent-dark));
  padding:        0.4rem 1.2rem;
  border-radius:  50px;
  margin:         0.5rem 0;
  display:        inline-block;
  animation:      recordPulse 1s ease-in-out infinite alternate;
}
.rank-badge {
  font-family:    var(--theme-font-display);
  font-size:      1.4rem;
  letter-spacing: 2px;
  color:          var(--theme-accent-light);
  background:     rgba(255,140,0,0.15);
  border:         2px solid var(--theme-border);
  border-radius:  50px;
  padding:        0.4rem 1.5rem;
  display:        inline-block;
  margin:         0.5rem 0 0.15rem;
}
/* S2: Optional subtitle below rank badge — shown only when rank.desc is present */
.rank-desc {
  font-size:     0.88rem;
  font-weight:   700;
  color:         var(--theme-text-dim);
  margin-bottom: 0.4rem;
}

/* S9: Badge chips row — rendered by computeBadges callback; hidden when empty */
.badges-row {
  display:         flex;
  flex-wrap:       wrap;
  justify-content: center;
  gap:             0.5rem;
  margin:          0.5rem 0 0;
  min-height:      0;   /* collapses cleanly when no badges */
}
.badge-chip {
  display:       flex;
  align-items:   center;
  gap:           0.45rem;
  background:    rgba(255, 140, 0, 0.12);
  border:        1.5px solid var(--theme-border-active);
  border-radius: 50px;
  padding:       0.35rem 0.9rem 0.35rem 0.6rem;
}
.badge-medal {
  font-size: 1.4rem;
  line-height: 1;
}
.badge-info {
  display:        flex;
  flex-direction: column;
  text-align:     left;
}
.badge-info strong {
  font-family:    var(--theme-font-display);
  font-size:      0.85rem;
  letter-spacing: 0.5px;
  color:          var(--theme-highlight);
  line-height:    1.1;
}
.badge-info span {
  font-size:   0.68rem;
  font-weight: 700;
  color:       var(--theme-text-dim);
  line-height: 1.2;
}

.stats-grid {
  display:               grid;
  grid-template-columns: 1fr 1fr;   /* S3: 2×2 grid — 4 stats (Correct, Streak, Accuracy, High Score) */
  gap:                   0.6rem;
  margin:                1rem 0;
}
.stat-box {
  background:    rgba(255,140,0,0.1);
  border:        1px solid var(--theme-border);
  border-radius: 14px;
  padding:       0.7rem;
}
.stat-value {
  font-family:    var(--theme-font-display);
  font-size:      1.5rem;
  color:          var(--theme-highlight);
  letter-spacing: 1px;
  display:        block;
}
.stat-label {
  font-size:      0.68rem;
  font-weight:    700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color:          var(--theme-text-dim);
  display:        block;
}
.encouragement {
  font-size:   0.95rem;
  font-weight: 700;
  color:       var(--theme-accent-light);
  margin-top:  0.5rem;
}
.end-buttons {
  display:        flex;
  flex-direction: column;
  gap:            0.7rem;
  margin-top:     1.2rem;
}

/* ══════════════════════════════════════════════════════════════
   GAME OVER SCREEN
══════════════════════════════════════════════════════════════ */
.game-over-emoji {
  font-size:     clamp(4rem, 12vw, 7rem);
  animation:     sadBounce 1s ease-in-out infinite;
  margin-bottom: 0.5rem;
}
.game-over-title  { color: var(--wrong) !important; }
.game-over-subtitle {
  font-size:     1.1rem;
  font-weight:   700;
  color:         var(--theme-text-dim);
  margin-bottom: 1.5rem;
}
.game-over-score-text {
  font-size:     1.1rem;
  font-weight:   700;
  margin-bottom: 0.8rem;
  color:         var(--theme-text);
}
.go-score-value {
  color:       var(--theme-highlight);
  font-family: var(--theme-font-display);
  font-size:   1.5rem;
}
.game-over-encourage {
  font-size:     0.95rem;
  opacity:       0.75;
  margin-bottom: 1.2rem;
  color:         var(--theme-text);
}

/* ══════════════════════════════════════════════════════════════
   LOAD ERROR SCREEN (shown when questions.json fails to load)
══════════════════════════════════════════════════════════════ */
.load-error {
  gap: 0.5rem;
}
.load-error p {
  max-width:   400px;
  line-height: 1.5;
  color:       var(--theme-text-dim);
}

/* ── CONFETTI CANVAS ── */
.confetti-canvas {
  position:       fixed;
  inset:          0;
  pointer-events: none;
  z-index:        999;
}
