:root {
  --navy: #101a30;
  --slate: #333d55;
  --muted: #5b6478;
  --border: #d7dbe4;
  --bg: #ffffff;
  --surface: #ffffff;
  --card: #dcefff;
  --orange: #ff8800;
  --orange-shadow: #cc6d00;
  --green: #3fa302;
  --green-bg: #e2f7ce;
  --red: #e6362f;
  --red-bg: #ffe0de;
  --gold: #e0a600;
  --shadow-soft: 0 1px 2px rgba(16, 26, 48, 0.06);
  --track: #e9edf4;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

:root[data-theme="dark"] {
  --navy: #f3f5fa;
  --slate: #c9d0e0;
  --muted: #a3acc2;
  --border: #4c5c82;
  --bg: #0e1526;
  --surface: #1a2740;
  --card: #223a5e;
  --orange: #ff9f33;
  --orange-shadow: #b3670a;
  --green: #77d92e;
  --green-bg: #1d3413;
  --red: #ff7168;
  --red-bg: #3d1a18;
  --gold: #ffd75e;
  --track: #2c3a58;
  --shadow-soft: 0 1px 3px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--navy);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  transition: background-color .25s ease, color .25s ease;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 76px;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* --- Top bar --- */
.topbar {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.topbar .flag { font-size: 22px; }
.topbar .stats { margin-left: auto; display: flex; gap: 14px; align-items: center; font-weight: 800; }
.topbar .stat { display: flex; align-items: center; gap: 4px; }
.topbar .xp { color: var(--gold); }
.topbar .streak { color: var(--orange); }
.topbar .due { color: var(--red); font-size: 13px; background: var(--red-bg); padding: 3px 9px; border-radius: 999px; }
.theme-btn {
  width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  flex-shrink: 0;
}

/* --- Progress bar (session) --- */
.progress-track { height: 12px; border-radius: 999px; background: var(--track); overflow: hidden; flex: 1; }
.progress-fill { height: 100%; background: var(--green); border-radius: 999px; transition: width .4s ease; }
.session-bar { display: flex; align-items: center; gap: 14px; padding: 16px; }
.close-btn { color: var(--muted); font-size: 24px; line-height: 1; }

/* --- Tabs --- */
.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  max-width: 480px;
  margin: 0 auto;
  z-index: 20;
}
.tab {
  flex: 1;
  padding: 10px 0 12px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.tab.active { color: var(--orange); }
.tab .icon { font-size: 20px; }

/* --- Home header --- */
.home-header { padding: 18px 16px 4px; }
.home-title { font-size: 21px; font-weight: 800; margin: 0 0 2px; }
.home-sub { color: var(--muted); font-size: 14px; margin: 0; }

/* --- Big CTA card (review now) --- */
.cta-card {
  margin: 16px;
  border-radius: 20px;
  padding: 20px;
  background: linear-gradient(135deg, #1c2a4a, #223766);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 14px;
}
.cta-card .emoji { font-size: 34px; }
.cta-card h3 { margin: 0 0 2px; font-size: 17px; font-weight: 800; }
.cta-card p { margin: 0; font-size: 13px; opacity: .8; }
.cta-btn {
  width: 100%;
  margin-top: 14px;
  padding: 13px;
  border-radius: 14px;
  background: var(--orange);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 4px 0 var(--orange-shadow);
}
.cta-btn:active { transform: translateY(2px); box-shadow: none; }
.cta-btn.secondary { background: var(--surface); color: var(--navy); box-shadow: 0 4px 0 var(--border); border: 1px solid var(--border); }

/* --- Category grid (vocab) --- */
.section-label { padding: 0 16px; font-size: 13px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 8px; }
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 16px 16px; }
.cat-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cat-card .name { font-weight: 800; font-size: 14px; }
.cat-card .count { font-size: 12px; color: var(--muted); }
.cat-card .bar { height: 6px; border-radius: 999px; background: var(--track); overflow: hidden; margin-top: 4px; }
.cat-card .bar-fill { height: 100%; background: var(--green); }

/* --- Grammar list --- */
.grammar-list { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.grammar-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}
.grammar-card .badge {
  width: 38px; height: 38px; border-radius: 12px;
  background: var(--card); display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--navy); flex-shrink: 0; font-size: 14px;
}
.grammar-card .title { font-weight: 800; font-size: 15px; }
.grammar-card .status { margin-left: auto; font-size: 12px; color: var(--muted); }
.grammar-card.done .badge { background: var(--green-bg); color: var(--green); }

/* --- Flashcard (reveal) --- */
.card-title { padding: 6px 16px 0; font-size: 20px; font-weight: 800; line-height: 1.25; }
.flash {
  margin: 18px 16px;
  border-radius: 22px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  text-align: left;
  width: calc(100% - 32px);
}
.flash-top {
  background: var(--card);
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
}
.flash-body { background: var(--surface); padding: 18px; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.flash-th { font-size: 26px; font-weight: 800; }
.flash-ph { color: var(--muted); font-size: 15px; margin-top: 4px; }
.flash-fr { color: var(--muted); font-size: 16px; padding: 0 18px 18px; text-transform: capitalize; }
.speak-btn { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; font-size: 16px; }

/* --- Quiz --- */
.quiz-prompt {
  margin: 16px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface);
  padding: 16px 18px; display: flex; align-items: center; justify-content: space-between;
  font-size: 19px; text-transform: capitalize;
}
.quiz-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 16px; }
.quiz-opt {
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 20px 10px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}
.quiz-opt .th { font-weight: 800; font-size: 17px; }
.quiz-opt .ph { color: var(--muted); font-size: 13px; }
.quiz-opt.correct { border-color: var(--green); background: var(--green-bg); }
.quiz-opt.wrong { border-color: var(--red); background: var(--red-bg); }
.quiz-opt.dim { opacity: .5; }

.quiz-list { padding: 0 16px; display: flex; flex-direction: column; gap: 10px; }
.quiz-list .quiz-opt { flex-direction: row; justify-content: flex-start; padding: 14px 16px; }

/* --- Self-rating (spaced repetition) --- */
.rate-row { display: flex; gap: 10px; }
.rate-btn {
  flex: 1; padding: 14px 6px; border-radius: 14px; font-weight: 800; font-size: 13px;
  color: #fff; text-align: center;
}
.rate-hard { background: var(--red); }
.rate-good { background: var(--orange); }
.rate-easy { background: var(--green); }

/* --- Footer / CTA --- */
.footer { margin-top: auto; padding: 16px; }

.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 15;
  display: flex;
  flex-direction: column;
}
.rate-row.action-bar { flex-direction: row; gap: 10px; }

.btn-primary {
  width: 100%; padding: 16px; border-radius: 16px; background: var(--orange); color: #fff;
  font-weight: 800; font-size: 16px; box-shadow: 0 4px 0 var(--orange-shadow);
}
.btn-primary:active { transform: translateY(2px); box-shadow: none; }
.btn-primary:disabled { opacity: .35; box-shadow: none; }
.btn-ghost { width: 100%; padding: 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); font-weight: 800; color: var(--navy); margin-top: 10px; }

/* --- Grammar detail --- */
.explain { padding: 4px 18px 0; color: var(--slate); font-size: 15px; line-height: 1.55; }
.point-card { margin: 14px 16px; border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; background: var(--surface); }
.point-card + .point-card { margin-top: -6px; }
.point-th { font-size: 18px; font-weight: 800; }
.point-ph { color: var(--muted); font-size: 13px; margin-top: 2px; }
.point-fr { color: var(--slate); font-size: 14px; margin-top: 6px; }

/* --- Empty state --- */
.empty-state { text-align: center; padding: 60px 30px; color: var(--muted); }
.empty-state .emoji { font-size: 44px; margin-bottom: 12px; }

/* --- Complete screen --- */
.complete { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 60px 30px; flex: 1; }
.complete .emoji { font-size: 60px; margin-bottom: 10px; }
.complete h2 { margin: 0 0 4px; font-size: 22px; font-weight: 800; }
.complete p { color: var(--muted); margin: 0; }
.crown-row { display: flex; gap: 8px; margin: 22px 0; }

/* --- Theme toggle switch --- */
.theme-row {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-soft);
}
.theme-row .badge {
  width: 38px; height: 38px; border-radius: 12px;
  background: var(--card); display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--navy); flex-shrink: 0; font-size: 14px;
}
.theme-row .title { font-weight: 800; font-size: 15px; }
.switch { margin-left: auto; position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px;
  transition: background-color .2s ease; cursor: pointer;
}
.switch .slider::before {
  content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px;
  background: var(--surface); border-radius: 50%; transition: transform .2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch input:checked + .slider { background: var(--orange); }
.switch input:checked + .slider::before { transform: translateX(20px); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
