:root {
  --paper:      #f6f1e7;
  --card:       #fbf8f2;
  --ink:        #2b2622;
  --ink-soft:   #6b6259;
  --seal:       #ae3b2e;
  --teal:       #1a7f8e;
  --gold:       #b07a18;
  --green:      #2e7d52;
  --rule:       #ddd3c0;
  --rule-light: #ede7d9;
  --font-display: "Source Serif 4", serif;
  --font-cn:      "Noto Serif SC", serif;
  --font-ui:      "IBM Plex Sans", sans-serif;
}

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

html, body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
}

/* ── Page ────────────────────────────────────────────────────────────── */
.page {
  max-width: 660px;
  margin: 0 auto;
  padding: 40px 20px 96px;
}

/* ── Top bar right group ─────────────────────────────────────────────── */
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Font size toggle ────────────────────────────────────────────────── */
.font-toggle {
  display: flex;
  align-items: baseline;
  gap: 2px;
  background: var(--rule-light);
  border-radius: 20px;
  padding: 3px 6px;
}

.font-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-weight: 600;
  cursor: pointer;
  border-radius: 12px;
  padding: 2px 6px;
  line-height: 1;
  transition: color 0.12s, background 0.12s;
}
.font-btn:nth-child(1) { font-size: 13px; }
.font-btn:nth-child(2) { font-size: 17px; }
.font-btn:nth-child(3) { font-size: 21px; }
.font-btn.active       { background: var(--card); color: var(--seal); }
.font-btn:hover:not(.active) { color: var(--ink); }

/* ── Large font overrides ────────────────────────────────────────────── */
html.font-large .headword       { font-size: 38px; }
html.font-large .pron-ipa       { font-size: 17px; }
html.font-large .quick-def      { font-size: 18px; }
html.font-large .pos-badge      { font-size: 13px; }
html.font-large .def-list li    { font-size: 18px; }
html.font-large .coll-items     { font-size: 17px; }
html.font-large .coll-pattern   { font-size: 13px; }
html.font-large .related-row    { font-size: 17px; }
html.font-large .example .en    { font-size: 17px; }
html.font-large .example .cn    { font-size: 17px; }
html.font-large .ex-num         { font-size: 16px; }
html.font-large .fav-word       { font-size: 22px; }
html.font-large #word-input     { font-size: 24px; }
html.font-large .trans-source        { font-size: 18px; }
html.font-large .trans-result        { font-size: 26px; }

/* ── Extra large font overrides ──────────────────────────────────────── */
html.font-xlarge .headword      { font-size: 46px; }
html.font-xlarge .pron-ipa      { font-size: 20px; }
html.font-xlarge .quick-def     { font-size: 22px; }
html.font-xlarge .pos-badge     { font-size: 15px; }
html.font-xlarge .def-list li   { font-size: 22px; }
html.font-xlarge .coll-items    { font-size: 20px; }
html.font-xlarge .coll-pattern  { font-size: 15px; }
html.font-xlarge .related-row   { font-size: 20px; }
html.font-xlarge .example .en   { font-size: 20px; }
html.font-xlarge .example .cn   { font-size: 20px; }
html.font-xlarge .ex-num        { font-size: 19px; }
html.font-xlarge .fav-word      { font-size: 26px; }
html.font-xlarge #word-input    { font-size: 26px; }
html.font-xlarge .trans-source        { font-size: 20px; }
html.font-xlarge .trans-result        { font-size: 30px; }

/* ── Top bar ─────────────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.app-title {
  font-family: var(--font-cn);
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.04em;
}

.fav-count-btn {
  display: none;
  align-items: center;
  gap: 5px;
  border: none;
  background: var(--seal);
  color: var(--card);
  border-radius: 20px;
  padding: 6px 12px 6px 10px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.fav-count-btn.visible { display: inline-flex; }
.fav-count-btn:hover   { background: #962f24; }

/* ── Search bar ──────────────────────────────────────────────────────── */
.search-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

#word-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-size: 22px;
  padding: 10px 4px;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--ink);
  color: var(--ink);
  outline: none;
}
#word-input::placeholder { color: var(--ink-soft); font-style: italic; }
#word-input:focus-visible { outline: none; border-bottom-color: var(--seal); }

#search-btn {
  flex-shrink: 0;
  white-space: nowrap;
  font-family: var(--font-cn);
  font-size: 20px;
  font-weight: 600;
  width: 56px;
  border: none;
  border-radius: 6px;
  background: var(--seal);
  color: var(--card);
  cursor: pointer;
  transition: background 0.15s;
}
#search-btn:hover    { background: #962f24; }
#search-btn:disabled { background: var(--ink-soft); cursor: default; }

/* ── Result area ─────────────────────────────────────────────────────── */
.result { margin-top: 28px; }

.empty-state, .status-state {
  color: var(--ink-soft);
  font-style: italic;
  text-align: center;
  padding: 40px 0;
}
.error-state {
  color: var(--seal);
  text-align: center;
  padding: 32px 0;
  font-weight: 500;
}

/* ── Card ────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 28px 24px;
}

/* ── Headword + fav button ───────────────────────────────────────────── */
.card-head { margin-bottom: 12px; }

.card-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.headword {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 32px;
  color: var(--ink);
  line-height: 1.1;
}

.fav-btn {
  flex-shrink: 0;
  border: none;
  background: transparent;
  font-size: 28px;
  color: var(--rule);
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  transition: color 0.15s, transform 0.15s;
}
.fav-btn:hover  { color: var(--seal); transform: scale(1.15); }
.fav-btn.active { color: var(--seal); }

.head-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mic-btn {
  flex-shrink: 0;
  border: none;
  background: var(--rule-light);
  color: var(--ink-soft);
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}
.mic-btn:hover { background: var(--rule); color: var(--ink); }
.mic-btn.recording {
  background: var(--seal);
  color: var(--card);
  animation: mic-pulse 1.1s ease-in-out infinite;
}
.mic-btn.scoring {
  background: var(--ink-soft);
  color: var(--card);
  animation: mic-spin 0.8s linear infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(174, 59, 46, 0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(174, 59, 46, 0); }
}
@keyframes mic-spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.pron-score {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.pron-score--good  { color: var(--green); }
.pron-score--ok    { color: var(--gold); }
.pron-score--low,
.pron-score--error { color: var(--seal); }

/* ── Pronunciation ───────────────────────────────────────────────────── */
.pron {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  align-items: center;
}
.pron-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.pron-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--card);
  background: var(--teal);
  border-radius: 3px;
  padding: 1px 6px;
}
.pron-ipa {
  font-size: 14px;
  color: var(--ink-soft);
}
.audio-btn {
  border: none;
  background: var(--teal);
  color: var(--card);
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.15s;
}
.audio-btn:hover { background: #155f6b; }

/* ── Quick Chinese summary ───────────────────────────────────────────── */
.quick-summary {
  margin: 14px 0;
  padding: 12px 14px;
  background: #eef7f8;
  border-left: 3px solid var(--teal);
  border-radius: 0 3px 3px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.quick-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.pos-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--card);
  background: var(--teal);
  border-radius: 3px;
  padding: 2px 6px;
}
.quick-def {
  font-family: var(--font-cn);
  font-size: 15px;
  color: var(--ink);
  line-height: 1.5;
}

/* ── Word forms ──────────────────────────────────────────────────────── */
.word-forms {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 16px;
  margin: 0 0 14px;
  font-size: 13px;
}
.wf-item { display: flex; gap: 5px; align-items: baseline; }
.wf-label { color: var(--gold); font-weight: 600; white-space: nowrap; }
.wf-val   { color: var(--ink); }

html.font-large  .word-forms { font-size: 16px; }
html.font-xlarge .word-forms { font-size: 19px; }

/* ── E-C Definitions ─────────────────────────────────────────────────── */
.def-block {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}
.pos-seal {
  flex-shrink: 0;
  background: var(--seal);
  color: var(--card);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 11px;
  border-radius: 3px;
  padding: 3px 7px;
  height: fit-content;
  margin-top: 2px;
}
.def-list {
  margin: 0;
  padding: 0;
  list-style: none;
  flex: 1;
}
.def-list li {
  display: flex;
  gap: 8px;
  font-family: var(--font-cn);
  font-size: 15px;
  line-height: 1.65;
  margin-bottom: 3px;
  color: var(--ink);
}
.def-list .num {
  font-family: var(--font-ui);
  color: var(--ink-soft);
  font-size: 12px;
  margin-top: 3px;
  flex-shrink: 0;
}

/* ── Divider ─────────────────────────────────────────────────────────── */
.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 20px 0 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
}
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}
.divider--coll { color: var(--gold); }
.divider--coll::after { background: #e8d5a3; }

/* ── Collocations ────────────────────────────────────────────────────── */
.coll-rows { display: flex; flex-direction: column; gap: 6px; }
.coll-row  { display: flex; align-items: baseline; gap: 10px; font-size: 14px; }
.coll-pattern {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--card);
  background: var(--gold);
  border-radius: 3px;
  padding: 2px 7px;
}
.coll-items { color: var(--ink); line-height: 1.5; }

/* ── Related words ───────────────────────────────────────────────────── */
.related-row {
  font-size: 14px;
  margin: 0 0 6px;
  line-height: 1.6;
  color: var(--ink);
}
.related-row:last-child { margin-bottom: 0; }
.related-label {
  display: inline-block;
  min-width: 68px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--card);
  background: var(--green);
  border-radius: 3px;
  padding: 2px 6px;
  margin-right: 8px;
}

/* ── Expand examples button ──────────────────────────────────────────── */
.expand-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 5px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}
.expand-btn:hover { border-color: var(--teal); color: var(--teal); }

/* ── Example sentences ───────────────────────────────────────────────── */
.example { margin-bottom: 14px; }
.example:last-child { margin-bottom: 0; }
.ex-num {
  font-family: var(--font-ui);
  color: var(--seal);
  font-weight: 700;
  font-size: 13px;
  margin-right: 4px;
}
.example .en {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
}
.example .cn {
  font-family: var(--font-cn);
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink-soft);
  margin-top: 3px;
  padding-left: 18px;
}
.ex-speak {
  border: none;
  background: transparent;
  color: var(--teal);
  cursor: pointer;
  padding: 0 4px;
  margin-left: 3px;
  vertical-align: middle;
  display: inline-flex;
  align-items: center;
  transition: color 0.12s, transform 0.12s;
}
.ex-speak:hover { color: #155f6b; transform: scale(1.12); }

/* ── Translation card (AI sentence translation) ──────────────────────── */
.trans-card { display: flex; flex-direction: column; gap: 14px; }
.trans-source {
  font-size: 16px;
  color: var(--ink);
  line-height: 1.5;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}
.trans-result { font-size: 22px; line-height: 1.7; color: var(--green); }

/* Sans for English, serif for Chinese — the balanced pairing used by the
   dictionary example sentences. Applies to both the source and result lines. */
.trans-source.lang-en, .trans-result.lang-en { font-family: var(--font-ui); }
.trans-source.lang-cn, .trans-result.lang-cn { font-family: var(--font-cn); }

/* ── Favourites overlay ──────────────────────────────────────────────── */
.fav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  align-items: flex-end;
  justify-content: center;
}
.fav-overlay.open { display: flex; }

.fav-panel {
  background: var(--card);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 660px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.18);
}
.fav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}
.fav-title {
  font-family: var(--font-cn);
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
}
.fav-close {
  border: none;
  background: var(--rule-light);
  color: var(--ink-soft);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fav-close:hover { background: var(--rule); }

.fav-list {
  overflow-y: auto;
  flex: 1;
  padding: 6px 16px;
}
.fav-empty {
  text-align: center;
  color: var(--ink-soft);
  font-style: italic;
  padding: 32px 0;
  font-size: 14px;
}

.fav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--rule-light);
  padding: 11px 0;
}
.fav-item:last-child { border-bottom: none; }

.fav-word-btn {
  flex: 1;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  padding: 4px 0;
}
.fav-word-btn:hover .fav-word { color: var(--teal); }

.fav-word {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  color: var(--ink);
  transition: color 0.12s;
}
.fav-def {
  font-family: var(--font-cn);
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}
.fav-remove {
  border: none;
  background: transparent;
  color: var(--rule);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  flex-shrink: 0;
  transition: color 0.12s;
}
.fav-remove:hover { color: var(--seal); }

.fav-footer {
  padding: 12px 22px 24px;
  border-top: 1px solid var(--rule);
  flex-shrink: 0;
}
.fav-clear-btn {
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 4px;
  cursor: pointer;
  width: 100%;
}
.fav-clear-btn:hover { border-color: var(--seal); color: var(--seal); }

.settings-body {
  padding: 20px 22px 24px;
}
.settings-desc {
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-soft);
  margin-bottom: 18px;
}
.reset-all-btn {
  border: none;
  background: var(--seal);
  color: var(--card);
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 4px;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
}
.reset-all-btn:hover { background: #962f24; }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .page      { padding: 32px 16px 80px; }
  .card      { padding: 22px 18px; }
  .headword  { font-size: 28px; }
  .word-forms { grid-template-columns: 1fr; }

  /* Stack the top bar so the title gets its own full-width centered line
     instead of being squeezed next to the controls. */
  .top-bar {
    flex-direction: column;
    align-items: center;
    gap: 14px;
  }
  .app-title { text-align: center; white-space: nowrap; }
  .top-bar-right { width: 100%; justify-content: center; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  .audio-btn, #search-btn, .fav-btn, .mic-btn { transition: none; }
  .mic-btn.recording, .mic-btn.scoring { animation: none; }
}

/* ── Icon button (import) ────────────────────────────────────────────── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 34px;
  padding: 0 12px 0 9px;
  border: none;
  background: var(--teal);
  color: var(--card);
  border-radius: 20px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: #155f6b; }

.icon-btn--ghost {
  width: 34px;
  padding: 0;
  background: var(--rule-light);
  color: var(--ink-soft);
}
.icon-btn--ghost:hover { background: var(--rule); color: var(--ink); }

/* ── Import panel cards ──────────────────────────────────────────────── */
.import-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.import-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 14px 14px;
  transition: border-color 0.15s;
}
.import-card:hover        { border-color: var(--teal); }
.import-card--done        { opacity: 0.6; }

.import-card-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.import-emoji { font-size: 28px; flex-shrink: 0; line-height: 1; }

.import-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.import-name {
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}
.import-count {
  font-size: 12px;
  color: var(--ink-soft);
}

.import-action-btn {
  flex-shrink: 0;
  border: none;
  color: var(--card);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.import-action-btn:hover { opacity: 0.85; }

.import-done-badge {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
}

/* ── Toast notification ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--card);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  padding: 11px 22px;
  border-radius: 24px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 2000;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Import controls (stepper + button) ──────────────────────────────── */
.import-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.import-stepper {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--rule);
  border-radius: 20px;
  overflow: hidden;
}

.stepper-btn {
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
}
.stepper-btn:hover { background: var(--rule-light); }

.stepper-val {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  min-width: 28px;
  text-align: center;
}

/* ── Import count picker (old - kept for compat) ─────────────────────── */
.import-card--picking {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}
.import-count-picker { display: flex; flex-direction: column; gap: 8px; }
.import-pick-label { font-size: 12px; font-weight: 600; color: var(--ink-soft); letter-spacing: 0.05em; text-transform: uppercase; }
.import-pick-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.import-pick-btn { border: none; color: var(--card); font-family: var(--font-ui); font-size: 14px; font-weight: 600; padding: 8px 18px; border-radius: 20px; cursor: pointer; transition: opacity 0.15s; }
.import-pick-btn:hover { opacity: 0.85; }
.import-pick-cancel { border: none; background: transparent; color: var(--ink-soft); font-family: var(--font-ui); font-size: 13px; cursor: pointer; padding: 8px 4px; text-decoration: underline; }
.import-pick-cancel:hover { color: var(--ink); }

/* ── Source indicator (local / blob / bing) ──────────────────────────── */
.headword.src-local { color: var(--green); }  /* on this device */
.headword.src-blob  { color: var(--teal);  }  /* cloud cache */
.headword.src-bing  { color: var(--seal);  }  /* live from Bing */
