/* ---------- Design tokens ---------- */
:root {
  --bg: #f5f1ea;
  --bg-accent: radial-gradient(1200px 600px at 80% -10%, #fde8d7 0%, transparent 60%),
               radial-gradient(900px 500px at -10% 110%, #fbe3e0 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #faf7f2;
  --ink: #221c17;
  --muted: #85796d;
  --line: #e8e0d5;
  --accent: #c73e1d;
  --accent-soft: #fbe9e4;
  --green: #1e7d43;
  --green-soft: #e3f3e9;
  --amber: #b97a13;
  --amber-soft: #fbf0dc;
  --red: #bb2c2c;
  --red-soft: #fbe7e7;
  --shadow: 0 1px 2px rgba(40, 30, 20, .05), 0 12px 32px -12px rgba(40, 30, 20, .18);
  --radius: 20px;
  --font-zh: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "SimHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130f;
    --bg-accent: radial-gradient(1200px 600px at 80% -10%, rgba(199, 62, 29, .12) 0%, transparent 60%),
                 radial-gradient(900px 500px at -10% 110%, rgba(199, 62, 29, .08) 0%, transparent 55%);
    --surface: #221d18;
    --surface-2: #2a241e;
    --ink: #f2ece3;
    --muted: #a2968a;
    --line: #38302a;
    --accent: #e2593a;
    --accent-soft: #3a241d;
    --green: #4cb878;
    --green-soft: #1e3327;
    --amber: #d99b36;
    --amber-soft: #362b18;
    --red: #e06767;
    --red-soft: #3a2020;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px -12px rgba(0, 0, 0, .5);
  }
}

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

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image: var(--bg-accent);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(16px, 4vw, 32px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: .01em;
}

.brand-logo {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-zh);
  font-size: 1.15rem;
  box-shadow: var(--shadow);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: var(--muted);
}

.icon-btn.small { width: 32px; height: 32px; border-radius: 10px; }

.icon-btn:hover { background: var(--surface); color: var(--ink); }

/* ---------- Layout ---------- */
main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 8px clamp(16px, 4vw, 32px) 32px;
  display: flex;
  flex-direction: column;
}

/* ---------- Home ---------- */
.home-hero { text-align: center; padding: clamp(10px, 3vh, 32px) 0 20px; }

.home-hero .hanzi-deco {
  font-family: var(--font-zh);
  font-size: clamp(2.4rem, 8vw, 3.2rem);
  color: var(--accent);
  letter-spacing: .12em;
}

.home-hero h1 { font-size: clamp(1.4rem, 5vw, 1.9rem); margin-top: 8px; }

.home-hero p { color: var(--muted); margin-top: 8px; max-width: 46ch; margin-inline: auto; }

.section-label {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  margin: 18px 0 10px;
}

/* Resume banner */
.resume-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 14px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}

.resume-text { flex: 1; min-width: 180px; display: flex; flex-direction: column; }
.resume-text span { color: var(--muted); font-size: .85rem; }

/* Level picker */
.level-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.level-chip {
  text-align: left;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.level-chip.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: var(--shadow);
}

.level-num {
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
}

.level-title { font-weight: 700; }

.level-sub { font-size: .76rem; color: var(--muted); }

.level-progress { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

.level-progress .bar {
  flex: 1;
  height: 5px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}

.level-progress .bar span { display: block; height: 100%; background: var(--green); }

.level-progress .nums { font-size: .72rem; font-weight: 700; color: var(--muted); }

/* Mode grid */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}

.mode-card {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
}

.mode-card:hover { border-color: var(--accent); }

.mode-card .mode-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-zh);
}

.mode-card h3 { font-size: 1.05rem; }

.mode-card p { color: var(--muted); font-size: .88rem; }

.mode-card .mode-arrow { margin-left: auto; color: var(--accent); font-weight: 600; font-size: .88rem; }

.deck-note { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 22px; }

/* ---------- Session header ---------- */
.session-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.session-top .end-link {
  margin-left: auto;
  color: var(--muted);
  font-size: .88rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.session-top .end-link:hover { color: var(--ink); }

.progress {
  height: 8px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
  display: flex;
  margin-bottom: 10px;
}

.progress .seg.done { background: var(--green); }
.progress .seg.incorrect { background: var(--red); }

.bucket-counts {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.count-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
}

.count-chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.count-chip .dot.stack { background: var(--muted); }
.count-chip .dot.done { background: var(--green); }
.count-chip .dot.incorrect { background: var(--red); }

/* ---------- Flashcard ---------- */
.flashcard {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 6px);
  box-shadow: var(--shadow);
  padding: clamp(20px, 5vw, 36px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* Attempt history for this card (this session), top-right corner */
.card-history {
  position: absolute;
  top: 14px;
  right: 16px;
  display: flex;
  gap: 5px;
  max-width: 40%;
  flex-wrap: wrap;
  justify-content: flex-end;
  cursor: help;
}

.h-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid var(--surface);
  box-shadow: 0 0 0 1px var(--line);
}

.h-dot.c { background: var(--green); }
.h-dot.w { background: var(--red); }
.h-dot.r { background: var(--amber); }

.exercise-tag {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 12px;
  border-radius: 99px;
}

.prompt-zh {
  font-family: var(--font-zh);
  font-size: clamp(3.2rem, 14vw, 5rem);
  line-height: 1.15;
  text-align: center;
}

.prompt-zh.long { font-size: clamp(1.7rem, 7vw, 2.6rem); line-height: 1.4; }

.prompt-en {
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  font-weight: 700;
  text-align: center;
}

.prompt-en.long { font-size: clamp(1.15rem, 5vw, 1.6rem); }

/* Interlinear pinyin: character on top, numbered pinyin (ni3) below, tap to hear */
.ruby-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  column-gap: 8px;
  row-gap: 10px;
}

.ruby-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3px 6px;
  border-radius: 12px;
}

button.ruby-col:hover { background: var(--accent-soft); }

.ruby-zh { font-family: var(--font-zh); line-height: 1.15; }

.ruby-py {
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .03em;
}

.ruby-row.big .ruby-zh { font-size: clamp(2.7rem, 11vw, 4.2rem); }
.ruby-row.big .ruby-py { font-size: clamp(.95rem, 3vw, 1.2rem); }
.ruby-row.big.long .ruby-zh { font-size: clamp(1.8rem, 6.5vw, 2.6rem); }
.ruby-row.big.long .ruby-py { font-size: clamp(.75rem, 2.2vw, .95rem); }
.ruby-row.small .ruby-zh { font-size: 1.7rem; }
.ruby-row.small .ruby-py { font-size: .82rem; }
.ruby-row.small .ruby-emoji { font-size: 1.05rem; }
.ruby-row.small { align-items: flex-start; }

.ruby-col.punct { cursor: default; }

/* progressive hints on the card prompt: the hanzi reads as continuous text,
   hidden hints take no space until their character is tapped */
.ruby-row.reveal {
  align-items: flex-start;
  column-gap: 0;
}

.ruby-row.reveal .ruby-col { padding: 0; }

.concealed { display: none; }

/* keeps neighboring visible pinyin from running together */
.ruby-py { padding: 0 3px; }

.ruby-emoji { font-size: 1.3rem; line-height: 1.3; }

.ruby-row.big .ruby-emoji { font-size: clamp(1.1rem, 3.2vw, 1.5rem); }

/* Speak buttons */
.speak-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  color: var(--accent);
  background: var(--surface);
}

.speak-btn svg { width: 20px; height: 20px; }

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

.speak-btn.small { width: 30px; height: 30px; vertical-align: middle; display: inline-grid; }

.speak-btn.small svg { width: 15px; height: 15px; }

/* Multiple choice */
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 460px;
}

.choices.long { grid-template-columns: 1fr; }

.choice {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  font-weight: 600;
}

.choice:hover:not(:disabled) { border-color: var(--accent); }

.choice:disabled { cursor: default; }

.choice.correct { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.choice.wrong { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.choice.faded { opacity: .45; }

/* Typing */
.answer-form {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 460px;
}

.answer-input {
  flex: 1;
  min-width: 0;
  padding: 13px 16px;
  font-size: 1.05rem;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
}

.answer-input.zh { font-family: var(--font-zh); font-size: 1.3rem; }

.answer-input::placeholder { color: var(--muted); opacity: .8; }

.submit-btn {
  padding: 13px 20px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.submit-btn:hover { filter: brightness(1.08); }

.reveal-btn {
  color: var(--muted);
  font-size: .88rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.reveal-btn:hover { color: var(--ink); }

/* Hidden-choices Recognize: prominent reveal button + hint */
.reveal-primary {
  min-width: 200px;
  margin-top: 4px;
}

.reveal-hint {
  color: var(--muted);
  font-size: .82rem;
  text-align: center;
}

/* Feedback */
.feedback {
  width: 100%;
  max-width: 460px;
  border-radius: 16px;
  padding: 16px 18px;
  text-align: center;
}

/* color alone signals the outcome, so make it unmistakable */
.feedback.good { background: var(--green-soft); border: 2px solid var(--green); }
.feedback.bad { background: var(--red-soft); border: 2px solid var(--red); }
.feedback.neutral { background: var(--surface-2); border: 2px solid var(--line); }

.feedback .full-answer { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.feedback .full-zh { font-family: var(--font-zh); font-size: 1.6rem; }
.feedback .full-zh.long { font-size: 1.2rem; }
.feedback .answer-en {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: .95rem;
  font-weight: 600;
}

/* Literal breakdown */
.literal {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: stretch;
  margin-top: 14px;
}

.lit-label {
  width: 100%;
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  margin-bottom: 4px;
}

.lit-seg {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  min-width: 68px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.lit-seg:hover { border-color: var(--accent); }

.lit-zh { font-family: var(--font-zh); font-size: 1.5rem; line-height: 1.25; }

.lit-gloss { font-size: .8rem; font-weight: 600; color: var(--ink); max-width: 130px; }

.lit-emoji { font-size: 1.6rem; line-height: 1.2; }

/* Interlinear gloss (phrases & sentences): each word above its meaning, in order */
.gloss { width: 100%; margin-top: 14px; }

.gloss-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 6px 2px;
  margin-top: 6px;
}

.gloss-seg {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 6px;
  border-radius: 10px;
  border: 1px solid transparent;
}

.gloss-seg:hover { background: var(--surface-2); border-color: var(--line); }

.gloss-zh { font-family: var(--font-zh); font-size: 1.55rem; line-height: 1.2; }

.gloss-en {
  font-size: .74rem;
  color: var(--muted);
  max-width: 92px;
  line-height: 1.2;
}

.auto-note { font-size: .8rem; color: var(--muted); margin-top: 8px; }

/* ---------- Buckets ---------- */
.buckets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.bucket {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px 12px;
  border-radius: 16px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  font-weight: 700;
  font-size: .85rem;
}

.bucket svg { width: 24px; height: 24px; }

.bucket:disabled { opacity: .4; cursor: not-allowed; }

.bucket.done { color: var(--green); }
.bucket.done:not(:disabled):hover { background: var(--green-soft); border-color: var(--green); }

.bucket.back { color: var(--amber); }
.bucket.back:not(:disabled):hover { background: var(--amber-soft); border-color: var(--amber); }

.bucket.incorrect { color: var(--red); }
.bucket.incorrect:not(:disabled):hover { background: var(--red-soft); border-color: var(--red); }

/* Deliberate exception to the no-animation rule: signals a pending automatic move. */
.bucket.pulse { animation: pulse 1s ease infinite; border-color: currentColor; }

@keyframes pulse {
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, currentColor 15%, transparent); }
}

.bucket-hint { text-align: center; color: var(--muted); font-size: .78rem; margin-top: 10px; }

/* ---------- Interstitial / summary ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 6px);
  box-shadow: var(--shadow);
  padding: clamp(24px, 6vw, 44px);
  text-align: center;
  margin-top: 4vh;
}

.panel .big-emoji { font-size: 3rem; }

.panel h2 { margin-top: 10px; font-size: 1.4rem; }

.panel p { color: var(--muted); margin-top: 8px; }

.stat-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 22px 0;
  flex-wrap: wrap;
}

.stat {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 22px;
  min-width: 96px;
}

.stat .num { font-size: 1.6rem; font-weight: 800; }
.stat .num.green { color: var(--green); }
.stat .num.red { color: var(--red); }
.stat .lbl { font-size: .78rem; color: var(--muted); font-weight: 600; }

.panel-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }

.btn {
  padding: 12px 24px;
  border-radius: 14px;
  font-weight: 700;
}

.btn.small { padding: 8px 16px; font-size: .88rem; }

.btn:hover { filter: brightness(1.05); }

.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { border: 1.5px solid var(--line); background: var(--surface); }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); background: var(--red-soft); }

/* ---------- Settings modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 8, .45);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(460px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 24px;
}

.modal h2 { font-size: 1.2rem; margin-bottom: 4px; }

.modal .modal-sub { color: var(--muted); font-size: .88rem; margin-bottom: 18px; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.setting-row .setting-text { flex: 1; }
.setting-row .setting-title { font-weight: 600; font-size: .95rem; }
.setting-row .setting-desc { color: var(--muted); font-size: .8rem; margin-top: 2px; }

/* Toggle switch */
.switch { position: relative; flex-shrink: 0; width: 48px; height: 28px; }

.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; margin: 0; }

.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 99px;
  background: var(--line);
  pointer-events: none;
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}

.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:disabled + .track { opacity: .4; }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.select {
  font: inherit;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  max-width: 170px;
}

.modal-close { display: block; margin: 20px auto 0; }

/* ---------- Related-words panel ---------- */
.char-panel-overlay {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(20, 14, 8, .35);
}

.char-panel {
  position: fixed;
  z-index: 56;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

/* desktop: side drawer on the right */
@media (min-width: 721px) {
  .char-panel {
    top: 0;
    right: 0;
    bottom: 0;
    width: min(380px, 90vw);
    border-top: none;
    border-bottom: none;
    border-right: none;
  }
}

/* mobile: bottom sheet */
@media (max-width: 720px) {
  .char-panel {
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 72dvh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    animation: sheet-up .18s ease;
  }

  @keyframes sheet-up {
    from { transform: translateY(35%); }
  }
}

.char-panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.cp-zh { font-family: var(--font-zh); font-size: 2rem; line-height: 1.2; }

.cp-emoji { font-size: 1.5rem; }

.cp-meta { flex: 1; min-width: 0; }

.cp-py { color: var(--accent); font-weight: 700; }

.cp-gloss { display: block; color: var(--muted); font-size: .82rem; }

.char-panel-list {
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.panel-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 10px;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
}

.panel-item:hover { background: var(--surface-2); border-color: var(--line); }

.pi-zh { font-family: var(--font-zh); font-size: 1.2rem; }

.pi-zh mark { background: none; color: var(--accent); font-weight: 700; }

.pi-emoji { font-size: 1.15rem; margin-left: auto; }

.pi-sub { width: 100%; color: var(--muted); font-size: .8rem; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  width: min(440px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 4px solid var(--amber);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px 16px;
  font-size: .88rem;
}

/* ---------- Learning / Explore ---------- */
.learn-cta {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 4px;
}

.learn-cta:hover { border-color: var(--accent); }

.learn-cta-icon {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  background: var(--accent-soft);
}

.learn-cta-text { flex: 1; display: flex; flex-direction: column; }
.learn-cta-text strong { font-size: 1.05rem; }
.learn-cta-text span { color: var(--muted); font-size: .85rem; }
.learn-cta .mode-arrow { margin-left: auto; color: var(--accent); font-weight: 600; font-size: .88rem; }

.learn-top { margin-bottom: 6px; }
.learn-top .end-link { color: var(--muted); font-size: .9rem; text-decoration: none; }
.learn-top .end-link:hover { color: var(--ink); }
.learn-hero { padding-top: 4px; }
.learn-hero .hanzi-deco { font-size: clamp(2rem, 7vw, 2.6rem); }

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 99px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  font-weight: 600;
  font-size: .88rem;
}

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

.tag-chip.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.tag-emoji { font-size: 1.05rem; }

.tag-count {
  font-size: .74rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 99px;
  padding: 1px 7px;
}

.tag-chip.selected .tag-count { color: var(--accent); background: var(--surface); }

.learn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.learn-word {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 14px 10px;
  border-radius: 16px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.learn-word:hover { border-color: var(--accent); }

.lw-emoji { font-size: 1.7rem; line-height: 1.3; }
.lw-emoji.lw-none { height: 1.7rem; }
.lw-zh { font-family: var(--font-zh); font-size: 1.7rem; line-height: 1.2; }
.lw-py { color: var(--accent); font-weight: 700; font-size: .85rem; }
.lw-en { color: var(--muted); font-size: .82rem; }

/* ---------- Mobile tweaks ---------- */
@media (max-width: 480px) {
  .choices { grid-template-columns: 1fr; }
  .answer-form { flex-direction: column; }
  .submit-btn { width: 100%; }
  .bucket { font-size: .78rem; padding: 12px 4px 10px; }
  .brand-name { font-size: 1rem; }
  .level-row { grid-template-columns: 1fr 1fr; }
  .learn-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
}
