:root {
  --bg: #FAFAF9; 
  --bg2: #F5F5F4;
  --bg-blur: rgba(250, 250, 249, 0.85);
  --nav-blur: rgba(255, 255, 255, 0.9);
  --ink: #1C1917;
  --ink2: #44403C;
  --ink3: #78716C;
  --accent: #E11D48;
  --accent-light: #FFE4E6;
  --accent2: #059669;
  --accent2-light: #D1FAE5;
  --accent3: #4F46E5;
  --gold: #D97706;
  --card: #FFFFFF;
  --border: #E7E5E4;
  --border2: #D6D3D1;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.08);
  --shadow-float: 0 12px 32px rgba(225, 29, 72, 0.2);
  --unit1: #3B82F6;
  --unit2: #8B5CF6;
  --unit3: #F59E0B;
  --unit4: #EF4444;
  --unit5: #10B981;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; font-size: 16px; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
  padding-bottom: 90px; /* Space for bottom nav */
}

/* ── TYPOGRAPHY ── */
.serif { font-family: 'Fraunces', serif; }
h1 { font-family: 'Fraunces', serif; font-weight: 500; font-size: clamp(2rem, 8vw, 3.5rem); line-height: 1.1; letter-spacing: -0.02em; }
h2 { font-family: 'Fraunces', serif; font-weight: 500; font-size: clamp(1.5rem, 5vw, 2.5rem); line-height: 1.2; letter-spacing: -0.01em; }
h3 { font-family: 'Fraunces', serif; font-weight: 500; font-size: 1.15rem; line-height: 1.3; }

/* ── LAYOUT PAGES ── */
.page { display: none; min-height: 100vh; animation: fadeIn 0.3s ease; }
.page.active { display: block; }

/* ── NOISE TEXTURE ── */
body::before {
  content: ''; position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none; z-index: 1000;
}

/* ════════════════════════════════
   GAMIFICATION UI (MOBILE FIRST)
════════════════════════════════ */
.top-bar {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg-blur); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(0,0,0,0.05);
  padding: 1rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
}
.logo-area {
  font-family: 'Fraunces', serif; font-size: 1.1rem; font-weight: 600; color: var(--ink);
  cursor: pointer; transition: opacity 0.2s ease;
}
.logo-area:hover { opacity: 0.8; }
.logo-area span { color: var(--accent); font-style: italic; }

.gamification-pill {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 100px; padding: 6px 12px;
  display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-sm);
}
.xp-icon {
  background: var(--gold-light); color: var(--gold);
  width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 700;
}
.xp-text { font-size: 0.8rem; font-weight: 600; color: var(--ink2); }
.lvl-text { font-size: 0.75rem; color: var(--ink3); font-weight: 500; border-left: 1px solid var(--border); padding-left: 8px; }

/* ════════════════════════════════
   HOME PAGE
════════════════════════════════ */
.hero-section { padding: 2.5rem 1.25rem; max-width: 1200px; margin: 0 auto; }
.hero-eyebrow {
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 1rem; display: flex; align-items: center; gap: 8px;
}
.hero-eyebrow::before { content: ''; width: 24px; height: 2px; background: var(--accent); border-radius: 2px; }
.hero-title em { color: var(--accent); }
.hero-desc { font-size: 1.05rem; line-height: 1.6; color: var(--ink2); margin: 1.5rem 0 2rem; max-width: 480px; }

.hero-cta {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--ink); color: var(--card);
  padding: 16px 32px; border-radius: 100px;
  font-size: 1rem; font-weight: 600; border: none; cursor: pointer;
  box-shadow: 0 8px 24px rgba(28, 25, 23, 0.2);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  width: 100%; max-width: 320px;
}
.hero-cta:active { transform: scale(0.96); }
.hero-cta:hover { background: var(--accent); box-shadow: var(--shadow-float); transform: translateY(-2px); }
.hero-cta svg { transition: transform 0.2s; }
.hero-cta:hover svg { transform: translateX(4px); }

.unit-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-top: 3rem; }

.unit-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem;
  position: relative; overflow: hidden; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: all 0.25s ease;
  display: flex; flex-direction: column; gap: 12px;
}
.unit-card::before {
  content: ''; position: absolute; top: 0; left: 0; bottom: 0; width: 4px; transition: width 0.2s ease;
}
.unit-card[data-u="0"]::before { background: var(--unit1); }
.unit-card[data-u="1"]::before { background: var(--unit2); }
.unit-card[data-u="2"]::before { background: var(--unit3); }
.unit-card[data-u="3"]::before { background: var(--unit4); }
.unit-card[data-u="4"]::before { background: var(--unit5); }

.unit-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: var(--border2); }
.unit-card:active { transform: scale(0.98); }
.unit-card:hover::before { width: 6px; }

.unit-card.locked { opacity: 0.6; filter: grayscale(100%); cursor: not-allowed; }
.unit-card.locked:hover { transform: none; box-shadow: var(--shadow-sm); }
.unit-card.done { background: var(--accent2-light); border-color: rgba(5,150,105,0.2); }

.uc-header { display: flex; justify-content: space-between; align-items: flex-start; }
.uc-num { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink3); background: var(--bg2); padding: 4px 10px; border-radius: 100px; }
.uc-status-icon { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--border); color: var(--ink3); }
.unit-card.done .uc-status-icon { background: var(--accent2); color: white; }
.unit-card.inprogress .uc-status-icon { background: var(--accent); color: white; animation: pulse 2s infinite; }

.uc-title { font-family: 'Fraunces', serif; font-size: 1.2rem; font-weight: 500; color: var(--ink); line-height: 1.3; }
.uc-prog-bar { height: 6px; background: var(--bg2); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.uc-prog-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1); }
.unit-card.done .uc-prog-fill { background: var(--accent2); }

/* ════════════════════════════════
   UNIT PAGE
════════════════════════════════ */
.unit-hero { padding: 2rem 1.25rem 1.5rem; }
.unit-color-tag { display: inline-block; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; padding: 6px 14px; border-radius: 100px; margin-bottom: 1.25rem; color: white; }
.unit-subtitle { font-size: 1.05rem; color: var(--ink2); line-height: 1.6; margin-top: 1rem; }

.lesson-list { padding: 0 1.25rem 2rem; display: flex; flex-direction: column; gap: 12px; }
.lesson-item {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 1.25rem; display: flex; gap: 1rem; align-items: center;
  box-shadow: var(--shadow-sm); transition: all 0.2s ease; cursor: pointer;
}
.lesson-item:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border2); }
.lesson-item:active { transform: scale(0.98); }
.lesson-item.done { background: var(--bg); border-color: transparent; box-shadow: none; }

.li-icon {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-light); color: var(--accent); font-weight: 700; font-size: 1.1rem;
}
.lesson-item.done .li-icon { background: var(--accent2-light); color: var(--accent2); }

.li-info { flex: 1; }
.li-title { font-size: 1.05rem; font-weight: 600; color: var(--ink); margin-bottom: 4px; line-height: 1.3; }
.li-meta { font-size: 0.8rem; color: var(--ink3); display: flex; align-items: center; gap: 6px; }
.li-meta svg { opacity: 0.7; }
.li-xp { font-weight: 600; color: var(--gold); }

/* ════════════════════════════════
   LESSON PAGE
════════════════════════════════ */
.lesson-body { padding: 1.5rem 1.25rem 4rem; max-width: 768px; margin: 0 auto; }
.lesson-header { margin-bottom: 2rem; }
.lesson-tag { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin-bottom: 1rem; }
.lesson-header h2 { font-size: 2rem; margin-bottom: 0.5rem; }

.section-header { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink3); margin: 2rem 0 1rem; display: flex; align-items: center; gap: 12px; }
.section-header::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.content-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow-sm); margin-bottom: 1.5rem; }
.content-card p { font-size: 1.05rem; line-height: 1.7; color: var(--ink2); }

.insight-box { background: var(--bg2); border-radius: var(--radius-sm); padding: 1.25rem 1.5rem; margin-top: 1.5rem; border-left: 4px solid var(--accent3); }
.insight-box p { font-size: 0.95rem; color: var(--ink); line-height: 1.6; font-style: italic; }

.steps-list { list-style: none; }
.steps-list li { display: flex; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--border); font-size: 1rem; color: var(--ink); line-height: 1.6; align-items: flex-start; }
.steps-list li:last-child { border-bottom: none; padding-bottom: 0; }
.step-label { background: var(--accent-light); color: var(--accent); font-size: 0.8rem; font-weight: 700; min-width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

.activity-box { background: var(--accent2-light); border: 1px solid rgba(5,150,105,0.2); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem; }
.activity-label-tag { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent2); margin-bottom: 10px; display: inline-block; background: white; padding: 4px 10px; border-radius: 100px; }
.activity-box h3 { color: #064E3B; margin-bottom: 12px; font-size: 1.25rem; }
.activity-box p { font-size: 0.95rem; color: #065F46; line-height: 1.6; margin-bottom: 20px; }

.check-items { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.check-label { display: flex; align-items: center; gap: 14px; padding: 12px 16px; background: rgba(255,255,255,0.6); border-radius: var(--radius-sm); font-size: 0.95rem; color: #064E3B; cursor: pointer; transition: all 0.2s ease; border: 1px solid transparent; }
.check-label:hover { background: white; }
.check-label.checked { background: white; border-color: rgba(5,150,105,0.3); opacity: 0.8; text-decoration: line-through; }
.custom-chk { width: 24px; height: 24px; border: 2px solid var(--accent2); border-radius: 6px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; background: white; }
.check-label.checked .custom-chk { background: var(--accent2); }
.check-label input { display: none; }
.custom-chk svg { opacity: 0; width: 14px; height: 14px; color: white; transition: opacity 0.2s; }
.check-label.checked .custom-chk svg { opacity: 1; }

.quiz-box { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 2rem; box-shadow: var(--shadow-sm); }
.quiz-q { font-family: 'Fraunces', serif; font-size: 1.25rem; font-weight: 500; color: var(--ink); margin-bottom: 1.5rem; line-height: 1.4; }
.quiz-options { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.quiz-options li { padding: 16px; border: 2px solid var(--border); border-radius: var(--radius-sm); font-size: 1rem; cursor: pointer; color: var(--ink); transition: all 0.2s ease; font-weight: 500; display: flex; align-items: center; gap: 12px; }
.quiz-options li::before { content: ''; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border2); flex-shrink: 0; transition: all 0.2s; }
.quiz-options li:hover:not(.disabled) { border-color: var(--accent); background: var(--accent-light); }
.quiz-options li.correct { background: var(--accent2-light); border-color: var(--accent2); color: #064E3B; }
.quiz-options li.correct::before { background: var(--accent2); border-color: var(--accent2); box-shadow: inset 0 0 0 3px var(--accent2-light); }
.quiz-options li.wrong { background: #FEF2F2; border-color: #FCA5A5; color: #991B1B; opacity: 0.6; }
.quiz-options li.disabled { pointer-events: none; }

.quiz-feedback { background: var(--bg2); border-radius: var(--radius-sm); padding: 16px; font-size: 0.95rem; color: var(--ink2); line-height: 1.6; margin-top: 1rem; display: none; border-left: 4px solid var(--accent2); animation: fadeIn 0.3s ease; }

/* ════════════════════════════════
   BOTTOM NAVIGATION (THUMB FRIENDLY)
════════════════════════════════ */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--nav-blur); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgba(0,0,0,0.08);
  padding: 12px 1.25rem 24px;
  display: flex; justify-content: center; z-index: 100;
  transform: translateY(100%); transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.bottom-nav.visible { transform: translateY(0); }

.nav-container { max-width: 768px; width: 100%; display: flex; gap: 12px; justify-content: space-between; }

.fab-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 20px; border-radius: 100px;
  font-size: 1rem; font-weight: 600; font-family: 'DM Sans', sans-serif;
  border: none; cursor: pointer; transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: var(--shadow-sm);
}
.fab-btn:active { transform: scale(0.96); }
.fab-back { background: var(--card); color: var(--ink); border: 1px solid var(--border); width: auto; flex-shrink: 0; }
.fab-back:hover { background: var(--bg2); }
.fab-action { background: var(--ink); color: var(--card); flex: 1; }
.fab-action:hover:not(:disabled) { background: var(--accent); }
.fab-action:disabled { opacity: 0.4; cursor: not-allowed; background: var(--border2); color: var(--ink3); box-shadow: none; }
.fab-action.done { background: var(--accent2); color: white; }

/* ════════════════════════════════
   ANIMATIONS & RESPONSIVE
════════════════════════════════ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(225, 29, 72, 0.4); } 70% { box-shadow: 0 0 0 6px rgba(225, 29, 72, 0); } 100% { box-shadow: 0 0 0 0 rgba(225, 29, 72, 0); } }

/* Progressively enhance for larger screens */
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .unit-grid { grid-template-columns: repeat(2, 1fr); }
  .bottom-nav { position: sticky; bottom: 2rem; border: 1px solid var(--border); border-radius: 100px; max-width: 600px; margin: 0 auto 2rem; padding: 12px; box-shadow: var(--shadow-lg); }
  .hero-section { padding: 5rem 2rem; display: grid; grid-template-columns: 1fr 1.2fr; gap: 4rem; align-items: center; }
  .unit-grid { margin-top: 0; }
}
@media (min-width: 1024px) {
  .hero-section { gap: 6rem; }
}