:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 14px;
  --nav-height: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  font-size: 16px;
}

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 24px);
}

h1 { font-size: 1.35rem; margin: 8px 0 16px; }
h2 { font-size: 1.05rem; margin: 20px 0 10px; }
a { color: var(--primary); text-decoration: none; }

/* ---------- 底部導覽 ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  font-size: 0.68rem;
}
.nav-item.active { color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 1.25rem; line-height: 1; }

/* ---------- 通用元件 ---------- */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 52px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  text-align: center;
}
.btn:active { transform: scale(0.98); }
.btn.secondary { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }
.btn.success { background: var(--success); }
.btn.danger { background: var(--danger); }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: 0.9rem; width: auto; }
.btn:disabled { opacity: 0.5; }

.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-row .btn { flex: 1; }

.muted { color: var(--text-muted); font-size: 0.88rem; }
.center { text-align: center; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--border);
  color: var(--text-muted);
}
.badge.known { background: #dcfce7; color: var(--success); }
.badge.learning { background: #e0e7ff; color: var(--primary); }

/* ---------- 首頁 ---------- */
.hero-count { font-size: 2.4rem; font-weight: 800; line-height: 1.1; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
}
.stat .num { font-size: 1.4rem; font-weight: 700; }
.stat .lbl { font-size: 0.72rem; color: var(--text-muted); }

/* ---------- 單字卡 ---------- */
.deck-status { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

.flashcard {
  perspective: 1200px;
  height: 320px;
  cursor: pointer;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.45s;
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
}
.card-face.back { transform: rotateY(180deg); }
.card-word { font-size: 2rem; font-weight: 800; word-break: break-word; }
.card-pos { color: var(--text-muted); font-size: 1rem; }
.card-def { font-size: 1.6rem; font-weight: 700; }
.card-hint { position: absolute; bottom: 14px; color: var(--text-muted); font-size: 0.78rem; }
.card-level { position: absolute; top: 14px; right: 16px; }

.speak-btn {
  position: absolute;
  top: 10px; left: 12px;
  border: none;
  background: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 8px;
}

/* ---------- 測驗 ---------- */
.quiz-prompt { font-size: 1.5rem; font-weight: 800; text-align: center; padding: 24px 12px; word-break: break-word; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  min-height: 54px;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 1.05rem;
  text-align: left;
  cursor: pointer;
  word-break: break-word;
}
.choice.correct { border-color: var(--success); background: #dcfce7; }
.choice.wrong { border-color: var(--danger); background: #fee2e2; }
.choice:disabled { cursor: default; }

/* ---------- 單字表 ---------- */
.filter-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filter-bar input[type="search"] {
  flex: 1 1 140px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
}
.filter-bar select {
  min-height: 44px;
  padding: 8px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--surface);
}

.word-list { list-style: none; margin: 0; padding: 0; }
.word-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
}
.word-row input[type="checkbox"] { width: 22px; height: 22px; flex-shrink: 0; }
.word-main { flex: 1; min-width: 0; }
.word-en { font-weight: 700; }
.word-zh { color: var(--text-muted); font-size: 0.88rem; }

.pager { display: flex; justify-content: space-between; align-items: center; margin: 16px 0; }

.bulk-bar {
  position: fixed;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: min(92%, 520px);
  display: none;
  gap: 10px;
  background: var(--text);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius);
  align-items: center;
  z-index: 90;
}
.bulk-bar.show { display: flex; }

/* ---------- 進度 ---------- */
table.progress-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.progress-table th, .progress-table td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--border); }
.progress-table th:first-child, .progress-table td:first-child { text-align: left; }

.progress-bar { background: var(--border); border-radius: 999px; height: 10px; overflow: hidden; margin-top: 8px; }
.progress-bar > div { background: var(--primary); height: 100%; border-radius: 999px; }

/* ---------- 登入 ---------- */
.login-wrap { max-width: 360px; margin: 18vh auto 0; padding: 0 20px; }
.login-wrap input[type="password"] {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  font-size: 1.1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
}
.error { color: var(--danger); font-size: 0.9rem; margin: 8px 0; }

/* ---------- 完成畫面 ---------- */
.done-screen { text-align: center; padding: 48px 16px; }
.done-screen .emoji { font-size: 3.4rem; }
