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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  color: #fff;
  overflow-x: hidden;
}

.container { max-width: 900px; margin: 0 auto; padding: 20px; }

/* ── Animated Stars Background ──────────────────────────────────────────────── */
.stars-bg {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(1px 1px at 10% 15%, white, transparent),
    radial-gradient(1px 1px at 25% 40%, white, transparent),
    radial-gradient(1px 1px at 40% 10%, white, transparent),
    radial-gradient(1px 1px at 60% 70%, white, transparent),
    radial-gradient(1px 1px at 75% 25%, white, transparent),
    radial-gradient(1px 1px at 85% 55%, white, transparent),
    radial-gradient(1px 1px at 5% 80%, white, transparent),
    radial-gradient(1px 1px at 50% 90%, white, transparent),
    radial-gradient(1px 1px at 90% 10%, white, transparent),
    radial-gradient(2px 2px at 30% 60%, rgba(255,255,255,.5), transparent),
    radial-gradient(2px 2px at 70% 35%, rgba(255,255,255,.5), transparent);
  animation: twinkle 4s infinite alternate;
}
@keyframes twinkle { 0% { opacity: .6; } 100% { opacity: 1; } }

/* ── Home Page ──────────────────────────────────────────────────────────────── */
.home-header { text-align: center; padding: 40px 0 30px; position: relative; z-index: 1; }
.site-title  { font-size: 3.5rem; font-weight: 900; letter-spacing: 2px; text-shadow: 0 0 30px #ffd700, 0 4px 10px rgba(0,0,0,.5); }
.site-subtitle { font-size: 1.3rem; color: #a8d8ff; margin-top: 8px; }

.who-playing { text-align: center; font-size: 1.5rem; margin-bottom: 20px; color: #ffd700; position: relative; z-index: 1; }

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 20px;
  position: relative; z-index: 1;
}
.profile-card {
  background: rgba(255,255,255,.1);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255,255,255,.2);
  border-radius: 20px;
  padding: 24px 16px;
  text-align: center;
  text-decoration: none;
  color: #fff;
  transition: transform .2s, box-shadow .2s, border-color .2s;
  cursor: pointer;
}
.profile-card:hover { transform: translateY(-6px) scale(1.03); box-shadow: 0 12px 40px rgba(255,215,0,.3); border-color: #ffd700; }
.profile-avatar   { font-size: 3.5rem; margin-bottom: 10px; }
.profile-name     { font-size: 1.2rem; font-weight: 700; margin-bottom: 6px; }
.profile-money    { font-size: 1.1rem; color: #ffd700; font-weight: 700; margin-bottom: 6px; }
.profile-stats    { font-size: .75rem; color: #a8d8ff; }

.empty-state { text-align: center; padding: 40px; position: relative; z-index: 1; }
.empty-state h2 { font-size: 2rem; margin: 16px 0 8px; }
.empty-state p  { color: #a8d8ff; }

.new-player-wrap { text-align: center; margin-top: 30px; position: relative; z-index: 1; }
.btn-new-player {
  display: inline-block;
  background: linear-gradient(135deg, #f7971e, #ffd200);
  color: #1a1a2e;
  font-size: 1.2rem;
  font-weight: 800;
  padding: 14px 36px;
  border-radius: 50px;
  text-decoration: none;
  box-shadow: 0 6px 20px rgba(255,210,0,.4);
  transition: transform .2s, box-shadow .2s;
}
.btn-new-player:hover { transform: translateY(-3px); box-shadow: 0 10px 30px rgba(255,210,0,.6); }

/* ── Create Page ────────────────────────────────────────────────────────────── */
.create-page .container { position: relative; z-index: 1; }
.back-link { color: #a8d8ff; text-decoration: none; font-size: .95rem; display: block; margin-bottom: 20px; }
.back-link:hover { color: #fff; }

.create-card {
  background: rgba(255,255,255,.1);
  backdrop-filter: blur(12px);
  border: 2px solid rgba(255,255,255,.2);
  border-radius: 24px;
  padding: 40px;
  max-width: 600px;
  margin: 0 auto;
}
.create-card h1 { text-align: center; font-size: 2rem; margin-bottom: 30px; }

.form-group { margin-bottom: 24px; }
.form-group label { display: block; font-size: 1.1rem; font-weight: 600; margin-bottom: 10px; color: #a8d8ff; }
.big-input {
  width: 100%;
  padding: 14px 18px;
  font-size: 1.1rem;
  background: rgba(255,255,255,.15);
  border: 2px solid rgba(255,255,255,.3);
  border-radius: 12px;
  color: #fff;
  outline: none;
}
.big-input:focus { border-color: #ffd700; }
.big-input option { background: #1a1a2e; }

.avatar-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.avatar-option { cursor: pointer; }
.avatar-option input { display: none; }
.avatar-emoji {
  display: block;
  font-size: 2.2rem;
  padding: 8px;
  border-radius: 12px;
  border: 3px solid transparent;
  transition: border-color .15s, transform .15s;
}
.avatar-option input:checked + .avatar-emoji,
.avatar-emoji:hover { border-color: #ffd700; transform: scale(1.2); }

.btn-start {
  width: 100%;
  padding: 16px;
  font-size: 1.3rem;
  font-weight: 800;
  background: linear-gradient(135deg, #11998e, #38ef7d);
  color: #1a1a2e;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(56,239,125,.4);
  transition: transform .2s, box-shadow .2s;
  margin-top: 10px;
}
.btn-start:hover { transform: translateY(-3px); box-shadow: 0 10px 30px rgba(56,239,125,.6); }

/* ── Play Page ──────────────────────────────────────────────────────────────── */
.play-page { display: flex; flex-direction: column; height: 100vh; }

.play-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(0,0,0,.3);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,.1);
  position: relative; z-index: 10;
  flex-shrink: 0;
}
.header-home { font-size: 1.5rem; text-decoration: none; }
.header-player { display: flex; align-items: center; gap: 8px; }
.header-avatar { font-size: 1.8rem; }
.header-name   { font-size: 1.1rem; font-weight: 700; }
.header-money  { font-size: 1.3rem; font-weight: 800; color: #ffd700; background: rgba(255,215,0,.15); padding: 6px 16px; border-radius: 20px; border: 2px solid rgba(255,215,0,.3); }

.play-container { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; }

/* Subject chooser */
.subject-chooser { text-align: center; width: 100%; max-width: 600px; }
.subject-chooser h2 { font-size: 1.8rem; margin-bottom: 30px; color: #ffd700; }
.subject-btns { display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; }
.subject-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 180px;
  padding: 30px 20px;
  border: 3px solid rgba(255,255,255,.2);
  border-radius: 24px;
  background: rgba(255,255,255,.08);
  color: #fff;
  cursor: pointer;
  transition: transform .2s, border-color .2s, box-shadow .2s;
  font-size: 1rem;
}
.subject-btn { position: relative; }
.subject-btn:hover { transform: translateY(-6px); box-shadow: 0 12px 40px rgba(255,255,255,.2); border-color: rgba(255,255,255,.6); }
/* Locked state */
.subject-locked { opacity: .45; cursor: not-allowed; }
.subject-locked:hover { transform: none !important; box-shadow: none !important; }
.lock-badge {
  position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.65); border-radius: 8px; padding: 3px 10px;
  font-size: .72rem; white-space: nowrap; color: #ffcc80; pointer-events: none;
}
/* Required state */
.subject-required { border-color: #ff8f00 !important; animation: req-pulse 2s ease-in-out infinite; }
.required-badge {
  position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%);
  background: rgba(255,143,0,.3); border-radius: 8px; padding: 3px 10px;
  font-size: .72rem; white-space: nowrap; color: #ffe082; pointer-events: none;
}
@keyframes req-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(255,143,0,.5); }
  50%      { box-shadow: 0 0 0 10px rgba(255,143,0,0); }
}
.lock-message {
  text-align: center;
  background: rgba(255,143,0,.12);
  border: 1px solid rgba(255,143,0,.35);
  border-radius: 10px;
  padding: 10px 18px;
  margin-top: 18px;
  color: #ffe082;
  font-size: .9rem;
  line-height: 1.5;
}
.math-btn:hover    { border-color: #4fc3f7; box-shadow: 0 12px 40px rgba(79,195,247,.3); }
.reading-btn:hover  { border-color: #a5d6a7; box-shadow: 0 12px 40px rgba(165,214,167,.3); }
.readalong-btn:hover { border-color: #ce93d8; box-shadow: 0 12px 40px rgba(206,147,216,.3); }
.subject-icon  { font-size: 3rem; }
.subject-label { font-size: 1.3rem; font-weight: 800; }
.subject-level { font-size: .85rem; color: #a8d8ff; }

/* Game info bar */
.game-info-bar { display: flex; gap: 16px; align-items: center; justify-content: center; margin-bottom: 16px; flex-wrap: wrap; width: 100%; max-width: 700px; }
.info-subject  { font-size: 1rem; font-weight: 700; color: #a8d8ff; }
.info-level    { background: rgba(255,215,0,.2); border: 1px solid rgba(255,215,0,.4); border-radius: 20px; padding: 4px 14px; font-size: .95rem; color: #ffd700; }
.info-streak   { background: rgba(255,80,0,.2); border: 1px solid rgba(255,80,0,.4); border-radius: 20px; padding: 4px 14px; font-size: .95rem; color: #ff8c00; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }

/* Question card */
.question-card {
  width: 100%; max-width: 700px;
  background: rgba(255,255,255,.1);
  backdrop-filter: blur(12px);
  border: 2px solid rgba(255,255,255,.2);
  border-radius: 24px;
  padding: 32px;
}
.passage-area {
  background: rgba(255,255,255,.08);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 20px;
  font-size: 1rem;
  line-height: 1.7;
  color: #e0e0e0;
  border-left: 4px solid #4fc3f7;
}
.question-text { font-size: 1.4rem; font-weight: 700; margin-bottom: 8px; line-height: 1.4; }
.hint-text     { font-size: .85rem; color: #a8d8ff; margin-bottom: 20px; font-style: italic; }
.choices-area  { display: flex; flex-direction: column; gap: 12px; }
.choice-btn {
  text-align: left;
  padding: 14px 20px;
  background: rgba(255,255,255,.1);
  border: 2px solid rgba(255,255,255,.2);
  border-radius: 14px;
  color: #fff;
  font-size: 1.05rem;
  cursor: pointer;
  transition: transform .15s, border-color .15s, background .15s;
}
.choice-btn:hover:not(:disabled) { transform: translateX(6px); border-color: #ffd700; background: rgba(255,215,0,.15); }
.choice-btn.correct { background: rgba(56,239,125,.25); border-color: #38ef7d; color: #38ef7d; font-weight: 700; animation: correct-bounce .4s ease; }
.choice-btn.wrong   { background: rgba(255,80,80,.25); border-color: #ff5050; color: #ff5050; }
.choice-btn:disabled { cursor: default; }

@keyframes correct-bounce { 0%,100% { transform: scale(1); } 50% { transform: scale(1.04); } }

.feedback-area { margin-top: 20px; padding: 16px; border-radius: 14px; text-align: center; font-size: 1.1rem; font-weight: 700; }
.feedback-area.correct-fb { background: rgba(56,239,125,.2); color: #38ef7d; border: 2px solid #38ef7d; }
.feedback-area.wrong-fb   { background: rgba(255,80,80,.15); color: #ff8080; border: 2px solid #ff5050; }

.btn-next {
  margin-top: 16px;
  padding: 14px 40px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border: none;
  border-radius: 14px;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  box-shadow: 0 6px 20px rgba(102,126,234,.4);
}
.btn-next:hover { transform: translateY(-3px); box-shadow: 0 10px 30px rgba(102,126,234,.6); }

.btn-switch {
  margin-top: 12px;
  padding: 10px 24px;
  background: transparent;
  border: 2px solid rgba(255,255,255,.3);
  border-radius: 10px;
  color: #a8d8ff;
  font-size: .9rem;
  cursor: pointer;
  display: block;
  margin-left: auto;
  margin-right: auto;
  transition: border-color .2s, color .2s;
}
.btn-switch:hover { border-color: #fff; color: #fff; }

/* ── Reward popup ────────────────────────────────────────────────────────────── */
.reward-popup {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: none;
}
.reward-inner {
  background: linear-gradient(135deg, #f7971e, #ffd200);
  color: #1a1a2e;
  padding: 24px 40px;
  border-radius: 24px;
  font-size: 2rem;
  font-weight: 900;
  box-shadow: 0 20px 60px rgba(255,210,0,.5);
  animation: reward-pop .5s cubic-bezier(.68,-.55,.27,1.55);
  text-align: center;
}
@keyframes reward-pop { 0% { transform: scale(0) rotate(-10deg); opacity: 0; } 100% { transform: scale(1) rotate(0); opacity: 1; } }

/* ── Confetti / Stars ────────────────────────────────────────────────────────── */
.confetti-container { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti-piece {
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 2px;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
.star-burst {
  position: fixed;
  font-size: 2.5rem;
  pointer-events: none;
  z-index: 60;
  animation: star-fly 1s ease-out forwards;
}
@keyframes star-fly {
  0%   { transform: translate(0,0) scale(0.5); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}
.balloon {
  position: fixed;
  font-size: 3rem;
  pointer-events: none;
  z-index: 55;
  animation: balloon-rise linear forwards;
}
@keyframes balloon-rise {
  0%   { transform: translateY(100vh) rotate(var(--tilt)); opacity: 1; }
  100% { transform: translateY(-20vh) rotate(var(--tilt)); opacity: .5; }
}

/* ── Loading spinner ─────────────────────────────────────────────────────────── */
.loading { text-align: center; padding: 40px; font-size: 2rem; animation: spin 1s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
/* ── Read Along ───────────────────────────────────────────────────────────── */
.ra-instructions {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #ce93d8;
  margin-bottom: 16px;
}
.ra-passage {
  font-size: 1.25rem;
  line-height: 2;
  color: #e8f4fd;
  background: rgba(255,255,255,.06);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 20px;
  letter-spacing: .01em;
}
.ra-word {
  display: inline-block;
  padding: 1px 2px;
  border-radius: 4px;
  transition: background .15s, color .15s;
}
.ra-word.ra-speaking {
  background: rgba(100,181,246,.4);
  color: #fff;
  font-weight: 700;
}
.ra-word.ra-correct {
  background: rgba(102,187,106,.25);
  color: #a5d6a7;
  font-weight: 700;
}
.ra-word.ra-wrong {
  background: rgba(239,83,80,.25);
  color: #ef9a9a;
  text-decoration: underline wavy rgba(239,83,80,.7);
}
.ra-controls {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.btn-ra-listen {
  background: rgba(100,181,246,.2);
  border: 2px solid #64b5f6;
  color: #e3f2fd;
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s, transform .15s;
}
.btn-ra-listen:hover:not(:disabled) { background: rgba(100,181,246,.35); transform: translateY(-2px); }
.btn-ra-listen:disabled { opacity: .5; cursor: not-allowed; }
.btn-ra-record {
  background: rgba(206,147,216,.2);
  border: 2px solid #ce93d8;
  color: #f3e5f5;
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s, transform .15s, box-shadow .2s;
}
.btn-ra-record:hover { background: rgba(206,147,216,.35); transform: translateY(-2px); }
.btn-ra-record.recording {
  background: rgba(239,83,80,.3);
  border-color: #ef5350;
  color: #ffcdd2;
  animation: ra-pulse 1.2s ease-in-out infinite;
}
@keyframes ra-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,83,80,.5); }
  50%       { box-shadow: 0 0 0 10px rgba(239,83,80,0); }
}
.ra-live-transcript {
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: .95rem;
  color: #b0bec5;
  min-height: 44px;
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.ra-no-support {
  color: #ffcc80;
  font-size: .95rem;
  text-align: center;
  padding: 10px;
}

/* Word practice panel */
.ra-practice-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 2px dashed rgba(255,255,255,.15);
}
.ra-practice-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: #ffcc80;
  text-align: center;
  margin-bottom: 14px;
}
.ra-practice-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 12px;
}
.ra-word-card {
  background: rgba(255,255,255,.07);
  border: 2px solid rgba(239,83,80,.4);
  border-radius: 12px;
  padding: 12px 14px;
  min-width: 100px;
  text-align: center;
  transition: border-color .25s, background .25s, transform .15s;
}
.ra-word-card.ra-card-correct {
  border-color: #66bb6a;
  background: rgba(102,187,106,.18);
  transform: scale(1.04);
}
.ra-word-big {
  font-size: 1.15rem;
  font-weight: 800;
  color: #ef9a9a;
  margin-bottom: 6px;
  letter-spacing: .02em;
}
.ra-card-correct .ra-word-big { color: #a5d6a7; }
.ra-dot-row {
  display: flex;
  gap: 5px;
  justify-content: center;
  margin-bottom: 8px;
}
.ra-dot {
  font-size: 1rem;
  line-height: 1;
  transition: color .2s, transform .2s;
}
.ra-dot-off { color: rgba(255,255,255,.25); }
.ra-dot-on  { color: #ffd700; transform: scale(1.2); }
.ra-word-actions {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 5px;
}
.btn-ra-mini {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: .95rem;
  cursor: pointer;
  transition: background .15s, transform .1s;
  line-height: 1;
}
.btn-ra-mini:hover:not(:disabled) { background: rgba(255,255,255,.22); transform: scale(1.1); }
.btn-ra-mini:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-ra-mini-listen:hover:not(:disabled) { background: rgba(100,181,246,.3); }
.btn-ra-mini-record:hover:not(:disabled) { background: rgba(206,147,216,.3); }
.ra-word-status {
  font-size: .72rem;
  color: #90a4ae;
  min-height: 16px;
  line-height: 1.3;
}
.ra-practice-hint {
  text-align: center;
  font-size: .82rem;
  color: #607d8b;
  margin-bottom: 10px;
}
.ra-try-again-row {
  text-align: center;
  margin-top: 14px;
}
.btn-ra-tryagain {
  background: rgba(255,255,255,.08);
  border: 2px solid rgba(255,255,255,.25);
  color: #cfd8dc;
  border-radius: 12px;
  padding: 10px 20px;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.btn-ra-tryagain:hover { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.5); }

/* ── Intake banner ───────────────────────────────────────────────────────────── */
.intake-banner {
  background: linear-gradient(90deg, rgba(100,181,246,.15), rgba(100,181,246,.05));
  border: 1.5px solid rgba(100,181,246,.4);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: .9rem;
  color: #90caf9;
  text-align: center;
  margin-bottom: 12px;
}
.intake-banner strong { color: #e3f2fd; }

/* ── Redirect hint & penalty text ────────────────────────────────────────────── */
.redirect-hint {
  display: block;
  margin-top: 8px;
  font-size: .88rem;
  color: #ffcc80;
  font-style: italic;
}
.penalty-text {
  color: #ef9a9a;
  font-weight: 700;
  margin-left: 6px;
}
.cap-note {
  color: #b0bec5;
  font-size: .88rem;
  font-style: italic;
}

@media (max-width: 600px) {
  .site-title   { font-size: 2.5rem; }
  .question-card { padding: 20px; }
  .question-text { font-size: 1.15rem; }
  .choice-btn    { font-size: .95rem; padding: 12px 14px; }
  .subject-btns  { flex-direction: column; align-items: center; }
  .play-header   { padding: 10px 14px; }
  .header-money  { font-size: 1.1rem; }
}

/* -- Math explanation box -------------------------------------------------- */
.math-explanation {
  margin-top: 14px;
  background: rgba(56,189,248,.07);
  border: 1px solid rgba(56,189,248,.2);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: .92rem;
  color: #bae6fd;
  line-height: 1.7;
  text-align: left;
}
.math-explanation-title {
  font-weight: 800;
  color: #7dd3fc;
  margin-bottom: 8px;
  font-size: .88rem;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.math-explanation strong { color: #fbbf24; }
