:root {
  --red: #c0392b;
  --red-light: #e74c3c;
  --red-bg: #fdf2f2;
  --gold: #d4a017;
  --text: #1a1a1a;
  --muted: #666;
  --border: #e0e0e0;
  --bg: #fafafa;
  --white: #fff;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --tab-h: 60px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--red); color: #fff; width: 100%; }
.btn-primary:hover { opacity: .9; }
.btn-ghost { background: transparent; color: var(--red); border: 1.5px solid var(--red); }
.btn-icon { padding: 10px; border-radius: 50%; background: var(--red-bg); color: var(--red); font-size: 18px; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Form ── */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  background: var(--white);
  transition: border-color .2s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--red);
}
textarea { resize: vertical; min-height: 80px; }

/* ── Cards ── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ── Auth page ── */
.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(135deg, #fff 0%, #fdf2f2 100%);
}
.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}
.auth-logo .char {
  font-size: 64px;
  line-height: 1;
  color: var(--red);
}
.auth-logo h1 { font-size: 22px; margin-top: 8px; color: var(--text); }
.auth-logo p { font-size: 14px; color: var(--muted); margin-top: 4px; }
.auth-box {
  width: 100%;
  max-width: 420px;
  background: var(--white);
  border-radius: 20px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.1);
  padding: 28px 24px;
}
.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 24px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition: all .2s;
}
.auth-tab.active { background: var(--white); color: var(--red); box-shadow: var(--shadow); }
.auth-form { display: none; }
.auth-form.active { display: block; }
.error-msg { color: var(--red); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* ── App layout ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 680px;
  margin: 0 auto;
  position: relative;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--red);
  color: #fff;
  flex-shrink: 0;
}
.topbar-title { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.topbar-user { font-size: 13px; opacity: .85; display: flex; align-items: center; gap: 8px; }
.topbar-user button {
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
}

/* Tab bar */
.tabbar {
  display: flex;
  background: var(--white);
  border-top: 1px solid var(--border);
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 680px;
  height: var(--tab-h);
  z-index: 100;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  transition: color .2s;
  padding: 4px 0;
}
.tab-btn .icon { font-size: 22px; }
.tab-btn.active { color: var(--red); }

/* Main content area */
.main-content {
  flex: 1;
  overflow: hidden;
  padding-bottom: var(--tab-h);
}
.tab-panel { display: none; height: 100%; flex-direction: column; overflow: hidden; }
.tab-panel.active { display: flex; }

/* ── CHAT TAB ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}
.msg {
  max-width: 82%;
  line-height: 1.55;
  font-size: 15px;
}
.msg-user {
  align-self: flex-end;
  background: var(--red);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 10px 14px;
}
.msg-assistant {
  align-self: flex-start;
  background: var(--white);
  border-radius: 18px 18px 18px 4px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
}
.msg-assistant .pinyin { color: var(--red); font-size: 13px; font-style: italic; }
.msg-time { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }
.typing-indicator {
  display: none;
  align-self: flex-start;
  background: var(--white);
  border-radius: 18px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.typing-dots { display: flex; gap: 4px; }
.typing-dots span {
  width: 8px; height: 8px;
  background: var(--muted);
  border-radius: 50%;
  animation: bounce .8s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--white);
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
.chat-input-bar textarea {
  flex: 1;
  border-radius: 20px;
  padding: 10px 14px;
  min-height: 42px;
  max-height: 120px;
  resize: none;
  font-size: 15px;
  line-height: 1.4;
}
.send-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  border: none;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s;
}
.send-btn:disabled { opacity: .5; }
.chat-actions {
  display: flex;
  justify-content: flex-end;
  padding: 6px 16px 0;
}
.chat-actions button { font-size: 12px; color: var(--muted); background: none; border: none; cursor: pointer; }

/* ── DICT TAB ── */
.dict-panel { padding: 16px; overflow-y: auto; }
.dict-search {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.dict-search input { flex: 1; border-radius: 20px; padding: 10px 16px; }
.dict-result {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: none;
}
.dict-result.show { display: block; }
.dict-hanzi { font-size: 42px; font-weight: 700; color: var(--red); }
.dict-pinyin { font-size: 16px; color: var(--gold); margin: 4px 0 8px; }
.dict-type { display: inline-block; background: var(--red-bg); color: var(--red); font-size: 12px; padding: 2px 10px; border-radius: 20px; margin-bottom: 8px; }
.dict-meaning { font-size: 17px; margin-bottom: 16px; }
.dict-examples { border-top: 1px solid var(--border); padding-top: 14px; }
.dict-examples h4 { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.example-item { margin-bottom: 12px; }
.example-zh { font-size: 16px; font-weight: 600; }
.example-pinyin { font-size: 13px; color: var(--gold); }
.example-vi { font-size: 14px; color: var(--muted); }
.dict-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.tts-btn { font-size: 20px; background: none; border: none; cursor: pointer; color: var(--red); }

/* ── TRANSLATE section ── */
.translate-box { margin-top: 16px; }
.translate-box .dir-toggle {
  display: flex; gap: 8px; margin-bottom: 10px;
}
.dir-toggle button {
  flex: 1; padding: 8px; font-size: 13px; border-radius: 20px; border: 1.5px solid var(--border); background: var(--white); cursor: pointer; font-family: inherit;
}
.dir-toggle button.active { border-color: var(--red); color: var(--red); }
.translate-output {
  background: var(--red-bg);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 16px;
  min-height: 50px;
  margin-top: 8px;
  line-height: 1.6;
}

/* ── NOTEBOOK TAB ── */
.notebook-panel { overflow-y: auto; padding: 16px; }
.notebook-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.notebook-header h2 { font-size: 18px; }
.word-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.word-main { flex: 1; }
.word-term { font-size: 22px; font-weight: 700; color: var(--red); }
.word-pinyin { font-size: 13px; color: var(--gold); }
.word-meaning { font-size: 14px; color: var(--muted); }
.word-status {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.status-seen { background: #f0f0f0; color: var(--muted); }
.status-learning { background: #fff3cd; color: #856404; }
.status-known { background: #d4edda; color: #155724; }
.status-error { background: #f8d7da; color: #721c24; }
.word-del { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px; }

/* ── SETTINGS TAB ── */
.settings-panel { overflow-y: auto; padding: 16px; }
.settings-panel h2 { font-size: 18px; margin-bottom: 20px; }
.settings-section { margin-bottom: 24px; }
.settings-section h3 { font-size: 14px; color: var(--muted); margin-bottom: 12px; text-transform: uppercase; letter-spacing: .5px; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(var(--tab-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #333;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  opacity: 0;
  transition: all .3s;
  pointer-events: none;
  z-index: 200;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: #27ae60; }
.toast.error { background: var(--red); }

/* ── Loading ── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Markdown-ish in chat ── */
.msg-assistant strong { font-weight: 700; }
.msg-assistant em { font-style: italic; color: var(--gold); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.empty-state .big-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; line-height: 1.6; }

@media (min-width: 600px) {
  .auth-box { padding: 36px 32px; }
}
