:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #18181b;
  --muted: #64748b;
  --border: #e4e7ef;
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --amber-bg: #fffbeb;
  --amber-border: #fcd34d;
  --amber-text: #b45309;
  --green-bg: #ecfdf5;
  --green-border: #6ee7b7;
  --green-text: #047857;
  --red-bg: #fef2f2;
  --red-text: #dc2626;
  --prefix-bg: #dbeafe;
  --prefix-text: #1d4ed8;
  --root-bg: #fef3c7;
  --root-text: #b45309;
  --suffix-bg: #d1fae5;
  --suffix-text: #047857;
  --shadow: 0 4px 18px rgba(15, 23, 42, 0.05);
  --radius: 16px;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

/* Auth Screen */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: 22px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-logo {
  width: 64px;
  height: 64px;
  margin-bottom: 10px;
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.auth-card input {
  width: 100%;
  padding: 13px 16px;
  font-size: 17px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  margin: 18px 0 12px;
  text-align: center;
  letter-spacing: 3px;
  outline: none;
}

.auth-card input:focus {
  border-color: var(--primary);
}

/* App Shell */
.app-shell {
  max-width: 680px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(245, 247, 251, 0.88);
  backdrop-filter: blur(12px);
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(228, 231, 239, 0.7);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.icon-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
}

.main-content {
  flex: 1;
  padding: 16px 16px calc(88px + env(safe-area-inset-bottom));
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* Cards & Reminders */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 14px;
}

.reminder-banner {
  border-radius: 18px;
  padding: 20px;
  margin-bottom: 16px;
}

.reminder-due {
  background: linear-gradient(135deg, #eef2ff 0%, #fffbeb 100%);
  border: 1.5px solid #c7d2fe;
}

.reminder-done {
  background: var(--green-bg);
  border: 1.5px solid var(--green-border);
}

.reminder-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.reminder-desc {
  font-size: 14px;
  color: #475569;
  margin: 0 0 14px;
}

.root-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.root-tag {
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid #cbd5e1;
  padding: 3px 9px;
  border-radius: 999px;
  color: #334155;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-outline {
  background: var(--primary-soft);
  color: var(--primary);
}

.btn-block {
  width: 100%;
  display: block;
}

.text-btn {
  background: none;
  border: none;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  padding: 6px 4px;
}

/* Stats Grid & Ladder */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 10px;
  text-align: center;
}

.stat-val {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
}

.stat-lbl {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ladder-bars {
  display: grid;
  gap: 10px;
}

.ladder-row {
  display: grid;
  grid-template-columns: 92px 1fr 42px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.bar-bg {
  height: 9px;
  background: #edf0f7;
  border-radius: 99px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 99px;
}

/* 7-Day Forecast */
.forecast-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  align-items: end;
  padding-top: 8px;
}

.forecast-col {
  text-align: center;
}

.forecast-bar-wrap {
  height: 64px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.forecast-bar {
  width: 20px;
  min-height: 4px;
  background: #c7d2fe;
  border-radius: 6px 6px 2px 2px;
}

.forecast-col.today .forecast-bar {
  background: var(--primary);
}

.forecast-cnt {
  font-size: 12px;
  font-weight: 700;
  color: #334155;
  margin-bottom: 4px;
}

.forecast-day {
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
}

/* Root List */
.root-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.root-code {
  font-size: 17px;
  font-weight: 800;
  color: var(--primary);
}

.root-meaning {
  font-size: 14px;
  font-weight: 600;
  margin-left: 6px;
}

.root-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* Morphological Breakdown Chips */
.morph-formula {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 10px 0;
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 700;
}

.chip small {
  font-weight: 500;
  font-size: 12px;
  opacity: 0.9;
}

.chip-prefix {
  background: var(--prefix-bg);
  color: var(--prefix-text);
}

.chip-root {
  background: var(--root-bg);
  color: var(--root-text);
}

.chip-suffix {
  background: var(--suffix-bg);
  color: var(--suffix-text);
}

.plus-sign {
  color: #94a3b8;
  font-weight: 700;
  font-size: 13px;
}

.bridge-box {
  background: #f8fafc;
  border-left: 3px solid var(--primary);
  padding: 8px 12px;
  border-radius: 0 10px 10px 0;
  font-size: 13.5px;
  color: #334155;
  margin: 8px 0;
}

.example-box {
  background: #fafafa;
  border-radius: 10px;
  padding: 10px 12px;
  margin-top: 8px;
  font-size: 14px;
}

.example-en {
  font-weight: 500;
  color: #0f172a;
}

.example-en mark {
  background: #fef08a;
  padding: 0 3px;
  border-radius: 4px;
}

.example-zh {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
}

.word-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.word-title {
  font-size: 20px;
  font-weight: 800;
}

.phonetic {
  font-size: 13px;
  color: var(--muted);
  margin-left: 6px;
}

.speak-btn {
  background: #f1f5f9;
  border: none;
  border-radius: 8px;
  padding: 4px 9px;
  font-size: 13px;
  cursor: pointer;
}

/* Bottom Tabbar */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 6px 12px calc(8px + env(safe-area-inset-bottom));
}

.tab-item {
  position: relative;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 18px;
  cursor: pointer;
}

.tab-item.active {
  color: var(--primary);
}

.tab-icon {
  font-size: 19px;
}

.badge {
  position: absolute;
  top: 0;
  right: 8px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 99px;
}

/* Fullscreen Overlays (Review & Root Detail) */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.overlay-header {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.progress-label {
  font-size: 14px;
  font-weight: 700;
  color: #334155;
}

.stage-pill {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 99px;
  background: var(--primary-soft);
  color: var(--primary);
}

.progress-track {
  max-width: 680px;
  width: calc(100% - 32px);
  margin: 0 auto 10px;
  height: 5px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.25s ease;
}

.review-body {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.overlay-scroll {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px calc(32px + env(safe-area-inset-bottom));
}

.flashcard {
  background: var(--card);
  border-radius: 22px;
  padding: 24px 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.flash-word {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.5px;
  text-align: center;
  margin: 8px 0 4px;
}

.flash-phonetic {
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 18px;
}

.answer-meaning {
  font-size: 21px;
  font-weight: 800;
  color: var(--primary);
  text-align: center;
  margin: 14px 0;
}

.siblings-box {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.siblings-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

.sibling-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sibling-pill {
  font-size: 12px;
  background: #f1f5f9;
  padding: 4px 9px;
  border-radius: 8px;
  color: #334155;
}

.rating-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.rate-btn {
  border: none;
  border-radius: 14px;
  padding: 12px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-weight: 700;
  font-size: 15px;
}

.rate-btn small {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.85;
}

.rate-forgot {
  background: #fee2e2;
  color: #b91c1c;
}

.rate-hard {
  background: #fef3c7;
  color: #b45309;
}

.rate-good {
  background: #d1fae5;
  color: #047857;
}

/* Search & Filter */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.search-bar input {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  background: var(--card);
  outline: none;
}

.filter-pills {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
}

.filter-pill {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 99px;
  padding: 5px 13px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.filter-pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Modal & Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-radius: 18px;
  padding: 20px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h3 {
  margin: 0;
  font-size: 17px;
}

.modal-card textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  margin: 10px 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

.error-text {
  color: var(--red-text);
  font-size: 13px;
  margin-top: 10px;
}

.toast {
  position: fixed;
  bottom: calc(82px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  background: #1e293b;
  color: #fff;
  padding: 9px 18px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
