/* ═══════════════════════════════════════════════════════════════════
   MagicListen PWA — main.css
   Primary:   #001D6C  (IBM Deep Blue)
   Font:      Noto Sans SC (matches Source Han Sans)
   ═══════════════════════════════════════════════════════════════════ */

/* ── Reset & base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:       #001D6C;
  --blue-mid:   #0043CE;
  --blue-light: #E6F1FF;
  --blue-faint: #F0F4FF;
  --green:      #24A148;
  --grey-100:   #F4F4F4;
  --grey-200:   #E0E0E0;
  --grey-400:   #A8A8A8;
  --grey-600:   #525252;
  --grey-800:   #262626;
  --white:      #FFFFFF;
  --danger:     #DA1E28;
  --warn:       #F1C21B;

  --font:       'Noto Sans SC', 'Source Han Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-sm:  8px;
  --radius-md:  12px;
  --radius-lg:  20px;
  --shadow-sm:  0 1px 4px rgba(0,29,108,.10);
  --shadow-md:  0 4px 16px rgba(0,29,108,.16);
  --nav-h:      64px;
  --header-h:   56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--grey-800);
  background: var(--grey-100);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ─────────────────────────────────────────────────── */
#ml-app {
  position: fixed;
  inset: 0 0 var(--nav-h) 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--white);
}

/* When bottom nav is hidden (upload flow) */
#ml-app:has(+ #ml-bottom-nav[style*="none"]),
.screen-upload #ml-app {
  bottom: 0;
}

/* ── Splash ─────────────────────────────────────────────────────── */
.splash-screen {
  position: fixed;
  inset: 0;
  background: var(--blue);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition: opacity .4s ease;
}
.splash-logo { width: 80px; filter: brightness(0) invert(1); }

/* ── Screens ────────────────────────────────────────────────────── */
.screen {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--white);
}

/* ── Bottom Nav ─────────────────────────────────────────────────── */
#ml-bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--white);
  border-top: 1px solid var(--grey-200);
  display: flex;
  align-items: stretch;
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--grey-400);
  font-size: 11px;
  font-family: var(--font);
  padding: 8px 4px;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn.active { color: var(--blue); }
.nav-btn svg    { stroke: currentColor; }

/* ── Header ─────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--white);
  border-bottom: 1px solid var(--grey-200);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}
.header-logo { height: 28px; width: auto; }
.header-title { display: flex; flex-direction: column; }
.header-grade { font-size: 13px; font-weight: 700; color: var(--blue); }

.upload-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--white);
  border-bottom: 1px solid var(--grey-200);
  flex-shrink: 0;
}
.header-grade-small { font-size: 11px; color: var(--grey-400); }
.upload-lesson-title { font-size: 15px; font-weight: 700; color: var(--blue); }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  padding: 14px 20px;
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary:not(:disabled):active { transform: scale(.98); }

.btn-outline {
  width: 100%;
  padding: 13px 20px;
  background: transparent;
  color: var(--blue);
  border: 1.5px solid var(--blue);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-outline:active { background: var(--blue-faint); }

.btn-ghost {
  width: 100%;
  padding: 12px 20px;
  background: transparent;
  color: var(--grey-600);
  border: none;
  font-size: 14px;
  font-family: var(--font);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: none;
  background: var(--grey-100);
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.btn-wechat {
  width: 100%;
  padding: 14px 20px;
  background: #07C160;
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-wechat:disabled { opacity: .4; cursor: not-allowed; }

/* ── Loading / Spinner ──────────────────────────────────────────── */
.loader-full {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--grey-400);
  font-size: 14px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--grey-200);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── LANDING ─────────────────────────────────────────────────────── */
.screen-landing {
  min-height: 100vh;
  background: var(--white);
}
.landing-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 64px 24px 40px;
  min-height: 100vh;
}
.landing-logo {
  width: 88px;
  margin-bottom: 16px;
}
.landing-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 6px;
}
.landing-tagline {
  font-size: 14px;
  color: var(--grey-400);
  margin-bottom: 8px;
  text-align: center;
}
.landing-spacer { flex: 1; min-height: 32px; }

.agreement-row {
  width: 100%;
  margin-bottom: 16px;
}
.agreement-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--grey-600);
  cursor: pointer;
  line-height: 1.5;
}
.agreement-checkbox {
  margin-top: 2px;
  width: 16px; height: 16px;
  accent-color: var(--blue);
  flex-shrink: 0;
}
.link-plain { color: var(--blue-mid); text-decoration: underline; }
.landing-hint {
  font-size: 13px;
  color: var(--grey-400);
  text-align: center;
  margin-top: 12px;
}

/* ── ONBOARDING ──────────────────────────────────────────────────── */
.screen-onboarding {
  min-height: 100vh;
  background: var(--white);
}
.onboard-inner {
  display: flex;
  flex-direction: column;
  padding: 48px 24px 40px;
  min-height: 100vh;
}
.onboard-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 32px;
}
.logo-img { width: 64px; margin-bottom: 8px; }
.onboard-tagline { font-size: 12px; color: var(--grey-400); }
.onboard-heading {
  font-size: 20px;
  font-weight: 700;
  color: var(--blue);
  text-align: center;
  margin-bottom: 4px;
}
.onboard-sub {
  font-size: 13px;
  color: var(--grey-400);
  text-align: center;
  margin-bottom: 24px;
}

.grade-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 28px;
}
.grade-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  border: 2px solid var(--grey-200);
  border-radius: var(--radius-md);
  background: var(--white);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.grade-card.selected {
  border-color: var(--blue);
  background: var(--blue-faint);
}
.grade-code {
  font-size: 24px;
  font-weight: 700;
  color: var(--blue);
  display: block;
  margin-bottom: 4px;
}
.grade-label {
  font-size: 12px;
  color: var(--grey-400);
}

.onboard-email-section { margin-bottom: 24px; }
.input-label    { font-size: 13px; color: var(--grey-600); display: block; margin-bottom: 4px; }
.input-label-en { font-size: 12px; color: var(--grey-400); margin-bottom: 10px; }
.input-wrap     { position: relative; }
.ml-input {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font);
  color: var(--grey-800);
  background: var(--white);
  outline: none;
  transition: border-color .15s;
}
.ml-input:focus      { border-color: var(--blue); }
.ml-input::placeholder { color: var(--grey-400); }

.btn-start { margin-top: auto; }

.toast-error {
  background: #FFF0F0;
  border: 1px solid #FFD5D5;
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
}

/* ── DASHBOARD ───────────────────────────────────────────────────── */
.progress-section {
  padding: 14px 16px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.progress-bar-wrap {
  flex: 1;
  height: 8px;
  background: var(--grey-200);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 4px;
  transition: width .5s ease;
}
.progress-label {
  font-size: 12px;
  color: var(--grey-400);
  white-space: nowrap;
}

.lesson-list {
  flex: 1;
  padding: 8px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lesson-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px;
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: box-shadow .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}
.lesson-card:active { transform: scale(.99); }

.lesson-locked  { opacity: .55; }
.lesson-done    { border-color: var(--green); }
.lesson-done .lesson-name { color: var(--grey-600); }

.lesson-card-left  { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.lesson-card-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.lesson-icon { font-size: 16px; flex-shrink: 0; }
.done-check  { color: var(--green); font-weight: 700; }

.lesson-info { display: flex; flex-direction: column; min-width: 0; }
.lesson-name { font-size: 14px; font-weight: 600; color: var(--grey-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lesson-free-badge {
  display: inline-block;
  margin-top: 2px;
  padding: 1px 7px;
  background: var(--blue-light);
  color: var(--blue);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  width: fit-content;
}

.lesson-tag {
  font-size: 11px;
  background: var(--blue);
  color: var(--white);
  padding: 3px 8px;
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.chevron { width: 16px; height: 16px; color: var(--grey-400); }

/* ── Pulse animation (studying lesson) ──────────────────────────── */
@keyframes pulse-border {
  0%,100% { box-shadow: 0 0 0 0 rgba(0,29,108,.25); }
  50%      { box-shadow: 0 0 0 6px rgba(0,29,108,.0); }
}
.lesson-pulse {
  animation: pulse-border 2s ease-in-out infinite;
  border-color: var(--blue);
}
.pulse-dot {
  width: 10px; height: 10px;
  background: var(--blue);
  border-radius: 50%;
  display: inline-block;
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%,100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.4); opacity: .6; }
}

/* ── MODALS ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  transition: opacity .28s ease;
}
.modal-overlay.modal-visible { opacity: 1; }
.modal-overlay.modal-visible .modal-sheet { transform: translateY(0); }

.modal-sheet {
  width: 100%;
  background: var(--white);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px 24px calc(24px + var(--safe-bottom));
  position: relative;
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.32,0,.67,0);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close-x {
  position: absolute;
  top: 14px; right: 16px;
  background: var(--grey-100);
  border: none;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: 13px;
  cursor: pointer;
  color: var(--grey-600);
  display: flex; align-items: center; justify-content: center;
}

.modal-icon   { font-size: 40px; text-align: center; margin-bottom: 12px; }
.modal-pigeon { display: block; margin: 0 auto 12px; width: 80px; }
.modal-title  { font-size: 20px; font-weight: 700; color: var(--blue); text-align: center; margin-bottom: 16px; }

.modal-body { font-size: 14px; color: var(--grey-600); line-height: 1.7; margin-bottom: 20px; }
.modal-body p { margin-bottom: 10px; }

.email-display {
  background: var(--blue-faint);
  border: 1px solid var(--blue-light);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-weight: 600;
  color: var(--blue);
  margin: 10px 0;
  word-break: break-all;
}

.modal-steps {
  padding-left: 20px;
  margin: 10px 0;
}
.modal-steps li { margin-bottom: 6px; font-size: 14px; }
.modal-spam-note {
  font-size: 13px;
  background: #FFFBF0;
  border-left: 3px solid var(--warn);
  padding: 8px 12px;
  border-radius: 0 6px 6px 0;
}

.modal-actions { display: flex; flex-direction: column; gap: 10px; }
.modal-note    { font-size: 12px; color: var(--grey-400); text-align: center; margin-top: 10px; }

.wechat-id-display {
  background: var(--blue-faint);
  border: 1px solid var(--blue-light);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 18px;
  font-weight: 700;
  color: var(--blue);
  text-align: center;
  margin: 14px 0;
  letter-spacing: .02em;
}

/* ── SOURCE SELECTION ────────────────────────────────────────────── */
.source-selection {
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
  gap: 14px;
}
.source-progress {
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  color: var(--blue);
}
.source-progress-num  { font-size: 36px; }
.source-progress-denom { font-size: 16px; color: var(--grey-400); }
.source-hint { font-size: 14px; color: var(--grey-400); text-align: center; margin-top: -8px; }

.source-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  background: var(--white);
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius-md);
  font-size: 16px;
  font-family: var(--font);
  font-weight: 600;
  color: var(--grey-800);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
  text-align: left;
}
.source-btn:active { background: var(--blue-faint); border-color: var(--blue); }
.source-btn-icon { font-size: 22px; flex-shrink: 0; }
.btn-view-grid { margin-top: 4px; }

/* ── LOADING STATE ───────────────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-h));
  gap: 20px;
}
.loading-pigeon { width: 80px; animation: float 3s ease-in-out infinite; }
.loading-text   { font-size: 16px; color: var(--grey-400); font-weight: 500; }
@keyframes float {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

/* ── 15-SLOT UPLOAD GRID ─────────────────────────────────────────── */
.grid-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
}
.grid-progress { font-size: 15px; font-weight: 700; color: var(--blue); }
.grid-uploading-label { font-size: 13px; color: var(--grey-400); animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

.upload-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 0 4px;
}

.grid-slot {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  background: var(--grey-100);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.grid-slot-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--grey-200);
  transition: border-color .15s, background .15s;
}
.grid-slot-empty:active { border-color: var(--blue); background: var(--blue-faint); }
.slot-plus { font-size: 28px; color: var(--grey-400); line-height: 1; }

.slot-thumb {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.slot-thumb-placeholder {
  width: 100%; height: 100%;
  background: linear-gradient(135deg, var(--grey-100), var(--grey-200));
}

.slot-done-badge {
  position: absolute;
  top: 4px; right: 4px;
  width: 20px; height: 20px;
  background: var(--green);
  color: var(--white);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.slot-uploading-badge {
  position: absolute;
  top: 4px; right: 4px;
  width: 20px; height: 20px;
  background: var(--blue);
  color: var(--white);
  border-radius: 50%;
  font-size: 10px;
  display: flex; align-items: center; justify-content: center;
  animation: spin .7s linear infinite;
}

.grid-actions {
  padding: 16px 16px calc(16px + var(--safe-bottom));
}

/* ── SUCCESS SCREEN ──────────────────────────────────────────────── */
.success-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 24px;
  min-height: calc(100vh - var(--header-h));
  text-align: center;
}
.success-pigeon {
  width: 100px;
  margin-bottom: 20px;
  animation: float 3s ease-in-out infinite;
}
.success-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 8px;
}
.success-sub {
  font-size: 14px;
  color: var(--grey-400);
  margin-bottom: 28px;
}

.streak-row {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
}
.streak-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.streak-dot {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--grey-200);
  transition: background .2s;
}
.streak-active .streak-dot  { background: var(--blue); }
.streak-today .streak-dot   { background: var(--blue); box-shadow: 0 0 0 3px rgba(0,29,108,.2); }
.streak-label { font-size: 11px; color: var(--grey-400); font-weight: 600; }
.streak-active .streak-label { color: var(--blue); }

.streak-count {
  font-size: 14px;
  color: var(--grey-400);
  margin-bottom: 28px;
}
.btn-back-roadmap { margin-top: auto; }

/* ── PROFILE ─────────────────────────────────────────────────────── */
.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px 24px;
  gap: 6px;
}
.profile-avatar {
  width: 72px; height: 72px;
  background: var(--blue);
  color: var(--white);
  border-radius: 50%;
  font-size: 28px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.profile-name  { font-size: 18px; font-weight: 700; color: var(--grey-800); }
.profile-grade { font-size: 13px; color: var(--blue); font-weight: 600; }
.profile-email { font-size: 13px; color: var(--grey-400); }
.btn-logout    { margin: 24px 24px 0; width: calc(100% - 48px); }

/* ── EMPTY STATE ─────────────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px 24px;
  text-align: center;
  color: var(--grey-400);
  font-size: 15px;
  line-height: 1.7;
}
.empty-pigeon { width: 80px; animation: float 3s ease-in-out infinite; }

/* ── TOAST ───────────────────────────────────────────────────────── */
.ml-toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--grey-800);
  color: var(--white);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  white-space: nowrap;
  max-width: calc(100vw - 40px);
  text-align: center;
  z-index: 300;
}
.ml-toast.toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── ERROR ───────────────────────────────────────────────────────── */
.error-msg {
  padding: 40px 24px;
  text-align: center;
  color: var(--danger);
  font-size: 15px;
}

/* ── Utilities ───────────────────────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}
