:root {
  --bg: #0f1419;
  --panel: #1a2330;
  --panel2: #223046;
  --text: #e8eef5;
  --muted: #8fa3b8;
  --accent: #4da3ff;
  --accent2: #0d3b66;
  --ok: #3ecf8e;
  --bad: #ff6b6b;
  --warn: #ffc857;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; }
.ok { color: var(--ok); }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card h1 { font-size: 2rem; margin-bottom: 6px; }
.login-card h1 span { color: var(--accent); }
.login-card input { margin: 18px 0 12px; }
.login-card button { width: 100%; }

/* ---------- каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: rgba(15,20,25,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid #263246;
}
.brand { font-weight: 700; }
.brand span { color: var(--accent); }
.topbar-stats { display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: .95rem; }

main { max-width: 720px; margin: 0 auto; padding: 16px 16px 90px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--panel); border-top: 1px solid #263246;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; padding: 10px 4px; background: none; border: none; color: var(--muted);
  font-size: .8rem; cursor: pointer; position: relative;
}
.tab.active { color: var(--accent); font-weight: 600; }
.badge {
  position: absolute; top: 4px; right: 12px; background: var(--bad); color: #fff;
  border-radius: 10px; padding: 0 6px; font-size: .7rem;
}

/* ---------- компоненты ---------- */
.card {
  background: var(--panel); border: 1px solid #263246; border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 1.15rem; margin-bottom: 8px; }
.card h3 { font-size: 1rem; margin: 10px 0 6px; }

.btn {
  display: inline-block; padding: 10px 18px; border-radius: 10px; border: 1px solid #33465e;
  background: var(--panel2); color: var(--text); font-size: 1rem; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06223f; font-weight: 600; }
.btn.ghost { background: none; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.wide { width: 100%; margin-top: 8px; }

input, textarea, select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid #33465e;
  background: #101923; color: var(--text); font-size: 1rem; font-family: inherit;
}
textarea { min-height: 90px; resize: vertical; }
label.field { display: block; margin: 10px 0 4px; font-size: .9rem; color: var(--muted); }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 560px) { .grid4 { grid-template-columns: repeat(2, 1fr); } }

.stat {
  background: var(--panel); border: 1px solid #263246; border-radius: var(--radius);
  padding: 12px; text-align: center;
}
.stat .num { font-size: 1.5rem; font-weight: 700; }
.stat .lbl { font-size: .8rem; color: var(--muted); }

.progressbar { height: 8px; background: #263246; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progressbar > i { display: block; height: 100%; background: var(--accent); }

/* ---------- юниты ---------- */
.unit-item {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: var(--panel); border: 1px solid #263246; border-radius: var(--radius); margin-bottom: 8px;
  cursor: pointer;
}
.unit-item.locked { opacity: .45; cursor: default; }
.unit-item .uid {
  width: 34px; height: 34px; border-radius: 50%; background: var(--panel2);
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.unit-item.done .uid { background: var(--ok); color: #06281a; }
.unit-item .info { flex: 1; min-width: 0; }
.unit-item .title { font-weight: 600; }
.unit-item .sub { font-size: .82rem; color: var(--muted); }
.unit-item .mastery { font-size: .85rem; color: var(--accent); white-space: nowrap; }

/* ---------- задания ---------- */
.ex-prompt { font-size: 1.1rem; margin-bottom: 12px; white-space: pre-wrap; }
.ex-options { display: grid; gap: 8px; }
.ex-options .btn { text-align: left; }
.ex-options .btn.chosen { border-color: var(--accent); }
.word-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip {
  padding: 8px 12px; background: var(--panel2); border: 1px solid #33465e; border-radius: 20px;
  cursor: pointer; user-select: none;
}
.chip.used { opacity: .3; pointer-events: none; }
.order-line {
  min-height: 48px; border: 1px dashed #33465e; border-radius: 10px; padding: 8px;
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px;
}
.order-line .chip { opacity: 1; }
.feedback { margin-top: 12px; padding: 12px; border-radius: 10px; }
.feedback.good { background: rgba(62,207,142,.12); border: 1px solid var(--ok); }
.feedback.bad { background: rgba(255,107,107,.1); border: 1px solid var(--bad); }
.feedback .right { font-weight: 600; margin-top: 4px; }

/* ---------- SRS ---------- */
.flashcard {
  background: var(--panel2); border-radius: var(--radius); padding: 32px 20px; text-align: center;
  cursor: pointer; margin-bottom: 14px; min-height: 120px;
  display: flex; flex-direction: column; justify-content: center; gap: 8px;
}
.flashcard .front { font-size: 1.6rem; font-weight: 600; }
.flashcard .back { font-size: 1.1rem; color: var(--muted); }
.grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

/* ---------- ошибки ---------- */
.mistake { border-left: 3px solid var(--warn); }
.mistake .mk-kind { font-size: .75rem; text-transform: uppercase; color: var(--warn); letter-spacing: .05em; }
.mistake .pair { margin: 6px 0; }
.mistake .wrong { color: var(--bad); text-decoration: line-through; }
.mistake .right { color: var(--ok); }

/* ---------- настройки ---------- */
.kv { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; font-size: .92rem; }
.kv code { color: var(--accent); word-break: break-all; }
.chatlog { max-height: 220px; overflow-y: auto; background: #101923; border-radius: 10px; padding: 10px; margin: 8px 0; }
.chatlog .msg { margin-bottom: 8px; }
.chatlog .msg .who { font-size: .75rem; color: var(--muted); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .75rem; background: var(--panel2); color: var(--muted); }
.tag.on { background: rgba(62,207,142,.15); color: var(--ok); }
.tag.off { background: rgba(255,107,107,.12); color: var(--bad); }

.toast {
  position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid #33465e; padding: 10px 18px; border-radius: 24px;
  z-index: 50; font-size: .9rem; max-width: 90vw;
}
.speak-btn { background: none; border: none; cursor: pointer; font-size: 1.1rem; vertical-align: middle; }
hr.sep { border: none; border-top: 1px solid #263246; margin: 14px 0; }
