* { box-sizing: border-box; }
body { margin: 0; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: #f2f4f8; }

.bd-outer {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.bd-container {
  width: 100%;
  max-width: 760px;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 18px 45px rgba(0,0,0,0.15);
}

/* ---------- Header ---------- */
.bd-header {
  background: #1c4e9e;
  color: #fff;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.bd-instruction { font-size: 14px; font-weight: 600; }
.bd-header-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.bd-progress, .bd-score, .bd-life { font-size: 13px; font-weight: 700; }
.bd-home-btn {
  background: #2ecc71; color: #fff; border: none; border-radius: 20px; padding: 6px 16px;
  font-size: 12px; font-weight: 700; cursor: pointer;
}

/* ---------- Loading / Warning ---------- */
.bd-loading, .bd-warning {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 60px 20px; gap: 14px; color: #3a3a3a;
}
.bd-spinner {
  width: 36px; height: 36px; border: 4px solid #cfe8ff; border-top-color: #1c4e9e;
  border-radius: 50%; animation: bd-spin 0.8s linear infinite;
}
@keyframes bd-spin { to { transform: rotate(360deg); } }
.bd-warning-icon { font-size: 40px; }

/* ---------- Question panel ---------- */
.bd-question-panel {
  background: #ffe066;
  padding: 20px 24px;
  text-align: center;
}
.bd-question-label { font-size: 16px; font-weight: 700; color: #4a3200; margin-bottom: 6px; }
.bd-question-text { font-size: 30px; font-weight: 800; color: #1a1a1a; }

/* ---------- Scene: dark starry background with bead track ---------- */
.bd-scene {
  position: relative;
  background: #1b2a4b;
  background-image:
    radial-gradient(circle, rgba(255,255,255,0.5) 1.5px, transparent 1.5px),
    radial-gradient(circle, rgba(255,255,255,0.3) 1px, transparent 1px);
  background-size: 60px 60px, 40px 40px;
  background-position: 0 0, 20px 25px;
  min-height: 260px;
  padding: 30px 20px;
  overflow: hidden;
}
.bd-star { position: absolute; color: rgba(255,255,255,0.5); font-size: 16px; }
.bd-star-1 { top: 12px; left: 8%; }
.bd-star-2 { top: 30px; right: 12%; font-size: 22px; }
.bd-star-3 { bottom: 20px; left: 15%; font-size: 20px; }
.bd-star-4 { bottom: 40px; right: 20%; }

/* ---------- Bead track ---------- */
.bd-track-wrap {
  position: relative;
  height: 90px;
  margin-top: 20px;
}
.bd-hole {
  position: absolute;
  left: 0; top: 50%; transform: translateY(-50%);
  width: 60px; height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffd1e8, #ff6fa5 60%, #7a1044 100%);
  border: 4px solid #ffd1e8;
  z-index: 2;
}
.bd-track {
  position: relative;
  height: 100%;
  width: 100%;
}
.bd-bead {
  position: absolute;
  top: 50%;
  width: 52px; height: 52px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3), inset 0 -4px 6px rgba(0,0,0,0.2), inset 0 4px 6px rgba(255,255,255,0.3);
  transition: transform 0.15s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  will-change: left;
}
.bd-bead:hover { transform: translateY(-50%) scale(1.08); }
.bd-bead.correct { animation: bd-pop 0.4s forwards; }
.bd-bead.incorrect { animation: bd-shake 0.4s; }
@keyframes bd-pop {
  0% { transform: translateY(-50%) scale(1); opacity: 1; }
  100% { transform: translateY(-50%) scale(0); opacity: 0; }
}
@keyframes bd-shake {
  0%, 100% { transform: translateY(-50%) translateX(0); }
  25% { transform: translateY(-50%) translateX(-6px); }
  75% { transform: translateY(-50%) translateX(6px); }
}

/* Bead color palette (cycled by index) */
.bd-bead.c0 { background: radial-gradient(circle at 35% 35%, #ffe27a, #d9a02b); }
.bd-bead.c1 { background: radial-gradient(circle at 35% 35%, #7ad9ff, #1c74a8); }
.bd-bead.c2 { background: radial-gradient(circle at 35% 35%, #ff9ecb, #c23b7a); }
.bd-bead.c3 { background: radial-gradient(circle at 35% 35%, #b48aff, #6a35c9); }
.bd-bead.c4 { background: radial-gradient(circle at 35% 35%, #8affb0, #24a35a); }

.bd-feedback {
  text-align: center; font-size: 14px; font-weight: 700; padding: 10px; margin: 14px 20px 20px;
  border-radius: 10px;
}
.bd-feedback-correct { background: #e6f9ee; color: #1e8449; }
.bd-feedback-incorrect { background: #fdecea; color: #c0392b; }

/* ---------- Result screen ---------- */
.bd-result { text-align: center; padding: 50px 30px; }
.bd-result-icon { font-size: 56px; margin-bottom: 8px; }
.bd-result h2 { margin: 0 0 8px; color: #2f3542; }
.bd-result p { color: #6b6b6b; margin: 0 0 20px; }
.bd-result-stats { display: flex; justify-content: center; gap: 30px; margin-bottom: 26px; }
.bd-result-stats span { display: block; font-size: 26px; font-weight: 800; color: #ff9f1c; }
.bd-result-stats small { color: #999; font-size: 12px; }
.bd-result-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

.bd-btn {
  border: none; border-radius: 12px; padding: 12px 26px; font-size: 14px; font-weight: 700;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.bd-btn-primary { background: #2ecc71; color: #fff; }
.bd-btn-secondary { background: #5b8def; color: #fff; }

/* ---------- Home confirmation modal ---------- */
.bd-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.bd-modal {
  background: #fff; border-radius: 16px; padding: 26px 24px; max-width: 340px; text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.bd-modal p { font-size: 15px; font-weight: 600; color: #2f3542; margin: 0 0 18px; }
.bd-modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .bd-outer { padding: 10px; }
  .bd-container { border-radius: 12px; }
  .bd-header { padding: 10px 12px; }
  .bd-instruction { font-size: 12px; flex-basis: 100%; text-align: center; order: 1; }
  .bd-header-right { order: 2; margin: 0 auto; }
  .bd-progress, .bd-score, .bd-life { font-size: 11px; }

  .bd-question-panel { padding: 14px 16px; }
  .bd-question-text { font-size: 22px; }
  .bd-scene { min-height: 220px; padding: 20px 14px; }
  .bd-hole { width: 48px; height: 48px; }
  .bd-bead { width: 44px; height: 44px; font-size: 16px; }
  .bd-btn { width: 100%; justify-content: center; }
}
