/* ============================================================
   English for Real Life — App Design System
   Style B: Clean Modern (Duolingo-inspired)
   ============================================================ */

:root {
  --bg: #ffffff;
  --surface: #f8fafc;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --nav-h: 64px;
  --header-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; -webkit-tap-highlight-color: transparent; }

/* ---- App shell (category pages) ---- */
.app-shell {
  font-family: 'Inter', sans-serif;
  background: var(--surface);
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: calc(var(--header-h) + var(--safe-top));
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* ---- App Header ---- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
.app-header-inner {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
}
.app-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-logo-icon { display: flex; align-items: center; color: #4f46e5; }
.app-logo-text {
  font-family: 'Fraunces', serif;
  font-size: 19px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

/* ---- Main content area ---- */
.app-main {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px 16px 8px;
}

/* ---- Category hero card ---- */
.cat-hero {
  background: var(--bg);
  border-radius: 20px;
  padding: 18px 18px 14px;
  margin-bottom: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.cat-hero-top {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}
.cat-hero-icon {
  width: 54px; height: 54px;
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.cat-hero-title {
  font-family: 'Fraunces', serif;
  font-size: 21px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.15;
}
.cat-hero-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
}
.cat-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 20px;
}

/* ---- Section label ---- */
.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin: 14px 2px 8px;
}

/* ---- Lesson List ---- */
.lesson-list { display: flex; flex-direction: column; gap: 10px; }

.lcard {
  background: var(--bg);
  border-radius: 18px;
  text-decoration: none;
  display: block;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  transition: transform 0.13s ease, box-shadow 0.13s ease;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
.lcard:active {
  transform: scale(0.975);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.lcard-body {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px 10px;
}
.lcard-num {
  width: 48px; height: 48px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 16px;
  color: white;
  flex-shrink: 0;
  letter-spacing: -0.5px;
}
.lcard-info { flex: 1; min-width: 0; }
.lcard-lesson-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 2px;
}
.lcard-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.lcard-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lcard-arrow {
  color: var(--border);
  font-size: 22px;
  font-weight: 300;
  flex-shrink: 0;
}
.lcard-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 16px 12px;
}
.lcard-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
}

/* ---- Bottom Navigation ---- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  background: var(--bg);
  border-top: 1.5px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
.bnav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 2px 10px;
  text-decoration: none;
  color: var(--text-muted);
  gap: 3px;
  transition: color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.bnav-item.active { color: var(--bnav-color, #4f46e5); }
.bnav-item.active::before {
  content: '';
  position: absolute;
  top: 0; left: 20%; right: 20%;
  height: 2.5px;
  border-radius: 0 0 3px 3px;
  background: var(--bnav-color, #4f46e5);
}
.bnav-icon { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; }
.bnav-label { font-size: 9px; font-weight: 600; letter-spacing: 0.01em; }

/* ---- Lesson Top Bar (legacy, kept for back-compat) ---- */
.lesson-topbar {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}
.lesson-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-primary);
  text-decoration: none;
  flex-shrink: 0;
  transition: background 0.15s;
}
.lesson-back:active { background: var(--surface-2); }
.lesson-topbar-emoji { font-size: 22px; flex-shrink: 0; }

/* ---- Lesson page container override ---- */
.lesson-page-wrap {
  max-width: 720px;
  margin: 0 auto;
  background: white;
  min-height: 100vh;
}

/* ============================================================
   LESSON COLOR TOKENS — one class per category
   ============================================================ */
.cat-agency  { --accent: #4f46e5; --accent-light: #e0e7ff; --accent-text: #4338ca; --accent-muted: #eef2ff; }
.cat-family  { --accent: #f43f5e; --accent-light: #ffe4e6; --accent-text: #e11d48; --accent-muted: #fff1f2; }
.cat-school  { --accent: #0891b2; --accent-light: #cffafe; --accent-text: #0e7490; --accent-muted: #ecfeff; }
.cat-travel  { --accent: #0284c7; --accent-light: #e0f2fe; --accent-text: #0369a1; --accent-muted: #f0f9ff; }

/* ============================================================
   LESSON SHELL — sticky header + sticky tabs + scrollable body
   ============================================================ */
.lesson-shell {
  font-family: 'Inter', sans-serif;
  background: #fff;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Top bar: fixed */
.lesson-topbar-fixed {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 40;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}
.lesson-topbar-inner {
  height: 52px;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
}
.lesson-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text-primary);
  text-decoration: none;
  flex-shrink: 0;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.1s, transform 0.1s;
}
.lesson-back-btn:active {
  background: var(--surface-2);
  transform: scale(0.93);
}
.lesson-topbar-meta { flex: 1; min-width: 0; }
.lesson-topbar-cat {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 2px;
}
.lesson-topbar-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.lesson-topbar-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--accent-muted);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
}
.lesson-topbar-icon svg { width: 20px; height: 20px; }

/* Tab bar: fixed under top bar */
.lesson-tabbar {
  position: fixed;
  top: calc(52px + var(--safe-top));
  left: 0; right: 0;
  z-index: 30;
  background: #fff;
  border-bottom: 1.5px solid var(--border);
  display: flex;
}
.lesson-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 2px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}
.lesson-tab svg { width: 20px; height: 20px; stroke-width: 1.8; }
.lesson-tab.tab-active {
  color: var(--accent);
}
.lesson-tab.tab-active::after {
  content: '';
  position: absolute;
  bottom: 0; left: 15%; right: 15%;
  height: 2.5px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
}

/* Scroll body with correct offset — below topbar (52px+safe) + tabbar (54px) */
.lesson-body {
  padding-top: calc(106px + var(--safe-top));
  flex: 1;
  overflow-y: auto;
}

/* Tab content wrapper */
.lesson-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 14px 32px;
}

/* Sticky audio player bar in listen mode */
.listen-player-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #f8fafc;
}

/* Update button */
.update-btn {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #0f172a;
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
  white-space: nowrap;
}
.update-btn:disabled { opacity: 0.7; }

/* ============================================================
   LESSON UI COMPONENTS — accent-aware
   ============================================================ */

/* Play button */
.btn-play {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s;
}
.btn-play:active { opacity: 0.8; }

/* Tab active state (legacy Tailwind tabs) */
.tab-active-legacy { background-color: var(--accent) !important; color: white !important; }

/* Highlight line */
.highlight-active-cat {
  background-color: var(--accent-muted) !important;
  border-left-color: var(--accent) !important;
}

/* Speaker color — primary (Alex) */
.speaker-primary { color: var(--accent); }

/* Vocab button */
.vocab-btn {
  background: var(--accent-muted);
  color: var(--accent-text);
  border: none;
  cursor: pointer;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}
.vocab-btn:active { background: var(--accent-light); }

/* Vocab word color */
.vocab-word { color: var(--accent-text); }

/* Practice reveal button */
.practice-btn {
  background: var(--accent-muted);
  color: var(--accent-text);
  border: none;
  cursor: pointer;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.practice-btn:active { background: var(--accent-light); }

/* Card back */
.card-back-cat {
  background-color: var(--accent-muted) !important;
}
.card-back-text { color: var(--accent-text); }

/* Quiz score */
.quiz-score-cat { color: var(--accent); }

/* Accent checkbox */
input[type="checkbox"].accent-cat { accent-color: var(--accent); }
