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

:root {
  --bg: #f7f3ea;
  --surface: #ffffff;
  --text: #1c1a17;
  --text-muted: #6b6459;
  --text-light: #9c9488;
  --accent: #b8342a;
  --accent-dark: #8f281f;
  --gold: #c9a24b;
  --border: #ddd4c4;
  --border-light: #eae3d4;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(28, 26, 23, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

html, body { max-width: 100%; overflow-x: hidden; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

.hanzi, .hz { font-family: 'Noto Sans SC', 'Inter', sans-serif; }

a { color: inherit; text-decoration: none; }

.wrap {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------- nav ---------- */
.topnav {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topnav .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding-top: 12px;
  padding-bottom: 12px;
  min-height: 64px;
}
.brand {
  font-weight: 700;
  font-size: 1.15em;
  display: flex;
  align-items: center;
  gap: 0.4em;
  flex: none;
}
.brand .hz { color: var(--accent); font-size: 1.2em; }
.navlinks { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.navlinks a {
  font-size: 0.92em;
  font-weight: 500;
  color: var(--text-muted);
  padding: 6px 2px;
  border-bottom: 2px solid transparent;
}
.navlinks a.active, .navlinks a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.home-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.82em;
  font-weight: 600;
  color: var(--text-muted) !important;
  border-bottom: 1px solid var(--border) !important;
  white-space: nowrap;
}
.home-pill:hover { background: var(--accent); border-color: var(--accent) !important; color: #fff !important; }

/* ---------- hero ---------- */
.hero { padding: 64px 0 40px; text-align: center; }
.hero .tag {
  display: inline-block;
  font-size: 0.78em;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(184, 52, 42, 0.08);
  border: 1px solid rgba(184, 52, 42, 0.25);
  border-radius: 999px;
  padding: 5px 14px;
  margin-bottom: 20px;
}
.hero h1 {
  font-size: clamp(2em, 5vw, 3em);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 14px;
}
.hero h1 .hz { color: var(--accent); }
.hero p.sub {
  font-size: 1.1em;
  color: var(--text-muted);
  max-width: 560px;
  margin: 0 auto 28px;
}
.btn {
  display: inline-block;
  font-weight: 600;
  font-size: 0.95em;
  padding: 12px 26px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------- concept note ---------- */
.note-box {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 0.92em;
  color: var(--text-muted);
  margin: 36px 0;
}

/* ---------- area cards ---------- */
.block { padding: 36px 0; }
.block h2 { font-size: 1.5em; margin-bottom: 6px; }
.block .lead { color: var(--text-muted); margin-bottom: 24px; }

.area-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.area-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.area-card .banner {
  font-family: 'Noto Sans SC', sans-serif;
  font-size: 2.2em;
  color: var(--accent);
  line-height: 1;
}
.area-card h3 { font-size: 1.15em; }
.area-card .range { font-size: 0.88em; color: var(--text-muted); }
.area-card .flavor { font-size: 0.82em; color: var(--gold); font-style: italic; }
.area-actions { display: flex; gap: 8px; margin-top: 10px; }
.area-actions .btn { padding: 8px 14px; font-size: 0.85em; }

/* ---------- flashcards ---------- */
.deck-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}
.deck-bar .progress-txt { font-size: 0.9em; color: var(--text-muted); }
.progress-track {
  height: 6px;
  background: var(--border-light);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
  width: 220px;
}
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.25s; }

.speak-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
  margin-left: 6px;
  flex: none;
  transition: background 0.15s, transform 0.1s;
}
.speak-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.speak-btn:active { transform: scale(0.92); }
.speak-btn.playing { background: var(--accent); color: #fff; border-color: var(--accent); animation: speak-pulse 0.8s ease-in-out infinite; }
.speak-btn.failed { background: var(--text-light); color: #fff; border-color: var(--text-light); animation: none; }
@keyframes speak-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(184, 52, 42, 0.35); }
  50% { box-shadow: 0 0 0 6px rgba(184, 52, 42, 0); }
}

.audio-warning {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  background: rgba(201, 162, 75, 0.14);
  border: 1px solid rgba(201, 162, 75, 0.4);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.85em;
  color: var(--text);
  text-align: left;
  margin-bottom: 20px;
}
.audio-warning button {
  background: none;
  border: none;
  font-size: 1.1em;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  flex: none;
}

.flashcard-stage {
  perspective: 1200px;
  max-width: 480px;
  margin: 0 auto 24px;
}
.flashcard {
  position: relative;
  min-height: 260px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(.4,.2,.2,1);
}
.flashcard.flipped { transform: rotateY(180deg); }
.fc-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px;
  gap: 10px;
}
.fc-back { transform: rotateY(180deg); }
.fc-emoji { font-size: 2.6em; line-height: 1; margin-bottom: 2px; }
.fc-picture { margin-bottom: 6px; }
.fc-img {
  width: 108px;
  height: 108px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border-light);
  display: block;
  margin: 0 auto;
}
.fc-hanzi { font-family: 'Noto Sans SC', sans-serif; font-size: 2.6em; font-weight: 700; }
.fc-pinyin { color: var(--accent); font-size: 1.1em; }
.fc-meaning { font-size: 1.15em; font-weight: 600; }
.fc-sentence { margin-top: 14px; font-size: 0.95em; }
.fc-sentence .hz { font-size: 1.15em; display: block; margin-bottom: 3px; }
.fc-sentence .py { color: var(--accent); display: block; font-size: 0.9em; }
.fc-sentence .en { color: var(--text-muted); display: block; margin-top: 3px; }
.fc-hint { position: absolute; bottom: 10px; right: 14px; font-size: 0.75em; color: var(--text-light); }

.grade-row { display: flex; justify-content: center; gap: 10px; }
.grade-row button {
  flex: 1;
  max-width: 160px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
}
.grade-row button.again { color: var(--accent); border-color: rgba(184,52,42,0.3); }
.grade-row button.good { color: #2e7d32; border-color: rgba(46,125,50,0.3); }
.grade-row button:hover { background: var(--border-light); }

.deck-done {
  text-align: center;
  padding: 40px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.deck-done .hz { font-size: 2.4em; color: var(--accent); }

/* ---------- quiz mode ---------- */
.quiz-prompt {
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 20px;
  margin-bottom: 20px;
}
.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.quiz-option {
  font-family: inherit;
  font-size: 1em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.quiz-option:hover:not(.disabled) { border-color: var(--accent); }
.quiz-option:active:not(.disabled) { transform: scale(0.97); }
.quiz-option .hz { display: block; font-family: 'Noto Sans SC', sans-serif; font-size: 1.3em; }
.quiz-option .py { display: block; color: var(--accent); font-size: 0.85em; margin-top: 2px; }
.quiz-option.disabled { cursor: default; }
.quiz-option.correct { border-color: #2e7d32; background: rgba(46,125,50,0.1); }
.quiz-option.correct .py { color: #2e7d32; }
.quiz-option.incorrect { border-color: var(--accent); background: rgba(184,52,42,0.08); }

@media (max-width: 600px) {
  .quiz-options { grid-template-columns: 1fr; }
}

/* ---------- dialogue player ---------- */
.dlg-head { margin-bottom: 18px; }
.dlg-head .register { font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.06em; color: var(--gold); font-weight: 600; }
.dlg-controls { display: flex; gap: 10px; margin-bottom: 22px; flex-wrap: wrap; align-items: center; }
.toggle {
  font-size: 0.85em;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  background: var(--surface);
}
.toggle.on { background: var(--accent); color: #fff; border-color: var(--accent); }

.scene-line {
  font-style: italic;
  color: var(--text-muted);
  padding: 10px 0;
  font-size: 0.95em;
}
.exchange { margin-bottom: 8px; }
.dlg-line {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 10px;
}
.dlg-line.role-you { border-left: 3px solid var(--accent); }
.dlg-line.role-other { border-left: 3px solid var(--gold); }
.dlg-line .role-tag { font-size: 0.75em; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.dlg-line .hz { font-size: 1.3em; display: block; }
.dlg-line .py { color: var(--accent); display: block; margin-top: 2px; }
.dlg-line .en { color: var(--text-muted); margin-top: 4px; display: block; }
.py-hidden .py { display: none; }
.en-hidden .en { display: none; }

.callout {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.86em;
}
.callout.vocab { background: rgba(201,162,75,0.12); border: 1px solid rgba(201,162,75,0.35); }
.callout.grammar { background: rgba(184,52,42,0.06); border: 1px solid rgba(184,52,42,0.2); }
.callout .callout-title { font-weight: 700; margin-bottom: 3px; }
.callout.vocab .hz { font-size: 1em; }

.reveal-btn { display: block; margin: 24px auto; }
.hidden-next { opacity: 0.35; filter: blur(2px); pointer-events: none; }

.dlg-done {
  text-align: center;
  padding: 32px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 10px;
}

/* ---------- picker (used on study/practice landing) ---------- */
.picker-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 30px; }
.picker-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  text-align: left;
}
.picker-card:hover { border-color: var(--accent); }
.picker-card .hz { font-size: 1.8em; color: var(--accent); }
.picker-card .done-badge { float: right; font-size: 0.75em; color: #2e7d32; font-weight: 600; }

/* ---------- grammar reference ---------- */
.grammar-search {
  width: 100%;
  font-family: inherit;
  font-size: 1em;
  padding: 13px 20px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.grammar-search::placeholder { color: var(--text-light); }
.grammar-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(184, 52, 42, 0.12);
}
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.chip {
  font-family: inherit;
  font-size: 0.82em;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.grammar-count {
  font-size: 0.8em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-light);
  margin-bottom: 22px;
}
.grammar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.grammar-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--border);
  border-left-color: var(--accent);
}
.grammar-card--core {
  border-left-color: var(--accent);
  background: linear-gradient(180deg, rgba(184,52,42,0.03), transparent 60%);
}
.grammar-tag {
  display: inline-block;
  font-size: 0.7em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gold);
  background: rgba(201,162,75,0.12);
  border-radius: 999px;
  padding: 3px 11px;
  margin-bottom: 10px;
}
.grammar-tag--core { color: #fff; background: var(--accent); }
.grammar-card h3 { font-size: 1.15em; margin-bottom: 8px; line-height: 1.35; }
.grammar-card p { color: var(--text-muted); font-size: 0.93em; margin-bottom: 14px; line-height: 1.6; }
.grammar-example {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.9em;
}
.grammar-example-label {
  font-size: 0.68em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-light);
  margin-bottom: 6px;
}
.grammar-example .hz { font-size: 1.15em; display: block; }
.grammar-example .py { color: var(--accent); display: block; margin-top: 2px; }
.grammar-example .en { color: var(--text-muted); display: block; margin-top: 4px; }

footer {
  border-top: 1px solid var(--border);
  padding: 30px 0 60px;
  margin-top: 40px;
}
footer .legal { font-size: 0.82em; color: var(--text-light); }

@media (max-width: 600px) {
  .hero { padding: 44px 0 28px; }
  .topnav .wrap { justify-content: center; text-align: center; }
  .navlinks { width: 100%; justify-content: center; gap: 8px 14px; }
  .navlinks a { font-size: 0.85em; }
  .progress-track { width: 140px; }
  .grade-row button { max-width: none; }
  .speak-btn { width: 38px; height: 38px; font-size: 16px; }
  .fc-face { padding: 22px 16px; }
}
