:root {
  --paper: #f7f3eb;
  --paper-deep: #ede6d8;
  --ink: #1a2332;
  --ink-soft: #3d4f66;
  --muted: #6b7d92;
  --accent: #c45c3e;
  --accent-soft: rgba(196, 92, 62, 0.12);
  --teal: #2a6f7a;
  --teal-soft: rgba(42, 111, 122, 0.1);
  --gold: #b8860b;
  --card: rgba(255, 252, 247, 0.92);
  --border: rgba(26, 35, 50, 0.1);
  --radius: 16px;
  --display: 'Fraunces', Georgia, serif;
  --body: 'DM Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', monospace;
  --shadow: 0 12px 40px rgba(26, 35, 50, 0.08);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--body);
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.6;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 60% 45% at 0% 0%, rgba(42, 111, 122, 0.08), transparent 55%),
    radial-gradient(ellipse 50% 40% at 100% 10%, rgba(196, 92, 62, 0.06), transparent 50%),
    linear-gradient(180deg, var(--paper) 0%, var(--paper-deep) 100%);
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
}

#app {
  position: relative;
  z-index: 1;
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -0.02em; }

.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 36px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--teal), var(--accent));
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  box-shadow: 0 4px 16px rgba(42, 111, 122, 0.25);
}

.logo h1 { font-size: 1.35rem; }
.logo p { font-size: 0.75rem; color: var(--muted); letter-spacing: 0.06em; }

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.user-badge strong { color: var(--teal); font-family: var(--mono); font-size: 0.8rem; }

.nav-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-link {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:hover { border-color: var(--teal); color: var(--teal); }

.btn-primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover { background: #235a63; color: #fff; }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-accent:hover { background: #a84d32; color: #fff; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.card + .card { margin-top: 20px; }

.hero-title {
  font-size: clamp(2rem, 5vw, 2.75rem);
  line-height: 1.15;
  margin-bottom: 12px;
}

.hero-sub { color: var(--muted); max-width: 520px; margin-bottom: 28px; }

.form-group { margin-bottom: 18px; }

.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.hint { font-size: 0.78rem; color: var(--muted); margin-top: 6px; }

.hint.ok { color: var(--teal); }
.hint.err { color: var(--accent); }

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.18s ease;
  user-select: none;
}

.chip:hover { border-color: var(--teal); }

.chip.active {
  background: var(--teal-soft);
  border-color: var(--teal);
  color: var(--teal);
  font-weight: 600;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-box {
  text-align: center;
  padding: 16px 12px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--border);
}

.stat-box strong {
  display: block;
  font-family: var(--display);
  font-size: 1.75rem;
  color: var(--teal);
}

.stat-box span { font-size: 0.75rem; color: var(--muted); }

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

.section-head h2 { font-size: 1.25rem; }

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.tabs button {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: inherit;
}

.tabs button.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.phrase-list { display: grid; gap: 10px; }

.phrase-item {
  display: flex;
  align-items: stretch;
  gap: 8px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  overflow: hidden;
  transition: border-color 0.18s ease;
}

.phrase-item:hover { border-color: var(--teal); }

.phrase-item-main {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: inherit;
}

.phrase-speak {
  align-self: center;
  margin-right: 10px;
}

.phrase-item .word-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.phrase-item .word { font-weight: 600; color: var(--ink); }

.word-row--large {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.word-row--large h3 { font-size: 1.5rem; color: var(--teal); margin: 0; }

.btn-speak, .btn-speak-sm {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.18s ease;
  flex-shrink: 0;
}

.btn-speak {
  padding: 7px 14px;
  font-size: 0.78rem;
  color: var(--teal);
}

.btn-speak-sm {
  padding: 2px 8px;
  font-size: 0.75rem;
  line-height: 1.4;
}

.btn-speak:hover, .btn-speak-sm:hover {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.sentence-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
}

.coverage-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin: -8px 0 14px;
  line-height: 1.7;
}

.phrase-item .trans { font-size: 0.82rem; color: var(--muted); }
.phrase-item .sample { font-size: 0.78rem; color: var(--ink-soft); margin-top: 4px; font-style: italic; }

.status-pill {
  flex-shrink: 0;
  font-size: 0.68rem;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-pill.new { background: var(--accent-soft); color: var(--accent); }
.status-pill.learning { background: rgba(184, 134, 11, 0.15); color: var(--gold); }
.status-pill.mastered { background: var(--teal-soft); color: var(--teal); }

/* Learn card */
.learn-card {
  min-height: 360px;
  display: flex;
  flex-direction: column;
}

.learn-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.tag {
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--paper-deep);
  color: var(--muted);
}

.sentence-en {
  font-family: var(--display);
  font-size: clamp(1.35rem, 3.5vw, 1.85rem);
  line-height: 1.45;
  margin-bottom: 16px;
  color: var(--ink);
}

.sentence-en mark {
  background: linear-gradient(180deg, transparent 60%, rgba(196, 92, 62, 0.25) 60%);
  color: var(--accent);
  font-weight: 700;
  padding: 0 2px;
}

.sentence-zh {
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 24px;
  padding-left: 14px;
  border-left: 3px solid var(--teal-soft);
}

.word-reveal {
  padding: 20px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--teal-soft), var(--accent-soft));
  border: 1px solid var(--border);
  margin-bottom: 24px;
}

.word-reveal.hidden { filter: blur(6px); user-select: none; pointer-events: none; }

.word-reveal h3 {
  font-size: 1.5rem;
  color: var(--teal);
  margin-bottom: 4px;
}

.word-reveal .phonetic {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.learn-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: auto;
  padding-top: 20px;
}

.progress-bar-wrap {
  height: 6px;
  background: var(--paper-deep);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 20px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--accent));
  border-radius: 999px;
  transition: width 0.3s ease;
}

.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--ink);
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 100;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-up { animation: fadeUp 0.45s ease forwards; }

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

.dialogue-toolbar .tabs { margin: 0; }

.dialogue-list { display: grid; gap: 12px; }

.dialogue-item {
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 16px 16px 14px;
  display: grid;
  gap: 8px;
  transition: border-color 0.18s ease, transform 0.18s ease;
}

.dialogue-item:hover { border-color: var(--teal); transform: translateY(-1px); }

.dialogue-item h3 {
  font-family: var(--display);
  font-size: 1.1rem;
  margin: 0;
}

.dialogue-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.dialogue-play {
  display: grid;
  gap: 14px;
}

.dialogue-bubbles {
  display: grid;
  gap: 10px;
  padding: 10px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(42,111,122,0.06), rgba(196,92,62,0.06));
  border: 1px solid var(--border);
}

.bubble {
  max-width: min(760px, 100%);
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fff;
  display: grid;
  gap: 6px;
}

.bubble .who {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--muted);
}

.bubble .en {
  font-size: 1.05rem;
  color: var(--ink);
  line-height: 1.6;
}

.bubble .zh {
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.7;
}

.bubble.a { justify-self: start; }
.bubble.b { justify-self: end; border-color: rgba(42,111,122,0.22); background: rgba(42,111,122,0.06); }

.bubble .en.blurred { filter: blur(7px); user-select: none; pointer-events: none; }

.ref-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ref-chip {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.18s ease;
}
.ref-chip:hover { border-color: var(--teal); background: var(--teal-soft); color: var(--teal); }

.quiz {
  margin-top: 14px;
  padding: 16px;
  border-radius: 16px;
  border: 1px solid rgba(196, 92, 62, 0.25);
  background: rgba(196, 92, 62, 0.06);
  display: grid;
  gap: 10px;
}

.quiz .quiz-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.quiz .quiz-head strong { font-family: var(--display); }
.quiz .quiz-sub { font-family: var(--mono); font-size: 0.82rem; color: var(--muted); }

.quiz-options { display: grid; gap: 10px; }

.quiz-opt {
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  transition: all 0.18s ease;
}

.quiz-opt:hover:not(:disabled) { border-color: var(--accent); }
.quiz-opt.correct { border-color: rgba(42,111,122,0.7); background: rgba(42,111,122,0.12); }
.quiz-opt.wrong { border-color: rgba(196,92,62,0.6); background: rgba(196,92,62,0.10); }
.quiz-opt:disabled { cursor: default; opacity: 0.95; }

.quiz-result {
  font-size: 0.92rem;
  color: var(--ink-soft);
  line-height: 1.7;
}

@media (max-width: 640px) {
  .card { padding: 20px; }
  .learn-actions .btn { flex: 1; min-width: calc(50% - 5px); }
}
