:root {
  --paper: #EDF0EB;
  --surface: #F8FAF7;
  --ink: #18222C;
  --muted: #5C6B71;
  --line: #D5DDD6;
  --jade: #2E6B5C;
  --jade-ink: #FFFFFF;
  --jade-soft: #D8E7E0;
  --gold: #A87B22;
  --gold-soft: #F2E6C8;
  --danger: #A23B2F;

  --ui: "Readex Pro", system-ui, -apple-system, sans-serif;
  --serif: "Amiri", "Times New Roman", serif;
  --quran: "Amiri Quran", "Amiri", serif;

  --radius-lg: 20px;
  --radius-sm: 12px;
  --gutter: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0E151C;
    --surface: #16202A;
    --ink: #E4EBE6;
    --muted: #8D9BA1;
    --line: #26333E;
    --jade: #5DB39B;
    --jade-ink: #0B1A15;
    --jade-soft: #1B362F;
    --gold: #D8AD55;
    --gold-soft: #3A2F1C;
    --danger: #E07A6C;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- السماء (الرأس) ---------- */
.sky {
  --top: #0E1B2E;
  --bottom: #2A3A5C;
  position: relative;
  overflow: hidden;
  color: #fff;
  background: linear-gradient(180deg, var(--top) 0%, var(--bottom) 100%);
  padding: calc(env(safe-area-inset-top) + 14px) var(--gutter) 86px;
  transition: background 1.2s ease;
}
.sky[data-period="fajr"]    { --top: #1F2547; --bottom: #A9637E; }
.sky[data-period="morning"] { --top: #2F6F98; --bottom: #8EBFD4; }
.sky[data-period="noon"]    { --top: #23699B; --bottom: #6FAFD3; }
.sky[data-period="asr"]     { --top: #9A6034; --bottom: #D9A964; }
.sky[data-period="maghrib"] { --top: #3B2347; --bottom: #C25A44; }
.sky[data-period="night"]   { --top: #0B1626; --bottom: #233456; }

.sky-stars {
  position: absolute; inset: 0;
  opacity: 0;
  transition: opacity 1.2s ease;
  background-image:
    radial-gradient(1.2px 1.2px at 12% 22%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 28% 64%, #fff 50%, transparent 51%),
    radial-gradient(1.4px 1.4px at 46% 18%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 61% 48%, #fff 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 77% 30%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 72%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 36% 86%, #fff 50%, transparent 51%),
    radial-gradient(1.3px 1.3px at 6% 78%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 54% 82%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 94% 12%, #fff 50%, transparent 51%);
}
.sky[data-period="night"] .sky-stars { opacity: .85; }
.sky[data-period="fajr"] .sky-stars,
.sky[data-period="maghrib"] .sky-stars { opacity: .35; }

/* الشمس أو القمر يتحرك على قوس حسب الوقت */
.sky-orb {
  --x: 50%;
  --y: 60%;
  position: absolute;
  width: 48px; height: 48px;
  left: var(--x); top: var(--y);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #FFF6D8, #F6C863 70%);
  box-shadow: 0 0 60px 18px rgba(255, 214, 120, .35);
  transition: left 1.2s ease, top 1.2s ease, background 1.2s ease, box-shadow 1.2s ease;
}
.sky[data-period="maghrib"] .sky-orb,
.sky[data-period="fajr"] .sky-orb {
  background: radial-gradient(circle at 40% 40%, #FFE3C4, #F08A5D 70%);
  box-shadow: 0 0 70px 24px rgba(240, 120, 80, .35);
}
.sky[data-period="night"] .sky-orb {
  width: 38px; height: 38px;
  background: transparent;
  box-shadow: inset -10px 3px 0 0 #F3EBD3, 0 0 40px 6px rgba(243, 235, 211, .12);
}

.sky::after {
  content: "";
  position: absolute; inset-inline: 0; bottom: 0; height: 18px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.12));
  pointer-events: none;
}
.sky-inner { position: relative; z-index: 1; }
.sky-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.hijri { font-family: var(--serif); font-size: 1.6rem; font-weight: 700; line-height: 1.3; text-shadow: 0 1px 12px rgba(0,0,0,.25); }
.greg { font-size: .85rem; opacity: .85; }
.sky-next { margin-top: 26px; }
.next-label { font-size: 1.75rem; font-weight: 500; line-height: 1.2; letter-spacing: -.01em; text-shadow: 0 1px 14px rgba(0,0,0,.25); }
.next-time { font-size: .95rem; opacity: .9; margin-top: 4px; }
.sky-status {
  margin-top: 18px;
  display: inline-block;
  font-size: .85rem;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,.16);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px;
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--muted);
}
.icon-btn.on-sky { color: #fff; background: rgba(255,255,255,.14); }

/* ---------- الأقسام ---------- */
main {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 var(--gutter) calc(env(safe-area-inset-bottom) + 32px);
}
.block { margin-top: 28px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.block-head h2 { margin: 0; font-size: 1.15rem; font-weight: 600; }
.tally { font-size: .82rem; color: var(--muted); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

/* ---------- الصلوات الخمس ---------- */
.prayers { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.prayer {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 4px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  transition: background .2s ease, border-color .2s ease, transform .15s ease;
}
.prayer:active { transform: scale(.96); }
.prayer .p-name { font-size: .95rem; font-weight: 500; }
.prayer .p-time { font-size: .74rem; color: var(--muted); }
.prayer .tick {
  width: 26px; height: 26px; border-radius: 50%;
  border: 1.5px solid var(--line);
  display: grid; place-items: center;
}
.prayer .tick svg { opacity: 0; transition: opacity .2s ease; }
.prayer.is-next { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.prayer.is-done { background: var(--jade); border-color: var(--jade); color: var(--jade-ink); }
.prayer.is-done .p-time { color: inherit; opacity: .8; }
.prayer.is-done .tick { border-color: transparent; background: rgba(255,255,255,.22); }
.prayer.is-done .tick svg { opacity: 1; }

/* ---------- صفوف القوائم ---------- */
.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 14px 16px;
  background: none; border: 0;
  text-align: right;
}
.row + .row, .row + .row-block, .row-block + .row, .row-block + .row-block { border-top: 1px solid var(--line); }
.row-block { padding: 14px 16px; }
.row-block .title { display: block; font-weight: 500; }
.row-block .sub { display: block; font-size: .8rem; color: var(--muted); }
.row .label { flex: 1; min-width: 0; }
.row .title { display: block; font-weight: 500; }
.row .sub { display: block; font-size: .8rem; color: var(--muted); }
.check {
  flex: none;
  width: 26px; height: 26px; border-radius: 8px;
  border: 1.5px solid var(--line);
  display: grid; place-items: center;
  transition: background .2s ease, border-color .2s ease;
}
.check svg { opacity: 0; transition: opacity .15s ease; }
.row[aria-pressed="true"] .check { background: var(--jade); border-color: var(--jade); color: var(--jade-ink); }
.row[aria-pressed="true"] .check svg { opacity: 1; }
.row[aria-pressed="true"] .title { color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  font-size: .82rem;
}
.chip[aria-pressed="true"] { background: var(--jade-soft); border-color: var(--jade); color: var(--ink); }
.chip b { font-weight: 600; }

/* ---------- ورد القرآن ---------- */
.wird { padding: 18px 16px 16px; }
.wird-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.wird-count { font-size: 2.4rem; font-weight: 300; line-height: 1; }
.wird-count small { font-size: 1rem; color: var(--muted); font-weight: 400; }
.wird-next { font-size: .82rem; color: var(--muted); text-align: left; }
.bar { height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; margin: 14px 0; }
.bar > i { display: block; height: 100%; width: 0; background: var(--jade); border-radius: 6px; transition: width .3s ease; }
.bar.is-full > i { background: var(--gold); }
.wird-actions { display: flex; gap: 8px; }
.step-btn {
  flex: 1;
  padding: 10px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: transparent;
  font-weight: 500;
}
.step-btn.fill { flex: 2; background: var(--jade); border-color: var(--jade); color: var(--jade-ink); }

/* ---------- الذكر ---------- */
.counter { display: flex; align-items: center; gap: 14px; }
.counter .label { flex: 1; min-width: 0; }
.counter .title { display: block; font-weight: 500; }
.counter .sub { display: block; font-size: .8rem; color: var(--muted); }
.tap {
  --p: 0;
  flex: none;
  position: relative;
  width: 76px; height: 76px;
  border-radius: 50%;
  border: 0;
  background: conic-gradient(var(--ring, var(--jade)) calc(var(--p) * 1turn), var(--line) 0);
  display: grid; place-items: center;
  transition: transform .1s ease;
}
.tap::before { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: var(--surface); }
.tap span { position: relative; font-size: 1.25rem; font-weight: 500; }
.tap:active { transform: scale(.94); }
.tap.is-full { --ring: var(--gold); }
.mini-btns { display: flex; flex-direction: column; gap: 6px; }
.mini {
  min-width: 46px;
  padding: 4px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  font-size: .8rem;
}

/* ---------- الجمعة ---------- */
.friday .panel { border-color: var(--gold); }
.friday .row[aria-pressed="true"] .check { background: var(--gold); border-color: var(--gold); }

/* ---------- الضروريات المؤقتة ---------- */
.temp {
  padding: 16px;
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.temp-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.temp-title { font-weight: 600; font-size: 1.05rem; }
.temp-sub { font-size: .82rem; color: var(--muted); }
.days { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.day-dot {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1.5px dashed var(--line);
  display: grid; place-items: center;
  font-size: .75rem; color: var(--muted);
}
.day-dot.on { border: 0; background: var(--gold); color: #fff; }
.day-dot.today { border-style: solid; border-color: var(--gold); }
.temp-btn {
  width: 100%;
  padding: 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gold);
  background: transparent;
  font-weight: 500;
}
.temp-btn[aria-pressed="true"] { background: var(--gold-soft); }
.temp-note { margin-top: 10px; font-family: var(--serif); font-size: .98rem; color: var(--muted); }
.empty { color: var(--muted); font-size: .9rem; padding: 4px 2px; }

/* ---------- زاد اليوم ---------- */
.hadith {
  padding: 22px 18px 18px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
}
.hadith .kind { font-size: .8rem; color: var(--gold); font-weight: 500; }
.hadith blockquote {
  margin: 8px 0 12px;
  font-family: var(--serif);
  font-size: 1.28rem;
  line-height: 1.95;
}
.hadith-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hadith cite { font-style: normal; font-size: .82rem; color: var(--muted); }

.text-btn {
  border: 0; background: none; padding: 4px 2px;
  color: var(--jade); font-weight: 500; font-size: .9rem;
}

.tilawa {
  margin-top: 12px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--jade);
  color: var(--jade-ink);
}
.reciters { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -4px 14px; padding: 0 4px; }
.reciters::-webkit-scrollbar { display: none; }
.reciter {
  flex: none;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid currentColor;
  background: transparent;
  font-size: .82rem;
  opacity: .75;
}
.reciter[aria-pressed="true"] { opacity: 1; background: var(--jade-ink); color: var(--jade); border-color: var(--jade-ink); }
.clip-title { font-weight: 500; font-size: .95rem; opacity: .9; }
.ayat {
  margin: 10px 0 14px;
  font-family: var(--quran);
  font-size: 1.45rem;
  line-height: 2.25;
  min-height: 2.25em;
}
.ayat .ayah { transition: color .3s ease, background .3s ease; border-radius: 6px; }
.ayat .ayah.now { background: rgba(255,255,255,.18); }
.ayat .num { font-family: var(--serif); font-size: .9em; opacity: .8; }
.ayat.loading { opacity: .6; font-family: var(--ui); font-size: .9rem; }
.player { display: flex; align-items: center; gap: 12px; }
.play {
  flex: none;
  width: 52px; height: 52px; border-radius: 50%;
  border: 0;
  background: var(--jade-ink); color: var(--jade);
  display: grid; place-items: center;
}
.player .track { flex: 1; }
.player .bar { margin: 0 0 6px; background: rgba(255,255,255,.25); }
.player .bar > i { background: var(--jade-ink); transition: width .25s linear; }
.player .meta { display: flex; justify-content: space-between; font-size: .78rem; opacity: .85; }
.tilawa .text-btn { color: inherit; opacity: .9; }
.tilawa .err { margin-top: 10px; font-size: .85rem; }

/* ---------- الأسبوع ---------- */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.wday { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: .75rem; color: var(--muted); }
.wbar {
  width: 100%; max-width: 30px; height: 64px;
  border-radius: 10px;
  background: var(--line);
  position: relative; overflow: hidden;
}
.wbar > i { position: absolute; inset: auto 0 0 0; background: var(--jade); }
.wbar.full > i { background: var(--gold); }
.wday.today { color: var(--ink); font-weight: 600; }

.foot { margin-top: 36px; font-size: .75rem; color: var(--muted); line-height: 1.7; }

/* ---------- تلميح التثبيت ---------- */
.install-hint {
  position: fixed;
  inset-inline: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  background: var(--ink); color: var(--paper);
  border-radius: 16px;
  font-size: .85rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  z-index: 10;
}
.install-hint .icon-btn { color: inherit; flex: none; }

/* ---------- النوافذ ---------- */
.sheet {
  width: min(520px, calc(100% - 24px));
  max-height: calc(100dvh - 40px);
  border: 0;
  border-radius: 22px;
  padding: 22px 18px 18px;
  background: var(--surface);
  color: var(--ink);
}
.sheet::backdrop { background: rgba(10, 16, 22, .5); }
.sheet h3 { margin: 0 0 12px; font-size: 1.2rem; }
fieldset { border: 0; padding: 0; margin: 0 0 18px; }
legend { font-size: .85rem; color: var(--muted); margin-bottom: 8px; padding: 0; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.field span { font-size: .95rem; }
.field input, .field select {
  font: inherit;
  width: 46%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}
#tempForm .field { flex-direction: column; align-items: stretch; gap: 6px; }
#tempForm .field input { width: 100%; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 6px; min-height: 1em; }
.sheet-actions { display: flex; gap: 8px; margin-top: 6px; }
.primary-btn, .ghost-btn {
  flex: 1;
  padding: 11px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.primary-btn { border: 0; background: var(--jade); color: var(--jade-ink); }
.ghost-btn { border: 1px solid var(--line); background: transparent; }
fieldset .ghost-btn { width: 100%; margin-top: 4px; }
.danger-link { display: block; margin: 14px auto 0; border: 0; background: none; color: var(--danger); font-size: .85rem; }

@media (max-width: 360px) {
  .prayer .p-name { font-size: .85rem; }
  .next-label { font-size: 1.7rem; }
}

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

/* ---------- الذكر بالخاتم ---------- */
.dhikr .tap { width: 64px; height: 64px; }
.dhikr .tap span { font-size: .9rem; }
.dhikr-num { display: block; font-size: .85rem; margin-top: 2px; }
.dhikr-num b { font-size: 1.05rem; font-weight: 600; }
.dhikr-entry { display: flex; gap: 8px; margin-top: 12px; }
.dhikr-entry input {
  flex: 1; min-width: 0;
  font: inherit;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}
.dhikr-quick { display: flex; gap: 8px; margin-top: 8px; }
.dhikr-quick .mini, .dhikr-entry .mini { flex: 1; padding: 8px 4px; font-size: .85rem; }
.mini.save, .mini.fill { background: var(--jade); border-color: var(--jade); color: var(--jade-ink); font-weight: 500; }
.dhikr-entry .mini.save { flex: none; padding-inline: 18px; }

/* ---------- التمرين ---------- */
.ex-row + .ex-row { border-top: 1px solid var(--line); }
.ex-amount { flex: none; font-weight: 600; font-size: .95rem; color: var(--jade); }
.row[aria-pressed="true"] .ex-amount { color: var(--muted); }
.ex-timer {
  display: block;
  width: calc(100% - 32px);
  margin: -4px 16px 14px;
  padding: 9px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--jade);
  background: transparent;
  color: var(--jade);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.ex-foot { margin-top: 8px; font-size: .78rem; color: var(--muted); }
.rest { padding: 16px; }
.rest .ex-foot { margin-top: 10px; }
.rest-when { font-weight: 500; }
.rest-list { list-style: none; margin: 10px 0 0; padding: 0; }
.rest-list li { display: flex; justify-content: space-between; padding: 6px 0; border-top: 1px dashed var(--line); font-size: .92rem; }
.rest-list li span:last-child { color: var(--jade); font-weight: 500; }
.switch { width: 22px !important; height: 22px; accent-color: var(--jade); }
#wdays { margin: 0 0 6px; }
