:root {
  --bg: #f4eedf;
  --surface: #fffdf7;
  --field: #f2ecdd;
  --text: #17171a;
  --muted: #66615a;
  --line: #e3d8bd;
  --accent: #165c48;
  --accent-text: #ffffff;
  --accent-soft: #e1eee7;
  --gold: #8c6a22;
  --ok: #1f7a4d;
  --ok-soft: #e2f3ea;
  --danger: #b9382f;
  --danger-soft: #fbe9e7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 32px rgba(70, 50, 10, .07);
  --motif: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 96 96'%3E%3Cg fill='none' stroke='%238c6a22' stroke-opacity='.17' stroke-width='1'%3E%3Crect x='27' y='27' width='42' height='42'/%3E%3Crect x='27' y='27' width='42' height='42' transform='rotate(45 48 48)'/%3E%3Ccircle cx='48' cy='48' r='9'/%3E%3Cpath d='M0 0L27 27M96 0L69 27M0 96L27 69M96 96L69 69M48 0v18M48 78v18M0 48h18M78 48h18'/%3E%3C/g%3E%3C/svg%3E");
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1613;
    --surface: #16201c;
    --field: #1f2a25;
    --text: #f1f1f2;
    --muted: #a3aba6;
    --line: #2c3a33;
    --accent: #4fb89c;
    --accent-text: #0d1f1a;
    --accent-soft: #1b3330;
    --gold: #d6ad5c;
    --ok: #5cc98f;
    --ok-soft: #173326;
    --danger: #ef7a72;
    --danger-soft: #3a1d1b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 32px rgba(0, 0, 0, .3);
    --motif: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 96 96'%3E%3Cg fill='none' stroke='%23d6ad5c' stroke-opacity='.09' stroke-width='1'%3E%3Crect x='27' y='27' width='42' height='42'/%3E%3Crect x='27' y='27' width='42' height='42' transform='rotate(45 48 48)'/%3E%3Ccircle cx='48' cy='48' r='9'/%3E%3Cpath d='M0 0L27 27M96 0L69 27M0 96L27 69M96 96L69 69M48 0v18M48 78v18M0 48h18M78 48h18'/%3E%3C/g%3E%3C/svg%3E");
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; }

body {
  font-family: "Inter", "Amiri", system-ui, -apple-system, "Segoe UI", sans-serif;
  background-color: var(--bg);
  background-image: var(--motif);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#compte { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.ar, [lang="ar"] { font-family: "Amiri", serif; font-size: 1.25em; line-height: 1.7; }

/* ---------- Mise en page ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: .95rem;
  color: inherit;
  text-decoration: none;
}
.brand::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.brand small { color: var(--muted); font-weight: 500; }

main { max-width: 860px; margin: 0 auto; padding: 8px 16px 64px; }

.hero { padding: 28px 0 20px; }
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); letter-spacing: -.02em; line-height: 1.2; }
.hero p { color: var(--muted); margin-top: 6px; }
.hero .ar { color: var(--gold); display: inline-block; margin-bottom: 4px; }

.crumbs { font-size: .88rem; color: var(--muted); margin-top: 8px; }
.crumbs a { color: var(--muted); }

h2 { font-size: 1.1rem; margin: 28px 0 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 120px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  transition: transform .12s ease, border-color .12s ease;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tile strong { font-size: 1.1rem; }
.tile span { color: var(--muted); font-size: .9rem; }
.tile .num {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  position: relative;
  isolation: isolate;
  color: var(--accent);
  font-weight: 700;
}
/* Rosette à 8 branches, comme les marques de fin de verset */
.tile .num::before, .tile .num::after {
  content: "";
  position: absolute;
  z-index: -1;
  clip-path: polygon(50.0% 0.0%, 64.6% 14.6%, 85.4% 14.6%, 85.4% 35.4%, 100.0% 50.0%, 85.4% 64.6%, 85.4% 85.4%, 64.6% 85.4%, 50.0% 100.0%, 35.4% 85.4%, 14.6% 85.4%, 14.6% 64.6%, 0.0% 50.0%, 14.6% 35.4%, 14.6% 14.6%, 35.4% 14.6%);
}
.tile .num::before { inset: 0; background: var(--gold); }
.tile .num::after { inset: 2px; background: var(--accent-soft); }
.tile .ar { color: var(--gold); font-size: 1.05rem; }

.empty { color: var(--muted); text-align: center; padding: 32px 16px; }

/* ---------- Formulaires ---------- */

label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--field);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 11px 12px;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); }

.field { margin-bottom: 14px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: inherit;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .btn:hover { border-color: var(--accent); }
button:focus-visible, .btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .55; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.danger { color: var(--danger); }
.small { min-height: 36px; padding: 6px 12px; font-size: .88rem; }
.wide { width: 100%; }

.msg { margin-top: 12px; font-size: .92rem; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* ---------- Passage d'une évaluation ---------- */

.question {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
}
.question .q-head { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: .85rem; margin-bottom: 8px; }
.question .enonce { font-size: 1.08rem; font-weight: 600; white-space: pre-line; }
.question img { display: block; max-width: 100%; max-height: 360px; margin: 14px auto 4px; border-radius: 10px; }

.choix { display: grid; gap: 8px; margin-top: 14px; padding: 0; border: 0; }
.choix legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  cursor: pointer;
  font-weight: 500;
  margin: 0;
}
.option input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.option:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.option.juste { border-color: var(--ok); background: var(--ok-soft); }
.option.faux { border-color: var(--danger); background: var(--danger-soft); }
.option .tag { margin-inline-start: auto; font-size: .8rem; font-weight: 700; }
.option.juste .tag { color: var(--ok); }
.option.faux .tag { color: var(--danger); }

.question.corrigee.ok { border-color: var(--ok); }
.question.corrigee.ko { border-color: var(--danger); }
.verdict { font-weight: 700; }
.verdict.ok { color: var(--ok); }
.verdict.ko { color: var(--danger); }
.explication { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--field); font-size: .95rem; white-space: pre-line; }

.progress {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 10px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: .88rem;
  color: var(--muted);
}
.bar { flex: 1; height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s ease; }

.score {
  text-align: center;
  padding: 28px 20px;
  margin-bottom: 18px;
}
.score .big { font-size: 3rem; font-weight: 800; letter-spacing: -.03em; }
.score .mention { font-size: 1.1rem; font-weight: 700; margin-top: 4px; }
.score .mention .ar { color: var(--gold); margin-inline-start: 8px; }
.score p { color: var(--muted); margin-top: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }

/* ---------- Admin ---------- */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: .78rem;
  font-weight: 700;
  background: var(--field);
  color: var(--muted);
}
.badge.on { background: var(--ok-soft); color: var(--ok); }

.list { display: grid; gap: 10px; }
.item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.item .grow { flex: 1; min-width: 0; }
.item .sub { color: var(--muted); font-size: .86rem; }
.item a.title { color: inherit; font-weight: 600; text-decoration: none; }
.item a.title:hover { color: var(--accent); }
.item .tools { display: flex; gap: 6px; flex-wrap: wrap; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 16px 0; }
.toolbar .spacer { flex: 1; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin: 20px 0 16px; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; min-height: 44px; }
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--accent); }

.q-admin { padding: 16px; }
.q-admin .q-meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .85rem; margin-bottom: 6px; }
.q-admin ol { margin: 10px 0 0; padding-inline-start: 22px; }
.q-admin li.bonne { color: var(--ok); font-weight: 700; }
.q-admin img { max-height: 140px; border-radius: 8px; margin-top: 10px; }

.choice-edit { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.choice-edit input[type="text"] { flex: 1; }
.choice-edit .mark { display: flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 600; margin: 0; white-space: nowrap; }
.choice-edit .mark input { width: 20px; height: 20px; accent-color: var(--ok); }

dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 22px;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h3 { margin-bottom: 16px; }
dialog .foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
caption { text-align: start; padding: 12px 14px; font-weight: 600; }
th, td { padding: 10px 14px; text-align: start; border-top: 1px solid var(--line); white-space: nowrap; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
td.num { font-variant-numeric: tabular-nums; font-weight: 700; }

.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
.stat { padding: 14px 16px; }
.stat .v { font-size: 1.5rem; font-weight: 800; }
.stat .l { color: var(--muted); font-size: .82rem; }

.login { max-width: 380px; margin: 12vh auto 0; }
.login h1 { font-size: 1.3rem; margin-bottom: 16px; }

code.block { display: block; white-space: pre; overflow-x: auto; background: var(--field); padding: 12px; border-radius: 10px; font-size: .8rem; }

@media (max-width: 560px) {
  .item { flex-wrap: wrap; }
  .item .tools { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Habillage Coran et tajwid ---------- */

/* Bandeau aux couleurs du tajwid, en haut de chaque page */
.bandeau-tajwid {
  height: 5px;
  background: linear-gradient(90deg,
    var(--tj-madd) 0 20%, var(--tj-ghunna) 20% 40%, var(--tj-qalqala) 40% 60%,
    var(--tj-tafkhim) 60% 80%, var(--tj-muet) 80% 100%);
}
:root {
  --tj-madd: #c0392b;
  --tj-ghunna: #2e8b57;
  --tj-qalqala: #2f86c9;
  --tj-tafkhim: #1f4e9a;
  --tj-muet: #8f8a80;
}
@media (prefers-color-scheme: dark) {
  :root { --tj-madd: #e5675a; --tj-ghunna: #4fbf84; --tj-qalqala: #5aa9e6; --tj-tafkhim: #7f9ee0; --tj-muet: #a3a09a; }
}

/* Cartouche comme les titres de sourate du mushaf */
.cartouche {
  position: relative;
  margin: 8px 0 22px;
  padding: 14px 56px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--gold);
  border-radius: 999px;
  box-shadow: 0 0 0 4px var(--bg), 0 0 0 5px var(--gold), var(--shadow);
}
.cartouche::before, .cartouche::after {
  content: "۞";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-family: "Amiri", serif;
  font-size: 1.6rem;
  color: var(--gold);
}
.cartouche::before { left: 22px; }
.cartouche::after { right: 22px; }
.cartouche .titre-ar {
  display: block;
  font-family: "Amiri", serif;
  font-weight: 700;
  font-size: clamp(1.5rem, 5vw, 2.1rem);
  line-height: 1.6;
  color: var(--accent);
}
.cartouche .sous { color: var(--muted); font-size: .95rem; font-weight: 600; letter-spacing: 0; line-height: 1.4; }

/* Séparateur orné */
.orne {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--gold);
  margin: 26px 0 14px;
}
.orne::before, .orne::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--gold), transparent); }

/* Tuiles : liseré doré comme un cadre de page */
.tile { border-top: 3px solid var(--gold); }
.tile:hover { border-color: var(--accent); border-top-color: var(--gold); }

/* Questions : fine marge dorée à droite comme la marge du mushaf */
.question { border-inline-start: 3px solid var(--gold); }
.question.corrigee.ok { border-inline-start-color: var(--ok); }
.question.corrigee.ko { border-inline-start-color: var(--danger); }

/* Pied de page : verset */
.pied {
  max-width: 860px;
  margin: 0 auto;
  padding: 8px 16px 40px;
  text-align: center;
  color: var(--muted);
  font-size: .85rem;
}
.pied .verset { display: block; font-family: "Amiri", serif; font-size: 1.5rem; color: var(--accent); line-height: 1.8; }
.pied .ref { display: block; }

@media (max-width: 560px) {
  .cartouche { padding: 12px 44px; }
  .cartouche::before { left: 14px; }
  .cartouche::after { right: 14px; }
}
