:root {
  --bg: #fbf6f1;
  --bg-2: #f5ece4;
  --card: #fffdfb;
  --ink: #2c2330;
  --ink-2: #574b5a;
  --line: #ecdfd6;
  --accent: #b24a6a;
  --accent-soft: #f6e1e7;
  --moon: #e9b872;

  --hayd: #b24a6a;      --hayd-bg: #f8e3ea;
  --nifas: #7c4f93;     --nifas-bg: #efe4f4;
  --istihada: #b9791f;  --istihada-bg: #f9ecd7;
  --tahir: #4f8a64;     --tahir-bg: #e2f0e6;
  --combine: #6c66b8;   --combine-bg: #e8e6f7;
  --info: #4d6488;      --info-bg: #e3e9f3;

  --blood: #b3263e;
  --blood-dark: #6e1426;
  --cotton: #ffffff;
  --cotton-edge: #d9cfc7;

  --shadow: 0 1px 2px rgba(60, 30, 50, .05), 0 8px 24px rgba(60, 30, 50, .07);
  --radius: 18px;
  color-scheme: light;
}

/* Light unless the device is dark or the header button picks dark (data-theme="dark", saved as "theme") */
:root[data-theme="dark"] {
  --bg: #19141c; --bg-2: #211a25; --card: #261f2b; --ink: #f3ecf2; --ink-2: #cdc1ce;
  --line: #3a3040; --accent: #e57f9c; --accent-soft: #3d2530; --moon: #f0c27e;
  --hayd: #ec8aa6; --hayd-bg: #3b2330; --nifas: #c39ad8; --nifas-bg: #322539;
  --istihada: #e6aa55; --istihada-bg: #3a2d1b; --tahir: #87c79c; --tahir-bg: #1f3326;
  --combine: #a8a3f0; --combine-bg: #2a2847; --info: #9db4da; --info-bg: #222c3d;
  --blood: #d0455d; --blood-dark: #8a2035; --cotton: #f4efe9; --cotton-edge: #8d8088;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 85% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font: 16px/1.55 "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
}
button { font: inherit; color: inherit; }
a { color: var(--accent); }

.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px 96px; }

/* ── Header */
header.top {
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-bottom: 1px solid var(--line);
}
header.top .wrap { padding-bottom: 0; display: flex; align-items: center; gap: 12px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; text-decoration: none; color: var(--ink); }
.brand svg { width: 34px; height: 34px; }
.brand b { font: 600 24px/1 "Noto Serif", "Fraunces", Georgia, serif; letter-spacing: .2px; }
.brand small { display: block; font-size: 13.5px; color: var(--ink-2); letter-spacing: .3px; margin-top: 2px; }
.tabs { display: flex; background: var(--bg-2); border-radius: 999px; padding: 4px; border: 1px solid var(--line); }
.tabs button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 999px; cursor: pointer;
  font-weight: 600; font-size: 16px; color: var(--ink-2);
}
.tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.theme-btn {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--ink); cursor: pointer; display: grid; place-items: center; padding: 0;
}
.theme-btn:hover { border-color: var(--accent); }
.theme-btn svg { width: 18px; height: 18px; }
.theme-btn .sun { display: none; }
:root[data-theme="dark"] .theme-btn .sun { display: block; }
:root[data-theme="dark"] .theme-btn .moon { display: none; }

/* ── Q&A */
.intro { margin: 28px 0 8px; }
.intro h1 { font: 600 30px/1.15 "Noto Serif", "Fraunces", Georgia, serif; margin: 0 0 6px; }
.intro p { margin: 0; color: var(--ink-2); }

.trail { list-style: none; margin: 20px 0 0; padding: 0; position: relative; }
.trail li { position: relative; padding-left: 26px; }
.trail li::before {
  content: ""; position: absolute; left: 8px; top: 0; bottom: 0; width: 2px; background: var(--line);
}
.trail li::after {
  content: ""; position: absolute; left: 4px; top: 16px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--card); border: 2px solid var(--accent);
}
.trail a {
  display: block; text-decoration: none; color: inherit; cursor: pointer;
  padding: 8px 10px; border-radius: 12px;
}
.trail a:hover, .trail a:focus-visible { background: var(--bg-2); outline: none; }
.trail .tq { display: block; font-size: 15px; color: var(--ink-2); }
.trail .ta { display: block; font-weight: 600; font-size: 16px; }
.trail .edit { float: right; font-size: 14px; color: var(--accent); font-weight: 600; opacity: .8; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px; margin-top: 16px; scroll-margin-top: 80px;
  animation: rise .28s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .card { animation: none; } }

.step { font-size: 14px; letter-spacing: .8px; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.card h2 { font: 600 22px/1.3 "Noto Serif", "Fraunces", Georgia, serif; margin: 6px 0 8px; }
.hint { color: var(--ink-2); font-size: 16px; margin: 0 0 14px; }
.art { margin: 6px 0 16px; display: flex; justify-content: center; }
.art svg { max-width: 100%; height: auto; }

.options { display: grid; gap: 10px; margin-top: 12px; }
.opt {
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
  border: 1.5px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 14px 16px; cursor: pointer; transition: border-color .15s, transform .1s, background .15s;
}
.opt:hover { border-color: var(--accent); background: var(--accent-soft); }
.opt:active { transform: scale(.99); }
.opt:focus-visible { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
.opt .ot { font-weight: 600; display: block; }
.opt .os { font-size: 15px; color: var(--ink-2); display: block; margin-top: 2px; }
.opt .oart { flex: 0 0 64px; }
.opt .oart svg { width: 64px; height: auto; display: block; }
.opt .chev { margin-left: auto; color: var(--ink-2); flex: 0 0 auto; }

/* Start screen: groups with icons; list on wide screens, tiles on phones */
.tone-hayd { --tone: var(--hayd); --tone-bg: var(--hayd-bg); }
.tone-tahir { --tone: var(--tahir); --tone-bg: var(--tahir-bg); }
.tone-info { --tone: var(--info); --tone-bg: var(--info-bg); }
.oicon {
  flex: 0 0 40px; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--tone-bg, var(--accent-soft)); color: var(--tone, var(--accent));
}
.oicon svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ogroup {
  font-size: 14px; letter-spacing: .06em; text-transform: uppercase; color: var(--tone);
  margin: 22px 0 8px; display: flex; align-items: center; gap: 8px;
}
.ogroup::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.ogroup:first-of-type { margin-top: 14px; }
.opt[class*="tone-"]:hover { border-color: var(--tone); background: var(--tone-bg); }
.opt { padding-top: 11px; padding-bottom: 11px; }

.tiles { grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px; min-height: 108px;
  border: 1.5px solid var(--line); background: var(--card); border-radius: 14px; padding: 14px;
  font-weight: 600; font-size: 16px; line-height: 1.3; transition: border-color .15s, background .15s;
}
.tile:hover { border-color: var(--tone); background: var(--tone-bg); }
.tile:focus-visible { outline: 3px solid var(--tone-bg); border-color: var(--tone); }

.tile .os { font-weight: 400; font-size: 15px; color: var(--ink-2); display: block; margin-top: 3px; }
.tiles { display: none; }
@media (max-width: 600px) {
  .options.grouped { display: none; }
  .tiles { display: grid; }
}

.nav { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.btn {
  border: 1.5px solid var(--line); background: var(--card); padding: 10px 16px; border-radius: 999px;
  cursor: pointer; font-weight: 600; font-size: 16px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }

/* ── Result */
.result { border-top: 6px solid var(--st); }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px;
  background: var(--st-bg); color: var(--st); font-weight: 700; font-size: 15px;
}
.badge i { width: 8px; height: 8px; border-radius: 50%; background: var(--st); }
.result .say { font-size: 17px; margin: 4px 0 12px; }
.pray { display: block; margin: 14px 0 4px; padding: 12px 14px; border-radius: 14px; background: var(--accent-soft); color: var(--ink); text-decoration: none; border: 1px solid var(--line); }
.pray b { display: block; color: var(--accent); }
.pray small { display: block; color: var(--ink-2); font-size: 15px; margin-top: 2px; }
.result h3 { font-size: 15px; text-transform: uppercase; letter-spacing: .7px; color: var(--ink-2); margin: 16px 0 6px; }
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.list li { position: relative; padding: 10px 12px 10px 38px; border-radius: 12px; background: var(--bg-2); }
.list li::before {
  position: absolute; left: 12px; top: 10px; width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; font-size: 14px; font-weight: 800; color: #fff;
}
.list.do li::before { content: "✓"; background: var(--tahir); }
.list.dont li::before { content: "✕"; background: var(--hayd); }
.list.example { counter-reset: ex; }
.list.example li:not(.sub)::before { counter-increment: ex; content: counter(ex); background: var(--istihada); }
.list li.sub { background: transparent; padding-top: 0; padding-bottom: 0; }
.list li.sub::before { display: none; }
.note {
  margin-top: 14px; padding: 12px 14px; border-radius: 12px; font-size: 16px;
  background: var(--st-bg); border: 1.5px solid color-mix(in srgb, var(--st) 45%, transparent);
}
.refs { margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 14px; }
.refs h3 { margin-top: 0; }
.refs h3 small { font: 500 14px "DM Sans", sans-serif; color: var(--ink-2); text-transform: none; letter-spacing: 0; margin-left: 6px; }
.refs h3 + .src { margin-top: 8px; }
.refs .src + h3 { margin-top: 16px; }
.src { border: 1px solid var(--line); border-radius: 12px; margin-top: 6px; background: var(--card); transition: border-color .15s; }
.src[open], .src:hover { border-color: var(--accent); }
.src summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; font-size: 16px;
}
.src summary::-webkit-details-marker { display: none; }
.src .sl { flex: 1; display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.src .sl span { color: var(--ink-2); font-size: 14px; text-align: right; }
.src.ar .sl b { font: 600 16px/1.5 "Noto Naskh Arabic", "Geeza Pro", serif; }
.src .ext {
  flex: 0 0 auto; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px;
  text-decoration: none; color: var(--accent); font-weight: 700;
}
.src .ext:hover { background: var(--bg-2); }
.src-text {
  max-height: 320px; overflow-y: auto; padding: 4px 14px 12px; border-top: 1px dashed var(--line);
  font-size: 16px; line-height: 1.6; color: var(--ink);
}
.src-text p { margin: 8px 0 0; }
.src-text[lang="ar"] { font: 17px/1.9 "Noto Naskh Arabic", "Geeza Pro", serif; }
.src-err { color: var(--ink-2); font-style: italic; }
.src-note { margin: 10px 0 0; font-size: 14px; color: var(--ink-2); }

.st-hayd { --st: var(--hayd); --st-bg: var(--hayd-bg); }
.st-nifas { --st: var(--nifas); --st-bg: var(--nifas-bg); }
.st-istihada { --st: var(--istihada); --st-bg: var(--istihada-bg); }
.st-tahir { --st: var(--tahir); --st-bg: var(--tahir-bg); }
.st-combine { --st: var(--combine); --st-bg: var(--combine-bg); }
.st-info { --st: var(--info); --st-bg: var(--info-bg); }

.disclaimer { margin-top: 28px; font-size: 14px; color: var(--ink-2); text-align: center; }

/* ── Calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 26px 0 10px; }
.cal-head h1 { font: 600 26px/1.2 "Noto Serif", "Fraunces", Georgia, serif; margin: 0; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--card);
  cursor: pointer; font-size: 18px; display: grid; place-items: center;
}
.icon-btn:hover { border-color: var(--accent); }
.status-line {
  display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 16px;
}
.status-line .dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 14px; }
.dow { text-align: center; font-size: 14px; font-weight: 700; color: var(--ink-2); padding: 4px 0; }
.day {
  aspect-ratio: 1; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card);
  cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-weight: 600; font-size: 16px; position: relative; padding: 0;
}
.day:hover { border-color: var(--accent); }
.day.blank { visibility: hidden; }
.day.today { border-color: var(--ink); }
.day .mark { width: 8px; height: 8px; border-radius: 50%; }
.day.s-bleeding { background: var(--hayd); border-color: var(--hayd); color: #fff; }
.day.s-bleeding .mark { background: #fff; }
.day.s-spotting { background: var(--hayd-bg); border-color: var(--hayd); color: var(--hayd); }
.day.s-spotting .mark { background: var(--hayd); }
.day.s-clean { background: var(--tahir-bg); border-color: var(--tahir); color: var(--tahir); }
.day.s-clean .mark { background: var(--tahir); }
.day .nn { position: absolute; top: 4px; right: 6px; font-size: 13.5px; opacity: .85; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 14px; font-size: 15px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }

/* ── Sheet */
.scrim { position: fixed; inset: 0; background: rgba(20, 10, 20, .35); z-index: 20; animation: fade .2s both; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: min(640px, 100%);
  background: var(--card); border-radius: 22px 22px 0 0; padding: 20px 16px 28px; z-index: 21;
  box-shadow: 0 -10px 40px rgba(0,0,0,.18); animation: up .22s ease both;
}
@keyframes up { from { transform: translate(-50%, 30px); opacity: 0; } }
.sheet h2 { font: 600 20px/1.2 "Noto Serif", "Fraunces", Georgia, serif; margin: 0 0 14px; }
.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.choice {
  border: 2px solid var(--line); border-radius: 14px; background: var(--card); padding: 14px 6px;
  cursor: pointer; font-weight: 700; font-size: 16px; display: grid; justify-items: center; gap: 8px;
}
.choice i { width: 22px; height: 22px; border-radius: 50%; }
.choice[aria-pressed="true"] { border-color: var(--ink); background: var(--bg-2); }
.sheet textarea {
  width: 100%; margin-top: 14px; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px;
  background: var(--bg); color: var(--ink); font: inherit; resize: vertical; min-height: 64px;
}
.sheet .row { display: flex; gap: 10px; margin-top: 14px; justify-content: space-between; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 30;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 16px;
  box-shadow: var(--shadow);
}

/* ── Calendar locked for testers */
.cal { position: relative; }
.cal.locked .cal-body { filter: blur(2px) saturate(.7); opacity: .5; pointer-events: none; user-select: none; }
.wip {
  position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 16px;
}
.wip-tag {
  transform: rotate(-8deg); padding: 12px 28px; border-radius: 16px;
  font: 600 clamp(26px, 7vw, 40px)/1.1 "Noto Serif", "Fraunces", Georgia, serif; letter-spacing: .02em; text-transform: uppercase;
  color: var(--accent); border: 2px solid var(--accent);
  background: color-mix(in srgb, var(--card) 45%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .18);
}
.wip p {
  margin: 0; padding: 8px 16px; border-radius: 999px; font-size: 16px; color: var(--ink);
  background: color-mix(in srgb, var(--card) 70%, transparent); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.wip a { color: var(--accent); font-weight: 700; }

/* ── Feedback */
.feedback { margin-top: 14px; border: 1.5px dashed var(--line); border-radius: 16px; padding: 4px 16px; }
.feedback summary { cursor: pointer; padding: 10px 0; font-size: 16px; font-weight: 600; color: var(--ink-2); }
.feedback[open] { background: var(--card); border-style: solid; }
.feedback form { padding-bottom: 14px; }
.feedback textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px;
  background: var(--bg); color: var(--ink); font: inherit; resize: vertical; min-height: 84px;
}
.feedback .row { display: flex; gap: 10px; margin-top: 10px; justify-content: space-between; align-items: center; }
.feedback .fb-meta { font-size: 14px; color: var(--ink-2); }

@media (max-width: 420px) {
  .brand small { display: none; }
  .card { padding: 18px; }
  .intro h1 { font-size: 26px; }
  .opt .oart { flex-basis: 52px; }
  .opt .oart svg { width: 52px; }
  .day { border-radius: 10px; font-size: 16px; }
}

/* Arabic source: each paragraph with its translation underneath */
.src-text .tr {
  font-family: "DM Sans", system-ui, sans-serif; font-size: 16px; color: var(--ink-2); text-align: left;
  border-left: 3px solid var(--accent); padding: 4px 0 4px 10px; margin: 2px 0 12px;
}
.src-text .tr-tag { display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); }
.src-text .tr-note { font-family: "DM Sans", system-ui, sans-serif; font-size: 14px; color: var(--ink-2); text-align: left; margin-top: 12px; }
.intro-link { color: var(--accent); font-weight: 600; white-space: nowrap; }

/* ───────── Ṭayyib: its own accent and result states (the rest is shared with Qamar's look) */
:root { --accent: #6b7a2a; --accent-soft: #eef1dc; --moon: #6b7a2a; }
:root[data-theme="dark"] { --accent: #b9c77a; --accent-soft: #2a2f1a; --moon: #b9c77a; }
.st-halal { --st: var(--tahir); --st-bg: var(--tahir-bg); }
.st-haram { --st: var(--hayd); --st-bg: var(--hayd-bg); }
.st-makruh { --st: var(--istihada); --st-bg: var(--istihada-bg); }
.st-tahir { --st: var(--tahir); --st-bg: var(--tahir-bg); }
.st-valid { --st: var(--tahir); --st-bg: var(--tahir-bg); }

/* "All apps" button beside the theme toggle: back to the prototype index at the site root */
.home-btn { display: grid; place-items: center; color: var(--ink-2); text-decoration: none; }
.home-btn svg { width: 17px; height: 17px; }
.home-btn + .theme-btn { margin-left: 6px; }
.st-qasr { --st: var(--nifas); --st-bg: var(--nifas-bg); }
.st-tamam { --st: var(--info); --st-bg: var(--info-bg); }
.tone-travel { --tone: var(--nifas); --tone-bg: var(--nifas-bg); }

/* No zoom on a double tap (pinch to zoom still works) */
html, body { touch-action: manipulation; }


/* Lists under an answer (steps, and notes that mix what is allowed, what isn't and plain facts): one quiet card with
   hairlines between lines; steps get a numbered circle in the app's colour, notes a small dot */
.list.example, .list.notes { gap: 0; padding: 2px 14px; border-radius: 14px; background: var(--bg-2); border: 1px solid var(--line); }
.list.example li, .list.notes li { padding: 11px 0 11px 30px; border-radius: 0; background: none; border-top: 1px solid var(--line); line-height: 1.5; }
.list.example li:first-child, .list.notes li:first-child { border-top: 0; }
.list.example li:not(.sub)::before { left: 0; top: 12px; width: 20px; height: 20px; font-size: 13.5px; background: var(--accent); color: var(--card); }
.list.notes li::before { content: ""; left: 6px; top: 20px; width: 6px; height: 6px; background: var(--accent); }
.list.example li.sub { border-top: 0; padding-top: 0; }

/* A link to another question, after the answer: plainly a link (label, arrow), not part of the ruling */
.related { position: relative; display: block; margin: 16px 0 4px; padding: 12px 40px 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg-2); color: var(--ink); text-decoration: none; }
.related small { display: block; font-size: 15px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); }
.related b { display: block; margin-top: 2px; color: var(--accent); font-size: 16px; }
.related span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 24px; color: var(--accent); }
.related:hover { border-color: var(--accent); }
