:root {
  color-scheme: light;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d7dde5;
  --panel: #ffffff;
  --canvas: #f4f7fb;
  --accent: #0f8b8d;
  --accent-dark: #0b686a;
  --gold: #f5a524;
  --red: #d64545;
  --green: #17845b;
  --blue: #2867b2;
  --shadow: 0 18px 50px rgba(31, 41, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 22px;
  background: #ffffff;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
}

.brand p,
.eyebrow,
.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.panel,
.details-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
}

.panel h2,
.details-card h3,
.section-head h2 {
  margin: 0 0 12px;
  font-size: 15px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.level-btn,
.segmented button,
.secondary-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 8px;
}

.level-btn.active,
.segmented button.active {
  border-color: var(--accent);
  background: #e8f7f6;
  color: var(--accent-dark);
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  color: var(--muted);
}

.stat-line {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid #eef2f6;
}

.stat-line:last-child {
  border-bottom: 0;
}

.utility-panel {
  display: grid;
  gap: 8px;
}

.secondary-btn {
  width: 100%;
  text-align: center;
}

.secondary-btn.danger {
  color: var(--red);
}

.workspace {
  padding: 24px;
}

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

.topbar h2 {
  margin: 0;
  font-size: 28px;
}

.search-wrap input {
  width: min(360px, 42vw);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fff;
}

.study-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}

.study-stage {
  display: grid;
  gap: 16px;
}

.flashcard {
  position: relative;
  min-height: 430px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  padding: 28px;
  padding-bottom: 240px;
  overflow: hidden;
  user-select: none;
}

.card-level {
  position: absolute;
  top: 22px;
  left: 22px;
  color: var(--accent-dark);
  background: #e8f7f6;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
}

.speak-btn {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  font-weight: 700;
}

.hanzi {
  font-size: clamp(118px, 20vw, 220px);
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0;
}

.card-sub {
  position: absolute;
  bottom: 148px;
  color: var(--muted);
}

.card-back {
  position: absolute;
  left: 28px;
  right: 28px;
  bottom: 24px;
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr) minmax(220px, 1fr);
  grid-template-rows: auto auto;
  gap: 10px;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: 0.18s ease;
}

.flashcard.revealed .card-back {
  opacity: 1;
  transform: translateY(0);
}

#cardExampleRow {
  grid-column: 1 / -1;
}

.polyphone-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.polyphone-badge {
  display: inline-block;
  background: #fff3e8;
  color: #b45309;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: help;
}

.stroke-order-wrap {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 12px;
  min-height: 40px;
}

.stroke-btn {
  border: 1px solid var(--accent);
  background: #e8f7f6;
  color: var(--accent-dark);
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

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

#strokeTarget {
  display: flex;
  align-items: center;
}

#strokeTarget svg {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.radical-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.radical-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 15px;
  font-weight: 500;
  min-width: 36px;
  text-align: center;
}

.radical-btn.active {
  border-color: var(--accent);
  background: #e8f7f6;
  color: var(--accent-dark);
  font-weight: 700;
}

.card-info,
.detail-grid div {
  border: 1px solid #edf1f5;
  background: #f8fafc;
  border-radius: 8px;
  padding: 12px;
}

.card-info strong {
  display: block;
  font-size: 15px;
  line-height: 1.45;
}

.card-info.primary strong {
  color: var(--accent-dark);
  font-size: 26px;
}

.meta-label,
.detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.review-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.rating {
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-weight: 700;
}

.again { background: var(--red); }
.hard { background: var(--gold); color: #332200; }
.good { background: var(--blue); }
.easy { background: var(--green); }

.quiz-panel,
.write-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.quiz-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.quiz-options button,
.write-panel button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  min-height: 48px;
}

.quiz-options button.correct {
  border-color: var(--green);
  background: #e8f8ef;
}

.quiz-options button.wrong {
  border-color: var(--red);
  background: #fff0f0;
}

.write-panel {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 10px;
  align-items: center;
}

.write-panel p,
.write-hint,
.write-result {
  grid-column: 1 / -1;
  margin: 0;
}

.write-hint {
  color: var(--muted);
  font-size: 14px;
}

.write-panel input {
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  font-size: 30px;
}

.details {
  position: sticky;
  top: 24px;
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: #e8edf3;
  overflow: hidden;
  margin-bottom: 14px;
}

.progress-track span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.char-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 156px;
  overflow: auto;
}

.char-pill,
.grid-char {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
}

.char-pill {
  min-width: 36px;
  height: 36px;
}

.char-pill.current,
.grid-char.current {
  border-color: var(--accent);
  background: #e8f7f6;
}

.source-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.browser-section {
  margin-top: 22px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

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

.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.site-footer {
  margin-top: 22px;
  padding: 20px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) minmax(220px, 1fr) minmax(260px, 1.2fr);
  gap: 18px;
  line-height: 1.6;
}

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

.footer-brand img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.footer-brand strong,
.footer-terms strong {
  color: var(--ink);
}

.footer-brand p,
.footer-meta p,
.footer-terms p {
  margin: 4px 0 0;
  font-size: 13px;
}

.grid-char {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-size: 24px;
  position: relative;
}

.grid-char.seen::after,
.grid-char.weak::after {
  content: "";
  position: absolute;
  right: 5px;
  top: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
}

.grid-char.weak::after {
  background: var(--red);
}

.hidden {
  display: none !important;
}

/* ── Auth overlay ─────────────────────────────────────────────────────────── */

.auth-overlay,
.modal-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0b4a4b 0%, #0f8b8d 50%, #17a89a 100%);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 20px;
}

.auth-overlay.hidden,
.modal-overlay.hidden {
  display: none !important;
}

.modal-overlay {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

/* Landing two-column panel */
.auth-panel {
  display: grid;
  grid-template-columns: 1fr 420px;
  max-width: 860px;
  width: 100%;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.35);
}

.auth-promo {
  background: linear-gradient(160deg, #083637 0%, #0f8b8d 100%);
  padding: 48px 40px;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

.promo-logo { width: 46px; height: 46px; }

.promo-brand { font-size: 20px; font-weight: 700; letter-spacing: 0.02em; }
.promo-brand-sub { font-size: 12px; opacity: 0.7; margin-top: 2px; }

.promo-tagline {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.35;
  margin: 0;
}

.promo-features {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.promo-features li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  opacity: 0.92;
}

.promo-features li span { font-size: 18px; flex-shrink: 0; }

.promo-stats-row {
  display: flex;
  gap: 0;
  margin-top: auto;
  border-top: 1px solid rgba(255,255,255,0.2);
  padding-top: 24px;
}

.promo-stat {
  flex: 1;
  text-align: center;
  border-right: 1px solid rgba(255,255,255,0.2);
}
.promo-stat:last-child { border-right: none; }
.promo-stat strong { display: block; font-size: 22px; font-weight: 700; }
.promo-stat span { font-size: 11px; opacity: 0.7; }

@media (max-width: 720px) {
  .auth-panel { grid-template-columns: 1fr; }
  .auth-promo { display: none; }
}

.auth-card,
.modal-card {
  background: #fff;
  border-radius: 0;
  padding: 36px 32px;
  width: 100%;
  display: grid;
  gap: 14px;
}

/* standalone auth-card (not inside panel) gets its own radius + shadow */
.auth-overlay > .auth-card {
  border-radius: 16px;
  width: min(420px, 100%);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}

.modal-card { border-radius: 16px; width: min(480px, 100%); box-shadow: 0 24px 60px rgba(0,0,0,.25); }

.modal-card {
  padding: 0;
  gap: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.modal-close {
  border: 0;
  background: none;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.modal-close:hover { background: #f0f3f7; }

.modal-body {
  padding: 20px 24px 24px;
  display: grid;
  gap: 14px;
}

.auth-logo-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin-bottom: 4px;
}

.auth-logo {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.3);
  flex-shrink: 0;
}

.auth-brand {
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
}

.auth-brand-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.auth-card h2 {
  margin: 0;
  font-size: 22px;
  text-align: center;
}

.auth-sub {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.auth-field {
  display: grid;
  gap: 6px;
}

.auth-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.auth-error {
  margin: 0;
  background: #fff0f0;
  border: 1px solid #fca5a5;
  color: var(--red);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}

.profile-success {
  margin: 0;
  background: #f0fdf4;
  border: 1px solid #86efac;
  color: var(--green);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  text-align: center;
}

.auth-input {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 11px 14px;
  font: inherit;
  font-size: 15px;
  transition: border-color 0.15s;
}

.auth-input:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-submit {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 2px;
  transition: background 0.15s;
}

.auth-submit:hover { background: var(--accent-dark); }
.auth-submit:disabled { opacity: 0.6; cursor: not-allowed; }

.auth-toggle-btn {
  width: 100%;
  padding: 8px;
  background: none;
  border: 0;
  color: var(--accent-dark);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.auth-screen { display: grid; gap: 14px; }
.auth-screen.hidden { display: none; }

.auth-footer-links {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.auth-forgot-btn {
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
}

.auth-forgot-btn:hover { color: var(--accent-dark); text-decoration: underline; }

.auth-privacy-note {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}
.auth-privacy-note a { color: var(--accent); text-decoration: none; }
.auth-privacy-note a:hover { text-decoration: underline; }

.pw-wrap {
  position: relative;
}

.pw-eye {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
}

.pw-eye:hover { color: var(--ink); }

.pw-wrap .auth-input { padding-right: 38px; }

/* ── User bar in sidebar ───────────────────────────────────────────────────── */

.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.user-avatar {
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-nickname {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.user-action-btn {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  line-height: 1;
}

.user-action-btn:hover {
  background: #e8edf3;
  color: var(--ink);
}

/* ── Streak badge ──────────────────────────────────────────────────────────── */

.streak-badge {
  font-size: 12px;
  font-weight: 700;
  background: #fff3e8;
  color: #b45309;
  border: 1px solid #fde68a;
  border-radius: 999px;
  padding: 2px 7px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Achievement toast ────────────────────────────────────────────────────── */

#toastContainer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #1f2933;
  color: #fff;
  padding: 13px 18px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  min-width: 220px;
  max-width: 320px;
  pointer-events: auto;
  animation: toastIn .35s cubic-bezier(.21,1.02,.73,1) forwards;
}

.toast.out { animation: toastOut .3s ease forwards; }

.toast-icon { font-size: 22px; flex-shrink: 0; }
.toast-body strong { display: block; font-size: 14px; margin-bottom: 2px; }
.toast-body span { font-size: 12px; color: #9ca3af; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(120%); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(120%); }
}

/* ── Stats modal ──────────────────────────────────────────────────────────── */

.modal-card.stats-card { width: min(680px, 96vw); }
.modal-card.leaderboard-card { width: min(460px, 96vw); }

.stats-summary-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stats-summary-card {
  background: #f8fafc;
  border-radius: 10px;
  padding: 14px 16px;
  text-align: center;
}

.stats-summary-card .val {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}

.stats-summary-card .lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }

.stats-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin: 18px 0 10px;
}

/* Heatmap */
.heatmap-wrap { overflow-x: auto; padding-bottom: 4px; }

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 1fr);
  gap: 3px;
  width: max-content;
}

.heatmap-cell {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  cursor: default;
}

.heatmap-cell.l0 { background: #e5e7eb; }
.heatmap-cell.l1 { background: #99d4d4; }
.heatmap-cell.l2 { background: #3fa8aa; }
.heatmap-cell.l3 { background: var(--accent-dark); }

/* HSK level bars */
.hsk-level-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.hsk-level-bar-row .level-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  width: 46px;
  flex-shrink: 0;
}

.hsk-bar-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.hsk-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width .5s ease;
}

.hsk-level-bar-row .bar-count {
  font-size: 11px;
  color: var(--muted);
  width: 60px;
  text-align: right;
  flex-shrink: 0;
}

/* Achievement list */
.achievement-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.achievement-item {
  background: #f8fafc;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border: 1px solid var(--line);
}

.achievement-item.unlocked {
  background: #e8f7f6;
  border-color: #b2e0df;
}

.achievement-item.locked { opacity: .45; filter: grayscale(1); }

.achievement-item .ach-icon { font-size: 20px; flex-shrink: 0; }
.achievement-item .ach-name { font-size: 12px; font-weight: 700; line-height: 1.3; }
.achievement-item .ach-desc { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* Leaderboard */
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid #f0f3f7;
}

.leaderboard-row:last-child { border-bottom: 0; }

.leaderboard-row.me {
  background: #e8f7f6;
  margin: 0 -24px;
  padding: 11px 24px;
  border-radius: 8px;
  border-bottom: 0;
}

.lb-rank {
  width: 28px;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  color: var(--muted);
  flex-shrink: 0;
}

.lb-rank.top3 { color: var(--gold); }

.lb-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.lb-name { flex: 1; font-size: 14px; font-weight: 500; }
.lb-score { font-size: 15px; font-weight: 700; color: var(--accent-dark); }
.lb-score-unit { font-size: 11px; color: var(--muted); font-weight: 400; }

/* ── Tablet (980px) ──────────────────────────────────────────────────────────── */
@media (max-width: 980px) {
  .app-shell,
  .study-layout,
  .site-footer { grid-template-columns: 1fr; }
  .sidebar, .details { position: static; height: auto; }
  .topbar { align-items: stretch; flex-direction: column; }
  .search-wrap input { width: 100%; }
}

/* ── Mobile top bar (hidden on desktop) ─────────────────────────────────────── */
.mobile-topbar { display: none; }
.drawer-overlay { display: none; }

/* ── Mobile (768px) ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Fixed top bar */
  .mobile-topbar {
    display: flex;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 54px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    align-items: center;
    padding: 0 12px;
    gap: 10px;
    z-index: 400;
    box-shadow: 0 1px 8px rgba(0,0,0,0.06);
  }

  .mobile-menu-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    background: none;
    border: 0;
    padding: 4px;
    cursor: pointer;
    flex-shrink: 0;
  }
  .mobile-menu-btn span {
    display: block;
    height: 2px;
    background: var(--ink);
    border-radius: 2px;
    transition: 0.2s;
  }

  .mobile-brand {
    flex: 1;
    font-size: 15px;
    font-weight: 700;
    color: var(--ink);
  }

  .mobile-nav-actions {
    display: flex;
    align-items: center;
    gap: 2px;
  }

  /* Sidebar → slide-in drawer */
  .sidebar {
    position: fixed;
    top: 54px; left: 0; bottom: 0;
    width: min(300px, 85vw);
    z-index: 600;
    transform: translateX(-100%);
    transition: transform 0.26s cubic-bezier(.4,0,.2,1);
    overflow-y: auto;
    height: auto;
    border-right: 1px solid var(--line);
    box-shadow: 4px 0 24px rgba(0,0,0,0.12);
  }
  .sidebar.open { transform: translateX(0); }

  /* Drawer overlay */
  .drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.38);
    z-index: 500;
    backdrop-filter: blur(1px);
  }
  .drawer-overlay.open { display: block; }

  /* App shell: single column, push down for top bar */
  .app-shell {
    grid-template-columns: 1fr;
    padding-top: 54px;
  }

  /* Workspace */
  .workspace { padding: 14px; }

  /* Hide desktop topbar title on mobile (shown by workspace below) */
  .topbar {
    flex-direction: row;
    align-items: center;
    margin-bottom: 12px;
    gap: 10px;
  }
  .topbar > div:first-child h2 { font-size: 18px; }
  .topbar > div:first-child p  { font-size: 12px; }
  .search-wrap input {
    width: 100%;
    font-size: 14px;
    padding: 9px 12px;
  }

  /* Flashcard: flex column, no absolute tricks */
  .flashcard {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: auto;
    padding: 16px;
    padding-bottom: 16px;
    gap: 12px;
  }

  .card-level {
    position: static;
    align-self: flex-start;
    margin: 0;
  }

  .speak-btn {
    position: absolute;
    top: 14px;
    right: 14px;
  }

  .hanzi {
    font-size: clamp(88px, 28vw, 130px);
    margin: 8px 0 4px;
  }

  .card-sub {
    position: static;
    margin: 0;
    text-align: center;
    font-size: 13px;
  }

  .card-back {
    position: static;
    display: none;
    grid-template-columns: 1fr;
    width: 100%;
    margin: 0;
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }

  .flashcard.revealed .card-back {
    display: grid;
  }

  .flashcard.revealed .card-sub { display: none; }

  /* Review controls */
  .review-controls {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .rating {
    min-height: 54px;
    font-size: 14px;
    font-weight: 700;
  }

  /* Quiz options */
  .quiz-options { grid-template-columns: 1fr 1fr; gap: 8px; }

  /* Study layout: single column */
  .study-layout { grid-template-columns: 1fr; }

  /* Modals: near full-width */
  .modal-card,
  .modal-card.stats-card,
  .modal-card.leaderboard-card {
    width: min(100vw, 100%);
    border-radius: 20px 20px 0 0;
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  /* Stats modal body scroll */
  .modal-card.stats-card .modal-body { overflow-y: auto; }

  /* Achievement grid on mobile */
  .achievement-grid { grid-template-columns: 1fr 1fr; }

  /* Auth panel: already handled */
}

/* ── Small phones (400px) ────────────────────────────────────────────────────── */
@media (max-width: 400px) {
  .mobile-nav-actions .streak-badge { display: none; }
  .hanzi { font-size: 80px; }
  .level-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ── Onboarding modal ────────────────────────────────────────────────────────── */

.onboard-card {
  width: min(400px, 96vw);
  padding: 32px;
  gap: 20px;
  text-align: center;
  border-radius: 20px;
  box-shadow: 0 28px 70px rgba(0,0,0,.35);
}

.onboard-steps-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.onboard-step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
  transition: background .2s;
}

.onboard-step-dot.active { background: var(--accent); }

.onboard-slide { display: none; }
.onboard-slide.active { display: block; }

.onboard-icon { font-size: 52px; margin-bottom: 8px; }

.onboard-card h3 { margin: 0 0 10px; font-size: 18px; }
.onboard-card p  { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.onboard-card strong { color: var(--ink); }

.onboard-img {
  width: 100%;
  border-radius: 10px;
  margin-top: 14px;
  border: 1px solid var(--line);
}

.onboard-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 4px;
}

.onboard-skip {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
}
.onboard-skip:hover { color: var(--ink); }

.onboard-next {
  flex: 1;
  max-width: 160px;
  padding: 10px 20px;
  font-size: 14px;
  margin: 0;
}
