*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.6;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(80px + var(--safe-bottom));
}

header {
  text-align: center;
  padding: 20px 0 16px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, #60a5fa, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

header p {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 4px;
}

.account-bar-wrap {
  display: flex;
  justify-content: center;
  margin-top: 12px;
  position: relative;
}

.account-bar { position: relative; }

.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 24px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
}

.account-avatar, .profile-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.account-level,
.account-lib {
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--surface2);
  padding: 2px 8px;
  border-radius: 10px;
}

.account-lib {
  max-width: 8em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-arrow { font-size: 0.7rem; color: var(--muted); }

.account-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  z-index: 100;
  overflow: hidden;
}

.account-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  border-bottom: 1px solid var(--surface2);
}
.account-item small { color: var(--muted); font-size: 0.75rem; margin-top: 2px; }
.account-item:hover { background: var(--surface2); }
.account-item.active { background: #1e3a5f; }
.account-item.manage { color: var(--primary); font-weight: 600; }

.accounts-section,
.library-section,
.backup-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 24px;
}
.profile-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.profile-card {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px;
  border: 1px solid transparent;
}
.profile-card.active { border-color: var(--primary); }
.profile-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.profile-card-head small { display: block; color: var(--muted); font-size: 0.75rem; }
.profile-lib-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.875rem;
}
.profile-lib-row span { color: var(--muted); flex-shrink: 0; }
.profile-lib-row select,
.profile-lib-select {
  flex: 1;
  padding: 8px 10px;
  background: var(--surface2);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.875rem;
}
.profile-card-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.current-tag { font-size: 0.75rem; color: var(--success); }
.add-profile-box {
  border-top: 1px solid var(--surface2);
  padding-top: 16px;
}
.add-profile-box h4 { margin-bottom: 12px; font-size: 0.95rem; }
.add-profile-box select {
  width: 100%;
  padding: 10px;
  background: var(--surface2);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
}

.stats-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
}

.stat .num {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}

.stat .label {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 2px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px;
}

.tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab.active {
  background: var(--primary);
  color: white;
}

.card-area {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  user-select: none;
}

.session-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.state-tag {
  font-size: 0.7rem;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 600;
}

.state-new { background: #1e3a5f; color: #60a5fa; }
.state-learning { background: #422006; color: #fbbf24; }
.state-review { background: #14532d; color: #4ade80; }
.state-relearning { background: #450a0a; color: #fca5a5; }

.card-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 12px;
  text-align: center;
}

.word-display {
  text-align: center;
}

.word-display .word {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.word-display .phonetic {
  color: var(--primary);
  font-size: 1.125rem;
  margin-top: 8px;
}

.word-display .pos {
  display: inline-block;
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 20px;
  margin-top: 8px;
}

.word-display .freq {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 6px;
}

.detail {
  margin-top: 20px;
  display: none;
}

.detail.show {
  display: block;
}

.detail section {
  margin-bottom: 16px;
}

.detail h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 6px;
}

.detail .zh {
  font-size: 1.125rem;
  color: #fbbf24;
}

.detail .en {
  font-size: 0.95rem;
  color: var(--text);
}

.detail .examples li {
  font-size: 0.9rem;
  color: var(--muted);
  margin-left: 18px;
  margin-bottom: 6px;
  font-style: italic;
}

.study-bar {
  margin-top: 16px;
}

.btn-show {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-show kbd,
.key-hint kbd {
  background: rgba(255,255,255,0.2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  margin-left: 6px;
}

.rating-bar {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 16px;
}

.rating-bar.show {
  display: grid;
}

.rate-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 4px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  color: white;
  transition: opacity 0.15s;
}

.rate-btn span { font-size: 0.8rem; }
.rate-btn small { font-size: 0.65rem; opacity: 0.85; font-weight: 400; }

.rate-btn:active { opacity: 0.8; }
.rate-btn.again { background: var(--danger); }
.rate-btn.hard { background: var(--warning); }
.rate-btn.good { background: var(--success); }
.rate-btn.easy { background: var(--primary); }

.key-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.7rem;
  margin-top: 12px;
}

.btn-primary, .btn-secondary, .btn-danger {
  width: 100%;
  padding: 12px;
  margin-top: 8px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  color: white;
}

.btn-primary { background: var(--primary); }
.btn-secondary { background: var(--surface2); }
.btn-danger { background: var(--danger); margin-top: 16px; }

.stats-panel .big-num {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--primary);
}

.deck-stats {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px 0;
  margin: 20px 0;
}

.deck-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--surface2);
  font-size: 0.9rem;
}

.deck-row:last-child { border-bottom: none; }
.deck-row span { color: var(--muted); }

.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 10px;
}

.upcoming-list {
  background: var(--surface);
  border-radius: var(--radius);
}

.upcoming-item {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--surface2);
  font-size: 0.9rem;
}

.upcoming-item:last-child { border-bottom: none; }
.upcoming-item span:last-child { color: var(--muted); font-size: 0.8rem; }

.settings-desc {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 16px;
  line-height: 1.5;
}

.list-more, .muted { color: var(--muted); text-align: center; padding: 12px; font-size: 0.85rem; }

.status.review { background: #14532d; color: #4ade80; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

.empty-state h2 {
  color: var(--text);
  margin-bottom: 8px;
}

.list-view .word-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
}

.list-view .word-item .rank {
  color: var(--muted);
  font-size: 0.8rem;
  min-width: 28px;
}

.list-view .word-item .w {
  font-weight: 600;
  flex: 1;
}

.list-view .word-item .status {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
}

.status.new { background: #1e3a5f; color: #60a5fa; }
.status.learning { background: #422006; color: #fbbf24; }
.status.mastered { background: #14532d; color: #4ade80; }

.search-box {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 16px;
  outline: none;
}

.search-box:focus {
  border-color: var(--primary);
}

.settings-panel label {
  display: block;
  margin-bottom: 16px;
}

.settings-panel span {
  display: block;
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.settings-panel input {
  width: 100%;
  padding: 10px;
  background: var(--surface2);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
}


.progress-ring-wrap {
  text-align: center;
  margin: 20px 0;
}

.progress-label {
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: 8px;
}

.tier-badge {
  display: inline-block;
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 6px;
}

.tier-spoken { background: #1e3a5f; color: #93c5fd; }
.tier-core { background: #1e3a5f; color: #93c5fd; }
.tier-daily { background: #064e3b; color: #6ee7b7; }
.tier-email { background: #4a1d96; color: #e9d5ff; }
.tier-work { background: #3b0764; color: #d8b4fe; }
.tier-fluent { background: #431407; color: #fdba74; }
.tier-news { background: #3b0764; color: #d8b4fe; }
.tier-advanced { background: #431407; color: #fdba74; }

.milestones {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 0.85rem;
}

.milestone-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--surface2);
}

.milestone-row:last-child { border-bottom: none; }
.milestone-row.done strong { color: var(--success); }

/* 批量学习 */
.study-home { display: flex; flex-direction: column; gap: 12px; }
.home-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
}
.home-card.highlight { border: 1px solid var(--primary); }
.home-card h3 { margin-bottom: 8px; font-size: 1.1rem; }
.home-card p { color: var(--muted); font-size: 0.9rem; margin-bottom: 12px; }

.batch-header { margin-bottom: 16px; }
.batch-header h3 { font-size: 1.1rem; margin-bottom: 6px; }
.batch-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.pick-list { max-height: 50vh; overflow-y: auto; margin-bottom: 80px; }
.pick-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; background: var(--surface);
  border-radius: 8px; margin-bottom: 6px; cursor: pointer;
}
.pick-item input { width: 18px; height: 18px; }
.pick-item .zh-preview { color: var(--muted); font-size: 0.85rem; margin-left: auto; }

.batch-word-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 80px; }
.word-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
}
.word-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.word-card-head .w { font-size: 1.25rem; }
.word-card-body label { display: block; font-size: 0.7rem; color: var(--muted); margin-bottom: 2px; }
.word-card-body > div { margin-bottom: 10px; font-size: 0.9rem; }
.row-zh span { color: #fbbf24; }
.row-en-zh span { color: #a5b4fc; }
.ex-pair { margin-top: 6px; padding-left: 8px; border-left: 2px solid var(--surface2); }
.ex-en { color: var(--text); }
.ex-zh { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }

.btn-sticky {
  position: fixed; bottom: calc(16px + var(--safe-bottom));
  left: 16px; right: 16px; max-width: 688px; margin: 0 auto;
  z-index: 10;
}
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-sm { padding: 8px 12px; font-size: 0.8rem; width: auto; }

.quiz-list { margin-bottom: 80px; }
.quiz-row {
  background: var(--surface); border-radius: var(--radius);
  padding: 12px; margin-bottom: 8px;
}
.quiz-word { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.quiz-btns { display: flex; gap: 8px; margin-top: 10px; }
.quiz-btn {
  flex: 1; padding: 10px; border: none; border-radius: 8px;
  font-weight: 600; cursor: pointer; background: var(--surface2); color: var(--muted);
}
.quiz-btn.active.good { background: var(--success); color: white; }
.quiz-btn.active.bad { background: var(--danger); color: white; }
.hidden { display: none !important; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 0.8rem; }

/* 发音与跟读 */
.audio-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--surface2);
}
.btn-audio {
  padding: 8px 14px; border: none; border-radius: 8px;
  background: var(--primary); color: white; font-size: 0.85rem; cursor: pointer;
}
.btn-audio.record { background: #7c3aed; }
.btn-audio:disabled { opacity: 0.6; }
.btn-speak-ex {
  background: none; border: none; cursor: pointer; font-size: 0.85rem; padding: 0 4px;
}
.score-badge {
  font-size: 0.8rem; padding: 4px 10px; border-radius: 12px; font-weight: 600;
}
.score-badge.s-good { background: #14532d; color: #4ade80; }
.score-badge.s-mid { background: #422006; color: #fbbf24; }
.score-badge.s-low { background: #450a0a; color: #fca5a5; }

/* 查词 */
.lookup-panel { padding-bottom: 24px; }
.lookup-results { margin-bottom: 12px; }
.lookup-hit {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px; margin-bottom: 6px; border: none; border-radius: 8px;
  background: var(--surface); color: var(--text); text-align: left; cursor: pointer;
}
.lookup-hit strong { min-width: 80px; }
.lookup-detail { margin-bottom: 20px; }
.lookup-detail:not(.show) { display: none; }
.history-header {
  display: flex; justify-content: space-between; align-items: center;
  margin: 20px 0 10px;
}
.history-header h3 { font-size: 1rem; }
.history-item {
  background: var(--surface); border-radius: var(--radius);
  padding: 12px; margin-bottom: 8px;
}
.history-main { margin-bottom: 8px; }
.history-meta { font-size: 0.75rem; color: var(--muted); margin-left: 8px; }
.history-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-mini {
  padding: 6px 10px; border: none; border-radius: 6px;
  background: var(--surface2); color: var(--text); font-size: 0.75rem; cursor: pointer;
}
.warn { color: var(--warning); font-size: 0.85rem; margin-bottom: 10px; }

.pick-progress {
  margin: 12px 0;
  text-align: center;
}
.pick-progress-bar {
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}
.pick-progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s;
}
.pick-section { margin-bottom: 16px; }
.pick-section h4 {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}
.pick-learned-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 0.8rem;
  background: #1e3a5f;
  color: #93c5fd;
}
.chip-x {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
}
.pick-item-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.pick-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.pick-btns { display: flex; gap: 8px; }
.btn-pick {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-pick.learn { background: var(--primary); color: white; }
.btn-pick.learn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-pick.known { background: var(--surface2); color: var(--muted); }
.en-text { color: var(--text); line-height: 1.5; }
.en-zh-text { color: #a5b4fc; font-size: 0.85rem; margin-top: 4px; }

.tabs { overflow-x: auto; flex-wrap: nowrap; }
.tab { white-space: nowrap; font-size: 0.8rem; padding: 10px 8px; }

@media (max-width: 480px) {
  .stats-bar {
    grid-template-columns: repeat(3, 1fr);
  }
  .stats-bar .stat:nth-child(4),
  .stats-bar .stat:nth-child(5) {
    grid-column: span 1;
  }
  .word-display .word {
    font-size: 1.75rem;
  }
  .rate-btn small { font-size: 0.6rem; }
  .key-hint { display: none; }
}

@media (min-width: 768px) {
  #app {
    padding: 24px;
  }
  header h1 {
    font-size: 1.75rem;
  }
}

.login-gate[hidden],
#app[hidden] {
  display: none !important;
}

.login-gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 32px 24px;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  text-align: center;
}

.login-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.login-card h2 {
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.login-hint {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 20px;
}

.login-label {
  display: block;
  text-align: left;
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.login-card input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--surface2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 8px;
}

.login-card input[type="password"]:focus {
  outline: none;
  border-color: var(--primary);
}

.login-error {
  min-height: 1.25rem;
  color: var(--danger);
  font-size: 0.875rem;
  margin-bottom: 8px;
}

.login-submit:disabled {
  opacity: 0.7;
  cursor: wait;
}

.boot-loading {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}

.backup-section .btn-primary,
.backup-section .btn-secondary {
  width: 100%;
  margin-bottom: 8px;
}
.muted-hint { margin-top: 12px; font-size: 0.8rem !important; }
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.study-log-list.compact .study-log-words { display: none; }
.study-log-item {
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: 8px;
  padding: 12px;
}
.study-log-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.875rem;
}
.study-log-head strong { color: var(--text); }
.log-tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
}
.log-lib {
  font-size: 0.75rem;
  color: var(--muted);
}
.study-log-summary { font-size: 0.875rem; color: var(--text); margin-bottom: 4px; }
.study-log-words { font-size: 0.8rem; margin-bottom: 8px; }
.btn-repeat-log { margin-top: 4px; }
