:root {
  --bg: #f7f5ef;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --line: #e2ded3;
  --accent: #0f5132;
  --accent-text: #ffffff;
  --ok: #157347;
  --bad: #c62828;
  --bad-bg: #fde8e8;
  --hint: #b26a00;
  --hint-bg: #fff3dc;
  --hidden: #d9d4c7;
  --current: #0f5132;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121412;
    --surface: #1c1f1c;
    --text: #ecebe6;
    --muted: #9a9a93;
    --line: #2e322e;
    --accent: #3fae78;
    --accent-text: #08130d;
    --ok: #5cc98e;
    --bad: #ff6b6b;
    --bad-bg: #3a1c1c;
    --hint: #ffb547;
    --hint-bg: #3a2a10;
    --hidden: #3a3f3a;
    --current: #3fae78;
  }
}
:root[data-theme="dark"] {
  --bg: #121412;
  --surface: #1c1f1c;
  --text: #ecebe6;
  --muted: #9a9a93;
  --line: #2e322e;
  --accent: #3fae78;
  --accent-text: #08130d;
  --ok: #5cc98e;
  --bad: #ff6b6b;
  --bad-bg: #3a1c1c;
  --hint: #ffb547;
  --hint-bg: #3a2a10;
  --hidden: #3a3f3a;
  --current: #3fae78;
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

.view { min-height: 100dvh; display: flex; flex-direction: column; }

.bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--accent); color: var(--accent-text);
}
.bar h1 { margin: 0; font-size: 1.15rem; font-weight: 600; flex: 1; }
.back {
  border: 0; background: transparent; color: inherit;
  font-size: 1.5rem; padding: 0 8px 0 0; cursor: pointer;
}

.tabs { display: flex; gap: 6px; padding: 12px 16px 0; }
.tab {
  flex: 1; padding: 10px; font-size: .95rem; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
.tab.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.sel-panel { padding: 16px; }
.sel-help { margin: 0 0 12px; color: var(--muted); font-size: .9rem; }
.sel-info { min-height: 1.4em; margin: 0 0 12px; font-size: .9rem; }
.range select {
  display: block; width: 100%; margin-top: 4px; padding: 10px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text);
}
.surah-head {
  text-align: center; margin: 12px 0 4px; padding: 4px 0;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  color: var(--accent); font-size: .9em;
}

.search { padding: 12px 16px; }
.search input {
  width: 100%; padding: 12px 14px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
}

.surah-list { list-style: none; margin: 0; padding: 0 16px 24px; }
.surah-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  cursor: pointer;
}
.surah-list .num {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
  background: var(--bg); color: var(--accent); font-weight: 600; font-size: .9rem;
}
.surah-list .info { flex: 1; min-width: 0; }
.surah-list .en { font-weight: 500; }
.surah-list .count { color: var(--muted); font-size: .85rem; }
.surah-list .ar { font-family: "Amiri Quran", serif; font-size: 1.3rem; }

.sheet {
  position: fixed; inset: 0; z-index: 10;
  background: rgb(0 0 0 / .45);
  display: flex; align-items: flex-end;
}
.sheet-body {
  width: 100%; background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px);
}
.sheet h2 { margin: 0 0 16px; font-size: 1.2rem; }
.range { display: flex; gap: 12px; margin-bottom: 16px; }
.range label { flex: 1; color: var(--muted); font-size: .9rem; }
.range input {
  display: block; width: 100%; margin-top: 4px; padding: 10px; font-size: 1.1rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text);
}
.actions { display: flex; gap: 12px; margin-bottom: 8px; }
.actions .btn { flex: 1; }

.btn {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; font-size: 1rem; cursor: pointer;
  background: var(--surface); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.ghost { background: transparent; }
#picker-close { width: 100%; }

.toolbar { display: flex; gap: 6px; padding: 10px 8px; flex-wrap: wrap; }
.toolbar .btn { padding: 10px 12px; font-size: .95rem; }
.toolbar select {
  padding: 10px; border-radius: 10px; font-size: .95rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.toolbar #reciter { flex: 1; min-width: 0; }

.mushaf {
  flex: 1;
  margin: 12px 16px; padding: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  font-family: "Amiri Quran", serif; font-size: 1.75rem; line-height: 2.6;
  text-align: justify; text-align-last: right;
  overflow-wrap: break-word;
}
.ayah { cursor: pointer; border-radius: 6px; padding: 0 2px; }
.ayah.playing { background: var(--hint-bg); }
.mark { color: var(--accent); font-size: .85em; margin: 0 4px; white-space: nowrap; }
.tip { color: var(--muted); font-size: .85rem; text-align: center; margin: 0 16px 16px; }

/* Mots en mode récitation */
.w { display: inline-block; margin: 0 3px; border-radius: 6px; }
.w.hidden {
  color: transparent; background: var(--hidden);
  height: .9em; vertical-align: middle; line-height: 0; overflow: hidden;
}
.w.current { box-shadow: 0 0 0 2px var(--current); }
.w.say { background: var(--hint-bg); box-shadow: 0 0 0 2px var(--hint); }
.w.peek { color: var(--muted); background: transparent; height: auto; line-height: inherit; }
.w.ok { color: var(--ok); }
.w.bad { color: var(--bad); background: var(--bad-bg); padding: 0 4px; }
.w.hint, .w.fixed { color: var(--hint); background: var(--hint-bg); padding: 0 4px; }
.opt {
  display: flex; align-items: center; gap: 8px;
  margin: 0 16px 8px; font-size: .9rem; color: var(--text);
}
.opt input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.w.unsure { color: var(--muted); text-decoration: underline dotted; text-underline-offset: 6px; }
.w.bad, .w.unsure { cursor: pointer; }

/* Boutons flottants ✗ / ✓ : déplaçables ensemble au doigt */
.fab-group {
  position: fixed; right: 16px; bottom: 190px; z-index: 6;
  display: flex; flex-direction: column; gap: 10px; align-items: stretch;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.fab {
  display: flex; align-items: center; gap: 6px;
  max-width: 50vw; padding: 10px 16px; border: 0; border-radius: 28px;
  background: var(--accent); color: var(--accent-text); opacity: .8;
  font-size: 1.1rem; box-shadow: 0 4px 14px rgb(0 0 0 / .25);
  touch-action: none; cursor: grab;
}
.fab.red { background: var(--bad); color: #fff; }
.fab.off { opacity: .35; }

/* mot signalé comme faute (reste marqué même s'il est ensuite corrigé) */
.w.flag { box-shadow: inset 0 -3px 0 var(--bad); }
.w.flag::after { content: "🚩"; font-size: .45em; vertical-align: super; }

/* liste « À revoir » */
.review-list { list-style: none; margin: 16px 0 0; padding: 0; }
.review-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.review-list .rw { font-family: "Amiri Quran", serif; font-size: 1.5rem; }
.review-list .rinfo { flex: 1; color: var(--muted); font-size: .85rem; }
.review-list button { border: 0; background: transparent; color: var(--muted); font-size: 1.2rem; cursor: pointer; padding: 4px 8px; }
.summary .rv { margin-top: 10px; text-align: right; }
.summary .rv .rw { font-family: "Amiri Quran", serif; font-size: 1.3rem; color: var(--bad); }
.summary .btn { margin-top: 10px; }
.fab span { font-family: "Amiri Quran", serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.severity {
  border: 1px solid rgb(255 255 255 / .4); border-radius: 8px;
  background: transparent; color: inherit; padding: 4px 6px; font-size: .85rem;
}
.severity option { color: #1d1d1b; }

.bar-btn {
  border: 1px solid rgb(255 255 255 / .4); border-radius: 10px;
  background: transparent; color: inherit; padding: 6px 10px; font-size: .9rem; cursor: pointer;
}

/* Mushaf paginé */
:root { --page: #fdfaf0; --page-line: #d8cfb3; --page-ink: #1d1d1b; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --page: #1f211d; --page-line: #3d4036; --page-ink: #ecebe6; }
}
:root[data-theme="dark"] { --page: #1f211d; --page-line: #3d4036; --page-ink: #ecebe6; }
/* Apprendre : l'écran fait exactement la hauteur de l'écran du téléphone ; le livre prend
   tout l'espace restant, le texte continu défile à l'intérieur */
#view-learn { height: 100dvh; min-height: 0; }
#view-learn #learn-text { overflow-y: auto; min-height: 0; }
.book-host { flex: 1; min-height: 0; margin: 4px 8px 0; overflow: hidden; }
.mbook { margin: 0 auto; }
.mpage {
  overflow: hidden;
  background: var(--page); color: var(--page-ink);
  border: 1px solid var(--page-line); border-radius: 6px;
}
.minner { height: 100%; display: flex; flex-direction: column; }
.mbody {
  flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: space-between;
  padding: 10px 26px 4px;
}
.mbody.first { justify-content: center; gap: .35em; }
.mline {
  position: relative; display: flex; justify-content: space-between; align-items: center;
  direction: rtl; white-space: nowrap; line-height: 1.6;
}
.mline.short { justify-content: center; gap: .18em; }
.mbody.measuring .mline.words { width: max-content; justify-content: flex-start; }
/* Réciter en mode livre : l'écran fait la hauteur du téléphone, le livre prend l'espace restant */
#view-recite.book { height: 100dvh; min-height: 0; }
#view-recite.book .recite-tip, #view-recite.book .legend { display: none; }
#view-recite.book .heard { min-height: 1.3em; font-size: 1rem; margin-top: 4px; }
#view-recite.book .summary {
  position: fixed; left: 12px; right: 12px; bottom: 170px; z-index: 7;
  box-shadow: 0 6px 24px rgb(0 0 0 / .3); max-height: 50vh; overflow-y: auto;
}

/* mots du livre pendant la récitation */
.mw.hidden { color: transparent; background: var(--hidden); }
.mw.current { box-shadow: 0 0 0 2px var(--current); }
.mw.peek { color: var(--muted); }
.mw.ok { color: var(--ok); }
.mw.bad { color: var(--bad); background: var(--bad-bg); }
.mw.unsure { color: var(--muted); text-decoration: underline dotted; }
.mw.hint, .mw.fixed { color: var(--hint); background: var(--hint-bg); }
.mw.flag { box-shadow: inset 0 -3px 0 var(--bad); }
.mw.say { background: var(--hint-bg); box-shadow: 0 0 0 2px var(--hint); }

.mw { border-radius: 4px; cursor: pointer; }
.mw.out { opacity: .3; cursor: default; }
.mw.playing { background: var(--hint-bg); }
.mw.recording { background: var(--bad-bg); }
.mline.head { justify-content: center; }
.mline.head span {
  font-family: "Amiri Quran", serif; font-size: .62em; line-height: 1.5; color: var(--accent);
  border: 3px double var(--accent); border-radius: 8px; padding: 0 1.4em;
}
.mline.basm { justify-content: center; font-family: "Amiri Quran", serif; font-size: .72em; }
.hmark {
  position: absolute; left: -1.25em; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center;
  font-family: "Amiri Quran", serif; font-size: .5em; line-height: 1; color: var(--accent);
}
.hmark small { font-size: .7em; white-space: nowrap; }
.mfoot { text-align: center; font-size: .75rem; color: var(--muted); padding: 0 0 4px; }

/* Labo */
.labo-row { display: flex; gap: 8px; align-items: center; margin: 0 16px 10px; flex-wrap: wrap; }
.labo-row select, .labo-row input {
  padding: 10px; border-radius: 10px; font-size: .95rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.labo-row select { flex: 1; min-width: 0; }
.labo-row label { color: var(--muted); font-size: .9rem; display: flex; align-items: center; gap: 6px; }
.labo-row input { width: 80px; }
.labo-ref { flex: none; }
.labo-rec { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 8px 16px; }
.labo-result h3 { margin: 12px 16px 0; font-size: .95rem; color: var(--muted); font-weight: 500; }
.labo-result .mushaf { flex: none; }
.lw { display: inline-block; margin: 0 4px; text-align: center; line-height: 1.6; vertical-align: top; }
.lw small { display: block; font-size: .6em; }
.lw.ok { color: var(--ok); }
.lw.vowel { color: var(--bad); }
.lw.vowel small { color: var(--bad); }
.lw.missing { color: var(--bad); text-decoration: line-through; }
.lw .bad-letter { background: var(--bad-bg); border-radius: 4px; }

.rec-bar {
  position: sticky; bottom: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--bad-bg);
  box-shadow: 0 -4px 14px rgb(0 0 0 / .12);
}
.rec-bar span { flex: 1; min-width: 140px; font-weight: 500; }
.ayah.recording { background: var(--bad-bg); }

.heard {
  min-height: 1.6em; margin: 0 16px; color: var(--muted);
  font-size: 1.1rem; text-align: center;
}
.notice {
  margin: 0 16px 8px; padding: 10px 12px; border-radius: 10px;
  background: var(--hint-bg); color: var(--text); font-size: .9rem;
}
.summary {
  margin: 8px 16px; padding: 12px; border-radius: 12px; text-align: center;
  background: var(--surface); border: 1px solid var(--line);
}
.summary b { font-size: 1.3rem; }

.controls {
  position: sticky; bottom: 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.controls .opt { margin: 0 0 10px; }
.controls .buttons { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mic {
  width: 76px; height: 76px; border-radius: 50%; flex: none;
  border: 0; font-size: 2rem; cursor: pointer;
  background: var(--accent); color: var(--accent-text);
  box-shadow: 0 4px 14px rgb(0 0 0 / .2);
}
.mic.on { background: var(--bad); animation: pulse 1.4s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgb(198 40 40 / .5); }
  100% { box-shadow: 0 0 0 18px rgb(198 40 40 / 0); }
}
.legend {
  display: flex; justify-content: center; gap: 14px; flex-wrap: wrap;
  padding: 4px 16px 6px; font-size: .8rem;
}
.legend .ok { color: var(--ok); }
.legend .bad { color: var(--bad); }
.legend .hint { color: var(--hint); }
.legend .unsure { color: var(--muted); text-decoration: underline dotted; }
