/* ===== CSS RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6C5CE7;
  --primary-light: #a29bfe;
  --primary-dark: #4a3fc7;
  --accent: #FF6B6B;
  --accent-light: #ff8e8e;
  --success: #00b894;
  --success-light: #55efc4;
  --warning: #fdcb6e;
  --danger: #e17055;
  --bg: #f8f9ff;
  --bg-card: #ffffff;
  --text: #2d3436;
  --text-light: #636e72;
  --text-lighter: #b2bec3;
  --shadow: 0 4px 15px rgba(108, 92, 231, 0.12);
  --shadow-lg: 0 8px 30px rgba(108, 92, 231, 0.18);
  --radius: 16px;
  --radius-sm: 10px;
  --border: #dfe6e9;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-display: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  background-image:
    radial-gradient(circle at 10% 20%, rgba(108,92,231,0.05) 0%, transparent 50%),
    radial-gradient(circle at 90% 80%, rgba(255,107,107,0.05) 0%, transparent 50%);
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  padding: 24px;
  max-width: 900px;
  margin: 0 auto;
  animation: fadeIn 0.3s ease;
}
.screen.active { display: block; }

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

@keyframes popIn {
  0%   { transform: scale(0.8); opacity: 0; }
  70%  { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-8px); }
  75%      { transform: translateX(8px); }
}

@keyframes starBurst {
  0%   { transform: scale(0) rotate(0deg); opacity: 0; }
  50%  { transform: scale(1.3) rotate(180deg); opacity: 1; }
  100% { transform: scale(1) rotate(360deg); opacity: 1; }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}

/* ===== TYPOGRAPHY ===== */
.logo {
  font-family: var(--font-display);
  font-size: 2.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
}

.tagline {
  text-align: center;
  font-size: 1.2rem;
  color: var(--text-light);
  margin-top: 4px;
}

h2 { font-size: 1.6rem; font-weight: 700; margin-bottom: 16px; }
h3 { font-size: 1.2rem; font-weight: 600; }

.section-title {
  margin: 28px 0 14px;
  color: var(--text-light);
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 1.5px;
}

.daily-nav-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 8px;
}
.daily-nav-row .section-title {
  flex: 1;
  margin: 0;
  text-align: center;
}

.subject-level-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted, var(--text-light));
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.subtitle { color: var(--text-light); margin-bottom: 16px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 12px rgba(108,92,231,0.3);
}
.btn-primary:hover { box-shadow: 0 6px 18px rgba(108,92,231,0.4); }

.btn-secondary {
  background: var(--bg);
  color: var(--primary);
  border: 2px solid var(--primary-light);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), #e74c3c);
  color: white;
  box-shadow: 0 4px 12px rgba(255,107,107,0.3);
}

.btn-outline {
  background: transparent;
  color: var(--text-light);
  border: 2px solid #dfe6e9;
}

.btn-small { padding: 8px 16px; font-size: 0.85rem; }
.btn-tiny  { padding: 3px 8px; font-size: 0.72rem; border-radius: 6px; }

.btn-large { padding: 16px 48px; font-size: 1.15rem; }

#btn-challenge-mode.challenge-active {
  background: linear-gradient(135deg, #f39c12, #e67e22);
  color: white;
  border-color: #e67e22;
  font-weight: 700;
}

.btn-back {
  background: none;
  border: none;
  font-size: 1rem;
  color: var(--text-light);
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  font-weight: 600;
}
.btn-back:hover { color: var(--primary); background: rgba(108,92,231,0.08); }

.btn-hint {
  background: none;
  border: 2px dashed var(--warning);
  color: var(--text-light);
  padding: 8px 20px;
  font-size: 0.9rem;
  margin-top: 12px;
}
.btn-hint:hover { background: rgba(253,203,110,0.15); color: var(--text); }

.btn-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ===== CARDS ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  text-align: center;
}
.card-narrow { max-width: 440px; margin: 40px auto; }
.card-wide { max-width: 800px; margin: 20px auto; }

/* ===== WELCOME SCREEN ===== */
.welcome-header { padding: 48px 0 32px; }

.profile-select-area { text-align: center; }

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  margin: 20px 0;
}

.profile-card {
  background: var(--bg-card);
  border: 3px solid transparent;
  border-radius: var(--radius);
  padding: 20px 12px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
  text-align: center;
  position: relative;
}
.profile-card:hover {
  border-color: var(--primary-light);
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}
.profile-card .avatar { font-size: 3rem; display: block; margin-bottom: 8px; }
.profile-card .name { font-weight: 700; font-size: 1rem; }
.profile-card .streak-mini {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 4px;
}
.profile-card .delete-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  font-size: 1rem;
  color: var(--text-lighter);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 50%;
  line-height: 1;
}
.profile-card .delete-btn:hover { color: var(--danger); background: rgba(225,112,85,0.1); }

/* ===== CREATE PROFILE ===== */
label {
  display: block;
  text-align: left;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 6px;
  margin-top: 16px;
}

input[type="text"], input[type="number"] {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #dfe6e9;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}
input:focus { border-color: var(--primary-light); }

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin: 12px 0 20px;
}
.avatar-option {
  font-size: 2.2rem;
  padding: 10px;
  border: 3px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg);
}
.avatar-option:hover { background: rgba(108,92,231,0.08); }
.avatar-option.selected {
  border-color: var(--primary);
  background: rgba(108,92,231,0.08);
  transform: scale(1.1);
}

/* ===== DASHBOARD ===== */
.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 2px solid #f0f0f5;
}

.dash-profile {
  display: flex;
  align-items: center;
  gap: 14px;
}

.avatar-lg { font-size: 3rem; }

.dash-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: linear-gradient(135deg, #fdcb6e, #f39c12);
  color: #2d3436;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
}

.dash-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin: 20px 0;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
}
.stat-label {
  font-size: 0.8rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.class-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.class-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.25s;
  border-left: 5px solid var(--primary);
  position: relative;
  overflow: hidden;
}
.class-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}
.class-card .class-icon { font-size: 2.2rem; margin-bottom: 8px; }
.class-card .class-name { font-weight: 700; font-size: 1.05rem; margin-bottom: 4px; }
.class-card .class-topic { font-size: 0.85rem; color: var(--text-light); }
.class-card.completed-class { border-left-color: var(--success); }
.class-card.completed-class::after {
  content: '\2713';
  position: absolute;
  top: 12px;
  right: 14px;
  color: var(--success);
  font-size: 1.4rem;
  font-weight: 800;
}
.class-redo-hint {
  font-size: 0.78rem;
  color: var(--success);
  font-weight: 600;
  margin-top: 6px;
  opacity: 0.8;
}

.class-card.color-purple { border-left-color: #6C5CE7; }
.class-card.color-red { border-left-color: #FF6B6B; }
.class-card.color-green { border-left-color: #00b894; }
.class-card.color-blue { border-left-color: #0984e3; }
.class-card.color-orange { border-left-color: #e17055; }
.class-card.color-pink { border-left-color: #fd79a8; }
.class-card.color-teal { border-left-color: #00cec9; }
.class-card.color-yellow { border-left-color: #fdcb6e; }

/* Subject Sections */
.subject-section { margin-bottom: 8px; }
.subject-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-light);
  margin: 16px 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
}
.subject-section-icon { font-size: 1rem; }
.subject-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

/* Schedule Strip */
.schedule-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0;
}
.schedule-day {
  flex: 0 0 auto;
  min-width: 100px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  text-align: center;
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  border: 2px solid transparent;
}
.schedule-day.today {
  border-color: var(--primary);
  background: rgba(108,92,231,0.06);
}
.schedule-day .day-name { font-weight: 700; color: var(--text); }
.schedule-day .day-topic { color: var(--text-light); margin-top: 4px; font-size: 0.8rem; }
.schedule-day .day-status { margin-top: 6px; font-size: 1.1rem; }

/* ===== CLASS INTRO ===== */
.class-intro-icon { font-size: 4rem; margin: 16px 0; }
.class-desc { color: var(--text-light); font-size: 1.05rem; max-width: 500px; margin: 0 auto 16px; line-height: 1.6; }
.tip-box {
  background: rgba(253,203,110,0.15);
  border: 2px solid var(--warning);
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  margin: 16px auto;
  max-width: 500px;
  text-align: left;
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.5;
}
.tip-box::before { content: 'Tip: '; font-weight: 700; color: #e67e22; }
.tip-box:empty { display: none; }
.class-meta {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin: 16px 0;
  font-size: 0.9rem;
  color: var(--text-light);
}

/* ===== PROBLEM SCREEN ===== */
.problem-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}

.problem-progress { flex: 1; min-width: 150px; display: flex; align-items: center; gap: 10px; }
.progress-bar {
  flex: 1;
  height: 12px;
  background: #e9ecef;
  border-radius: 6px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 6px;
  transition: width 0.4s ease;
}
#problem-counter { font-weight: 700; font-size: 0.9rem; color: var(--text-light); white-space: nowrap; }

.problem-stars { font-size: 1.4rem; white-space: nowrap; }

.problem-area {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  text-align: center;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.problem-category-badge {
  display: inline-block;
  padding: 4px 14px;
  background: rgba(108,92,231,0.1);
  color: var(--primary);
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

.problem-question {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.6;
  margin-bottom: 20px;
  max-width: 600px;
}

.problem-visual {
  margin: 12px 0 20px;
  font-size: 1.8rem;
  line-height: 2;
}

.choices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 500px;
  margin-top: 8px;
}

.choice-btn {
  padding: 16px 20px;
  border: 3px solid #e9ecef;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}
.choice-btn:hover { border-color: var(--primary-light); background: rgba(108,92,231,0.04); }

.choice-btn.correct {
  border-color: var(--success);
  background: rgba(0,184,148,0.1);
  color: var(--success);
  animation: popIn 0.3s ease;
}
.choice-btn.incorrect {
  border-color: var(--danger);
  background: rgba(225,112,85,0.1);
  color: var(--danger);
  animation: shake 0.4s ease;
}
.choice-btn.disabled {
  pointer-events: none;
  opacity: 0.7;
}

/* Input Area */
.input-area {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
}
.answer-input {
  width: 120px !important;
  text-align: center;
  font-size: 1.4rem !important;
  font-weight: 700;
  padding: 12px !important;
}
.answer-input::-webkit-outer-spin-button,
.answer-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.answer-input[type=number] { -moz-appearance: textfield; }

/* Hint Box */
.hint-box {
  background: rgba(253,203,110,0.12);
  border: 1px solid var(--warning);
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  margin-top: 12px;
  font-size: 0.95rem;
  color: var(--text);
  max-width: 500px;
  line-height: 1.5;
  animation: fadeIn 0.3s ease;
}

/* ===== FEEDBACK OVERLAY ===== */
.feedback-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.feedback-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 36px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.3s ease;
}

.feedback-icon { font-size: 3.5rem; margin-bottom: 12px; }
.feedback-card h3 { font-size: 1.4rem; margin-bottom: 10px; }
.feedback-card p { color: var(--text-light); line-height: 1.6; }

.feedback-detail {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin: 16px 0;
  font-size: 0.95rem;
  text-align: left;
  line-height: 1.6;
}
.feedback-detail:empty { display: none; }

.feedback-card.correct-card { border-top: 5px solid var(--success); }
.feedback-card.incorrect-card { border-top: 5px solid var(--danger); }

/* ===== RESULTS SCREEN ===== */
.results-card { text-align: center; }

.results-header {
  margin-bottom: 20px;
}
.results-header .result-emoji { font-size: 4rem; margin-bottom: 8px; }
.results-header h2 { font-size: 1.6rem; }

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

.result-stat {
  text-align: center;
}
.result-stat .value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
}
.result-stat .label {
  font-size: 0.8rem;
  color: var(--text-light);
  text-transform: uppercase;
}

.results-breakdown {
  margin: 20px 0;
  text-align: left;
}
.result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 0.95rem;
}
.result-item.correct-item { background: rgba(0,184,148,0.08); }
.result-item.incorrect-item { background: rgba(225,112,85,0.08); }
.result-item .result-icon { font-size: 1.2rem; flex-shrink: 0; }
.result-item .result-text { flex: 1; }
.result-item .result-answer {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-light);
}

.results-feedback {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 18px 22px;
  margin: 16px 0;
  text-align: left;
  line-height: 1.7;
  font-size: 0.95rem;
}
.results-feedback:empty { display: none; }
.results-feedback h4 { margin-bottom: 8px; color: var(--primary); }
.results-feedback ul { padding-left: 20px; }
.results-feedback li { margin-bottom: 6px; }

/* ===== PROGRESS SCREEN ===== */
.progress-calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin: 16px 0;
}
.cal-header {
  text-align: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--text-light);
  padding: 4px;
}
.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--bg);
  position: relative;
}
.cal-day.today { border: 2px solid var(--primary); }
.cal-day.has-activity { background: rgba(0,184,148,0.15); color: var(--success); }
.cal-day.perfect { background: rgba(108,92,231,0.15); color: var(--primary); }
.cal-day.empty { background: transparent; }
.cal-day .cal-dot {
  width: 6px; height: 6px;
  background: var(--success);
  border-radius: 50%;
  position: absolute;
  bottom: 4px;
}
.cal-day.past-day { cursor: pointer; }
.cal-day.past-day:hover { background: var(--bg-card); box-shadow: var(--shadow); }
.cal-day.today { cursor: pointer; }

/* Calendar navigation */
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 6px;
}
.cal-nav-title { font-weight: 700; font-size: 1rem; }
.cal-nav-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.3rem;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text);
  transition: background 0.2s;
}
.cal-nav-btn:hover:not(:disabled) { background: var(--bg-card); }
.cal-nav-btn:disabled { opacity: 0.3; cursor: default; }

/* Past-day banner */
.past-day-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, rgba(108,92,231,0.12), rgba(0,184,148,0.10));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 12px;
  gap: 12px;
}
.past-day-label { font-weight: 600; font-size: 0.95rem; }

.progress-detail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin: 20px 0;
}

.topic-breakdown { margin-top: 20px; }
.topic-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f5;
}
.topic-row:last-child { border-bottom: none; }
.topic-icon { font-size: 1.4rem; flex-shrink: 0; }
.topic-info { flex: 1; }
.topic-name { font-weight: 600; font-size: 0.95rem; }
.topic-stats { font-size: 0.8rem; color: var(--text-light); }
.topic-bar {
  width: 120px;
  height: 8px;
  background: #e9ecef;
  border-radius: 4px;
  overflow: hidden;
}
.topic-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* ===== REVIEW SCREEN ===== */
.review-list { text-align: left; }

.review-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin-bottom: 12px;
  border-left: 4px solid var(--danger);
}
.review-item .review-q { font-weight: 700; font-size: 1rem; margin-bottom: 6px; }
.review-item .review-your-answer { color: var(--danger); font-size: 0.9rem; }
.review-item .review-correct { color: var(--success); font-weight: 600; font-size: 0.9rem; margin-top: 2px; }
.review-item .review-explanation {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #dfe6e9;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.5;
}

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-light);
  font-size: 1.1rem;
}

/* ===== CONFIRM DIALOG ===== */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.confirm-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 28px 32px;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.2s ease;
}
.confirm-card p { margin-bottom: 20px; font-size: 1.05rem; }

/* ===== FAMILY SETTINGS MODAL ===== */
.family-member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg, #f5f5ff);
  margin-bottom: 8px;
}
.family-member-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.family-member-email {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}
.family-member-badges {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.family-badge-owner {
  font-size: 0.72rem;
  background: linear-gradient(135deg, #f9a825, #f57f17);
  color: white;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 700;
}
.family-badge-you {
  font-size: 0.72rem;
  background: var(--primary, #6C63FF);
  color: white;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 700;
}
.family-member-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.btn-danger {
  background: #e74c3c;
  color: white;
  border: none;
}
.btn-danger:hover { background: #c0392b; }
.family-owner-note {
  font-size: 0.8rem;
  color: var(--text-light, #636e72);
  text-align: center;
  margin-top: 12px;
  padding: 8px 12px;
  background: #fff8e1;
  border-radius: 8px;
  border-left: 3px solid #f9a825;
}

/* ===== LEVEL BADGES ===== */
.level-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
}

.level-badge-large {
  display: inline-block;
  padding: 10px 28px;
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  border-radius: 30px;
  margin: 8px 0;
  box-shadow: 0 4px 15px rgba(108,92,231,0.3);
  animation: popIn 0.4s ease;
  letter-spacing: 0.5px;
}

.level-mini {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  background: rgba(108,92,231,0.12);
  color: var(--primary);
  border-radius: 10px;
  margin-top: 2px;
}

/* ===== ASSESSMENT SCREENS ===== */
.assessment-intro-icon {
  font-size: 4rem;
  margin-bottom: 8px;
  animation: bounce 1s ease infinite;
}

.assessment-meta-row {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 20px 0;
  flex-wrap: wrap;
}

.assessment-meta-item {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-light);
  padding: 14px 18px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  min-width: 90px;
  flex: 1;
  max-width: 120px;
}
.assessment-meta-item span {
  display: block;
  margin-top: 6px;
  font-weight: 600;
  font-size: 0.82rem;
}

/* ===== RESUME CARD ===== */
.resume-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, rgba(108,92,231,0.07), rgba(162,155,254,0.05));
  border: 2px solid var(--primary-light);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
  position: relative;
  animation: fadeIn 0.3s ease;
  cursor: default;
}

.resume-icon {
  font-size: 2.4rem;
  flex-shrink: 0;
}

.resume-info {
  flex: 1;
  text-align: left;
}

.resume-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.resume-meta {
  font-size: 0.82rem;
  color: var(--text-light);
  margin-top: 3px;
}

.resume-dismiss {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--text-lighter);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 50%;
  line-height: 1;
  transition: all 0.2s;
}
.resume-dismiss:hover { color: var(--danger); background: rgba(225,112,85,0.1); }

/* ===== DIFFICULTY INDICATOR (floating toast) ===== */
.difficulty-indicator {
  position: fixed;
  top: 80px;
  right: 24px;
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 0.95rem;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  z-index: 90;
  animation: popIn 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}

.difficulty-indicator.level-up {
  background: linear-gradient(135deg, var(--success), #00cec9);
  color: white;
}

.difficulty-indicator.level-down {
  background: linear-gradient(135deg, var(--warning), #f39c12);
  color: var(--text);
}

/* ===== TUTORIAL SCREEN ===== */
.tutorial-card {
  text-align: left;
}

.tutorial-badge {
  display: inline-block;
  padding: 6px 18px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 12px;
}

/* Step progress dots */
.step-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
}

.step-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #dfe6e9;
  transition: all 0.3s;
  flex-shrink: 0;
}

.step-dot.done {
  background: var(--success);
}

.step-dot.active {
  background: var(--primary);
  transform: scale(1.35);
  box-shadow: 0 0 0 3px rgba(108,92,231,0.2);
}

/* Tutorial step content box */
.tutorial-step-box {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin: 8px 0 16px;
  min-height: 130px;
}

.tutorial-step-text {
  font-size: 1.1rem;
  line-height: 1.75;
  color: var(--text);
  font-weight: 500;
  margin-bottom: 14px;
}

.tutorial-step-visual {
  font-size: 1.35rem;
  line-height: 1.8;
  text-align: center;
  color: var(--primary);
  font-weight: 700;
  white-space: pre-line;
  padding: 14px 18px;
  background: white;
  border-radius: var(--radius-sm);
  border: 2px solid var(--primary-light);
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tutorial-step-visual:empty { display: none; }

/* Tutorial practice header */
.tutorial-practice-header {
  text-align: center;
  margin-bottom: 12px;
  padding-bottom: 14px;
  border-bottom: 2px solid #f0f0f5;
}
.tutorial-practice-header h3 { margin-bottom: 4px; }

/* Practice result dots */
.practice-dots {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 8px 0;
}

.practice-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #f0f0f5;
  border: 2px solid #dfe6e9;
  transition: all 0.3s;
}

.practice-dot.active {
  background: rgba(108,92,231,0.12);
  border-color: var(--primary);
  transform: scale(1.2);
  box-shadow: 0 0 0 3px rgba(108,92,231,0.15);
}

.practice-dot.correct {
  background: var(--success);
  border-color: var(--success);
  animation: popIn 0.3s ease;
}

.practice-dot.incorrect {
  background: var(--danger);
  border-color: var(--danger);
  animation: shake 0.4s ease;
}

/* Tutorial inline feedback */
.tutorial-feedback {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  text-align: center;
  animation: fadeIn 0.2s ease;
  margin-top: 10px;
}

.tutorial-feedback.correct {
  background: rgba(0,184,148,0.1);
  color: var(--success);
  border: 1px solid rgba(0,184,148,0.3);
}

.tutorial-feedback.incorrect {
  background: rgba(225,112,85,0.1);
  color: var(--danger);
  border: 1px solid rgba(225,112,85,0.3);
}

/* Tutorial practice summary */
.tutorial-summary {
  text-align: center;
  padding: 20px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin: 12px 0;
  font-size: 1.05rem;
  line-height: 1.6;
}

/* Toast notification */
#app-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #2d3436;
  color: #fff;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 0.93rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  z-index: 9999;
  white-space: nowrap;
}
#app-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .logo { font-size: 2rem; }
  .screen { padding: 16px; }
  .card { padding: 20px; }
  .problem-question { font-size: 1.15rem; }
  .choices-grid { grid-template-columns: 1fr; }
  .dash-header { flex-direction: column; align-items: flex-start; }
  .dash-stats { grid-template-columns: repeat(2, 1fr); }
  .profile-grid { grid-template-columns: repeat(2, 1fr); }
  .avatar-grid { grid-template-columns: repeat(5, 1fr); }
  .progress-calendar { gap: 3px; }
  .cal-day { font-size: 0.7rem; }
  .resume-card { flex-wrap: wrap; }
  .assessment-meta-row { gap: 10px; }
  .assessment-meta-item { min-width: 80px; padding: 10px 12px; }
  .difficulty-indicator { top: auto; bottom: 24px; right: 16px; font-size: 0.85rem; }
  .tutorial-step-box { padding: 16px 18px; }
  .tutorial-step-text { font-size: 1rem; }
}

/* ===== WHITEBOARD MODAL ===== */
.whiteboard-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  animation: fadeIn 0.2s ease;
}
.whiteboard-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 28px 32px;
  max-width: 580px;
  width: 94%;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.25s ease;
}
.whiteboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--bg);
}
.whiteboard-content {
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
  gap: 16px;
}
.wb-question-review {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.wb-question-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.4;
}
.wb-choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.wb-choice {
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
}
.wb-choice-correct {
  background: rgba(0,184,148,0.15);
  border: 1.5px solid var(--success);
  color: var(--success);
}
.wb-choice-wrong {
  background: rgba(200,200,200,0.12);
  border: 1.5px solid var(--border);
  color: var(--text-light);
}
.wb-answer-reveal {
  font-size: 0.95rem;
  color: var(--success);
  font-weight: 600;
}
.wb-explanation {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--text-light);
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.whiteboard-content svg {
  max-width: 100%;
  height: auto;
}
.whiteboard-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-light);
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}
.whiteboard-close:hover { background: var(--bg); }

/* ===== LIBRARY SCREEN ===== */
.library-search {
  margin-bottom: 8px;
}
.library-search input {
  width: 100%;
  max-width: 420px;
}
.library-section-title {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-light);
  margin: 22px 0 10px;
  font-weight: 700;
}
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 8px;
}
.library-card {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  border-left: 4px solid #dfe6e9;
  transition: transform 0.15s, box-shadow 0.15s;
}
.library-card:hover:not(.locked) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.library-card.mastered    { border-left-color: var(--success); }
.library-card.in-progress { border-left-color: var(--warning); }
.library-card.not-started { border-left-color: #b2bec3; }
.library-card.locked      { border-left-color: #dfe6e9; opacity: 0.5; pointer-events: none; }
.library-grade-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  background: rgba(108, 92, 231, 0.1);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  margin-bottom: 7px;
}
.library-subject-name {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 8px;
  color: var(--text);
}
.library-progress-bar {
  height: 8px;
  background: #e9ecef;
  border-radius: 4px;
  overflow: hidden;
  margin: 6px 0;
}
.library-progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}
.library-progress-fill.mastery-high { background: var(--success); }
.library-progress-fill.mastery-mid  { background: var(--warning); }
.library-progress-fill.mastery-low  { background: var(--danger); }
.library-stats {
  font-size: 0.78rem;
  color: var(--text-light);
  margin-bottom: 12px;
}
.library-btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.library-btn-row .btn {
  font-size: 0.8rem;
  padding: 6px 12px;
}

/* ===== GRADE PROGRESS PANEL ===== */
.grade-progress-content {
  padding: 8px 0;
}
.grade-progress-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: rgba(108, 92, 231, 0.07);
  border-radius: var(--radius-sm);
}
.grade-progress-header .grade-icon {
  font-size: 2rem;
}
.grade-progress-header .grade-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
}
.grade-progress-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #f0f0f5;
}
.grade-progress-bar-row:last-of-type { border-bottom: none; }
.grade-subject-name {
  width: 140px;
  font-weight: 600;
  font-size: 0.88rem;
  flex-shrink: 0;
  color: var(--text);
}
.grade-bar-track {
  flex: 1;
  height: 10px;
  background: #e9ecef;
  border-radius: 5px;
  overflow: hidden;
}
.grade-bar-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.6s ease;
}
.grade-bar-fill.mastery-high { background: var(--success); }
.grade-bar-fill.mastery-mid  { background: var(--warning); }
.grade-bar-fill.mastery-low  { background: var(--danger); }
.grade-bar-fill.mastery-none { background: #dfe6e9; width: 0 !important; }
.grade-pct {
  font-size: 0.8rem;
  color: var(--text-light);
  width: 44px;
  text-align: right;
  flex-shrink: 0;
}
.grade-milestones {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #f0f0f5;
}
.grade-milestone-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  background: rgba(0, 184, 148, 0.1);
  border-radius: 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--success);
}

/* ===== ASSESSMENT GROWTH MESSAGE ===== */
.assessment-growth-msg {
  margin: 12px auto 0;
  padding: 12px 20px;
  background: rgba(0, 184, 148, 0.1);
  border: 2px solid var(--success);
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--success);
  max-width: 320px;
  text-align: center;
  animation: popIn 0.4s ease;
}

/* ===== LEVEL BADGE LARGE (assessment results) ===== */
.level-badge-large {
  display: inline-block;
  padding: 8px 24px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border-radius: 20px;
  font-size: 1.3rem;
  font-weight: 800;
  margin: 8px 0;
  letter-spacing: 0.5px;
}

@media (max-width: 600px) {
  .library-grid { grid-template-columns: 1fr; }
  .grade-subject-name { width: 100px; font-size: 0.8rem; }
  .whiteboard-card { padding: 20px 18px; }
}

/* ===== AUTH SCREEN ===== */
#screen-auth.active {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}
.auth-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 48px 40px;
  text-align: center;
  max-width: 380px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}
.auth-logo { font-size: 4rem; margin-bottom: 16px; }
.auth-card h1 { font-size: 1.6rem; margin-bottom: 12px; color: var(--text); }
.auth-card p  { color: var(--text-light); margin-bottom: 32px; line-height: 1.5; }
#btn-google-signin {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

/* Family name on welcome screen */
.family-name-display {
  font-size: 0.85rem;
  color: var(--text-lighter);
  letter-spacing: 0.5px;
  margin-top: 4px;
  min-height: 1.2em;
}

/* ===================================================================
   MANDARIN INTERACTIVE EXERCISES
   =================================================================== */

/* --- Audio Play Button (listen-mc, listen-write) --- */
#listen-mc-area {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}
.btn-play-audio {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #4834d4);
  color: white;
  font-size: 2rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(108,92,231,0.35);
  transition: transform 0.15s, box-shadow 0.15s;
  touch-action: manipulation;
  margin: 8px auto;
}
.btn-play-audio span {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.btn-play-audio:active { transform: scale(0.91); box-shadow: 0 3px 10px rgba(108,92,231,0.3); }
.btn-play-audio-small {
  width: 72px;
  height: 72px;
  font-size: 1.5rem;
}

/* --- Canvas Drawing Pad (listen-write) --- */
#listen-write-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
/* Meaning + pinyin label shown above canvas on listen-write problems */
.listen-write-meaning {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
  padding: 8px 16px;
  background: rgba(108, 92, 231, 0.08);
  border-radius: 12px;
  border: 2px solid rgba(108, 92, 231, 0.2);
}
.lw-meaning-word {
  color: var(--primary);
}
.lw-meaning-pinyin {
  color: var(--text-light);
  font-size: 1rem;
  font-weight: 400;
  margin-left: 4px;
}
.canvas-wrapper {
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
}
#drawing-canvas {
  display: block;
  width: 100%;
  max-width: 300px;
  height: auto;
  aspect-ratio: 1;
  border: 3px solid var(--primary-light, #a29bfe);
  border-radius: var(--radius, 12px);
  background: #fff;
  touch-action: none;
  cursor: crosshair;
  box-shadow: var(--shadow, 0 2px 8px rgba(0,0,0,.08));
}
.canvas-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.self-grade-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  animation: fadeIn 0.25s ease;
}
.self-grade-prompt {
  font-size: 1rem;
  color: var(--text-light);
  font-weight: 600;
  margin: 0;
}
.btn-self-grade {
  font-size: 1.2rem;
  padding: 14px 36px;
  min-width: 140px;
  border-radius: var(--radius, 12px);
}
.btn-success { background: var(--success, #00b894); color: white; border: none; }
.btn-danger  { background: var(--danger, #e17055);  color: white; border: none; }

/* --- Speak (mic button + character display) --- */
#speak-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.speak-char-display {
  font-size: 5rem;
  line-height: 1.2;
  font-weight: 700;
  text-align: center;
  margin: 4px 0 4px;
  transition: font-size 0.2s;
}
/* Char-only mode: bigger since it's the sole visual cue */
.speak-char-display.speak-char-solo {
  font-size: 7rem;
  margin-bottom: 8px;
}
/* Pinyin display — shown in 'pinyin' and 'both' modes */
.speak-pinyin-display {
  font-size: 2.2rem;
  font-weight: 700;
  text-align: center;
  color: var(--primary);
  letter-spacing: 2px;
  margin: 4px 0;
  font-family: 'Georgia', serif;
}
/* Pinyin-only mode: even larger */
.speak-pinyin-display.speak-pinyin-solo {
  font-size: 3.2rem;
  margin-bottom: 6px;
}
/* Meaning shown as soft context label */
.speak-meaning-label {
  font-size: 0.9rem;
  color: var(--text-light);
  text-align: center;
  margin: 0 0 8px;
  font-style: italic;
}
.btn-mic {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e17055, #d63031);
  color: white;
  font-size: 2rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(225,112,85,0.4);
  transition: transform 0.15s, box-shadow 0.15s;
  touch-action: manipulation;
  margin: 4px auto;
}
.btn-mic span {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.btn-mic:active { transform: scale(0.91); }
.btn-mic.listening {
  background: linear-gradient(135deg, #fd79a8, #e84393);
  animation: micPulse 1s ease-in-out infinite;
  position: relative;
}
/* Radiating ring so child clearly sees "mic is on" */
.btn-mic.listening::after {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 3px solid rgba(232,67,147,0.6);
  animation: micRing 1.4s ease-out infinite;
  pointer-events: none;
}
.btn-mic:disabled { cursor: default; }
@keyframes micPulse {
  0%, 100% { transform: scale(1);    box-shadow: 0 6px 20px rgba(225,112,85,0.4); }
  50%      { transform: scale(1.08); box-shadow: 0 6px 36px rgba(232,67,147,0.7); }
}
@keyframes micRing {
  0%   { inset: -8px;  opacity: 0.7; }
  100% { inset: -28px; opacity: 0;   }
}
/* Speak Up! — “heard you, now scoring” (covers Azure / network delay) */
.speak-progress {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 12px auto 4px;
  padding: 14px 16px;
  max-width: 300px;
  border-radius: 16px;
  background: linear-gradient(160deg, rgba(46, 204, 113, 0.14), rgba(52, 152, 219, 0.1));
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.06);
}
.speak-progress--heard {
  animation: speakProgressPop 0.38s ease;
}
.speak-progress-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
}
.speak-progress-caption {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.35;
  color: var(--text);
}
.speak-check-badge {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(145deg, #2ecc71, #27ae60);
  color: #fff;
  font-size: 1.45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(39, 174, 96, 0.35);
}
.speak-spinner-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  height: 22px;
}
.speak-spinner-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary, #6c5ce7);
  opacity: 0.35;
  animation: speakDotBounce 0.55s ease-in-out infinite;
}
.speak-spinner-dots i:nth-child(2) { animation-delay: 0.12s; }
.speak-spinner-dots i:nth-child(3) { animation-delay: 0.24s; }
@keyframes speakDotBounce {
  0%, 100% { transform: translateY(0); opacity: 0.35; }
  50%      { transform: translateY(-6px); opacity: 1; }
}
@keyframes speakProgressPop {
  0%   { transform: scale(0.92); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.speak-status {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  min-height: 1.6em;
  margin: 6px 0;
  transition: color 0.2s;
}
.speak-result {
  font-size: 0.9rem;
  color: var(--text);
  background: rgba(108,92,231,0.07);
  border-radius: var(--radius-sm, 8px);
  padding: 8px 14px;
  text-align: center;
  max-width: 300px;
}
.speak-retry-btns {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  justify-content: center;
}
.btn-speak-replay, .btn-speak-retry, .btn-speak-next {
  padding: 10px 20px;
  border: none;
  border-radius: 24px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s;
}
.btn-speak-replay:active, .btn-speak-retry:active, .btn-speak-next:active { transform: scale(0.93); }
.btn-speak-replay {
  background: #74b9ff;
  color: #fff;
}
.btn-speak-retry {
  background: #00b894;
  color: #fff;
}
.btn-speak-next {
  background: #a29bfe;
  color: #fff;
}

/* --- Match Grid --- */
#match-area {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
}
.match-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}
.match-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.match-item {
  padding: 14px 10px;
  border: 3px solid #e9ecef;
  border-radius: var(--radius-sm, 8px);
  background: var(--bg-card, #fff);
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
  text-align: center;
  touch-action: manipulation;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
}
.match-item:hover:not(.matched):not(.wrong) { border-color: var(--primary-light, #a29bfe); }
.match-item:active:not(.matched) { transform: scale(0.95); }
.match-item.selected {
  border-color: var(--primary, #6c5ce7);
  background: rgba(108,92,231,0.1);
  transform: scale(1.04);
  box-shadow: 0 0 0 3px rgba(108,92,231,0.25);
}
.match-item.matched {
  border-color: var(--success, #00b894);
  background: rgba(0,184,148,0.1);
  color: var(--success, #00b894);
  opacity: 0.65;
  pointer-events: none;
}
.match-item.wrong {
  border-color: var(--danger, #e17055);
  background: rgba(225,112,85,0.1);
  animation: matchShake 0.4s ease;
}
@keyframes matchShake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}
.match-status {
  text-align: center;
  margin-top: 10px;
  font-size: 0.95rem;
  color: var(--text-light);
  min-height: 1.4em;
}

/* ===== MANDARIN CHAT ===== */
/* ── Chat window ── */
.ma-chat-window {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  height: 420px;
  overflow-y: auto;
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
@media (max-width: 480px) { .ma-chat-window { height: 340px; } }

/* ── Message bubbles ── */
.ma-msg { max-width: 80%; padding: 12px 16px; border-radius: 16px; font-size: 0.95rem; line-height: 1.6; }
.ma-msg-ai     { background: #FECACA; color: var(--text); border-bottom-left-radius: 4px; align-self: flex-start; }
.ma-msg-user   { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; align-self: flex-end; }
.ma-msg-system { font-size: 0.8rem; color: var(--text-light); text-align: center; align-self: center; font-style: italic; }
.ma-msg-loading { align-self: flex-start; }

/* EN translation toggle */
.ma-msg-translation {
  font-size: 0.78rem; color: var(--primary); margin-top: 6px;
  cursor: pointer; border-top: 1px solid rgba(0,0,0,0.08); padding-top: 4px;
  display: block;
}
.ma-msg-translation.visible { color: var(--text-light); cursor: default; }

/* Karaoke word highlight */
.ma-speak-char { display: inline; border-radius: 3px; transition: background 0.08s; }
.ma-speak-char.speaking { background: #FEF08A; color: #78350F; }

/* Dots loader */
.ma-dots { display: flex; gap: 4px; padding: 10px 14px; background: #FECACA; border-radius: 16px; border-bottom-left-radius: 4px; }
.ma-dot  { width: 7px; height: 7px; background: var(--primary); border-radius: 50%; animation: maDotBounce 1.2s infinite; }
.ma-dot:nth-child(2) { animation-delay: 0.2s; }
.ma-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes maDotBounce { 0%,80%,100% { transform:scale(0.6); opacity:0.5; } 40% { transform:scale(1); opacity:1; } }

/* ── Chat input ── */
.ma-chat-input-area { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 8px; }
.ma-chat-textarea {
  flex: 1; border: 2px solid #d0d8ff; border-radius: 12px;
  padding: 12px 14px; font-size: 1rem; font-family: var(--font);
  outline: none; resize: none; transition: border-color 0.2s;
  min-height: 46px; max-height: 120px;
}
.ma-chat-textarea:focus { border-color: var(--primary); }
.ma-send-btn {
  width: 48px; height: 48px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; font-size: 1.2rem;
  cursor: pointer; flex-shrink: 0; transition: background 0.2s;
}
.ma-send-btn:hover    { background: var(--primary-dark); }
.ma-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Mic bar ── */
.ma-mic-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: #f8f9ff;
  border-radius: 12px; border: 1.5px solid #d0d8ff;
  flex-wrap: wrap;
}
.ma-mic-indicator { font-size: 1.5rem; flex-shrink: 0; }
.ma-mic-indicator.listening { animation: maMicPulse 1.4s ease-in-out infinite; }
.ma-mic-indicator.muted     { opacity: 0.3; }
@keyframes maMicPulse { 0%,100% { opacity:1; } 50% { opacity:0.35; } }
.ma-mic-status        { flex: 1; font-size: 0.82rem; color: var(--text-light); min-width: 80px; }
.ma-mic-status.active { color: var(--primary); font-weight: 500; }
.ma-mic-bar-btns      { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Session timer ── */
.ma-timer-row { text-align: center; margin: 4px 0 10px; }
.ma-chat-timer {
  display: inline-block;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--primary);
  background: #f0f3ff;
  border-radius: 10px;
  padding: 4px 18px;
}

/* ===== COMPANION CLASS CARDS (Logic in Math, Spirit in English) ===== */
.class-card--companion {
  text-decoration: none;
  display: block;
  border-style: dashed;
  opacity: 0.8;
}
.class-card--companion:hover { opacity: 1; }

/* ===== TREEHOUSE FEATURED LINK ===== */
.treehouse-featured-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: linear-gradient(135deg, #e8f8f4, #d5f5ec);
  border: 2px solid var(--success);
  border-radius: 14px;
  text-decoration: none;
  color: var(--text);
  margin-bottom: 12px;
  transition: box-shadow 0.15s, transform 0.15s;
}
.treehouse-featured-link:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.treehouse-featured-icon { font-size: 2rem; flex-shrink: 0; }
.treehouse-featured-body { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.treehouse-featured-body strong { font-size: 1rem; font-weight: 600; }
.treehouse-featured-body span { font-size: 0.82rem; color: var(--text-light); }
.treehouse-featured-arrow { font-size: 0.9rem; font-weight: 600; color: var(--success); white-space: nowrap; }

/* ===== OPTIONAL EXTRAS ===== */
.optional-extras-section {
  max-width: 600px;
  margin: 0 auto 32px;
  padding: 0 16px;
}
.optional-extras-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.optional-extras-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  background: #f0f4ff;
  color: #3a3a6a;
  border-radius: 20px;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  border: 1.5px solid #d0d8ff;
  transition: background 0.15s;
}
.optional-extras-link:hover { background: #e0e8ff; }

/* ===== OFFLINE BANNER ===== */
#offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  background: var(--warning, #fdcb6e);
  color: var(--text, #2d3436);
  text-align: center;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
body.is-offline {
  padding-top: 38px;
}

/* ===== SCHOOL TOPICS ===== */
.school-topic-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.school-topic-input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--border, #e0e0e0);
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.school-topic-input:focus {
  border-color: var(--primary, #6C63FF);
}
.school-topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 32px;
}
.school-topic-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light, #ede9ff);
  color: var(--primary-dark, #4a3fa0);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.88rem;
  font-weight: 600;
}
.school-topic-chip button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--primary-dark, #4a3fa0);
  padding: 0;
  line-height: 1;
}
.school-topic-tag {
  padding: 8px 14px;
  border-radius: 20px;
  border: 2px solid var(--border, #e0e0e0);
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s;
}
.school-topic-tag.active {
  background: var(--primary, #6C63FF);
  color: #fff;
  border-color: var(--primary, #6C63FF);
}
.learning-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.learning-log-entry {
  background: var(--bg, #f5f5ff);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.88rem;
}
.log-entry-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}
.log-date {
  color: var(--text-light, #636e72);
  font-size: 0.82rem;
}
.log-entry-score {
  color: var(--text, #2d3436);
  margin-bottom: 2px;
}
.log-entry-topics {
  color: var(--text-light, #636e72);
  font-size: 0.82rem;
}
.log-reinforced-badge {
  display: inline-block;
  background: #d1fae5;
  color: #065F46;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  margin-left: 6px;
}
