/* Цвета — из темы Telegram (светлая/тёмная — как в самом Telegram); запасные — для проверки в обычном браузере. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f1f5);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: var(--tg-theme-accent-text-color, var(--link));
  --head: var(--tg-theme-section-header-text-color, var(--hint));
  --danger: var(--tg-theme-destructive-text-color, #e5393b);
  --ok: #2f9e55;
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--btn) 12%, transparent);
  --fs: 21px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
a { color: var(--link); text-decoration: none; }
h1 { font-size: 22px; margin: 0; line-height: 1.25; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--head); margin: 22px 16px 6px; font-weight: 600; }
button, .btn, input, textarea, select { font: inherit; color: inherit; }

.top { padding: 18px 16px 6px; }
.sub { color: var(--hint); font-size: 14px; margin-top: 3px; }
.meta { color: var(--hint); font-size: 14px; margin-top: 4px; }
.hint { color: var(--hint); font-size: 14px; }
.pad { padding: 10px 12px; }
.stack > * + * { margin-top: 8px; }
.center { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 10px; }
.big { font-size: 44px; margin: 0; }

.card { background: var(--section); border-radius: 14px; padding: 14px 16px; margin: 10px 12px; }
.card.book { cursor: pointer; }
.card .title { font-weight: 600; font-size: 17px; }
.card.empty { color: var(--hint); }
.info > div:not(.bar) { padding: 3px 0; }

.bar { height: 6px; border-radius: 3px; background: var(--line); margin-top: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--btn); border-radius: 3px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 11px 16px; min-height: 44px;
  background: var(--soft); color: var(--accent); font-weight: 500; cursor: pointer;
}
button:disabled { opacity: .5; }
button.primary { background: var(--btn); color: var(--btn-text); }
button.success { background: var(--ok); color: #fff; }
button.danger { color: var(--danger); }
.wide { width: 100%; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.row-btns > * { flex: 1 1 auto; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { min-height: 36px; padding: 7px 13px; border-radius: 18px; font-size: 15px; }
.chip.on, .row.on { background: var(--btn); color: var(--btn-text); }

.list { padding: 4px 0; }
.list .row {
  display: flex; flex-direction: column; align-items: flex-start; width: 100%; text-align: start;
  background: none; color: var(--text); border-radius: 0; padding: 12px 16px; min-height: 48px; font-weight: 400;
}
.list .row + .row, .list .row + .acts, .list .acts + .row { border-top: 1px solid var(--line); }
.list .row small { color: var(--hint); font-size: 13px; margin-top: 2px; }
.list .row > span[dir], .list .row > small[dir] { display: block; width: 100%; text-align: start; }
.list .row.sel { background: var(--soft); }
.list .row.on { background: var(--btn); color: var(--btn-text); }
.list .row.off { color: var(--hint); }
.list .acts { display: flex; flex-direction: column; gap: 8px; padding: 10px 16px 14px; background: var(--soft); }
.lessons .row { flex-direction: row; justify-content: space-between; gap: 10px; }
.lessons .row span:last-child { color: var(--hint); font-size: 14px; white-space: nowrap; }

form { display: flex; flex-direction: column; gap: 10px; margin: 0; }
input, textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 11px 12px;
  font-size: 17px; outline: none;
}
input:focus, textarea:focus { border-color: var(--btn); }
textarea { resize: vertical; min-height: 96px; }
label.field { display: flex; flex-direction: column; gap: 6px; color: var(--hint); font-size: 14px; margin-top: 12px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > * { flex: 1; }

/* урок */
.lesson-head { padding: 16px 16px 0; }
.lesson-head h3 { font-size: 20px; margin: 0 0 4px; }
.lesson-head p { margin: 0; color: var(--hint); font-size: 14px; }
.tools { display: flex; gap: 8px; padding: 10px 12px 0; flex-wrap: wrap; }
.tools > * { min-height: 36px; padding: 6px 12px; font-size: 15px; }
.audio audio { width: 100%; }
.audio .hint { margin-top: 6px; }
.text { background: var(--section); margin: 10px 12px; padding: 6px 18px 12px; border-radius: 14px; font-size: var(--fs); line-height: 1.75; overflow-wrap: anywhere; }
.text.ar, .ar { font-family: "Geeza Pro", "SF Arabic", "Noto Naskh Arabic", "Amiri", -apple-system, sans-serif; }
.text.ar { line-height: 2.05; }
.text p { margin: .7em 0; }
.text h4, .text h5 { margin: 1.1em 0 .4em; color: var(--accent); }
.text h4 { font-size: 1.08em; }
.text h5 { font-size: 1em; }
.text details { margin: .6em 0; font-size: .82em; color: var(--hint); }
.text details summary { cursor: pointer; }
.text b { font-weight: 700; }
.text i { color: var(--hint); font-style: normal; font-size: .8em; }

/* разъяснение */
.expl h3 { font-size: 18px; margin: 4px 0 8px; }
.expl p { margin: .5em 0; }
.expl details { border-top: 1px solid var(--line); padding: 10px 0; }
.expl details summary { font-weight: 600; cursor: pointer; list-style-position: outside; }
.expl blockquote { margin: 8px 0 0; padding: 8px 12px; border-inline-start: 3px solid var(--btn); background: var(--soft); border-radius: 8px; }
.expl cite { display: block; color: var(--hint); font-size: 13px; margin-top: 4px; font-style: normal; }
.expl.ar { font-size: 18px; line-height: 1.9; }
.ai p { margin: .5em 0; }
.ai blockquote { margin: 8px 0; padding: 6px 12px; border-inline-start: 3px solid var(--btn); background: var(--soft); border-radius: 8px; }

/* тест и экзамен */
.progress { display: flex; justify-content: space-between; color: var(--hint); font-size: 14px; }
.q { font-size: 18px; font-weight: 600; margin: 10px 0 4px; line-height: 1.5; }
.q.ar { font-size: 21px; line-height: 1.8; }
.opts { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.opt { justify-content: flex-start; text-align: start; background: var(--bg2); color: var(--text); font-weight: 400; padding: 12px 14px; line-height: 1.4; }
.opt .l { font-weight: 700; color: var(--accent); min-width: 1.4em; }
.opt.right { background: color-mix(in srgb, var(--ok) 20%, transparent); }
.opt.wrong { background: color-mix(in srgb, var(--danger) 18%, transparent); }
.opt.ar { font-size: 19px; }
.opt:disabled { opacity: 1; }
.opt:disabled:not(.right):not(.wrong) { opacity: .55; }
.verdict { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--bg2); }
.verdict.good { background: color-mix(in srgb, var(--ok) 16%, transparent); }
.verdict.bad { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.score { font-size: 40px; font-weight: 700; text-align: center; margin: 6px 0 0; }
.item { border-top: 1px solid var(--line); padding: 10px 0; }
.item:first-of-type { border-top: 0; }
.item .ok { color: var(--ok); }
.item .no { color: var(--danger); }

.pager { display: flex; justify-content: space-between; gap: 8px; padding: 6px 12px; }
.pager > * { flex: 1; }

.spin { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--btn); border-radius: 50%; animation: spin .8s linear infinite; }
.spin.small { width: 16px; height: 16px; border-width: 2px; display: inline-block; vertical-align: -3px; margin-inline-end: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 10;
  background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--bg); padding: 12px 14px; border-radius: 12px;
  font-size: 15px; box-shadow: 0 6px 24px rgba(0, 0, 0, .2);
}
#toast.bad { background: var(--danger); color: #fff; }
