:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --bg: #ffffff;
  --surface: #f5f7fb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --correct: #16a34a;
  --wrong: #dc2626;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; }

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#topbar {
  background: var(--primary);
  color: white;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 10;
}
#topbar h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 600; }
#topbar #subtitle { font-size: 12px; opacity: .85; }
#back-btn {
  background: transparent; color: white; border: none;
  font-size: 28px; line-height: 1; padding: 0 4px; min-width: 32px;
}

#main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* Lists */
.list { list-style: none; padding: 0; margin: 0; }
.list-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: white;
  display: flex; align-items: center; gap: 12px;
  cursor: pointer;
}
.list-item:active { background: var(--surface); }
.list-item .name { flex: 1; }
.list-item .meta { color: var(--text-muted); font-size: 12px; }
.list-item .arrow { color: #c0c4cd; font-size: 18px; }

.section-title {
  padding: 16px 16px 8px;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--surface);
  text-transform: none;
  letter-spacing: .02em;
}

/* Card mode */
.card-screen {
  display: flex; flex-direction: column;
  padding: 16px; gap: 16px;
  min-height: 100%;
}
.card {
  background: white;
  border-radius: 16px;
  padding: 32px 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
  text-align: center;
  flex: 1;
  display: flex; flex-direction: column; justify-content: center;
  min-height: 280px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .08s ease;
}
.card:active { transform: scale(.98); background: #fafbfc; }
.card .word {
  font-size: 44px; font-weight: 700; color: var(--text);
  word-break: break-word;
}
.card .phonetic { color: var(--text-muted); font-size: 18px; margin-top: 8px; }
.card .tran {
  margin-top: 18px; color: var(--text); font-size: 16px;
  line-height: 1.6; padding: 0 4px;
}
.card .tran-hidden { color: #c0c4cd; font-size: 14px; }

.card-controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 8px;
}
.btn {
  background: white;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 8px;
  border-radius: 12px;
  font-size: 14px;
}
.btn:active { background: var(--surface); }
.btn-primary {
  background: var(--primary); color: white; border-color: var(--primary);
}
.btn-primary:active { background: var(--primary-dark); }

.progress {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

/* Spell mode */
.spell-screen { padding: 16px; display: flex; flex-direction: column; gap: 16px; min-height: 100%; }
.spell-tran {
  background: white; border-radius: 12px; padding: 16px;
  font-size: 16px; text-align: center; line-height: 1.6;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.spell-input {
  width: 100%;
  padding: 16px;
  font-size: 22px;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: white;
  -webkit-appearance: none;
  outline: none;
}
.spell-input:focus { border-color: var(--primary); }
.spell-feedback {
  text-align: center; font-size: 28px; font-weight: 700;
  min-height: 40px;
}
.spell-feedback.ok { color: var(--correct); }
.spell-feedback.bad { color: var(--wrong); }
.spell-stats {
  text-align: center; color: var(--text-muted); font-size: 13px;
}

/* Bottom tabs (only in study mode) */
#bottom-tabs {
  display: flex;
  border-top: 1px solid var(--border);
  background: white;
  padding-bottom: var(--safe-bottom);
}
#bottom-tabs .tab {
  flex: 1;
  padding: 12px;
  background: transparent;
  border: none;
  font-size: 14px;
  color: var(--text-muted);
}
#bottom-tabs .tab.active { color: var(--primary); font-weight: 600; }

/* Empty state */
.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-muted);
}

/* ---------- AI 例句 ---------- */
.ai-trigger {
  align-self: stretch;
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  color: white;
  border: none;
  font-weight: 600;
}
.ai-trigger:active { opacity: .85; }

.ai-box {
  background: white;
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 2px 10px rgba(99, 102, 241, .12);
  border: 1px solid #e0e7ff;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-loading, .ai-error {
  text-align: center;
  color: #6366f1;
  font-size: 14px;
  padding: 8px 0;
}
.ai-error { color: var(--wrong); }
.ai-error .btn-mini { margin-top: 8px; }

.ai-sent {
  padding: 10px 0;
  border-bottom: 1px dashed #e5e7eb;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-sent:last-child { border-bottom: none; }
.ai-en {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  font-weight: 500;
}
.ai-en > span { flex: 1; }
.ai-zh {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  padding-left: 38px;
}

.ai-play {
  background: #ede9fe;
  color: #6366f1;
  border: none;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 14px;
  flex-shrink: 0;
  min-width: 34px;
}
.ai-play:active { background: #ddd6fe; }

.btn-mini {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text);
}
