/* =============================================
   ChinesePod PWA — Stylesheet
   Aesthetic: Ink & Jade · editorial calm
   Font: Playfair Display + DM Sans
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700&family=DM+Sans:wght@300;400;500;600&display=swap');

/* ---- Tokens ---- */
:root {
  --jade: #3D8C7A;
  --jade-light: #52A990;
  --jade-dark: #2A6358;
  --ink: #1A1F1E;
  --sand: #F2F5F3;
  --sand-dark: #E4EAE7;
  --surface: #F8FAF9;
  --card: #FFFFFF;
  --muted: #6B7876;
  --border: #D8E2DF;

  --level-newbie: #4A90A4;
  --level-beginner: #5BA85A;
  --level-intermediate: #C47B2A;
  --level-upper: #7B5EA7;
  --level-culture: #C4453A;

  --radius: 14px;
  --radius-sm: 8px;
  --nav-h: 64px;
  --transition: 0.2s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --sand: #111615;
    --sand-dark: #1A201E;
    --surface: #0D1210;
    --card: #161D1B;
    --ink: #E8F0ED;
    --muted: #7A9490;
    --border: #263330;
    --jade-light: #4A9E8C;
  }
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--surface);
  color: var(--ink);
  min-height: 100dvh;
  overflow-x: hidden;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

/* ---- Utilities ---- */
.hidden { display: none !important; }
.loading { text-align: center; padding: 2rem; color: var(--muted); font-size: 0.9rem; }
.empty-msg { color: var(--muted); font-size: 0.9rem; padding: 1rem 0; text-align: center; }

/* ---- Views ---- */
.view { display: none; padding: 1rem; padding-top: 1.5rem; max-width: 640px; margin: 0 auto; }
.view.active { display: block; }

/* ---- Bottom Nav ---- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; align-items: flex-start; padding-top: 6px;
  z-index: 100; backdrop-filter: blur(12px);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; cursor: pointer; color: var(--muted);
  font-family: 'DM Sans', sans-serif; font-size: 0.7rem; font-weight: 500; padding: 6px 0;
  transition: color var(--transition);
}
.nav-btn .nav-icon { font-size: 1.4rem; line-height: 1; }
.nav-btn.active { color: var(--jade); }

/* ---- Page Header ---- */
.page-header { margin-bottom: 1.5rem; }
.page-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem; font-weight: 700; color: var(--ink); line-height: 1.1;
}
.page-subtitle { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }

/* ---- Section Labels ---- */
.section-label {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--muted); margin: 1.5rem 0 0.6rem;
}

/* ---- Cards ---- */
.lesson-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; margin-bottom: 0.6rem;
  cursor: pointer; transition: transform var(--transition);
  display: flex; flex-direction: column; gap: 4px; position: relative;
}
.lesson-card:active { transform: scale(0.98); }
.lesson-card.card-next {
  background: linear-gradient(135deg, var(--jade) 0%, var(--jade-dark) 100%);
  border-color: transparent; color: white;
}
.card-next .card-meta { color: rgba(255,255,255,0.7); }
.card-next .card-arrow {
  position: absolute; right: 1rem; top: 50%; transform: translateY(-50%);
  font-size: 1.4rem; color: rgba(255,255,255,0.6);
}
.lesson-card.lesson-list-item {
  flex-direction: row; align-items: center; gap: 0.75rem; padding: 0.85rem 1rem;
}
.card-left { flex: 1; min-width: 0; }
.card-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.lesson-card.lesson-card-sm { padding: 0.75rem 1rem; }
.card-title { font-weight: 600; font-size: 1rem; color: var(--ink); line-height: 1.3; }
.card-next .card-title { color: white; }
.card-meta { font-size: 0.75rem; color: var(--muted); }

/* ---- Level Badges ---- */
.card-level-badge {
  display: inline-block; font-size: 0.6rem; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; padding: 2px 6px; border-radius: 4px; margin-bottom: 4px; color: white;
}
.level-newbie { background: var(--level-newbie); }
.level-beginner { background: var(--level-beginner); }
.level-intermediate { background: var(--level-intermediate); }
.level-upper { background: var(--level-upper); }
.level-culture { background: var(--level-culture); }
.level-chip-culture { border-left: 3px solid var(--level-culture); }

/* ---- Badges ---- */
.badge { font-size: 0.65rem; font-weight: 600; padding: 2px 5px; border-radius: 4px; display: inline-block; }
.badge-listen { background: rgba(61,140,122,0.12); color: var(--jade); }
.fav-star { color: #F0A020; font-size: 1rem; }
.done-check { color: var(--level-beginner); font-size: 0.85rem; font-weight: 700; }

/* ---- Hero ---- */
.home-hero {
  background: linear-gradient(135deg, var(--jade) 0%, #1E5C50 100%);
  border-radius: var(--radius); padding: 1.5rem; color: white;
  margin-bottom: 0.5rem; position: relative; overflow: hidden;
}
.home-hero::after {
  content: '中'; position: absolute; right: 1rem; top: 50%; transform: translateY(-50%);
  font-size: 5rem; opacity: 0.12; font-weight: 700; line-height: 1;
}
.hero-tagline {
  font-family: 'Playfair Display', serif; font-size: 1.4rem; font-weight: 700; margin-bottom: 1rem;
}
.hero-stats { display: flex; gap: 1rem; }
.hero-stat { display: flex; flex-direction: column; }
.stat-num { font-size: 1.5rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.7rem; opacity: 0.75; text-transform: uppercase; letter-spacing: 0.05em; }

/* ---- Level Grid ---- */
.level-grid { display: flex; flex-direction: column; gap: 0.5rem; }
.level-chip {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.75rem 1rem;
  display: flex; align-items: center; gap: 0.75rem;
  cursor: pointer; transition: background var(--transition);
}
.level-chip:active { background: var(--sand-dark); }
.level-chip-icon { font-size: 1.3rem; }
.level-chip-name { flex: 1; font-weight: 500; font-size: 0.9rem; }
.level-chip-count { font-size: 0.75rem; color: var(--muted); background: var(--sand-dark); padding: 2px 8px; border-radius: 20px; }
.level-chip-newbie { border-left: 3px solid var(--level-newbie); }
.level-chip-beginner { border-left: 3px solid var(--level-beginner); }
.level-chip-intermediate { border-left: 3px solid var(--level-intermediate); }
.level-chip-upper { border-left: 3px solid var(--level-upper); }

/* ---- Library Filters ---- */
.library-filters { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.search-box {
  display: flex; align-items: center;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 0.75rem;
}
.search-box input {
  flex: 1; border: none; background: none; padding: 0.65rem 0.5rem;
  font-family: 'DM Sans', sans-serif; font-size: 0.9rem; color: var(--ink); outline: none;
}
.search-icon { color: var(--muted); font-size: 1rem; }
.filter-select {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem; font-family: 'DM Sans', sans-serif; font-size: 0.8rem;
  color: var(--ink); cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.6rem center; padding-right: 1.8rem;
}
.library-count { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.5rem; }

/* ---- Lesson View ---- */
.lesson-view-header {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 1.25rem; padding-top: env(safe-area-inset-top);
}
.back-btn {
  background: var(--card); border: 1px solid var(--border); border-radius: 50%;
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 1rem; color: var(--ink); flex-shrink: 0;
}
.lesson-header-info { flex: 1; min-width: 0; }
.lesson-title-text {
  font-family: 'Playfair Display', serif; font-size: 1.15rem; font-weight: 700;
  line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lesson-meta-row { display: flex; align-items: center; gap: 0.4rem; margin-top: 2px; }
.lesson-level-text, .lesson-id-text { font-size: 0.72rem; color: var(--muted); }
.fav-btn { background: none; border: none; cursor: pointer; font-size: 1.5rem; color: #F0A020; flex-shrink: 0; padding: 0; }

/* ---- Listen count ---- */
.play-counts {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.65rem 1rem; margin-bottom: 1rem;
}
.play-count-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.play-count-num { font-size: 1.3rem; font-weight: 700; color: var(--jade); margin-left: 0.4rem; }

/* ---- Audio Player ---- */
.audio-section {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem;
}
.player-controls {
  display: flex; align-items: center; gap: 0.75rem;
  justify-content: center; margin-bottom: 0.75rem;
}
.ctrl-btn {
  background: none; border: none; cursor: pointer;
  font-size: 0.85rem; color: var(--muted); padding: 0.4rem;
  display: flex; align-items: center; gap: 2px;
}
.ctrl-btn.play-btn-main {
  background: var(--jade); color: white; border-radius: 50%;
  width: 48px; height: 48px; font-size: 1.2rem; justify-content: center; flex-shrink: 0;
}
.progress-section { display: flex; align-items: center; gap: 0.5rem; }
.time-label { font-size: 0.7rem; color: var(--muted); white-space: nowrap; min-width: 30px; }
.time-label:last-child { text-align: right; }
input[type=range].progress-bar {
  flex: 1; appearance: none; height: 3px;
  background: var(--border); border-radius: 2px; cursor: pointer; outline: none;
}
input[type=range].progress-bar::-webkit-slider-thumb {
  appearance: none; width: 14px; height: 14px; background: var(--jade); border-radius: 50%;
}

/* ---- Notes (PDF) ---- */
.notes-section-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem;
}
.notes-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600;
}
.notes-container { display: flex; flex-direction: column; gap: 0.5rem; }
.notes-iframe {
  width: 100%;
  height: 65vh;
  min-height: 480px;
  border: none;
  border-radius: var(--radius-sm);
  background: #fff;
  display: block;
}
.transcript-link {
  color: #5A8FAA; font-size: 0.82rem; text-decoration: none;
}
.transcript-link:hover { text-decoration: underline; }

/* ---- Stats ---- */
.stats-filters { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.stats-summary { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
.stat-card {
  flex: 1; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.75rem; text-align: center;
}
.stat-big { font-size: 1.8rem; font-weight: 700; color: var(--jade); line-height: 1; }
.stat-desc { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 3px; }
.stats-level-section { margin-bottom: 1.5rem; }
.stats-level-header {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: white; padding: 4px 10px; border-radius: 6px; display: inline-block; margin-bottom: 0.5rem;
}
.stats-table { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.stats-row {
  display: grid; grid-template-columns: 1fr 48px;
  padding: 0.6rem 0.75rem; gap: 0.25rem; align-items: center;
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background var(--transition);
}
.stats-row:last-child { border-bottom: none; }
.stats-row:active { background: var(--sand-dark); }
.stats-row.stats-header {
  background: var(--sand-dark); cursor: default;
  font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600;
}
.stats-lesson-name { font-size: 0.85rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-count { text-align: center; font-size: 0.8rem; color: var(--muted); }
.stats-count b { color: var(--jade); font-weight: 700; }
