/* =============================================
   SpanishPod PWA - Stylesheet
   Aesthetic: Warm editorial · Terracotta & sand
   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 {
  --terra: #C45B35;
  --terra-light: #E07A55;
  --terra-dark: #9B3F22;
  --sand: #F5EDE3;
  --sand-dark: #EAD9C8;
  --ink: #1E1410;
  --muted: #7A6558;
  --surface: #FDFAF7;
  --card: #FFFFFF;
  --border: #E8D9CC;

  --level-newbie: #4A90A4;
  --level-elementary: #5BA85A;
  --level-intermediate: #D4A017;
  --level-upper: #C45B35;
  --level-advanced: #8B3A8B;
  --level-series: #555;

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

@media (prefers-color-scheme: dark) {
  :root {
    --sand: #1A1210;
    --sand-dark: #241915;
    --surface: #110E0C;
    --card: #1E1612;
    --ink: #F5EDE3;
    --muted: #A08878;
    --border: #3A2A22;
    --terra-light: #D96A45;
  }
}

/* ---- 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(--terra); }

/* ---- 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), box-shadow 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(--terra) 0%, var(--terra-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-elementary { background: var(--level-elementary); }
.level-intermediate { background: var(--level-intermediate); }
.level-upper { background: var(--level-upper); }
.level-advanced { background: var(--level-advanced); }
.level-series { background: var(--level-series); }

/* ---- Play count badges ---- */
.badge {
  font-size: 0.65rem; font-weight: 600; padding: 2px 5px;
  border-radius: 4px; display: inline-block;
}
.badge-p { background: rgba(196,91,53,0.12); color: var(--terra); }
.badge-d { background: rgba(75,144,164,0.12); color: var(--level-newbie); }
.badge-r { background: rgba(91,168,90,0.12); color: var(--level-elementary); }

.fav-star { color: #F0A020; font-size: 1rem; }
.done-check { color: var(--level-elementary); font-size: 0.85rem; font-weight: 700; }

/* ---- Hero ---- */
.home-hero {
  background: linear-gradient(135deg, var(--terra) 0%, #A03020 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: 1.2rem; top: 50%; transform: translateY(-50%);
  font-size: 3rem; opacity: 0.18;
}
.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; }

/* ---- Series Grid ---- */
.series-grid { display: flex; flex-direction: column; gap: 0.5rem; }
.series-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);
}
.series-chip:active { background: var(--sand-dark); }
.series-icon { font-size: 1.4rem; }
.series-name { flex: 1; font-weight: 500; font-size: 0.9rem; }
.series-count {
  font-size: 0.75rem; color: var(--muted);
  background: var(--sand-dark); padding: 2px 8px; border-radius: 20px;
}

/* ---- 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-row { display: flex; gap: 0.5rem; }
.filter-select {
  flex: 1; 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.2rem; 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 { font-size: 0.72rem; color: var(--muted); }
.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;
}

/* ---- Play counts display ---- */
.play-counts {
  display: flex; gap: 0.5rem; margin-bottom: 1rem;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.65rem 1rem;
}
.play-count-item {
  display: flex; flex-direction: column; align-items: center; flex: 1;
}
.play-count-label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.play-count-num { font-size: 1.2rem; font-weight: 700; color: var(--terra); }
.play-count-item:nth-child(2) .play-count-num { color: var(--level-newbie); }
.play-count-item:nth-child(3) .play-count-num { color: var(--level-elementary); }

/* ---- Audio Player ---- */
.audio-section {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
  margin-bottom: 1rem;
}
.track-tabs { display: flex; gap: 0.4rem; margin-bottom: 1rem; }
.track-tab {
  flex: 1; background: var(--sand-dark); border: none;
  border-radius: var(--radius-sm); padding: 0.45rem 0;
  font-family: 'DM Sans', sans-serif; font-size: 0.78rem; font-weight: 500;
  color: var(--muted); cursor: pointer; transition: all var(--transition);
}
.track-tab.active { background: var(--terra); color: white; }

.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(--terra); 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(--terra); border-radius: 50%;
}

/* ---- Video section ---- */
.video-section {
  margin-bottom: 1rem; border-radius: var(--radius); overflow: hidden;
  background: #000; aspect-ratio: 4/3;
}
.video-section iframe { width: 100%; height: 100%; border: none; }

/* ---- Transcript ---- */
.transcript-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.75rem;
}
.transcript-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 600;
}
.translate-toggle {
  background: none; border: 1px solid var(--border); border-radius: 20px;
  padding: 3px 10px; font-family: 'DM Sans', sans-serif;
  font-size: 0.72rem; color: var(--muted); cursor: pointer;
}

.transcript-fallback {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.25rem 0;
}
.transcript-iframe {
  width: 100%;
  min-height: 280px;
  border: none;
  border-radius: var(--radius-sm);
  color-scheme: light;
  background: #fff;
}
.transcript-link {
  color: #5A8FAA;
  font-size: 0.82rem;
  text-decoration: none;
}
.transcript-link:hover { text-decoration: underline; }

.dialog-line {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}
.dialog-line:last-child { border-bottom: none; }
.line-es { font-weight: 500; color: var(--ink); font-size: 0.95rem; line-height: 1.4; }
.line-en { font-size: 0.85rem; color: var(--muted); margin-top: 3px; line-height: 1.4; font-style: italic; }

/* ---- Stats View ---- */
.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(--terra); 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 48px 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(--terra); font-weight: 700; }
