:root {
  --bg: #fff8f2;
  --card: #ffffff;
  --ink: #2c241c;
  --muted: #8a7a6c;
  --accent: #e87a4a;
  --accent-soft: #fde8dc;
  --ok: #3d9a6a;
  --border: #f0e4d8;
  --shadow: 0 8px 24px rgba(44, 36, 28, 0.08);
  --radius: 16px;
  --font: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
}
body {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 0 88px;
}

.app-header {
  padding: 20px 20px 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.app-header img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
}
.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}
.app-header p {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.tabs {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, 100%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 20;
}
.tabs button {
  border: none;
  background: transparent;
  padding: 10px 4px;
  font: inherit;
  color: var(--muted);
  border-radius: 12px;
  cursor: pointer;
}
.tabs button.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.panel { display: none; padding: 12px 20px 24px; }
.panel.active { display: block; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}
input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  background: #fff;
  color: var(--ink);
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 72px; resize: vertical; }

.row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn {
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary {
  background: var(--accent-soft);
  color: var(--accent);
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn.danger {
  background: #fde8e8;
  color: #c44;
}

.result {
  margin-top: 12px;
  padding: 12px;
  background: var(--accent-soft);
  border-radius: 12px;
  min-height: 48px;
}
.result .word { font-size: 1.15rem; font-weight: 700; }
.result .meaning { margin-top: 6px; color: var(--ink); }
.result .hint { margin-top: 6px; font-size: 0.85rem; color: var(--muted); }

.stats {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.stat {
  flex: 1;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 4px;
}
.stat strong { display: block; font-size: 1.2rem; color: var(--accent); }
.stat span { font-size: 0.75rem; color: var(--muted); }

.word-list { list-style: none; margin: 0; padding: 0; }
.word-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.word-item:last-child { border-bottom: none; }
.word-item .meta { flex: 1; min-width: 0; }
.word-item .w { font-weight: 700; }
.word-item .t { color: var(--muted); font-size: 0.9rem; margin-top: 2px; word-break: break-word; }
.word-item .actions { display: flex; gap: 4px; align-items: flex-start; }
.word-item .actions button {
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.75rem;
  cursor: pointer;
}

.flashcard {
  text-align: center;
  padding: 28px 16px;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.flashcard .front {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.flashcard .back {
  margin-top: 16px;
  font-size: 1.2rem;
  color: var(--accent);
}
.flashcard .empty { color: var(--muted); }

.search-box { margin-bottom: 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  background: rgba(44, 36, 28, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 50;
  max-width: 90%;
}
.toast.show { opacity: 1; }

.hidden { display: none !important; }

.section-title {
  margin: 0 0 8px;
  font-size: 1.05rem;
}
.sync-hint, .field-hint {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}
.field-hint { margin-top: 6px; margin-bottom: 10px; }
.sync-status {
  margin-top: 14px;
  padding: 12px;
  background: #f5f0ea;
  border-radius: 12px;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.5;
}
.sync-status.ok {
  background: #e8f6ee;
  color: var(--ok);
}
.tabs button { font-size: 0.85rem; padding: 10px 2px; }

/* LLM explanation card */
.result .meta-line {
  margin-top: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}
.result .phonetic { font-family: ui-monospace, Menlo, Consolas, monospace; }
.result .pos { font-weight: 600; color: var(--accent); }
.result .badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--border);
  font-weight: 600;
}
.result .examples {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}
.result .examples li {
  padding: 8px 0;
  border-top: 1px dashed var(--border);
}
.result .ex-en { font-size: 0.92rem; }
.result .ex-zh { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }
.result .extra {
  margin-top: 8px;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--ink);
}
.result .extra strong { color: var(--accent); margin-right: 4px; }
