:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1d2129);
  --hint: var(--tg-theme-hint-color, #8b919a);
  --link: var(--tg-theme-link-color, #2a7ae2);
  --btn: var(--tg-theme-button-color, #2a7ae2);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --ok: #2f9e5c;
  --bad: #d9483b;
  --warn: #e39a2d;
  --line: rgba(128, 128, 128, 0.28);
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 16px calc(28px + env(safe-area-inset-bottom));
}

h1 { font-size: 22px; line-height: 1.25; margin: 2px 0; }
p { margin: 8px 0; }
b { font-weight: 600; }

.ar, .ar-in {
  font-family: "Noto Naskh Arabic", "Geeza Pro", "Traditional Arabic", "Arabic Typesetting", serif;
}
.ar { direction: rtl; unicode-bidi: isolate; }
.ar-in { font-size: 1.15em; }

.sub, .hint { color: var(--hint); }
.sub { font-size: 14px; }
.center { text-align: center; }
.small { font-size: 13px; }
.mt { margin-top: 14px; }

.home-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.icon-btn {
  border: 0; background: var(--card); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; font-size: 19px; cursor: pointer; flex: none;
}

.section-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--hint); margin: 22px 4px 8px;
}

.card { background: var(--card); border-radius: 16px; padding: 14px 16px; }
.card + .card { margin-top: 10px; }

.review-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.review-card .btn { width: auto; flex: none; }
.big-num { font-size: 30px; font-weight: 700; line-height: 1.1; }

.lesson-card { cursor: pointer; }
.lesson-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.lesson-num { color: var(--hint); font-size: 13px; }
.lesson-title { font-weight: 600; margin-top: 2px; }
.lesson-ar { font-size: 21px; line-height: 1.6; }

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

.meta { color: var(--hint); font-size: 13px; margin-top: 7px; display: flex; gap: 14px; flex-wrap: wrap; }

.btn {
  display: block; width: 100%; border: 0; border-radius: 12px;
  padding: 13px 16px; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--btn); color: var(--btn-text);
}
.btn.secondary { background: transparent; color: var(--link); box-shadow: inset 0 0 0 1.5px var(--link); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.btn:disabled { opacity: 0.55; cursor: default; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.tabs { display: flex; background: var(--card); border-radius: 12px; padding: 3px; margin: 14px 0; }
.tabs button {
  flex: 1; border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 15px; padding: 8px 4px; border-radius: 9px; cursor: pointer;
}
.tabs button.active { background: var(--bg); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); }

/* карточки слов */
.session-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 2px 0; }
.flash {
  position: relative; min-height: 240px; margin-top: 14px;
  border-radius: 20px; background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px 18px; text-align: center; cursor: pointer; user-select: none;
}
.flash .ar-big { font-size: 42px; line-height: 1.75; }
.flash .ru { font-size: 22px; font-weight: 600; margin-top: 6px; }
.flash .note { color: var(--hint); font-size: 15px; margin-top: 10px; max-width: 460px; }
.flash .tap { color: var(--hint); font-size: 13px; margin-top: 14px; }
.speak {
  position: absolute; top: 8px; right: 8px; border: 0; background: transparent;
  font-size: 22px; cursor: pointer; padding: 8px; line-height: 1;
}

.word-list { margin-top: 12px; }
.w { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.w:last-child { border-bottom: 0; }
.w .ru-cell { flex: 1; font-size: 15px; }
.w .ar-cell { font-size: 21px; line-height: 1.6; text-align: right; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--line); }
.dot.learning { background: var(--warn); }
.dot.learned { background: var(--ok); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; margin-top: 10px; color: var(--hint); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

/* правило */
.rule h3 { font-size: 17px; margin: 22px 0 8px; }
.rule h3:first-child { margin-top: 4px; }
.rule ul { padding-left: 20px; margin: 8px 0; }
.rule li { margin: 7px 0; }
.rule .note { background: rgba(42, 122, 226, 0.1); border-radius: 12px; padding: 10px 14px; margin: 10px 0; }
.rule .ar-line {
  font-size: 23px; line-height: 1.8; text-align: center;
  background: var(--card); border-radius: 12px; padding: 8px 12px; margin: 10px 0;
}
.table-wrap { overflow-x: auto; margin: 10px 0; }
.rule table { width: 100%; border-collapse: collapse; font-size: 15px; }
.rule th, .rule td { border: 1px solid var(--line); padding: 8px 7px; text-align: left; vertical-align: middle; }
.rule th { background: var(--card); font-weight: 600; }

/* тест */
.q { font-size: 17px; font-weight: 600; margin: 12px 0 10px; }
.opt {
  display: block; width: 100%; text-align: left;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--text);
  border-radius: 12px; padding: 12px 14px; margin: 8px 0; font: inherit; cursor: pointer;
}
.opt.ar { text-align: right; font-size: 20px; line-height: 1.7; }
.opt.right { border-color: var(--ok); background: rgba(47, 158, 92, 0.14); }
.opt.wrong { border-color: var(--bad); background: rgba(217, 72, 59, 0.12); }
.opt:disabled { cursor: default; color: var(--text); }
.explain { background: var(--card); border-radius: 12px; padding: 12px 14px; margin: 12px 0; }

/* настройки */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-row select {
  font: inherit; padding: 7px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; background: var(--line); border-radius: 15px; cursor: pointer; transition: background 0.2s;
}
.switch span::before {
  content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(20px); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(20, 20, 20, 0.88); color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; z-index: 10; max-width: 90%; text-align: center;
}
