@font-face { font-family: 'Amiri'; font-weight: 400; font-display: swap; src: url('../fonts/amiri-400.woff2') format('woff2'); }
@font-face { font-family: 'Amiri'; font-weight: 700; font-display: swap; src: url('../fonts/amiri-700.woff2') format('woff2'); }
@font-face { font-family: 'Scheherazade New'; font-display: swap; src: url('../fonts/scheherazade.woff2') format('woff2'); }
@font-face { font-family: 'Noto Naskh Arabic'; font-display: swap; src: url('../fonts/noto-naskh.woff2') format('woff2'); }
@font-face { font-family: 'Markazi Text'; font-display: swap; src: url('../fonts/markazi.woff2') format('woff2'); }
@font-face { font-family: 'Lateef'; font-display: swap; src: url('../fonts/lateef.woff2') format('woff2'); }
@font-face { font-family: 'Cairo'; font-display: swap; src: url('../fonts/cairo.woff2') format('woff2'); }

:root {
  --bg: #f6f4ef; --surface: #fff; --surface-2: #efece4; --text: #1f2421; --muted: #6b716c;
  --line: #e1ddd2; --accent: #1f6f5c; --accent-2: #e5f1ec; --mask: #d9d6ce;
  --blue: #1d5fc2; --red: #c0352b; --yellow: #c99400; --green: #2c8a4b;
  --play: #fff3c4; --play-line: #e2b300;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  --ar: 'Amiri', 'Traditional Arabic', serif;
  color-scheme: light dark;
  --fs: 1; --ar-k: 1; --ar-lh: 2.1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816; --surface: #1d2320; --surface-2: #262d29; --text: #e8ebe8; --muted: #9aa39d;
    --line: #313a35; --accent: #5cc3a5; --accent-2: #1f3a31; --mask: #3a423e;
    --blue: #6ea8ff; --red: #ff7a6e; --yellow: #f0c04a; --green: #5ccf82;
    --play: #3d3615; --play-line: #c9a227; --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

.ar, [lang="ar"] { font-family: var(--ar); line-height: var(--ar-lh); }
.ar-big { font-size: calc(36px * var(--fs) * var(--ar-k)); }
.ar-mid { font-size: calc(30px * var(--fs) * var(--ar-k)); }
.g-m { color: var(--blue); }
.g-f { color: var(--red); }

/* ---------- Каркас ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px max(16px, env(safe-area-inset-left));
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar-mid { flex: 1; min-width: 0; }
.brand { display: flex; align-items: baseline; gap: 10px; font-weight: 700; font-size: 19px; white-space: nowrap; overflow: hidden; }
.brand-ru { overflow: hidden; text-overflow: ellipsis; }
.font-btns { display: flex; gap: 4px; }
.icon-btn.font-btn { font-size: 16px; font-weight: 700; gap: 1px; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; padding: 0 6px; line-height: 1; height: 44px; }
.font-btn:disabled { opacity: .35; cursor: default; }
.a-small { font-size: 14px; }
.a-big { font-size: 20px; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 220px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 46px; padding: 8px 12px; border: 0; border-radius: 10px;
  background: none; text-decoration: none; color: var(--text); font-size: 17px; cursor: pointer; text-align: left;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); }
.menu-item[aria-current="page"] { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.menu-ico { width: 24px; text-align: center; }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }
@media (max-width: 420px) {
  .topbar { gap: 6px; }
  .brand-ar { display: none; }
  .font-btns { gap: 2px; }
}
.brand-ar { font-family: var(--ar); font-size: 28px; color: var(--accent); line-height: 1.4; }
.lesson-title { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.lesson-title strong { font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lesson-title .muted { font-size: 14px; }
.icon-btn {
  min-width: 44px; min-height: 44px; display: grid; place-items: center; border: 0; border-radius: 12px;
  background: var(--surface-2); font-size: 22px; text-decoration: none; color: var(--text); cursor: pointer;
}
.page { max-width: 1100px; margin: 0 auto; padding: 18px 16px 40px; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 18px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer;
  text-decoration: none; color: var(--text); font-weight: 500; user-select: none;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(1); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0f1a16; } }
.btn-red { background: var(--red); border-color: var(--red); color: #fff; }
.btn-ghost { background: transparent; }
.g-no { background: var(--red); border-color: var(--red); color: #fff; }
.g-weak { background: var(--yellow); border-color: var(--yellow); color: #1c1600; }
.g-good { background: var(--green); border-color: var(--green); color: #fff; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg-btn { border: 0; background: transparent; min-height: 40px; padding: 6px 14px; border-radius: 10px; cursor: pointer; }
.seg-btn[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
section > .seg { margin-bottom: 14px; }
@media (max-width: 600px) {
  .seg:not(.speed) { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
  .seg:not(.speed) .seg-btn { padding: 6px 4px; font-size: 14px; line-height: 1.2; }
  .toolbar .btn { width: 100%; }
}
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 12px; }

/* ---------- Главная ---------- */
.continue { width: 100%; margin-bottom: 18px; min-height: 52px; font-size: 18px; }
.lesson-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
@media (max-width: 520px) { .lesson-grid { grid-template-columns: 1fr 1fr; gap: 10px; } }
.lesson-card {
  background: var(--surface); border-radius: var(--radius); overflow: hidden; text-decoration: none; color: inherit;
  box-shadow: var(--shadow); border: 1px solid var(--line); display: flex; flex-direction: column; transition: transform .15s;
}
.lesson-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.cover { aspect-ratio: 16 / 9; background: var(--accent-2); display: grid; place-items: center; position: relative; }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-num { font-family: var(--ar); font-size: 54px; color: var(--accent); line-height: 1; }
.badge-watched { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.lc-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.lc-num { font-size: 13px; color: var(--muted); }
.lc-title { font-weight: 600; line-height: 1.3; flex: 1; }
.lc-status { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.st-progress { background: #fff1c7; color: #7a5a00; }
.st-done { background: #d7f2df; color: #1d6b37; }
@media (prefers-color-scheme: dark) { .st-progress { background: #4a3d10; color: #ffd866; } .st-done { background: #18402a; color: #7ee2a0; } }

/* ---------- Урок ---------- */
.tabs-wrap { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; max-width: 1100px; margin: 0 auto; padding: 8px 16px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; min-height: 44px; display: flex; align-items: center; padding: 6px 14px; border-radius: 10px;
  text-decoration: none; color: var(--muted); font-weight: 500; white-space: nowrap;
}
.tab { gap: 8px; }
.tab-ico { display: inline-grid; place-items: center; flex: none; }
.tab-ico svg { display: block; }
.tab[aria-selected="true"] { background: var(--accent); color: #fff; }
.tab:not([aria-selected="true"]):hover { color: var(--text); background: var(--surface-2); }
/* Телефон: только иконки, вкладки делят ширину поровну */
@media (max-width: 700px) {
  .tabs { padding: 6px 8px; gap: 2px; overflow: visible; }
  .tab { flex: 1 1 0; justify-content: center; padding: 6px 0; min-width: 44px; }
  .tab-ico svg { width: 24px; height: 24px; }
  .tab-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
@media (prefers-color-scheme: dark) { .tab[aria-selected="true"] { color: #0f1a16; } }

.pager { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-top: 32px; }
.pager > :first-child { justify-self: start; }
.pager > :last-child { justify-self: end; }
.pager-mid { text-align: center; white-space: nowrap; }
.pager-btn { white-space: nowrap; }
.pager-arrow { font-size: 20px; line-height: 1; }
@media (max-width: 600px) {
  .pager-label { display: none; }
  .pager-btn { width: 52px; min-height: 48px; padding: 0; }
  .pager-arrow { font-size: 24px; }
}

.line { cursor: pointer; transition: background .15s, box-shadow .15s; outline-offset: 2px; }
.line.playing, .story-s.playing, .story-ru-s.playing { background: var(--play); box-shadow: 0 0 0 2px var(--play-line); }

/* Видео */
.video-wrap { aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); overflow: hidden; }
.video-wrap video { width: 100%; height: 100%; display: block; }

/* Словарь */
.word-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.word-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  text-align: center; display: flex; flex-direction: column; justify-content: center; min-height: 140px; box-shadow: var(--shadow);
}
.word-card .ar-big { display: block; }
.forms { font-size: calc(14px * var(--fs)); margin-bottom: 4px; display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 2px 8px; }
.form { unicode-bidi: isolate; white-space: nowrap; }
.sep { color: var(--muted); }
.forms .ar { font-size: calc(22px * var(--fs) * var(--ar-k)); line-height: 1.8; }
.ru-line { font-size: calc(17px * var(--fs)); }
.story-ru { font-size: calc(17px * var(--fs)); }
.lc-title { font-size: calc(17px * var(--fs)); }

/* Предложения */
.sent-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.sent { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.num { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 14px; color: var(--muted); margin-top: 12px; }
.sent-body { flex: 1; display: grid; gap: 2px; }
.ar-line { text-align: right; }
@media (min-width: 900px) {
  .sent-body { grid-template-columns: 1fr 1fr; align-items: center; gap: 20px; }
  .sent-body .ru-line { order: -1; }
}

/* Диалог: реплики на всю ширину, у каждого участника свой фон */
.chat { display: flex; flex-direction: column; gap: 10px; }
.bubble { border: 1px solid transparent; border-radius: var(--radius); padding: 10px 16px; background: var(--sp-bg); border-color: var(--sp-line); }
.sp-0 { --sp-bg: #ffffff; --sp-line: #e1ddd2; }
.sp-1 { --sp-bg: #e4f1ec; --sp-line: #c4e0d5; }
.sp-2 { --sp-bg: #fdf0dc; --sp-line: #f0d9b0; }
.sp-3 { --sp-bg: #e6eefb; --sp-line: #c8d8f2; }
.sp-4 { --sp-bg: #f6e6f0; --sp-line: #e8c9dc; }
@media (prefers-color-scheme: dark) {
  .sp-0 { --sp-bg: #1d2320; --sp-line: #313a35; }
  .sp-1 { --sp-bg: #1c3a30; --sp-line: #2b5444; }
  .sp-2 { --sp-bg: #3a2f1b; --sp-line: #5a4627; }
  .sp-3 { --sp-bg: #1f2c42; --sp-line: #30436a; }
  .sp-4 { --sp-bg: #3a2333; --sp-line: #573449; }
}

/* Рассказ */
.story { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; }
.story-ar { font-family: var(--ar); font-size: calc(32px * var(--fs) * var(--ar-k)); line-height: 2.3; margin: 0 0 14px; text-align: right; }
.story-s { cursor: pointer; border-radius: 6px; padding: 0 2px; }
.story-ru { margin: 0; border-top: 1px solid var(--line); padding-top: 12px; }
.story-ru-s { border-radius: 4px; }

/* Скрытие сторон: серая плашка той же высоты */
.mode-hide-ru .ru-t, .mode-hide-ar .line .ar {
  color: transparent !important; background: var(--mask); border-radius: 6px; user-select: none;
  -webkit-touch-callout: none;
}
.mode-hide-ar .line .ar * { color: transparent !important; }
.mode-hide-ru .line.reveal .ru-t, .mode-hide-ar .line.reveal .ar, .mode-hide-ar .story-s.reveal,
.mode-hide-ar .line.reveal .ar *, .mode-hide-ar .story-s.reveal * { color: inherit !important; background: transparent; }
.mode-hide-ar .line.reveal .ar .g-m, .mode-hide-ar .story-s.reveal .g-m { color: var(--blue) !important; }
.mode-hide-ar .line.reveal .ar .g-f, .mode-hide-ar .story-s.reveal .g-f { color: var(--red) !important; }
@media (hover: hover) {
  .mode-hide-ru .ru-t:hover { color: inherit !important; background: transparent; }
  .mode-hide-ar .line .ar:hover, .mode-hide-ar .story-s:hover { color: inherit !important; background: transparent; }
  .mode-hide-ar .line .ar:hover *, .mode-hide-ar .story-s:hover * { color: inherit !important; }
}
.mode-hide-ru .line, .mode-hide-ar .line, .mode-hide-ar .story-s { -webkit-user-select: none; user-select: none; }


/* ---------- Тест ---------- */
.sec-test, .sec-tr { max-width: 560px; margin: 0 auto; }
.test-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.counter { font-weight: 600; }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0 16px; }
.progress-bar { height: 100%; background: var(--green); transition: width .3s; }
.flip { display: block; width: 100%; aspect-ratio: 1; border: 0; padding: 0; background: none; perspective: 1400px; cursor: pointer; }
.flip-inner { position: relative; width: 100%; height: 100%; transition: transform .4s; transform-style: preserve-3d; }
.flip.is-flipped .flip-inner { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: var(--radius); overflow: hidden; background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line); }
.face img { width: 100%; height: 100%; object-fit: cover; }
.back { transform: rotateY(180deg); }
.grades { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.hint-keys { text-align: center; font-size: 14px; }
@media (hover: none) { .hint-keys { display: none; } }
.done-box { text-align: center; padding: 30px 16px; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); }
.done-box h3 { margin: 6px 0; font-size: 22px; }
.done-icon { width: 64px; height: 64px; border-radius: 50%; background: var(--green); color: #fff; font-size: 34px; display: grid; place-items: center; margin: 0 auto; }

/* ---------- Запиши перевод ---------- */
.tr-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 14px; margin-top: 12px; box-shadow: var(--shadow); }
.tr-ru { font-size: calc(21px * var(--fs)); font-weight: 600; text-align: center; }
.tr-ar { min-height: 76px; display: grid; place-items: center; border-radius: 12px; }
.hidden-ar { background: var(--mask); }
.dots { font-size: 28px; color: var(--muted); }
.tr-ar-line { display: flex; align-items: center; gap: 10px; padding: 0 12px; border-radius: 10px; cursor: pointer; transition: background .15s, box-shadow .15s; }
.tr-ar-line.playing { background: var(--play); box-shadow: 0 0 0 2px var(--play-line); }
.ico { font-size: 18px; }
.rec-row { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
.btn-rec { min-width: 160px; background: var(--accent); border-color: var(--accent); color: #fff; font-size: 18px; }
.btn-rec.recording { background: var(--red); border-color: var(--red); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(192,53,43,.15); } }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); }
.meter { width: 90px; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter-bar { height: 100%; width: 0; background: var(--green); transition: width .08s; }
.tr-after { display: grid; gap: 10px; }
.tr-after .g-good, .tr-after .g-no { flex: 1; }
.mic-help:empty { display: none; }
.mic-help { text-align: center; background: var(--surface-2); padding: 10px; border-radius: 12px; }

/* ---------- Прочее ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--surface); border-radius: 18px; padding: 20px; max-width: 420px; width: 100%; display: grid; gap: 12px; }
.modal-box h3, .modal-box p { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast, .update-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: max(16px, env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 14px; z-index: 60;
  display: flex; gap: 12px; align-items: center; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.center-box { max-width: 420px; margin: 12vh auto; text-align: center; padding: 16px; }
.big-icon { font-size: 52px; }
.boot { display: grid; place-items: center; min-height: 60vh; color: var(--muted); }

/* Настройки: выбор арабского шрифта */
.settings-box { max-width: 480px; max-height: calc(100vh - 32px); overflow-y: auto; }
.settings-box h4 { margin: 6px 0 0; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.font-list { display: grid; gap: 6px; }
.font-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 6px 12px; min-height: 56px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; text-align: left;
}
.font-opt:hover { border-color: var(--accent); }
.font-opt[aria-checked="true"] { border: 2px solid var(--accent); background: var(--accent-2); padding: 5px 11px; }
.font-opt-name { display: flex; flex-direction: column; line-height: 1.25; font-size: 15px; }
.font-opt-name .muted { font-size: 13px; }
.font-sample { line-height: 1.9; white-space: nowrap; }
@media (max-width: 420px) { .font-opt { flex-direction: column; align-items: stretch; } .font-sample { text-align: right; } }
.tr-after .btn { white-space: nowrap; padding-left: 12px; padding-right: 12px; }

/* Рассказ: режим «Учить» — предложение и перевод блоками */
.sec-story .seg:not(.speed) { grid-template-columns: repeat(2, 1fr); }
.story-learn { display: grid; gap: 10px; }
.story-block {
  display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; cursor: pointer; transition: background .15s, box-shadow .15s;
}
.story-block.playing { background: var(--play); box-shadow: 0 0 0 2px var(--play-line); }
.story-block-body { flex: 1; min-width: 0; }
.story-block-ru { font-size: calc(17px * var(--fs)); color: var(--muted); }
