/* ═══════════════════════════════════════════════════════
   CSS VARIABLES & THEME
═══════════════════════════════════════════════════════ */
:root {
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface2: #f0f4f8;
  --primary: #3ecf8e;
  --primary-dark: #2ab578;
  --primary-light: #d4f5e9;
  --accent: #f59e0b;
  --accent2: #6366f1;
  --red: #ef4444;
  --text: #1a1f36;
  --text2: #64748b;
  --text3: #94a3b8;
  --border: #e2e8f0;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
  --radius: 20px;
  --radius-sm: 12px;
  --nav-h: 72px;
  --header-h: 64px;

  /* ── FIX: iOS safe-area support ──
     env(safe-area-inset-bottom) adds space on iPhone X+ notch phones
     so the nav is never hidden under the home indicator bar.        */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-dark] {
  --bg: #0f1117;
  --surface: #1a1f2e;
  --surface2: #242938;
  --primary: #3ecf8e;
  --primary-light: #1a3d2e;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --text3: #64748b;
  --border: #2d3448;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

/* ═══════════════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════════════ */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html {
  /* FIX: Use -webkit-fill-available so iOS Safari doesn't include its
     chrome in the height calculation, preventing nav from being clipped */
  height: -webkit-fill-available;
  height: 100%;
}

body {
  height: 100%;
  /* FIX: overflow auto on body (not hidden) — trapping overflow on body
     was contributing to scroll / z-index stacking bugs on mobile */
  overflow: hidden;
  background: var(--bg);
  font-family: -apple-system, 'SF Pro Display', 'Segoe UI', sans-serif;
  color: var(--text);
}

/* ═══════════════════════════════════════════════════════
   AUTH SCREEN
═══════════════════════════════════════════════════════ */
#authScreen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

#authLoading { text-align: center; }

.auth-logo-icon { font-size: 48px; margin-bottom: 16px; }
.auth-logo-text {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 12px;
}

.auth-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

#authForm {
  display: none;
  width: 90%;
  max-width: 360px;
  background: var(--surface);
  padding: 32px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-form-header { text-align: center; margin-bottom: 28px; }
.auth-form-header .auth-logo-icon { font-size: 40px; margin-bottom: 10px; }

.auth-form-title {
  font-size: 22px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.auth-form-sub { font-size: 13px; color: var(--text2); margin-top: 4px; }

.auth-input {
  width: 100%;
  margin-bottom: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  font-size: 15px;
  background: var(--surface2);
  color: var(--text);
  outline: none;
  display: block;
}
.auth-input:last-of-type { margin-bottom: 20px; }

.auth-msg {
  margin-top: 12px;
  text-align: center;
  font-size: 13px;
  color: var(--red);
  min-height: 18px;
}

/* ═══════════════════════════════════════════════════════
   APP SHELL
   FIX: Changed from height:100vh to min-height with dvh fallback.
   On mobile: 100dvh is "dynamic viewport height" which excludes
   browser chrome. Falls back to -webkit-fill-available / 100vh.
═══════════════════════════════════════════════════════ */
#app {
  display: flex;
  flex-direction: column;
  /* ── Mobile: use dynamic viewport so nav is never clipped ── */
  height: 100vh;
  height: 100dvh;                   /* modern browsers: true available height */
  min-height: -webkit-fill-available; /* Safari iOS fallback                   */

  max-width: 430px;
  margin: 0 auto;
  position: relative;
  background: var(--bg);

  /* FIX: was overflow:hidden which trapped fixed children and caused
     z-index / click-through bugs on the quiz and lesson pages.
     Changed to overflow:clip which clips visually but does NOT create
     a new stacking context that breaks fixed positioning of overlays. */
  overflow: clip;
}

/* ═══════════════════════════════════════════════════════
   HEADER
═══════════════════════════════════════════════════════ */
.header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  /* FIX: Use sticky + z-index instead of relative so the header stays
     on top without creating stacking context issues for modal/lesson overlays */
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-logo {
  font-size: 18px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-right { display: flex; gap: 12px; align-items: center; }

.streak-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(135deg, #ff6b35, #f59e0b);
  color: white;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
}

.xp-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
}

.sync-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background .3s, opacity .3s;
}
.sync-indicator.idle { opacity: 0; }
.sync-indicator.syncing { background: #f59e0b; opacity: 1; animation: syncPulse .8s ease-in-out infinite; }
.sync-indicator.synced { background: #22c55e; opacity: 1; }
.sync-indicator.error  { background: #ef4444; opacity: 1; }

@keyframes syncPulse {
  0%, 100% { transform: scale(1); opacity: .6; }
  50%      { transform: scale(1.4); opacity: 1; }
}

.dark-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface2);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

/* ═══════════════════════════════════════════════════════
   PAGES
   FIX: padding-bottom now accounts for iOS safe-area so content
   is not hidden under the home indicator on modern iPhones.
═══════════════════════════════════════════════════════ */
.page {
  flex: 1;
  overflow-y: auto;
  /* safe-area ensures content clears both the nav bar AND the iOS home indicator */
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  scroll-behavior: smooth;
  /* FIX: Allow overflow to scroll on iOS (momentum scrolling) */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;        /* Firefox: hide scrollbar */
}
.page:focus { outline: none; }
.page::-webkit-scrollbar { display: none; }
.page-hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════
   BOTTOM NAVIGATION
   FIX: Changed to position:fixed so it is anchored to the
   viewport bottom and never gets pushed off-screen regardless
   of content height. Added safe-area padding for iOS notch phones.
═══════════════════════════════════════════════════════ */
.nav {
  /* ── FIX: fixed to viewport so it can never be clipped or pushed off ── */
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;

  /* Height = base nav + iOS home indicator gap */
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);

  display: flex;
  align-items: flex-start;      /* items align to top of the nav area, not the home indicator gap */
  justify-content: space-around;
  padding-top: 6px;

  background: var(--surface);
  border-top: 1px solid var(--border);

  /* ── FIX: high z-index so nothing ever overlaps the nav ── */
  z-index: 40;

  /* Ensure nav is always clickable */
  pointer-events: all;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 4px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all .2s;
  /* FIX: ensure each nav item captures its own touch events */
  pointer-events: all;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.nav-item .nav-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  transition: all .2s;
  color: var(--text3);
}

.nav-item .nav-label { font-size: 10px; font-weight: 600; color: var(--text3); transition: color .2s; }
.nav-item.active .nav-icon { background: var(--primary-light); color: var(--primary); transform: translateY(-2px); }
.nav-item.active .nav-label { color: var(--primary); }

/* ═══════════════════════════════════════════════════════
   REUSABLE COMPONENTS
═══════════════════════════════════════════════════════ */
.card { background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.card-sm { background: var(--surface); border-radius: var(--radius-sm); padding: 16px; box-shadow: var(--shadow-sm); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all .2s;
  outline: none;
  /* FIX: explicit pointer-events and touch-action so buttons are always tappable */
  pointer-events: all;
  touch-action: manipulation;
  /* FIX: relative + z-index ensures buttons sit above any sibling overlays */
  position: relative;
  z-index: 1;
}
.btn-primary { background: var(--primary); color: white; box-shadow: 0 4px 15px rgba(62,207,142,0.4); }
.btn-primary:active { transform: scale(0.97); }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-danger { background: #fef2f2; color: var(--red); }
.btn-full { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: 13px; border-radius: 10px; }

.section { padding: 20px 20px 0; }
.section-title { font-size: 20px; font-weight: 800; margin-bottom: 16px; }
.section-sub { font-size: 13px; color: var(--text2); margin-top: 4px; }

.progress-bar { height: 10px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  border-radius: 99px;
  transition: width .6s cubic-bezier(.34,1.56,.64,1);
}

.chip { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; color: white; }

.empty-state { text-align: center; padding: 48px 24px; }
.empty-state-icon { font-size: 64px; margin-bottom: 16px; }
.empty-state-title { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.empty-state-sub { font-size: 14px; color: var(--text2); }

/* ═══════════════════════════════════════════════════════
   HOME PAGE
═══════════════════════════════════════════════════════ */
.home-hero {
  margin: 20px;
  background: linear-gradient(135deg, #3ecf8e 0%, #2ab578 50%, #1a9e63 100%);
  border-radius: 24px;
  padding: 24px;
  color: white;
  position: relative;
  overflow: hidden;
}
.home-hero::before { content: ''; position: absolute; top: -30px; right: -30px; width: 150px; height: 150px; background: rgba(255,255,255,.1); border-radius: 50%; }
.home-hero::after { content: ''; position: absolute; bottom: -20px; right: 40px; width: 80px; height: 80px; background: rgba(255,255,255,.08); border-radius: 50%; }

.hero-greeting { font-size: 14px; opacity: .85; margin-bottom: 4px; }
.hero-title { font-size: 26px; font-weight: 800; margin-bottom: 8px; line-height: 1.2; }
.hero-sub { font-size: 13px; opacity: .8; margin-bottom: 20px; }
.hero-stats { display: flex; gap: 20px; }
.hero-stat { text-align: center; }
.hero-stat-val { font-size: 22px; font-weight: 800; }
.hero-stat-lbl { font-size: 11px; opacity: .75; }
.hero-emoji { position: absolute; right: 24px; top: 50%; transform: translateY(-50%); font-size: 64px; opacity: .4; }

.today-goal { margin: 0 20px 20px; background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.goal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.goal-title { font-size: 15px; font-weight: 700; }
.goal-pct { font-size: 15px; font-weight: 800; color: var(--primary); }
.goal-tasks { display: flex; gap: 10px; margin-top: 14px; }
.goal-task { flex: 1; background: var(--surface2); border-radius: var(--radius-sm); padding: 12px; text-align: center; }
.goal-task.done { background: var(--primary-light); }
.goal-task-icon { font-size: 22px; margin-bottom: 4px; }
.goal-task-lbl { font-size: 11px; font-weight: 600; color: var(--text2); }
.goal-task.done .goal-task-lbl { color: var(--primary-dark); }

.hsk-scroll { display: flex; gap: 12px; padding: 0 20px 4px; overflow-x: auto; }
.hsk-scroll::-webkit-scrollbar { display: none; }
.hsk-chip {
  flex-shrink: 0;
  padding: 10px 18px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text2);
  touch-action: manipulation;
}
.hsk-chip.active { background: var(--primary); color: white; border-color: var(--primary); box-shadow: 0 4px 12px rgba(62,207,142,0.3); }
.hsk-chip.locked { opacity: .5; }

.lesson-grid { display: flex; flex-direction: column; gap: 12px; padding: 0 20px; }
.lesson-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: all .2s;
  border: 2px solid transparent;
  touch-action: manipulation;
}
.lesson-card:active { transform: scale(.98); }
.lesson-card.completed { border-color: var(--primary); }
.lesson-card.locked { opacity: .6; pointer-events: none; }
.lesson-icon { width: 52px; height: 52px; border-radius: 16px; display: flex; align-items: center; justify-content: center; font-size: 26px; flex-shrink: 0; }
.lesson-info { flex: 1; }
.lesson-title { font-size: 15px; font-weight: 700; margin-bottom: 3px; }
.lesson-meta { font-size: 12px; color: var(--text2); }
.lesson-badge { padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.lesson-badge.new { background: var(--primary-light); color: var(--primary-dark); }
.lesson-badge.done { background: #f0fdf4; color: #16a34a; }
.lesson-badge.locked { background: var(--surface2); color: var(--text3); }

/* ═══════════════════════════════════════════════════════
   SEARCH BAR
═══════════════════════════════════════════════════════ */
.search-bar { margin: 0 20px 12px; }
.search-bar-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 0 14px;
  transition: all .25s;
  box-shadow: var(--shadow-sm);
}
.search-bar-inner:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(62,207,142,0.15);
}
.search-icon {
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}
.search-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  outline: none;
  font-family: inherit;
}
.search-input::placeholder {
  color: var(--text3);
  font-weight: 400;
}
.search-clear-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--surface2);
  color: var(--text2);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all .2s;
}
.search-clear-btn:hover {
  background: var(--border);
  color: var(--text);
}
.search-header {
  font-size: 13px;
  color: var(--text2);
  margin: 4px 20px 12px;
  padding: 0 4px;
}
.vocab-hsk-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* ═══════════════════════════════════════════════════════
   STUDY PAGE
═══════════════════════════════════════════════════════ */
.level-select { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 0 20px; }
.level-btn { background: var(--surface); border-radius: var(--radius-sm); padding: 16px 8px; text-align: center; cursor: pointer; border: 2px solid var(--border); transition: all .2s; touch-action: manipulation; }
.level-btn:active { transform: scale(.97); }
.level-btn.active { border-color: var(--primary); background: var(--primary-light); }
.level-btn.locked { opacity: .5; }
.level-num { font-size: 22px; font-weight: 800; color: var(--primary); }
.level-name { font-size: 10px; color: var(--text2); margin-top: 2px; }
.level-words { font-size: 10px; color: var(--text3); margin-top: 2px; }

.vocab-list { display: flex; flex-direction: column; gap: 10px; padding: 0 20px; }
.vocab-item { background: var(--surface); border-radius: var(--radius-sm); padding: 16px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow-sm); cursor: pointer; transition: all .2s; touch-action: manipulation; }
.vocab-item:active { transform: scale(.98); }
.vocab-char { font-size: 32px; font-weight: 400; min-width: 48px; text-align: center; line-height: 1; }
.vocab-details { flex: 1; }
.vocab-pinyin { font-size: 13px; color: var(--primary-dark); font-weight: 600; margin-bottom: 2px; }
.vocab-meaning { font-size: 14px; color: var(--text); font-weight: 500; }
.vocab-type { font-size: 11px; color: var(--text3); background: var(--surface2); padding: 2px 8px; border-radius: 20px; display: inline-block; margin-top: 4px; }
.vocab-audio { width: 36px; height: 36px; border-radius: 50%; background: var(--primary-light); display: flex; align-items: center; justify-content: center; font-size: 16px; cursor: pointer; flex-shrink: 0; touch-action: manipulation; }

/* ═══════════════════════════════════════════════════════
   FLASHCARDS PAGE
═══════════════════════════════════════════════════════ */
.fc-container { display: flex; flex-direction: column; align-items: center; padding: 20px; height: 100%; }
.fc-progress { width: 100%; display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.fc-prog-bar { flex: 1; height: 8px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.fc-prog-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent2)); border-radius: 99px; transition: width .4s; }
.fc-counter { font-size: 13px; font-weight: 700; color: var(--text2); }

.fc-card-area { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; perspective: 1000px; }
.fc-card { width: 100%; max-width: 340px; height: 380px; position: relative; cursor: pointer; transition: transform .05s; touch-action: manipulation; }
.fc-card:active { transform: scale(.98); }
.fc-card.flipped .fc-front { transform: rotateY(180deg); }
.fc-card.flipped .fc-back { transform: rotateY(0deg); }
.fc-front, .fc-back {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  border-radius: 28px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px;
  transition: transform .5s cubic-bezier(.34,1.56,.64,1);
}
.fc-front { background: linear-gradient(135deg, var(--surface) 0%, var(--surface2) 100%); border: 2px solid var(--border); box-shadow: var(--shadow); }
.fc-back { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); transform: rotateY(-180deg); box-shadow: 0 8px 32px rgba(62,207,142,0.4); }
.fc-char { font-size: 80px; font-weight: 300; line-height: 1; text-align: center; }
.fc-hint { font-size: 13px; color: var(--text3); margin-top: 20px; }
.fc-pinyin { font-size: 24px; font-weight: 700; color: white; margin-bottom: 12px; }
.fc-meaning { font-size: 20px; font-weight: 600; color: rgba(255,255,255,.9); text-align: center; }
.fc-example { font-size: 13px; color: rgba(255,255,255,.7); margin-top: 16px; text-align: center; font-style: italic; }

.fc-swipe-hint { display: flex; justify-content: space-between; width: 100%; max-width: 340px; margin: 16px 0; }
.fc-swipe-lbl { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text3); font-weight: 600; }
.fc-actions { display: flex; gap: 16px; width: 100%; max-width: 340px; }
.fc-btn { flex: 1; padding: 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 700; border: none; cursor: pointer; transition: all .2s; display: flex; flex-direction: column; align-items: center; gap: 4px; touch-action: manipulation; }
.fc-btn:active { transform: scale(.96); }
.fc-btn-skip { background: #fef2f2; color: var(--red); }
.fc-btn-know { background: var(--primary-light); color: var(--primary-dark); }
.fc-btn-icon { font-size: 22px; }

/* ═══════════════════════════════════════════════════════
   QUIZ PAGE
   FIX: Added explicit z-index and pointer-events to all quiz
   interactive elements so they can never be blocked by
   sibling fixed/absolute elements from other pages.
═══════════════════════════════════════════════════════ */
.quiz-container { padding: 20px; position: relative; z-index: 1; }
.quiz-header { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.quiz-q-num { font-size: 13px; color: var(--text2); font-weight: 600; margin-bottom: 6px; }
.quiz-score-badge { background: var(--primary-light); color: var(--primary-dark); padding: 6px 14px; border-radius: 20px; font-size: 14px; font-weight: 800; }
.qtype-chip { flex-shrink: 0; padding: 8px 14px; border-radius: 20px; font-size: 12px; font-weight: 700; cursor: pointer; border: 2px solid var(--border); background: var(--surface); color: var(--text2); transition: all .2s; touch-action: manipulation; }
.qtype-chip.active { background: var(--accent2); color: white; border-color: var(--accent2); }
.quiz-question { background: var(--surface); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow-sm); margin-bottom: 20px; text-align: center; }
.quiz-q-label { font-size: 12px; color: var(--text3); font-weight: 600; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 16px; }
.quiz-q-char { font-size: 56px; font-weight: 300; line-height: 1.1; }
.quiz-q-text { font-size: 18px; font-weight: 600; line-height: 1.4; }
.quiz-q-pinyin { font-size: 16px; color: var(--primary-dark); font-weight: 600; margin-top: 8px; }
.quiz-audio-btn {
  width: 60px; height: 60px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent2), #8b5cf6);
  border: none; cursor: pointer; font-size: 28px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto; box-shadow: 0 4px 16px rgba(99,102,241,.35); transition: all .2s;
  touch-action: manipulation;
  position: relative; z-index: 1;
}
.quiz-audio-btn:active { transform: scale(.92); }
.quiz-options { display: flex; flex-direction: column; gap: 10px; position: relative; z-index: 1; }
.quiz-opt {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  font-size: 15px;
  font-weight: 600;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  gap: 12px;
  /* FIX: explicit pointer-events + touch-action so options are always tappable */
  pointer-events: all;
  touch-action: manipulation;
  position: relative;
  z-index: 1;
}
.quiz-opt:active { transform: scale(.98); }
.quiz-opt.correct { background: #f0fdf4; border-color: #22c55e; color: #16a34a; }
.quiz-opt.wrong { background: #fef2f2; border-color: var(--red); color: var(--red); }
.quiz-opt-num { width: 28px; height: 28px; border-radius: 50%; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; flex-shrink: 0; }
.quiz-feedback { margin-top: 16px; padding: 14px 18px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.quiz-feedback.correct { background: #f0fdf4; color: #16a34a; }
.quiz-feedback.wrong { background: #fef2f2; color: var(--red); }

/* ═══════════════════════════════════════════════════════
   PROFILE PAGE
═══════════════════════════════════════════════════════ */
.profile-hero { margin: 20px; background: linear-gradient(135deg, var(--accent2) 0%, #8b5cf6 100%); border-radius: 24px; padding: 24px; color: white; display: flex; align-items: center; gap: 20px; }
.profile-avatar { width: 72px; height: 72px; border-radius: 50%; background: rgba(255,255,255,.25); display: flex; align-items: center; justify-content: center; font-size: 36px; border: 3px solid rgba(255,255,255,.4); flex-shrink: 0; }
.profile-name { font-size: 22px; font-weight: 800; }
.profile-level { font-size: 13px; opacity: .85; margin-top: 4px; }
.profile-joined { font-size: 12px; opacity: .65; margin-top: 2px; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 0 20px; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); text-align: center; }
.stat-card-icon { font-size: 28px; margin-bottom: 8px; }
.stat-card-val { font-size: 28px; font-weight: 800; }
.stat-card-lbl { font-size: 12px; color: var(--text2); margin-top: 2px; }

.achievement-list { display: flex; flex-direction: column; gap: 10px; padding: 0 20px; }
.achievement-item { background: var(--surface); border-radius: var(--radius-sm); padding: 16px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow-sm); }
.ach-icon { width: 48px; height: 48px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0; }
.ach-info { flex: 1; }
.ach-title { font-size: 14px; font-weight: 700; }
.ach-desc { font-size: 12px; color: var(--text2); margin-top: 2px; }
.ach-badge { padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; background: var(--primary-light); color: var(--primary-dark); }
.ach-badge.locked { background: var(--surface2); color: var(--text3); }

/* ═══════════════════════════════════════════════════════
   MODALS
   FIX: When closed, pointer-events:none prevents modal overlay
   from silently blocking all taps on the content behind it.
   This was the #1 cause of "buttons not clickable" on quiz page.
═══════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  /* FIX: z-index 300 — above nav (40) and lesson (50), below auth (999) */
  z-index: 300;
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(4px);
  opacity: 0;
  /* FIX: pointer-events none when closed — this was blocking quiz button taps */
  pointer-events: none;
  transition: opacity .3s;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  padding: 24px 24px 40px;
  width: 100%; max-width: 430px;
  transform: translateY(100%);
  transition: transform .4s cubic-bezier(.34,1.56,.64,1);
  max-height: 85vh; overflow-y: auto;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-handle { width: 40px; height: 4px; background: var(--border); border-radius: 99px; margin: 0 auto 20px; }

.vd-char { font-size: 72px; text-align: center; line-height: 1; margin: 20px 0 12px; }
.vd-pinyin { font-size: 22px; color: var(--primary-dark); font-weight: 700; text-align: center; margin-bottom: 4px; }
.vd-meaning { font-size: 18px; font-weight: 600; text-align: center; color: var(--text); margin-bottom: 16px; }
.vd-tags { display: flex; gap: 8px; justify-content: center; margin-bottom: 20px; flex-wrap: wrap; }
.vd-tag { padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--surface2); color: var(--text2); }
.vd-examples { background: var(--surface2); border-radius: var(--radius-sm); padding: 16px; }
.vd-example { margin-bottom: 14px; }
.vd-example:last-child { margin-bottom: 0; }
.vd-ex-cn { font-size: 16px; font-weight: 500; margin-bottom: 2px; }
.vd-ex-py { font-size: 13px; color: var(--primary-dark); font-weight: 500; margin-bottom: 2px; }
.vd-ex-en { font-size: 13px; color: var(--text2); }

/* ═══════════════════════════════════════════════════════
   LESSON MODE
   FIX: When closed (off-screen), pointer-events:none prevents
   the off-screen lesson panel from blocking taps on the quiz
   and other pages behind it (was a major source of unclickable buttons).
═══════════════════════════════════════════════════════ */
.lesson-page {
  position: fixed; inset: 0;
  background: var(--bg);
  /* FIX: z-index 200 — above nav (40) but below modal (300) and auth (999) */
  z-index: 200;
  display: flex; flex-direction: column;
  max-width: 430px; margin: 0 auto;
  transform: translateX(100%);
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  /* FIX: pointer-events none when hidden so it never blocks taps on pages below */
  pointer-events: none;
}
.lesson-page.open {
  transform: translateX(0);
  /* Only accept taps when visible */
  pointer-events: all;
}

.lesson-header {
  height: 60px; display: flex; align-items: center; padding: 0 20px; gap: 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.lesson-back-btn {
  width: 36px; height: 36px; border-radius: 50%; background: var(--surface2);
  border: none; cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0; touch-action: manipulation;
}
.lesson-header-title { font-size: 30px; font-weight: 700; flex: 1; }
.lesson-step-indicator { display: flex; gap: 6px; }
.lesson-step-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); transition: background .3s; }
.lesson-step-dot.active { background: var(--primary); }
.lesson-step-dot.done { background: var(--primary-dark); }

.lesson-body { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.lesson-body::-webkit-scrollbar { display: none; }

/* Lesson Intro */
.lesson-intro { padding: 24px 20px; }
.lesson-intro-hero { border-radius: 24px; padding: 32px 24px; text-align: center; color: white; margin-bottom: 24px; position: relative; overflow: hidden; }
.lesson-intro-hero::before { content: ''; position: absolute; top: -20px; right: -20px; width: 100px; height: 100px; background: rgba(255,255,255,.12); border-radius: 50%; }
.lesson-intro-icon { font-size: 60px; margin-bottom: 12px; }
.lesson-intro-title { font-size: 22px; font-weight: 800; margin-bottom: 6px; }
.lesson-intro-sub { font-size: 14px; opacity: .85; }

.lesson-word-preview { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.lesson-word-preview-item { background: var(--surface); border-radius: var(--radius-sm); padding: 14px 16px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow-sm); }
.lwp-char { font-size: 26px; min-width: 40px; text-align: center; }
.lwp-info { flex: 1; }
.lwp-pinyin { font-size: 12px; color: var(--primary-dark); font-weight: 600; }
.lwp-meaning { font-size: 14px; font-weight: 600; }
.lwp-type { font-size: 11px; color: var(--text3); background: var(--surface2); padding: 2px 8px; border-radius: 20px; display: inline-block; margin-top: 3px; }

/* Lesson Study Cards */
.lesson-study { padding: 0; height: 100%; display: flex; flex-direction: column; }
.lesson-study-progress { padding: 16px 20px 8px; }
.lesson-study-card-area { flex: 1; display: flex; align-items: center; justify-content: center; padding: 0 20px; perspective: 1000px; }

.ls-card { width: 100%; max-width: 340px; height: 360px; position: relative; cursor: pointer; touch-action: manipulation; }
.ls-card.flipped .ls-front { transform: rotateY(180deg); }
.ls-card.flipped .ls-back { transform: rotateY(0deg); }
.ls-front, .ls-back { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 28px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px; transition: transform .5s cubic-bezier(.34,1.56,.64,1); }
.ls-front { background: var(--surface); border: 2px solid var(--border); box-shadow: var(--shadow); }
.ls-back { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); transform: rotateY(-180deg); box-shadow: 0 8px 32px rgba(62,207,142,0.4); }
.ls-char { font-size: 72px; font-weight: 300; line-height: 1; }
.ls-hint { font-size: 13px; color: var(--text3); margin-top: 16px; }
.ls-lesson-tag { font-size: 11px; font-weight: 700; background: var(--surface2); color: var(--text3); padding: 4px 12px; border-radius: 20px; margin-bottom: 20px; }
.ls-pinyin { font-size: 22px; font-weight: 700; color: white; margin-bottom: 10px; }
.ls-meaning { font-size: 19px; font-weight: 600; color: rgba(255,255,255,.95); text-align: center; }
.ls-example { font-size: 13px; color: rgba(255,255,255,.7); margin-top: 14px; text-align: center; font-style: italic; }

.lesson-study-actions { padding: 16px 20px 24px; display: flex; gap: 12px; }
.ls-btn { flex: 1; padding: 14px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 700; border: none; cursor: pointer; transition: all .2s; display: flex; flex-direction: column; align-items: center; gap: 4px; touch-action: manipulation; }
.ls-btn:active { transform: scale(.96); }
.ls-btn-again { background: #fef2f2; color: var(--red); }
.ls-btn-good { background: #fefce8; color: #a16207; }
.ls-btn-easy { background: var(--primary-light); color: var(--primary-dark); }
.ls-btn-icon { font-size: 20px; }

/* Lesson Quiz */
.lesson-quiz { padding: 20px; }
.lq-question { background: var(--surface); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow-sm); margin-bottom: 20px; text-align: center; }
.lq-label { font-size: 11px; color: var(--text3); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 14px; }
.lq-char { font-size: 52px; font-weight: 300; line-height: 1.1; }
.lq-pinyin { font-size: 15px; color: var(--primary-dark); font-weight: 600; margin-top: 6px; }
.lq-options { display: flex; flex-direction: column; gap: 10px; }
.lq-opt { background: var(--surface); border-radius: var(--radius-sm); padding: 16px 18px; font-size: 15px; font-weight: 600; border: 2px solid var(--border); cursor: pointer; transition: all .2s; display: flex; align-items: center; gap: 12px; touch-action: manipulation; pointer-events: all; }
.lq-opt.correct { background: #f0fdf4; border-color: #22c55e; color: #16a34a; }
.lq-opt.wrong { background: #fef2f2; border-color: var(--red); color: var(--red); }
.lq-opt-num { width: 26px; height: 26px; border-radius: 50%; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; flex-shrink: 0; }
.lq-feedback { margin-top: 14px; padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; }
.lq-feedback.correct { background: #f0fdf4; color: #16a34a; }
.lq-feedback.wrong { background: #fef2f2; color: var(--red); }

/* Lesson Complete */
.lesson-complete { padding: 32px 20px; text-align: center; }
.lc-trophy { font-size: 80px; margin-bottom: 16px; animation: pop .5s cubic-bezier(.34,1.56,.64,1); }
.lc-title { font-size: 26px; font-weight: 800; margin-bottom: 8px; }
.lc-sub { font-size: 15px; color: var(--text2); margin-bottom: 32px; }
.lc-stats { display: flex; justify-content: center; gap: 28px; margin-bottom: 32px; }
.lc-stat { text-align: center; }
.lc-stat-val { font-size: 28px; font-weight: 800; }
.lc-stat-lbl { font-size: 12px; color: var(--text2); margin-top: 2px; }
.lc-xp-badge { display: inline-flex; align-items: center; gap: 8px; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: white; padding: 12px 24px; border-radius: 99px; font-size: 18px; font-weight: 800; margin-bottom: 28px; box-shadow: 0 4px 20px rgba(62,207,142,0.4); animation: bounce .6s ease .3s both; }
.lc-words-mastered { background: var(--surface2); border-radius: var(--radius); padding: 20px; margin-bottom: 24px; text-align: left; }
.lc-words-title { font-size: 13px; font-weight: 700; color: var(--text2); margin-bottom: 12px; }
.lc-word-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); padding: 6px 12px; border-radius: 20px; font-size: 13px; font-weight: 600; margin: 4px; box-shadow: var(--shadow-sm); }

/* ═══════════════════════════════════════════════════════
   XP TOAST
═══════════════════════════════════════════════════════ */
.xp-toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 14px; font-weight: 700;
  z-index: 500;
  opacity: 0; pointer-events: none;
  transition: all .3s;
  white-space: nowrap;
}
.xp-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ═══════════════════════════════════════════════════════
   HSK LEVEL COLORS
═══════════════════════════════════════════════════════ */
.hsk1 { background: linear-gradient(135deg, #84cc16, #65a30d); }
.hsk2 { background: linear-gradient(135deg, #22c55e, #16a34a); }
.hsk3 { background: linear-gradient(135deg, #06b6d4, #0891b2); }
.hsk4 { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.hsk5 { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }
.hsk6 { background: linear-gradient(135deg, #ec4899, #db2777); }
.hsk7 { background: linear-gradient(135deg, #f97316, #ea580c); }
.hsk8 { background: linear-gradient(135deg, #ef4444, #dc2626); }
.hsk9 { background: linear-gradient(135deg, #1a1a2e, #16213e); }

/* ═══════════════════════════════════════════════════════
   ANIMATIONS
═══════════════════════════════════════════════════════ */
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pop { 0% { transform: scale(0.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes swipeLeft { to { transform: translateX(-120%) rotate(-15deg); opacity: 0; } }
@keyframes swipeRight { to { transform: translateX(120%) rotate(15deg); opacity: 0; } }

.animate-up { animation: slideUp .4s ease forwards; }
.animate-pop { animation: pop .3s cubic-bezier(.34,1.56,.64,1) forwards; }
.animate-shake { animation: shake .4s ease; }


/* ═══════════════════════════════════════════════════════
   DESKTOP PANEL — hidden on mobile, built for CSS grid
   All these styles are display:none until ≥1024px.
═══════════════════════════════════════════════════════ */

/* Wrapper and sidebar/panel hidden by default (mobile) */
#desktopWrapper { display: contents; }
#desktopSidebar { display: none; }
#desktopPanel   { display: none; }

/* ── Right Panel card components ── */
.dp-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  border: 1px solid var(--border);
}

.dp-card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 14px;
}

/* User card */
.dp-user-card { display: flex; align-items: center; gap: 12px; }
.dp-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent2), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex-shrink: 0;
}
.dp-user-name { font-size: 15px; font-weight: 700; }
.dp-user-level { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* Stats row */
.dp-stats-row { display: flex; align-items: center; gap: 0; }
.dp-stat { flex: 1; text-align: center; }
.dp-stat-val { font-size: 24px; font-weight: 800; color: var(--text); }
.dp-stat-lbl { font-size: 11px; color: var(--text2); margin-top: 2px; }
.dp-stat-divider { width: 1px; height: 36px; background: var(--border); }

.dp-sync-row {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.dp-sync-label { font-size: 11px; color: var(--text3); transition: color .3s; }
.dp-sync-row .sync-indicator.synced + .dp-sync-label { color: #22c55e; }
.dp-sync-row .sync-indicator.error + .dp-sync-label { color: #ef4444; }

/* Daily goal */
.dp-goal-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.dp-goal-label { font-size: 13px; color: var(--text2); }
.dp-goal-pct { font-size: 13px; font-weight: 800; color: var(--primary); }
.dp-progress-bar { height: 8px; background: var(--surface2); border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.dp-progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-dark)); border-radius: 99px; transition: width .6s cubic-bezier(.34,1.56,.64,1); }

.dp-goal-tasks { display: flex; flex-direction: column; gap: 8px; }
.dp-goal-task {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface2);
  font-size: 13px; font-weight: 600; color: var(--text2);
  transition: all .2s;
}
.dp-task-icon { font-size: 16px; }
.dp-goal-task span:nth-child(2) { flex: 1; }
.dp-task-check { font-size: 14px; font-weight: 800; color: var(--text3); }
.dp-goal-task.dp-task-done { background: var(--primary-light); color: var(--primary-dark); }
.dp-goal-task.dp-task-done .dp-task-check { color: var(--primary); }

/* Quick actions */
.dp-quick-actions { display: flex; flex-direction: column; gap: 8px; }
.dp-action-btn {
  display: block; width: 100%;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 13px; font-weight: 600; color: var(--text);
  cursor: pointer; text-align: left;
  transition: all .15s;
}
.dp-action-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary-dark); }

/* HSK list */
.dp-hsk-list { display: flex; flex-direction: column; gap: 6px; }
.dp-hsk-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  cursor: pointer; transition: background .15s;
}
.dp-hsk-row:hover { background: var(--surface2); }
.dp-hsk-emoji { font-size: 18px; flex-shrink: 0; }
.dp-hsk-name { flex: 1; font-size: 13px; font-weight: 600; }
.dp-hsk-words { font-size: 11px; color: var(--text3); }
.dp-hsk-badge { font-size: 12px; }
.dp-hsk-locked { opacity: .5; cursor: default; }
.dp-hsk-locked:hover { background: transparent; }

/* Tip card */
.dp-tip-card { background: linear-gradient(135deg, #fef9c3, #fef3c7); border-color: #fde68a; }
[data-dark] .dp-tip-card { background: #2d2810; border-color: #4a3f10; }
.dp-tip-label { font-size: 12px; font-weight: 700; color: #a16207; margin-bottom: 8px; }
[data-dark] .dp-tip-label { color: #f59e0b; }
.dp-tip-text { font-size: 13px; color: #78350f; line-height: 1.55; }
[data-dark] .dp-tip-text { color: #fbbf24; }

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — DESKTOP (≥ 1024px)
   Full 3-column layout: sidebar | main | right panel
═══════════════════════════════════════════════════════ */
@media (min-width: 1024px) {

  /* ── Body: nicer background for the desktop chrome ── */
  body { background: #eef1f8; overflow: hidden; }
  [data-dark] body { background: #0d0f18; }

  /* ── Auth screen: centered card, no change needed ── */
  #authScreen { background: #eef1f8; }
  [data-dark] #authScreen { background: #0d0f18; }

  /* ══════════════════════════════════════════════════
     DESKTOP WRAPPER: 3-column CSS Grid
     Sidebar (90px) | Main (1fr) | Right Panel (300px)
  ═══════════════════════════════════════════════════ */
  #desktopWrapper {
    display: grid;
    grid-template-columns: 90px 1fr 300px;
    grid-template-rows: 100vh;
    grid-template-areas: "sidebar main panel";
    max-width: 1400px;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    background: var(--bg);
  }

  /* ══════════════════════════════════════════════════
     LEFT SIDEBAR
  ═══════════════════════════════════════════════════ */
  #desktopSidebar {
    display: flex;           /* show on desktop */
    grid-area: sidebar;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 0 24px;
    position: sticky;
    top: 0;
    z-index: 30;
    overflow: hidden;
  }

  /* Sidebar logo */
  .ds-logo {
  display: flex;
  align-items: center;
}

.ds-logo img {
  height: 40px;
  width: auto;
  position: relative;
  top: -5px; 
}

  /* Sidebar nav */
  .ds-nav {
    display: flex; flex-direction: column; align-items: center;
    gap: 4px; width: 100%; flex: 1;
  }

  .ds-nav-item {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    width: 72px; padding: 10px 6px;
    background: none; border: none; cursor: pointer;
    border-radius: 14px;
    transition: background .15s, transform .15s;
    color: var(--text3);
    font-family: inherit;
    position: relative;
  }
  .ds-nav-item:hover { background: var(--surface2); color: var(--text2); }
  .ds-nav-item.active {
    background: var(--primary-light);
    color: var(--primary-dark);
  }
  /* Green left accent bar on active item */
  .ds.nav-item.active::before {
    content: '';
    position: absolute; left: -1px; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 24px;
    background: var(--primary);
    border-radius: 0 4px 4px 0;
    transition: all 0.25s ease;
  }

  .ds-nav-icon { font-size: 22px; line-height: 1; }
  .ds-nav-label { font-size: 10px; font-weight: 600; }

  /* Dark mode toggle at sidebar bottom */
  .ds-dark-btn {
    width: 42px; height: 42px; border-radius: 50%;
    background: var(--surface2); border: 1px solid var(--border);
    font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s;
    margin-top: auto;
  }
  .ds-dark-btn:hover { background: var(--border); }

  /* ══════════════════════════════════════════════════
     MAIN APP COLUMN
  ═══════════════════════════════════════════════════ */
  #app {
    grid-area: main;
    /* Override mobile sizing — let the grid control width */
    max-width: none;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    /* Remove mobile clip that caused z-index issues */
    overflow: clip;
  }

  /* ── Header: shown in main column (no longer hidden) ── */
  .header {
    position: sticky; top: 0; z-index: 20;
    /* Slightly different style on desktop — more spacious */
    padding: 0 28px;
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  /* ── Mobile bottom nav: completely hidden on desktop ── */
  .nav { display: none !important; }

  /* ── Pages: fill remaining space, scrollable ── */
  .page {
    flex: 1;
    overflow-y: auto;
    /* No bottom nav on desktop — just a comfortable bottom gap */
    padding-bottom: 32px;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Lesson page overlay: constrained to main column ── */
  .lesson-page {
    position: absolute;   /* relative to #app, not the full viewport */
    inset: 0;
    max-width: none;
    margin: 0;
    z-index: 200;
  }

  /* ── Modal overlay: also constrained to main column ── */
  .modal-overlay {
    position: absolute;
    inset: 0;
  }
  .modal { max-width: 100%; border-radius: 20px 20px 0 0; }

  /* ══════════════════════════════════════════════════
     RIGHT PANEL
  ═══════════════════════════════════════════════════ */
  #desktopPanel {
    display: flex;
    grid-area: panel;
    flex-direction: column;
    gap: 14px;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
    border-left: 1px solid var(--border);
    padding: 20px 16px 24px;
    overflow-y: auto;
    overflow-x: hidden;
    position: sticky;
    top: 0;
  }
  #desktopPanel::-webkit-scrollbar { display: none; }

  /* ══════════════════════════════════════════════════
     CONTENT REFINEMENTS FOR DESKTOP
  ═══════════════════════════════════════════════════ */

  /* Home hero — slightly taller on desktop */
  .home-hero { margin: 20px 24px 16px; }
  .today-goal { margin: 0 24px 16px; }

  /* Lesson grid: 2 columns */
  .lesson-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    padding: 0 24px;
  }

  /* HSK scroll */
  .hsk-scroll { padding: 0 24px 4px; }

  /* Section padding */
  .section { padding: 20px 24px 0; }

  /* Study level selector: 5 columns */
  .level-select {
    grid-template-columns: repeat(5, 1fr);
    padding: 0 24px;
    gap: 12px;
  }
  .search-bar { margin: 0 24px 12px; }
  .search-header { margin: 4px 24px 12px; }
  .vocab-list { padding: 0 24px; }

  /* Stats grid: 3 columns on desktop */
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
    padding: 0 24px;
  }
  .achievement-list { padding: 0 24px; }
  .profile-hero { margin: 20px 24px; }

  /* Flashcard: comfortable size on desktop */
  .fc-container { padding: 24px 40px; }
  .fc-card { max-width: 400px; height: 340px; }
  .fc-actions { max-width: 400px; }
  .fc-swipe-hint { max-width: 400px; }

  /* Quiz: centered column */
  .quiz-container { max-width: 580px; margin: 0 auto; padding: 24px 32px; }

  /* Lesson overlays */
  .lesson-study-card-area { padding: 0 40px; }
  .ls-card { max-width: 400px; }
  .lesson-study-actions { padding: 16px 40px 28px; }
  .lesson-quiz { padding: 24px 40px; }
  .lesson-intro { padding: 24px 40px; }
  .lesson-complete { padding: 36px 40px; }

} /* end @media (min-width:1024px) */

/* ── Very wide screens (≥ 1440px): wider main, wider panel ── */
@media (min-width: 1440px) {
  #desktopWrapper {
    grid-template-columns: 100px 1fr 320px;
    max-width: 1560px;
  }
  #desktopSidebar { width: 100px; }
  .ds-nav-item { width: 80px; }
}
