:root {
  color-scheme: light;
  --bg: #f6f1e6;
  --surface: #fffdf8;
  --surface-2: #f1ebdd;
  --ink: #1d2621;
  --ink-2: #4b564f;
  --muted: #6f7a72;
  --border: #e3dbc8;
  --accent: #1e6b4f;
  --accent-hover: #185a42;
  --accent-ink: #ffffff;
  --accent-soft: #e2ede6;
  --gold: #8f6a22;
  --danger: #a8321f;
  --track: #e9e3d4;
  /* Bar segments, oldest phase first (validated: adjacent pairs gold/blue and blue/green) */
  --series-p0: #c27d0e;
  --series-p1: #3f72c4;
  --series-p2: #16855a;
  --shadow: 0 1px 2px rgba(40, 35, 20, 0.05), 0 10px 30px rgba(40, 35, 20, 0.06);
  --radius: 18px;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-arabic: 'Amiri', 'Traditional Arabic', serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111613;
    --surface: #1b211e;
    --surface-2: #232b27;
    --ink: #ece7db;
    --ink-2: #c2c8bf;
    --muted: #949d96;
    --border: #2f3934;
    --accent: #5fbf93;
    --accent-hover: #74cda3;
    --accent-ink: #0d1a13;
    --accent-soft: #1f3329;
    --gold: #d5a64a;
    --danger: #f08a78;
    --track: #2c3530;
    --series-p0: #b97f12;
    --series-p1: #5b8fd6;
    --series-p2: #2f9a6c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.25);
  }
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

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

main.wrap { flex: 1; padding-top: 24px; padding-bottom: 32px; }

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 7vw, 2.75rem); }
h2 { font-size: clamp(1.45rem, 5vw, 1.85rem); }
h3 { font-size: 1.2rem; }
h2:focus { outline: none; }

p { margin: 0; }
strong { font-weight: 600; }

button, input { font: inherit; color: inherit; }

/* ---------- Top bar ---------- */
.topbar { border-bottom: 1px solid var(--border); background: var(--bg); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: var(--accent); }
.brand-mark { width: 22px; height: 22px; }
.privacy-pill { font-size: 0.8rem; color: var(--ink-2); background: var(--surface-2); padding: 4px 10px; border-radius: 999px; white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 22px;
  min-height: 48px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, transform 0.05s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .choice input:focus-visible + .choice-body, input:focus-visible, summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--surface); border-color: var(--accent); color: var(--accent); }
.btn.secondary:hover { background: var(--accent-soft); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.link { background: none; border: 0; padding: 4px 6px; min-height: 0; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.btn[disabled] { opacity: 0.6; cursor: progress; }
.btn-row { display: flex; flex-wrap: wrap; gap: 12px; }

/* ---------- Intro ---------- */
#screen-intro { display: grid; gap: 20px; padding-top: 12px; }
.arabic { font-family: var(--font-arabic); font-size: 2rem; color: var(--gold); line-height: 1.2; }
.lede { font-size: 1.1rem; color: var(--ink-2); }
.facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.facts li { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
.fact-icon { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 0.95rem; }
#screen-intro .btn.primary { min-width: 160px; }
.hadith { margin: 8px 0 0; padding: 16px 18px; border-left: 3px solid var(--gold); background: var(--surface-2); border-radius: 0 12px 12px 0; }
.hadith blockquote { margin: 0; font-family: var(--font-display); font-size: 1.05rem; line-height: 1.5; }
.hadith figcaption { margin-top: 6px; font-size: 0.85rem; color: var(--muted); }

/* ---------- Survey ---------- */
.progress { height: 6px; background: var(--track); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width 0.3s ease; }
.step-count { margin: 12px 0 18px; font-size: 0.85rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }

#question { display: grid; gap: 16px; }
.help { color: var(--ink-2); }
.note { font-size: 0.9rem; color: var(--muted); }

.choices { border: 0; margin: 0; padding: 0; display: grid; gap: 10px; }
.choice { position: relative; display: block; cursor: pointer; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-body {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px; min-height: 60px;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 14px;
  transition: border-color 0.15s, background-color 0.15s;
}
.choice:hover .choice-body { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.choice-dot { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; transition: border-color 0.15s; }
.choice-dot::after { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); transform: scale(0); transition: transform 0.15s; }
.choice input:checked + .choice-body { border-color: var(--accent); background: var(--accent-soft); }
.choice input:checked + .choice-body .choice-dot { border-color: var(--accent); }
.choice input:checked + .choice-body .choice-dot::after { transform: scale(1); }
.choice-text { display: grid; gap: 2px; }
.choice-label { font-weight: 600; }
.choice-hint { font-size: 0.9rem; color: var(--muted); }

.field { display: grid; gap: 8px; }
.field-label { font-weight: 600; }
.number-row { display: flex; align-items: center; gap: 12px; }
.number-input {
  width: 120px; padding: 12px 14px; font-size: 1.4rem; font-weight: 600;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 12px;
  font-variant-numeric: tabular-nums;
}
.number-input.small { width: 92px; font-size: 1.15rem; padding: 10px 12px; }
.number-input:focus { border-color: var(--accent); outline: none; }
.number-input:disabled { opacity: 0.45; }
.unit { color: var(--ink-2); }

.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }

.slider-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; display: grid; gap: 10px; }
.slider-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.slider-name { font-weight: 600; }
.slider-sub { display: block; font-size: 0.85rem; font-weight: 400; color: var(--muted); }
.slider-value { font-weight: 600; color: var(--accent); white-space: nowrap; font-variant-numeric: tabular-nums; }
.big-value { font-size: 2rem; font-weight: 700; color: var(--accent); text-align: center; }
input[type='range'] { width: 100%; height: 32px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.ticks { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--muted); padding: 0 2px; }
.sliders { display: grid; gap: 10px; }
.unit-toggle { display: inline-flex; justify-self: start; padding: 3px; gap: 2px; border-radius: 999px; background: var(--surface-2); }
.unit-toggle label { position: relative; cursor: pointer; }
.unit-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.unit-toggle span { display: block; padding: 5px 12px; border-radius: 999px; font-size: 0.85rem; font-weight: 500; color: var(--ink-2); transition: background-color 0.15s, color 0.15s; }
.unit-toggle label:hover input:not(:checked) + span { color: var(--accent); }
.unit-toggle input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.unit-toggle input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }

.gap-list { display: grid; gap: 10px; }
.gap-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; }
.gap-row .remove { margin-left: auto; }
.add-gap { justify-self: start; }

.review-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.review-list li { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
.review-list li:first-child { border-top: 0; }
.review-q { font-size: 0.85rem; color: var(--muted); }
.review-a { font-weight: 600; }

.error { min-height: 1.5em; margin: 14px 0 0; color: var(--danger); font-weight: 500; }
.nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; }
.nav .btn.primary { min-width: 140px; }

/* ---------- Results ---------- */
.results { display: grid; gap: 18px; }
.eyebrow { font-size: 0.85rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.hero { display: grid; gap: 2px; }
.hero-grid { display: grid; gap: 14px 28px; margin-top: 4px; }
.hero-number { font-family: var(--font-body); font-weight: 700; font-size: clamp(3rem, 14vw, 4.25rem); line-height: 1; letter-spacing: -0.03em; color: var(--accent); }
.hero-label { font-size: 1.2rem; font-weight: 600; }
.hero-sub { color: var(--ink-2); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.card-head { display: grid; gap: 4px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.875rem; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch-p0 { background: var(--series-p0); }
.swatch-p1 { background: var(--series-p1); }
.swatch-p2 { background: var(--series-p2); }

.bars { display: grid; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 68px 1fr auto; align-items: center; gap: 12px; }
.bar-label { font-weight: 600; }
.bar-track { display: flex; gap: 2px; height: 14px; }
.seg { height: 100%; min-width: 2px; }
.seg:last-child { border-radius: 0 4px 4px 0; }
.seg.p0 { background: var(--series-p0); }
.seg.p1 { background: var(--series-p1); }
.seg.p2 { background: var(--series-p2); }
.bar-value { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 4.5ch; text-align: right; }

details.table-view summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 0.9rem; width: fit-content; }
.table-scroll { overflow-x: auto; margin-top: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--muted); font-weight: 600; }
tfoot td { font-weight: 700; border-bottom: 0; }

.plan-result { font-size: 1.1rem; }
.plan-control { display: grid; gap: 6px; }
.plan-control label { display: flex; justify-content: space-between; font-weight: 600; }
.plan-control output { color: var(--accent); }

.notes ul { margin: 0; padding-left: 20px; display: grid; gap: 10px; color: var(--ink-2); }
.notes li strong { color: var(--ink); }
.ayah { margin: 0; padding: 14px 16px; border-left: 3px solid var(--gold); background: var(--surface-2); border-radius: 0 12px 12px 0; }
.ayah p { font-family: var(--font-display); }
.ayah cite { display: block; margin-top: 6px; font-style: normal; font-size: 0.85rem; color: var(--muted); }

.zero-state { display: grid; gap: 12px; padding: 8px 0; }

.all-missed strong { font-weight: 600; }

.mode-link { justify-self: start; }
.mode-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; margin-top: 4px; }
.btn.link.subtle { color: var(--muted); font-weight: 500; }
.rough { display: grid; gap: 12px; }
.notice { display: grid; gap: 8px; padding: 16px 18px; background: var(--surface-2); border-left: 3px solid var(--gold); border-radius: 0 14px 14px 0; }
.notice .btn.link { justify-self: start; }
.subtle-check { padding: 8px 0 0; background: none; font-size: 0.9rem; color: var(--ink-2); }
.subtle-check .note { display: block; }
input[type='range']:disabled { opacity: 0.35; cursor: not-allowed; }

.split { display: grid; gap: 12px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.split-row { display: grid; gap: 2px; font-size: 0.875rem; color: var(--ink-2); }
.split-row strong { color: var(--ink); font-size: 1.05rem; }

.lead-line { font-family: var(--font-display); font-size: 1.25rem; line-height: 1.35; }
.plan-block { display: grid; gap: 8px; padding-top: 14px; border-top: 1px solid var(--border); }
.plan-start { padding-top: 14px; border-top: 1px solid var(--border); display: grid; gap: 4px; }
.plan-start .muted { font-size: 0.875rem; }

.how-phase { display: grid; gap: 6px; }
.how-phase + .how-phase { padding-top: 12px; border-top: 1px solid var(--border); }
h4 { margin: 0; font-size: 0.95rem; font-weight: 600; }
.how-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: max-content 1fr auto; gap: 4px 12px; align-items: baseline; font-size: 0.9rem; }
.how-list li { display: contents; }
.how-label { font-weight: 600; }
.how-calc { color: var(--ink-2); }
.how-value { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Footer & tooltip ---------- */
.footer { padding-top: 16px; padding-bottom: 28px; font-size: 0.85rem; color: var(--muted); border-top: 1px solid var(--border); }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--ink); color: var(--bg);
  font-size: 0.8rem; font-weight: 500; line-height: 1.35;
  padding: 6px 10px; border-radius: 8px; max-width: 240px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

@media (max-width: 359px) {
  .privacy-pill { display: none; }
}

@media (min-width: 560px) {
  main.wrap { padding-top: 40px; }
  .hero-grid { grid-template-columns: 1fr 1fr; }
  .card { padding: 24px; }
}

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