:root {
  --bg: #0f172a;
  --bg-elevated: #161f38;
  --card: #1b2542;
  --border: #2b3660;
  --text: #eef1fb;
  --text-dim: #9aa4c7;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5fb;
    --bg-elevated: #ffffff;
    --card: #ffffff;
    --border: #e3e6f3;
    --text: #171a2b;
    --text-dim: #5b6280;
    --accent: #4f46e5;
    --accent-2: #6366f1;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(72px + var(--safe-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 18px 14px;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  backdrop-filter: blur(6px);
}
.topbar h1 {
  font-size: 19px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.level-badge {
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
}

main {
  flex: 1;
  padding: 4px 18px 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 6px; font-size: 17px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.card p { margin: 0; color: var(--text-dim); font-size: 14px; line-height: 1.5; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.stat .num { font-size: 24px; font-weight: 800; color: var(--accent-2); }
.stat .label { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn.ghost {
  background: transparent;
  color: var(--accent-2);
  width: auto;
  padding: 8px 4px;
}
.btn.small { padding: 9px 12px; font-size: 13px; width: auto; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-row { display: flex; gap: 10px; margin-top: 10px; }
.btn-row .btn { flex: 1; }

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
}
.list-item:active { opacity: 0.8; }
.list-item .title { font-weight: 600; font-size: 15px; }
.list-item .sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.list-item .chevron { color: var(--text-dim); font-size: 18px; }
.pill {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-2);
}
.pill.done { background: rgba(34, 197, 94, 0.15); color: var(--good); }
.pill.current { background: var(--accent); color: white; }

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin: 10px 0;
}
.progress-bar > div {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tabbar-inner {
  max-width: 560px;
  width: 100%;
  display: flex;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 4px 8px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
}
.tab .icon { font-size: 20px; }
.tab.active { color: var(--accent-2); }

.option {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  font-size: 15px;
  cursor: pointer;
}
.option:active { transform: scale(0.99); }
.option.correct { border-color: var(--good); background: rgba(34,197,94,0.12); }
.option.wrong { border-color: var(--bad); background: rgba(239,68,68,0.12); }
.option.disabled { pointer-events: none; }

.flashcard {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 22px;
  min-height: 230px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  cursor: pointer;
}
.flashcard .word { font-size: 28px; font-weight: 800; }
.flashcard .pos { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.flashcard .ru { font-size: 19px; color: var(--accent-2); font-weight: 700; }
.flashcard .def { font-size: 14px; color: var(--text-dim); }
.flashcard .example { font-size: 14px; font-style: italic; color: var(--text); margin-top: 4px; }
.flashcard .hint { font-size: 12px; color: var(--text-dim); margin-top: 10px; }

.quality-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.qbtn {
  border: none;
  border-radius: 12px;
  padding: 12px 4px;
  font-size: 13px;
  font-weight: 700;
  color: white;
  cursor: pointer;
}
.qbtn.again { background: var(--bad); }
.qbtn.hard { background: var(--warn); }
.qbtn.good { background: var(--accent); }
.qbtn.easy { background: var(--good); }

.text-block {
  font-size: 15.5px;
  line-height: 1.7;
  white-space: pre-line;
  margin-bottom: 16px;
}
.explain-block {
  font-size: 14.5px;
  line-height: 1.65;
  white-space: pre-line;
  color: var(--text);
  margin-bottom: 6px;
}

.center-flow {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  padding-top: 30px;
}
.center-flow .big-emoji { font-size: 52px; }
.center-flow h2 { margin: 0; font-size: 22px; }
.center-flow p { color: var(--text-dim); font-size: 14.5px; line-height: 1.6; margin: 0; }

.qhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 12px; color: var(--text-dim); }

.result-level {
  font-size: 46px;
  font-weight: 900;
  color: var(--accent-2);
  text-align: center;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 18px 0 8px;
}
.section-title:first-child { margin-top: 0; }

.feedback-banner {
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  margin-top: 10px;
  font-weight: 600;
}
.feedback-banner.ok { background: rgba(34,197,94,0.15); color: var(--good); }
.feedback-banner.no { background: rgba(239,68,68,0.15); color: var(--bad); }

a { color: var(--accent-2); }
.attribution { font-size: 11px; color: var(--text-dim); margin-top: 24px; line-height: 1.5; }
