:root {
  --bg: #0e0f14;
  --surface: #171922;
  --surface-2: #20232f;
  --surface-3: #2a2e3d;
  --line: #2c3040;
  --text: #eceef5;
  --muted: #8b90a5;
  --accent: #8b7cff;
  --accent-2: #b3a8ff;
  --good: #3ecf8e;
  --bad: #ff6b6b;
  --warn: #ffb547;
  --info: #5aa9ff;
  --m: #5aa9ff;
  --f: #ff6b8a;
  --n: #4fd18b;
  --pl: #c08bff;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 50% -200px, #1d1b33 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}
body.loading main, body.loading nav { visibility: hidden; }
a { color: var(--accent-2); text-decoration: none; }
h2 { margin: 0 0 14px; font-size: 20px; }
h3 { margin: 0 0 12px; font-size: 17px; }
code { background: var(--surface-3); padding: 1px 6px; border-radius: 6px; font-size: .9em; }
kbd {
  font: 11px/1 ui-monospace, monospace; padding: 3px 5px; border-radius: 5px;
  background: rgba(255, 255, 255, .12); margin-left: 6px; opacity: .75;
}
@media (hover: none) { kbd { display: none; } }

/* ---------- каркас ---------- */
header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(14, 15, 20, .8); backdrop-filter: blur(14px);
}
.brand { font-weight: 800; font-size: 20px; color: var(--text); letter-spacing: -.02em; }
.brand span { color: var(--accent); }
#langs { margin-left: auto; display: flex; gap: 6px; overflow-x: auto; }
main { max-width: 640px; margin: 0 auto; padding: 8px 16px 24px; }

nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: rgba(14, 15, 20, .88); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
nav a {
  flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px; border-radius: 12px; color: var(--muted); font-size: 11px; transition: color .2s, background .2s;
}
nav a .ni { font-size: 20px; line-height: 1.2; }
nav a.on { color: var(--text); background: var(--surface-2); }
body.studying nav, body.auth nav, body.auth header #langs { display: none; }
body.studying { padding-bottom: 24px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin: 12px 0;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.row.center, .center { justify-content: center; text-align: center; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--bad); }
.link { color: var(--accent-2); }

/* ---------- формы ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; min-width: 0; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 124, 255, .2); }
textarea { width: 100%; resize: vertical; line-height: 1.5; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; font-size: 14px; color: var(--muted); }
.field input, .field select { color: var(--text); font-size: 16px; }
.field small { font-size: 12px; opacity: .8; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 11px 16px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 600; font-size: 15px;
  transition: transform .12s, background .2s, border-color .2s, opacity .2s; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0e0f14; }
.btn.primary:hover { background: var(--accent-2); }
.btn.good { background: rgba(62, 207, 142, .16); border-color: rgba(62, 207, 142, .5); color: var(--good); }
.btn.bad { background: rgba(255, 107, 107, .14); border-color: rgba(255, 107, 107, .45); color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--bad); border-color: rgba(255, 107, 107, .35); }
.btn.wide { flex: 1; }
.icon-btn {
  width: 38px; height: 38px; flex: none; display: inline-grid; place-items: center;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--text); }

.pill, .chip {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: all .15s;
}
.pill.on, .chip.on { background: var(--accent); border-color: var(--accent); color: #0e0f14; font-weight: 600; }
.chip.sm { padding: 2px 8px; font-size: 12px; cursor: default; }
button.chip.sm { cursor: pointer; }
.chip.new { color: var(--accent-2); border-color: rgba(139, 124, 255, .5); }
.chip.bad { color: var(--bad); border-color: rgba(255, 107, 107, .5); }
.chip.warn { color: var(--warn); border-color: rgba(255, 181, 71, .5); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.chip.info { color: var(--info); border-color: rgba(90, 169, 255, .5); }
.chip.tag { color: var(--accent-2); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip.g-m:not(.on) { color: var(--m); }
.chip.g-f:not(.on) { color: var(--f); }
.chip.g-n:not(.on) { color: var(--n); }

/* цвет рода */
.g-m { color: var(--m) !important; }
.g-f { color: var(--f) !important; }
.g-n { color: var(--n) !important; }
.g-pl { color: var(--pl) !important; }

/* чекбокс */
.check { position: relative; display: inline-grid; place-items: center; cursor: pointer; flex: none; }
.check input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.check span {
  width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line); background: var(--surface-2);
  transition: all .15s; display: grid; place-items: center;
}
.check input:checked + span { background: var(--accent); border-color: var(--accent); }
.check input:checked + span::after { content: '✓'; color: #0e0f14; font-weight: 800; font-size: 14px; }

/* ---------- главная ---------- */
.streak { display: flex; align-items: center; gap: 16px; }
.flame { font-size: 44px; filter: grayscale(1) opacity(.45); transition: filter .4s; }
.lit .flame, .flame.lit { filter: none; animation: flicker 1.6s ease-in-out infinite; }
.flame.big { font-size: 72px; }
@keyframes flicker {
  0%, 100% { transform: scale(1) rotate(-2deg); }
  50% { transform: scale(1.1) rotate(3deg); }
}
.streak-n { font-size: 30px; font-weight: 800; line-height: 1.1; }
.streak-n span { font-size: 15px; font-weight: 500; color: var(--muted); }
.goal { display: flex; align-items: center; gap: 10px; margin: 8px 0 4px; font-size: 13px; color: var(--muted); }
.bar { flex: 1; height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--warn), #ff7a45); border-radius: 99px; transition: width .6s; }
.hist { display: flex; align-items: flex-end; gap: 3px; height: 42px; }
.hist i { width: 5px; border-radius: 3px; background: var(--surface-3); }
.hist i.done { background: var(--warn); }
@media (max-width: 420px) { .hist { display: none; } }

.modes { display: grid; gap: 10px; }
.mode {
  display: flex; align-items: center; gap: 14px; margin: 0; width: 100%; text-align: left; cursor: pointer;
  transition: transform .15s, border-color .2s, background .2s;
}
.mode:hover { border-color: var(--accent); background: var(--surface-2); }
.mode:active { transform: scale(.98); }
.mode-icon { font-size: 26px; width: 48px; height: 48px; display: grid; place-items: center; background: var(--surface-2); border-radius: 14px; flex: none; }
.mode-body { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.mode-t { font-weight: 700; font-size: 17px; }
.mode-sub { color: var(--muted); font-size: 13px; }
.mode-cnt { font-size: 14px; margin-top: 4px; }
.mode-cnt b { color: var(--accent-2); }
.mode-go { color: var(--muted); font-size: 20px; transition: transform .2s; }
.mode:hover .mode-go { transform: translateX(4px); color: var(--accent); }
.extra .btn { flex: 1; }

.empty { text-align: center; padding: 32px 18px; }
.empty-emoji { font-size: 52px; margin-bottom: 8px; animation: pop .5s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }

/* ---------- сессия ---------- */
.study-top { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.progress { flex: 1; height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--good)); transition: width .4s ease; }
.study-badges { display: flex; gap: 6px; align-items: center; min-height: 30px; margin: 10px 0 4px; }

.stage { perspective: 1400px; margin: 8px 0 16px; }
.flip { position: relative; touch-action: pan-y; user-select: none; -webkit-user-select: none; transition: transform .3s; }
.flip.enter { animation: cardIn .45s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes cardIn { from { transform: translateY(40px) scale(.92) rotate(-2deg); opacity: 0; } }
.flip-inner {
  display: grid; transform-style: preserve-3d;
  transition: transform .6s cubic-bezier(.3, 1.4, .5, 1);
}
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.face {
  grid-area: 1 / 1; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  min-height: 300px; padding: 28px 22px; border-radius: 26px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center;
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.face.back { transform: rotateY(180deg); background: linear-gradient(160deg, #262340, var(--surface)); }
.flip.ok .face.back { border-color: rgba(62, 207, 142, .6); box-shadow: 0 0 0 4px rgba(62, 207, 142, .12), var(--shadow); }
.flip.nope .face.back { border-color: rgba(255, 107, 107, .6); }
.flip.nope { animation: shake .45s .45s; }
@keyframes shake {
  20%, 60% { transform: translateX(-9px); }
  40%, 80% { transform: translateX(9px); }
}
.shake { animation: shake .4s; }

.kind { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.term { font-size: clamp(26px, 7vw, 38px); font-weight: 750; line-height: 1.2; overflow-wrap: anywhere; }
.term-sm { font-size: 16px; color: var(--muted); }
.answer { font-size: clamp(24px, 6.5vw, 34px); font-weight: 750; line-height: 1.25; overflow-wrap: anywhere; animation: rise .5s .15s both; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
.comment {
  font-size: 15px; color: #c9cce0; background: rgba(255, 255, 255, .05); border-radius: 12px; padding: 10px 14px;
  max-width: 100%; animation: rise .5s .25s both;
}
.tap-hint { color: var(--muted); font-size: 13px; opacity: .7; margin-top: 8px; }
.hint-btn { background: none; border: 1px dashed var(--line); color: var(--muted); padding: 6px 12px; border-radius: 99px; cursor: pointer; font-size: 13px; }
.hint { font-size: 14px; color: #c9cce0; background: rgba(255, 181, 71, .08); border-radius: 12px; padding: 8px 12px; animation: rise .3s both; }

#ansForm { width: 100%; max-width: 380px; margin-top: 6px; }
#ans { width: 100%; font-size: 20px; text-align: center; padding: 14px; border-radius: 16px; }
.uml { display: flex; gap: 8px; }
.uml button {
  width: 44px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-3);
  cursor: pointer; font-size: 18px; transition: transform .1s;
}
.uml button:active { transform: scale(.9); }

.verdict { display: flex; flex-direction: column; gap: 4px; animation: rise .4s .2s both; }
.v-title { font-weight: 700; font-size: 16px; }
.verdict.good .v-title { color: var(--good); }
.verdict.warn .v-title { color: var(--warn); }
.verdict.bad .v-title { color: var(--bad); }
.v-mine { color: var(--muted); font-size: 14px; }
.verdict.bad .v-mine span { text-decoration: line-through; text-decoration-color: var(--bad); }
.v-note { color: var(--warn); font-size: 14px; }

.swipe-tag {
  position: absolute; top: 22px; padding: 6px 14px; border-radius: 10px; font-weight: 800; font-size: 15px;
  text-transform: uppercase; letter-spacing: .05em; pointer-events: none; border: 2px solid;
}
.swipe-tag.no { right: 22px; color: var(--bad); opacity: var(--l, 0); transform: rotate(12deg); }
.swipe-tag.yes { left: 22px; color: var(--good); opacity: var(--r, 0); transform: rotate(-12deg); }

.actions { display: flex; gap: 10px; }
.actions .btn { padding: 15px 16px; font-size: 16px; border-radius: 16px; }
.finish h2 { margin: 6px 0; }

/* ---------- добавление ---------- */
.help { margin-top: 10px; color: var(--muted); font-size: 14px; }
.help summary { cursor: pointer; color: var(--text); }
.help li { margin: 6px 0; }
.prev { display: grid; gap: 10px; }
.prow {
  display: grid; gap: 8px; padding: 12px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line);
  transition: opacity .2s;
}
.prow.off { opacity: .45; }
.prow input, .prow select { background: var(--surface); padding: 8px 10px; font-size: 15px; }
.prow-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.prow-main { display: flex; gap: 6px; align-items: center; }
.prow-main input { flex: 1; }
.prow-main input[data-f="term"] { font-weight: 600; }
.prow-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.prow-meta input { flex: 1; min-width: 140px; }
@media (max-width: 480px) {
  .prow-main { flex-wrap: wrap; }
  .prow-main input { flex-basis: 100%; }
  .prow-main .icon-btn { margin: -2px auto; height: 28px; }
}

.sticky-bar {
  position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 5;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px; margin: 12px 0; border-radius: 18px;
  background: rgba(32, 35, 47, .92); backdrop-filter: blur(12px); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.sticky-bar input { flex: 1; min-width: 100px; }

/* ---------- список слов ---------- */
.words { display: grid; }
.word { display: flex; gap: 12px; align-items: flex-start; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.word:last-child { border-bottom: 0; }
.word .check { margin-top: 2px; }
.w-main { flex: 1; min-width: 0; cursor: pointer; }
.w-line { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.w-term { font-weight: 700; }
.w-tr { color: #c9cce0; }
.w-cm { color: var(--muted); font-size: 13px; margin-top: 2px; }
.w-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.stat { font-size: 12px; color: var(--muted); }
.word.hard .w-term::after { content: ' 💪'; }
.word.editing { display: block; }
.edit { display: grid; gap: 8px; }
.edit .row { margin: 0; }

.steps { color: var(--muted); padding-left: 20px; }
.steps li { margin: 4px 0; }

/* ---------- вход ---------- */
.auth-card { max-width: 360px; margin: 12vh auto 0; display: grid; gap: 12px; text-align: center; }
.auth-card h2 { margin: 0; }
.auth-logo {
  width: 64px; height: 64px; margin: 0 auto 4px; border-radius: 18px; background: var(--accent); color: #0e0f14;
  display: grid; place-items: center; font: 700 40px Georgia, serif; animation: pop .6s cubic-bezier(.2, 1.6, .4, 1);
}

/* ---------- toast и конфетти ---------- */
.toast {
  position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top)); z-index: 100; transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--line); padding: 10px 16px; border-radius: 14px;
  box-shadow: var(--shadow); max-width: calc(100% - 32px); animation: toastIn .35s cubic-bezier(.2, 1.4, .4, 1);
  transition: opacity .3s, transform .3s;
}
.toast.good { border-color: rgba(62, 207, 142, .6); }
.toast.bad { border-color: rgba(255, 107, 107, .6); }
.toast.out { opacity: 0; transform: translate(-50%, -10px); }
@keyframes toastIn { from { transform: translate(-50%, -20px); opacity: 0; } }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
