*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-app: #F5F5F0;
  --bg-surface: #FFFFFF;
  --bg-dark: #1A1A2E;
  --bg-dark-hover: #25253E;
  --text-on-dark: #E8E8E8;
  --text-muted-dark: #9090A0;

  --green: #4CAF50;
  --green-dark: #3D8B40;
  --green-bg: #E8F5E9;
  --red: #E53935;
  --red-dark: #C62828;
  --red-bg: #FFEBEE;
  --accent: #3B5998;
  --accent-dark: #2D4373;
  --accent-bg: #EBF0FA;
  --gold: #D4A017;

  --white: #FFFFFF;
  --snow: #EDEDEA;
  --border: #E0E0E0;
  --border-dark: #CCCCCC;
  --disabled: #E5E5E5;
  --disabled-text: #AFAFAF;
  --text2: #7A7A8A;
  --text: #2D2D2D;
  --text-dark: #1A1A1A;

  --learning: #D4A017;
  --reviewing: #3B5998;
  --mastered: #4CAF50;
  --lapsed: #E53935;
  --unseen: #E0E0E0;
}

body {
  background: var(--bg-app);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  font-weight: 450;
  -webkit-font-smoothing: antialiased;
}

/* ================================================================
   App Shell — Sidebar + Content
   ================================================================ */
#app-shell {
  display: flex;
  min-height: 100dvh;
}

#sidebar {
  display: none;
}

#app-content {
  flex: 1;
  min-width: 0;
}

@media (min-width: 900px) {
  #sidebar {
    display: flex;
    flex-direction: column;
    width: 220px;
    flex-shrink: 0;
    background: var(--bg-dark);
    color: var(--text-on-dark);
    padding: 24px 0;
    position: sticky;
    top: 0;
    height: 100dvh;
    overflow-y: auto;
  }
  .sidebar-brand {
    font-size: 18px;
    font-weight: 700;
    padding: 0 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 12px;
  }
  .sidebar-link {
    display: block;
    padding: 9px 20px;
    color: var(--text-muted-dark);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    border-left: 3px solid transparent;
  }
  .sidebar-link:hover {
    color: var(--text-on-dark);
    background: var(--bg-dark-hover);
  }
  .sidebar-link.active {
    color: #FFFFFF;
    border-left-color: var(--accent);
    background: var(--bg-dark-hover);
  }
  .sidebar-footer {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
  }
  .sidebar-user {
    padding: 6px 20px;
    font-size: 13px;
    color: var(--text-muted-dark);
  }

  /* Hide mobile top-bar elements when sidebar present */
  #logout-btn { display: none; }
  .top-bar h1 { display: none; }
}

/* ================================================================
   Mobile Tab Bar
   ================================================================ */
#mobile-tabs {
  display: none;
}
@media (max-width: 899px) {
  #mobile-tabs {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    z-index: 50;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mobile-tab {
    flex: 1;
    text-align: center;
    padding: 10px 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--text2);
    cursor: pointer;
    text-decoration: none;
    border-top: 2px solid transparent;
  }
  .mobile-tab.active {
    color: var(--accent);
    border-top-color: var(--accent);
  }
  /* Pad bottom of screens to clear tab bar */
  #screen-dashboard .container,
  #screen-leaderboard .container,
  #screen-progress .container {
    padding-bottom: 60px;
  }
}

/* ================================================================
   Button System — flat, no 3D, sentence case
   ================================================================ */
.duo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: 3px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
  transition: background 0.15s;
}
.duo-btn:active:not(:disabled) {
  opacity: 0.9;
  transform: translateY(1px);
}
.duo-btn:disabled {
  background: var(--disabled);
  color: var(--disabled-text);
  cursor: default;
}

.duo-btn-green { background: var(--green); color: white; }
.duo-btn-green:hover:not(:disabled) { background: var(--green-dark); }

.duo-btn-blue { background: var(--accent); color: white; }
.duo-btn-blue:hover:not(:disabled) { background: var(--accent-dark); }

.duo-btn-red { background: var(--red); color: white; }
.duo-btn-red:hover:not(:disabled) { background: var(--red-dark); }

.duo-btn-outline {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--accent);
}
.duo-btn-outline:hover:not(:disabled) { background: var(--snow); }

.duo-btn-sm { padding: 8px 16px; font-size: 13px; }

.duo-btn-full { width: 100%; }

/* ================================================================
   Option Cards — flat, no 3D
   ================================================================ */
.option-card {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  margin-bottom: 6px;
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 450;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
  text-align: left;
}
.option-card:hover:not(.locked) {
  transform: translateY(-1px);
}
.option-card:active:not(.locked) {
  background: var(--snow);
  transform: translateY(0);
}
.option-card.selected {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.option-card.correct {
  border-color: var(--green);
  background: var(--green-bg);
}
.option-card.incorrect {
  border-color: var(--red);
  background: var(--red-bg);
}
.option-card.locked { cursor: default; }
.option-letter {
  font-weight: 600;
  margin-right: 12px;
  color: var(--text2);
  min-width: 20px;
}
.option-card.selected .option-letter { color: var(--accent-dark); }
.option-card.correct .option-letter { color: var(--green-dark); }
.option-card.incorrect .option-letter { color: var(--red-dark); }

/* ================================================================
   Layout
   ================================================================ */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px 20px;
}

@media (min-width: 900px) {
  .container {
    max-width: 800px;
    padding: 24px 32px;
  }
}

#screen-dashboard .container { max-width: 1100px; }
#screen-progress .container { max-width: 900px; }
@media (min-width: 1400px) {
  #screen-dashboard .container { max-width: 1280px; }
}

.screen { display: none; }
.screen.active { display: flex; flex-direction: column; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ================================================================
   Auth
   ================================================================ */
#screen-auth {
  min-height: 100dvh;
  justify-content: center;
  align-items: center;
  background: var(--bg-dark);
}
#auth-form {
  width: 100%;
  max-width: 340px;
  padding: 0 16px;
}
#auth-form h1 {
  font-size: 28px;
  font-weight: 800;
  color: #FFFFFF;
  text-align: center;
  margin-bottom: 32px;
}
#auth-form input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 3px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: rgba(255,255,255,0.95);
  outline: none;
  margin-bottom: 10px;
}
#auth-form input:focus { border-color: var(--accent); }
#auth-form input::placeholder { color: var(--disabled-text); }

#auth-error {
  color: #FF6B6B;
  font-size: 14px;
  text-align: center;
  margin-top: 8px;
  min-height: 20px;
}
.auth-toggle {
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-muted-dark);
}
.auth-toggle span {
  color: var(--text-on-dark);
  cursor: pointer;
  font-weight: 600;
}

/* ================================================================
   Top bar (dashboard/progress) — mobile only
   ================================================================ */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  margin-bottom: 16px;
}
.top-bar h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-dark);
}
.top-bar-link {
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

/* Dashboard skeleton loading */
.dashboard-skeleton {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 580px) {
  .dashboard-skeleton { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1100px) {
  .dashboard-skeleton { grid-template-columns: repeat(3, 1fr); gap: 14px; }
}
.skeleton-card {
  height: 140px;
  background: var(--border);
  border-radius: 3px;
  opacity: 0.6;
  animation: skeleton-pulse 1.2s ease-in-out infinite;
}
@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.8; }
}
.dashboard-error {
  padding: 24px;
  text-align: center;
}

.resume-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: var(--accent-bg);
  border: 1px solid var(--accent);
  border-radius: 3px;
  font-size: 14px;
}
.resume-banner span { color: var(--text); }

/* ================================================================
   Dashboard — Subject cards
   ================================================================ */
.subjects-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 580px) {
  .subjects-list { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1100px) {
  .subjects-list { grid-template-columns: repeat(3, 1fr); gap: 14px; }
}

.subject-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 14px 16px;
  transition: border-color 0.15s, transform 0.15s;
}
.subject-card:hover {
  border-color: var(--border-dark);
  transform: translateY(-1px);
}

.subject-top {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.mastery-ring {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}
.mastery-ring-inner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
}

.subject-info { flex: 1; min-width: 0; }
.subject-name { font-size: 17px; font-weight: 600; color: var(--text-dark); }
.subject-description {
  font-size: 13px;
  color: var(--text2);
  margin-top: 3px;
  line-height: 1.4;
}
.subject-stats {
  font-size: 13px;
  color: var(--text2);
  margin-top: 2px;
}

/* Segmented mastery bar */
.mastery-bar {
  display: flex;
  height: 8px;
  border-radius: 2px;
  overflow: hidden;
  background: var(--unseen);
  margin-bottom: 8px;
}
.mastery-bar .seg {
  height: 100%;
  transition: width 0.4s;
}
.seg-mastered { background: var(--mastered); }
.seg-reviewing { background: var(--reviewing); }
.seg-learning { background: var(--learning); }
.seg-lapsed { background: var(--lapsed); }

/* Legend (used in progress screen) */
.mastery-legend, .progress-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 12px;
}
.mastery-legend span, .progress-legend span {
  display: flex;
  align-items: center;
  gap: 4px;
}
.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

/* Compact stats row (dashboard cards) */
.mastery-stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 10px;
}
.ms-item {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.ms-item::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 1px;
}
.ms-mastered::before { background: var(--mastered); }
.ms-mastered { color: var(--mastered); }
.ms-reviewing::before { background: var(--reviewing); }
.ms-reviewing { color: var(--reviewing); }
.ms-learning::before { background: var(--learning); }
.ms-learning { color: var(--learning); }
.ms-lapsed::before { background: var(--lapsed); }
.ms-lapsed { color: var(--lapsed); }
.ms-unseen::before { background: var(--unseen); }
.ms-unseen { color: var(--text2); }

/* Subject action buttons */
.subject-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.subject-actions .duo-btn { flex: 1; }
.subject-actions .count-select { flex-shrink: 0; }

/* Available (unenrolled) cards */
.subject-card-available {
  border-style: dashed;
  opacity: 0.85;
}
.subject-card-available:hover {
  opacity: 1;
  border-style: solid;
}

/* Session count selector */
.count-select {
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-surface);
  outline: none;
  cursor: pointer;
}

/* Locked / available cards */
.subject-card.locked { opacity: 0.5; }
.prereq-info {
  font-size: 13px;
  color: var(--text2);
  margin-top: 8px;
}
.prereq-bar-track {
  height: 4px;
  background: var(--unseen);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 6px;
}
.prereq-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

/* ================================================================
   Quiz — Fixed layout
   ================================================================ */
#screen-quiz.active {
  position: fixed;
  inset: 0;
  background: var(--bg-app);
  z-index: 100;
  overflow-y: auto;
}

.quiz-top-bar {
  position: sticky;
  top: 0;
  background: var(--bg-app);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  z-index: 10;
}
.quiz-close {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--border-dark);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  padding: 0;
}
.quiz-close:hover { background: var(--border); color: var(--text2); }

.quiz-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.quiz-progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.4s ease;
}

.quiz-body {
  max-width: 600px;
  margin: 0 auto;
  padding: 8px 16px 120px;
  width: 100%;
}

@media (min-width: 900px) {
  .quiz-body { max-width: 720px; }
  .quiz-bottom-inner { max-width: 720px; }
  .feedback-banner-inner { max-width: 720px; }
}

.quiz-meta {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 8px;
}
.quiz-question {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-dark);
  line-height: 1.35;
  margin-bottom: 24px;
}
@media (max-width: 579px) {
  .quiz-question { font-size: 20px; }
}

.quiz-options { margin-bottom: 16px; }

/* Fixed bottom bar */
.quiz-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-app);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
}
.quiz-bottom-inner {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.voice-toggle, .mic-btn {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--text2);
  flex-shrink: 0;
}
.voice-toggle.active { color: var(--accent); border-color: var(--accent); }
.mic-btn.listening { color: var(--red); border-color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.5; } }

/* Feedback banner (replaces bottom bar) */
.feedback-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 16px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 30;
  animation: slideUp 0.3s ease-out;
}
.feedback-banner-inner {
  max-width: 600px;
  margin: 0 auto;
}
.feedback-banner.correct-fb {
  background: var(--green-bg);
}
.feedback-banner.incorrect-fb {
  background: var(--red-bg);
}
.feedback-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}
.feedback-banner.correct-fb .feedback-title { color: var(--green); }
.feedback-banner.incorrect-fb .feedback-title { color: var(--red); }

.feedback-explanation {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 4px;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
}
.feedback-clearance {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cl-dots { display: flex; gap: 3px; }
.cl-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border);
}
.cl-dot.cl-filled { background: var(--accent); }
.clearance-progress {
  color: var(--accent);
  font-weight: 600;
}
.feedback-status {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 12px;
}
.feedback-banner .duo-btn { width: 100%; }

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ================================================================
   Intro / Corrective cards
   ================================================================ */
.teach-card {
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 20px;
  margin-bottom: 20px;
}
.teach-card.intro { border-left: 4px solid var(--accent); background: var(--accent-bg); }
.teach-card.corrective { border-left: 4px solid var(--red); background: var(--red-bg); }

.teach-card-type {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}
.teach-card.intro .teach-card-type { color: var(--accent-dark); }
.teach-card.corrective .teach-card-type { color: var(--red); }

.teach-card-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 12px;
}
.lesson-image, .teach-card-image { margin: 12px 0; text-align: center; }
.lesson-image img, .teach-card-image img { max-width: 100%; max-height: 280px; border-radius: 3px; }
.teach-fact {
  padding: 8px 0;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  font-size: 15px;
  line-height: 1.6;
}
.teach-fact:last-child { border-bottom: none; }
.teach-fact-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
}
.teach-fact-value { color: var(--text-dark); font-weight: 450; }
.teach-fact-prose { line-height: 1.5; font-size: 0.95rem; font-weight: 400; color: var(--text2); }

.teach-footer {
  font-size: 13px;
  color: var(--text2);
  margin-top: 8px;
  margin-bottom: 12px;
}

/* ================================================================
   Summary / Celebration
   ================================================================ */
#screen-summary .container { text-align: center; padding-top: 40px; }

.summary-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 8px;
}
.summary-accuracy {
  font-size: 52px;
  font-weight: 800;
  margin: 16px 0;
}
.summary-accuracy.good { color: var(--green); }
.summary-accuracy.ok { color: var(--gold); }
.summary-accuracy.bad { color: var(--red); }

.summary-stats {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 16px 20px;
  margin: 20px auto;
  max-width: 360px;
  text-align: left;
}
.summary-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  max-width: 340px;
  margin: 0 auto;
}
.summary-stat {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.summary-stat:last-child { border-bottom: none; }
.summary-stat-label { color: var(--text2); }
.summary-stat-value { font-weight: 600; color: var(--text-dark); }

.summary-changes {
  max-width: 360px;
  margin: 16px auto;
  text-align: left;
}
.summary-changes h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 8px;
}
.change-row {
  font-size: 13px;
  padding: 4px 0;
  color: var(--text2);
}
.change-arrow { color: var(--text); margin: 0 4px; }

/* ================================================================
   Progress view
   ================================================================ */
.progress-overview {
  text-align: center;
  margin-bottom: 20px;
}
.progress-pct {
  font-size: 36px;
  font-weight: 800;
  color: var(--text-dark);
}
.progress-bar-large {
  height: 10px;
  border-radius: 2px;
  overflow: hidden;
  background: var(--unseen);
  margin: 12px 0;
}
.progress-bar-large .seg { height: 100%; }

.progress-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 8px;
}
.progress-legend span {
  display: flex;
  align-items: center;
  gap: 4px;
}
.progress-legend .legend-dot { width: 8px; height: 8px; border-radius: 2px; }

.progress-meta {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 20px;
}

/* Topics grid */
.topics-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 580px) {
  .topics-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 900px) {
  .topics-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
}

.topic-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.topic-card:hover {
  border-color: var(--border-dark);
  transform: translateY(-1px);
}
.topic-card.locked { opacity: 0.4; pointer-events: none; }

.topic-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.topic-ring {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.topic-ring-inner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--text);
}
.topic-name { font-size: 14px; font-weight: 600; color: var(--text-dark); }
.topic-meta { font-size: 12px; color: var(--text2); }

.step-bars {
  display: flex;
  gap: 2px;
  margin-top: 6px;
}
.step-bar {
  flex: 1;
  height: 3px;
  border-radius: 1px;
  background: var(--unseen);
}
.step-bar.done { background: var(--mastered); }
.step-bar.current { background: var(--accent); }

/* Subtopic rows inside topic cards */
.subtopic-toggle {
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  margin-top: 6px;
  font-weight: 500;
}
.subtopic-rows {
  margin-top: 6px;
}
.subtopic-row {
  position: relative;
  padding: 6px 8px;
  margin-bottom: 2px;
  border-radius: 2px;
  overflow: hidden;
  background: var(--bg-surface);
}
.subtopic-bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--green-bg);
  border-radius: 2px 0 0 2px;
  transition: width 0.3s ease;
}
.subtopic-row.mastered .subtopic-bar {
  background: var(--green-bg);
}
.subtopic-row.unseen .subtopic-bar {
  background: transparent;
}
.subtopic-info {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.subtopic-name {
  font-size: 13px;
  color: var(--text);
  font-weight: 450;
}
.subtopic-stat {
  font-size: 12px;
  color: var(--text2);
  font-weight: 500;
}

.topic-lock-reason {
  font-size: 12px;
  color: var(--text2);
  margin-top: 6px;
}

/* ================================================================
   Phase badge
   ================================================================ */
.phase-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 2px;
  font-size: 11px;
  font-weight: 600;
}
.phase-badge.review { background: var(--accent-bg); color: var(--accent-dark); }
.phase-badge.learn { background: var(--green-bg); color: var(--green-dark); }

/* ================================================================
   Toast
   ================================================================ */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 3px;
  font-size: 14px;
  font-weight: 600;
  z-index: 1000;
  animation: toastIn 0.3s ease;
}
.toast-success { background: var(--green); color: white; }
.toast-error { background: var(--red); color: white; }
@keyframes toastIn {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ================================================================
   Confetti
   ================================================================ */
@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ================================================================
   Step Lesson
   ================================================================ */
.lesson-body {
  max-width: 540px;
  margin: 0 auto;
  padding: 0 20px 120px;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - 140px);
}

@media (min-width: 900px) {
  .lesson-body { max-width: 640px; }
}

/* Hook screen */
.lesson-hook {
  text-align: left;
  padding: 48px 0 20px;
}
.lesson-hook-text {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-dark);
  line-height: 1.25;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 4px solid var(--text-dark);
}
.lesson-hook-context {
  font-size: 17px;
  color: var(--text2);
  line-height: 1.6;
  font-weight: 450;
}

/* Teach screen */
.lesson-teach-heading {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 20px;
  line-height: 1.3;
}
.lesson-point {
  font-size: 17px;
  line-height: 1.7;
  color: var(--text);
  font-weight: 450;
  padding: 12px 16px;
  margin-bottom: 2px;
  background: var(--bg-surface);
  border-radius: 2px;
  border-left: none;
}
.lesson-point:nth-child(even) {
  background: transparent;
}
.lesson-point.caution {
  border-left: 3px solid var(--red);
  background: var(--red-bg);
}

/* Summary screen */
.lesson-summary-heading {
  font-size: 14px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 14px;
}
.lesson-summary-pt {
  font-size: 16px;
  color: var(--text);
  font-weight: 500;
  line-height: 1.6;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}
.lesson-summary-pt:last-child { border-bottom: none; }

/* Detail text (smaller context shown after teach points) */
.lesson-detail {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text2);
  font-weight: 450;
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border-radius: 2px;
  border-left: 3px solid var(--border);
}

/* Scaffold screen — big picture context, subtle tint */
.lesson-scaffold {
  padding: 12px 16px;
  background: var(--accent-bg);
  border-radius: 2px;
  border-left: 3px solid var(--accent);
}
.lesson-scaffold .lesson-teach-heading {
  font-size: 20px;
  color: var(--accent-dark);
}
.lesson-scaffold .lesson-point {
  background: transparent;
}

/* Example callout — inline analogy/case */
.lesson-example {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text2);
  font-weight: 450;
  font-style: italic;
  margin-top: 12px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border-radius: 2px;
  border-left: 3px solid var(--green);
}
.lesson-example-block {
  padding: 4px 0;
}
.lesson-example-block .lesson-example {
  margin-top: 16px;
}

/* Check question — inline understanding test */
.lesson-check {
  padding: 4px 0;
}
.lesson-check-question {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-dark);
  line-height: 1.4;
  margin-bottom: 16px;
}
.lesson-check-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  margin-bottom: 4px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--bg-surface);
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  font-weight: 450;
  line-height: 1.5;
}
.lesson-check-option:hover:not([disabled]) {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.lesson-check-option .check-letter {
  font-weight: 700;
  color: var(--text2);
  margin-right: 6px;
}
.lesson-check-option.correct {
  border-color: var(--green);
  background: var(--green-bg);
}
.lesson-check-option.wrong {
  border-color: var(--red);
  background: var(--red-bg);
}
.lesson-check-option.dimmed {
  opacity: 0.5;
}
.lesson-check-option[disabled] {
  cursor: default;
}
.lesson-check-feedback {
  font-size: 15px;
  font-weight: 500;
  padding: 12px 16px;
  border-radius: 2px;
  margin-top: 8px;
  line-height: 1.5;
}
.lesson-check-feedback.correct {
  color: var(--green-dark);
  background: var(--green-bg);
}
.lesson-check-feedback.wrong {
  color: var(--red-dark);
  background: var(--red-bg);
}

/* Pager — segmented progress bars */
.lesson-dots {
  display: flex;
  gap: 4px;
  padding: 16px 0;
}
.lesson-dot {
  flex: 1;
  height: 3px;
  border-radius: 1px;
  background: var(--border);
}
.lesson-dot.active {
  background: var(--accent);
}
.lesson-dot.done {
  background: var(--accent);
  opacity: 0.4;
}

/* ================================================================
   Utility
   ================================================================ */
.text-center { text-align: center; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.hidden { display: none !important; }

/* ================================================================
   IDK Button
   ================================================================ */
.idk-btn {
  display: block;
  margin: 12px auto 0;
  padding: 12px 24px;
  min-height: 44px;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.idk-btn:hover { text-decoration: underline; }

/* ================================================================
   Leaderboard
   ================================================================ */
.lb-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.lb-tab {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
}
.lb-tab:hover { color: var(--text); }
.lb-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.lb-table th {
  text-align: left;
  padding: 8px 12px;
  font-weight: 600;
  color: var(--text2);
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.lb-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.lb-table tr.lb-you { background: var(--accent-bg); }
.lb-table .lb-rank { width: 40px; font-weight: 600; color: var(--text2); }
.lb-table .lb-name { font-weight: 500; }
.lb-table .lb-val { font-weight: 600; color: var(--text-dark); text-align: right; }

.lb-opt-in {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
}
.lb-toggle {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-surface);
  font-family: inherit;
}
.lb-toggle.active { background: var(--accent); color: white; border-color: var(--accent); }

/* Status change pills on summary */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 3px 0;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ================================================================
   Speed Round
   ================================================================ */
.speed-round-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin-bottom: 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 14px;
  color: var(--text2);
}

.speed-subject-breakdown {
  max-width: 340px;
  margin: 16px auto 0;
  text-align: left;
}
.speed-subject-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.speed-subject-row:last-child { border-bottom: none; }

