:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #15171a);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2a7de1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2a7de1);
  --sep: var(--tg-theme-section-separator-color, rgba(128, 128, 128, .18));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --soft: rgba(128, 128, 128, .12);

  --m: #3b7cf4;   /* мужской род */
  --f: #e0457b;   /* женский */
  --n: #1d9e6c;   /* средний */
  --c: #8b5cf6;   /* общий */
  --again: #e5484d;
  --hard: #e88a0c;
  --good: #2ea56a;
  --easy: #3b7cf4;
  --new: #3b7cf4;
  --lrn: #e88a0c;
  --rev: #2ea56a;

  --radius: 16px;
  --safe-b: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { font-size: 16px; line-height: 1.4; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; color: var(--text); }
svg { display: block; }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }
.view { padding: 16px 16px calc(84px + var(--safe-b)); }
.boot { display: grid; place-items: center; height: 80vh; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--soft); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

h1 { font-size: 26px; margin: 4px 0 2px; letter-spacing: -.01em; }
h2 { font-size: 19px; margin: 0 0 10px; }
.sub { color: var(--hint); font-size: 14px; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-top: 12px; }
.card-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin-bottom: 10px; font-weight: 600; }

/* кнопки */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px;
  background: var(--soft); font-weight: 600; font-size: 15px; width: 100%;
  transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.big { min-height: 54px; font-size: 17px; border-radius: 14px; }
.btn.danger { color: var(--danger); }
.btn.known { background: rgba(46, 165, 106, .15); color: var(--good); }
.study-bottom .btn-row .btn.known { flex: 1; }
.study-bottom .btn-row .btn.primary { flex: 1.5; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row .btn { flex: 1; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--hint); flex: none; }
.icon-btn:active { background: var(--soft); }
.icon-btn svg { width: 22px; height: 22px; }
.link { color: var(--link); font-weight: 500; }

/* нижняя навигация */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--sep);
  padding-bottom: var(--safe-b);
}
.tabbar-in { display: flex; width: 100%; max-width: 560px; }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; color: var(--hint); font-size: 11px; font-weight: 500; }
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--accent); }

/* главная */
.today-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { text-align: center; padding: 10px 4px; border-radius: 12px; background: var(--soft); }
.stat b { display: block; font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--hint); }
.stat.new b { color: var(--new); }
.stat.lrn b { color: var(--lrn); }
.stat.rev b { color: var(--rev); }
.done-today { text-align: center; padding: 6px 0 12px; }
.done-today .em { font-size: 40px; }

.bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--soft); }
.bar i { display: block; height: 100%; }
.bar .b-learned { background: var(--good); }
.bar .b-learning { background: var(--lrn); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; color: var(--hint); }
.legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; background: var(--dot); }
.big-num { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* тепловая карта */
.heat { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; }
.heat i { aspect-ratio: 1; border-radius: 3px; background: var(--soft); max-width: 18px; }
.heat i.l1 { background: rgba(46, 165, 106, .3); }
.heat i.l2 { background: rgba(46, 165, 106, .55); }
.heat i.l3 { background: rgba(46, 165, 106, .8); }
.heat i.l4 { background: rgb(46, 165, 106); }
.heat i.x { visibility: hidden; }
.heat i.today { outline: 1.5px solid var(--text); outline-offset: -1.5px; }
.heat-months { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; font-size: 11px; color: var(--hint); margin-bottom: 4px; }

.forecast { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 16px; }
.fc-bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.fc-bar i { width: 100%; border-radius: 4px 4px 2px 2px; background: var(--rev); min-height: 2px; opacity: .85; }
.fc-bar.today i { opacity: 1; background: var(--accent); }
.fc-bar b { font-size: 10px; color: var(--hint); font-weight: 500; font-variant-numeric: tabular-nums; }
.fc-bar small { font-size: 10px; color: var(--hint); }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--soft); border-radius: 12px; padding: 10px; text-align: center; }
.tile b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.tile span { font-size: 12px; color: var(--hint); }

/* словарь */
.search {
  display: flex; align-items: center; gap: 8px; background: var(--card);
  border-radius: 12px; padding: 0 12px; height: 44px;
}
.search svg { width: 18px; height: 18px; color: var(--hint); flex: none; }
.search input { border: 0; outline: 0; background: none; width: 100%; height: 100%; font-size: 16px; }
.seg { display: flex; background: var(--soft); border-radius: 10px; padding: 2px; margin: 12px 0 4px; }
.seg button { flex: 1; padding: 7px 4px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--hint); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 6px 12px; border-radius: 999px; background: var(--card); font-size: 14px; color: var(--hint); font-weight: 500; }
.chip.on { background: var(--accent); color: var(--accent-text); }

.list { background: var(--card); border-radius: var(--radius); margin-top: 12px; overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--sep); min-height: 52px; }
.item:last-child { border-bottom: 0; }
.item:active { background: var(--soft); }
.item .emoji { font-size: 26px; width: 34px; text-align: center; flex: none; }
.item .title { font-weight: 600; }
.item .meta { font-size: 13px; color: var(--hint); }
.item .bar { height: 6px; margin-top: 6px; }
.level { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: var(--soft); color: var(--hint); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--sep); }
.dot.new { background: var(--sep); }
.dot.learning { background: var(--lrn); }
.dot.learned { background: var(--good); }
.dot.suspended { background: transparent; border: 1.5px solid var(--hint); }
.w-gr { font-weight: 600; }
.w-ru { color: var(--hint); font-size: 14px; }
.w-tr { color: var(--hint); font-weight: 400; font-size: 13px; margin-left: 8px; }

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--sep); transition: background .2s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s; }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(18px); }

/* род */
.art { font-weight: 600; }
.g-m { color: var(--m); }
.g-f { color: var(--f); }
.g-n { color: var(--n); }
.g-c { color: var(--c); }

/* занятие */
.study {
  position: fixed; inset: 0; z-index: 30; background: var(--bg);
  display: flex; flex-direction: column; max-width: 560px; margin: 0 auto;
  padding-bottom: var(--safe-b);
}
.study-top { display: flex; align-items: center; gap: 4px; padding: 8px 8px 0; }
.counts { flex: 1; display: flex; justify-content: center; gap: 14px; font-variant-numeric: tabular-nums; }
.counts span { display: flex; flex-direction: column; align-items: center; line-height: 1.1; padding-bottom: 2px; border-bottom: 2px solid transparent; min-width: 44px; }
.counts b { font-size: 17px; font-weight: 700; }
.counts i { font-style: normal; font-size: 10px; font-weight: 500; color: var(--hint); }
.counts .new { color: var(--new); }
.counts .lrn { color: var(--lrn); }
.counts .rev { color: var(--rev); }
.counts span.cur { border-bottom-color: currentColor; }
.study-body { flex: 1; overflow-y: auto; padding: 8px 16px 12px; display: flex; flex-direction: column; }
.fc {
  background: var(--card); border-radius: 22px; padding: 22px 20px 24px; flex: 1;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  border-top: 5px solid transparent; min-height: 320px;
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: translateY(6px) scale(.985); opacity: .4; } }
.fc.fc-m { border-top-color: var(--m); }
.fc.fc-f { border-top-color: var(--f); }
.fc.fc-n { border-top-color: var(--n); }
.fc.fc-c { border-top-color: var(--c); }
.fc-dir { font-size: 12px; font-weight: 700; letter-spacing: .08em; color: var(--hint); margin-bottom: 8px; }
.fc-tag-new.work { color: var(--lrn); background: rgba(232, 138, 12, .13); }
.fc-tag-new { display: inline-block; font-size: 11px; font-weight: 700; color: var(--new); background: rgba(59, 124, 244, .12); padding: 2px 8px; border-radius: 6px; margin-left: 6px; letter-spacing: .04em; }
.fc-main { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; min-height: 150px; }
.fc-word { font-size: 34px; font-weight: 600; line-height: 1.2; word-break: break-word; letter-spacing: -.01em; }
.fc-ru-big { font-size: 28px; font-weight: 600; line-height: 1.25; }
.fc-translit { color: var(--hint); font-size: 17px; margin-top: 6px; }
.fc-speak { margin-top: 10px; width: 46px; height: 46px; border-radius: 50%; background: var(--soft); display: grid; place-items: center; color: var(--accent); }
.fc-speak svg { width: 22px; height: 22px; }
.fc-speak.sm { width: 30px; height: 30px; margin: 0; flex: none; }
.fc-speak.sm svg { width: 16px; height: 16px; }
.fc-back { width: 100%; border-top: 1px solid var(--sep); margin-top: 18px; padding-top: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.fc-ru { font-size: 22px; font-weight: 600; }
.fc-tags { font-size: 13px; color: var(--hint); }
.fc-forms { font-size: 16px; background: var(--soft); padding: 6px 12px; border-radius: 10px; }
.fc-ex { width: 100%; text-align: left; background: var(--soft); border-radius: 14px; padding: 12px; margin-top: 4px; }
.fc-ex-gr { display: flex; gap: 10px; align-items: flex-start; font-size: 17px; }
.fc-ex-ru { color: var(--hint); font-size: 15px; margin-top: 4px; padding-left: 40px; }
.fc-note { font-size: 14px; color: var(--hint); }
.fc-hint { color: var(--hint); font-size: 13px; margin-top: 14px; }

.study-bottom { padding: 8px 16px 12px; }
.rates { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rate { border-radius: 14px; padding: 8px 2px 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-weight: 700; font-size: 14px; transition: transform .08s; white-space: nowrap; }
.rate:active { transform: scale(.96); }
.rate small { font-size: 12px; font-weight: 500; opacity: .85; }
.rate.r1 { background: rgba(229, 72, 77, .14); color: var(--again); }
.rate.r2 { background: rgba(232, 138, 12, .15); color: var(--hard); }
.rate.r3 { background: rgba(46, 165, 106, .15); color: var(--good); }
.rate.r4 { background: rgba(59, 124, 244, .14); color: var(--easy); }
.kbd-hint { text-align: center; font-size: 11px; color: var(--hint); margin-top: 6px; }

.done { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 6px; }
.done .em { font-size: 64px; }

/* шторка */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .4); animation: fade .15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 560px; margin: 0 auto;
  background: var(--bg); border-radius: 20px 20px 0 0; max-height: 92vh; overflow-y: auto;
  padding: 8px 16px calc(20px + var(--safe-b)); animation: up .22s cubic-bezier(.2, .8, .3, 1);
}
@keyframes up { from { transform: translateY(40%); opacity: .3; } }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--sep); margin: 2px auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.sheet-head h2 { flex: 1; margin: 0; }

.field { display: block; margin-top: 10px; }
.field > span { display: block; font-size: 13px; color: var(--hint); margin: 0 0 4px 4px; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--sep); background: var(--card); border-radius: 12px;
  padding: 11px 12px; font-size: 16px; outline: none;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }

.set-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--sep); min-height: 52px; }
.set-row:last-child { border-bottom: 0; }
.set-row .grow > div:first-child { font-weight: 500; }
.set-row select { max-width: 150px; text-overflow: ellipsis; }
.set-row input[type=time], .set-row select {
  border: 0; background: var(--soft); border-radius: 8px; padding: 6px 8px; font-size: 15px; color: var(--text); max-width: 170px;
}
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 34px; height: 34px; border-radius: 10px; background: var(--soft); font-size: 20px; font-weight: 600; }
.stepper b { min-width: 34px; text-align: center; font-variant-numeric: tabular-nums; }
.seg.small { margin: 0; }
.seg.small button { padding: 5px 8px; font-size: 13px; }
input[type=range] { width: 100%; accent-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 60;
  background: rgba(30, 30, 30, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); animation: fade .2s;
}
.empty { text-align: center; color: var(--hint); padding: 30px 16px; }
.notice { background: rgba(59, 124, 244, .1); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-top: 10px; }
.notice.warn { background: rgba(232, 138, 12, .12); }
.variants { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.wd-word { font-size: 30px; font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; margin-top: 8px; }
.kv dt { color: var(--hint); }
.kv dd { margin: 0; }
