/**
 * style.css — Stock Market Learning Guide for Kids
 * Clean/modern theme with teen-friendly hooks.
 * Light/dark mode via [data-theme="dark"] on <html>.
 * <!-- FUTURE: Vietnamese i18n — no text in CSS, all in HTML/JS -->
 */

/* ═══════════════════════ CSS Custom Properties ═══════════════════════ */

:root {
  /* Accent palette */
  --teal: #14b8a6;
  --teal-light: #5eead4;
  --coral: #f43f5e;
  --coral-light: #fb7185;
  --amber: #f59e0b;
  --amber-light: #fbbf24;
  --blue: #3b82f6;
  --purple: #8b5cf6;
  --green: #10b981;
  --pink: #ec4899;

  /* Theme colors — Light */
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-heading: #0f172a;
  --border: #e2e8f0;
  --shadow: rgba(0, 0, 0, 0.06);
  --shadow-lg: rgba(0, 0, 0, 0.1);
  --hover-bg: #f1f5f9;
  --xp-bar-bg: #e2e8f0;
  --xp-bar-fill: linear-gradient(90deg, var(--teal), var(--blue));
  --badge-glow: rgba(20, 184, 166, 0.3);
  --quiz-correct: #dcfce7;
  --quiz-wrong: #fef2f2;
  --gain: #10b981;
  --loss: #ef4444;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-heading: #f8fafc;
  --border: #334155;
  --shadow: rgba(0, 0, 0, 0.3);
  --shadow-lg: rgba(0, 0, 0, 0.5);
  --hover-bg: #334155;
  --xp-bar-bg: #334155;
  --badge-glow: rgba(20, 184, 166, 0.5);
  --quiz-correct: #052e16;
  --quiz-wrong: #450a0a;
  --gain: #34d399;
  --loss: #f87171;
  /* Tell browser this is a dark page — fixes form control colors, scrollbars, etc. */
  color-scheme: dark;
}

/* ═══════════════════════ Reset & Base ═══════════════════════ */

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4 { color: var(--text-heading); font-weight: 700; line-height: 1.3; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 600;
  transition: all 0.2s ease;
}

button:active { transform: scale(0.97); }

/* ═══════════════════════ Layout ═══════════════════════ */

.app-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  min-height: 100vh;
}

/* Header */
.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px var(--shadow);
}

.app-title {
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* XP Bar */
.xp-container {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.xp-bar {
  width: 160px;
  height: 10px;
  background: var(--xp-bar-bg);
  border-radius: 5px;
  overflow: hidden;
}

.xp-bar-fill {
  height: 100%;
  background: var(--xp-bar-fill);
  border-radius: 5px;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  width: 0%;
}

/* Dark/Light Toggle */
.theme-toggle {
  background: var(--hover-bg);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 20px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  background: var(--border);
}

/* Sidebar */
.app-sidebar {
  grid-area: sidebar;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
}

.nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 12px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.95rem;
  color: var(--text-muted);
  position: relative;
}

.nav-item:hover { background: var(--hover-bg); color: var(--text); }

.nav-item.active {
  background: var(--teal);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(20, 184, 166, 0.3);
}

.nav-item.completed::after {
  content: '✓';
  position: absolute;
  right: 12px;
  font-size: 0.85rem;
  color: var(--green);
  font-weight: bold;
}

.nav-item.active.completed::after { color: #fff; }

.nav-item.nav-locked {
  opacity: 0.42;
  pointer-events: none;
  cursor: not-allowed;
}

.nav-item.nav-locked::before {
  content: '🔒';
  font-size: 0.75rem;
  margin-right: 6px;
  opacity: 0.7;
}

.nav-emoji { font-size: 1.3rem; }

.nav-progress {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 16px 28px 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.progress-dots {
  display: flex;
  gap: 4px;
}

.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s ease;
}

.progress-dot.filled { background: var(--teal); }

.progress-count {
  font-size: 0.75rem;
  color: var(--teal);
  font-weight: 600;
  margin-left: 4px;
}

/* Earned badges sidebar */
.sidebar-badges {
  padding: 16px 28px;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

.sidebar-badges h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge-mini {
  font-size: 1.4rem;
  opacity: 0.3;
  transition: opacity 0.3s ease, transform 0.3s ease;
  cursor: default;
}

.badge-mini.earned {
  opacity: 1;
  animation: badgeEarn 0.5s ease;
}

/* Mastery (hidden) badge slots */
.mastery-badge:not(.earned) {
  filter: grayscale(1) opacity(0.35);
  font-size: 1.1rem;
}

.mastery-badge.earned {
  animation: masteryPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ultimate-mastery-badge.earned {
  filter: drop-shadow(0 0 6px #f59e0b);
}

@keyframes masteryPop {
  0%   { transform: scale(0) rotate(-15deg); }
  70%  { transform: scale(1.35) rotate(5deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* Main Content */
.app-main {
  grid-area: main;
  padding: 32px;
  max-width: 880px;
  width: 100%;
}

.module-section {
  display: none;
  animation: fadeIn 0.4s ease;
}

.module-section.active { display: block; }

/* Footer */
.app-footer {
  grid-area: footer;
  text-align: center;
  padding: 16px 24px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.disclaimer-banner {
  background: #fef3c7;
  border: 1px solid #fbbf24;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.82rem;
  color: #92400e;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

[data-theme="dark"] .disclaimer-banner {
  background: #422006;
  border-color: #92400e;
  color: #fbbf24;
}

/* ═══════════════════════ Module Cards & Content ═══════════════════════ */

.module-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.module-header .module-emoji { font-size: 2.5rem; }

.module-header .module-meta h2 { margin-bottom: 4px; }
.module-header .module-meta p { color: var(--text-muted); font-size: 0.9rem; }

.content-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px var(--shadow);
  transition: box-shadow 0.2s ease;
}

.content-card:hover { box-shadow: 0 4px 12px var(--shadow-lg); }

.content-card h3 { margin-bottom: 12px; }
.content-card p { margin-bottom: 12px; color: var(--text); }
.content-card p:last-child { margin-bottom: 0; }

/* Analogy cards */
.analogy-card {
  background: linear-gradient(135deg, #f0fdfa, #ecfdf5);
  border: 1px solid var(--teal-light);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

[data-theme="dark"] .analogy-card {
  background: linear-gradient(135deg, #042f2e, #064e3b);
  border-color: #0d9488;
}

/* Module 6 intro card — teal gradient, theme-aware */
.card-teal-intro {
  background: linear-gradient(135deg, #f0fdfa, #ecfdf5);
  border-color: var(--teal-light);
}

[data-theme="dark"] .card-teal-intro {
  background: linear-gradient(135deg, #042f2e, #052e1e);
  border-color: var(--teal);
}

.analogy-card .analogy-emoji {
  font-size: 2rem;
  display: block;
  margin-bottom: 8px;
}

/* Did You Know cards */
.dyk-card {
  background: var(--bg-card);
  border: 1px solid var(--amber-light);
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.dyk-card:hover { background: var(--hover-bg); }

.dyk-card .dyk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.95rem;
}

.dyk-card .dyk-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, margin 0.3s ease;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.dyk-card.open .dyk-content {
  max-height: 200px;
  margin-top: 10px;
}

.dyk-card .dyk-arrow {
  transition: transform 0.3s ease;
  font-size: 0.8rem;
}

.dyk-card.open .dyk-arrow { transform: rotate(180deg); }

/* ═══════════════════════ Quiz Styles ═══════════════════════ */

.quiz-container {
  background: var(--bg-card);
  border: 2px solid var(--teal);
  border-radius: 14px;
  padding: 24px;
  margin-top: 24px;
  margin-bottom: 20px;
}

.quiz-container h3 { color: var(--teal); margin-bottom: 16px; }

.quiz-question {
  font-weight: 600;
  margin-bottom: 14px;
  font-size: 1.05rem;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.quiz-option {
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.95rem;
  text-align: left;
  background: var(--bg);
  color: var(--text);
}

.quiz-option:hover:not(.disabled) {
  border-color: var(--teal);
  background: var(--hover-bg);
}

.quiz-option.correct {
  background: var(--quiz-correct);
  border-color: var(--green);
  color: var(--text);
}

.quiz-option.wrong {
  background: var(--quiz-wrong);
  border-color: var(--coral);
  color: var(--text);
}

.quiz-option.disabled { cursor: default; opacity: 0.6; }

.quiz-feedback {
  padding: 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-bottom: 16px;
  display: none;
  animation: fadeIn 0.3s ease;
}

.quiz-feedback.show { display: block; }

.quiz-feedback.correct {
  background: var(--quiz-correct);
  border: 1px solid var(--green);
}

.quiz-feedback.wrong {
  background: var(--quiz-wrong);
  border: 1px solid var(--coral);
}

.quiz-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.quiz-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

.quiz-progress {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ═══════════════════════ Interactive Elements ═══════════════════════ */

/* Supply & Demand Slider (Module 2) */
.slider-demo {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  margin-bottom: 20px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.slider-row label {
  width: 100px;
  font-weight: 600;
  font-size: 0.9rem;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--teal);
  height: 6px;
}

.slider-row .slider-val {
  width: 40px;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.price-display {
  text-align: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--bg), var(--hover-bg));
  border-radius: 12px;
  margin-top: 12px;
}

.price-display .price-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.price-display .price-value {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--teal);
  transition: all 0.3s ease;
}

.price-display .price-arrow {
  font-size: 1.5rem;
  transition: all 0.3s ease;
}

/* Company Cards (Module 3) */
.company-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.company-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  text-align: center;
  transition: all 0.2s ease;
  cursor: grab;
}

.company-card:hover {
  box-shadow: 0 4px 16px var(--shadow-lg);
  transform: translateY(-2px);
}

.company-card.dragging {
  opacity: 0.5;
  transform: scale(0.95);
}

.company-card .card-emoji { font-size: 2.5rem; margin-bottom: 8px; }
.company-card .card-name { font-weight: 700; font-size: 1.1rem; margin-bottom: 4px; }
.company-card .card-sector { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 12px; }

.stat-bar {
  height: 8px;
  background: var(--xp-bar-bg);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease;
}

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

/* Ranking zone */
.ranking-zone {
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 20px;
  min-height: 100px;
  margin-bottom: 20px;
}

.ranking-zone h4 {
  margin-bottom: 12px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.rank-slot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  min-height: 50px;
  transition: all 0.2s ease;
}

.rank-slot.drag-over {
  border-color: var(--teal);
  background: rgba(20, 184, 166, 0.05);
}

.rank-slot .rank-number {
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--text-muted);
  width: 28px;
}

.rank-slot .rank-content {
  flex: 1;
  font-weight: 600;
}

/* Tap-to-select states (touch-fallback) */
.company-card.tap-selected {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--badge-glow);
  transform: scale(1.03);
}

.touch-hint {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 8px;
  background: var(--hover-bg);
  border-radius: 8px;
  margin-bottom: 12px;
  display: none;
}

.touch-device .touch-hint { display: block; }

/* ═══════════════════════ Simulator (Module 6) ═══════════════════════ */

.sim-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.sim-stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.sim-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  text-align: center;
  min-width: 120px;
}

.sim-stat .stat-val {
  font-size: 1.3rem;
  font-weight: 800;
}

.sim-stat .stat-lbl {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* News ticker */
.news-ticker {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 20px;
  max-height: 160px;
  overflow-y: auto;
}

.news-item {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  animation: slideIn 0.4s ease;
}

.news-item:last-child { border-bottom: none; }

.news-item .news-week {
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-right: 8px;
}

/* Portfolio table */
.portfolio-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.portfolio-table th {
  background: var(--bg-sidebar);
  font-weight: 700;
  padding: 10px 12px;
  text-align: left;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}

.portfolio-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.portfolio-table tr:hover td { background: var(--hover-bg); }

.positive { color: var(--gain); font-weight: 600; }
.negative { color: var(--loss); font-weight: 600; }

/* Buy/Sell buttons */
.trade-btn-group {
  display: flex;
  gap: 4px;
}

.trade-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.trade-btn.buy {
  background: var(--green);
  color: #fff;
}

.trade-btn.buy:hover { background: #059669; }

.trade-btn.sell {
  background: var(--coral);
  color: #fff;
}

.trade-btn.sell:hover { background: #dc2626; }

.trade-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Chart area */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 20px;
  overflow: hidden;
}

/* Sim advance button */
.sim-advance-btn {
  background: var(--teal);
  color: #fff;
  padding: 14px 28px;
  font-size: 1.05rem;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 auto;
}

.sim-advance-btn:hover { background: #0d9488; }
.sim-advance-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* End screen */
.sim-end-screen {
  text-align: center;
  padding: 32px;
  animation: fadeIn 0.5s ease;
}

.sim-end-screen .final-value {
  font-size: 2.5rem;
  font-weight: 800;
  margin: 12px 0;
}

.sim-end-screen .return-badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 20px;
}

.reflection-box {
  width: 100%;
  max-width: 500px;
  min-height: 80px;
  margin: 12px auto;
  display: block;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
}

/* Module nav button */
.btn-primary {
  background: var(--teal);
  color: #fff;
  padding: 12px 24px;
  font-size: 1rem;
  border-radius: 10px;
}

.btn-primary:hover { background: #0d9488; }

.btn-primary:disabled,
.btn-primary[disabled] {
  opacity: 0.38;
  cursor: not-allowed;
  filter: grayscale(0.5);
  pointer-events: auto; /* keep hover cursor visible */
}
.btn-primary:disabled:hover,
.btn-primary[disabled]:hover { background: var(--teal); }

.btn-secondary {
  background: var(--hover-bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 24px;
  font-size: 1rem;
  border-radius: 10px;
}

.btn-secondary:hover { background: var(--border); }

.module-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ═══════════════════════ Badge Pop-up ═══════════════════════ */

.badge-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.badge-popup {
  background: var(--bg-card);
  border: 2px solid var(--teal);
  border-radius: 20px;
  padding: 40px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: badgePop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  max-width: 360px;
  width: 90%;
}

.badge-popup .badge-emoji {
  font-size: 4rem;
  display: block;
  margin-bottom: 12px;
  animation: bounce 0.6s ease 0.3s;
}

.badge-popup .badge-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--teal);
  margin-bottom: 8px;
}

.badge-popup .badge-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.badge-popup .badge-xp {
  font-weight: 700;
  color: var(--amber);
  margin-bottom: 16px;
}

/* Mastery / Secret Achievement Popup */
.mastery-overlay {
  background: rgba(0, 0, 0, 0.75);
}

.mastery-popup {
  background: linear-gradient(135deg, #1c1500 0%, #2d2200 50%, #1c1500 100%);
  border: 2px solid #f59e0b;
  box-shadow: 0 0 40px rgba(245, 158, 11, 0.5), 0 20px 60px rgba(0, 0, 0, 0.6);
  color: #fef3c7;
}

.mastery-secret-label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 2.5px;
  color: #f59e0b;
  text-transform: uppercase;
  margin-bottom: 14px;
  padding: 4px 14px;
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 99px;
  background: rgba(245, 158, 11, 0.08);
  display: inline-block;
}

.mastery-popup .badge-title {
  color: #fbbf24;
}

.mastery-popup .badge-desc {
  color: #d4a017;
}

.mastery-xp {
  font-weight: 700;
  color: #fbbf24 !important;
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.mastery-btn {
  background: linear-gradient(135deg, #d97706, #f59e0b) !important;
  color: #1c1500 !important;
  font-weight: 800;
}

.mastery-btn:hover {
  background: linear-gradient(135deg, #f59e0b, #fbbf24) !important;
}

.ultimate-overlay .mastery-popup {
  box-shadow: 0 0 60px rgba(245, 158, 11, 0.7), 0 0 120px rgba(245, 158, 11, 0.25), 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: badgePop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), ultimateGlow 2s ease-in-out 0.5s infinite alternate;
}

@keyframes ultimateGlow {
  from { box-shadow: 0 0 40px rgba(245, 158, 11, 0.5), 0 0 80px rgba(245, 158, 11, 0.2); }
  to   { box-shadow: 0 0 80px rgba(245, 158, 11, 0.9), 0 0 140px rgba(245, 158, 11, 0.4); }
}

/* Confetti */
.confetti-piece {
  position: fixed;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  z-index: 1001;
  pointer-events: none;
  animation: confettiFall 2.5s ease-out forwards;
}

/* ═══════════════════════ XP Toast ═══════════════════════ */

.xp-toast {
  position: fixed;
  top: 64px;
  right: 20px;
  background: linear-gradient(135deg, var(--teal), var(--blue));
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 5px 14px;
  border-radius: 20px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  opacity: 0;
  transform: translateY(0) scale(0.85);
  transition: opacity 0.25s ease, transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
  z-index: 2000;
}

.xp-toast.show {
  opacity: 1;
  transform: translateY(-20px) scale(1);
}

/* ═══════════════════════ Course Complete ═══════════════════════ */

.course-complete-panel {
  margin: 24px 0;
  border-radius: 16px;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border: 2px solid var(--teal);
  overflow: hidden;
}

[data-theme="light"] .course-complete-panel {
  background: linear-gradient(135deg, #f0fdfa 0%, #ecfdf5 100%);
}

.course-complete-inner {
  padding: 36px 28px;
  text-align: center;
}

.course-complete-emoji {
  font-size: 3.5rem;
  display: block;
  margin-bottom: 12px;
  animation: bounce 1s ease 0.2s both;
}

.course-complete-inner h2 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--teal);
  margin-bottom: 8px;
}

.course-complete-inner p {
  color: var(--text-muted);
  max-width: 440px;
  margin: 0 auto 20px;
}

.course-complete-stats {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.ccs-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

/* ═══════════════════════ Animations ═══════════════════════ */

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

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes badgePop {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes badgeEarn {
  0% { transform: scale(0); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

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

@keyframes confettiFall {
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

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

.shake { animation: shake 0.4s ease; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--badge-glow); }
  50% { box-shadow: 0 0 0 8px transparent; }
}

/* ═══════════════════════ Profile System ═══════════════════════ */

.profile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.3s ease;
  backdrop-filter: blur(4px);
}

.profile-overlay.hidden { display: none; }

.profile-picker {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 36px;
  max-width: 480px;
  width: 92%;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  animation: badgePop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.profile-picker-header {
  text-align: center;
  margin-bottom: 24px;
}

.profile-picker-header h2 {
  margin-top: 8px;
  font-size: 1.4rem;
}

.profile-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.profile-card:hover {
  border-color: var(--teal);
  background: rgba(20, 184, 166, 0.06);
  transform: translateY(-1px);
}

.profile-card .profile-avatar {
  font-size: 2rem;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 184, 166, 0.1);
  border-radius: 50%;
  flex-shrink: 0;
}

.profile-card .profile-info { flex: 1; min-width: 0; }

.profile-card .profile-info .profile-card-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-card .profile-info .profile-card-detail {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.profile-card .profile-delete {
  background: none;
  border: none;
  padding: 6px;
  font-size: 1rem;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  opacity: 0.5;
  transition: all 0.2s ease;
}

.profile-card .profile-delete:hover {
  color: var(--coral);
  opacity: 1;
  background: rgba(244, 63, 94, 0.08);
}

.profile-create {
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.profile-create h4 {
  font-size: 0.95rem;
  margin-bottom: 12px;
}

.profile-create-row {
  display: flex;
  gap: 10px;
}

.profile-name-input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease;
}

.profile-name-input:focus {
  border-color: var(--teal);
}

.profile-name-input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

/* User indicator in header */
.user-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(20, 184, 166, 0.08);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text);
  font-size: 0.85rem;
}

.user-indicator:hover {
  border-color: var(--teal);
  background: rgba(20, 184, 166, 0.15);
}

.user-indicator .user-avatar { font-size: 1.1rem; }

.user-indicator .user-name {
  font-weight: 600;
  max-width: 100px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Welcome-back banner */
.welcome-back-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1500;
  background: linear-gradient(135deg, #0d9488, #14b8a6);
  color: #fff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  animation: slideDown 0.4s ease;
}

.welcome-back-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  max-width: 1200px;
  margin: 0 auto;
  gap: 16px;
  flex-wrap: wrap;
}

.welcome-back-text {
  display: flex;
  align-items: center;
  gap: 10px;
}

.welcome-back-emoji { font-size: 1.6rem; }

.welcome-back-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-sm {
  padding: 8px 16px !important;
  font-size: 0.85rem !important;
}

.welcome-back-banner .btn-primary {
  background: #fff;
  color: #0d9488;
}

.welcome-back-banner .btn-primary:hover { background: #f0fdfa; }

.welcome-back-banner .btn-secondary {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
}

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

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ═══════════════════════ Responsive ═══════════════════════ */

@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "main"
      "footer";
  }

  .app-sidebar {
    display: none;
    position: fixed;
    left: 0; top: 56px;
    width: 280px; height: calc(100vh - 56px);
    z-index: 200;
    box-shadow: 4px 0 20px var(--shadow-lg);
  }

  .app-sidebar.open {
    display: block;
    animation: slideIn 0.3s ease;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 199;
  }

  .sidebar-overlay.open { display: block; }

  .menu-toggle {
    display: flex !important;
    background: none;
    font-size: 1.5rem;
    padding: 4px 8px;
    color: var(--text);
  }

  .app-main { padding: 20px 16px; }

  .xp-bar { width: 100px; }

  .company-cards {
    grid-template-columns: 1fr;
  }

  .sim-stats {
    width: 100%;
    justify-content: center;
  }

  .sim-stat { min-width: 100px; flex: 1; }

  .trade-btn {
    width: 44px;
    height: 44px;
  }

  .welcome-back-content { padding: 12px 16px; }

  .user-indicator .user-name { max-width: 60px; }

  .profile-picker { padding: 24px 20px; }
  .profile-create-row { flex-direction: column; }
}

@media (max-width: 480px) {
  .app-title { font-size: 1rem; }
  .xp-container { display: none; }
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.2rem; }
  .content-card { padding: 16px; }
  .quiz-container { padding: 16px; }

  .module-nav {
    flex-direction: column;
    gap: 8px;
  }

  .module-nav button { width: 100%; }

  .user-indicator .user-name { display: none; }
  .welcome-back-content { flex-direction: column; text-align: center; }
}

/* Desktop: hide menu toggle */
@media (min-width: 769px) {
  .menu-toggle { display: none !important; }
  .sidebar-overlay { display: none !important; }
}

/* ──────────────────────────── Difficulty Selector ──────────────────────────── */

.difficulty-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.diff-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.diff-btn {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 700;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1.4;
}

.diff-btn.easy {
  background: #dcfce7;
  color: #166534;
  border-color: var(--green);
}

.diff-btn.medium {
  background: #fef3c7;
  color: #92400e;
  border-color: var(--amber);
}

.diff-btn.hard {
  background: #fef2f2;
  color: #991b1b;
  border-color: var(--coral);
}

.diff-btn.active {
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.3);
  transform: scale(1.05);
}

.diff-btn.locked {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(1);
}

.diff-btn:hover:not(.locked):not(.active) {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

[data-theme="dark"] .diff-btn.easy {
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
}

[data-theme="dark"] .diff-btn.medium {
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
}

[data-theme="dark"] .diff-btn.hard {
  background: rgba(244, 63, 94, 0.15);
  color: #fda4af;
}

/* ──────────────────────────── Simulator Enhancements ──────────────────────────── */

/* Three-panel simulator layout */
.sim-body {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  margin-bottom: 20px;
}

@media (max-width: 900px) {
  .sim-body {
    grid-template-columns: 1fr;
  }
  .sim-right-panel {
    order: -1;
  }
}

.sim-left-panel,
.sim-right-panel {
  min-width: 0;
  overflow: hidden;
}

.sim-left-panel .portfolio-table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

.sim-right-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.sim-chart-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
}

/* Stock ticker tape */
.sim-ticker-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  white-space: nowrap;
  padding: 8px 0;
  margin-bottom: 16px;
}

.sim-ticker-inner {
  display: inline-block;
  animation: tickerScroll 20s linear infinite;
  padding-left: 100%;
}

.sim-ticker-inner.restart {
  animation: none;
}

.tick-item {
  margin: 0 16px;
  font-size: 0.82rem;
  font-weight: 600;
}

.tick-up { color: var(--gain); }
.tick-dn { color: var(--loss); }
.tick-flat { color: var(--text-muted); }
.tick-sep { color: var(--text-muted); margin: 0 8px; }

@keyframes tickerScroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-100%); }
}

/* Sparkline cell */
.spark-cell {
  padding: 4px 8px !important;
  width: 72px;
}

.spark-canvas {
  display: block;
}

/* Sector badge */
.sector-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  background: var(--hover-bg);
  color: var(--text-muted);
  white-space: nowrap;
}

/* Week-over-week change */
.wk-change {
  font-size: 0.8rem;
  font-weight: 700;
}

/* Market summary card */
.market-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 20px;
  margin-bottom: 16px;
}

.market-summary.bull { border-color: var(--green); }
.market-summary.bear { border-color: var(--coral); }
.market-summary.mixed { border-color: var(--amber); }

.market-emoji { font-size: 2.2rem; flex-shrink: 0; }

.market-info { flex: 1; min-width: 0; }
.market-info strong { font-size: 0.9rem; display: block; }
.market-info span { font-size: 0.82rem; color: var(--text-muted); }

.market-stats {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 0;
}

/* Clickable portfolio rows */
.portfolio-table tr { cursor: pointer; }
.portfolio-table tr.selected-row td {
  background: rgba(20, 184, 166, 0.08);
}

/* Chart type toggle button */
.chart-type-toggle {
  font-size: 0.78rem;
  padding: 5px 10px;
  background: var(--hover-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: 8px;
  display: inline-block;
}

.chart-type-toggle:hover { background: var(--border); }

@media (max-width: 768px) {
  .chart-type-toggle { display: none; }
  .portfolio-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .spark-cell { display: none; }
}

/* Reduced motion: stop ticker & all transitions */
@media (prefers-reduced-motion: reduce) {
  .sim-ticker-inner { animation: none; overflow-x: auto; }
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Difficulty badge pills (Medium / Hard lesson cards) ── */
.diff-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  margin-right: 6px;
  vertical-align: middle;
  letter-spacing: 0.03em;
  line-height: 1.6;
}
.diff-badge.medium {
  background: var(--amber);
  color: #fff;
}
.diff-badge.hard {
  background: var(--purple);
  color: #fff;
}
