@font-face {
  font-family: 'QuranFont';
  src: url('fonts/MY_QURAN_FONT.TTF') format('truetype');
  font-display: swap;
}

:root {
  --bg: #f6f3ec;
  --paper: #fffdf8;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #e4ded1;
  --izhar: #2f6db3;
  --idgham: #2a8a55;
  --iqlab: #cf6d17;
  --ikhfa: #b8365c;
  --dk: #c9423a;
  --weak: #d99a1c;
  --good: #2a8a55;
  --radius: 22px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(60,45,20,.10);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }

.ar, [lang="ar"] {
  font-family: 'QuranFont', 'Amiri', 'Traditional Arabic', serif;
  font-weight: normal;
  direction: rtl;
  unicode-bidi: isolate;
}

/* ===== Стартовая и итог ===== */
.project-header { flex: none; width: min(calc(100% - 36px), 524px); margin: env(safe-area-inset-top) auto 0; }
.screen { flex: 1 0 auto; }
.home-wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
}
.home-head { text-align: center; margin: 4px 0 14px; }
.home-ar { font-size: 44px; line-height: 1.4; color: var(--ikhfa); }
h1 { font-size: 26px; margin: 2px 0 4px; letter-spacing: -.01em; }
.home-sub { margin: 0; color: var(--muted); font-size: 16px; }
.intro { font-size: 17px; line-height: 1.5; margin: 0 0 14px; }
.intro .ar { font-size: 1.45em; line-height: 1; }

.rules { display: grid; gap: 10px; }
.rule {
  background: var(--paper);
  border-radius: 16px;
  padding: 12px 14px 10px;
  border-top: 6px solid var(--c);
  box-shadow: var(--shadow);
  text-align: center;
}
.rule-title { display: block; font-size: 21px; color: var(--c); }
.rule-groups { display: flex; justify-content: center; gap: 10px 28px; flex-wrap: wrap; margin-top: 2px; }
.rule-group { display: flex; flex-direction: column; align-items: center; }
.rule-letters {
  font-size: 34px; line-height: 1.5; color: var(--ink); word-spacing: .2em;
}
.rule-group + .rule-group { border-right: 2px solid var(--line); padding-right: 28px; }
.rule-group small { font-size: 14px; color: var(--muted); margin-top: -2px; }

.progress-box {
  margin-top: 16px; background: var(--paper); border-radius: 16px;
  padding: 14px 16px; box-shadow: var(--shadow);
}
.pb-top { display: flex; justify-content: space-between; font-size: 17px; margin-bottom: 8px; }
.bar { height: 10px; background: #ebe5d8; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--good); border-radius: 99px; transition: width .35s ease; }
.pb-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 7px; }
.pb-list li { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; font-size: 15px; }
.pb-list .bar { grid-column: 1 / -1; height: 6px; }
.pb-list .bar i { background: var(--c, var(--good)); }
.pb-list span:last-of-type { color: var(--muted); font-variant-numeric: tabular-nums; }

.home-actions { display: grid; gap: 10px; margin-top: 18px; }
.btn {
  min-height: 56px; border: 0; border-radius: 16px; font-size: 18px; font-weight: 600;
  background: var(--paper); box-shadow: var(--shadow); cursor: pointer;
}
.btn.primary { background: var(--ink); color: #fff; }
.btn.danger { background: var(--dk); color: #fff; }
.btn:active { transform: scale(.98); }

/* ===== Тест ===== */
#test {
  flex: 1 1 0; min-height: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%; max-width: 560px; margin: 0 auto;
}
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px 6px; }
.icon-btn {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 14px;
  background: var(--paper); box-shadow: var(--shadow); cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.top-prog { flex: 1; display: flex; align-items: center; gap: 10px; }
.top-prog .bar { flex: 1; }
.top-prog span { font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.card-area { min-height: 0; padding: 8px 14px; perspective: 1400px; }
.card {
  position: relative; width: 100%; height: 100%;
  cursor: pointer; outline: none;
  -webkit-user-select: none; user-select: none;
}
.card-inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.3,.7,.3,1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.card.no-anim .card-inner { transition: none; }
.face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow);
  border-top: 7px solid var(--c, #c9bfa9);
  display: flex; flex-direction: column; align-items: center;
  padding: 18px 18px 16px; overflow: hidden; text-align: center;
}
.face.back { transform: rotateY(180deg); }

.tag {
  font-size: 14px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); flex: none;
}
.task { font-size: 21px; font-weight: 600; color: var(--ink); text-transform: none; letter-spacing: 0; flex: none; }
.face-body {
  flex: 1; min-height: 0; width: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
.qtext { font-size: 56px; line-height: 1.35; font-weight: 600; max-width: 100%; }
.atext { font-size: 56px; line-height: 1.4; max-width: 100%; }
.qtext .ar, .atext .ar { font-size: 1.6em; line-height: 1.25; font-weight: normal; white-space: nowrap; }
.hint { flex: none; font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.hint svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.ex-img {
  display: block; width: 92%; max-width: 100%;
  max-height: 100%; min-height: 0; flex: 0 1 auto;
  object-fit: contain;
  pointer-events: none;
}
.rule-name { font-size: 30px; font-weight: 700; color: var(--c); line-height: 1.15; flex: none; }
.rule-letters-back { font-size: 40px; line-height: 1.5; word-spacing: .25em; color: var(--ink); flex: none; max-width: 100%; }
.rule-name small { display: block; font-size: 30px; font-weight: normal; margin-top: 4px; }

.audio-btn {
  flex: none; width: 64px; height: 64px; border-radius: 50%; border: 0;
  background: var(--c); color: #fff; cursor: pointer;
  display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,.15);
}
.audio-btn svg { width: 30px; height: 30px; fill: currentColor; }
.audio-btn.playing { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }

.grades {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  padding: 8px 14px calc(12px + env(safe-area-inset-bottom));
}
.grade {
  min-height: 60px; border: 0; border-radius: 16px; cursor: pointer;
  font-size: 18px; font-weight: 700; color: #fff;
  transition: opacity .2s, filter .2s, transform .1s;
}
.g-dk { background: var(--dk); }
.g-weak { background: var(--weak); }
.g-good { background: var(--good); }
.grade:disabled { background: #d9d3c6; color: #8f8a80; cursor: default; }
.grade:not(:disabled):active { transform: scale(.96); }

/* ===== Итог ===== */
.done-wrap { text-align: center; padding-top: 40px; }
.done-badge {
  width: 84px; height: 84px; margin: 0 auto 12px; border-radius: 50%;
  background: var(--good); display: grid; place-items: center;
}
.done-badge svg { width: 46px; height: 46px; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.done-sum { font-size: 18px; line-height: 1.5; color: #3b3f45; }
.hard-box { text-align: left; margin-top: 18px; background: var(--paper); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow); }
.hard-box h2 { font-size: 17px; margin: 0 0 8px; }
.hard-box ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.hard-box li { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 15.5px; }
.hard-box li:first-child { border-top: 0; }
.hard-box li img { height: 46px; width: auto; flex: none; }
.hard-box li .hl-text { flex: 1; }
.hard-box li .hl-text .ar { font-size: 1.4em; }
.hard-box li .hl-cnt { color: var(--muted); font-size: 14px; white-space: nowrap; }

/* ===== Диалог ===== */
.dialog { position: fixed; inset: 0; background: rgba(20,18,14,.45); display: grid; place-items: center; padding: 20px; z-index: 10; }
.dialog-box { background: var(--paper); border-radius: 20px; padding: 20px; width: 100%; max-width: 360px; box-shadow: var(--shadow); }
.dialog-box h3 { margin: 0 0 6px; font-size: 20px; }
.dialog-box p { margin: 0 0 16px; color: #3b3f45; font-size: 16px; }
.dialog-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Невысокие экраны */
@media (max-height: 620px) {
  .grade { min-height: 56px; }
  .face { padding: 12px 14px 12px; }
  .rule-name { font-size: 26px; }
  .audio-btn { width: 54px; height: 54px; }
  .rule-letters-back { font-size: 32px; }
}
.qtext .ar.wrap, .atext .ar.wrap { white-space: normal; }

.audio-err { font-size: 14px; color: var(--dk); max-width: 90%; flex: none; }
