/* ============================================================
   Math Drills — Core Styles
   ============================================================ */

:root {
  --md-primary: #FF6B35;
  --md-primary-light: #F7931E;
  --md-primary-dark: #E55A25;
  --md-success: #34D399;
  --md-success-light: rgba(52, 211, 153, 0.2);
  --md-error: #FB7185;
  --md-error-light: rgba(251, 113, 133, 0.2);
  --md-warning: #FBBF24;
  --md-gold: #FFD700;
  --md-bg: transparent;
  --md-card: rgba(255, 255, 255, 0.12);
  --md-text: #FFFFFF;
  --md-text-muted: rgba(255, 255, 255, 0.65);
  --md-border: rgba(255, 255, 255, 0.18);
  --md-radius: 12px;
  --md-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  --md-shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
}

/* Page wrapper */
.math-drills-page {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 16px 80px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--md-text);
}

/* Header */
.math-drills-header {
  text-align: center;
  margin-bottom: 32px;
}

.math-drills-title {
  font-size: 2rem;
  font-weight: 700;
  margin: 0 0 4px;
}

.math-drills-subtitle {
  font-size: 1.1rem;
  color: var(--md-text-muted);
  margin: 0 0 12px;
}

.math-drills-back {
  display: inline-block;
  color: var(--md-primary);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 500;
}

.math-drills-back:hover {
  text-decoration: underline;
  color: var(--md-primary-light);
}

/* Drill link button on course pages */
.math-drill-link-button {
  display: inline-block;
  background: var(--md-primary);
  color: #fff;
  padding: 12px 28px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 1.05rem;
  margin: 16px 0;
  transition: background .2s, transform .1s;
}

.math-drill-link-button:hover {
  background: var(--md-primary-dark);
  transform: translateY(-1px);
}

/* Confetti canvas */
.math-drills-confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

/* ============================================================
   Drill Menu (course home)
   ============================================================ */

.drill-menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.drill-menu-header {
  text-align: center;
  margin-bottom: 8px;
}

.drill-menu-xp {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 12px;
  font-size: .95rem;
  color: var(--md-text-muted);
}

.drill-menu-xp strong {
  color: var(--md-primary);
}

.drill-card {
  background: var(--md-card);
  border: 1px solid var(--md-border);
  border-radius: var(--md-radius);
  padding: 20px 24px;
  cursor: pointer;
  transition: box-shadow .2s, border-color .2s, transform .1s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.drill-card:hover {
  border-color: var(--md-primary-light);
  box-shadow: var(--md-shadow-lg);
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.18);
}

.drill-card-info h3 {
  margin: 0 0 4px;
  font-size: 1.1rem;
  font-weight: 600;
}

.drill-card-info p {
  margin: 0;
  color: var(--md-text-muted);
  font-size: .9rem;
}

.drill-card-badge {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  background: var(--md-primary);
  color: #fff;
}

.drill-card-badge.mastered {
  background: var(--md-success);
}

/* ============================================================
   Stats Bar (during drill)
   ============================================================ */

.drill-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--md-card);
  border: 1px solid var(--md-border);
  border-radius: var(--md-radius);
  padding: 12px 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.drill-stat {
  text-align: center;
}

.drill-stat-label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--md-text-muted);
  margin-bottom: 2px;
}

.drill-stat-value {
  font-size: 1.3rem;
  font-weight: 700;
}

.drill-stat-value.streak {
  color: var(--md-gold);
}

.drill-stat-value.score {
  color: var(--md-primary);
}

/* XP Bar */
.xp-bar-wrapper {
  width: 100%;
  margin-top: 4px;
}

.xp-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: .75rem;
  color: var(--md-text-muted);
  margin-bottom: 4px;
}

.xp-bar-track {
  height: 8px;
  background: var(--md-border);
  border-radius: 4px;
  overflow: hidden;
}

.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--md-primary), var(--md-primary-light));
  border-radius: 4px;
  transition: width .4s ease;
  width: 0%;
}

/* ============================================================
   Problem Area
   ============================================================ */

.drill-problem-card {
  background: var(--md-card);
  border: 1px solid var(--md-border);
  border-radius: var(--md-radius);
  padding: 32px 24px;
  text-align: center;
  margin-bottom: 20px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: border-color .3s, box-shadow .3s;
}

.drill-problem-card.correct {
  border-color: var(--md-success);
  box-shadow: 0 0 0 3px var(--md-success-light);
}

.drill-problem-card.wrong {
  border-color: var(--md-error);
  box-shadow: 0 0 0 3px var(--md-error-light);
  animation: shake .4s ease;
}

.drill-problem-text {
  font-size: 1.3rem;
  line-height: 1.8;
  margin-bottom: 8px;
}

.drill-problem-number {
  font-size: .8rem;
  color: var(--md-text-muted);
  margin-bottom: 12px;
}

/* Answer input */
.drill-answer-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.drill-input {
  font-size: 1.2rem;
  padding: 12px 20px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  width: 200px;
  text-align: center;
  outline: none;
  transition: border-color .2s;
  background: rgba(255, 255, 255, 0.1);
  color: #FFFFFF;
}

.drill-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.drill-input:focus {
  border-color: var(--md-primary);
}

.drill-input:disabled {
  opacity: .6;
}

/* Multiple choice */
.drill-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 400px;
}

.drill-choice {
  padding: 14px 16px;
  border: 2px solid var(--md-border);
  border-radius: 8px;
  background: var(--md-card);
  cursor: pointer;
  font-size: 1.05rem;
  text-align: center;
  transition: border-color .2s, background .2s;
}

.drill-choice:hover {
  border-color: var(--md-primary-light);
  background: rgba(255, 255, 255, 0.18);
}

.drill-choice.selected {
  border-color: var(--md-primary);
  background: rgba(255, 107, 53, 0.2);
}

.drill-choice.correct {
  border-color: var(--md-success);
  background: var(--md-success-light);
  color: #FFFFFF;
}

.drill-choice.wrong {
  border-color: var(--md-error);
  background: var(--md-error-light);
  color: #FFFFFF;
}

.drill-choice:disabled,
.drill-choice.disabled {
  cursor: default;
  pointer-events: none;
}

/* Buttons */
.drill-btn {
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
}

.drill-btn:active {
  transform: scale(.97);
}

.drill-btn-primary {
  background: var(--md-primary);
  color: #fff;
}

.drill-btn-primary:hover {
  background: var(--md-primary-dark);
}

.drill-btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  color: #FFFFFF;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.drill-btn-secondary:hover {
  background: rgba(255, 255, 255, 0.25);
}

.drill-btn-success {
  background: var(--md-success);
  color: #fff;
}

.drill-btn-success:hover {
  background: #059669;
}

.drill-btn-hint {
  background: transparent;
  border: 1px dashed var(--md-warning);
  color: var(--md-warning);
  font-size: .85rem;
  padding: 6px 16px;
}

.drill-btn-hint:hover {
  background: rgba(251, 191, 36, 0.15);
}

.drill-btn-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ============================================================
   Feedback Overlay
   ============================================================ */

.drill-feedback {
  margin-top: 16px;
  padding: 16px;
  border-radius: 8px;
  text-align: center;
  font-size: .95rem;
}

.drill-feedback.correct {
  background: var(--md-success-light);
  color: #FFFFFF;
}

.drill-feedback.wrong {
  background: var(--md-error-light);
  color: #FFFFFF;
}

.drill-feedback-icon {
  font-size: 1.8rem;
  display: block;
  margin-bottom: 4px;
}

/* Hint */
.drill-hint-box {
  margin-top: 12px;
  padding: 12px 16px;
  background: rgba(251, 191, 36, 0.15);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 8px;
  text-align: left;
  font-size: .9rem;
  color: #FFFFFF;
}

/* Solution reveal */
.drill-solution-box {
  margin-top: 12px;
  padding: 16px;
  background: rgba(129, 140, 248, 0.15);
  border: 1px solid rgba(129, 140, 248, 0.3);
  border-radius: 8px;
  text-align: left;
  font-size: .95rem;
  color: #FFFFFF;
}

.drill-solution-box h4 {
  margin: 0 0 8px;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--md-primary-light);
}

/* ============================================================
   Results Screen
   ============================================================ */

.drill-results {
  text-align: center;
  background: var(--md-card);
  border: 1px solid var(--md-border);
  border-radius: var(--md-radius);
  padding: 40px 24px;
}

.drill-results h2 {
  font-size: 1.6rem;
  margin: 0 0 8px;
}

.drill-results-grade {
  font-size: 3rem;
  font-weight: 800;
  margin: 16px 0;
}

.drill-results-grade.a { color: var(--md-success); }
.drill-results-grade.b { color: #2563EB; }
.drill-results-grade.c { color: var(--md-warning); }
.drill-results-grade.d { color: #EA580C; }
.drill-results-grade.f { color: var(--md-error); }

.drill-results-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin: 20px 0;
  flex-wrap: wrap;
}

.drill-results-stat {
  text-align: center;
}

.drill-results-stat-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.drill-results-stat-label {
  font-size: .8rem;
  color: var(--md-text-muted);
  text-transform: uppercase;
}

.drill-results-xp {
  margin: 20px 0;
  font-size: 1.1rem;
}

.drill-results-xp strong {
  color: var(--md-primary);
}

.drill-results-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
  flex-wrap: wrap;
}

/* ============================================================
   Leaderboard
   ============================================================ */

.drill-leaderboard {
  margin-top: 32px;
}

.drill-leaderboard h3 {
  font-size: 1.1rem;
  margin-bottom: 12px;
  text-align: center;
}

.drill-leaderboard table {
  width: 100%;
  border-collapse: collapse;
}

.drill-leaderboard th,
.drill-leaderboard td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--md-border);
  font-size: .9rem;
}

.drill-leaderboard th {
  font-weight: 600;
  color: var(--md-text-muted);
  text-transform: uppercase;
  font-size: .75rem;
  letter-spacing: .04em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.drill-leaderboard tr:nth-child(1) td {
  font-weight: 700;
  color: var(--md-gold);
}

/* ============================================================
   Size selector
   ============================================================ */

.drill-size-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}

.drill-size-selector label {
  font-size: .9rem;
  color: var(--md-text-muted);
}

.drill-size-selector select {
  padding: 6px 12px;
  border: 1px solid var(--md-border);
  border-radius: 6px;
  font-size: .9rem;
  background: rgba(255, 255, 255, 0.1);
  color: #FFFFFF;
}

/* ============================================================
   Animations
   ============================================================ */

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.drill-animate-pop {
  animation: pop .3s ease;
}

.drill-animate-in {
  animation: fadeIn .3s ease;
}

/* Streak glow */
@keyframes streakGlow {
  0%, 100% { text-shadow: 0 0 4px rgba(245,158,11,.3); }
  50% { text-shadow: 0 0 16px rgba(245,158,11,.6); }
}

.drill-streak-active {
  animation: streakGlow 1s ease infinite;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 600px) {
  .drill-stats {
    justify-content: center;
  }

  .drill-choices {
    grid-template-columns: 1fr;
  }

  .drill-results-stats {
    gap: 20px;
  }

  .drill-problem-text {
    font-size: 1.1rem;
  }
}
