/* Mandarin Notes — follows the desktop app's 纸墨 (paper) theme tokens. */
@font-face {
  font-family: "Instrument Sans";
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/instrument-sans-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Instrument Sans";
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/instrument-sans-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Instrument Sans";
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/instrument-sans-latin-600-normal.woff2") format("woff2");
}

:root {
  color-scheme: light;
  --ground: #F4F2EC;
  --surface: #FFFFFF;
  --surface-2: #FAF9F5;
  --subtle: #F1EEE7;
  --border: #E6E3DB;
  --divider: #EFECE5;
  --line-strong: #D6D2C7;
  --faint: #8B8E94;
  --muted: #6E7178;
  --ink-2: #4A4E55;
  --ink: #17191C;
  --on-ink: #F4F2EC;
  --primary: #0E5A50;
  --primary-hover: #0B4A42;
  --primary-soft: #E3EFEC;
  --pill-border: #9CC4BC;
  --accent: #C23B22;
  --accent-soft: #FBEAE5;
  --accent-text: #A1311B;
  --speaker-b: #F6EEDF;
  --speaker-b-ink: #7A5418;
  --focus-ring: rgba(14, 90, 80, 0.18);
  --shadow: 0 1px 2px rgba(23, 25, 28, 0.04), 0 4px 16px rgba(23, 25, 28, 0.05);
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --font: "Instrument Sans", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-hanzi: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ground: #151716;
    --surface: #1D201F;
    --surface-2: #222524;
    --subtle: #262A28;
    --border: #2E3331;
    --divider: #2A2E2C;
    --line-strong: #3A403D;
    --faint: #7E8582;
    --muted: #9AA19E;
    --ink-2: #C5CBC8;
    --ink: #EEF1EF;
    --on-ink: #151716;
    --primary: #6FC3B2;
    --primary-hover: #8AD3C4;
    --primary-soft: #1E3833;
    --pill-border: #2F5C53;
    --accent: #F08A6E;
    --accent-soft: #3A2520;
    --accent-text: #F4A48D;
    --speaker-b: #33291B;
    --speaker-b-ink: #E8C489;
    --focus-ring: rgba(111, 195, 178, 0.25);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; border-radius: 6px; }
.hidden { display: none !important; }
.hanzi { font-family: var(--font-hanzi); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--ground) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--divider);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--primary);
  color: var(--on-ink);
  font-family: var(--font-hanzi);
  font-size: 18px;
  line-height: 1;
}
.brand-name { font-size: 15px; letter-spacing: 0.01em; }
.topnav { display: flex; gap: 4px; }
.topnav a {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
}
.topnav a:hover { background: var(--subtle); text-decoration: none; }
.topnav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }

/* ---------- Layout ---------- */
.page {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 96px;
  outline: none;
}
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 48px 0; justify-content: center; }
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 13px; font-weight: 500; letter-spacing: 0.02em; }
.page-title { margin: 0; font-size: 28px; line-height: 1.2; font-weight: 600; letter-spacing: -0.01em; }
.page-sub { margin: 8px 0 0; color: var(--muted); }
.page-head { margin-bottom: 24px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 14px; color: var(--muted); font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

.section { margin-top: 32px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-title { margin: 0; font-size: 18px; font-weight: 600; }
.section-title .zh { margin-left: 6px; color: var(--muted); font-weight: 500; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Buttons & chips ---------- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.button:hover { background: var(--subtle); text-decoration: none; }
.button:active { transform: translateY(1px); }
.button svg { width: 14px; height: 14px; flex: none; }
.button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-ink); }
.button.primary:hover { background: var(--primary-hover); }
.button.soft { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.button[disabled] { opacity: 0.5; cursor: default; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--subtle);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.chip.green { background: var(--primary-soft); color: var(--primary); }

.icon-button {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  cursor: pointer;
}
.icon-button:hover { border-color: var(--pill-border); }
.icon-button.playing { background: var(--primary); color: var(--on-ink); }
.icon-button.loading { position: relative; color: transparent; }
.icon-button.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  border: 2px solid var(--pill-border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.icon-button svg { width: 16px; height: 16px; }
.icon-button.small { width: 28px; height: 28px; }
.icon-button.small svg { width: 14px; height: 14px; }

/* ---------- Home: lesson timeline ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 20px; }
.stat { padding: 14px 16px; }
.stat-value { font-size: 24px; font-weight: 600; line-height: 1.1; }
.stat-label { margin-top: 2px; color: var(--muted); font-size: 13px; }

.lesson-list { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }
.lesson-card {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  color: var(--ink);
  transition: border-color 0.15s, transform 0.15s;
}
.lesson-card:hover { border-color: var(--pill-border); text-decoration: none; transform: translateY(-1px); }
.lesson-date {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0;
  border-radius: var(--r-md);
  background: var(--primary-soft);
  color: var(--primary);
  line-height: 1.1;
}
.lesson-date .month { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.lesson-date .day { font-size: 20px; font-weight: 600; }
.lesson-title { font-weight: 600; }
.lesson-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.lesson-card .chevron { color: var(--faint); }
.lesson-card.latest { border-color: var(--pill-border); }
.new-badge { margin-left: 6px; vertical-align: 2px; }

.empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.empty h2 { margin: 0 0 6px; color: var(--ink); font-size: 18px; }

/* ---------- Lesson page ---------- */
.toolbar {
  position: sticky;
  top: 51px;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 -16px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--ground) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--divider);
}
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.tab:hover { background: var(--subtle); }
.tab[aria-selected="true"] { background: var(--ink); color: var(--on-ink); }
.toggles { display: flex; gap: 6px; }
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.toggle[aria-pressed="true"] { border-color: var(--pill-border); background: var(--primary-soft); color: var(--primary); }
.toggle .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.4; }
.toggle[aria-pressed="true"] .dot { opacity: 1; }

/* Hidden pinyin / English stay tappable so a student can check one line at a time. */
.pinyin, .english { transition: filter 0.15s, opacity 0.15s; }
.hide-pinyin .pinyin:not(.revealed),
.hide-english .english:not(.revealed),
.role-hidden:not(.revealed) {
  filter: blur(5px);
  opacity: 0.55;
  cursor: pointer;
  user-select: none;
}

.word-strip { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.word-pill {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-hanzi);
  font-size: 16px;
  cursor: pointer;
}
.word-pill:hover { border-color: var(--pill-border); background: var(--primary-soft); }

.entry { padding: 18px; margin-bottom: 14px; scroll-margin-top: 120px; }
.entry-words { display: flex; flex-direction: column; gap: 10px; }
.word-row { display: flex; align-items: center; gap: 12px; }
.word-main { min-width: 0; flex: 1; }
.word-hanzi { font-family: var(--font-hanzi); font-size: 32px; line-height: 1.2; font-weight: 600; }
.word-detail { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-top: 2px; }
.word-detail .pinyin { color: var(--primary); font-weight: 500; }
.word-detail .pos { color: var(--faint); font-size: 13px; font-style: italic; }
.word-detail .english { color: var(--ink-2); }
.entry.other .entry-label { font-weight: 600; }

.block-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.block-label::after { content: ""; flex: 1; height: 1px; background: var(--divider); }

.sentence-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.line {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  padding: 8px 10px;
  margin: 0 -10px;
  border-radius: var(--r-md);
}
.line:hover { background: var(--surface-2); }
.line-text { min-width: 0; }
.line .zh { font-size: 19px; line-height: 1.5; }
.line .pinyin { color: var(--primary); font-size: 14px; }
.line .english { color: var(--muted); font-size: 14px; }

.dialogue { margin-top: 6px; padding: 14px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--divider); }
.dialogue + .dialogue { margin-top: 12px; }
.dialogue-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.dialogue-title { font-weight: 600; }
.dialogue-title .en { display: block; color: var(--muted); font-size: 13px; font-weight: 400; }
.dialogue-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.dialogue-actions .button { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.bubble { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: start; padding: 8px 0; }
.speaker {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
}
.bubble.speaker-b .speaker { background: var(--speaker-b); color: var(--speaker-b-ink); }
.bubble .zh { font-size: 18px; line-height: 1.5; }
.bubble .pinyin { color: var(--primary); font-size: 14px; }
.bubble .english { color: var(--muted); font-size: 14px; }
.bubble.active { background: var(--primary-soft); margin: 0 -8px; padding: 8px; border-radius: var(--r-md); }

/* Rich text (grammar, homework) */
.rich { padding: 18px; margin-bottom: 14px; }
.rich h3 { margin: 0 0 2px; font-size: 18px; }
.rich .en-title { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.prose { color: var(--ink-2); overflow-wrap: anywhere; }
.prose p { margin: 0 0 10px; }
.prose ul, .prose ol { margin: 0 0 10px; padding-left: 22px; }
.prose li { margin: 4px 0; }
.prose strong { color: var(--ink); }
.prose img { display: block; max-width: 100%; height: auto; margin: 10px 0; border-radius: var(--r-md); border: 1px solid var(--border); }
.prose table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 14px; display: block; overflow-x: auto; }
.prose th, .prose td { padding: 6px 10px; border: 1px solid var(--border); text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); }
.prose .speakable { cursor: pointer; border-radius: 4px; }
.prose .speakable:hover { background: var(--primary-soft); }
.prose blockquote { margin: 0 0 10px; padding: 6px 12px; border-left: 3px solid var(--pill-border); color: var(--muted); }

/* ---------- Practice ---------- */
.practice-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.practice-option { display: flex; flex-direction: column; gap: 4px; padding: 16px; text-align: left; cursor: pointer; color: var(--ink); }
.practice-option:hover { border-color: var(--pill-border); }
.practice-option strong { font-size: 16px; }
.practice-option span { color: var(--muted); font-size: 14px; }

.flashcard-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.progress { width: 100%; height: 6px; border-radius: 999px; background: var(--subtle); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); transition: width 0.25s; }
.flashcard {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 260px;
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  user-select: none;
}
.flashcard .word-hanzi { font-size: 56px; }
.flashcard .hint { color: var(--faint); font-size: 13px; }
.flashcard .back { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.flashcard .back .pinyin { color: var(--primary); font-size: 20px; font-weight: 500; }
.flashcard .back .english { color: var(--ink-2); font-size: 17px; }
.flashcard .speak-corner { position: absolute; top: 12px; right: 12px; }
.counter { color: var(--muted); font-size: 14px; }

.quiz-question { padding: 22px 18px; text-align: center; }
.quiz-prompt { font-size: 15px; color: var(--muted); }
.quiz-target { margin-top: 6px; font-size: 22px; font-weight: 600; }
.quiz-target.hanzi { font-size: 44px; }
.quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.quiz-option {
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  cursor: pointer;
}
.quiz-option.hanzi { font-family: var(--font-hanzi); font-size: 24px; }
.quiz-option:hover:not([disabled]) { border-color: var(--pill-border); background: var(--primary-soft); }
.quiz-option.correct { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.quiz-option.wrong { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.quiz-option[disabled] { cursor: default; }
.result { padding: 28px 18px; text-align: center; }
.result .score { font-size: 48px; font-weight: 600; color: var(--primary); }

/* ---------- Word bank ---------- */
.search {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.search:focus { outline: none; border-color: var(--pill-border); box-shadow: 0 0 0 3px var(--focus-ring); }
.word-table { margin-top: 14px; overflow: hidden; }
.word-item { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--divider); }
.word-item:first-child { border-top: 0; }
.word-item .hanzi { font-size: 22px; font-weight: 600; }
.word-item .pinyin { color: var(--primary); font-size: 14px; }
.word-item .english { color: var(--muted); font-size: 14px; }
.word-item .from { color: var(--faint); font-size: 12px; white-space: nowrap; }
.known-dot { display: inline-block; width: 8px; height: 8px; margin-left: 6px; border-radius: 50%; background: var(--primary); vertical-align: middle; }

/* ---------- Landing ---------- */
.hero { padding: 48px 0 24px; text-align: center; }
.hero .hanzi-big { font-family: var(--font-hanzi); font-size: 64px; line-height: 1; color: var(--primary); }
.hero h1 { margin: 18px 0 8px; font-size: 30px; }
.hero p { max-width: 460px; margin: 0 auto; color: var(--muted); }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-top: 32px; }
.feature { padding: 16px; }
.feature strong { display: block; margin-bottom: 4px; }
.feature span { color: var(--muted); font-size: 14px; }

.footer-note { margin-top: 40px; text-align: center; color: var(--faint); font-size: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 50;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--on-ink);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 560px) {
  .page { padding-top: 18px; }
  .page-title { font-size: 24px; }
  .stats { gap: 8px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 20px; }
  .toggles .toggle .label-long { display: none; }
  .word-hanzi { font-size: 28px; }
  .quiz-options { grid-template-columns: 1fr; }
  .lesson-card { grid-template-columns: 48px 1fr auto; gap: 12px; padding: 12px; }
  .word-item .from { display: none; }
  .brand-name { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
