:root {
  --green: #0a7d4b;
  --green-600: #0a7d4b;
  --green-700: #086840;
  --red: #c42b2b;
  --yellow: #f5c518;
  --bg: #f2f3f5;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #1a1c1e;
  --text-dim: #6b7280;
  --border: #e3e5e8;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.06);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --accent: var(--green);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121316;
    --surface: #1d1f23;
    --surface-2: #26282d;
    --text: #f2f3f5;
    --text-dim: #9aa0a8;
    --border: #2f3237;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.35);
    --green: #22c37e;
    --accent: #22c37e;
  }
}

:root[data-theme="dark"] {
  --bg: #121316;
  --surface: #1d1f23;
  --surface-2: #26282d;
  --text: #f2f3f5;
  --text-dim: #9aa0a8;
  --border: #2f3237;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.35);
  --green: #22c37e;
  --accent: #22c37e;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  padding: calc(var(--safe-top) + 8px) 16px calc(var(--safe-bottom) + 28px);
}

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

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 18px;
  min-height: 44px;
}
.topbar h1 {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}
.topbar .subtitle {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
}
.back-btn {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px 8px 0;
  margin-left: -4px;
}
.icon-btn {
  margin-left: auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* ---------- Home: stat row ---------- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat .num {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.stat .num.due { color: var(--accent); }
.stat .lbl {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---------- Big action buttons ---------- */
.cta {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  padding: 18px 20px;
  font-size: 17px;
  font-weight: 700;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  transition: transform 0.08s ease, filter 0.15s;
}
.cta:active { transform: scale(0.98); }
.cta.secondary {
  background: var(--surface);
  color: var(--text);
}
.cta .big-emoji { font-size: 24px; }
.cta .cta-text { text-align: left; flex: 1; }
.cta .cta-sub {
  display: block;
  font-size: 12px;
  font-weight: 500;
  opacity: 0.85;
  margin-top: 2px;
}
.cta .chev { font-size: 20px; opacity: 0.6; }
.cta[disabled] { opacity: 0.5; filter: grayscale(0.4); }
.cta .badge {
  background: rgba(255,255,255,0.28);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 13px;
  font-weight: 800;
}
.cta.secondary .badge { background: var(--accent); color: #fff; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 22px 4px 10px;
}

/* ---------- Deck list ---------- */
.deck {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  text-align: left;
  transition: transform 0.08s ease;
}
.deck:active { transform: scale(0.99); }
.deck .deck-emoji {
  font-size: 26px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border-radius: 12px;
  flex-shrink: 0;
}
.deck .deck-body { flex: 1; min-width: 0; }
.deck .deck-name { font-weight: 700; font-size: 16px; }
.deck .deck-pt { font-size: 13px; color: var(--text-dim); }
.deck .deck-right { text-align: right; flex-shrink: 0; }
.deck .deck-count { font-size: 13px; color: var(--text-dim); font-weight: 600; }
.progress-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  margin-top: 8px;
  overflow: hidden;
}
.progress-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ---------- Flashcard ---------- */
.card-stage {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 220px);
}
.session-progress {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
  margin-bottom: 6px;
}
.session-progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}
.session-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 18px;
}

.flashcard {
  flex: 1;
  perspective: 1400px;
  margin-bottom: 18px;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 300px;
  transition: transform 0.5s cubic-bezier(0.4, 0.1, 0.2, 1);
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  text-align: center;
}
.face.back { transform: rotateY(180deg); }
.face .lang-tag {
  position: absolute;
  top: 18px;
  left: 0;
  right: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.face .word {
  font-size: 38px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.face .word.small { font-size: 30px; }
.face .note {
  margin-top: 14px;
  font-size: 14px;
  color: var(--text-dim);
  font-style: italic;
}
.face .deck-chip {
  position: absolute;
  bottom: 18px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
}
.face .tap-hint {
  position: absolute;
  bottom: 18px;
  font-size: 13px;
  color: var(--text-dim);
}
.speak-btn {
  margin-top: 20px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-size: 22px;
  box-shadow: var(--shadow);
}
.speak-btn:active { transform: scale(0.92); }

/* ---------- Answer buttons ---------- */
.answer-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.answer-row.single { grid-template-columns: 1fr; }
.ans {
  padding: 18px;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 700;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease;
}
.ans:active { transform: scale(0.97); }
.ans.again { background: var(--surface); color: var(--red); }
.ans.good { background: var(--accent); color: #fff; }
.ans.reveal { background: var(--accent); color: #fff; }

/* ---------- Quiz ---------- */
.quiz-prompt {
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 34px 24px;
  text-align: center;
  margin-bottom: 18px;
}
.quiz-prompt .lang-tag {
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-dim); margin-bottom: 10px;
}
.quiz-prompt .word { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; }
.quiz-options { display: flex; flex-direction: column; gap: 12px; }
.quiz-opt {
  padding: 17px 18px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 17px;
  font-weight: 600;
  text-align: left;
  transition: transform 0.08s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.quiz-opt:active { transform: scale(0.98); }
.quiz-opt.correct { background: var(--accent); color: #fff; }
.quiz-opt.wrong { background: var(--red); color: #fff; }
.quiz-opt.dim { opacity: 0.5; }
.quiz-opt .mark { font-size: 18px; }

/* ---------- Browse ---------- */
.browse-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: 14px;
  padding: 13px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.browse-item .pt { font-weight: 700; font-size: 16px; }
.browse-item .de { font-size: 14px; color: var(--text-dim); }
.browse-item .mini-speak {
  margin-left: auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid; place-items: center; font-size: 16px;
  flex-shrink: 0;
}
.box-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}
.box-dot.learned { background: var(--accent); }

/* ---------- Done / empty states ---------- */
.done-card {
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 40px 28px;
  text-align: center;
  margin-top: 30px;
}
.done-card .emoji { font-size: 56px; }
.done-card h2 { margin: 16px 0 6px; font-size: 22px; }
.done-card p { color: var(--text-dim); margin: 0 0 22px; font-size: 15px; }

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
  font-size: 15px;
}

/* ---------- Settings sheet ---------- */
.setting-group {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
}
.setting-row:last-child { border-bottom: none; }
.setting-row .desc { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.switch {
  position: relative;
  width: 51px; height: 31px;
  border-radius: 999px;
  background: var(--border);
  transition: background 0.2s;
  flex-shrink: 0;
}
.switch.on { background: var(--accent); }
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 27px; height: 27px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.switch.on::after { transform: translateX(20px); }
.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
  flex-shrink: 0;
}
.seg button {
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
}
.seg button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.danger-btn {
  width: 100%;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--red);
  font-weight: 700;
  font-size: 16px;
  box-shadow: var(--shadow);
}

.install-tip {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 8px;
  line-height: 1.5;
}

/* ---------- Help: stat hints, How it works ---------- */
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.topbar-actions .icon-btn { margin-left: 0; font-weight: 700; color: var(--text); }
button.stat { font: inherit; color: inherit; cursor: pointer; border: 2px solid transparent; }
button.stat.active { border-color: var(--accent); }
.stat-hint {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin: -6px 0 16px;
  font-size: 14px;
  line-height: 1.45;
}
.help-intro { font-size: 15px; line-height: 1.5; margin: 0 2px 14px; }
.help-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 12px;
}
.help-card h3 { margin: 0 0 8px; font-size: 16px; }
.help-card p, .help-card li { font-size: 14.5px; line-height: 1.5; margin: 0 0 6px; }
.help-card ul { margin: 0; padding-left: 18px; }
.help-card .dim { color: var(--text-dim); }
.help-ladder { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: 8px 0 10px; }
.help-ladder span {
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 700;
}
.help-ladder i { font-style: normal; color: var(--text-dim); }
.help .cta { margin-top: 6px; }
.done-note { font-size: 13.5px; line-height: 1.45; color: var(--text-dim); }

/* ---------- Voice picker ---------- */
.voice-row { align-items: flex-end; gap: 12px; }
.voice-sel {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}
.voice-diag {
  padding: 0 18px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-dim);
}
.voice-diag:not(:empty) { padding: 0 18px 14px; }
.test-btn {
  flex-shrink: 0;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

/* ---------- Conjugation ---------- */
.conj-btn {
  margin-top: 16px;
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow);
}
.conj-btn:active { transform: scale(0.96); }
.card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}
.card-actions .conj-btn { margin-top: 0; }
a.info-link, a.mini-info { text-decoration: none; }
a.info-link { display: inline-block; }
.browse-item .mini-info {
  margin-left: auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid; place-items: center;
  font-size: 16px;
  flex-shrink: 0;
}
.browse-item .mini-info + .mini-speak { margin-left: 8px; }
a.conj-more {
  display: block;
  text-align: center;
  margin: 14px 0 6px;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 700;
  font-size: 15px;
}
.conj-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  animation: fade 0.2s ease;
  padding: 0 12px calc(var(--safe-bottom) + 12px);
}
.conj-sheet {
  background: var(--surface);
  width: 100%;
  max-width: 460px;
  border-radius: 24px;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.3);
  padding: 20px 20px 10px;
  animation: sheetUp 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.conj-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}
.conj-title { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.conj-sub { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.conj-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1.5px solid currentColor;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  vertical-align: middle;
}
.conj-tag.regular { color: var(--accent); }
.conj-tag.irregular { color: #c98a00; }
.conj-tag.impersonal { color: var(--text-dim); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .conj-tag.irregular { color: #e8b84b; }
}
:root[data-theme="dark"] .conj-tag.irregular { color: #e8b84b; }
.conj-close {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 700;
  flex-shrink: 0;
  display: grid; place-items: center;
}
.conj-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 6px;
  border-top: 1px solid var(--border);
}
.conj-row .conj-pron {
  width: 104px;
  flex-shrink: 0;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.25;
  font-weight: 600;
}
.conj-row .conj-form { font-size: 18px; font-weight: 700; flex: 1; }
.conj-row .conj-say {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid; place-items: center;
  font-size: 15px;
  flex-shrink: 0;
}

/* ---------- Direction switch (top of home) ---------- */
.dir-switch {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: 14px;
  padding: 5px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.dir-switch button {
  flex: 1;
  padding: 11px 6px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}
.dir-switch button.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.fade-in { animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Conjugation tense switch ---------- */
.conj-tenses { display: flex; margin: 0 0 6px; }
.conj-tenses button { flex: 1; }

/* ---------- Mute / unmute ---------- */
.mute-btn { font-size: 18px; }
.topbar-actions .mute-btn { font-weight: 400; }
body.muted .speak-btn,
body.muted .mini-speak,
body.muted .conj-say { opacity: 0.3; }

/* ---------- Sync between devices ---------- */
.sync-row { gap: 10px; justify-content: stretch; }
.sync-row .test-btn { flex: 1; padding: 12px 10px; }
.test-btn.alt { background: var(--surface-2); color: var(--accent); }
.sync-msg { display: none; padding: 0 18px 15px; font-size: 13px; line-height: 1.4; color: var(--accent); }
.sync-msg.show { display: block; }
.sync-msg.warn { color: var(--red); }

/* ---------- ⭐ Difficult words ---------- */
.star-btn {
  position: absolute;
  top: 10px; right: 10px;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: transparent;
  border: none;
  font-size: 26px; line-height: 1;
  color: var(--text-dim);
  cursor: pointer;
  z-index: 2;
}
.star-btn.on, .mini-star.on { color: #f5a623; }
.browse-item .mini-star {
  margin-left: auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--surface-2);
  border: none;
  display: grid; place-items: center;
  font-size: 19px; line-height: 1;
  color: var(--text-dim);
  flex-shrink: 0;
  cursor: pointer;
}
.browse-item .mini-star + .mini-info { margin-left: 8px; }
.browse-item .mini-star.on { color: #f5a623; }
