:root {
  --terra: #B4532A;
  --terra-dark: #93401F;
  --teal: #0F766E;
  --teal-dark: #0B5A54;
  --sand: #FAF3E7;
  --card: #FFFFFF;
  --ink: #2B2118;
  --ink-soft: #6B5D4F;
  --line: #EADFCE;
  --ok: #1A7F4B;
  --ok-bg: #E3F4EA;
  --ko: #B3372B;
  --ko-bg: #FBE7E4;
  --gold: #C98A1B;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(43, 33, 24, .07);
}

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

/* les règles d'affichage ci-dessous (display:block sur .btn, flex sur .btn-row...)
   l'emportent sinon sur le [hidden] du navigateur : les boutons masqués resteraient visibles */
[hidden] { display: none !important; }

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--sand);
  color: var(--ink);
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.arabic, .ar {
  font-family: "Noto Naskh Arabic", "Geeza Pro", "Traditional Arabic", "Arabic Typesetting", serif;
  direction: rtl;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--sand);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 1.25rem; font-weight: 800; letter-spacing: -.02em; color: var(--terra); }
.brand span { color: var(--teal); }
.topstats { display: flex; gap: 8px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px; font-size: .8rem; font-weight: 700; color: var(--ink-soft);
}
.stat strong { color: var(--terra); }

/* ---------- screen ---------- */
.screen { padding: 16px; max-width: 560px; margin: 0 auto; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 14px;
}
.card h2 { font-size: 1.05rem; margin-bottom: 8px; }
.card h3 { font-size: .95rem; margin-bottom: 6px; }
.muted { color: var(--ink-soft); font-size: .88rem; line-height: 1.45; }
.small { font-size: .8rem; }

.kicker {
  display: inline-block; font-size: .72rem; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; color: var(--teal); margin-bottom: 6px;
}
.kicker.terra { color: var(--terra); }
.kicker.gold { color: var(--gold); }

/* ---------- buttons ---------- */
.btn {
  display: block; width: 100%; border: none; border-radius: 14px;
  padding: 15px 18px; font-size: 1rem; font-weight: 700; cursor: pointer;
  font-family: inherit; text-align: center; transition: transform .05s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--terra); color: #fff; }
.btn-teal { background: var(--teal); color: #fff; }
.btn-ghost { background: transparent; color: var(--terra); border: 2px solid var(--terra); }
.btn-soft { background: var(--sand); color: var(--ink); border: 1px solid var(--line); }
.btn + .btn { margin-top: 10px; }
.btn[disabled] { opacity: .45; cursor: default; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; margin-top: 0; }

/* ---------- hero (today) ---------- */
.hero {
  background: linear-gradient(135deg, var(--terra), var(--terra-dark));
  color: #fff; border-radius: var(--radius); padding: 22px 18px; margin-bottom: 14px;
}
.hero .kicker { color: #FFD9C4; }
.hero h1 { font-size: 1.4rem; line-height: 1.25; margin-bottom: 4px; }
.hero p { opacity: .92; font-size: .9rem; margin-bottom: 14px; }
.hero .btn { background: #fff; color: var(--terra-dark); }
.hero.done { background: linear-gradient(135deg, var(--teal), var(--teal-dark)); }
.hero.done .btn { color: var(--teal-dark); }

.pill-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pill {
  background: rgba(255,255,255,.16); border-radius: 999px; padding: 4px 12px;
  font-size: .78rem; font-weight: 700;
}

/* ---------- lesson ---------- */
.progressbar { height: 6px; background: var(--line); border-radius: 3px; margin-bottom: 16px; overflow: hidden; }
.progressbar i { display: block; height: 100%; background: var(--teal); border-radius: 3px; transition: width .3s; }

.vocab-card { text-align: center; padding: 26px 18px; }
.vocab-card .darija { font-size: 2rem; font-weight: 800; color: var(--terra); line-height: 1.2; }
.vocab-card .ar { font-size: 1.7rem; color: var(--teal); margin-top: 8px; }
.vocab-card .fr { font-size: 1.05rem; margin-top: 12px; font-weight: 600; }
.vocab-card .ex {
  margin-top: 16px; background: var(--sand); border-radius: 12px; padding: 12px;
  font-size: .9rem; line-height: 1.5;
}
.vocab-card .ex b { color: var(--teal-dark); }
.counter { text-align: center; font-size: .8rem; color: var(--ink-soft); font-weight: 700; margin-bottom: 8px; }

.speak {
  margin-top: 10px; background: none; border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; font-size: .78rem; color: var(--ink-soft); cursor: pointer; font-family: inherit;
}

/* aide de prononciation (sons 3, 7, q, kh, gh présents dans le mot) */
.pron {
  margin-top: 12px; font-size: .78rem; color: var(--ink-soft); text-align: center;
  background: #FFF4E0; border: 1px solid #F0D9A8; border-radius: 10px;
  padding: 8px 12px; line-height: 1.55;
}
.pron b { color: var(--terra); font-size: .9rem; }

/* dialogue */
.bubble { display: flex; margin-bottom: 10px; }
.bubble .msg {
  max-width: 85%; border-radius: 14px; padding: 10px 14px; font-size: .95rem; line-height: 1.4;
}
.bubble.a .msg { background: var(--sand); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.b { justify-content: flex-end; }
.bubble.b .msg { background: var(--teal); color: #fff; border-bottom-right-radius: 4px; }
.bubble .fr { display: block; font-size: .78rem; opacity: .75; margin-top: 3px; }

/* quiz */
.quiz-q { font-size: 1.15rem; font-weight: 700; margin: 6px 0 16px; line-height: 1.35; }
.quiz-q .ar { font-size: 1.3rem; color: var(--teal); }
.opt {
  display: block; width: 100%; text-align: left; background: var(--card);
  border: 2px solid var(--line); border-radius: 12px; padding: 13px 15px;
  font-size: .98rem; font-weight: 600; font-family: inherit; cursor: pointer; margin-bottom: 10px;
}
.opt.correct { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--ko); background: var(--ko-bg); }
.opt[disabled] { cursor: default; }
.feedback { font-weight: 700; margin: 4px 0 12px; }
.feedback.ok { color: var(--ok); }
.feedback.ko { color: var(--ko); }

/* fusha */
.fusha-card { text-align: center; padding: 26px 18px; border-top: 4px solid var(--gold); }
.fusha-card .ar { font-size: 3rem; line-height: 1.4; color: var(--ink); }
.fusha-card .tr { font-size: 1.1rem; font-weight: 700; color: var(--gold); margin-top: 4px; }
.fusha-card .fr { margin-top: 6px; font-weight: 600; }
.fusha-card .note { margin-top: 14px; font-size: .88rem; color: var(--ink-soft); line-height: 1.5; text-align: right; direction: rtl; }
.fusha-card .note.ltr { direction: ltr; text-align: left; }

/* completion */
.splash { text-align: center; padding: 40px 18px; }
.splash .big { font-size: 2.2rem; font-weight: 800; color: var(--terra); animation: pop .4s ease; }
.splash .sub { color: var(--ink-soft); margin: 10px 0 20px; }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.reward-row { display: flex; justify-content: center; gap: 10px; margin-bottom: 20px; }
.reward {
  background: var(--sand); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 16px; font-weight: 800; color: var(--teal-dark);
}

/* ---------- review flashcards ---------- */
.flash { text-align: center; padding: 34px 18px; min-height: 210px; display: flex; flex-direction: column; justify-content: center; }
.flash .prompt-label { font-size: .75rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 10px; }
.flash .prompt { font-size: 1.6rem; font-weight: 800; }
.flash .answer { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--line); }
.flash .answer .darija { font-size: 1.6rem; font-weight: 800; color: var(--terra); }
.flash .answer .ar { font-size: 1.3rem; color: var(--teal); margin-top: 4px; }

/* ---------- memo ---------- */
.search {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  font-size: 1rem; font-family: inherit; background: var(--card); margin-bottom: 14px;
}
.memo-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.memo-item:last-child { border-bottom: none; }
.memo-item .row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.memo-item .darija { font-weight: 800; color: var(--terra); }
.memo-item .fr { color: var(--ink-soft); font-size: .88rem; text-align: right; }
.memo-item .detail { margin-top: 6px; font-size: .88rem; color: var(--ink-soft); line-height: 1.5; }
.memo-item .detail .ar { color: var(--teal); font-size: 1.05rem; }

details.unit { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; }
details.unit summary {
  list-style: none; cursor: pointer; padding: 15px 18px; font-weight: 700;
  display: flex; justify-content: space-between; align-items: center;
}
details.unit summary::-webkit-details-marker { display: none; }
details.unit summary .count { font-size: .78rem; color: var(--ink-soft); font-weight: 600; }
details.unit .body { padding: 0 18px 14px; }

table.alpha { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.alpha td { padding: 7px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.alpha .ar { font-size: 1.5rem; }
table.alpha td:first-child { width: 3rem; text-align: center; }

/* ---------- progress ---------- */
.big-num { font-size: 2rem; font-weight: 800; color: var(--terra); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.stat-grid .card { margin-bottom: 0; text-align: center; padding: 16px 10px; }
.stat-grid .lbl { font-size: .75rem; color: var(--ink-soft); font-weight: 700; margin-top: 2px; }

.goal { margin-bottom: 14px; }
.goal .goal-head { display: flex; justify-content: space-between; font-size: .85rem; font-weight: 700; margin-bottom: 5px; }
.goal .goal-head span:last-child { color: var(--ink-soft); font-weight: 600; }
.goal .bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.goal .bar i { display: block; height: 100%; border-radius: 4px; background: var(--teal); }
.goal.g2 .bar i { background: var(--terra); }
.goal.g3 .bar i { background: var(--gold); }

.setting-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.setting-row:last-child { border-bottom: none; }
.setting-row label { font-weight: 600; font-size: .92rem; }
.setting-row input[type="time"] { font-family: inherit; font-size: .95rem; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.link-btn { background: none; border: none; color: var(--teal); font-weight: 700; font-family: inherit; font-size: .9rem; cursor: pointer; padding: 0; }
.link-btn.danger { color: var(--ko); }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: none; padding: 9px 4px 7px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-family: inherit; font-size: .68rem; font-weight: 700; color: var(--ink-soft);
  position: relative;
}
.tab svg { width: 22px; height: 22px; fill: currentColor; }
.tab.active { color: var(--terra); }
.tab .badge {
  position: absolute; top: 4px; right: calc(50% - 22px);
  background: var(--ko); color: #fff; font-style: normal; font-size: .62rem;
  font-weight: 800; border-radius: 999px; padding: 1px 6px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: calc(84px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: .85rem; font-weight: 600;
  z-index: 50; max-width: 90vw; text-align: center;
}

/* banner */
.banner {
  background: #FFF4E0; border: 1px solid #F0D9A8; border-radius: 12px;
  padding: 12px 14px; font-size: .88rem; line-height: 1.45; margin-bottom: 14px;
}

/* ---------- connexion ---------- */
.login-mode .tabbar, .login-mode .topstats { display: none; }

/* ---------- profils ---------- */
.profile-chip { cursor: pointer; border: 1px solid var(--line); font-family: inherit; color: var(--teal-dark); font-weight: 800; }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 8px 0 16px; }
.profile-card {
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 12px; cursor: pointer; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  font-size: 1rem; font-weight: 700; color: var(--ink);
}
.profile-card:active { transform: scale(.97); }
.profile-card .avatar {
  width: 58px; height: 58px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 1.5rem; font-weight: 800; color: #fff;
  background: var(--ink-soft);
}
.profile-card.add { border-style: dashed; color: var(--ink-soft); }
.profile-card .mini { font-size: .72rem; font-weight: 600; color: var(--ink-soft); }
.profile-manage { display: flex; gap: 12px; justify-content: center; margin-top: 4px; }

/* ---------- sourates ---------- */
.surah-row { cursor: pointer; }
.surah-row .num {
  display: inline-flex; width: 30px; height: 30px; border-radius: 50%; align-items: center;
  justify-content: center; background: var(--sand); border: 1px solid var(--line);
  font-size: .75rem; font-weight: 800; color: var(--teal-dark); margin-right: 10px; flex: none;
}
.surah-status { font-size: .68rem; font-weight: 800; border-radius: 999px; padding: 2px 8px; }
.surah-status.lue { background: #FFF4E0; color: var(--gold); border: 1px solid #F0D9A8; }
.surah-status.apprise { background: var(--ok-bg); color: var(--ok); }
.surah-status.next { background: var(--terra); color: #fff; }
.verse { padding: 16px 0; border-bottom: 1px dashed var(--line); }
.verse:last-child { border-bottom: none; }
.verse .var { font-size: 1.65rem; line-height: 2.1; text-align: right; direction: rtl; }
.verse .vtr { margin-top: 6px; font-size: .85rem; font-weight: 700; color: var(--gold); }
.verse .vfr { margin-top: 4px; font-size: .92rem; color: var(--ink); line-height: 1.5; }
.verse .vnum { font-size: .68rem; color: var(--ink-soft); font-weight: 700; }
.bismillah { text-align: center; font-size: 1.4rem; color: var(--teal); padding: 8px 0 14px; }
.btn-gold { background: var(--gold); color: #fff; }
.fld { display: block; font-weight: 700; font-size: .82rem; margin-bottom: 12px; color: var(--ink-soft); }
.fld input {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; font-size: 1rem;
  font-family: inherit; background: var(--card); box-sizing: border-box;
}
.feedback:empty { display: none; }

/* ---------- administration ---------- */
.table-wrap { overflow-x: auto; }
table.users { border-collapse: collapse; width: 100%; font-size: .82rem; min-width: 860px; }
table.users th, table.users td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; vertical-align: top; }
table.users th { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
tr.row-off td { opacity: .55; }
.badge-role { background: var(--teal); color: #fff; border-radius: 999px; padding: 2px 8px; font-size: .68rem; font-weight: 700; }
.badge-off { background: var(--ko-bg); color: var(--ko); border-radius: 999px; padding: 2px 8px; font-size: .68rem; font-weight: 700; }
.mini-bar { width: 80px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; }
.mini-bar i { display: block; height: 100%; background: var(--teal); }
.link-btn.mr { margin-right: 12px; }
.history-box { background: var(--sand); border-radius: 10px; padding: 10px 12px; line-height: 1.6; white-space: normal; }
