:root {
  --bg: #f7f9fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #22a34a;
  --primary-dark: #178a3b;
  --primary-light: #e6f7ec;
  --accent: #4c6fff;
  --accent-light: #eaefff;
  --warn: #f5a623;
  --warn-light: #fff4e0;
  --danger: #e5484d;
  --danger-light: #fdecec;
  --shadow: 0 2px 10px rgba(20, 30, 40, 0.06);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151a;
    --card: #1b1f27;
    --text: #eef1f5;
    --muted: #9aa4b2;
    --border: #2a2f3a;
    --primary: #34c95f;
    --primary-dark: #28a34c;
    --primary-light: #163524;
    --accent: #7d97ff;
    --accent-light: #1c2340;
    --warn: #f5b94f;
    --warn-light: #3a2e12;
    --danger: #ff6b70;
    --danger-light: #3a1e20;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #12151a;
  --card: #1b1f27;
  --text: #eef1f5;
  --muted: #9aa4b2;
  --border: #2a2f3a;
  --primary: #34c95f;
  --primary-dark: #28a34c;
  --primary-light: #163524;
  --accent: #7d97ff;
  --accent-light: #1c2340;
  --warn: #f5b94f;
  --warn-light: #3a2e12;
  --danger: #ff6b70;
  --danger-light: #3a1e20;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
body { padding-bottom: 76px; }

#app { max-width: 640px; margin: 0 auto; padding: 16px 16px 8px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 2px 14px;
}
.topbar h1 { font-size: 20px; margin: 0; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: none; background: var(--card); color: var(--text);
  width: 38px; height: 38px; border-radius: 12px; box-shadow: var(--shadow);
  cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center;
}

.stats-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px;
}
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow);
}
.stat-card .num { font-size: 24px; font-weight: 700; }
.stat-card .label { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.stat-card.streak .num { color: var(--warn); }
.stat-card.today .num { color: var(--primary); }
.stat-card.due .num { color: var(--danger); }
.stat-card.total .num { color: var(--accent); }

.section-title {
  font-size: 14px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  margin: 18px 2px 8px;
}

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px;
}

.session-buttons { display: flex; gap: 10px; }
.session-btn {
  flex: 1; border: none; border-radius: 14px; padding: 16px 8px;
  background: var(--primary-light); color: var(--primary-dark);
  font-weight: 700; font-size: 16px; cursor: pointer; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.session-btn small { font-weight: 500; font-size: 11.5px; color: var(--muted); }
.session-btn:active { transform: scale(0.97); }

.progressbar-outer {
  height: 8px; background: var(--border); border-radius: 8px; overflow: hidden; margin-top: 6px;
}
.progressbar-inner { height: 100%; background: var(--primary); border-radius: 8px; transition: width .3s; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}
.nav-btn {
  border: none; background: none; color: var(--muted); font-size: 11px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 10px; border-radius: 10px; cursor: pointer; min-width: 60px;
}
.nav-btn .ico { font-size: 19px; }
.nav-btn.active { color: var(--primary); font-weight: 700; }

.view { display: none; }
.view.active { display: block; }

.word-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 4px; border-bottom: 1px solid var(--border);
  gap: 8px;
}
.word-row:last-child { border-bottom: none; }
.word-row .es { font-weight: 600; }
.word-row .ru { color: var(--muted); font-size: 13px; }
.word-row .box-dots { display: flex; gap: 3px; flex-shrink: 0; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.dot.on { background: var(--primary); }
.word-row .assoc-btn {
  border: none; background: var(--accent-light); color: var(--accent);
  font-size: 11px; padding: 5px 9px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}

.mic-btn {
  border: none; background: var(--primary-light); color: var(--primary-dark);
  font-size: 15px; width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.mic-btn.listening { background: var(--danger); color: white; animation: mic-pulse 1s infinite; }
@keyframes mic-pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

.reader-mic { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.reader-mic .mic-btn { width: 36px; height: 36px; font-size: 17px; }
.reader-mic-label { font-size: 12.5px; color: var(--muted); }

input[type="text"], input[type="search"], textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit;
}
textarea { resize: vertical; min-height: 64px; }

.filter-row { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; }
.filter-chip {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 7px 13px; border-radius: 999px; font-size: 12.5px; white-space: nowrap; cursor: pointer;
}
.filter-chip.active { background: var(--primary); border-color: var(--primary); color: white; }

/* Flashcard session */
.session-overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 50;
  display: flex; flex-direction: column; padding: 16px;
}
.session-top { display: flex; align-items: center; gap: 10px; }
.session-progress { flex: 1; }
.close-x { border: none; background: var(--card); width: 36px; height: 36px; border-radius: 10px; font-size: 16px; cursor: pointer; color: var(--text); }

.flash-wrap {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
}
.flashcard {
  position: relative;
  width: 100%; max-width: 440px; min-height: 220px; background: var(--card);
  border-radius: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 28px 20px; text-align: center; gap: 14px;
  cursor: pointer;
}
.flashcard .card-mic-btn { position: absolute; top: 12px; right: 12px; }
.flashcard .es-word { font-size: 30px; font-weight: 800; }
.flashcard .ru-word { font-size: 20px; color: var(--primary-dark); font-weight: 600; }
.flashcard .hint { font-size: 12.5px; color: var(--muted); }
.flashcard .dir-badge {
  font-size: 11px; font-weight: 700; letter-spacing: .04em; color: var(--accent);
  background: var(--accent-light); padding: 3px 9px; border-radius: 999px; margin-bottom: 4px;
}
.flashcard .dir-badge.learn-badge { color: var(--primary-dark); background: var(--primary-light); }
.flashcard .assoc-box {
  margin-top: 6px; background: var(--accent-light); color: var(--text);
  border-radius: 12px; padding: 10px 12px; font-size: 13px; text-align: left;
}

.reveal-btn {
  width: 100%; max-width: 440px; padding: 14px; border: none; border-radius: 14px;
  background: var(--primary); color: white; font-weight: 700; font-size: 15px; cursor: pointer;
}
.reveal-btn:disabled { opacity: .6; cursor: default; }
.reveal-btn.ghost {
  background: none; color: var(--muted); border: 1px solid var(--border);
  padding: 10px; font-size: 13px; font-weight: 600;
}
.small-btn.learn-btn { background: var(--primary-light); color: var(--primary-dark); border-color: transparent; font-weight: 700; }

.type-answer-row {
  width: 100%; max-width: 440px; display: flex; gap: 8px;
}
.type-answer-input {
  flex: 1; padding: 14px 14px; border-radius: 14px; border: 2px solid var(--border);
  background: var(--card); color: var(--text); font-size: 16px;
}
.type-answer-input:focus { outline: none; border-color: var(--accent); }
.check-btn {
  border: none; border-radius: 14px; padding: 0 18px; background: var(--accent);
  color: white; font-weight: 700; font-size: 14px; cursor: pointer;
}
.typed-feedback {
  font-size: 13px; border-radius: 10px; padding: 8px 10px; margin-top: 4px;
}
.typed-feedback.good { background: var(--primary-light); color: var(--primary-dark); }
.typed-feedback.bad { background: var(--danger-light); color: var(--danger); }
.think-btn {
  width: 100%; max-width: 440px; padding: 10px; border: none; border-radius: 12px;
  background: none; color: var(--muted); font-size: 12.5px; cursor: pointer; text-decoration: underline;
}

.session-done { text-align: center; padding: 40px 10px; }
.session-done .big { font-size: 46px; }

/* Association view */
.assoc-detail { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.assoc-detail .es { font-size: 19px; font-weight: 700; }
.assoc-detail .ru { color: var(--muted); margin-bottom: 8px; }
.assoc-detail .translit { font-size: 12.5px; color: var(--accent); margin-bottom: 6px; }
.assoc-detail .body { font-size: 14px; line-height: 1.5; background: var(--accent-light); padding: 10px 12px; border-radius: 12px; margin-bottom: 10px; }
.assoc-detail .tag { display:inline-block; font-size:10.5px; background: var(--primary-light); color: var(--primary-dark); padding: 2px 8px; border-radius: 999px; margin-bottom:8px; font-weight:700; }
.assoc-detail .tag.auto { background: var(--warn-light); color: #9a6a00; }
.assoc-detail .assoc-request {
  font-size: 12.5px; line-height: 1.5; background: var(--warn-light); color: var(--text);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 10px;
}
.assoc-detail .assoc-request .small-btn { margin-top: 8px; }

.text-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 10px; cursor: pointer; }
.text-card .title { font-weight: 700; font-size: 15.5px; }
.text-card .theme { font-size: 12px; color: var(--accent); }
.text-card .pct { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

.reader { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.reader-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.lang-toggle { display: flex; background: var(--border); border-radius: 999px; padding: 3px; }
.lang-toggle button {
  border: none; background: none; padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; cursor: pointer; color: var(--muted);
}
.lang-toggle button.active { background: var(--primary); color: white; }
.reader-body { font-size: 16.5px; line-height: 1.7; }
.reader-body .unknown { background: var(--warn-light); border-radius: 4px; padding: 0 2px; }
.reader-body .tap-word { cursor: pointer; border-radius: 4px; }
.reader-body .tap-word:active { background: var(--accent-light); }
.reader-body .pron-ok { background: var(--primary-light); }
.reader-body .pron-bad { background: var(--danger-light); }
.word-translate-popup {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  background: var(--accent-light); color: var(--text); font-size: 14px;
}
.reader-translate-box {
  margin-top: 10px; padding: 12px 14px; border-radius: 12px;
  background: var(--primary-light); color: var(--text); font-size: 15px; line-height: 1.6;
}
.reader-meta { font-size: 12.5px; color: var(--muted); margin-top: 12px; }

.empty-state { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 14px; }

button { font-family: inherit; }
a { color: var(--accent); }

.settings-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* DUO log */
.duo-day { margin-bottom: 14px; }
.duo-day-date { font-weight: 700; font-size: 15.5px; margin-bottom: 8px; text-transform: capitalize; }
.duo-lessons { display: flex; flex-direction: column; gap: 4px; }
.duo-lesson-row {
  display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted);
  background: var(--bg); padding: 6px 10px; border-radius: 8px;
}
.duo-lesson-score { font-weight: 700; color: var(--primary-dark); }
.duo-words-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.duo-word-chip {
  font-size: 12.5px; background: var(--primary-light); color: var(--primary-dark);
  padding: 5px 10px; border-radius: 999px;
}
.duo-rule {
  background: var(--warn-light); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px;
}
.duo-rule-title { font-weight: 700; font-size: 13.5px; margin-bottom: 6px; color: #9a6a00; }
.duo-rule-body { font-size: 13px; line-height: 1.55; }
.small-btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 8px 12px; border-radius: 10px; font-size: 12.5px; cursor: pointer;
}
