:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --text: var(--tg-theme-text-color, #14171a);
  --hint: var(--tg-theme-hint-color, #808891);
  --accent: var(--tg-theme-button-color, #2f80d8);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d8453b);
  --good: #2e9f5b;
  --radius: 14px;
  --tabs-height: 54px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

h2 { margin: 0 0 4px; font-size: 18px; }
p { margin: 0; }
.muted { color: var(--hint); }
.small { font-size: 13px; }

main {
  min-height: 100%;
  padding: 16px 16px calc(var(--tabs-height) + var(--safe-bottom) + 16px);
}

.view { display: flex; flex-direction: column; gap: 12px; }

/* --- изучение --- */
#view-study { min-height: calc(100vh - var(--tabs-height) - var(--safe-bottom) - 32px); }
.study-head { display: flex; justify-content: space-between; font-size: 14px; }

.card {
  flex: 1;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px 18px;
  border: 0;
  border-radius: 22px;
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: center;
  cursor: pointer;
}
.card-front { font-size: 32px; font-weight: 650; line-height: 1.2; overflow-wrap: anywhere; }
.card-answer { display: flex; flex-direction: column; gap: 8px; animation: reveal .18s ease-out; }
.card-back { font-size: 22px; overflow-wrap: anywhere; }
.card-note { font-size: 15px; color: var(--hint); font-style: italic; overflow-wrap: anywhere; }
.card-note:empty { display: none; }
.card-hint { font-size: 13px; color: var(--hint); }

.quiz { cursor: default; }
.quiz-sentence { font-size: 21px; line-height: 1.45; overflow-wrap: anywhere; }
.quiz-sentence:empty, .card-front:empty, .card-hint:empty { display: none; }
.quiz-gap { display: inline-block; min-width: 4.5em; border-bottom: 2px solid var(--hint); }
.quiz-fill { font-weight: 650; color: var(--accent); }
.input.quiz-input { max-width: 340px; background: var(--bg); font-size: 18px; text-align: center; }
.quiz-input:disabled { opacity: 1; }
.quiz-input.right { border-color: var(--good); }
.quiz-input.wrong { border-color: var(--danger); }
.quiz-result { display: flex; flex-direction: column; gap: 8px; animation: reveal .18s ease-out; }
.quiz-verdict { font-weight: 650; }
.quiz-verdict.right { color: var(--good); }
.quiz-verdict.wrong { color: var(--danger); }

@keyframes reveal { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .card-answer, .quiz-result { animation: none; } }

.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; }
.empty-title { font-size: 20px; font-weight: 650; }
.empty .btn { flex: 0 0 auto; margin-top: 6px; padding: 0 22px; }

/* --- кнопки и поля --- */
.row { display: flex; gap: 10px; }

.btn {
  flex: 1;
  min-height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled { opacity: .5; }
.btn-plain { background: var(--surface); color: var(--text); }
.btn-good { background: var(--good); color: #fff; }
.btn-bad { background: var(--danger); color: #fff; }
.btn-danger { flex: 0 0 auto; width: 100%; background: transparent; color: var(--danger); }

.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  outline: none;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--hint); }
.area { resize: vertical; line-height: 1.35; }

/* --- список слов --- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.item-text { flex: 1; min-width: 0; }
.item-front { font-weight: 600; overflow-wrap: anywhere; }
.item-back { color: var(--hint); font-size: 14px; overflow-wrap: anywhere; }
.item-level { flex: 0 0 auto; font-size: 12px; color: var(--hint); font-variant-numeric: tabular-nums; }

/* --- настройки --- */
.group { border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.line { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 50px; padding: 8px 14px; }
.line + .line { border-top: 1px solid var(--bg); }
.line input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.line input[type="time"], .line select {
  padding: 6px 8px; border: 0; border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}

/* --- занятие дня --- */
.progress { height: 6px; border-radius: 3px; background: var(--surface); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.intro { cursor: default; }
.quiz-options { justify-content: center; }
.day-stats { width: 100%; text-align: left; }
.day-step { width: 100%; display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: var(--radius); background: var(--surface); }
.small-title { font-size: 17px; }
.segmented { display: flex; gap: 4px; padding: 3px; border-radius: 12px; background: var(--surface); }
.seg { flex: 1; min-height: 34px; border: 0; border-radius: 9px; background: transparent; color: var(--hint); font: inherit; font-size: 14px; cursor: pointer; }
.seg.active { background: var(--bg); color: var(--text); font-weight: 600; }
.line input.num { width: 72px; padding: 6px 8px; border: 0; border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; text-align: right; }
.item-level.hard { color: var(--danger); }

/* --- практика с ИИ --- */
.pr-menu, .pr-exercise, .pr-chat { display: flex; flex-direction: column; gap: 10px; }
.pr-body { display: flex; flex-direction: column; gap: 12px; }
.pr-text { font-size: 17px; line-height: 2.1; white-space: pre-wrap; overflow-wrap: anywhere; }
.pr-gap {
  width: auto; min-width: 5em; max-width: 100%; padding: 2px 6px; margin: 0 2px;
  border: 0; border-bottom: 2px solid var(--hint); border-radius: 6px 6px 0 0;
  background: var(--surface); color: var(--text); font: inherit; text-align: center; outline: none;
}
.pr-gap:focus { border-bottom-color: var(--accent); }
.pr-gap.right { border-bottom-color: var(--good); color: var(--good); }
.pr-gap.wrong { border-bottom-color: var(--danger); color: var(--danger); }
.pr-fix { margin-left: 2px; color: var(--good); font-weight: 600; }
.pr-hints { margin: 0; padding-left: 22px; color: var(--hint); font-size: 14px; }
.pr-item { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: var(--radius); background: var(--surface); }
.pr-sentence { font-size: 17px; overflow-wrap: anywhere; }
.pr-blank { display: inline-block; min-width: 3em; border-bottom: 2px solid var(--hint); text-align: center; }
.pr-blank.right { border-bottom-color: var(--good); color: var(--good); font-weight: 600; }
.pr-options { display: flex; flex-wrap: wrap; gap: 6px; }
.pr-option {
  padding: 8px 12px; border: 1px solid var(--hint); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit; cursor: pointer;
}
.pr-option.right { border-color: var(--good); background: var(--good); color: #fff; }
.pr-option.wrong { border-color: var(--danger); background: var(--danger); color: #fff; }
.pr-option:disabled { cursor: default; }
.pr-option:disabled:not(.right):not(.wrong) { opacity: .5; }
.pr-item .input { background: var(--bg); }
.pr-verdict { font-weight: 650; }
.pr-verdict.right { color: var(--good); }
.pr-verdict.wrong { color: var(--danger); }
.pr-score { font-weight: 650; text-align: center; }
.pr-group-title { margin-top: 6px; font-weight: 650; }
.pr-resume {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px 14px;
  border: 1px solid var(--accent); border-radius: var(--radius); background: var(--surface);
  color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.pr-bank { display: flex; flex-wrap: wrap; gap: 6px; }
.pr-chip { padding: 5px 10px; border-radius: 10px; background: var(--surface); font-size: 15px; }
.pr-chip.used { opacity: .4; text-decoration: line-through; }
select.pr-gap { min-width: 6em; text-align: left; }
.pr-letter { white-space: nowrap; }
.pr-letter b { color: var(--accent); }
.pr-letter .pr-gap { margin-left: 1px; min-width: 4em; }
.pr-hints-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.btn-small { flex: 0 0 auto; min-height: 34px; padding: 0 12px; font-size: 14px; }
.pr-translation { font-size: 15px; line-height: 1.5; }

/* чат во всю высоту, поле ввода внизу экрана */
body.chat-open main { padding-bottom: calc(var(--tabs-height) + var(--safe-bottom)); }
body.chat-open #view-practice { height: calc(var(--tg-viewport-height, 100vh) - var(--tabs-height) - var(--safe-bottom) - 16px); }
.pr-chat { min-height: 0; height: 100%; }
body.chat-open .pr-chat { gap: 8px; }
.pr-messages { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.pr-chat-empty { margin: auto 0; text-align: center; }
.pr-msg { max-width: 88%; padding: 9px 12px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.pr-msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); }
.pr-msg.assistant { align-self: flex-start; background: var(--surface); }
.pr-msg.pending { color: var(--hint); font-style: italic; }
.pr-compose { flex: 0 0 auto; display: flex; gap: 8px; align-items: flex-end; padding: 6px 0 10px; background: var(--bg); }
.pr-compose .input { flex: 1; resize: none; max-height: 120px; }
.pr-send { flex: 0 0 auto; width: 48px; padding: 0; font-size: 18px; }

/* --- вкладки --- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex;
  height: calc(var(--tabs-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg);
  border-top: 1px solid var(--surface);
}
.tab { flex: 1; border: 0; background: transparent; color: var(--hint); font: inherit; font-size: 14px; cursor: pointer; }
.tab.active { color: var(--accent); font-weight: 600; }

/* --- всплывающие панели --- */
.sheet { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; background: rgba(0, 0, 0, .45); }
.sheet-body {
  width: 100%; max-height: 92vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
  padding: 18px 16px calc(16px + var(--safe-bottom));
  border-radius: 20px 20px 0 0;
  background: var(--bg);
}
.result { padding: 10px 12px; border-radius: var(--radius); background: var(--surface); white-space: pre-wrap; overflow-wrap: anywhere; }

.blocker { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 32px; text-align: center; color: var(--hint); }

.toast {
  position: fixed; left: 16px; right: 16px; z-index: 20;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--text); color: var(--bg);
  font-size: 14px; text-align: center;
}
