:root {
  color-scheme: light;
  --ink: #141414;
  --muted: #6b6f78;
  --paper: #f8f5ef;
  --card: #ffffff;
  --line: #dfd8cc;
  --accent: #ff6b57;
  --mint: #dcefe6;
  --sky: #dce8f7;
  --gold: #ffe3a6;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: #eceff3;
  color: var(--ink);
}

body:has(.onboarding:not(.hidden)) { overflow: hidden; }

button, input, select { font: inherit; }

button {
  min-height: 42px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 0 16px;
  cursor: pointer;
}

button:disabled { opacity: .5; cursor: default; }

.secondary-action, .text-button {
  border-color: var(--line);
  background: #fffdf8;
  color: var(--ink);
}

.text-button { border-color: transparent; background: transparent; }

.onboarding {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 20, 20, .38);
  backdrop-filter: blur(16px);
}

.hidden { display: none !important; }

.onboarding-card {
  display: grid;
  width: min(100%, 430px);
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 22px;
}

.onboarding-card img { width: min(100%, 300px); }
.onboarding-card h1 { margin: 0; font-size: 32px; line-height: 1.05; }
.onboarding-card p { margin: 0; color: var(--muted); line-height: 1.55; }

label { display: grid; gap: 8px; font-weight: 750; }

select {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 12px;
}

.app-shell {
  display: grid;
  width: min(100%, 440px);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 245, 239, .96);
  padding: 10px 14px;
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
}

.brand img { width: 48px; height: 48px; border-radius: 8px; }
.brand strong { display: block; font-size: 20px; line-height: 1; white-space: nowrap; }
.brand span { color: var(--muted); font-size: 12px; font-weight: 750; }

nav { display: none; gap: 8px; }

.nav-item {
  justify-content: flex-start;
  border-color: transparent;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.nav-item.active { border-color: var(--line); background: #fff; }

.side-card { display: none; }

main { padding: 18px 14px 92px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.topbar h1, .lesson-hero h2, .section-head h2, .membership h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 { font-size: 28px; line-height: 1.05; }

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.icon-button {
  width: 44px;
  min-width: 44px;
  padding: 0;
  font-size: 20px;
}

.view { display: none; }
.view.active { display: block; }

.lesson-hero, .recall-panel, .swap-panel, .checkin-panel, .progress-panel, .membership,
.practice-card, .science-panel article, .library-item, .review-item, .empty-state, .legal-links {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.lesson-hero {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.lesson-meta { display: flex; flex-wrap: wrap; gap: 8px; }
.lesson-meta span, .tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--mint);
  padding: 6px 10px;
  color: #26352d;
  font-size: 12px;
  font-weight: 850;
}

#sentenceZh {
  font-size: clamp(34px, 9vw, 54px);
  line-height: 1.12;
}

#sentencePinyin {
  margin: 0;
  color: #394459;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.4;
}

#sentenceEn, .practice-card p, .membership p, .feedback, .status-line, #progressSummary {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.hero-actions, .checkin-panel, .section-head, .compact, .member-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.practice-grid, .stats-grid, .pricing-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 10px;
}

.practice-card, .recall-panel, .swap-panel, .checkin-panel, .progress-panel, .membership {
  margin-top: 10px;
  padding: 16px;
}

.practice-card h3, .recall-panel h2, .swap-panel h2, .checkin-panel h2 {
  margin: 0 0 8px;
  font-size: 20px;
  line-height: 1.2;
}

.quiz-options, .swap-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.quiz-options button, .swap-list button {
  min-height: 52px;
  background: #fffdf8;
  color: var(--ink);
  text-align: left;
}

.quiz-options button.correct { border-color: #2e8f5a; background: var(--mint); }
.quiz-options button.wrong { border-color: var(--accent); background: #ffe2dc; }

.checkin-panel button { flex: 0 0 auto; }
.status-line { margin: 10px 2px 0; }

.review-list, .library-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.review-item, .library-item {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.review-item strong, .library-item strong {
  font-size: 22px;
  line-height: 1.25;
}

.library-item p, .review-item p { margin: 0; color: var(--muted); line-height: 1.45; }

.stats-grid { margin: 0 0 10px; }
.stats-grid div, .pricing-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

.stats-grid span, .pricing-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.stats-grid strong, .pricing-grid strong { display: block; margin-top: 5px; font-size: 30px; }

.science-panel {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.science-panel article { display: grid; gap: 5px; padding: 14px; }
.science-panel span { color: var(--muted); line-height: 1.45; }

canvas {
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: #fffdf8;
}

.pricing-grid article {
  display: grid;
  gap: 8px;
}

.pricing-grid .featured { background: var(--gold); }

.member-actions {
  justify-content: flex-start;
  margin-top: 12px;
}

.legal-links {
  display: flex;
  justify-content: space-around;
  margin-top: 10px;
  padding: 14px;
}

.legal-links a { color: var(--ink); font-weight: 800; }

.bottom-tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--line);
  background: rgba(248, 245, 239, .97);
  padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  backdrop-filter: blur(16px);
}

.bottom-tab {
  min-height: 46px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 3px;
  font-size: 12px;
  font-weight: 850;
}

.bottom-tab.active {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

@media (min-width: 860px) {
  .app-shell {
    grid-template-columns: 280px minmax(0, 1fr);
    width: min(1180px, 100%);
  }

  .sidebar {
    position: sticky;
    align-self: start;
    height: 100dvh;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    padding: 22px;
  }

  nav { display: grid; margin-top: 22px; }
  .side-card {
    display: grid;
    gap: 5px;
    margin-top: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 16px;
  }

  .side-card span, .side-card small { color: var(--muted); }
  .side-card strong { font-size: 30px; }

  main { padding: 28px 30px 40px; }
  .bottom-tabs { display: none; }
  .practice-grid, .stats-grid, .pricing-grid { grid-template-columns: repeat(3, 1fr); }
  .practice-grid { grid-template-columns: 1fr 1fr; }
  .library-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
