:root {
  --bg: #fbf6f1;
  --card: #ffffff;
  --ink: #2b1d22;
  --muted: #7d6a70;
  --line: #eadfd8;
  --brand: #7a2945;      /* grenade */
  --brand-soft: #f4e3e8;
  --period: #c0395f;
  --predicted: #e7a3b6;
  --fertile: #2f8a84;    /* vert d'eau */
  --fertile-soft: #dcefed;
  --ram: #c99a3b;        /* or, Ramadan */
  --ram-soft: #f7edd8;
  --warn: #a5541b;
  --ok: #2f7a4b;
  --radius: 18px;
  --shadow: 0 1px 2px rgb(60 20 35 / 6%), 0 6px 20px rgb(60 20 35 / 6%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1417; --card: #261c20; --ink: #f4e9ec; --muted: #b29ea5; --line: #3a2c31;
    --brand: #e07a98; --brand-soft: #3a2029; --fertile-soft: #173331; --ram-soft: #352b17;
    --predicted: #8e4a5e; color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", "Noto Naskh Arabic", sans-serif;
  min-height: 100dvh;
}
[dir="rtl"] body { font-size: 17px; }
body.noscroll { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; width: 100%;
}
textarea { resize: vertical; }
h1 { font-size: 1.6rem; margin: .4em 0; }
h2 { font-size: 1.2rem; margin: 0 0 .4em; }
h3 { font-size: 1rem; margin: 0 0 .5em; }
p { margin: .4em 0; }
.small { font-size: .85rem; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.ok { color: var(--ok); }
.label { font-weight: 600; font-size: .9rem; margin: 16px 0 8px; }

#app { max-width: 520px; margin: 0 auto; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

/* En-tête */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 18px 6px;
}
.brand { font-weight: 800; letter-spacing: .02em; color: var(--brand); font-size: 1.25rem; }
.brand.big { font-size: 2.4rem; text-align: center; }
.by { text-align: center; color: var(--muted); font-size: .85rem; margin-top: -4px; }
.hijri { color: var(--muted); font-size: .8rem; text-align: end; }
.content { padding: 8px 16px; }

/* Anneau du cycle */
.hero { display: flex; justify-content: center; padding: 10px 0 18px; }
.ring {
  --c: var(--brand);
  width: 236px; height: 236px; border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--pct) * 360deg), var(--brand-soft) 0);
  display: grid; place-items: center;
}
.hero.period .ring { --c: var(--period); }
.hero.fertile .ring, .hero.ovulation .ring { --c: var(--fertile); }
.ring-inner {
  width: 200px; height: 200px; border-radius: 50%; background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 18px; box-shadow: var(--shadow);
}
.hero-label { color: var(--muted); font-size: .9rem; }
.hero-big { font-size: 2.3rem; font-weight: 800; color: var(--brand); line-height: 1.1; }
.hero-top { font-size: 1.35rem; font-weight: 700; color: var(--brand); }
.hero.period .hero-top { color: var(--period); }
.hero-sub { color: var(--muted); font-size: .85rem; margin-top: 6px; }
.hero-small { color: var(--muted); font-size: .95rem; }

/* Boutons */
.btn {
  border: 0; border-radius: 14px; padding: 13px 16px; font-weight: 600;
  background: var(--brand-soft); color: var(--brand); min-height: 48px;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
.btn.danger { background: #b3261e; color: #fff; }
.btn.wide { width: 100%; }
.btn.icon { width: 44px; min-height: 44px; padding: 0; font-size: 1.3rem; border-radius: 50%; }
.btn:disabled { opacity: .45; }
.btn:active { transform: scale(.98); }
.link { background: none; border: 0; color: var(--brand); padding: 10px 4px; text-decoration: underline; }
.actions { display: grid; gap: 10px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; margin-top: 16px; }
.row > * { flex: 1; }

/* Cartes */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin: 12px 0;
}
.card.note { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.card.soft { background: var(--brand-soft); }
.card.fertile { background: var(--fertile-soft); color: var(--fertile); font-weight: 600; }
.card.ramadan { background: var(--ram-soft); }
.moon { color: var(--ram); font-size: 1.1em; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.facts span { display: block; color: var(--muted); font-size: .8rem; }
.facts b { font-size: 1rem; }
.disclaimer { text-align: center; margin: 18px 6px; }
.line { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }

/* Qada */
.qada { text-align: center; }
.qada-big { font-size: 3.4rem; font-weight: 800; color: var(--brand); line-height: 1; margin: 8px 0; }
.qada-big span { display: block; font-size: .9rem; font-weight: 500; color: var(--muted); margin-top: 4px; }
.qada-row { display: flex; justify-content: center; gap: 40px; margin: 12px 0 16px; }
.qada-row b { display: block; font-size: 1.4rem; }
.qada-row span { color: var(--muted); font-size: .8rem; }
.stepper { display: flex; align-items: center; justify-content: center; gap: 28px; }
.stepper b { font-size: 1.6rem; min-width: 3ch; text-align: center; }

/* Pastilles */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 8px 14px; min-height: 40px;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.check, .switch { display: flex; align-items: center; gap: 10px; margin: 14px 0; }
.check input, .switch input { width: 22px; height: 22px; accent-color: var(--brand); }

/* Calendrier */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 12px; }
.cal-title { text-align: center; }
.cal-title b { display: block; font-size: 1.15rem; text-transform: capitalize; }
.cal-title span { color: var(--ram); font-size: .8rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-grid.wd div { text-align: center; color: var(--muted); font-size: .75rem; padding-bottom: 4px; }
.cell {
  position: relative; aspect-ratio: 1; border: 0; border-radius: 12px; background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0;
}
.cell.empty { background: transparent; }
.cell .g { font-weight: 600; font-size: .95rem; }
.cell .h { font-size: .62rem; color: var(--muted); }
.cell.ram { box-shadow: inset 0 -3px 0 var(--ram); }
.cell.period { background: var(--period); color: #fff; }
.cell.period .h { color: #ffe3ea; }
.cell.predicted { background: transparent; outline: 2px dashed var(--predicted); outline-offset: -3px; }
.cell.fertile { background: var(--fertile-soft); }
.cell.ovulation { background: var(--fertile); color: #fff; }
.cell.ovulation .h { color: #e1f4f2; }
.cell.today { outline: 2.5px solid var(--ink); outline-offset: -2px; }
.cell .dot { position: absolute; top: 5px; inset-inline-end: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }
.cell.period .dot, .cell.ovulation .dot { background: #fff; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0; font-size: .8rem; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 6px; }
.lg { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.lg.period { background: var(--period); }
.lg.predicted { outline: 2px dashed var(--predicted); outline-offset: -2px; }
.lg.fertile { background: var(--fertile-soft); border: 1px solid var(--fertile); }
.lg.ovulation { background: var(--fertile); }
.lg.ram { box-shadow: inset 0 -3px 0 var(--ram); background: var(--card); }

/* Navigation */
.tabs {
  position: fixed; bottom: 0; inset-inline: 0; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); z-index: 5;
}
.tabs button {
  flex: 1; max-width: 130px; border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; font-size: .75rem;
}
.tabs .ico { font-size: 1.25rem; line-height: 1; }
.tabs button.on { color: var(--brand); font-weight: 700; }

/* Fiche du bas */
.backdrop { position: fixed; inset: 0; background: rgb(20 8 12 / 45%); z-index: 10; animation: fade .2s; }
.sheet {
  position: fixed; bottom: 0; inset-inline: 0; margin: 0 auto; max-width: 520px; max-height: 92dvh; overflow: auto;
  background: var(--bg); border-radius: 22px 22px 0 0; z-index: 11;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* Code PIN */
.lock { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px; }
.pin { text-align: center; margin-top: 18px; }
.pin-title { font-weight: 600; margin-bottom: 14px; }
.pin-dots { display: flex; justify-content: center; gap: 16px; margin-bottom: 6px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--brand); }
.pin-dots span.on { background: var(--brand); }
.pin-dots.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pin-error { color: #b3261e; min-height: 1.4em; font-size: .9rem; }
.pin-keys { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px; justify-content: center; margin-top: 8px; }
.pin-keys button {
  height: 72px; border-radius: 50%; border: 0; background: var(--card); box-shadow: var(--shadow);
  font-size: 1.5rem; font-weight: 600;
}

/* Premier lancement */
.onboard { padding: calc(40px + env(safe-area-inset-top)) 22px 30px; display: flex; flex-direction: column; gap: 6px; }
.onboard .btn.primary { margin-top: 22px; }
.onboard .link { align-self: center; }

#toast {
  position: fixed; bottom: calc(90px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 20; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
.danger-zone h3 { color: #b3261e; }
